"use client"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { CARD_TITLE_ACTION } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { IconTooltip } from "@/components/ui/tooltip"; import { NativeSelect } from "@/components/ui/native-select"; import { CHART_SCOPES, CHART_SCOPE_LABELS, periodLabel, periodRange, } from "@/lib/chart-period"; import type { ChartPeriodState } from "@/hooks/useChartPeriodView"; import { cn } from "@/lib/utils"; export interface ChartPeriodControlsProps { // The card's name as every control's accessible name leads with it - // "Dive activity", "Gas consumption". name: string; view: ChartPeriodState; } // A Home trend card's period stepper and All/Year/Month toggle. Two siblings // rather than one box, laid out by the `CARD_TITLE_ROW` they sit in after the // card's title, which is an `@container`: below its `2xl` the stepper wraps onto // a line of its own. // // Every control here names its own card, because the two cards draw the same row // and `Card` is a plain `div` - so nothing scopes them to each other. Read in // place the heading is all the context you need, but a screen reader's controls // list is flat names and nothing else, and four arrows reading "Previous period // with dives" in it are four coin flips. The card name leads rather than trails // so the list groups by chart when it is scanned or sorted. Same ambiguity // `screenshots.mjs` hit from the automation side, where the fix was to scope by // the card's own heading, which is exactly the context a controls list drops. export function ChartPeriodControls({ name, view }: ChartPeriodControlsProps) { const { scope, anchor, setAnchor, setScope, previous, next, periods } = view; return ( <> {/* Only the bounded scopes have a period to navigate. "All" already shows everything there is, so arrows on it would have nowhere to go. */} {scope !== "all" && (
{/* The label is also the jump-to control - stepping one period at a time is fine for "the trip before this one", and useless for reaching one several seasons back. Its value is the *period's* start, never the anchor itself: the anchor is whichever dive or day you happened to land on, which usually matches no option, and a `