nook
Browse the docs

Components

Trip tracker

Native

A ride map, trip progress, driver details and a pre-trip ride chooser.

See the prompt

Driver on the way

4 min away

Drag to pan. Focus the map and use arrow keys to pan, plus and minus to zoom. Use Tab to reach places and map controls.

  • Trip route from Bergen Street station · Smith Street to Northline Studio · 18 Orchard Street. Route coordinates: 40.68606, -73.99089; 40.68698, -73.99030; 40.68746, -73.98997; 40.68820, -73.98950; 40.68830, -73.98945
  • Pickup: 40.68606, -73.99089
  • Drop-off: 40.68830, -73.98945
Zoom 16.0. Center 40.6872, -73.9908.
© OpenStreetMap contributors
Pickup
Bergen Street station · Smith Street
Drop-off
Northline Studio · 18 Orchard Street
  1. Done:
    Finding a driver
  2. 2Current:
    Driver on the way
  3. 3Upcoming:
    On trip
  4. 4Upcoming:
    Arrived
AM

Alex Morgan

4.9
Toyota Camry · SilverNYC 2048
Estimated fare$19.50

Installation

npx nook-ui@latest add trip-tracker

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Trip tracker" component to this project, exactly as Nook ships it.

A ride map, trip progress, driver details and a pre-trip ride chooser.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add trip-tracker`. It writes `components/ui/trip-tracker.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/trip-tracker.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
"use client";

import * as React from "react";
import { TripTracker, type TripStatus } from "@/components/ui/trip-tracker";
import { ToggleGroup, Toggle } from "@/components/ui/toggle-group";
import { OSM_TILES, cityCenter, cityRoute, station, studio } from "../map/data";

