@vjdesigns/vjdesigns-ui 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -1
- package/dist/ai/llms-full.txt +91 -1
- package/dist/ai/llms.txt +1 -0
- package/dist/ai/registry.json +154 -2
- package/dist/components/data-display/Countdown/Countdown.cjs.js +1 -0
- package/dist/components/data-display/Countdown/Countdown.d.ts +98 -0
- package/dist/components/data-display/Countdown/Countdown.mjs +150 -0
- package/dist/components/data-display/Countdown/Countdown.module.css.cjs.js +1 -0
- package/dist/components/data-display/Countdown/Countdown.module.css.mjs +30 -0
- package/dist/components/data-display/Countdown/index.d.ts +1 -0
- package/dist/i18n/en.cjs.js +1 -1
- package/dist/i18n/en.mjs +4 -0
- package/dist/i18n/types.d.ts +6 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +79 -78
- package/dist/locales/ar.cjs.js +1 -1
- package/dist/locales/ar.mjs +4 -0
- package/dist/locales/bn.cjs.js +1 -1
- package/dist/locales/bn.mjs +4 -0
- package/dist/locales/cs.cjs.js +1 -1
- package/dist/locales/cs.mjs +4 -0
- package/dist/locales/da.cjs.js +1 -1
- package/dist/locales/da.mjs +4 -0
- package/dist/locales/de.cjs.js +1 -1
- package/dist/locales/de.mjs +4 -0
- package/dist/locales/el.cjs.js +1 -1
- package/dist/locales/el.mjs +4 -0
- package/dist/locales/es.cjs.js +1 -1
- package/dist/locales/es.mjs +4 -0
- package/dist/locales/fa.cjs.js +1 -1
- package/dist/locales/fa.mjs +4 -0
- package/dist/locales/fi.cjs.js +1 -1
- package/dist/locales/fi.mjs +4 -0
- package/dist/locales/fr.cjs.js +1 -1
- package/dist/locales/fr.mjs +4 -0
- package/dist/locales/he.cjs.js +1 -1
- package/dist/locales/he.mjs +4 -0
- package/dist/locales/hi.cjs.js +1 -1
- package/dist/locales/hi.mjs +4 -0
- package/dist/locales/hu.cjs.js +1 -1
- package/dist/locales/hu.mjs +4 -0
- package/dist/locales/id.cjs.js +1 -1
- package/dist/locales/id.mjs +4 -0
- package/dist/locales/it.cjs.js +1 -1
- package/dist/locales/it.mjs +4 -0
- package/dist/locales/ja.cjs.js +1 -1
- package/dist/locales/ja.mjs +4 -0
- package/dist/locales/ko.cjs.js +1 -1
- package/dist/locales/ko.mjs +4 -0
- package/dist/locales/nb.cjs.js +1 -1
- package/dist/locales/nb.mjs +4 -0
- package/dist/locales/nl.cjs.js +1 -1
- package/dist/locales/nl.mjs +4 -0
- package/dist/locales/pl.cjs.js +1 -1
- package/dist/locales/pl.mjs +4 -0
- package/dist/locales/pt-BR.cjs.js +1 -1
- package/dist/locales/pt-BR.mjs +4 -0
- package/dist/locales/ro.cjs.js +1 -1
- package/dist/locales/ro.mjs +4 -0
- package/dist/locales/ru.cjs.js +1 -1
- package/dist/locales/ru.mjs +4 -0
- package/dist/locales/sv.cjs.js +1 -1
- package/dist/locales/sv.mjs +4 -0
- package/dist/locales/th.cjs.js +1 -1
- package/dist/locales/th.mjs +4 -0
- package/dist/locales/tr.cjs.js +1 -1
- package/dist/locales/tr.mjs +4 -0
- package/dist/locales/uk.cjs.js +1 -1
- package/dist/locales/uk.mjs +4 -0
- package/dist/locales/ur.cjs.js +1 -1
- package/dist/locales/ur.mjs +4 -0
- package/dist/locales/vi.cjs.js +1 -1
- package/dist/locales/vi.mjs +4 -0
- package/dist/locales/zh-Hans.cjs.js +1 -1
- package/dist/locales/zh-Hans.mjs +4 -0
- package/dist/locales/zh-Hant.cjs.js +1 -1
- package/dist/locales/zh-Hant.mjs +4 -0
- package/dist/tailwind.css +243 -0
- package/dist/vjdesigns-ui.css +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -379,6 +379,45 @@ brandCss("acme", "#e11d48"); // '[data-brand="acme"] { --brand-light-primary:
|
|
|
379
379
|
|
|
380
380
|
Add the rule to your stylesheet and use `<html data-brand="acme">`. `createBrandPalette(color)` returns the generated colors as an object, if you need them directly.
|
|
381
381
|
|
|
382
|
+
### Tailwind CSS
|
|
383
|
+
|
|
384
|
+
A Tailwind CSS v4 preset turns the design tokens into utilities, so your own layouts match the components. Import it after Tailwind in your CSS, and keep importing the library's stylesheet as usual:
|
|
385
|
+
|
|
386
|
+
```css
|
|
387
|
+
@import "tailwindcss";
|
|
388
|
+
@import "@vjdesigns/vjdesigns-ui/tailwind.css";
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
```tsx
|
|
392
|
+
<section className="bg-surface text-text rounded-xl shadow-md p-6">
|
|
393
|
+
<h2 className="font-display text-2xl tracking-tight">Season stats</h2>
|
|
394
|
+
<p className="text-text-muted">Updated after every game.</p>
|
|
395
|
+
<span className="bg-accent text-on-accent rounded-control px-3">New</span>
|
|
396
|
+
</section>
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
Every utility points at a token (`bg-primary` is `var(--color-primary)`), so Tailwind classes follow `Theme`, `data-theme`, `data-brand`, and `data-accent` exactly like the components, with no `dark:` variants needed.
|
|
400
|
+
|
|
401
|
+
| Group | Utilities |
|
|
402
|
+
| --- | --- |
|
|
403
|
+
| Colors | `bg-`, `text-`, `border-`, `ring-`, … with `bg`, `surface` (`-raised`, `-sunken`, `-hover`, `-active`), `overlay`, `text` (`-muted`, `-disabled`, `-inverse`), `border` (`-strong`, `-input`), `focus-ring`, `link-visited`; and for `primary`, `accent`, `success`, `warning`, `danger`, `info`, `neutral`: the solid color, `-hover`, `-active`, `on-…` (text on the solid), `-subtle`, `-subtle-hover`, `-subtle-text`, `-border`. Opacity modifiers work (`bg-primary/50`). |
|
|
404
|
+
| Charts | `bg-chart-1` to `bg-chart-8`, for fills only, in that order. Slots 3 to 5 are under 3:1 on white, so pair them with a legend, labels, or a data table. |
|
|
405
|
+
| Type | `font-display` (headings, buttons, labels, numbers), `font-body`, `font-mono`; `text-xs` to `text-6xl` (plus `text-md`); `font-regular` to `font-black`; `leading-tight`, `-snug`, `-normal`, `-relaxed`; `tracking-tight`, `-normal`, `-wide`, `-caps` |
|
|
406
|
+
| Shape | `rounded-control` (pill controls), `rounded-field` (text fields), `rounded-xs` to `rounded-2xl`, `rounded-pill` |
|
|
407
|
+
| Depth | `shadow-xs` to `shadow-xl`, `blur-sm`, `blur-lg` |
|
|
408
|
+
| Motion | `ease-spring` (enter and press), `ease-standard`, `ease-in`, `ease-out`; `duration-instant`, `-fast`, `-normal`, `-slow` (0ms under reduced motion) |
|
|
409
|
+
| Sizes | `h-control-sm`, `-md`, `-lg` (and `w-`, `min-h-`, …), `size-target` (the 24px minimum pointer target), `max-w-xs` to `max-w-2xl` and `@xs:` to `@2xl:` container queries |
|
|
410
|
+
| Layers | `z-sticky`, `z-overlay`, `z-modal`, `z-popover`, `z-dropdown`, `z-toast`, `z-tooltip` |
|
|
411
|
+
| Dark mode | `dark:` follows `data-theme="dark"`, not the OS setting. |
|
|
412
|
+
|
|
413
|
+
Tailwind's numeric spacing (`p-4` = 1rem) already matches the 4px token scale, and the breakpoints (`sm:` to `2xl:`) are the same as Tailwind's.
|
|
414
|
+
|
|
415
|
+
Some Tailwind names change meaning with the preset: `rounded-*`, `shadow-*`, `blur-sm`/`-lg`, `ease-in`/`-out`, `font-mono`, `font-medium` to `font-black`, `leading-*`, and the `text-*` sizes take the library's values (for example, `rounded-md` is 12px and `font-black` is 800). So do the containers: `max-w-md` and `@md:` are 48rem, not Tailwind's 28rem. The library's stylesheet already gives some of these names its own values once it's loaded, even without the preset; the preset keeps the utilities and the container queries consistent.
|
|
416
|
+
|
|
417
|
+
For text contrast, use the pairs the components use: `text-text` or `text-text-muted` on `bg-bg`, `bg-surface`, and the other surfaces; `text-on-primary` on `bg-primary` (likewise `on-accent`, `on-success`, …); `text-primary-subtle-text` on `bg-primary-subtle` (likewise for each tone). These pairs meet WCAG 2.2 AA in both themes and every brand. Don't use accent or chart colors for text.
|
|
418
|
+
|
|
419
|
+
The preset doesn't change the components, and Tailwind's preflight (its CSS reset) doesn't override them, whichever stylesheet loads first.
|
|
420
|
+
|
|
382
421
|
---
|
|
383
422
|
|
|
384
423
|
## Languages
|
|
@@ -718,7 +757,7 @@ To manage several options as one `string[]` value, use `CheckBoxGroup`:
|
|
|
718
757
|
|
|
719
758
|
## Pro
|
|
720
759
|
|
|
721
|
-
Everything above is free. `@vjdesigns/
|
|
760
|
+
Everything above is free. `@vjdesigns-pro/ui` is a commercial add-on for teams that need more from their data grids:
|
|
722
761
|
|
|
723
762
|
- **DataGridPro:** everything `DataGrid` does, plus resizable columns (pointer and keyboard), saved column layouts, and columns pinned to either edge.
|
|
724
763
|
- **CSV export:** export exactly what a grid shows, safe to open in a spreadsheet.
|
package/dist/ai/llms-full.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @vjdesigns/vjdesigns-ui 3.
|
|
1
|
+
# @vjdesigns/vjdesigns-ui 3.1.0: full reference
|
|
2
2
|
|
|
3
3
|
> Accessible React 19 component library: WCAG 2.2 AA verified (axe on every story, a contrast check on every color pair), 31 languages with right-to-left support, themeable with any brand color (auto-adjusted to stay accessible), tree-shakable, no runtime dependencies besides React.
|
|
4
4
|
|
|
@@ -378,6 +378,45 @@ brandCss("acme", "#e11d48"); // '[data-brand="acme"] { --brand-light-primary:
|
|
|
378
378
|
|
|
379
379
|
Add the rule to your stylesheet and use `<html data-brand="acme">`. `createBrandPalette(color)` returns the generated colors as an object, if you need them directly.
|
|
380
380
|
|
|
381
|
+
### Tailwind CSS
|
|
382
|
+
|
|
383
|
+
A Tailwind CSS v4 preset turns the design tokens into utilities, so your own layouts match the components. Import it after Tailwind in your CSS, and keep importing the library's stylesheet as usual:
|
|
384
|
+
|
|
385
|
+
```css
|
|
386
|
+
@import "tailwindcss";
|
|
387
|
+
@import "@vjdesigns/vjdesigns-ui/tailwind.css";
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
```tsx
|
|
391
|
+
<section className="bg-surface text-text rounded-xl shadow-md p-6">
|
|
392
|
+
<h2 className="font-display text-2xl tracking-tight">Season stats</h2>
|
|
393
|
+
<p className="text-text-muted">Updated after every game.</p>
|
|
394
|
+
<span className="bg-accent text-on-accent rounded-control px-3">New</span>
|
|
395
|
+
</section>
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
Every utility points at a token (`bg-primary` is `var(--color-primary)`), so Tailwind classes follow `Theme`, `data-theme`, `data-brand`, and `data-accent` exactly like the components, with no `dark:` variants needed.
|
|
399
|
+
|
|
400
|
+
| Group | Utilities |
|
|
401
|
+
| --- | --- |
|
|
402
|
+
| Colors | `bg-`, `text-`, `border-`, `ring-`, … with `bg`, `surface` (`-raised`, `-sunken`, `-hover`, `-active`), `overlay`, `text` (`-muted`, `-disabled`, `-inverse`), `border` (`-strong`, `-input`), `focus-ring`, `link-visited`; and for `primary`, `accent`, `success`, `warning`, `danger`, `info`, `neutral`: the solid color, `-hover`, `-active`, `on-…` (text on the solid), `-subtle`, `-subtle-hover`, `-subtle-text`, `-border`. Opacity modifiers work (`bg-primary/50`). |
|
|
403
|
+
| Charts | `bg-chart-1` to `bg-chart-8`, for fills only, in that order. Slots 3 to 5 are under 3:1 on white, so pair them with a legend, labels, or a data table. |
|
|
404
|
+
| Type | `font-display` (headings, buttons, labels, numbers), `font-body`, `font-mono`; `text-xs` to `text-6xl` (plus `text-md`); `font-regular` to `font-black`; `leading-tight`, `-snug`, `-normal`, `-relaxed`; `tracking-tight`, `-normal`, `-wide`, `-caps` |
|
|
405
|
+
| Shape | `rounded-control` (pill controls), `rounded-field` (text fields), `rounded-xs` to `rounded-2xl`, `rounded-pill` |
|
|
406
|
+
| Depth | `shadow-xs` to `shadow-xl`, `blur-sm`, `blur-lg` |
|
|
407
|
+
| Motion | `ease-spring` (enter and press), `ease-standard`, `ease-in`, `ease-out`; `duration-instant`, `-fast`, `-normal`, `-slow` (0ms under reduced motion) |
|
|
408
|
+
| Sizes | `h-control-sm`, `-md`, `-lg` (and `w-`, `min-h-`, …), `size-target` (the 24px minimum pointer target), `max-w-xs` to `max-w-2xl` and `@xs:` to `@2xl:` container queries |
|
|
409
|
+
| Layers | `z-sticky`, `z-overlay`, `z-modal`, `z-popover`, `z-dropdown`, `z-toast`, `z-tooltip` |
|
|
410
|
+
| Dark mode | `dark:` follows `data-theme="dark"`, not the OS setting. |
|
|
411
|
+
|
|
412
|
+
Tailwind's numeric spacing (`p-4` = 1rem) already matches the 4px token scale, and the breakpoints (`sm:` to `2xl:`) are the same as Tailwind's.
|
|
413
|
+
|
|
414
|
+
Some Tailwind names change meaning with the preset: `rounded-*`, `shadow-*`, `blur-sm`/`-lg`, `ease-in`/`-out`, `font-mono`, `font-medium` to `font-black`, `leading-*`, and the `text-*` sizes take the library's values (for example, `rounded-md` is 12px and `font-black` is 800). So do the containers: `max-w-md` and `@md:` are 48rem, not Tailwind's 28rem. The library's stylesheet already gives some of these names its own values once it's loaded, even without the preset; the preset keeps the utilities and the container queries consistent.
|
|
415
|
+
|
|
416
|
+
For text contrast, use the pairs the components use: `text-text` or `text-text-muted` on `bg-bg`, `bg-surface`, and the other surfaces; `text-on-primary` on `bg-primary` (likewise `on-accent`, `on-success`, …); `text-primary-subtle-text` on `bg-primary-subtle` (likewise for each tone). These pairs meet WCAG 2.2 AA in both themes and every brand. Don't use accent or chart colors for text.
|
|
417
|
+
|
|
418
|
+
The preset doesn't change the components, and Tailwind's preflight (its CSS reset) doesn't override them, whichever stylesheet loads first.
|
|
419
|
+
|
|
381
420
|
# Guide: Languages
|
|
382
421
|
|
|
383
422
|
Components have built-in text: button names like "Close" and "Next page", screen-reader announcements like "3 results available", validation messages, and date formats. Wrap your app in `LocaleProvider` to show all of it in another language:
|
|
@@ -1219,6 +1258,57 @@ users can scroll it. Copy results are announced in a polite live region.
|
|
|
1219
1258
|
- Custom highlighter
|
|
1220
1259
|
- Both themes
|
|
1221
1260
|
|
|
1261
|
+
## Countdown
|
|
1262
|
+
|
|
1263
|
+
import { Countdown } from "@vjdesigns/vjdesigns-ui";
|
|
1264
|
+
|
|
1265
|
+
Category: data-display · Storybook: Data Display/Countdown
|
|
1266
|
+
|
|
1267
|
+
A live countdown to a moment: the end of a sale, the start of an event,
|
|
1268
|
+
tip-off. Updates every second (or every minute without seconds), shows
|
|
1269
|
+
the time in tiles or inline text, and calls `onComplete` at zero.
|
|
1270
|
+
|
|
1271
|
+
Semantics: `role="timer"`, named by `aria-label` (default "Time remaining")
|
|
1272
|
+
or `aria-labelledby`. Screen readers read the whole time as one phrase
|
|
1273
|
+
("4 hours, 12 minutes, 9 seconds") when they reach it, without being
|
|
1274
|
+
interrupted every second; reaching zero is announced once. Numbers and unit
|
|
1275
|
+
names are formatted for the current locale. Rendered on the server, the
|
|
1276
|
+
digits show as "--" until hydration, so the markup always matches.
|
|
1277
|
+
|
|
1278
|
+
### Props
|
|
1279
|
+
|
|
1280
|
+
- `to`: `string | number` (required). When the countdown ends: an ISO 8601 date-time, or milliseconds since the epoch. Include the offset (`"2026-12-01T09:00:00-05:00"` or a trailing `Z`) so everyone counts down to the same moment; a date-time without one is read in each viewer's own time zone.
|
|
1281
|
+
- `units`: `CountdownUnit[]` (default ["days", "hours", "minutes", "seconds"]). Units to show, largest first whatever the order given. The largest takes everything above it (`["hours", "minutes"]` shows 2 days as 48 hours), and the time is rounded up to the smallest, so the count reaches 0 exactly at `to`.
|
|
1282
|
+
- `layout`: `CountdownLayout` (default "tiles"). Tiles (a box per unit) or one line of text.
|
|
1283
|
+
- `align`: `CountdownAlign` (default "start"). Where the tiles sit. The `tiles` layout fills its container's width (and wraps to two columns when that's too narrow for one row); `inline` ignores it.
|
|
1284
|
+
- `variant`: `CountdownVariant` (default "solid"). Tile style, for the `tiles` layout. `inline` takes the surrounding text color.
|
|
1285
|
+
- `tone`: `Tone` (default "neutral"). Tile color, for the `solid`, `soft`, and `outline` variants.
|
|
1286
|
+
- `size`: `Size` (default "md"). Type and tile size.
|
|
1287
|
+
- `completedContent`: `ReactNode`. Shown in place of the timer once it reaches zero, e.g. "This sale has ended". Without it, the timer stays on screen at zero.
|
|
1288
|
+
- `completedLabel`: `string` (default "Time's up"). Announced to screen readers when the countdown reaches zero while on screen. Match it to `completedContent` when you set one.
|
|
1289
|
+
- `onComplete`: `() => void`. Called once when the countdown reaches zero, including when `to` has already passed when it first renders (after hydration). Called again only if `to` changes.
|
|
1290
|
+
- `aria-label`: `string` (default "Time remaining"). The timer's accessible name, e.g. `"Sale ends in"`. Use it (or `aria-labelledby` pointing at a visible heading) to say what the time is for.
|
|
1291
|
+
- Plus every native `<div>` attribute (className, style, id, aria-*, data-*, event handlers), spread onto the root.
|
|
1292
|
+
|
|
1293
|
+
### Examples (Storybook stories)
|
|
1294
|
+
|
|
1295
|
+
- Playground: Counting down to 2 days, 4 hours, and 30 minutes from when the story opens.
|
|
1296
|
+
- All Variants: Every tile style side by side. `plain` has no box; `outline` sits on the surface.
|
|
1297
|
+
- All Tones: Every tone, as solid and soft tiles. The default, neutral solid, is a dark scoreboard look.
|
|
1298
|
+
- All Sizes: Small, medium, and large.
|
|
1299
|
+
- Inline: One line of text in the surrounding color, for a sentence, a Banner, or a Button.
|
|
1300
|
+
- Units: Pick the units. The largest takes everything above it, so 2 days show as 50 hours here, and the time rounds up to the smallest unit.
|
|
1301
|
+
- Reaches Zero: A countdown that ends while you watch: `onComplete` runs, the end content replaces it, and screen readers hear it.
|
|
1302
|
+
- Already Ended: An end time that has already passed: the end content shows right away, and `onComplete` still runs once.
|
|
1303
|
+
- Stopped At Zero: Without `completedContent`, the timer stays on screen at zero.
|
|
1304
|
+
- Alignment: The tiles fill their container's width; `align` places them in it.
|
|
1305
|
+
- Narrow: In a container too narrow for one row (a phone, a sidebar card), the tiles wrap to two columns instead of squeezing. With three tiles, the last spans both.
|
|
1306
|
+
- Long Wait: A long way off: the days tile grows to fit three digits.
|
|
1307
|
+
- Localized: Unit names, numbers, and list wording follow the locale, and the tiles mirror in right-to-left languages.
|
|
1308
|
+
- Sale Card: A sale card: the timer is named by the visible heading through `aria-labelledby`.
|
|
1309
|
+
- Event Hero: An event page hero: large plain numbers.
|
|
1310
|
+
- In Banner: Inline in a Banner, for a site-wide announcement.
|
|
1311
|
+
|
|
1222
1312
|
## DataGrid
|
|
1223
1313
|
|
|
1224
1314
|
import { DataGrid } from "@vjdesigns/vjdesigns-ui";
|
package/dist/ai/llms.txt
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
- [ChipGroup](llms-full.txt#chipgroup): Lays out chips with a gap and wraps them.
|
|
31
31
|
- [Code](llms-full.txt#code): Inline code inside running text, e.g. a prop name or a command.
|
|
32
32
|
- [CodeBlock](llms-full.txt#codeblock): A block of source code with a header (language and filename), a copy button, optional line numbers, highlighted lines, and diff gutters.
|
|
33
|
+
- [Countdown](llms-full.txt#countdown): A live countdown to a moment: the end of a sale, the start of an event, tip-off.
|
|
33
34
|
- [DataGrid](llms-full.txt#datagrid): An interactive data table (WAI-ARIA APG "Data Grid"): sortable columns (with Shift for multi-column sorts), search filtering, single or multiple row selection, pagination, and a full keyboard model.
|
|
34
35
|
- [EmptyState](llms-full.txt#emptystate): A friendly, centered block for "no data", "no results", "error", and first-run moments.
|
|
35
36
|
- [Image](llms-full.txt#image): A native `<img>` in a frame that reserves its aspect ratio, shows a placeholder while loading, fades the picture in, and falls back gracefully on errors (`fallbackSrc`, then a `fallback` box that keeps the `alt` text as its accessible name).
|
package/dist/ai/registry.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vjdesigns/vjdesigns-ui",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"summary": "Accessible React 19 component library: WCAG 2.2 AA verified (axe on every story, a contrast check on every color pair), 31 languages with right-to-left support, themeable with any brand color (auto-adjusted to stay accessible), tree-shakable, no runtime dependencies besides React.",
|
|
5
5
|
"install": "npm install @vjdesigns/vjdesigns-ui",
|
|
6
6
|
"stylesheet": "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
{
|
|
28
28
|
"id": "theming",
|
|
29
29
|
"title": "Theming",
|
|
30
|
-
"markdown": "Wrap any part of your app in `Theme` to set the color mode, brand palette, and accent for everything inside it:\n\n```tsx\nimport { Theme, Button } from \"@vjdesigns/vjdesigns-ui\";\n\n<Theme mode=\"dark\" brand=\"purple\" fill>\n <Button>Dark, purple button</Button>\n</Theme>\n```\n\n| Prop | Type | Default | Description |\n| --- | --- | --- | --- |\n| `mode` | `\"light\" \\| \"dark\"` | inherited | Color mode for everything inside. |\n| `brand` | `\"black\" \\| \"blue\" \\| \"gold\" \\| \"green\" \\| \"purple\"`, a hex color, or `{ light, dark }` | inherited | Brand palette for buttons, links, focus rings and indicators. |\n| `accent` | `\"brand\" | \"lime\"`, a hex color, or `{ light, dark }` | inherited (the brand's own) | The bright highlight on badges, switches, progress bars, sliders, steppers, and active navigation. |\n| `fill` | `boolean` | `false` | Paints the theme's background and text color on the wrapper. |\n\nOutside React (or to theme the whole page), set the attributes on `<html>` instead:\n\n```html\n<html data-theme=\"dark\" data-brand=\"purple\" data-accent=\"lime\">\n```\n\n### Accent color\n\nThe accent is the energetic highlight: badges, switches, progress bars, sliders, steppers, and the active link in the Navbar. By default it follows the brand, as a bright shade of the brand's own color, so it always fits:\n\n| Brand | Default accent |\n| --- | --- |\n| `blue` (default) | sky blue `#76c7ff` |\n| `purple` | lavender `#c0b0ff` |\n| `gold` | amber `#f5ad5f` |\n| `green` | mint `#72d4ad` |\n| `black` | lime `#c8f031` (black has no hue to build on) |\n| a custom hex | generated from that color |\n\nTo choose a different one:\n\n```tsx\n<Theme accent=\"lime\">…</Theme> // the original bright yellow-green (\"volt\", its former name, still works)\n<Theme accent=\"#ff6b00\">…</Theme> // any color\n<Theme accent=\"brand\">…</Theme> // back to the brand's own, inside an area with another accent\n```\n\nAccents always carry dark text. A color too dark for that is lightened (same hue) just enough to meet WCAG AA, with a warning in development. An accent you set also holds inside nested brands. In CSS, `accentCss(\"name\", \"#ff6b00\")` generates a `[data-accent=\"name\"]` rule, like `brandCss` below.\n\n### Custom brand colors\n\nPass any hex color as `brand` and a full palette is generated for both modes:\n\n```tsx\n<Theme brand=\"#e11d48\">…</Theme>\n<Theme brand={{ light: \"#4338ca\", dark: \"#f472b6\" }}>…</Theme>\n```\n\nEvery generated palette meets WCAG 2.2 AA. A single color is used exactly as given in the mode where it has enough contrast (dark colors in light mode, light colors in dark mode), and the other mode gets a matching shade of the same hue. If a color doesn't have enough contrast (for example, a mid-tone that fails in both modes), its lightness is shifted just enough to pass, and a warning is logged in development.\n\nTo define a brand in CSS instead (for the whole page, applied before any JavaScript runs), generate a stylesheet rule with `brandCss`:\n\n```ts\nimport { brandCss } from \"@vjdesigns/vjdesigns-ui\";\n\nbrandCss(\"acme\", \"#e11d48\"); // '[data-brand=\"acme\"] { --brand-light-primary: … }'\n```\n\nAdd the rule to your stylesheet and use `<html data-brand=\"acme\">`. `createBrandPalette(color)` returns the generated colors as an object, if you need them directly."
|
|
30
|
+
"markdown": "Wrap any part of your app in `Theme` to set the color mode, brand palette, and accent for everything inside it:\n\n```tsx\nimport { Theme, Button } from \"@vjdesigns/vjdesigns-ui\";\n\n<Theme mode=\"dark\" brand=\"purple\" fill>\n <Button>Dark, purple button</Button>\n</Theme>\n```\n\n| Prop | Type | Default | Description |\n| --- | --- | --- | --- |\n| `mode` | `\"light\" \\| \"dark\"` | inherited | Color mode for everything inside. |\n| `brand` | `\"black\" \\| \"blue\" \\| \"gold\" \\| \"green\" \\| \"purple\"`, a hex color, or `{ light, dark }` | inherited | Brand palette for buttons, links, focus rings and indicators. |\n| `accent` | `\"brand\" | \"lime\"`, a hex color, or `{ light, dark }` | inherited (the brand's own) | The bright highlight on badges, switches, progress bars, sliders, steppers, and active navigation. |\n| `fill` | `boolean` | `false` | Paints the theme's background and text color on the wrapper. |\n\nOutside React (or to theme the whole page), set the attributes on `<html>` instead:\n\n```html\n<html data-theme=\"dark\" data-brand=\"purple\" data-accent=\"lime\">\n```\n\n### Accent color\n\nThe accent is the energetic highlight: badges, switches, progress bars, sliders, steppers, and the active link in the Navbar. By default it follows the brand, as a bright shade of the brand's own color, so it always fits:\n\n| Brand | Default accent |\n| --- | --- |\n| `blue` (default) | sky blue `#76c7ff` |\n| `purple` | lavender `#c0b0ff` |\n| `gold` | amber `#f5ad5f` |\n| `green` | mint `#72d4ad` |\n| `black` | lime `#c8f031` (black has no hue to build on) |\n| a custom hex | generated from that color |\n\nTo choose a different one:\n\n```tsx\n<Theme accent=\"lime\">…</Theme> // the original bright yellow-green (\"volt\", its former name, still works)\n<Theme accent=\"#ff6b00\">…</Theme> // any color\n<Theme accent=\"brand\">…</Theme> // back to the brand's own, inside an area with another accent\n```\n\nAccents always carry dark text. A color too dark for that is lightened (same hue) just enough to meet WCAG AA, with a warning in development. An accent you set also holds inside nested brands. In CSS, `accentCss(\"name\", \"#ff6b00\")` generates a `[data-accent=\"name\"]` rule, like `brandCss` below.\n\n### Custom brand colors\n\nPass any hex color as `brand` and a full palette is generated for both modes:\n\n```tsx\n<Theme brand=\"#e11d48\">…</Theme>\n<Theme brand={{ light: \"#4338ca\", dark: \"#f472b6\" }}>…</Theme>\n```\n\nEvery generated palette meets WCAG 2.2 AA. A single color is used exactly as given in the mode where it has enough contrast (dark colors in light mode, light colors in dark mode), and the other mode gets a matching shade of the same hue. If a color doesn't have enough contrast (for example, a mid-tone that fails in both modes), its lightness is shifted just enough to pass, and a warning is logged in development.\n\nTo define a brand in CSS instead (for the whole page, applied before any JavaScript runs), generate a stylesheet rule with `brandCss`:\n\n```ts\nimport { brandCss } from \"@vjdesigns/vjdesigns-ui\";\n\nbrandCss(\"acme\", \"#e11d48\"); // '[data-brand=\"acme\"] { --brand-light-primary: … }'\n```\n\nAdd the rule to your stylesheet and use `<html data-brand=\"acme\">`. `createBrandPalette(color)` returns the generated colors as an object, if you need them directly.\n\n### Tailwind CSS\n\nA Tailwind CSS v4 preset turns the design tokens into utilities, so your own layouts match the components. Import it after Tailwind in your CSS, and keep importing the library's stylesheet as usual:\n\n```css\n@import \"tailwindcss\";\n@import \"@vjdesigns/vjdesigns-ui/tailwind.css\";\n```\n\n```tsx\n<section className=\"bg-surface text-text rounded-xl shadow-md p-6\">\n <h2 className=\"font-display text-2xl tracking-tight\">Season stats</h2>\n <p className=\"text-text-muted\">Updated after every game.</p>\n <span className=\"bg-accent text-on-accent rounded-control px-3\">New</span>\n</section>\n```\n\nEvery utility points at a token (`bg-primary` is `var(--color-primary)`), so Tailwind classes follow `Theme`, `data-theme`, `data-brand`, and `data-accent` exactly like the components, with no `dark:` variants needed.\n\n| Group | Utilities |\n| --- | --- |\n| Colors | `bg-`, `text-`, `border-`, `ring-`, … with `bg`, `surface` (`-raised`, `-sunken`, `-hover`, `-active`), `overlay`, `text` (`-muted`, `-disabled`, `-inverse`), `border` (`-strong`, `-input`), `focus-ring`, `link-visited`; and for `primary`, `accent`, `success`, `warning`, `danger`, `info`, `neutral`: the solid color, `-hover`, `-active`, `on-…` (text on the solid), `-subtle`, `-subtle-hover`, `-subtle-text`, `-border`. Opacity modifiers work (`bg-primary/50`). |\n| Charts | `bg-chart-1` to `bg-chart-8`, for fills only, in that order. Slots 3 to 5 are under 3:1 on white, so pair them with a legend, labels, or a data table. |\n| Type | `font-display` (headings, buttons, labels, numbers), `font-body`, `font-mono`; `text-xs` to `text-6xl` (plus `text-md`); `font-regular` to `font-black`; `leading-tight`, `-snug`, `-normal`, `-relaxed`; `tracking-tight`, `-normal`, `-wide`, `-caps` |\n| Shape | `rounded-control` (pill controls), `rounded-field` (text fields), `rounded-xs` to `rounded-2xl`, `rounded-pill` |\n| Depth | `shadow-xs` to `shadow-xl`, `blur-sm`, `blur-lg` |\n| Motion | `ease-spring` (enter and press), `ease-standard`, `ease-in`, `ease-out`; `duration-instant`, `-fast`, `-normal`, `-slow` (0ms under reduced motion) |\n| Sizes | `h-control-sm`, `-md`, `-lg` (and `w-`, `min-h-`, …), `size-target` (the 24px minimum pointer target), `max-w-xs` to `max-w-2xl` and `@xs:` to `@2xl:` container queries |\n| Layers | `z-sticky`, `z-overlay`, `z-modal`, `z-popover`, `z-dropdown`, `z-toast`, `z-tooltip` |\n| Dark mode | `dark:` follows `data-theme=\"dark\"`, not the OS setting. |\n\nTailwind's numeric spacing (`p-4` = 1rem) already matches the 4px token scale, and the breakpoints (`sm:` to `2xl:`) are the same as Tailwind's.\n\nSome Tailwind names change meaning with the preset: `rounded-*`, `shadow-*`, `blur-sm`/`-lg`, `ease-in`/`-out`, `font-mono`, `font-medium` to `font-black`, `leading-*`, and the `text-*` sizes take the library's values (for example, `rounded-md` is 12px and `font-black` is 800). So do the containers: `max-w-md` and `@md:` are 48rem, not Tailwind's 28rem. The library's stylesheet already gives some of these names its own values once it's loaded, even without the preset; the preset keeps the utilities and the container queries consistent.\n\nFor text contrast, use the pairs the components use: `text-text` or `text-text-muted` on `bg-bg`, `bg-surface`, and the other surfaces; `text-on-primary` on `bg-primary` (likewise `on-accent`, `on-success`, …); `text-primary-subtle-text` on `bg-primary-subtle` (likewise for each tone). These pairs meet WCAG 2.2 AA in both themes and every brand. Don't use accent or chart colors for text.\n\nThe preset doesn't change the components, and Tailwind's preflight (its CSS reset) doesn't override them, whichever stylesheet loads first."
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
33
|
"id": "languages",
|
|
@@ -2059,6 +2059,158 @@
|
|
|
2059
2059
|
}
|
|
2060
2060
|
]
|
|
2061
2061
|
},
|
|
2062
|
+
{
|
|
2063
|
+
"name": "Countdown",
|
|
2064
|
+
"category": "data-display",
|
|
2065
|
+
"folder": "Countdown",
|
|
2066
|
+
"import": "import { Countdown } from \"@vjdesigns/vjdesigns-ui\";",
|
|
2067
|
+
"description": "A live countdown to a moment: the end of a sale, the start of an event,\ntip-off. Updates every second (or every minute without seconds), shows\nthe time in tiles or inline text, and calls `onComplete` at zero.\n\nSemantics: `role=\"timer\"`, named by `aria-label` (default \"Time remaining\")\nor `aria-labelledby`. Screen readers read the whole time as one phrase\n(\"4 hours, 12 minutes, 9 seconds\") when they reach it, without being\ninterrupted every second; reaching zero is announced once. Numbers and unit\nnames are formatted for the current locale. Rendered on the server, the\ndigits show as \"--\" until hydration, so the markup always matches.",
|
|
2068
|
+
"nativeElement": "div",
|
|
2069
|
+
"props": [
|
|
2070
|
+
{
|
|
2071
|
+
"name": "to",
|
|
2072
|
+
"type": "string | number",
|
|
2073
|
+
"required": true,
|
|
2074
|
+
"description": "When the countdown ends: an ISO 8601 date-time, or milliseconds since the\nepoch. Include the offset (`\"2026-12-01T09:00:00-05:00\"` or a trailing\n`Z`) so everyone counts down to the same moment; a date-time without one\nis read in each viewer's own time zone."
|
|
2075
|
+
},
|
|
2076
|
+
{
|
|
2077
|
+
"name": "units",
|
|
2078
|
+
"type": "CountdownUnit[]",
|
|
2079
|
+
"required": false,
|
|
2080
|
+
"default": "[\"days\", \"hours\", \"minutes\", \"seconds\"]",
|
|
2081
|
+
"description": "Units to show, largest first whatever the order given. The largest takes\neverything above it (`[\"hours\", \"minutes\"]` shows 2 days as 48 hours),\nand the time is rounded up to the smallest, so the count reaches 0 exactly\nat `to`."
|
|
2082
|
+
},
|
|
2083
|
+
{
|
|
2084
|
+
"name": "layout",
|
|
2085
|
+
"type": "CountdownLayout",
|
|
2086
|
+
"required": false,
|
|
2087
|
+
"default": "\"tiles\"",
|
|
2088
|
+
"description": "Tiles (a box per unit) or one line of text."
|
|
2089
|
+
},
|
|
2090
|
+
{
|
|
2091
|
+
"name": "align",
|
|
2092
|
+
"type": "CountdownAlign",
|
|
2093
|
+
"required": false,
|
|
2094
|
+
"default": "\"start\"",
|
|
2095
|
+
"description": "Where the tiles sit. The `tiles` layout fills its container's width (and\nwraps to two columns when that's too narrow for one row); `inline` ignores it."
|
|
2096
|
+
},
|
|
2097
|
+
{
|
|
2098
|
+
"name": "variant",
|
|
2099
|
+
"type": "CountdownVariant",
|
|
2100
|
+
"required": false,
|
|
2101
|
+
"default": "\"solid\"",
|
|
2102
|
+
"description": "Tile style, for the `tiles` layout. `inline` takes the surrounding text color."
|
|
2103
|
+
},
|
|
2104
|
+
{
|
|
2105
|
+
"name": "tone",
|
|
2106
|
+
"type": "Tone",
|
|
2107
|
+
"required": false,
|
|
2108
|
+
"default": "\"neutral\"",
|
|
2109
|
+
"description": "Tile color, for the `solid`, `soft`, and `outline` variants."
|
|
2110
|
+
},
|
|
2111
|
+
{
|
|
2112
|
+
"name": "size",
|
|
2113
|
+
"type": "Size",
|
|
2114
|
+
"required": false,
|
|
2115
|
+
"default": "\"md\"",
|
|
2116
|
+
"description": "Type and tile size."
|
|
2117
|
+
},
|
|
2118
|
+
{
|
|
2119
|
+
"name": "completedContent",
|
|
2120
|
+
"type": "ReactNode",
|
|
2121
|
+
"required": false,
|
|
2122
|
+
"description": "Shown in place of the timer once it reaches zero, e.g. \"This sale has\nended\". Without it, the timer stays on screen at zero."
|
|
2123
|
+
},
|
|
2124
|
+
{
|
|
2125
|
+
"name": "completedLabel",
|
|
2126
|
+
"type": "string",
|
|
2127
|
+
"required": false,
|
|
2128
|
+
"default": "\"Time's up\"",
|
|
2129
|
+
"description": "Announced to screen readers when the countdown reaches zero while on\nscreen. Match it to `completedContent` when you set one."
|
|
2130
|
+
},
|
|
2131
|
+
{
|
|
2132
|
+
"name": "onComplete",
|
|
2133
|
+
"type": "() => void",
|
|
2134
|
+
"required": false,
|
|
2135
|
+
"description": "Called once when the countdown reaches zero, including when `to` has\nalready passed when it first renders (after hydration). Called again only\nif `to` changes."
|
|
2136
|
+
},
|
|
2137
|
+
{
|
|
2138
|
+
"name": "aria-label",
|
|
2139
|
+
"type": "string",
|
|
2140
|
+
"required": false,
|
|
2141
|
+
"default": "\"Time remaining\"",
|
|
2142
|
+
"description": "The timer's accessible name, e.g. `\"Sale ends in\"`. Use it (or\n`aria-labelledby` pointing at a visible heading) to say what the time is for."
|
|
2143
|
+
}
|
|
2144
|
+
],
|
|
2145
|
+
"subcomponents": [],
|
|
2146
|
+
"storybook": "Data Display/Countdown",
|
|
2147
|
+
"stories": [
|
|
2148
|
+
{
|
|
2149
|
+
"name": "Playground",
|
|
2150
|
+
"description": "Counting down to 2 days, 4 hours, and 30 minutes from when the story opens."
|
|
2151
|
+
},
|
|
2152
|
+
{
|
|
2153
|
+
"name": "All Variants",
|
|
2154
|
+
"description": "Every tile style side by side. `plain` has no box; `outline` sits on the surface."
|
|
2155
|
+
},
|
|
2156
|
+
{
|
|
2157
|
+
"name": "All Tones",
|
|
2158
|
+
"description": "Every tone, as solid and soft tiles. The default, neutral solid, is a dark scoreboard look."
|
|
2159
|
+
},
|
|
2160
|
+
{
|
|
2161
|
+
"name": "All Sizes",
|
|
2162
|
+
"description": "Small, medium, and large."
|
|
2163
|
+
},
|
|
2164
|
+
{
|
|
2165
|
+
"name": "Inline",
|
|
2166
|
+
"description": "One line of text in the surrounding color, for a sentence, a Banner, or a Button."
|
|
2167
|
+
},
|
|
2168
|
+
{
|
|
2169
|
+
"name": "Units",
|
|
2170
|
+
"description": "Pick the units. The largest takes everything above it, so 2 days show as\n50 hours here, and the time rounds up to the smallest unit."
|
|
2171
|
+
},
|
|
2172
|
+
{
|
|
2173
|
+
"name": "Reaches Zero",
|
|
2174
|
+
"description": "A countdown that ends while you watch: `onComplete` runs, the end content replaces it, and screen readers hear it."
|
|
2175
|
+
},
|
|
2176
|
+
{
|
|
2177
|
+
"name": "Already Ended",
|
|
2178
|
+
"description": "An end time that has already passed: the end content shows right away, and `onComplete` still runs once."
|
|
2179
|
+
},
|
|
2180
|
+
{
|
|
2181
|
+
"name": "Stopped At Zero",
|
|
2182
|
+
"description": "Without `completedContent`, the timer stays on screen at zero."
|
|
2183
|
+
},
|
|
2184
|
+
{
|
|
2185
|
+
"name": "Alignment",
|
|
2186
|
+
"description": "The tiles fill their container's width; `align` places them in it."
|
|
2187
|
+
},
|
|
2188
|
+
{
|
|
2189
|
+
"name": "Narrow",
|
|
2190
|
+
"description": "In a container too narrow for one row (a phone, a sidebar card), the tiles\nwrap to two columns instead of squeezing. With three tiles, the last spans both."
|
|
2191
|
+
},
|
|
2192
|
+
{
|
|
2193
|
+
"name": "Long Wait",
|
|
2194
|
+
"description": "A long way off: the days tile grows to fit three digits."
|
|
2195
|
+
},
|
|
2196
|
+
{
|
|
2197
|
+
"name": "Localized",
|
|
2198
|
+
"description": "Unit names, numbers, and list wording follow the locale, and the tiles mirror in right-to-left languages."
|
|
2199
|
+
},
|
|
2200
|
+
{
|
|
2201
|
+
"name": "Sale Card",
|
|
2202
|
+
"description": "A sale card: the timer is named by the visible heading through `aria-labelledby`."
|
|
2203
|
+
},
|
|
2204
|
+
{
|
|
2205
|
+
"name": "Event Hero",
|
|
2206
|
+
"description": "An event page hero: large plain numbers."
|
|
2207
|
+
},
|
|
2208
|
+
{
|
|
2209
|
+
"name": "In Banner",
|
|
2210
|
+
"description": "Inline in a Banner, for a site-wide announcement."
|
|
2211
|
+
}
|
|
2212
|
+
]
|
|
2213
|
+
},
|
|
2062
2214
|
{
|
|
2063
2215
|
"name": "DataGrid",
|
|
2064
2216
|
"category": "data-display",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";const e=require("../../../hooks/useEnvironment.cjs.js"),t=require("../../../hooks/useTiming.cjs.js"),n=require("../../../utils/announce.cjs.js"),r=require("../../../utils/cx.cjs.js"),i=require("../../utilities/LocaleProvider/LocaleProvider.cjs.js"),a=require("../../utilities/VisuallyHidden/VisuallyHidden.cjs.js"),o=require("./Countdown.module.css.cjs.js");let s=require("react"),c=require("react/jsx-runtime");var l=[`days`,`hours`,`minutes`,`seconds`],u={days:86400,hours:3600,minutes:60,seconds:1},d={days:`day`,hours:`hour`,minutes:`minute`,seconds:`second`},ee={tiles:o.default.tilesLayout,inline:o.default.inlineLayout},f={solid:o.default.solid,soft:o.default.soft,outline:o.default.outline,plain:o.default.plain},p={neutral:o.default.toneNeutral,primary:o.default.tonePrimary,accent:o.default.toneAccent,success:o.default.toneSuccess,warning:o.default.toneWarning,danger:o.default.toneDanger,info:o.default.toneInfo},m={start:o.default.alignStart,center:o.default.alignCenter,end:o.default.alignEnd},h={sm:o.default.sm,md:o.default.md,lg:o.default.lg},te=globalThis.process?.env?.NODE_ENV!==`production`;function g(e){return typeof e==`number`?e:Date.parse(e)}function _(e,t=l){let n={days:0,hours:0,minutes:0,seconds:0},r=Math.max(0,Math.floor(e));for(let e of l)t.includes(e)&&(n[e]=Math.floor(r/u[e]),r-=n[e]*u[e]);return n}function v(e){let t=t=>new Intl.NumberFormat(e,{minimumIntegerDigits:t,useGrouping:!1}),n=(t,n)=>Object.fromEntries(l.map(r=>[r,new Intl.NumberFormat(e,{style:`unit`,unit:d[r],unitDisplay:t,minimumIntegerDigits:n,useGrouping:!1})]));return{padded:t(2),long:n(`long`,1),narrow:n(`narrow`,1),narrowPadded:n(`narrow`,2),longList:new Intl.ListFormat(e,{type:`unit`,style:`long`}),narrowList:new Intl.ListFormat(e,{type:`unit`,style:`narrow`})}}var y=({to:d,units:y,layout:b=`tiles`,align:x=`start`,variant:S=`solid`,tone:C=`neutral`,size:ne=`md`,completedContent:w,completedLabel:T,onComplete:E,className:D,"aria-label":O,"aria-labelledby":k,ref:A,...j})=>{let{messages:M,locale:N}=i.useLocale(),P=e.useHydrated(),F=g(d),I=Number.isFinite(F),L=(y?.length?y:l).join(),R=(0,s.useMemo)(()=>l.filter(e=>L.split(`,`).includes(e)),[L]),z=u[R[R.length-1]],B=e=>I?Math.max(0,Math.ceil((F-e)/1e3/z))*z:0,[V,H]=(0,s.useState)(()=>Date.now());(0,s.useEffect)(()=>H(Date.now()),[F]);let U=B(V),W=I&&U===0;t.useInterval(()=>{let e=Date.now();H(t=>B(t)===B(e)?t:e)},P&&I&&!W?z===1?250:1e3:null),(0,s.useEffect)(()=>{te&&!I&&console.warn(`[Countdown] Can't read the end time ${JSON.stringify(d)}. Pass an ISO 8601 date-time or milliseconds since the epoch.`)},[I,d]);let G=(0,s.useRef)(E);G.current=E;let K=(0,s.useRef)(!1),q=(0,s.useRef)(void 0),J=T??M.countdown.completed;(0,s.useEffect)(()=>{P&&I&&(W?q.current!==F&&(q.current=F,G.current?.(),K.current&&n.announce(J),K.current=!1):K.current=!0)},[P,I,W,F,J]);let Y=(0,s.useMemo)(()=>v(N),[N]);if(W&&w!==void 0)return(0,c.jsx)(`div`,{...j,ref:A,className:r.cx(o.default.root,o.default.completed,D),children:w});let X=P&&I,Z=_(U,R),re=(e,t)=>Y.long[e].formatToParts(t).filter(e=>e.type===`unit`).map(e=>e.value).join(``),Q=R.findIndex(e=>Z[e]>0),$=R.slice(Q===-1?R.length-1:Q),ie=X?Y.longList.format($.map(e=>Y.long[e].format(Z[e]))):``;return(0,c.jsxs)(`div`,{...j,ref:A,role:`timer`,"aria-label":k?O:O??M.countdown.label,"aria-labelledby":k,"data-complete":W||void 0,className:r.cx(o.default.root,ee[b],b===`tiles`&&m[x],f[S],p[C],h[ne],D),children:[b===`tiles`?(0,c.jsx)(`span`,{className:o.default.tiles,"data-count":R.length,"aria-hidden":`true`,children:R.map(e=>(0,c.jsxs)(`span`,{className:o.default.tile,children:[(0,c.jsx)(`span`,{className:o.default.value,children:X?Y.padded.format(Z[e]):`--`}),(0,c.jsx)(`span`,{className:o.default.unit,children:re(e,X?Z[e]:0)})]},e))}):(0,c.jsx)(`span`,{className:o.default.text,"aria-hidden":`true`,children:X?Y.narrowList.format($.map((e,t)=>(t===0?Y.narrow:Y.narrowPadded)[e].format(Z[e]))):`--`}),(0,c.jsx)(a.VisuallyHidden,{children:ie})]})};exports.Countdown=y,exports.getCountdownParts=_;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { ComponentPropsWithRef, ReactNode } from 'react';
|
|
2
|
+
import { Size, Tone } from '../../../types/common';
|
|
3
|
+
/** A unit the countdown can show. */
|
|
4
|
+
export type CountdownUnit = "days" | "hours" | "minutes" | "seconds";
|
|
5
|
+
/**
|
|
6
|
+
* How the time is laid out.
|
|
7
|
+
* - `tiles`: one box per unit, a big number over its unit name (sale banners, event pages).
|
|
8
|
+
* - `inline`: one line of text, like "2d 04h 12m", that fits in a sentence, Banner, or Button.
|
|
9
|
+
*/
|
|
10
|
+
export type CountdownLayout = "tiles" | "inline";
|
|
11
|
+
/**
|
|
12
|
+
* Tile style (the `tiles` layout only).
|
|
13
|
+
* - `solid`: filled with the tone color.
|
|
14
|
+
* - `soft`: a subtle tint of the tone.
|
|
15
|
+
* - `outline`: a tone-colored border on the surface.
|
|
16
|
+
* - `plain`: no box, just big numbers and unit names.
|
|
17
|
+
*/
|
|
18
|
+
export type CountdownVariant = "solid" | "soft" | "outline" | "plain";
|
|
19
|
+
/** Where the tile group sits in the countdown's width (the `tiles` layout). `start` and `end` flip in RTL. */
|
|
20
|
+
export type CountdownAlign = "start" | "center" | "end";
|
|
21
|
+
/**
|
|
22
|
+
* Splits a number of seconds into the given units. The largest unit takes
|
|
23
|
+
* everything above it (with `["hours", "minutes"]`, 2 days is 48 hours), and
|
|
24
|
+
* any remainder below the smallest unit is dropped.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* getCountdownParts(93_784, ["days", "hours", "minutes", "seconds"]);
|
|
28
|
+
* // { days: 1, hours: 2, minutes: 3, seconds: 4 }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function getCountdownParts(totalSeconds: number, units?: readonly CountdownUnit[]): Record<CountdownUnit, number>;
|
|
32
|
+
export interface CountdownProps extends Omit<ComponentPropsWithRef<"div">, "children"> {
|
|
33
|
+
/**
|
|
34
|
+
* When the countdown ends: an ISO 8601 date-time, or milliseconds since the
|
|
35
|
+
* epoch. Include the offset (`"2026-12-01T09:00:00-05:00"` or a trailing
|
|
36
|
+
* `Z`) so everyone counts down to the same moment; a date-time without one
|
|
37
|
+
* is read in each viewer's own time zone.
|
|
38
|
+
*/
|
|
39
|
+
to: string | number;
|
|
40
|
+
/**
|
|
41
|
+
* Units to show, largest first whatever the order given. The largest takes
|
|
42
|
+
* everything above it (`["hours", "minutes"]` shows 2 days as 48 hours),
|
|
43
|
+
* and the time is rounded up to the smallest, so the count reaches 0 exactly
|
|
44
|
+
* at `to`.
|
|
45
|
+
* @default ["days", "hours", "minutes", "seconds"]
|
|
46
|
+
*/
|
|
47
|
+
units?: CountdownUnit[];
|
|
48
|
+
/** Tiles (a box per unit) or one line of text. @default "tiles" */
|
|
49
|
+
layout?: CountdownLayout;
|
|
50
|
+
/**
|
|
51
|
+
* Where the tiles sit. The `tiles` layout fills its container's width (and
|
|
52
|
+
* wraps to two columns when that's too narrow for one row); `inline` ignores it.
|
|
53
|
+
* @default "start"
|
|
54
|
+
*/
|
|
55
|
+
align?: CountdownAlign;
|
|
56
|
+
/** Tile style, for the `tiles` layout. `inline` takes the surrounding text color. @default "solid" */
|
|
57
|
+
variant?: CountdownVariant;
|
|
58
|
+
/** Tile color, for the `solid`, `soft`, and `outline` variants. @default "neutral" */
|
|
59
|
+
tone?: Tone;
|
|
60
|
+
/** Type and tile size. @default "md" */
|
|
61
|
+
size?: Size;
|
|
62
|
+
/**
|
|
63
|
+
* Shown in place of the timer once it reaches zero, e.g. "This sale has
|
|
64
|
+
* ended". Without it, the timer stays on screen at zero.
|
|
65
|
+
*/
|
|
66
|
+
completedContent?: ReactNode;
|
|
67
|
+
/**
|
|
68
|
+
* Announced to screen readers when the countdown reaches zero while on
|
|
69
|
+
* screen. Match it to `completedContent` when you set one.
|
|
70
|
+
* @default "Time's up"
|
|
71
|
+
*/
|
|
72
|
+
completedLabel?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Called once when the countdown reaches zero, including when `to` has
|
|
75
|
+
* already passed when it first renders (after hydration). Called again only
|
|
76
|
+
* if `to` changes.
|
|
77
|
+
*/
|
|
78
|
+
onComplete?: () => void;
|
|
79
|
+
/**
|
|
80
|
+
* The timer's accessible name, e.g. `"Sale ends in"`. Use it (or
|
|
81
|
+
* `aria-labelledby` pointing at a visible heading) to say what the time is for.
|
|
82
|
+
* @default "Time remaining"
|
|
83
|
+
*/
|
|
84
|
+
"aria-label"?: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A live countdown to a moment: the end of a sale, the start of an event,
|
|
88
|
+
* tip-off. Updates every second (or every minute without seconds), shows
|
|
89
|
+
* the time in tiles or inline text, and calls `onComplete` at zero.
|
|
90
|
+
*
|
|
91
|
+
* Semantics: `role="timer"`, named by `aria-label` (default "Time remaining")
|
|
92
|
+
* or `aria-labelledby`. Screen readers read the whole time as one phrase
|
|
93
|
+
* ("4 hours, 12 minutes, 9 seconds") when they reach it, without being
|
|
94
|
+
* interrupted every second; reaching zero is announced once. Numbers and unit
|
|
95
|
+
* names are formatted for the current locale. Rendered on the server, the
|
|
96
|
+
* digits show as "--" until hydration, so the markup always matches.
|
|
97
|
+
*/
|
|
98
|
+
export declare const Countdown: ({ to, units: unitsProp, layout, align, variant, tone, size, completedContent, completedLabel, onComplete, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, ref, ...rest }: CountdownProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useHydrated as e } from "../../../hooks/useEnvironment.mjs";
|
|
3
|
+
import { useInterval as t } from "../../../hooks/useTiming.mjs";
|
|
4
|
+
import { announce as n } from "../../../utils/announce.mjs";
|
|
5
|
+
import { cx as r } from "../../../utils/cx.mjs";
|
|
6
|
+
import { useLocale as ee } from "../../utilities/LocaleProvider/LocaleProvider.mjs";
|
|
7
|
+
import { VisuallyHidden as i } from "../../utilities/VisuallyHidden/VisuallyHidden.mjs";
|
|
8
|
+
import a from "./Countdown.module.css.mjs";
|
|
9
|
+
import { useEffect as o, useMemo as s, useRef as c, useState as te } from "react";
|
|
10
|
+
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
11
|
+
// src/components/data-display/Countdown/Countdown.tsx
|
|
12
|
+
var d = [
|
|
13
|
+
"days",
|
|
14
|
+
"hours",
|
|
15
|
+
"minutes",
|
|
16
|
+
"seconds"
|
|
17
|
+
], f = {
|
|
18
|
+
days: 86400,
|
|
19
|
+
hours: 3600,
|
|
20
|
+
minutes: 60,
|
|
21
|
+
seconds: 1
|
|
22
|
+
}, p = {
|
|
23
|
+
days: "day",
|
|
24
|
+
hours: "hour",
|
|
25
|
+
minutes: "minute",
|
|
26
|
+
seconds: "second"
|
|
27
|
+
}, m = {
|
|
28
|
+
tiles: a.tilesLayout,
|
|
29
|
+
inline: a.inlineLayout
|
|
30
|
+
}, h = {
|
|
31
|
+
solid: a.solid,
|
|
32
|
+
soft: a.soft,
|
|
33
|
+
outline: a.outline,
|
|
34
|
+
plain: a.plain
|
|
35
|
+
}, g = {
|
|
36
|
+
neutral: a.toneNeutral,
|
|
37
|
+
primary: a.tonePrimary,
|
|
38
|
+
accent: a.toneAccent,
|
|
39
|
+
success: a.toneSuccess,
|
|
40
|
+
warning: a.toneWarning,
|
|
41
|
+
danger: a.toneDanger,
|
|
42
|
+
info: a.toneInfo
|
|
43
|
+
}, _ = {
|
|
44
|
+
start: a.alignStart,
|
|
45
|
+
center: a.alignCenter,
|
|
46
|
+
end: a.alignEnd
|
|
47
|
+
}, v = {
|
|
48
|
+
sm: a.sm,
|
|
49
|
+
md: a.md,
|
|
50
|
+
lg: a.lg
|
|
51
|
+
}, y = globalThis.process?.env?.NODE_ENV !== "production";
|
|
52
|
+
function ne(e) {
|
|
53
|
+
return typeof e == "number" ? e : Date.parse(e);
|
|
54
|
+
}
|
|
55
|
+
function b(e, t = d) {
|
|
56
|
+
let n = {
|
|
57
|
+
days: 0,
|
|
58
|
+
hours: 0,
|
|
59
|
+
minutes: 0,
|
|
60
|
+
seconds: 0
|
|
61
|
+
}, r = Math.max(0, Math.floor(e));
|
|
62
|
+
for (let e of d) t.includes(e) && (n[e] = Math.floor(r / f[e]), r -= n[e] * f[e]);
|
|
63
|
+
return n;
|
|
64
|
+
}
|
|
65
|
+
function re(e) {
|
|
66
|
+
let t = (t) => new Intl.NumberFormat(e, {
|
|
67
|
+
minimumIntegerDigits: t,
|
|
68
|
+
useGrouping: !1
|
|
69
|
+
}), n = (t, n) => Object.fromEntries(d.map((r) => [r, new Intl.NumberFormat(e, {
|
|
70
|
+
style: "unit",
|
|
71
|
+
unit: p[r],
|
|
72
|
+
unitDisplay: t,
|
|
73
|
+
minimumIntegerDigits: n,
|
|
74
|
+
useGrouping: !1
|
|
75
|
+
})]));
|
|
76
|
+
return {
|
|
77
|
+
padded: t(2),
|
|
78
|
+
long: n("long", 1),
|
|
79
|
+
narrow: n("narrow", 1),
|
|
80
|
+
narrowPadded: n("narrow", 2),
|
|
81
|
+
longList: new Intl.ListFormat(e, {
|
|
82
|
+
type: "unit",
|
|
83
|
+
style: "long"
|
|
84
|
+
}),
|
|
85
|
+
narrowList: new Intl.ListFormat(e, {
|
|
86
|
+
type: "unit",
|
|
87
|
+
style: "narrow"
|
|
88
|
+
})
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
var x = ({ to: p, units: x, layout: S = "tiles", align: ie = "start", variant: C = "solid", tone: w = "neutral", size: ae = "md", completedContent: T, completedLabel: oe, onComplete: E, className: D, "aria-label": O, "aria-labelledby": k, ref: A, ...j }) => {
|
|
92
|
+
let { messages: M, locale: N } = ee(), P = e(), F = ne(p), I = Number.isFinite(F), L = (x?.length ? x : d).join(), R = s(() => d.filter((e) => L.split(",").includes(e)), [L]), z = f[R[R.length - 1]], B = (e) => I ? Math.max(0, Math.ceil((F - e) / 1e3 / z)) * z : 0, [V, H] = te(() => Date.now());
|
|
93
|
+
o(() => H(Date.now()), [F]);
|
|
94
|
+
let U = B(V), W = I && U === 0;
|
|
95
|
+
t(() => {
|
|
96
|
+
let e = Date.now();
|
|
97
|
+
H((t) => B(t) === B(e) ? t : e);
|
|
98
|
+
}, P && I && !W ? z === 1 ? 250 : 1e3 : null), o(() => {
|
|
99
|
+
y && !I && console.warn(`[Countdown] Can't read the end time ${JSON.stringify(p)}. Pass an ISO 8601 date-time or milliseconds since the epoch.`);
|
|
100
|
+
}, [I, p]);
|
|
101
|
+
let G = c(E);
|
|
102
|
+
G.current = E;
|
|
103
|
+
let K = c(!1), q = c(void 0), J = oe ?? M.countdown.completed;
|
|
104
|
+
o(() => {
|
|
105
|
+
P && I && (W ? q.current !== F && (q.current = F, G.current?.(), K.current && n(J), K.current = !1) : K.current = !0);
|
|
106
|
+
}, [
|
|
107
|
+
P,
|
|
108
|
+
I,
|
|
109
|
+
W,
|
|
110
|
+
F,
|
|
111
|
+
J
|
|
112
|
+
]);
|
|
113
|
+
let Y = s(() => re(N), [N]);
|
|
114
|
+
if (W && T !== void 0) return /* @__PURE__ */ l("div", {
|
|
115
|
+
...j,
|
|
116
|
+
ref: A,
|
|
117
|
+
className: r(a.root, a.completed, D),
|
|
118
|
+
children: T
|
|
119
|
+
});
|
|
120
|
+
let X = P && I, Z = b(U, R), se = (e, t) => Y.long[e].formatToParts(t).filter((e) => e.type === "unit").map((e) => e.value).join(""), Q = R.findIndex((e) => Z[e] > 0), $ = R.slice(Q === -1 ? R.length - 1 : Q), ce = X ? Y.longList.format($.map((e) => Y.long[e].format(Z[e]))) : "";
|
|
121
|
+
return /* @__PURE__ */ u("div", {
|
|
122
|
+
...j,
|
|
123
|
+
ref: A,
|
|
124
|
+
role: "timer",
|
|
125
|
+
"aria-label": k ? O : O ?? M.countdown.label,
|
|
126
|
+
"aria-labelledby": k,
|
|
127
|
+
"data-complete": W || void 0,
|
|
128
|
+
className: r(a.root, m[S], S === "tiles" && _[ie], h[C], g[w], v[ae], D),
|
|
129
|
+
children: [S === "tiles" ? /* @__PURE__ */ l("span", {
|
|
130
|
+
className: a.tiles,
|
|
131
|
+
"data-count": R.length,
|
|
132
|
+
"aria-hidden": "true",
|
|
133
|
+
children: R.map((e) => /* @__PURE__ */ u("span", {
|
|
134
|
+
className: a.tile,
|
|
135
|
+
children: [/* @__PURE__ */ l("span", {
|
|
136
|
+
className: a.value,
|
|
137
|
+
children: X ? Y.padded.format(Z[e]) : "--"
|
|
138
|
+
}), /* @__PURE__ */ l("span", {
|
|
139
|
+
className: a.unit,
|
|
140
|
+
children: se(e, X ? Z[e] : 0)
|
|
141
|
+
})]
|
|
142
|
+
}, e))
|
|
143
|
+
}) : /* @__PURE__ */ l("span", {
|
|
144
|
+
className: a.text,
|
|
145
|
+
"aria-hidden": "true",
|
|
146
|
+
children: X ? Y.narrowList.format($.map((e, t) => (t === 0 ? Y.narrow : Y.narrowPadded)[e].format(Z[e]))) : "--"
|
|
147
|
+
}), /* @__PURE__ */ l(i, { children: ce })]
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
export { x as Countdown, b as getCountdownParts };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=`_root_1b43d_12`,t=`_sm_1b43d_40`,n=`_md_1b43d_49`,r=`_lg_1b43d_53`,i=`_toneNeutral_1b43d_64`,a=`_tonePrimary_1b43d_68`,o=`_toneAccent_1b43d_76`,s=`_toneSuccess_1b43d_84`,c=`_toneWarning_1b43d_92`,l=`_toneDanger_1b43d_100`,u=`_toneInfo_1b43d_108`,d=`_solid_1b43d_118`,f=`_soft_1b43d_124`,p=`_outline_1b43d_130`,m=`_plain_1b43d_135`,h=`_tilesLayout_1b43d_144`,g=`_alignStart_1b43d_150`,_=`_alignCenter_1b43d_154`,v=`_alignEnd_1b43d_158`,y=`_tiles_1b43d_144`,b=`_tile_1b43d_144`,x=`_value_1b43d_191`,S=`_unit_1b43d_203`,C=`_inlineLayout_1b43d_274`,w=`_text_1b43d_278`,T=`_completed_1b43d_299`,E={root:e,sm:t,md:n,lg:r,toneNeutral:i,tonePrimary:a,toneAccent:o,toneSuccess:s,toneWarning:c,toneDanger:l,toneInfo:u,solid:d,soft:f,outline:p,plain:m,tilesLayout:h,alignStart:g,alignCenter:_,alignEnd:v,tiles:y,tile:b,value:x,unit:S,inlineLayout:C,text:w,completed:T};exports.alignCenter=_,exports.alignEnd=v,exports.alignStart=g,exports.completed=T,exports.default=E,exports.inlineLayout=C,exports.lg=r,exports.md=n,exports.outline=p,exports.plain=m,exports.root=e,exports.sm=t,exports.soft=f,exports.solid=d,exports.text=w,exports.tile=b,exports.tiles=y,exports.tilesLayout=h,exports.toneAccent=o,exports.toneDanger=l,exports.toneInfo=u,exports.toneNeutral=i,exports.tonePrimary=a,exports.toneSuccess=s,exports.toneWarning=c,exports.unit=S,exports.value=x;
|