@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.
Files changed (89) hide show
  1. package/package.json +12 -11
  2. package/src/components/atoms/alert-dialog.tsx +1 -4
  3. package/src/components/atoms/alert.tsx +59 -35
  4. package/src/components/atoms/badge.tsx +2 -2
  5. package/src/components/atoms/breadcrumb.tsx +154 -59
  6. package/src/components/atoms/button-group.tsx +1 -1
  7. package/src/components/atoms/button.tsx +2 -2
  8. package/src/components/atoms/calendar.tsx +2 -2
  9. package/src/components/atoms/card.tsx +15 -2
  10. package/src/components/atoms/carousel.tsx +33 -7
  11. package/src/components/atoms/chart.tsx +3 -3
  12. package/src/components/atoms/checkbox.tsx +1 -1
  13. package/src/components/atoms/combobox.tsx +60 -36
  14. package/src/components/atoms/command.tsx +17 -7
  15. package/src/components/atoms/context-menu.tsx +5 -5
  16. package/src/components/atoms/dialog.tsx +30 -14
  17. package/src/components/atoms/dropdown-menu.tsx +1 -1
  18. package/src/components/atoms/hover-card.tsx +1 -1
  19. package/src/components/atoms/input-group.tsx +30 -12
  20. package/src/components/atoms/input-otp.tsx +2 -2
  21. package/src/components/atoms/input.tsx +13 -3
  22. package/src/components/atoms/menubar.tsx +2 -2
  23. package/src/components/atoms/native-select.tsx +1 -1
  24. package/src/components/atoms/navigation-menu.tsx +3 -3
  25. package/src/components/atoms/pagination.tsx +52 -15
  26. package/src/components/atoms/popover.tsx +1 -1
  27. package/src/components/atoms/select.tsx +3 -3
  28. package/src/components/atoms/sheet.tsx +35 -15
  29. package/src/components/atoms/sidebar.tsx +224 -36
  30. package/src/components/atoms/skeleton.tsx +6 -3
  31. package/src/components/atoms/spinner.tsx +7 -2
  32. package/src/components/atoms/tabs.tsx +6 -2
  33. package/src/components/atoms/textarea.tsx +1 -1
  34. package/src/components/atoms/toggle.tsx +1 -1
  35. package/src/components/molecules/action-needed.tsx +483 -0
  36. package/src/components/molecules/anonymized-token.tsx +70 -25
  37. package/src/components/molecules/app-shell.tsx +14 -5
  38. package/src/components/molecules/checklist/checklist.tsx +47 -17
  39. package/src/components/molecules/chip.tsx +37 -19
  40. package/src/components/molecules/choice-card.tsx +117 -9
  41. package/src/components/molecules/code-block/package-manager-storage.ts +50 -0
  42. package/src/components/molecules/code-block/process-code.ts +1 -1
  43. package/src/components/molecules/code-block.tsx +58 -47
  44. package/src/components/molecules/combobox-free-text.tsx +75 -20
  45. package/src/components/molecules/confirm-dialog.tsx +17 -5
  46. package/src/components/molecules/copyable-text.tsx +10 -8
  47. package/src/components/molecules/data-table/data-table-filters.tsx +36 -6
  48. package/src/components/molecules/data-table/data-table-helpers.tsx +109 -3
  49. package/src/components/molecules/data-table/data-table-row-count-storage.tsx +88 -0
  50. package/src/components/molecules/data-table/data-table-selection-storage.tsx +33 -15
  51. package/src/components/molecules/data-table/data-table-types.tsx +156 -29
  52. package/src/components/molecules/data-table/data-table-view-options.tsx +14 -4
  53. package/src/components/molecules/data-table/data-table.tsx +156 -75
  54. package/src/components/molecules/data-table/table-pagination.tsx +142 -38
  55. package/src/components/molecules/date-picker.tsx +58 -25
  56. package/src/components/molecules/date-range-picker.tsx +59 -24
  57. package/src/components/molecules/date-time-picker.tsx +63 -25
  58. package/src/components/molecules/date-time.tsx +38 -3
  59. package/src/components/molecules/elapsed-time.tsx +61 -12
  60. package/src/components/molecules/file-dropzone.tsx +151 -40
  61. package/src/components/molecules/format-provider.tsx +14 -4
  62. package/src/components/molecules/id-chip-chrome.tsx +114 -0
  63. package/src/components/molecules/id-chip.tsx +13 -115
  64. package/src/components/molecules/issued-secret.tsx +35 -25
  65. package/src/components/molecules/live-indicator.tsx +1 -1
  66. package/src/components/molecules/money.tsx +44 -3
  67. package/src/components/molecules/multi-select.tsx +62 -16
  68. package/src/components/molecules/page-header.tsx +6 -2
  69. package/src/components/molecules/password-input.tsx +11 -10
  70. package/src/components/molecules/relative-time.tsx +88 -16
  71. package/src/components/molecules/search-trigger.tsx +5 -3
  72. package/src/components/molecules/secret-value.tsx +35 -19
  73. package/src/components/molecules/skip-link.tsx +11 -9
  74. package/src/components/molecules/stat-card.tsx +145 -33
  75. package/src/components/molecules/state-views/empty-state.tsx +16 -12
  76. package/src/components/molecules/state-views/error-state.tsx +36 -20
  77. package/src/components/molecules/state-views/loading-state.tsx +18 -6
  78. package/src/components/molecules/state-views/skeleton-parts.tsx +6 -4
  79. package/src/components/molecules/status-badge.tsx +11 -35
  80. package/src/components/molecules/time-tooltip.tsx +55 -1
  81. package/src/hooks/use-copy.ts +3 -1
  82. package/src/lib/deprecated.ts +71 -0
  83. package/src/lib/field-surface.ts +7 -7
  84. package/src/lib/format-messages.ts +368 -0
  85. package/src/lib/highlight.ts +1 -1
  86. package/src/lib/menu-item.tsx +1 -1
  87. package/src/lib/tint-recipes.ts +10 -5
  88. package/src/lib/utils.ts +19 -1
  89. package/src/lib/dialog-padding.ts +0 -48
