Skip to content

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

EV Charging Map Block for React

A charge planner on a live map of the A2 from Berlin to Dortmund: pick a plug, a battery and a charge window, and rank eight stops by cost or by time.

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

Help drivers plan the stop before the trip with this EV charging map for React with Base UI. Plugvale, a charging network, has eight stops at real towns along the A2 from Berlin to Dortmund, and the road itself is drawn on a live Map that follows your theme, light or dark: 491 km baked from the OSRM route service when the block was written, never fetched. A band docked under the map sets the car: a connector Native Select (CCS, Type 2 or CHAdeMO), a battery select (60, 77 or 100 kWh) and a two-thumb Slider for the charge window (arrive at 20 percent, leave at 80), which together give the energy to add. Every stop that has your connector is a dot on the road labelled with the time to charge there; the table under the band gives each one's rate, time, cost and free bays in words, and a Toggle Group ranks them by cheapest or fastest. A stop without the connector turns to a hollow ring and drops, greyed, below the rest, so the table keeps its eight rows and its height. Choosing a stop, in the table or on the map, flies the camera there. Built from Map, Native Select, Slider, Toggle Group, Button and Guides. For charging networks, fleet apps and EV trip planners.

FAQ

Where do the road and the stops come from, and what stays local?

The road is ROUTE_LINE: the public OSRM demo's driving route from Potsdamer Platz to Dortmund, asked once while the block was written and simplified to 77 points, so nothing is fetched at runtime. The stops are LINES: each town's point on the A2, its kilometre from Berlin, its rate per connector, tariff in cents per kWh and bays. The road and towns are real; Plugvale, its rates, tariffs and bays are invented. Nothing is booked or sent, and only the map tiles are loaded, from CARTO over OpenStreetMap data.

How are the time and the cost worked out?

The energy to add is the battery times the charge window: 77 kWh from 20 to 80 percent is 46.2 kWh. A stop's time is that energy over the lower of the car's top rate on the connector (175 kW on CCS, 11 kW on Type 2, 50 kW on CHAdeMO) and the stop's rate, rounded up to the minute; its cost is the energy times its tariff, in integer cents. Real charging slows as the battery fills, so treat the times as a floor.

How does the ranking work?

Cheapest orders the stops that have your connector by cost and then by time, fastest by time and then by cost; the stops without it follow in road order, greyed, with "No CCS here" or the like. The rows hold their places and their contents change, so the table never jumps or changes height.

How does the map fly to a stop?

The block keeps one aim: the whole trip (TRIP, the corners of the road) or the chosen stop. MapCamera frames it when the map starts and flies to each new one, at once when reduced motion is on; the map button frames the trip again. Stops without your connector can't be chosen.

Can I use it without a mouse?

Yes. The connector and battery are native selects, the slider moves with the arrow keys and says "Arrive at 20 percent" and "Leave at 80 percent", the ranking is a toggle group, and every stop with your connector is a button in the table; the zoom and frame buttons work from the keyboard and the map takes the arrow keys and plus and minus once focused. A polite message gives the energy, how many stops have your connector and the best one once the controls settle.

How does it look on a phone?

The map comes first with plain dots, then the band (the two selects side by side, the slider under them) and the table, which keeps the stop, time and cost and moves the free bays under the stop's name. The page scrolls over the map; hold Ctrl or ⌘ to zoom it with the wheel, or use two fingers.