@vendure-io/ui 3.0.0-next.4 → 3.0.0-next.6
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/package.json +12 -11
- package/src/components/atoms/alert-dialog.tsx +1 -4
- package/src/components/atoms/alert.tsx +59 -35
- package/src/components/atoms/badge.tsx +2 -2
- package/src/components/atoms/breadcrumb.tsx +154 -59
- package/src/components/atoms/button-group.tsx +1 -1
- package/src/components/atoms/button.tsx +2 -2
- package/src/components/atoms/calendar.tsx +2 -2
- package/src/components/atoms/card.tsx +15 -2
- package/src/components/atoms/carousel.tsx +33 -7
- package/src/components/atoms/chart.tsx +3 -3
- package/src/components/atoms/checkbox.tsx +1 -1
- package/src/components/atoms/combobox.tsx +60 -36
- package/src/components/atoms/command.tsx +17 -7
- package/src/components/atoms/context-menu.tsx +5 -5
- package/src/components/atoms/dialog.tsx +30 -14
- package/src/components/atoms/dropdown-menu.tsx +1 -1
- package/src/components/atoms/hover-card.tsx +1 -1
- package/src/components/atoms/input-group.tsx +30 -12
- package/src/components/atoms/input-otp.tsx +2 -2
- package/src/components/atoms/input.tsx +13 -3
- package/src/components/atoms/menubar.tsx +2 -2
- package/src/components/atoms/native-select.tsx +1 -1
- package/src/components/atoms/navigation-menu.tsx +3 -3
- package/src/components/atoms/pagination.tsx +52 -15
- package/src/components/atoms/popover.tsx +1 -1
- package/src/components/atoms/select.tsx +3 -3
- package/src/components/atoms/sheet.tsx +35 -15
- package/src/components/atoms/sidebar.tsx +224 -36
- package/src/components/atoms/skeleton.tsx +6 -3
- package/src/components/atoms/spinner.tsx +7 -2
- package/src/components/atoms/tabs.tsx +6 -2
- package/src/components/atoms/textarea.tsx +1 -1
- package/src/components/atoms/toggle.tsx +1 -1
- package/src/components/molecules/action-needed.tsx +483 -0
- package/src/components/molecules/anonymized-token.tsx +70 -25
- package/src/components/molecules/app-shell.tsx +14 -5
- package/src/components/molecules/checklist/checklist.tsx +47 -17
- package/src/components/molecules/chip.tsx +37 -19
- package/src/components/molecules/choice-card.tsx +117 -9
- package/src/components/molecules/code-block/package-manager-storage.ts +50 -0
- package/src/components/molecules/code-block/process-code.ts +1 -1
- package/src/components/molecules/code-block.tsx +58 -47
- package/src/components/molecules/combobox-free-text.tsx +75 -20
- package/src/components/molecules/confirm-dialog.tsx +17 -5
- package/src/components/molecules/copyable-text.tsx +10 -8
- package/src/components/molecules/data-table/data-table-filters.tsx +36 -6
- package/src/components/molecules/data-table/data-table-helpers.tsx +109 -3
- package/src/components/molecules/data-table/data-table-row-count-storage.tsx +88 -0
- package/src/components/molecules/data-table/data-table-selection-storage.tsx +33 -15
- package/src/components/molecules/data-table/data-table-types.tsx +156 -29
- package/src/components/molecules/data-table/data-table-view-options.tsx +14 -4
- package/src/components/molecules/data-table/data-table.tsx +156 -75
- package/src/components/molecules/data-table/table-pagination.tsx +142 -38
- package/src/components/molecules/date-picker.tsx +58 -25
- package/src/components/molecules/date-range-picker.tsx +59 -24
- package/src/components/molecules/date-time-picker.tsx +63 -25
- package/src/components/molecules/date-time.tsx +38 -3
- package/src/components/molecules/elapsed-time.tsx +61 -12
- package/src/components/molecules/file-dropzone.tsx +151 -40
- package/src/components/molecules/format-provider.tsx +14 -4
- package/src/components/molecules/id-chip-chrome.tsx +114 -0
- package/src/components/molecules/id-chip.tsx +13 -115
- package/src/components/molecules/issued-secret.tsx +35 -25
- package/src/components/molecules/live-indicator.tsx +1 -1
- package/src/components/molecules/money.tsx +44 -3
- package/src/components/molecules/multi-select.tsx +62 -16
- package/src/components/molecules/page-header.tsx +6 -2
- package/src/components/molecules/password-input.tsx +11 -10
- package/src/components/molecules/relative-time.tsx +88 -16
- package/src/components/molecules/search-trigger.tsx +5 -3
- package/src/components/molecules/secret-value.tsx +35 -19
- package/src/components/molecules/skip-link.tsx +11 -9
- package/src/components/molecules/stat-card.tsx +145 -33
- package/src/components/molecules/state-views/empty-state.tsx +16 -12
- package/src/components/molecules/state-views/error-state.tsx +36 -20
- package/src/components/molecules/state-views/loading-state.tsx +18 -6
- package/src/components/molecules/state-views/skeleton-parts.tsx +6 -4
- package/src/components/molecules/status-badge.tsx +11 -35
- package/src/components/molecules/time-tooltip.tsx +55 -1
- package/src/hooks/use-copy.ts +3 -1
- package/src/lib/deprecated.ts +71 -0
- package/src/lib/field-surface.ts +7 -7
- package/src/lib/format-messages.ts +368 -0
- package/src/lib/highlight.ts +1 -1
- package/src/lib/menu-item.tsx +1 -1
- package/src/lib/tint-recipes.ts +10 -5
- package/src/lib/utils.ts +19 -1
- package/src/lib/dialog-padding.ts +0 -48
|
@@ -6,10 +6,11 @@ import { Input } from '@vendure-io/ui/components/atoms/input';
|
|
|
6
6
|
import { Popover, PopoverContent, PopoverTrigger } from '@vendure-io/ui/components/atoms/popover';
|
|
7
7
|
import { useFormatSettings } from '@vendure-io/ui/components/molecules/format-provider';
|
|
8
8
|
import { formatDateLabel, parseInstant } from '@vendure-io/ui/lib/date-value';
|
|
9
|
-
import { fieldButton } from '@vendure-io/ui/lib/field-surface';
|
|
10
9
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
11
10
|
import { CalendarClockIcon, XIcon } from 'lucide-react';
|
|
12
11
|
import * as React from 'react';
|
|
12
|
+
import { fieldButton } from '../../lib/field-surface.ts';
|
|
13
|
+
import { useMessages } from '../../lib/format-messages.ts';
|
|
13
14
|
|
|
14
15
|
type CalendarProps = Omit<
|
|
15
16
|
React.ComponentProps<typeof Calendar>,
|
|
@@ -18,36 +19,64 @@ type CalendarProps = Omit<
|
|
|
18
19
|
|
|
19
20
|
interface DateTimePickerProps
|
|
20
21
|
extends Omit<React.ComponentProps<'div'>, 'defaultValue' | 'onChange'> {
|
|
21
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* ISO 8601 instant. Calendar and time controls edit it in the user's local
|
|
24
|
+
* zone. Pass `value` to control the picker. Leave the prop out and it keeps
|
|
25
|
+
* its own state.
|
|
26
|
+
*/
|
|
22
27
|
value?: string;
|
|
28
|
+
/** Initial instant when `value` is not passed. */
|
|
29
|
+
defaultValue?: string;
|
|
23
30
|
onValueChange?: (value: string | undefined) => void;
|
|
31
|
+
/** @default `messages.dateTimePicker.placeholder`, "Pick a date and time" */
|
|
24
32
|
placeholder?: React.ReactNode;
|
|
25
33
|
clearable?: boolean;
|
|
26
34
|
disabled?: boolean;
|
|
27
35
|
invalid?: boolean;
|
|
36
|
+
/** `sm` is 28px tall, for dense rows, like `Input size="sm"`. */
|
|
37
|
+
size?: 'sm' | 'default';
|
|
28
38
|
name?: string;
|
|
29
39
|
id?: string;
|
|
30
40
|
calendarProps?: CalendarProps;
|
|
41
|
+
/** Accessible name of the clear button. @default `messages.dateTimePicker.clear`, "Clear date and time" */
|
|
42
|
+
clearLabel?: string;
|
|
43
|
+
/** Accessible name of the time field. @default `messages.dateTimePicker.time`, "Time" */
|
|
44
|
+
timeLabel?: string;
|
|
31
45
|
}
|
|
32
46
|
|
|
33
|
-
function DateTimePicker({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
function DateTimePicker(allProps: DateTimePickerProps) {
|
|
48
|
+
const {
|
|
49
|
+
value: valueProp,
|
|
50
|
+
defaultValue,
|
|
51
|
+
onValueChange,
|
|
52
|
+
placeholder,
|
|
53
|
+
clearable = true,
|
|
54
|
+
disabled,
|
|
55
|
+
invalid,
|
|
56
|
+
size = 'default',
|
|
57
|
+
name,
|
|
58
|
+
id,
|
|
59
|
+
calendarProps,
|
|
60
|
+
clearLabel,
|
|
61
|
+
timeLabel,
|
|
62
|
+
className,
|
|
63
|
+
...props
|
|
64
|
+
} = allProps;
|
|
65
|
+
// Controlled when the `value` prop is passed, even as `undefined` (no value).
|
|
66
|
+
const controlled = 'value' in allProps;
|
|
46
67
|
const [open, setOpen] = React.useState(false);
|
|
68
|
+
const [own, setOwn] = React.useState(defaultValue);
|
|
69
|
+
const value = controlled ? valueProp : own;
|
|
70
|
+
function commit(next: string | undefined) {
|
|
71
|
+
if (!controlled) setOwn(next);
|
|
72
|
+
onValueChange?.(next);
|
|
73
|
+
}
|
|
47
74
|
// The calendar popup is a dialog, named by its trigger.
|
|
48
75
|
const generatedId = React.useId();
|
|
49
76
|
const triggerId = id ?? generatedId;
|
|
50
77
|
const { locale } = useFormatSettings();
|
|
78
|
+
const t = useMessages('dateTimePicker', { clear: clearLabel, time: timeLabel });
|
|
79
|
+
const placeholderText = placeholder !== undefined ? placeholder : t.placeholder;
|
|
51
80
|
const selected = parseInstant(value);
|
|
52
81
|
const timeValue = selected
|
|
53
82
|
? `${String(selected.getHours()).padStart(2, '0')}:${String(selected.getMinutes()).padStart(2, '0')}`
|
|
@@ -57,7 +86,7 @@ function DateTimePicker({
|
|
|
57
86
|
if (!date) return;
|
|
58
87
|
const next = new Date(date);
|
|
59
88
|
next.setHours(selected?.getHours() ?? 0, selected?.getMinutes() ?? 0, 0, 0);
|
|
60
|
-
|
|
89
|
+
commit(next.toISOString());
|
|
61
90
|
setOpen(false);
|
|
62
91
|
}
|
|
63
92
|
|
|
@@ -69,13 +98,15 @@ function DateTimePicker({
|
|
|
69
98
|
if (!Number.isFinite(hours) || !Number.isFinite(minutes)) return;
|
|
70
99
|
const next = selected ? new Date(selected) : new Date();
|
|
71
100
|
next.setHours(hours, minutes, 0, 0);
|
|
72
|
-
|
|
101
|
+
commit(next.toISOString());
|
|
73
102
|
}
|
|
74
103
|
|
|
75
104
|
return (
|
|
76
105
|
<div
|
|
77
106
|
data-slot="date-time-picker"
|
|
78
|
-
|
|
107
|
+
data-size={size}
|
|
108
|
+
// max-w-92 is the calendar (62), the gap and the w-28 time box. Pass max-w-none to fill the column.
|
|
109
|
+
className={cn('flex min-w-0 max-w-92 items-center gap-2', className)}
|
|
79
110
|
{...props}
|
|
80
111
|
>
|
|
81
112
|
{name ? <input type="hidden" name={name} value={value ?? ''} /> : null}
|
|
@@ -89,7 +120,7 @@ function DateTimePicker({
|
|
|
89
120
|
disabled={disabled}
|
|
90
121
|
aria-invalid={invalid || undefined}
|
|
91
122
|
// Pickers sit in forms next to Inputs, so they take the field look.
|
|
92
|
-
className={fieldButton}
|
|
123
|
+
className={cn(fieldButton, size === 'sm' && 'h-7')}
|
|
93
124
|
/>
|
|
94
125
|
}
|
|
95
126
|
>
|
|
@@ -98,12 +129,18 @@ function DateTimePicker({
|
|
|
98
129
|
data-placeholder={selected ? undefined : ''}
|
|
99
130
|
className={cn('truncate', !selected && 'text-faint-foreground')}
|
|
100
131
|
>
|
|
101
|
-
{selected ? formatDateLabel(selected, locale) :
|
|
132
|
+
{selected ? formatDateLabel(selected, locale) : placeholderText}
|
|
102
133
|
</span>
|
|
103
134
|
</PopoverTrigger>
|
|
104
|
-
<PopoverContent
|
|
135
|
+
<PopoverContent
|
|
136
|
+
className="w-auto min-w-(--anchor-width) p-0"
|
|
137
|
+
align="start"
|
|
138
|
+
aria-labelledby={triggerId}
|
|
139
|
+
>
|
|
105
140
|
<Calendar
|
|
106
141
|
{...calendarProps}
|
|
142
|
+
// In a popup wider than the grid, the month sits centred with even padding.
|
|
143
|
+
className={cn('mx-auto', calendarProps?.className)}
|
|
107
144
|
mode="single"
|
|
108
145
|
selected={selected}
|
|
109
146
|
defaultMonth={selected}
|
|
@@ -113,10 +150,11 @@ function DateTimePicker({
|
|
|
113
150
|
</Popover>
|
|
114
151
|
<Input
|
|
115
152
|
type="time"
|
|
116
|
-
aria-label=
|
|
153
|
+
aria-label={t.time}
|
|
117
154
|
aria-invalid={invalid || undefined}
|
|
118
155
|
value={timeValue}
|
|
119
156
|
disabled={disabled || !selected}
|
|
157
|
+
size={size}
|
|
120
158
|
className="w-28"
|
|
121
159
|
onChange={(event) => commitTime(event.currentTarget.value)}
|
|
122
160
|
/>
|
|
@@ -124,10 +162,10 @@ function DateTimePicker({
|
|
|
124
162
|
<Button
|
|
125
163
|
type="button"
|
|
126
164
|
variant="ghost"
|
|
127
|
-
size=
|
|
165
|
+
size={size === 'sm' ? 'icon-xs' : 'icon-sm'}
|
|
128
166
|
disabled={disabled}
|
|
129
|
-
aria-label=
|
|
130
|
-
onClick={() =>
|
|
167
|
+
aria-label={t.clear}
|
|
168
|
+
onClick={() => commit(undefined)}
|
|
131
169
|
>
|
|
132
170
|
<XIcon />
|
|
133
171
|
</Button>
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
import { useFormatSettings } from '@vendure-io/ui/components/molecules/format-provider';
|
|
4
4
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
5
5
|
import type { ComponentProps, ReactNode } from 'react';
|
|
6
|
+
import { useMessages } from '../../lib/format-messages.ts';
|
|
7
|
+
// Relative: `time-tooltip` is internal.
|
|
8
|
+
import { sampleText, TimeSkeleton } from './time-tooltip.tsx';
|
|
6
9
|
|
|
7
10
|
function toDate(value: string | number | Date | null | undefined): Date | null {
|
|
8
11
|
if (value === null || value === undefined) return null;
|
|
@@ -10,7 +13,15 @@ function toDate(value: string | number | Date | null | undefined): Date | null {
|
|
|
10
13
|
return Number.isNaN(date.getTime()) ? null : date;
|
|
11
14
|
}
|
|
12
15
|
|
|
16
|
+
// A late date with two-digit fields, so the sample is as long as the longest
|
|
17
|
+
// dates: "Dec 28, 2026, 10:58 PM" in en-US.
|
|
18
|
+
const SAMPLE_DATE = Date.UTC(2026, 11, 28, 22, 58, 58);
|
|
19
|
+
|
|
13
20
|
interface DateTimeProps extends Omit<ComponentProps<'time'>, 'dateTime'> {
|
|
21
|
+
/**
|
|
22
|
+
* `undefined` means not loaded yet and renders a one-line skeleton as wide
|
|
23
|
+
* as the formatted date. `null` and an invalid date render `fallback`.
|
|
24
|
+
*/
|
|
14
25
|
value: string | number | Date | null | undefined;
|
|
15
26
|
locale?: string;
|
|
16
27
|
/** `Intl` date preset. Default `'medium'`. */
|
|
@@ -20,8 +31,10 @@ interface DateTimeProps extends Omit<ComponentProps<'time'>, 'dateTime'> {
|
|
|
20
31
|
timeZone?: string;
|
|
21
32
|
/** Escape hatch — full control, ignores `dateStyle`/`timeStyle`. */
|
|
22
33
|
formatOptions?: Intl.DateTimeFormatOptions;
|
|
23
|
-
/** Rendered for
|
|
34
|
+
/** Rendered for `null` and invalid input. Default `'—'`. */
|
|
24
35
|
fallback?: ReactNode;
|
|
36
|
+
/** Screen-reader text while `value` is `undefined`. @default `messages.dateTime.loading`, "Loading date" */
|
|
37
|
+
loadingLabel?: string;
|
|
25
38
|
}
|
|
26
39
|
|
|
27
40
|
/**
|
|
@@ -40,12 +53,12 @@ function DateTime({
|
|
|
40
53
|
timeZone,
|
|
41
54
|
formatOptions,
|
|
42
55
|
fallback = '—',
|
|
56
|
+
loadingLabel,
|
|
43
57
|
className,
|
|
44
58
|
...props
|
|
45
59
|
}: DateTimeProps) {
|
|
46
60
|
const settings = useFormatSettings();
|
|
47
|
-
const
|
|
48
|
-
if (!date) return <>{fallback}</>;
|
|
61
|
+
const t = useMessages('dateTime', { loading: loadingLabel });
|
|
49
62
|
|
|
50
63
|
// Explicit wins over context: an escape-hatch `formatOptions.timeZone` must
|
|
51
64
|
// not be clobbered by the provider's zone.
|
|
@@ -58,6 +71,28 @@ function DateTime({
|
|
|
58
71
|
...(resolvedTimeZone ? { timeZone: resolvedTimeZone } : {}),
|
|
59
72
|
};
|
|
60
73
|
|
|
74
|
+
if (value === undefined) {
|
|
75
|
+
const sample = sampleText(
|
|
76
|
+
() =>
|
|
77
|
+
new Intl.DateTimeFormat(locale ?? settings.locale, { ...options, timeZone: 'UTC' }).format(
|
|
78
|
+
SAMPLE_DATE,
|
|
79
|
+
),
|
|
80
|
+
'Dec 28, 2026',
|
|
81
|
+
);
|
|
82
|
+
return (
|
|
83
|
+
<TimeSkeleton
|
|
84
|
+
slot="date-time"
|
|
85
|
+
sample={sample}
|
|
86
|
+
loadingLabel={t.loading}
|
|
87
|
+
className={className}
|
|
88
|
+
{...props}
|
|
89
|
+
/>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const date = toDate(value);
|
|
94
|
+
if (!date) return <>{fallback}</>;
|
|
95
|
+
|
|
61
96
|
let formatted: string;
|
|
62
97
|
try {
|
|
63
98
|
formatted = new Intl.DateTimeFormat(locale ?? settings.locale, options).format(date);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useFormatSettings } from '@vendure-io/ui/components/molecules/format-provider';
|
|
4
|
-
import { formatElapsed, isoDuration } from '@vendure-io/ui/lib/format-elapsed';
|
|
5
4
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
6
5
|
import {
|
|
7
6
|
type ComponentProps,
|
|
@@ -13,8 +12,18 @@ import {
|
|
|
13
12
|
useState,
|
|
14
13
|
useSyncExternalStore,
|
|
15
14
|
} from 'react';
|
|
15
|
+
import { warnDeprecated } from '../../lib/deprecated.ts';
|
|
16
|
+
import { formatElapsed, isoDuration } from '../../lib/format-elapsed.ts';
|
|
17
|
+
import { useMessages } from '../../lib/format-messages.ts';
|
|
16
18
|
// Relative: `time-tooltip` is internal.
|
|
17
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
sampleText,
|
|
21
|
+
TimeSkeleton,
|
|
22
|
+
TimeSpan,
|
|
23
|
+
TimeTooltip,
|
|
24
|
+
toTime,
|
|
25
|
+
useReadersClock,
|
|
26
|
+
} from './time-tooltip.tsx';
|
|
18
27
|
|
|
19
28
|
// One shared clock for every timer on the page: one interval, whole seconds.
|
|
20
29
|
// It runs only while at least one visible timer listens.
|
|
@@ -88,16 +97,31 @@ function useOnScreen(element: React.RefObject<HTMLElement | null>) {
|
|
|
88
97
|
return onScreen && tabVisible;
|
|
89
98
|
}
|
|
90
99
|
|
|
100
|
+
type ElapsedTimeValue = string | number | Date | null | undefined;
|
|
101
|
+
|
|
91
102
|
interface ElapsedTimeProps extends Omit<ComponentProps<'time'>, 'dateTime' | 'children'> {
|
|
92
|
-
/** When the count started: a Date, an ISO string or epoch milliseconds. */
|
|
93
|
-
since: string | number | Date | null | undefined;
|
|
94
103
|
/**
|
|
95
|
-
* When the count
|
|
96
|
-
*
|
|
104
|
+
* When the count started: a Date, an ISO string or epoch milliseconds.
|
|
105
|
+
* `undefined` means not loaded yet and renders a one-line skeleton. `null`
|
|
106
|
+
* and an invalid date render `fallback`.
|
|
97
107
|
*/
|
|
108
|
+
from?: ElapsedTimeValue;
|
|
109
|
+
/**
|
|
110
|
+
* When the count stopped. With `to`, the text is fixed. Omitted,
|
|
111
|
+
* `undefined` or `null` means it has not stopped: a live count that ticks
|
|
112
|
+
* every second. `to` never shows a skeleton; only `from={undefined}` does.
|
|
113
|
+
* When the end loads separately from the start, keep `from` `undefined`
|
|
114
|
+
* until both are known, or the count runs live until `to` arrives.
|
|
115
|
+
*/
|
|
116
|
+
to?: string | number | Date | null;
|
|
117
|
+
/** @deprecated Use `from`. Removed in 4.0. */
|
|
118
|
+
since?: ElapsedTimeValue;
|
|
119
|
+
/** @deprecated Use `to`. Removed in 4.0. */
|
|
98
120
|
until?: string | number | Date | null;
|
|
121
|
+
/** Screen-reader text while `from` is `undefined`. @default `messages.elapsedTime.loading`, "Loading duration" */
|
|
122
|
+
loadingLabel?: string;
|
|
99
123
|
/**
|
|
100
|
-
* Rendered for
|
|
124
|
+
* Rendered for `null` or invalid input, and on the server and the first
|
|
101
125
|
* client render of a server-rendered page (the server has no reader's
|
|
102
126
|
* clock or locale). An app that renders only in the browser shows the count
|
|
103
127
|
* from the first paint.
|
|
@@ -111,7 +135,7 @@ interface ElapsedTimeProps extends Omit<ComponentProps<'time'>, 'dateTime' | 'ch
|
|
|
111
135
|
format?: (ms: number) => string;
|
|
112
136
|
/**
|
|
113
137
|
* A tooltip on hover and focus. Default `false`. `true` shows when the
|
|
114
|
-
* count started in the reader's locale (with `
|
|
138
|
+
* count started in the reader's locale (with `to`, the range and how
|
|
115
139
|
* long it took). Pass content to show that instead. The tooltip content is
|
|
116
140
|
* the accessible description too.
|
|
117
141
|
*/
|
|
@@ -135,7 +159,7 @@ interface ElapsedTimeProps extends Omit<ComponentProps<'time'>, 'dateTime' | 'ch
|
|
|
135
159
|
* - It stops ticking while it is off screen or the tab is hidden, and catches
|
|
136
160
|
* up when it shows again. All timers on a page share one interval.
|
|
137
161
|
* - The server and the first client render show `fallback`, also with
|
|
138
|
-
* `
|
|
162
|
+
* `to`, so hydration matches; the count shows right after. In an app
|
|
139
163
|
* that renders only in the browser it shows from the first paint.
|
|
140
164
|
* - It renders a `<time>` with the ISO duration (`PT1M15S`). Screen readers
|
|
141
165
|
* do not announce each tick.
|
|
@@ -143,9 +167,12 @@ interface ElapsedTimeProps extends Omit<ComponentProps<'time'>, 'dateTime' | 'ch
|
|
|
143
167
|
* a tab stop and the tooltip opens beside the whole status block.
|
|
144
168
|
*/
|
|
145
169
|
function ElapsedTime({
|
|
170
|
+
from: fromProp,
|
|
146
171
|
since,
|
|
172
|
+
to: toProp,
|
|
147
173
|
until,
|
|
148
174
|
fallback = '—',
|
|
175
|
+
loadingLabel,
|
|
149
176
|
format,
|
|
150
177
|
tooltip = false,
|
|
151
178
|
focusable,
|
|
@@ -153,11 +180,16 @@ function ElapsedTime({
|
|
|
153
180
|
className,
|
|
154
181
|
...props
|
|
155
182
|
}: ElapsedTimeProps) {
|
|
183
|
+
if (since !== undefined) warnDeprecated('ElapsedTime', 'since', 'from');
|
|
184
|
+
if (until !== undefined) warnDeprecated('ElapsedTime', 'until', 'to');
|
|
185
|
+
const from = fromProp !== undefined ? fromProp : since;
|
|
186
|
+
const to = toProp !== undefined ? toProp : until;
|
|
156
187
|
const ref = useRef<HTMLTimeElement>(null);
|
|
157
188
|
const descriptionId = useId();
|
|
158
189
|
const settings = useFormatSettings();
|
|
159
|
-
const
|
|
160
|
-
const
|
|
190
|
+
const t = useMessages('elapsedTime', { loading: loadingLabel });
|
|
191
|
+
const start = toTime(from);
|
|
192
|
+
const end = toTime(to);
|
|
161
193
|
const live = start !== null && end === null;
|
|
162
194
|
const active = useOnScreen(ref) && live;
|
|
163
195
|
const subscribe = useCallback(
|
|
@@ -165,7 +197,7 @@ function ElapsedTime({
|
|
|
165
197
|
[active],
|
|
166
198
|
);
|
|
167
199
|
const now = useSyncExternalStore(subscribe, readClock, readServerClock);
|
|
168
|
-
// A fixed count (`
|
|
200
|
+
// A fixed count (`to`) does not need the clock, but its text and its
|
|
169
201
|
// description depend on the reader's locale: the server renders the
|
|
170
202
|
// fallback for it too, the same as RelativeTime.
|
|
171
203
|
const readersClock = useReadersClock();
|
|
@@ -180,6 +212,23 @@ function ElapsedTime({
|
|
|
180
212
|
...props,
|
|
181
213
|
};
|
|
182
214
|
const resolvedLocale = locale ?? settings.locale;
|
|
215
|
+
|
|
216
|
+
if (from === undefined) {
|
|
217
|
+
return (
|
|
218
|
+
<TimeSkeleton
|
|
219
|
+
slot="elapsed-time"
|
|
220
|
+
// A typical count: "1m 15s" in English.
|
|
221
|
+
sample={sampleText(
|
|
222
|
+
() => (format ? format(75_000) : formatElapsed(75_000, { locale: resolvedLocale })),
|
|
223
|
+
'1m 15s',
|
|
224
|
+
)}
|
|
225
|
+
loadingLabel={t.loading}
|
|
226
|
+
className={className}
|
|
227
|
+
{...props}
|
|
228
|
+
/>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
183
232
|
const text =
|
|
184
233
|
elapsed === null || !readersClock
|
|
185
234
|
? fallback
|