@@ -9,6 +9,7 @@ import { CopyStateIcon, useCopyAction } from '@vendure-io/ui/components/molecule
9
9
  import { cn } from '@vendure-io/ui/lib/utils';
10
10
  import type * as React from 'react';
11
11
  import { useEffect, useId, useRef, useState } from 'react';
12
+ import { fillMessage, useMessages } from '../../lib/format-messages.ts';
12
13
 
13
14
  /**
14
15
  * The close guard of a dialog that holds a secret that was just issued. Before
@@ -61,21 +62,21 @@ interface IssuedSecretOwnProps {
61
62
  name?: React.ReactNode;
62
63
  /** Values of the issue that are not secret, for example a sign-in name. */
63
64
  children?: React.ReactNode;
64
- /** Text of the copy button when there is one value. @default `Copy ${secretName}` */
65
+ /** Text of the copy button when there is one value. @default `messages.issuedSecret.copy`, "Copy {secret}", with `{secret}` the `secretName` */
65
66
  copyLabel?: string;
66
- /** Text of a copy button just after a copy. @default "Copied" */
67
+ /** Text of a copy button just after a copy. @default `messages.issuedSecret.copied`, "Copied" */
67
68
  copiedLabel?: string;
68
- /** The line under the buttons. @default `You can copy the ${secretName} only now.` */
69
+ /** The line under the buttons. @default `messages.issuedSecret.notice`, "You can copy the {secret} only now." */
69
70
  notice?: React.ReactNode;
70
71
  /** Label of the field that shows the value when the clipboard fails. @default secretName, capitalised */
71
72
  fallbackLabel?: string;
72
- /** @default `The clipboard is not available. Select the ${secretName} and copy it by hand.` */
73
+ /** @default `messages.issuedSecret.fallbackDescription`, "The clipboard is not available. Select the {secret} and copy it by hand." */
73
74
  fallbackDescription?: React.ReactNode;
74
75
  /** Classes for that field, for example a session replay mask class. */
75
76
  fallbackInputClassName?: string;
76
- /** @default `The ${secretName} is not copied` */
77
+ /** @default `messages.issuedSecret.warningTitle`, "The {secret} is not copied" */
77
78
  warningTitle?: React.ReactNode;
78
- /** @default "You cannot copy it after you close. Copy it now, or close without copying." */
79
+ /** @default `messages.issuedSecret.warningDescription`, "You cannot copy it after you close. Copy it now, or close without copying." */
79
80
  warningDescription?: React.ReactNode;
80
81
  /** Called after a copy by a button. Falls back to `CopyFeedbackProvider`. */
81
82
  onCopied?: () => void;
