Skip to content

shadcn.io is an independent project built on shadcn/ui

Commute Calculator Map Block for React

A draggable Home pin on a live Melbourne map and four weekly places; Drive, Transit or Bike turns each leg into minutes, ranked fastest first with bars.

On this page5 sections

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Show house hunters what the commute would be from the street they are looking at, with this commute calculator map for React with Base UI. Pacefield, a house-hunting commute tool, puts a Home pin on a live Map of Melbourne that follows your theme, with the four places a household goes every week in real neighbourhoods: an office in Southbank, a clinic in Footscray, a print studio in Collingwood and a library in Brunswick. Drag Home with a mouse, pen or finger, click the map to drop it there, or focus it and move it with the arrow keys; Escape puts it back. A Toggle Group picks Drive, Transit or Bike, and each leg becomes minutes from its straight-line distance, a street detour and a typed pace for the mode, plus a wait for transit. The legs are dashed lines with their minutes on them; the card floating over the map lists the places fastest first with their minutes, distance and a Progress bar, and gives the average. Pressing a place draws its leg solid and inverts its pill, and the camera stays put while Home moves. Built from Map, Toggle Group, Progress, Button and Guides. For property, relocation and recruiting apps.

FAQ

How are the minutes worked out?

minutesOf takes the great-circle distance from Home to the place in kilometres, multiplies it by DETOUR (1.3, because streets are rarely straight), divides it by the mode's pace in MODES (30 km/h driving, 20 km/h transit, 15 km/h cycling) and adds the mode's wait (6 minutes for transit). It is an estimate, not a route: no routing service is called, and the caption says how it's made. In your app, swap it for travel times from your routing or transit provider and keep the rest.

What is real, and what stays local?

The neighbourhoods and the map are real; the four places, the household and the paces are invented sample data. Nothing asks for the device's location and nothing is sent anywhere: Home is local state, and only the map tiles are loaded. In your app, let people search an address, put Home there, and fetch the four travel times when the pin rests.

What are the ways to move Home?

Drag the pin, click anywhere on the map, or focus the pin with Tab and use the arrow keys (Shift moves it four times as far). Escape and the reset button under the zoom controls put it back in Northcote. The numbers follow the pin as it moves; the camera doesn't, so the map never jumps while you drag.

Can I use it without a mouse?

Yes. The Home pin is focusable and moves with the arrow keys, described by the hint in the card. The modes are a toggle group, each place in the ranked list is a button that draws its leg solid, and the zoom and reset buttons work from the keyboard; the map itself takes the arrow keys and plus and minus once focused. A polite message gives the average and the fastest and slowest places once Home has rested.

Why does the card float over the map?

On a wide screen the card sits over the start of the map, and the camera keeps room for it so no place hides underneath. Below the md breakpoint it docks under the map instead and the camera takes the whole width; a small effect reads the breakpoint with matchMedia to choose the camera's padding.

How does it look on a phone?

The map comes first with Home, the four places and their minutes, then the card: the average, the three modes, the ranked places and the hint, then the caption. The rows keep their height when the order changes, so nothing jumps while Home is dragged. Scrolling the page over the map scrolls the page; two fingers move the map.