|
| 1 | +import { useState } from "react"; |
| 2 | +import { |
| 3 | + DateTime, |
| 4 | + DateTimeAccurate, |
| 5 | + DateTimeShort, |
| 6 | + RelativeDateTime, |
| 7 | + SmartDateTime, |
| 8 | +} from "~/components/primitives/DateTime"; |
| 9 | +import { PrettyDuration } from "~/components/primitives/PrettyDuration"; |
| 10 | +import { LiveCountdown, LiveCountUp, LiveTimer } from "~/components/runs/v3/LiveTimer"; |
| 11 | +import { Story, StoryGrid, StoryPage, StorySection } from "../storybook/StoryKit"; |
| 12 | + |
| 13 | +/* A fixed moment so the formatting variants are comparable at a glance. */ |
| 14 | +const SAMPLE = new Date("2026-08-12T09:24:03.256Z"); |
| 15 | +const SAMPLE_EARLIER = new Date("2026-08-12T09:23:41.881Z"); |
| 16 | +const SAMPLE_PREVIOUS_DAY = new Date("2026-08-11T22:10:00.000Z"); |
| 17 | + |
| 18 | +export default function Story_() { |
| 19 | + // Anchored on mount so the live components have something to count against. |
| 20 | + const [mountedAt] = useState(() => new Date(Date.now() - 83_000)); |
| 21 | + const [countdownEnd] = useState(() => new Date(Date.now() + 95_000)); |
| 22 | + |
| 23 | + return ( |
| 24 | + <StoryPage |
| 25 | + title="Dates & timers" |
| 26 | + description="Every date formatting component, plus the live-updating timers used on run rows." |
| 27 | + > |
| 28 | + <StorySection title="DateTime" description="The standard formatter; hover for the tooltip."> |
| 29 | + <StoryGrid min="16rem"> |
| 30 | + <Story label="Default"> |
| 31 | + <DateTime date={SAMPLE} /> |
| 32 | + </Story> |
| 33 | + <Story label="includeSeconds"> |
| 34 | + <DateTime date={SAMPLE} includeSeconds /> |
| 35 | + </Story> |
| 36 | + <Story label="includeTime={false}"> |
| 37 | + <DateTime date={SAMPLE} includeTime={false} /> |
| 38 | + </Story> |
| 39 | + <Story label="showTimezone"> |
| 40 | + <DateTime date={SAMPLE} showTimezone /> |
| 41 | + </Story> |
| 42 | + <Story label="hour12={false}"> |
| 43 | + <DateTime date={SAMPLE} hour12={false} /> |
| 44 | + </Story> |
| 45 | + </StoryGrid> |
| 46 | + </StorySection> |
| 47 | + |
| 48 | + <StorySection title="Variants"> |
| 49 | + <StoryGrid min="16rem"> |
| 50 | + <Story label="DateTimeAccurate (ms)"> |
| 51 | + <DateTimeAccurate date={SAMPLE} /> |
| 52 | + </Story> |
| 53 | + <Story label="DateTimeShort"> |
| 54 | + <DateTimeShort date={SAMPLE} /> |
| 55 | + </Story> |
| 56 | + <Story label="SmartDateTime (same day as previous)"> |
| 57 | + <SmartDateTime date={SAMPLE} previousDate={SAMPLE_EARLIER} /> |
| 58 | + </Story> |
| 59 | + <Story label="SmartDateTime (new day)"> |
| 60 | + <SmartDateTime date={SAMPLE} previousDate={SAMPLE_PREVIOUS_DAY} /> |
| 61 | + </Story> |
| 62 | + <Story label="RelativeDateTime"> |
| 63 | + <RelativeDateTime date={SAMPLE_PREVIOUS_DAY} /> |
| 64 | + </Story> |
| 65 | + </StoryGrid> |
| 66 | + </StorySection> |
| 67 | + |
| 68 | + <StorySection title="PrettyDuration"> |
| 69 | + <StoryGrid min="16rem"> |
| 70 | + <Story label="22.4s"> |
| 71 | + <PrettyDuration startAt={SAMPLE_EARLIER} endAt={SAMPLE} /> |
| 72 | + </Story> |
| 73 | + <Story label="11h 14m"> |
| 74 | + <PrettyDuration startAt={SAMPLE_PREVIOUS_DAY} endAt={SAMPLE} /> |
| 75 | + </Story> |
| 76 | + <Story label="Missing dates → fallback"> |
| 77 | + <PrettyDuration startAt={null} endAt={null} fallback="Not started" /> |
| 78 | + </Story> |
| 79 | + </StoryGrid> |
| 80 | + </StorySection> |
| 81 | + |
| 82 | + <StorySection |
| 83 | + title="Live timers" |
| 84 | + description="Update in place — used while a run is executing." |
| 85 | + > |
| 86 | + <StoryGrid min="16rem"> |
| 87 | + <Story label="LiveTimer (running)"> |
| 88 | + <LiveTimer startTime={mountedAt} /> |
| 89 | + </Story> |
| 90 | + <Story label="LiveTimer (ended)"> |
| 91 | + <LiveTimer startTime={SAMPLE_EARLIER} endTime={SAMPLE} /> |
| 92 | + </Story> |
| 93 | + <Story label="LiveCountUp"> |
| 94 | + <LiveCountUp lastUpdated={mountedAt} /> |
| 95 | + </Story> |
| 96 | + <Story label="LiveCountdown"> |
| 97 | + <LiveCountdown endTime={countdownEnd} /> |
| 98 | + </Story> |
| 99 | + </StoryGrid> |
| 100 | + </StorySection> |
| 101 | + </StoryPage> |
| 102 | + ); |
| 103 | +} |
0 commit comments