@@ -112,25 +113,27 @@ function IssuedSecret({
112
113
  children,
113
114
  value,
114
115
  formats,
115
- copyLabel = `Copy ${secretName}`,
116
- copiedLabel = 'Copied',
117
- notice = `You can copy the ${secretName} only now.`,
116
+ copyLabel,
117
+ copiedLabel,
118
+ notice,
118
119
  fallbackLabel = capitalize(secretName),
119
- fallbackDescription = `The clipboard is not available. Select the ${secretName} and copy it by hand.`,
120
+ fallbackDescription,
120
121
  fallbackInputClassName,
121
- warningTitle = `The ${secretName} is not copied`,
122
- warningDescription = 'You cannot copy it after you close. Copy it now, or close without copying.',
122
+ warningTitle,
123
+ warningDescription,
123
124
  onCopied,
124
125
  onCopyError,
125
126
  className,
126
127
  ...props
127
128
  }: IssuedSecretProps) {
129
+ const t = useMessages('issuedSecret', { copy: copyLabel, copied: copiedLabel });
130
+ const named = (text: string) => fillMessage(text, { secret: secretName });
128
131
  // The text of the copy the clipboard refused. It contains the secret.
129
132
  const [manual, setManual] = useState<string | null>(null);
130
133
  const firstButton = useRef<HTMLButtonElement>(null);
131
134
  const field = useRef<HTMLInputElement>(null);
132
135
  const fieldId = useId();
133
- const buttons = formats ?? [{ label: copyLabel, value: value ?? '' }];
136
+ const buttons = formats ?? [{ label: named(t.copy), value: value ?? '' }];
134
137
 
135
138
  useEffect(() => {
136
139
  firstButton.current?.focus();
@@ -172,7 +175,7 @@ function IssuedSecret({
172
175
  key={format.label}
173
176
  ref={index === 0 ? firstButton : undefined}
174
177
  format={format}
175
- copiedLabel={copiedLabel}
178
+ copiedLabel={t.copied}
176
179
  // One primary until the first copy; then Done takes it.
177
180
  variant={index === 0 && !guard.copied ? 'default' : 'outline'}
178
181
  onCopied={() => {
@@ -185,7 +188,7 @@ function IssuedSecret({
185
188
  />
186
189
  ))}
187
190
  <p data-slot="issued-secret-notice" className="text-muted-foreground text-xs">
188
- {notice}
191
+ {notice !== undefined ? notice : named(t.notice)}
189
192
  </p>
190
193
  </div>
191
194
  {manual !== null ? (
@@ -202,13 +205,19 @@ function IssuedSecret({
202
205
  onFocus={(event) => event.currentTarget.select()}
203
206
  onCopy={guard.markCopied}
204
207
  />
205
- <FieldDescription>{fallbackDescription}</FieldDescription>
208
+ <FieldDescription>
209
+ {fallbackDescription !== undefined ? fallbackDescription : named(t.fallbackDescription)}
210
+ </FieldDescription>
206
211
  </Field>
207
212
  ) : null}
208
213
  {guard.warned ? (
209
- <Alert data-slot="issued-secret-warning" variant="warning">
210
- <AlertTitle>{warningTitle}</AlertTitle>
211
- <AlertDescription>{warningDescription}</AlertDescription>
214
+ <Alert data-slot="issued-secret-warning" tone="warning">
215
+ <AlertTitle>
216
+ {warningTitle !== undefined ? warningTitle : named(t.warningTitle)}
217
+ </AlertTitle>
218
+ <AlertDescription>
219
+ {warningDescription !== undefined ? warningDescription : t.warningDescription}
220
+ </AlertDescription>
212
221
  </Alert>
213
222
  ) : null}
214
223
  </section>
@@ -266,9 +275,9 @@ interface IssuedSecretFooterProps
266
275
  extends Omit<React.ComponentProps<typeof DialogFooter>, 'children'> {
267
276
  /** The guard from `useIssuedSecretGuard`, shared with `IssuedSecret`. */
268
277
  guard: IssuedSecretGuard;
269
- /** @default "Done" */
278
+ /** @default `messages.issuedSecret.done`, "Done" */
270
279
  doneLabel?: string;
271
- /** The second action after the warning. @default "Close without copying" */
280
+ /** The second action after the warning. @default `messages.issuedSecret.closeAnyway`, "Close without copying" */
272
281
  closeAnywayLabel?: string;
273
282
  }
274
283
 
@@ -279,10 +288,11 @@ interface IssuedSecretFooterProps
279
288
  */
280
289
  function IssuedSecretFooter({
281
290
  guard,
282
- doneLabel = 'Done',
283
- closeAnywayLabel = 'Close without copying',
291
+ doneLabel,
292
+ closeAnywayLabel,
284
293
  ...props
285
294
  }: IssuedSecretFooterProps) {
295
+ const t = useMessages('issuedSecret', { done: doneLabel, closeAnyway: closeAnywayLabel });
286
296
  return (
287
297
  <DialogFooter data-slot="issued-secret-footer" {...props}>
288
298
  {guard.warned ? (
@@ -293,7 +303,7 @@ function IssuedSecretFooter({
293
303
  variant="destructive-outline"
294
304
  onClick={guard.closeAnyway}
295
305
  >
296
- {closeAnywayLabel}
306
+ {t.closeAnyway}
297
307
  </Button>
298
308
  ) : (
299
309
  <Button
@@ -303,7 +313,7 @@ function IssuedSecretFooter({
303
313
  variant={guard.copied ? 'default' : 'outline'}
304
314
  onClick={guard.requestClose}
305
315
  >
306
- {doneLabel}
316
+ {t.done}
307
317
  </Button>
308
318
  )}
309
319
  </DialogFooter>
@@ -1,7 +1,7 @@
1
1
  import type { Tone } from '@vendure-io/ui/lib/state-dictionary';
2
- import { statusToneText } from '@vendure-io/ui/lib/tint-recipes';
3
2
  import { cn } from '@vendure-io/ui/lib/utils';
4
3
  import type * as React from 'react';
4
+ import { statusToneText } from '../../lib/tint-recipes.ts';
5
5
 
6
6
  // The dot fill of each tone, as in StatusBadge: a dot is a filled shape, so
7
7
  // warning takes `warning-indicator`; in `warning-text` the dot reads brown.
@@ -1,9 +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';
6
7
  import { isDevelopment } from '../../lib/env.ts';
8
+ import { useMessages } from '../../lib/format-messages.ts';
7
9
 
8
10
  // How many minor-unit digits a currency uses — 2 for USD (cents), 0 for JPY, 3
9
11
  // for BHD. Derived from Intl rather than a hardcoded `/100`, which is wrong for
@@ -26,8 +28,16 @@ function currencyFractionDigits(currency?: string): number {
26
28
  let warnedMissingCurrency = false;
27
29
 
28
30
  interface MoneyProps extends ComponentProps<'span'> {
29
- /** Amount in integer minor units (Vendure convention), e.g. `2500` = $25.00. */
30
- value: number;
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;
31
41
  /** ISO 4217 code. Falls back to `FormatProvider`'s `currency`. */
32
42
  currency?: string;
33
43
  /** BCP 47 locale. Falls back to `FormatProvider`, then the runtime default. */
@@ -48,6 +58,8 @@ interface MoneyProps extends ComponentProps<'span'> {
48
58
  */
49
59
  function Money({
50
60
  value,
61
+ fallback = '—',
62
+ loadingLabel,
51
63
  currency,
52
64
  locale,
53
65
  precision,
@@ -56,6 +68,35 @@ function Money({
56
68
  ...props
57
69
  }: MoneyProps) {
58
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
+
59
100
  const resolvedCurrency = currency ?? settings.currency;
60
101
  const resolvedLocale = locale ?? settings.locale;
61
102
  const resolvedPrecision =
@@ -8,9 +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';
13
15
  import { isDevelopment } from '../../lib/env.ts';
16
+ import { useMessages } from '../../lib/format-messages.ts';
14
17
 
15
18
  type ItemValue = string | number;
16
19
 
@@ -26,8 +29,18 @@ function resolveAccessor<T, R>(item: T, accessor: Accessor<T, R>): R {
26
29
  }
27
30
 
28
31
  export interface MultiSelectProps<T> {
29
- /** The list of options to choose from. */
30
- items: readonly T[];
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;
31
44
  /**
32
45
  * How to render each option's label. Pass a property key for the common case
33
46
  * (`itemToLabel="name"`), or a function for full control
@@ -47,7 +60,10 @@ export interface MultiSelectProps<T> {
47
60
  defaultValue?: readonly ItemValue[];
48
61
  /** Called with the next array of selected values whenever the selection changes. */
49
62
  onValueChange?: (value: ItemValue[]) => void;
50
- /** Text shown in the trigger when nothing is selected. */
63
+ /**
64
+ * Text shown in the trigger when nothing is selected.
65
+ * @default `messages.multiSelect.placeholder`, "Select…"
66
+ */
51
67
  placeholder?: React.ReactNode;
52
68
  /**
53
69
  * Override how the selected options are summarised in the trigger. Defaults
@@ -75,12 +91,13 @@ export interface MultiSelectProps<T> {
75
91
 
76
92
  function MultiSelect<T>({
77
93
  items,
94
+ loadingLabel,
78
95
  itemToLabel = String as unknown as Accessor<T, React.ReactNode>,
79
96
  itemToValue,
80
97
  value,
81
98
  defaultValue,
82
99
  onValueChange,
83
- placeholder = 'Select…',
100
+ placeholder: placeholderProp,
84
101
  renderValue,
85
102
  disabled,
86
103
  invalid,
@@ -101,9 +118,13 @@ function MultiSelect<T>({
101
118
  [itemToLabel],
102
119
  );
103
120
 
121
+ const t = useMessages('multiSelect', { loading: loadingLabel });
122
+ const placeholder = placeholderProp !== undefined ? placeholderProp : t.placeholder;
123
+ const isLoading = items === undefined;
124
+
104
125
  const itemByValue = React.useMemo(() => {
105
126
  const map = new Map<ItemValue, T>();
106
- for (const item of items) {
127
+ for (const item of items ?? []) {
107
128
  const itemValue = getValue(item);
108
129
  if (isDevelopment) {
109
130
  if (typeof itemValue !== 'string' && typeof itemValue !== 'number') {
@@ -141,9 +162,22 @@ function MultiSelect<T>({
141
162
  size={size}
142
163
  className={cn('w-full', className)}
143
164
  aria-invalid={invalid || undefined}
165
+ aria-busy={isLoading || undefined}
144
166
  >
145
167
  <SelectValue placeholder={placeholder}>
146
168
  {(selected: ItemValue[]) => {
169
+ // The labels of the selected values come with the options. Until
170
+ // then a skeleton holds their place: the raw values are ids, not
171
+ // text a person reads. With nothing selected, the placeholder is
172
+ // already right.
173
+ if (isLoading && selected.length > 0) {
174
+ return (
175
+ <>
176
+ <SkeletonLine data-slot="multi-select-value-skeleton" className="w-24" />
177
+ <span className="sr-only">{t.loading}</span>
178
+ </>
179
+ );
180
+ }
147
181
  const selectedItems = selected
148
182
  .map((v) => itemByValue.get(v))
149
183
  .filter((item): item is T => item !== undefined);
@@ -158,17 +192,29 @@ function MultiSelect<T>({
158
192
  }}
159
193
  </SelectValue>
160
194
  </SelectTrigger>
161
- <SelectContent className={contentClassName}>
162
- <SelectGroup>
163
- {items.map((item) => {
164
- const itemValue = getValue(item);
165
- return (
166
- <SelectItem key={itemValue} value={itemValue}>
167
- {getLabel(item)}
168
- </SelectItem>
169
- );
170
- })}
171
- </SelectGroup>
195
+ <SelectContent className={contentClassName} aria-busy={isLoading || undefined}>
196
+ {isLoading ? (
197
+ // Decorative: a listbox holds only options and groups, and the
198
+ // trigger is already busy. One option tall (the SelectItem height).
199
+ <div
200
+ data-slot="multi-select-loading"
201
+ aria-hidden="true"
202
+ className="text-muted-foreground flex min-h-8.5 items-center justify-center"
203
+ >
204
+ <Loader2Icon className="size-4 motion-safe:animate-spin" />
205
+ </div>
206
+ ) : (
207
+ <SelectGroup>
208
+ {items.map((item) => {
209
+ const itemValue = getValue(item);
210
+ return (
211
+ <SelectItem key={itemValue} value={itemValue}>
212
+ {getLabel(item)}
213
+ </SelectItem>
214
+ );
215
+ })}
216
+ </SelectGroup>
217
+ )}
172
218
  </SelectContent>
173
219
  </Select>
174
220
  );
@@ -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. The 2.x name, kept so code written against 2.x still compiles.
163
+ * link. Removed in 4.0.
163
164
  */
164
- const PageHeaderBackLink = PageHeaderBackRow;
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 are props so consumers can localize them — the design system
22
- * carries no i18n runtime of its own.
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 ? hidePasswordLabel : showPasswordLabel}
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 '@vendure-io/ui/lib/format-relative';
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 { TimeSpan, TimeTooltip, toTime, useReadersClock } from './time-tooltip.tsx';
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 nullish/invalid input, and on the server and the first client
27
- * render of a server-rendered page (the server has no reader's clock).
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 `start` to `value` and how long it took:
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 `start`). Pass content to show that instead, or `false` where
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 resolvedLocale = locale ?? settings.locale;
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
- // Re-exported so the spike's import surface (molecules/relative-time) keeps
158
- // working; the implementation lives in lib/ per the JSX-or-lib rule.
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
- type FormatRelativeOptions,
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 = 'Search',
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} (command palette)`}
85
+ aria-label={ariaLabel ?? `${label} (${commandPalette})`}
84
86
  aria-keyshortcuts={
85
87
  shortcutKey ? `${apple ? 'Meta' : 'Control'}+${shortcutKey.toUpperCase()}` : undefined
86
88
  }