# Departure board

Switch platforms and advance the clock to see the next trains roll onto the board.

[View Departure board on CyberSpec](https://www.cyberspec.dev/sink/departure-board)

## Installation

Use a React 19 project with shadcn configured. Render the installed components inside the Cyber root, and import your global stylesheet in the app entry point.

```sh
bunx --bun shadcn@latest add https://www.cyberspec.dev/r/departure-board.json
```

## Usage

```tsx
import { Cyber } from "@/components/ui/cyber"
import Recipe from "@/components/recipes/departure-board"

export default function App() {
  return (
    <Cyber>
      <Recipe />
    </Cyber>
  )
}
```

## Source

```tsx
"use client"

import { useState } from "react"
import { Clock3 } from "lucide-react"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { SegmentedControl } from "@/components/ui/segmented-control"
import "./recipe-layout.css"

const services = [
  { line: "A", every: 12, offset: 1, outbound: "East Pier", inbound: "Union Square" },
  { line: "B", every: 15, offset: 4, outbound: "Glassworks", inbound: "Northgate" },
  { line: "C", every: 20, offset: 9, outbound: "Salt Market", inbound: "City Hall" },
]
const startTime = 17 * 60 + 30
function clock(minutes: number) {
  return [Math.floor(minutes / 60) % 24, minutes % 60].map(part => String(part).padStart(2, "0")).join(":")
}

export default function DepartureBoard() {
  const [platform, setPlatform] = useState("Outbound")
  const [elapsed, setElapsed] = useState(0)
  const inbound = platform === "Inbound"
  const upcoming = services.flatMap(service => {
    const first = service.offset + (inbound ? 3 : 0)
    const departure = first + Math.max(0, Math.ceil((elapsed - first) / service.every)) * service.every
    return [departure, departure + service.every].map(minute => ({
      line: service.line, destination: inbound ? service.inbound : service.outbound, minute,
    }))
  }).sort((a, b) => a.minute - b.minute).slice(0, 4)
  return (
    <div className="sink-stack">
      <SegmentedControl label="Platform" options={["Outbound", "Inbound"]} value={platform}
        onValueChange={next => next && setPlatform(next)} />
      <div className="sink-between"><span className="sink-label">Grand Terminal</span><strong className="sink-metric">{clock(startTime + elapsed)}</strong></div>
      <ol className="sink-list" aria-label={`${platform} departures`}>
        {upcoming.map(({ line, destination, minute }) => (
          <li className="sink-item" key={`${line}-${minute}`}>
            <span className="sink-row"><Badge tone={line === "A" ? "signal" : line === "B" ? "flag" : "epic"}>{line}</Badge><strong>{destination}</strong></span>
            <span style={{ fontFamily: "var(--cy-mono)", color: "var(--cy-flag)" }}>{minute === elapsed ? "Due" : `${minute - elapsed} min`}</span>
          </li>
        ))}
      </ol>
      <Button size="sm" onClick={() => setElapsed(current => current + 5)}><Clock3 aria-hidden />Advance 5 minutes</Button>
    </div>
  )
}
```

## Components in this recipe

- [Segmented control](https://www.cyberspec.dev/components/sidebar/segmented-control.md) — A row of segments with an indicator that slides to the choice.
- [Badge](https://www.cyberspec.dev/components/sidebar/badge.md) — A small cut label in seven tones, with count and status variants.
- [Button](https://www.cyberspec.dev/components/sidebar/button.md) — A cut-corner button with a raised tab, five tones, and a press flash. Enable the cipher prop to scramble the label and briefly tear the frame on hover.

## Resources

- [All kitchen sink recipes](https://www.cyberspec.dev/sink.md)
- [Recipe source on GitHub](https://github.com/agnelnieves/cyberspec/blob/main/registry/cyber/recipes/departure-board.tsx)
- [Recipe layout stylesheet](https://github.com/agnelnieves/cyberspec/blob/main/registry/cyber/recipes/recipe-layout.css)
- [Shadcn registry item](https://www.cyberspec.dev/r/departure-board.json)
