@vendure-io/ui 3.0.0-next.3 → 3.0.0-next.5
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 -10
- 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 +124 -49
- package/src/components/atoms/button-group.tsx +1 -1
- package/src/components/atoms/button.tsx +4 -3
- package/src/components/atoms/calendar.tsx +2 -2
- package/src/components/atoms/card.tsx +15 -2
- package/src/components/atoms/chart.tsx +3 -3
- package/src/components/atoms/checkbox.tsx +1 -1
- package/src/components/atoms/combobox.tsx +37 -26
- package/src/components/atoms/command.tsx +3 -3
- 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 +9 -3
- 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 +200 -31
- package/src/components/atoms/skeleton.tsx +6 -3
- package/src/components/atoms/switch.tsx +1 -1
- 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 +52 -8
- package/src/components/molecules/chip.tsx +37 -18
- package/src/components/molecules/choice-card.tsx +114 -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 +11 -1
- package/src/components/molecules/copyable-text.tsx +10 -8
- package/src/components/molecules/data-table/data-table-filters.tsx +14 -2
- 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 +123 -13
- package/src/components/molecules/data-table/data-table.tsx +112 -55
- package/src/components/molecules/data-table/table-pagination.tsx +96 -14
- package/src/components/molecules/date-picker.tsx +55 -24
- package/src/components/molecules/date-range-picker.tsx +54 -23
- package/src/components/molecules/date-time-picker.tsx +60 -24
- 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 +139 -39
- 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 +3 -107
- package/src/components/molecules/issued-secret.tsx +1 -1
- package/src/components/molecules/live-indicator.tsx +1 -1
- package/src/components/molecules/money.tsx +46 -4
- package/src/components/molecules/multi-select.tsx +58 -15
- 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 +10 -2
- package/src/components/molecules/stat-card.tsx +143 -33
- package/src/components/molecules/state-views/empty-state.tsx +16 -12
- package/src/components/molecules/state-views/error-state.tsx +19 -15
- package/src/components/molecules/state-views/loading-state.tsx +16 -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/env.ts +9 -0
- package/src/lib/field-surface.ts +7 -7
- package/src/lib/format-messages.ts +192 -0
- package/src/lib/highlight.ts +1 -1
- package/src/lib/menu-item.tsx +1 -1
- package/src/lib/state-dictionary.ts +2 -3
- package/src/lib/tint-recipes.ts +10 -5
- package/src/lib/utils.ts +19 -1
- package/src/lib/dialog-padding.ts +0 -48
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useFormatSettings } from '@vendure-io/ui/components/molecules/format-provider';
|
|
4
|
+
import { SkeletonLine } from '@vendure-io/ui/components/molecules/state-views/skeleton-parts';
|
|
4
5
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
5
|
-
import type { ComponentProps } from 'react';
|
|
6
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
7
|
+
import { isDevelopment } from '../../lib/env.ts';
|
|
8
|
+
import { useMessages } from '../../lib/format-messages.ts';
|
|
6
9
|
|
|
7
10
|
// How many minor-unit digits a currency uses — 2 for USD (cents), 0 for JPY, 3
|
|
8
11
|
// for BHD. Derived from Intl rather than a hardcoded `/100`, which is wrong for
|
|
@@ -25,8 +28,16 @@ function currencyFractionDigits(currency?: string): number {
|
|
|
25
28
|
let warnedMissingCurrency = false;
|
|
26
29
|
|
|
27
30
|
interface MoneyProps extends ComponentProps<'span'> {
|
|
28
|
-
/**
|
|
29
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Amount in integer minor units (Vendure convention), e.g. `2500` = $25.00.
|
|
33
|
+
* `undefined` means not loaded yet and renders a one-line skeleton; `null`
|
|
34
|
+
* means there is no amount and renders `fallback`. `0` is a real amount.
|
|
35
|
+
*/
|
|
36
|
+
value: number | null | undefined;
|
|
37
|
+
/** Rendered when `value` is `null`. @default "—" */
|
|
38
|
+
fallback?: ReactNode;
|
|
39
|
+
/** Screen-reader text while `value` is `undefined`. @default `messages.money.loading`, "Loading amount" */
|
|
40
|
+
loadingLabel?: string;
|
|
30
41
|
/** ISO 4217 code. Falls back to `FormatProvider`'s `currency`. */
|
|
31
42
|
currency?: string;
|
|
32
43
|
/** BCP 47 locale. Falls back to `FormatProvider`, then the runtime default. */
|
|
@@ -47,6 +58,8 @@ interface MoneyProps extends ComponentProps<'span'> {
|
|
|
47
58
|
*/
|
|
48
59
|
function Money({
|
|
49
60
|
value,
|
|
61
|
+
fallback = '—',
|
|
62
|
+
loadingLabel,
|
|
50
63
|
currency,
|
|
51
64
|
locale,
|
|
52
65
|
precision,
|
|
@@ -55,12 +68,41 @@ function Money({
|
|
|
55
68
|
...props
|
|
56
69
|
}: MoneyProps) {
|
|
57
70
|
const settings = useFormatSettings();
|
|
71
|
+
const t = useMessages('money', { loading: loadingLabel });
|
|
72
|
+
|
|
73
|
+
// The skeleton is a typical amount wide ("$1,234.56" in tabular digits) and
|
|
74
|
+
// one line box tall, so the line does not move when the amount arrives.
|
|
75
|
+
if (value === undefined) {
|
|
76
|
+
return (
|
|
77
|
+
<span
|
|
78
|
+
data-slot="money"
|
|
79
|
+
aria-busy="true"
|
|
80
|
+
className={cn('inline-flex w-[9ch] max-w-full tabular-nums', className)}
|
|
81
|
+
{...props}
|
|
82
|
+
>
|
|
83
|
+
{/* A zero-width space gives the skeleton a text baseline, so a
|
|
84
|
+
baseline-aligned row does not grow when it loads. */}
|
|
85
|
+
<span aria-hidden="true">{'\u200b'}</span>
|
|
86
|
+
<SkeletonLine />
|
|
87
|
+
<span className="sr-only">{t.loading}</span>
|
|
88
|
+
</span>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (value === null) {
|
|
93
|
+
return (
|
|
94
|
+
<span data-slot="money" className={cn('tabular-nums', className)} {...props}>
|
|
95
|
+
{fallback}
|
|
96
|
+
</span>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
58
100
|
const resolvedCurrency = currency ?? settings.currency;
|
|
59
101
|
const resolvedLocale = locale ?? settings.locale;
|
|
60
102
|
const resolvedPrecision =
|
|
61
103
|
precision ?? settings.currencyPrecision ?? currencyFractionDigits(resolvedCurrency);
|
|
62
104
|
|
|
63
|
-
if (!resolvedCurrency && !warnedMissingCurrency &&
|
|
105
|
+
if (!resolvedCurrency && !warnedMissingCurrency && isDevelopment) {
|
|
64
106
|
warnedMissingCurrency = true;
|
|
65
107
|
console.warn(
|
|
66
108
|
'<Money> was rendered without a `currency` prop or a `FormatProvider` currency; ' +
|
|
@@ -8,8 +8,12 @@ import {
|
|
|
8
8
|
SelectTrigger,
|
|
9
9
|
SelectValue,
|
|
10
10
|
} from '@vendure-io/ui/components/atoms/select';
|
|
11
|
+
import { SkeletonLine } from '@vendure-io/ui/components/molecules/state-views/skeleton-parts';
|
|
11
12
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
13
|
+
import { Loader2Icon } from 'lucide-react';
|
|
12
14
|
import * as React from 'react';
|
|
15
|
+
import { isDevelopment } from '../../lib/env.ts';
|
|
16
|
+
import { useMessages } from '../../lib/format-messages.ts';
|
|
13
17
|
|
|
14
18
|
type ItemValue = string | number;
|
|
15
19
|
|
|
@@ -25,8 +29,18 @@ function resolveAccessor<T, R>(item: T, accessor: Accessor<T, R>): R {
|
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
export interface MultiSelectProps<T> {
|
|
28
|
-
/**
|
|
29
|
-
|
|
32
|
+
/**
|
|
33
|
+
* The list of options to choose from. `undefined` means the options are
|
|
34
|
+
* still loading: a selected value shows as a skeleton in the trigger (its
|
|
35
|
+
* label is not known yet), and the open list shows a loading row, one
|
|
36
|
+
* option tall. `[]` means there are no options.
|
|
37
|
+
*/
|
|
38
|
+
items: readonly T[] | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Announced while `items` is `undefined`.
|
|
41
|
+
* @default `messages.multiSelect.loading`, "Loading…"
|
|
42
|
+
*/
|
|
43
|
+
loadingLabel?: string;
|
|
30
44
|
/**
|
|
31
45
|
* How to render each option's label. Pass a property key for the common case
|
|
32
46
|
* (`itemToLabel="name"`), or a function for full control
|
|
@@ -74,6 +88,7 @@ export interface MultiSelectProps<T> {
|
|
|
74
88
|
|
|
75
89
|
function MultiSelect<T>({
|
|
76
90
|
items,
|
|
91
|
+
loadingLabel,
|
|
77
92
|
itemToLabel = String as unknown as Accessor<T, React.ReactNode>,
|
|
78
93
|
itemToValue,
|
|
79
94
|
value,
|
|
@@ -100,11 +115,14 @@ function MultiSelect<T>({
|
|
|
100
115
|
[itemToLabel],
|
|
101
116
|
);
|
|
102
117
|
|
|
118
|
+
const t = useMessages('multiSelect', { loading: loadingLabel });
|
|
119
|
+
const isLoading = items === undefined;
|
|
120
|
+
|
|
103
121
|
const itemByValue = React.useMemo(() => {
|
|
104
122
|
const map = new Map<ItemValue, T>();
|
|
105
|
-
for (const item of items) {
|
|
123
|
+
for (const item of items ?? []) {
|
|
106
124
|
const itemValue = getValue(item);
|
|
107
|
-
if (
|
|
125
|
+
if (isDevelopment) {
|
|
108
126
|
if (typeof itemValue !== 'string' && typeof itemValue !== 'number') {
|
|
109
127
|
console.warn(
|
|
110
128
|
'MultiSelect: `itemToValue` must resolve to a string or number. When `items` are ' +
|
|
@@ -140,9 +158,22 @@ function MultiSelect<T>({
|
|
|
140
158
|
size={size}
|
|
141
159
|
className={cn('w-full', className)}
|
|
142
160
|
aria-invalid={invalid || undefined}
|
|
161
|
+
aria-busy={isLoading || undefined}
|
|
143
162
|
>
|
|
144
163
|
<SelectValue placeholder={placeholder}>
|
|
145
164
|
{(selected: ItemValue[]) => {
|
|
165
|
+
// The labels of the selected values come with the options. Until
|
|
166
|
+
// then a skeleton holds their place: the raw values are ids, not
|
|
167
|
+
// text a person reads. With nothing selected, the placeholder is
|
|
168
|
+
// already right.
|
|
169
|
+
if (isLoading && selected.length > 0) {
|
|
170
|
+
return (
|
|
171
|
+
<>
|
|
172
|
+
<SkeletonLine data-slot="multi-select-value-skeleton" className="w-24" />
|
|
173
|
+
<span className="sr-only">{t.loading}</span>
|
|
174
|
+
</>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
146
177
|
const selectedItems = selected
|
|
147
178
|
.map((v) => itemByValue.get(v))
|
|
148
179
|
.filter((item): item is T => item !== undefined);
|
|
@@ -157,17 +188,29 @@ function MultiSelect<T>({
|
|
|
157
188
|
}}
|
|
158
189
|
</SelectValue>
|
|
159
190
|
</SelectTrigger>
|
|
160
|
-
<SelectContent className={contentClassName}>
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
191
|
+
<SelectContent className={contentClassName} aria-busy={isLoading || undefined}>
|
|
192
|
+
{isLoading ? (
|
|
193
|
+
// Decorative: a listbox holds only options and groups, and the
|
|
194
|
+
// trigger is already busy. One option tall (the SelectItem height).
|
|
195
|
+
<div
|
|
196
|
+
data-slot="multi-select-loading"
|
|
197
|
+
aria-hidden="true"
|
|
198
|
+
className="text-muted-foreground flex min-h-8.5 items-center justify-center"
|
|
199
|
+
>
|
|
200
|
+
<Loader2Icon className="size-4 motion-safe:animate-spin" />
|
|
201
|
+
</div>
|
|
202
|
+
) : (
|
|
203
|
+
<SelectGroup>
|
|
204
|
+
{items.map((item) => {
|
|
205
|
+
const itemValue = getValue(item);
|
|
206
|
+
return (
|
|
207
|
+
<SelectItem key={itemValue} value={itemValue}>
|
|
208
|
+
{getLabel(item)}
|
|
209
|
+
</SelectItem>
|
|
210
|
+
);
|
|
211
|
+
})}
|
|
212
|
+
</SelectGroup>
|
|
213
|
+
)}
|
|
171
214
|
</SelectContent>
|
|
172
215
|
</Select>
|
|
173
216
|
);
|
|
@@ -2,6 +2,7 @@ import { mergeProps } from '@base-ui/react/merge-props';
|
|
|
2
2
|
import { useRender } from '@base-ui/react/use-render';
|
|
3
3
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
4
4
|
import type * as React from 'react';
|
|
5
|
+
import { warnDeprecated } from '../../lib/deprecated.ts';
|
|
5
6
|
import { DirectionLink, ExternalArrow } from './direction-link.tsx';
|
|
6
7
|
|
|
7
8
|
// Compound-only, by decision: there is no simple-props sugar and
|
|
@@ -159,9 +160,12 @@ function PageHeaderBackRow({ className, ...props }: React.ComponentProps<'div'>)
|
|
|
159
160
|
|
|
160
161
|
/**
|
|
161
162
|
* @deprecated Use `PageHeaderBackRow`, and put a `PageHeaderBack` in it for the
|
|
162
|
-
* link.
|
|
163
|
+
* link. Removed in 4.0.
|
|
163
164
|
*/
|
|
164
|
-
|
|
165
|
+
function PageHeaderBackLink(props: React.ComponentProps<'div'>) {
|
|
166
|
+
warnDeprecated('PageHeaderBackLink', 'PageHeaderBackLink', 'PageHeaderBackRow');
|
|
167
|
+
return <PageHeaderBackRow {...props} />;
|
|
168
|
+
}
|
|
165
169
|
|
|
166
170
|
/**
|
|
167
171
|
* The link up one level, above the title: "Deployments", "All profiles".
|
|
@@ -8,25 +8,26 @@ import {
|
|
|
8
8
|
} from '@vendure-io/ui/components/atoms/input-group';
|
|
9
9
|
import { VisibilityIcon } from '@vendure-io/ui/components/molecules/visibility-icon';
|
|
10
10
|
import * as React from 'react';
|
|
11
|
+
import { useMessages } from '../../lib/format-messages.ts';
|
|
11
12
|
|
|
12
13
|
export interface PasswordInputProps extends Omit<React.ComponentProps<'input'>, 'type'> {
|
|
13
|
-
/** Accessible label for the reveal toggle while the password is hidden. */
|
|
14
|
+
/** Accessible label for the reveal toggle while the password is hidden. @default `messages.passwordInput.showPassword`, "Show password" */
|
|
14
15
|
showPasswordLabel?: string;
|
|
15
|
-
/** Accessible label for the reveal toggle while the password is shown. */
|
|
16
|
+
/** Accessible label for the reveal toggle while the password is shown. @default `messages.passwordInput.hidePassword`, "Hide password" */
|
|
16
17
|
hidePasswordLabel?: string;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* A password field with a show/hide toggle, composed from the InputGroup atoms.
|
|
21
|
-
* Toggle labels
|
|
22
|
-
*
|
|
22
|
+
* Toggle labels come from `FormatProvider`'s `messages`; the label props win
|
|
23
|
+
* over them.
|
|
23
24
|
*/
|
|
24
|
-
function PasswordInput({
|
|
25
|
-
showPasswordLabel = 'Show password',
|
|
26
|
-
hidePasswordLabel = 'Hide password',
|
|
27
|
-
...props
|
|
28
|
-
}: PasswordInputProps) {
|
|
25
|
+
function PasswordInput({ showPasswordLabel, hidePasswordLabel, ...props }: PasswordInputProps) {
|
|
29
26
|
const [showPassword, setShowPassword] = React.useState(false);
|
|
27
|
+
const t = useMessages('passwordInput', {
|
|
28
|
+
showPassword: showPasswordLabel,
|
|
29
|
+
hidePassword: hidePasswordLabel,
|
|
30
|
+
});
|
|
30
31
|
|
|
31
32
|
return (
|
|
32
33
|
<InputGroup>
|
|
@@ -35,7 +36,7 @@ function PasswordInput({
|
|
|
35
36
|
<InputGroupButton
|
|
36
37
|
size="icon-xs"
|
|
37
38
|
onClick={() => setShowPassword((prev) => !prev)}
|
|
38
|
-
aria-label={showPassword ?
|
|
39
|
+
aria-label={showPassword ? t.hidePassword : t.showPassword}
|
|
39
40
|
>
|
|
40
41
|
<VisibilityIcon visible={!showPassword} />
|
|
41
42
|
</InputGroupButton>
|
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useFormatSettings } from '@vendure-io/ui/components/molecules/format-provider';
|
|
4
|
+
import { cn } from '@vendure-io/ui/lib/utils';
|
|
5
|
+
import { type ComponentProps, type ReactNode, useEffect, useId, useState } from 'react';
|
|
6
|
+
import { warnDeprecated } from '../../lib/deprecated.ts';
|
|
7
|
+
import { useMessages } from '../../lib/format-messages.ts';
|
|
4
8
|
import {
|
|
5
9
|
type FormatRelativeOptions,
|
|
6
10
|
formatRelative,
|
|
7
11
|
formatRelativeDuration,
|
|
8
|
-
} from '
|
|
9
|
-
import { cn } from '@vendure-io/ui/lib/utils';
|
|
10
|
-
import { type ComponentProps, type ReactNode, useEffect, useId, useState } from 'react';
|
|
12
|
+
} from '../../lib/format-relative.ts';
|
|
11
13
|
// Relative: `time-tooltip` is internal.
|
|
12
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
sampleText,
|
|
16
|
+
TimeSkeleton,
|
|
17
|
+
TimeSpan,
|
|
18
|
+
TimeTooltip,
|
|
19
|
+
toTime,
|
|
20
|
+
useReadersClock,
|
|
21
|
+
} from './time-tooltip.tsx';
|
|
13
22
|
|
|
14
23
|
interface RelativeTimeProps extends Omit<ComponentProps<'time'>, 'dateTime'> {
|
|
24
|
+
/**
|
|
25
|
+
* The time the text describes, and the end of the range with `from`.
|
|
26
|
+
* `undefined` means not loaded yet and renders a one-line skeleton. `null`
|
|
27
|
+
* and an invalid date render `fallback`.
|
|
28
|
+
*/
|
|
15
29
|
value: string | number | Date | null | undefined;
|
|
16
30
|
locale?: string;
|
|
17
31
|
numeric?: 'auto' | 'always';
|
|
@@ -23,11 +37,13 @@ interface RelativeTimeProps extends Omit<ComponentProps<'time'>, 'dateTime'> {
|
|
|
23
37
|
*/
|
|
24
38
|
updateInterval?: number | false;
|
|
25
39
|
/**
|
|
26
|
-
* Rendered for
|
|
27
|
-
* render of a server-rendered page (the server has no reader's
|
|
28
|
-
* Default `'—'`.
|
|
40
|
+
* Rendered for `null` and invalid input, and on the server and the first
|
|
41
|
+
* client render of a server-rendered page (the server has no reader's
|
|
42
|
+
* clock). Default `'—'`.
|
|
29
43
|
*/
|
|
30
44
|
fallback?: ReactNode;
|
|
45
|
+
/** Screen-reader text while `value` is `undefined`. @default `messages.relativeTime.loading`, "Loading time" */
|
|
46
|
+
loadingLabel?: string;
|
|
31
47
|
/**
|
|
32
48
|
* What the text says.
|
|
33
49
|
* - `relative` (default): how long ago or how far ahead: `2 minutes ago`.
|
|
@@ -39,13 +55,15 @@ interface RelativeTimeProps extends Omit<ComponentProps<'time'>, 'dateTime'> {
|
|
|
39
55
|
display?: 'relative' | 'duration';
|
|
40
56
|
/**
|
|
41
57
|
* When the thing that ended at `value` started. The default tooltip then
|
|
42
|
-
* shows the range from `
|
|
58
|
+
* shows the range from `from` to `value` and how long it took:
|
|
43
59
|
* `11/11/2026, 10:14:47 – 10:15:29 AM` over `42s`.
|
|
44
60
|
*/
|
|
61
|
+
from?: string | number | Date | null;
|
|
62
|
+
/** @deprecated Use `from`. Removed in 4.0. */
|
|
45
63
|
start?: string | number | Date | null;
|
|
46
64
|
/**
|
|
47
65
|
* The tooltip on hover and focus. Default `true`: the absolute time (or the
|
|
48
|
-
* range, with `
|
|
66
|
+
* range, with `from`). Pass content to show that instead, or `false` where
|
|
49
67
|
* the time sits inside another tooltip trigger, so the outer tooltip keeps
|
|
50
68
|
* its content. The tooltip content stays the accessible description either
|
|
51
69
|
* way.
|
|
@@ -81,14 +99,19 @@ function RelativeTime({
|
|
|
81
99
|
unitStyle,
|
|
82
100
|
updateInterval = 60_000,
|
|
83
101
|
fallback = '—',
|
|
102
|
+
loadingLabel,
|
|
84
103
|
display = 'relative',
|
|
104
|
+
from: fromProp,
|
|
85
105
|
start,
|
|
86
106
|
tooltip = true,
|
|
87
107
|
focusable,
|
|
88
108
|
...props
|
|
89
109
|
}: RelativeTimeProps) {
|
|
110
|
+
if (start !== undefined) warnDeprecated('RelativeTime', 'start', 'from');
|
|
111
|
+
const from = fromProp !== undefined ? fromProp : start;
|
|
90
112
|
const descriptionId = useId();
|
|
91
113
|
const settings = useFormatSettings();
|
|
114
|
+
const t = useMessages('relativeTime', { loading: loadingLabel });
|
|
92
115
|
// A bare counter to force a re-format on each tick; the value itself is unused.
|
|
93
116
|
const [, tick] = useState(0);
|
|
94
117
|
|
|
@@ -103,10 +126,37 @@ function RelativeTime({
|
|
|
103
126
|
return () => clearInterval(id);
|
|
104
127
|
}, [updateInterval, hasDate]);
|
|
105
128
|
|
|
129
|
+
const resolvedLocale = locale ?? settings.locale;
|
|
130
|
+
|
|
131
|
+
if (value === undefined) {
|
|
132
|
+
// A typical text: "12 minutes ago", or "13 days" for a duration.
|
|
133
|
+
const sample =
|
|
134
|
+
display === 'duration'
|
|
135
|
+
? sampleText(
|
|
136
|
+
() =>
|
|
137
|
+
new Intl.NumberFormat(resolvedLocale, {
|
|
138
|
+
style: 'unit',
|
|
139
|
+
unit: 'day',
|
|
140
|
+
unitDisplay: unitStyle ?? 'long',
|
|
141
|
+
}).format(13),
|
|
142
|
+
'13 days',
|
|
143
|
+
)
|
|
144
|
+
: sampleText(
|
|
145
|
+
() =>
|
|
146
|
+
new Intl.RelativeTimeFormat(resolvedLocale, { numeric, style: unitStyle }).format(
|
|
147
|
+
-12,
|
|
148
|
+
'minute',
|
|
149
|
+
),
|
|
150
|
+
'12 minutes ago',
|
|
151
|
+
);
|
|
152
|
+
return (
|
|
153
|
+
<TimeSkeleton slot="relative-time" sample={sample} loadingLabel={t.loading} {...props} />
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
106
157
|
if (!date) return <>{fallback}</>;
|
|
107
158
|
|
|
108
|
-
const
|
|
109
|
-
const startTime = toTime(start);
|
|
159
|
+
const startTime = toTime(from);
|
|
110
160
|
const absolute =
|
|
111
161
|
startTime === null ? (
|
|
112
162
|
date.toLocaleString(resolvedLocale, { timeZone: settings.timeZone })
|
|
@@ -154,12 +204,34 @@ function RelativeTime({
|
|
|
154
204
|
);
|
|
155
205
|
}
|
|
156
206
|
|
|
157
|
-
//
|
|
158
|
-
//
|
|
207
|
+
// The 3.0.0-next.0 import surface re-exported the format helpers from here.
|
|
208
|
+
// They live in `@vendure-io/ui/lib/format-relative`. Remove these in 4.0.
|
|
209
|
+
const relativeTimeModule = 'molecules/relative-time';
|
|
210
|
+
const libPath = '`@vendure-io/ui/lib/format-relative`';
|
|
211
|
+
|
|
212
|
+
/** @deprecated Import `formatRelative` from `@vendure-io/ui/lib/format-relative`. Removed in 4.0. */
|
|
213
|
+
const deprecatedFormatRelative: typeof formatRelative = (...args) => {
|
|
214
|
+
warnDeprecated(relativeTimeModule, 'formatRelative', `formatRelative from ${libPath}`);
|
|
215
|
+
return formatRelative(...args);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/** @deprecated Import `formatRelativeDuration` from `@vendure-io/ui/lib/format-relative`. Removed in 4.0. */
|
|
219
|
+
const deprecatedFormatRelativeDuration: typeof formatRelativeDuration = (...args) => {
|
|
220
|
+
warnDeprecated(
|
|
221
|
+
relativeTimeModule,
|
|
222
|
+
'formatRelativeDuration',
|
|
223
|
+
`formatRelativeDuration from ${libPath}`,
|
|
224
|
+
);
|
|
225
|
+
return formatRelativeDuration(...args);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/** @deprecated Import `FormatRelativeOptions` from `@vendure-io/ui/lib/format-relative`. Removed in 4.0. */
|
|
229
|
+
type DeprecatedFormatRelativeOptions = FormatRelativeOptions;
|
|
230
|
+
|
|
159
231
|
export {
|
|
160
232
|
RelativeTime,
|
|
161
|
-
formatRelative,
|
|
162
|
-
formatRelativeDuration,
|
|
163
233
|
type RelativeTimeProps,
|
|
164
|
-
|
|
234
|
+
deprecatedFormatRelative as formatRelative,
|
|
235
|
+
deprecatedFormatRelativeDuration as formatRelativeDuration,
|
|
236
|
+
type DeprecatedFormatRelativeOptions as FormatRelativeOptions,
|
|
165
237
|
};
|
|
@@ -5,6 +5,7 @@ import { useIsApplePlatform } from '@vendure-io/ui/hooks/use-apple-platform';
|
|
|
5
5
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
6
6
|
import { SearchIcon } from 'lucide-react';
|
|
7
7
|
import type * as React from 'react';
|
|
8
|
+
import { useMessages } from '../../lib/format-messages.ts';
|
|
8
9
|
|
|
9
10
|
type SearchTriggerCollapse = 'md' | 'never' | 'always';
|
|
10
11
|
|
|
@@ -40,7 +41,7 @@ const collapseClasses: Record<SearchTriggerCollapse, { box: string; hidden: stri
|
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
interface SearchTriggerProps extends Omit<React.ComponentProps<'button'>, 'children'> {
|
|
43
|
-
/** The placeholder word in the field. @default 'Search' */
|
|
44
|
+
/** The placeholder word in the field. @default `messages.searchTrigger.label`, 'Search' */
|
|
44
45
|
label?: string;
|
|
45
46
|
/**
|
|
46
47
|
* The letter of the shortcut that opens the palette. The trigger shows it
|
|
@@ -66,13 +67,14 @@ interface SearchTriggerProps extends Omit<React.ComponentProps<'button'>, 'child
|
|
|
66
67
|
*/
|
|
67
68
|
function SearchTrigger({
|
|
68
69
|
className,
|
|
69
|
-
label
|
|
70
|
+
label: labelProp,
|
|
70
71
|
shortcutKey = 'K',
|
|
71
72
|
collapse = 'md',
|
|
72
73
|
'aria-label': ariaLabel,
|
|
73
74
|
...props
|
|
74
75
|
}: SearchTriggerProps) {
|
|
75
76
|
const apple = useIsApplePlatform();
|
|
77
|
+
const { label, commandPalette } = useMessages('searchTrigger', { label: labelProp });
|
|
76
78
|
const { box, hidden } = collapseClasses[collapse];
|
|
77
79
|
|
|
78
80
|
return (
|
|
@@ -80,7 +82,7 @@ function SearchTrigger({
|
|
|
80
82
|
type="button"
|
|
81
83
|
data-slot="search-trigger"
|
|
82
84
|
aria-haspopup="dialog"
|
|
83
|
-
aria-label={ariaLabel ?? `${label} (
|
|
85
|
+
aria-label={ariaLabel ?? `${label} (${commandPalette})`}
|
|
84
86
|
aria-keyshortcuts={
|
|
85
87
|
shortcutKey ? `${apple ? 'Meta' : 'Control'}+${shortcutKey.toUpperCase()}` : undefined
|
|
86
88
|
}
|
|
@@ -6,11 +6,12 @@ import {
|
|
|
6
6
|
CopyButton,
|
|
7
7
|
type CopyButtonProps,
|
|
8
8
|
} from '@vendure-io/ui/components/molecules/copyable-text';
|
|
9
|
-
import { chipChromeClass, chipIconButtonClass } from '@vendure-io/ui/components/molecules/id-chip';
|
|
10
9
|
import { VisibilityIcon } from '@vendure-io/ui/components/molecules/visibility-icon';
|
|
11
10
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
12
11
|
import type * as React from 'react';
|
|
13
12
|
import { useReducer, useRef } from 'react';
|
|
13
|
+
import { useMessages } from '../../lib/format-messages.ts';
|
|
14
|
+
import { chipChromeClass, chipIconButtonClass } from './id-chip-chrome.tsx';
|
|
14
15
|
|
|
15
16
|
interface SecretValueProps extends Omit<React.ComponentProps<'span'>, 'children'> {
|
|
16
17
|
/**
|
|
@@ -39,6 +40,11 @@ interface SecretValueProps extends Omit<React.ComponentProps<'span'>, 'children'
|
|
|
39
40
|
copiedLabel?: CopyButtonProps['copiedLabel'];
|
|
40
41
|
/** Shown inline when `loadValue` rejects. @default "Couldn't load the value." */
|
|
41
42
|
loadErrorMessage?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Screen-reader text of the spinner while the value loads.
|
|
45
|
+
* @default `messages.secretValue.loading`, "Loading"
|
|
46
|
+
*/
|
|
47
|
+
loadingLabel?: string;
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
const MASK = '••••••••';
|
|
@@ -99,9 +105,11 @@ function SecretValue({
|
|
|
99
105
|
copyLabel = 'Copy value',
|
|
100
106
|
copiedLabel = 'Value copied',
|
|
101
107
|
loadErrorMessage = "Couldn't load the value.",
|
|
108
|
+
loadingLabel,
|
|
102
109
|
className,
|
|
103
110
|
...props
|
|
104
111
|
}: SecretValueProps) {
|
|
112
|
+
const t = useMessages('secretValue', { loading: loadingLabel });
|
|
105
113
|
const [state, dispatch] = useReducer(revealReducer, { status: 'hidden' });
|
|
106
114
|
// Drops a load that settles after the user hid the value or asked again.
|
|
107
115
|
const request = useRef(0);
|
|
@@ -171,7 +179,7 @@ function SecretValue({
|
|
|
171
179
|
else void reveal();
|
|
172
180
|
}}
|
|
173
181
|
>
|
|
174
|
-
{loading ? <Spinner /> : <VisibilityIcon visible={!revealed} />}
|
|
182
|
+
{loading ? <Spinner aria-label={t.loading} /> : <VisibilityIcon visible={!revealed} />}
|
|
175
183
|
</Button>
|
|
176
184
|
{copyable ? (
|
|
177
185
|
<CopyButton
|