export default function TripDefault() {
  const [status, setStatus] = React.useState<TripStatus>("driver-on-way");
  const [ride, setRide] = React.useState("comfort");
  const [message, setMessage] = React.useState("");
  const rides = [
    { id: "economy", name: "Economy", price: 14.5, arrival: "3 min away" },
    { id: "comfort", name: "Comfort", price: 19.5, arrival: "4 min away" },
    { id: "xl", name: "XL", price: 26, arrival: "6 min away" },
  ];
  return (
    <div className="grid w-full gap-6">
      <ToggleGroup
        value={[status]}
        onValueChange={(value) => {
          if (value[0]) setStatus(value[0] as TripStatus);
        }}
        aria-label="Preview trip status"
        className="flex-wrap"
      >
        <Toggle value="finding">Finding</Toggle>
        <Toggle value="driver-on-way">Driver coming</Toggle>
        <Toggle value="on-trip">On trip</Toggle>
        <Toggle value="arrived">Arrived</Toggle>
      </ToggleGroup>
      <TripTracker
        status={status}
        pickup={{
          name: "Bergen Street station · Smith Street",
          position: station,
        }}
        dropoff={{
          name: "Northline Studio · 18 Orchard Street",
          position: studio,
        }}
        route={cityRoute}
        mapProps={{
          defaultValue: { center: cityCenter, zoom: 16 },
          tileUrl: OSM_TILES,
          attribution: (
            <>
              ©{" "}
              <a href="https://www.openstreetmap.org/copyright" className="underline">
                OpenStreetMap
              </a>{" "}
              contributors
            </>
          ),
        }}
        driver={{
          name: "Alex Morgan",
          rating: 4.9,
          car: "Toyota Camry · Silver",
          plate: "NYC 2048",
        }}
        eta={status === "on-trip" ? "8 min" : "4 min"}
        fare={rides.find((option) => option.id === ride)!.price}
        rideTypes={rides}
        rideType={ride}
        onRideTypeChange={setRide}
        onCall={() =>
          setMessage("Call Alex at the number provided by your ride service.")
        }
        onMessage={() =>
          setMessage("Message to Alex: I am by the Smith Street exit.")
        }
        onCancel={() =>
          setMessage(
            "Cancellation requested. Confirm it with your ride service.",
          )
        }
        onShare={() =>
          setMessage("Trip details are ready to share with someone you trust.")
        }
      />
      <p role="status" className="text-sm text-muted-foreground">
        {message}
      </p>
    </div>
  );
}
```

API
- `TripTracker`: Composes Map, Steps, Avatar, Rating and Money. The app owns trip status and all service actions.
  - `status` (`TripStatus`): Required state: finding, driver-on-way, on-trip or arrived. Does not advance automatically.
  - `pickup / dropoff / route` (`TripPlace / TripPlace / MapCoordinate[]`): Named endpoints and optional ordered route coordinates.
  - `driver` (`TripDriver`): name, optional avatar, rating, car and plate. Shown once a driver is on the way.
  - `eta / fare / currency` (`string / number / string`): Human-readable ETA and fare in major currency units.
  - `rideTypes / rideType / defaultRideType / onRideTypeChange` (`RideType[] / string / callback`): Pre-trip choices with id, name, price and arrival. Selection can be controlled.
  - `onCall / onMessage / onCancel / onShare` (`() => void`): App-owned actions. No call, message, share or cancellation request is sent by the component.
  - `mapProps / mapOverlay` (`MapProps / ReactNode`): Map viewport, tile configuration and optional geographic road overlays.
- Variant `status`: finding, driver-on-way, on-trip, arrived (default finding)

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Status is stated in words and through the existing Steps. Ride types are native radios. Driver rating has a text label, the license plate is named, and every map gesture has keyboard controls.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

"use client";

import * as React from "react";
import { TripTracker, type TripStatus } from "@/components/ui/trip-tracker";
import { ToggleGroup, Toggle } from "@/components/ui/toggle-group";
import { OSM_TILES, cityCenter, cityRoute, station, studio } from "../map/data";

export default function TripDefault() {
  const [status, setStatus] = React.useState<TripStatus>("driver-on-way");
  const [ride, setRide] = React.useState("comfort");
  const [message, setMessage] = React.useState("");
  const rides = [
    { id: "economy", name: "Economy", price: 14.5, arrival: "3 min away" },
    { id: "comfort", name: "Comfort", price: 19.5, arrival: "4 min away" },
    { id: "xl", name: "XL", price: 26, arrival: "6 min away" },
  ];
  return (
    <div className="grid w-full gap-6">
      <ToggleGroup
        value={[status]}
        onValueChange={(value) => {
          if (value[0]) setStatus(value[0] as TripStatus);
        }}
        aria-label="Preview trip status"
        className="flex-wrap"
      >
        <Toggle value="finding">Finding</Toggle>
        <Toggle value="driver-on-way">Driver coming</Toggle>
        <Toggle value="on-trip">On trip</Toggle>
        <Toggle value="arrived">Arrived</Toggle>
      </ToggleGroup>
      <TripTracker
        status={status}
        pickup={{
          name: "Bergen Street station · Smith Street",
          position: station,
        }}
        dropoff={{
          name: "Northline Studio · 18 Orchard Street",
          position: studio,
        }}
        route={cityRoute}
        mapProps={{
          defaultValue: { center: cityCenter, zoom: 16 },
          tileUrl: OSM_TILES,
          attribution: (
            <>
              ©{" "}
              <a href="https://www.openstreetmap.org/copyright" className="underline">
                OpenStreetMap
              </a>{" "}
              contributors
            </>
          ),
        }}
        driver={{
          name: "Alex Morgan",
          rating: 4.9,
          car: "Toyota Camry · Silver",
          plate: "NYC 2048",
        }}
        eta={status === "on-trip" ? "8 min" : "4 min"}
        fare={rides.find((option) => option.id === ride)!.price}
        rideTypes={rides}
        rideType={ride}
        onRideTypeChange={setRide}
        onCall={() =>
          setMessage("Call Alex at the number provided by your ride service.")
        }
        onMessage={() =>
          setMessage("Message to Alex: I am by the Smith Street exit.")
        }
        onCancel={() =>
          setMessage(
            "Cancellation requested. Confirm it with your ride service.",
          )
        }
        onShare={() =>
          setMessage("Trip details are ready to share with someone you trust.")
        }
      />
      <p role="status" className="text-sm text-muted-foreground">
        {message}
      </p>
    </div>
  );
}

Variants

Defined in one place with cva, at the top of the component file.

  • status

    finding (default)driver-on-wayon-triparrived

Props

TripTracker

Composes Map, Steps, Avatar, Rating and Money. The app owns trip status and all service actions.

PropTypeDefaultDescription
statusTripStatus–Required state: finding, driver-on-way, on-trip or arrived. Does not advance automatically.
pickup / dropoff / routeTripPlace / TripPlace / MapCoordinate[]–Named endpoints and optional ordered route coordinates.
driverTripDriver–name, optional avatar, rating, car and plate. Shown once a driver is on the way.
eta / fare / currencystring / number / string–Human-readable ETA and fare in major currency units.
rideTypes / rideType / defaultRideType / onRideTypeChangeRideType[] / string / callback–Pre-trip choices with id, name, price and arrival. Selection can be controlled.
onCall / onMessage / onCancel / onShare() => void–App-owned actions. No call, message, share or cancellation request is sent by the component.
mapProps / mapOverlayMapProps / ReactNode–Map viewport, tile configuration and optional geographic road overlays.

Accessibility

Status is stated in words and through the existing Steps. Ride types are native radios. Driver rating has a text label, the license plate is named, and every map gesture has keyboard controls.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.