diff --git a/package.json b/package.json index 071fe6f..24d82ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@schemavaults/ui", - "version": "0.71.1", + "version": "0.72.1", "private": false, "license": "UNLICENSED", "description": "React.js UI components for SchemaVaults frontend applications", diff --git a/src/components/ui/index.ts b/src/components/ui/index.ts index 6910cd6..f0d2bba 100644 --- a/src/components/ui/index.ts +++ b/src/components/ui/index.ts @@ -290,3 +290,6 @@ export type * from "./date-range-picker"; export * from "./time-picker"; export type * from "./time-picker"; + +export * from "./relative-time"; +export type * from "./relative-time"; diff --git a/src/components/ui/relative-time/RelativeTime.stories.tsx b/src/components/ui/relative-time/RelativeTime.stories.tsx new file mode 100644 index 0000000..025a77d --- /dev/null +++ b/src/components/ui/relative-time/RelativeTime.stories.tsx @@ -0,0 +1,309 @@ +import type { Meta, StoryObj } from "@storybook/react"; +import type { ReactElement } from "react"; + +import { + RelativeTime, + relativeTimeFormatIds, + relativeTimeSizeIds, + relativeTimeVariantIds, +} from "./relative-time"; + +const SECOND_MS = 1000; +const MINUTE_MS = 60 * SECOND_MS; +const HOUR_MS = 60 * MINUTE_MS; +const DAY_MS = 24 * HOUR_MS; +const WEEK_MS = 7 * DAY_MS; +const MONTH_MS = 30 * DAY_MS; +const YEAR_MS = 365 * DAY_MS; + +function fromNow(ms: number): number { + return Date.now() + ms; +} + +const meta = { + title: "Components/RelativeTime", + component: RelativeTime, + parameters: { + layout: "centered", + docs: { + description: { + component: + "Displays a timestamp as a human-readable relative phrase like `5 minutes ago` or `in 3 days`, auto-refreshing at the appropriate cadence (every second for sub-minute values, every minute for sub-hour, and so on).\n\n" + + "Built on top of [`Intl.RelativeTimeFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat), so it supports any browser-recognised BCP-47 locale and three format widths (`long`, `short`, `narrow`). Renders as a semantic `