@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
@@ -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
  /**
@@ -27,18 +28,23 @@ interface SecretValueProps extends Omit<React.ComponentProps<'span'>, 'children'
27
28
  onCopied?: CopyButtonProps['onCopied'];
28
29
  /** Called when the load or the clipboard write fails. Falls back to `CopyFeedbackProvider`. */
29
30
  onCopyError?: CopyButtonProps['onCopyError'];
30
- /** Accessible name while the value is masked. @default "Hidden value" */
31
+ /** Accessible name while the value is masked. @default `messages.secretValue.hidden`, "Hidden value" */
31
32
  hiddenLabel?: string;
32
- /** Accessible label of the reveal button. @default "Show value" */
33
+ /** Accessible label of the reveal button. @default `messages.secretValue.show`, "Show value" */
33
34
  showLabel?: string;
34
- /** Accessible label of the button that masks the value again. @default "Hide value" */
35
+ /** Accessible label of the button that masks the value again. @default `messages.secretValue.hide`, "Hide value" */
35
36
  hideLabel?: string;
36
- /** Accessible label before copying. @default "Copy value" */
37
+ /** Accessible label before copying. @default `messages.secretValue.copy`, "Copy value" */
37
38
  copyLabel?: CopyButtonProps['copyLabel'];
38
- /** Accessible label while the copied state is active. @default "Value copied" */
39
+ /** Accessible label while the copied state is active. @default `messages.secretValue.copied`, "Value copied" */
39
40
  copiedLabel?: CopyButtonProps['copiedLabel'];
40
- /** Shown inline when `loadValue` rejects. @default "Couldn't load the value." */
41
+ /** Shown inline when `loadValue` rejects. @default `messages.secretValue.loadError`, "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 = '••••••••';
@@ -93,15 +99,25 @@ function SecretValue({
93
99
  timeout,
94
100
  onCopied,
95
101
  onCopyError,
96
- hiddenLabel = 'Hidden value',
97
- showLabel = 'Show value',
98
- hideLabel = 'Hide value',
99
- copyLabel = 'Copy value',
100
- copiedLabel = 'Value copied',
101
- loadErrorMessage = "Couldn't load the value.",
102
+ hiddenLabel,
103
+ showLabel,
104
+ hideLabel,
105
+ copyLabel,
106
+ copiedLabel,
107
+ loadErrorMessage,
108
+ loadingLabel,
102
109
  className,
103
110
  ...props
104
111
  }: SecretValueProps) {
112
+ const t = useMessages('secretValue', {
113
+ loading: loadingLabel,
114
+ hidden: hiddenLabel,
115
+ show: showLabel,
116
+ hide: hideLabel,
117
+ copy: copyLabel,
118
+ copied: copiedLabel,
119
+ loadError: loadErrorMessage,
120
+ });
105
121
  const [state, dispatch] = useReducer(revealReducer, { status: 'hidden' });
106
122
  // Drops a load that settles after the user hid the value or asked again.
107
123
  const request = useRef(0);
@@ -153,7 +169,7 @@ function SecretValue({
153
169
  <code data-slot="secret-value-value" dir="ltr" aria-hidden="true">
154
170
  {MASK}
155
171
  </code>
156
- <span className="sr-only">{hiddenLabel}</span>
172
+ <span className="sr-only">{t.hidden}</span>
157
173
  </>
158
174
  )}
159
175
  <Button
@@ -161,7 +177,7 @@ function SecretValue({
161
177
  data-slot="secret-value-reveal"
162
178
  variant="ghost"
163
179
  size="icon-xs"
164
- aria-label={revealed ? hideLabel : showLabel}
180
+ aria-label={revealed ? t.hide : t.show}
165
181
  aria-busy={loading || undefined}
166
182
  aria-disabled={loading || undefined}
167
183
  className={CHIP_BUTTON_CLASS}
@@ -171,7 +187,7 @@ function SecretValue({
171
187
  else void reveal();
172
188
  }}
173
189
  >
174
- {loading ? <Spinner /> : <VisibilityIcon visible={!revealed} />}
190
+ {loading ? <Spinner aria-label={t.loading} /> : <VisibilityIcon visible={!revealed} />}
175
191
  </Button>
176
192
  {copyable ? (
177
193
  <CopyButton
@@ -179,8 +195,8 @@ function SecretValue({
179
195
  timeout={timeout}
180
196
  onCopied={onCopied}
181
197
  onCopyError={onCopyError}
182
- copyLabel={copyLabel}
183
- copiedLabel={copiedLabel}
198
+ copyLabel={t.copy}
199
+ copiedLabel={t.copied}
184
200
  // 6px more than the chip gap puts the icon centres 25px apart, so
185
201
  // the two 24px targets do not overlap.
186
202
  className={cn(CHIP_BUTTON_CLASS, 'ms-1.5')}
@@ -192,7 +208,7 @@ function SecretValue({
192
208
  role="alert"
193
209
  className="text-destructive-subtle-foreground pe-1 font-sans"
194
210
  >
195
- {loadErrorMessage}
211
+ {t.loadError}
196
212
  </span>
197
213
  ) : null}
198
214
  </span>
@@ -1,23 +1,25 @@
1
+ 'use client';
2
+
1
3
  import { cn } from '@vendure-io/ui/lib/utils';
2
4
  import type * as React from 'react';
5
+ import { useMessages } from '../../lib/format-messages.ts';
3
6
 
4
7
  interface SkipLinkProps extends React.ComponentProps<'a'> {
5
8
  /** The main-content element to focus. Include the leading `#`. */
6
9
  href?: `#${string}`;
10
+ /** @default `messages.skipLink.label`, "Skip to main content" */
11
+ children?: React.ReactNode;
7
12
  }
8
13
 
9
14
  /**
10
15
  * Keyboard-only escape hatch for repeated application chrome. Place it as the
11
16
  * first focusable element in the document and point it at `AppShellMain` (whose
12
- * default id is `main-content`). Native anchor behavior keeps this server-safe
13
- * and works before React hydrates.
17
+ * default id is `main-content`). Native anchor behavior works before React
18
+ * hydrates. A client component, for its text from `FormatProvider`: a server
19
+ * component can still render it.
14
20
  */
15
- function SkipLink({
16
- className,
17
- href = '#main-content',
18
- children = 'Skip to main content',
19
- ...props
20
- }: SkipLinkProps) {
21
+ function SkipLink({ className, href = '#main-content', children, ...props }: SkipLinkProps) {
22
+ const t = useMessages('skipLink');
21
23
  return (
22
24
  <a
23
25
  data-slot="skip-link"
@@ -28,7 +30,7 @@ function SkipLink({
28
30
  )}
29
31
  {...props}
30
32
  >
31
- {children}
33
+ {children !== undefined ? children : t.label}
32
34
  </a>
33
35
  );
34
36
  }
@@ -1,8 +1,14 @@
1
+ 'use client';
2
+
1
3
  import { Card, CardAction, CardContent, CardHeader } from '@vendure-io/ui/components/atoms/card';
2
- import { Skeleton } from '@vendure-io/ui/components/atoms/skeleton';
4
+ import { useFormatSettings } from '@vendure-io/ui/components/molecules/format-provider';
5
+ import { SkeletonLine } from '@vendure-io/ui/components/molecules/state-views/skeleton-parts';
6
+ import { cn } from '@vendure-io/ui/lib/utils';
3
7
  import { cva } from 'class-variance-authority';
4
8
  import { ArrowDown, ArrowUp } from 'lucide-react';
5
9
  import type { ComponentProps, ReactNode } from 'react';
10
+ import { warnDeprecated } from '../../lib/deprecated.ts';
11
+ import { useMessages } from '../../lib/format-messages.ts';
6
12
 
7
13
  // Delta color follows the outcome, not the direction: `goodWhen` says which
8
14
  // way is good for this metric (revenue up vs. refund-rate down), and the token
@@ -23,32 +29,114 @@ const statCardDeltaVariants = cva('inline-flex items-center gap-0.5 text-xs font
23
29
  });
24
30
 
25
31
  interface StatCardDelta {
26
- /** Raw percentage change, e.g. `-3.2`. Sign drives the arrow and color. */
27
- value: number;
28
- /** Suffix after the number. Default `'%'`. */
32
+ /**
33
+ * Percentage change, e.g. `-3.2` for −3.2 %. The sign drives the arrow and
34
+ * the color; a change that rounds to `0.0` has neither. `undefined` means
35
+ * not known yet: the delta draws a skeleton. `NaN` and `±Infinity` (a change
36
+ * from zero) show "—".
37
+ */
38
+ value: number | undefined;
39
+ /**
40
+ * A unit for a change that is not a percentage, e.g. `' pp'` for percentage
41
+ * points. The number is then a plain decimal in the `FormatProvider` locale,
42
+ * followed by this unit. `undefined` → a percent in that locale ("12.4%",
43
+ * "12,4 %").
44
+ */
45
+ unit?: string;
46
+ /**
47
+ * @deprecated Use `unit`. `'%'` (the 2.x default) is the locale percent,
48
+ * so leave `unit` out for it. Removed in 4.0.
49
+ */
29
50
  label?: string;
30
- /** Which direction is a good outcome for this metric. Default `'up'`. */
51
+ /** Which direction is a good outcome for this metric. @default "up" */
31
52
  goodWhen?: 'up' | 'down';
32
53
  }
33
54
 
34
55
  interface StatCardProps extends ComponentProps<typeof Card> {
35
56
  label: ReactNode;
36
- /** Pre-formatted display value — pass `<Money>`, `<AnimatedNumber>`, a string. */
37
- value: ReactNode;
57
+ /**
58
+ * Pre-formatted display value: `<Money>`, `<AnimatedNumber>`, a string.
59
+ * `undefined` means not known yet: a skeleton of the value's height draws
60
+ * under the real label, so nothing moves when the value arrives. `null`
61
+ * means there is no value and renders `fallback`. `0` and `''` are real
62
+ * values.
63
+ */
64
+ value?: ReactNode;
65
+ /** Rendered when `value` is `null`. @default "—" */
66
+ fallback?: ReactNode;
38
67
  /** Secondary line, e.g. "vs. previous period". */
39
68
  description?: ReactNode;
40
69
  icon?: ReactNode;
41
70
  delta?: StatCardDelta;
42
71
  /** Optional sparkline/chart slot. */
43
72
  chart?: ReactNode;
44
- isLoading?: boolean;
45
73
  /** Header-right slot, e.g. a menu or timeframe select. */
46
74
  action?: ReactNode;
75
+ /** Screen-reader text while the value loads. @default `messages.statCard.loading`, "Loading value" */
76
+ loadingLabel?: string;
77
+ /** Screen-reader word before a rising delta. @default `messages.statCard.up`, "up" */
78
+ deltaUpLabel?: string;
79
+ /** Screen-reader word before a falling delta. @default `messages.statCard.down`, "down" */
80
+ deltaDownLabel?: string;
81
+ /** @deprecated Leave `value` undefined while it loads. Removed in 4.0. */
82
+ isLoading?: boolean;
83
+ }
84
+
85
+ // One line of the surrounding text size, so the loaded text takes exactly its
86
+ // place. The value and the delta sit in a baseline-aligned row: the
87
+ // zero-width space gives the skeleton a text baseline, so the row keeps its
88
+ // height whether one, both or neither of them is loading.
89
+ function StatCardSkeleton({ className }: { className: string }) {
90
+ return (
91
+ <span aria-hidden="true" className={cn('inline-flex max-w-full', className)}>
92
+ <span>{'\u200b'}</span>
93
+ <SkeletonLine />
94
+ </span>
95
+ );
96
+ }
97
+
98
+ interface StatCardDeltaBadgeProps extends StatCardDelta {
99
+ upWord: string;
100
+ downWord: string;
47
101
  }
48
102
 
49
- function StatCardDeltaBadge({ value, label = '%', goodWhen = 'up' }: StatCardDelta) {
50
- const direction = value > 0 ? 'up' : value < 0 ? 'down' : 'flat';
103
+ function StatCardDeltaBadge({
104
+ value,
105
+ unit,
106
+ goodWhen = 'up',
107
+ upWord,
108
+ downWord,
109
+ }: StatCardDeltaBadgeProps) {
110
+ const { locale } = useFormatSettings();
111
+
112
+ if (value === undefined) {
113
+ return (
114
+ <span data-slot="stat-card-delta" className={statCardDeltaVariants({ outcome: 'flat' })}>
115
+ <StatCardSkeleton className="w-10" />
116
+ </span>
117
+ );
118
+ }
119
+
120
+ // A change from zero is ±Infinity: there is no percentage to show.
121
+ if (!Number.isFinite(value)) {
122
+ return (
123
+ <span data-slot="stat-card-delta" className={statCardDeltaVariants({ outcome: 'flat' })}>
124
+ —
125
+ </span>
126
+ );
127
+ }
128
+
129
+ // One fraction digit in the locale ("12.4%", "12,4 %"), or the decimal and
130
+ // the caller's unit. The direction follows the shown number, so a change
131
+ // that rounds to 0.0 has no arrow and a neutral tone.
132
+ const digits = { minimumFractionDigits: 1, maximumFractionDigits: 1 };
133
+ const shown = Math.round(Math.abs(value) * 10) / 10;
134
+ const direction = shown === 0 ? 'flat' : value > 0 ? 'up' : 'down';
51
135
  const outcome = direction === 'flat' ? 'flat' : direction === goodWhen ? 'good' : 'bad';
136
+ const formatted =
137
+ unit === undefined
138
+ ? new Intl.NumberFormat(locale, { style: 'unit', unit: 'percent', ...digits }).format(shown)
139
+ : new Intl.NumberFormat(locale, digits).format(shown);
52
140
 
53
141
  return (
54
142
  <span data-slot="stat-card-delta" className={statCardDeltaVariants({ outcome })}>
@@ -57,45 +145,60 @@ function StatCardDeltaBadge({ value, label = '%', goodWhen = 'up' }: StatCardDel
57
145
  ) : direction === 'down' ? (
58
146
  <ArrowDown aria-hidden="true" className="size-3" />
59
147
  ) : null}
60
- {/* Math.abs strips the sign and the arrow is visual-only, so screen
148
+ {/* The number has no sign and the arrow is visual-only, so screen
61
149
  readers need the direction spelled out. */}
62
150
  {direction !== 'flat' ? (
63
- <span className="sr-only">{direction === 'up' ? 'up' : 'down'} </span>
151
+ <span className="sr-only">{direction === 'up' ? upWord : downWord} </span>
64
152
  ) : null}
65
- {Math.abs(value).toFixed(1)}
66
- {label}
153
+ {formatted}
154
+ {unit}
67
155
  </span>
68
156
  );
69
157
  }
70
158
 
71
159
  function StatCard({
72
160
  label,
73
- value,
161
+ value: valueProp,
162
+ fallback = '—',
74
163
  description,
75
164
  icon,
76
- delta,
165
+ delta: deltaProp,
77
166
  chart,
78
- isLoading = false,
79
167
  action,
168
+ loadingLabel,
169
+ deltaUpLabel,
170
+ deltaDownLabel,
171
+ isLoading,
80
172
  className,
81
173
  ...props
82
174
  }: StatCardProps) {
83
- if (isLoading) {
84
- return (
85
- <Card data-slot="stat-card" className={className} {...props}>
86
- <CardHeader>
87
- <Skeleton className="h-4 w-24" />
88
- </CardHeader>
89
- <CardContent className="flex flex-col gap-2">
90
- <Skeleton className="h-8 w-32" />
91
- <Skeleton className="h-4 w-40" />
92
- </CardContent>
93
- </Card>
94
- );
95
- }
175
+ if (isLoading !== undefined) warnDeprecated('StatCard', 'isLoading', 'value={undefined}');
176
+ if (deltaProp?.label !== undefined) warnDeprecated('StatCard', 'delta.label', 'delta.unit');
177
+ // 2.x: `isLoading` hid the value and the delta; `label` was the unit, with
178
+ // `'%'` for a percent.
179
+ const value = isLoading ? undefined : valueProp;
180
+ const delta =
181
+ deltaProp === undefined
182
+ ? undefined
183
+ : {
184
+ ...deltaProp,
185
+ value: isLoading ? undefined : deltaProp.value,
186
+ unit: deltaProp.unit ?? (deltaProp.label === '%' ? undefined : deltaProp.label),
187
+ };
188
+ const t = useMessages('statCard', {
189
+ loading: loadingLabel,
190
+ up: deltaUpLabel,
191
+ down: deltaDownLabel,
192
+ });
193
+ const isBusy = value === undefined || (delta !== undefined && delta.value === undefined);
96
194
 
97
195
  return (
98
- <Card data-slot="stat-card" className={className} {...props}>
196
+ <Card
197
+ data-slot="stat-card"
198
+ aria-busy={isBusy ? true : undefined}
199
+ className={className}
200
+ {...props}
201
+ >
99
202
  <CardHeader>
100
203
  <div
101
204
  data-slot="stat-card-label"
@@ -113,9 +216,18 @@ function StatCard({
113
216
  <CardContent className="flex flex-col gap-1">
114
217
  <div className="flex items-baseline gap-2">
115
218
  <span data-slot="stat-card-value" className="text-2xl font-semibold tabular-nums">
116
- {value}
219
+ {value === undefined ? (
220
+ <>
221
+ <StatCardSkeleton className="w-24" />
222
+ <span className="sr-only">{t.loading}</span>
223
+ </>
224
+ ) : value === null ? (
225
+ fallback
226
+ ) : (
227
+ value
228
+ )}
117
229
  </span>
118
- {delta ? <StatCardDeltaBadge {...delta} /> : null}
230
+ {delta ? <StatCardDeltaBadge {...delta} upWord={t.up} downWord={t.down} /> : null}
119
231
  </div>
120
232
  {description ? (
121
233
  <p data-slot="stat-card-description" className="text-muted-foreground text-sm">
@@ -8,6 +8,7 @@ import {
8
8
  } from '@vendure-io/ui/components/atoms/empty';
9
9
  import { EmptyCollectionIllustration } from '@vendure-io/ui/components/molecules/illustrations/empty-collection';
10
10
  import { cn } from '@vendure-io/ui/lib/utils';
11
+ import { warnDeprecated } from '../../../lib/deprecated.ts';
11
12
 
12
13
  // `title` is redefined as `ReactNode`, so drop the native string `title` attr.
13
14
  export interface EmptyStateProps extends Omit<React.ComponentProps<typeof Empty>, 'title'> {
@@ -35,13 +36,14 @@ export interface EmptyStateProps extends Omit<React.ComponentProps<typeof Empty>
35
36
  */
36
37
  bordered?: boolean;
37
38
  /**
38
- * `compact` drops the illustration and tightens the spacing. Use it with an
39
+ * `sm` drops the illustration and tightens the spacing. Use it with an
39
40
  * `icon` inside a card, a secondary panel or a side column: the icon sits
40
41
  * above a 14px title. Keep the `default` size with an illustration for a
41
- * whole page or a whole list. Keep compact to a title, a description and at
42
+ * whole page or a whole list. Keep `sm` to a title, a description and at
42
43
  * most one action. Defaults to `default`.
44
+ * `compact` is deprecated: use `sm`. It is removed in 4.0.
43
45
  */
44
- size?: 'default' | 'compact';
46
+ size?: 'default' | 'sm' | 'compact';
45
47
  }
46
48
 
47
49
  /**
@@ -60,16 +62,18 @@ function EmptyState({
60
62
  description,
61
63
  children,
62
64
  bordered = false,
63
- size = 'default',
65
+ size: sizeProp = 'default',
64
66
  className,
65
67
  ...props
66
68
  }: EmptyStateProps) {
67
- const compact = size === 'compact';
69
+ if (sizeProp === 'compact') warnDeprecated('EmptyState', 'size="compact"', 'size="sm"');
70
+ const size = sizeProp === 'compact' ? 'sm' : sizeProp;
71
+ const small = size === 'sm';
68
72
  // Precedence: an explicit `illustration` (including `null`, to opt out)
69
73
  // always wins; otherwise an explicit `icon` keeps rendering exactly as
70
74
  // before. Only when neither is touched does the default illustration fill
71
75
  // the media slot, so existing icon-only consumers see no change.
72
- const resolvedIllustration = compact ? null : illustration !== undefined ? (
76
+ const resolvedIllustration = small ? null : illustration !== undefined ? (
73
77
  illustration
74
78
  ) : icon === undefined ? (
75
79
  <EmptyCollectionIllustration />
@@ -83,28 +87,28 @@ function EmptyState({
83
87
  // Unbordered clears the atom's dashed style, so a border the consumer
84
88
  // adds through `className` is solid.
85
89
  bordered ? 'border' : 'rounded-none border-solid',
86
- compact && 'gap-3 p-6 py-10',
90
+ small && 'gap-3 p-6 py-10',
87
91
  className,
88
92
  )}
89
93
  {...props}
90
94
  >
91
- <EmptyHeader className={cn(compact && 'gap-1')}>
95
+ <EmptyHeader className={cn(small && 'gap-1')}>
92
96
  {resolvedIllustration ? (
93
97
  <EmptyMedia>{resolvedIllustration}</EmptyMedia>
94
98
  ) : icon ? (
95
99
  // 20px from the icon to the title in the default size.
96
- <EmptyMedia variant="bare" className={cn(!compact && 'mb-3')}>
100
+ <EmptyMedia variant="bare" className={cn(!small && 'mb-3')}>
97
101
  {icon}
98
102
  </EmptyMedia>
99
103
  ) : null}
100
- <EmptyTitle className={cn(compact && 'text-style-card-title leading-5.25')}>
104
+ <EmptyTitle className={cn(small && 'text-style-card-title leading-5.25')}>
101
105
  {title}
102
106
  </EmptyTitle>
103
107
  {description ? (
104
- <EmptyDescription className={cn(compact && 'text-sm')}>{description}</EmptyDescription>
108
+ <EmptyDescription className={cn(small && 'text-sm')}>{description}</EmptyDescription>
105
109
  ) : null}
106
110
  </EmptyHeader>
107
- {children ? <EmptyContent className={cn(compact && 'gap-2')}>{children}</EmptyContent> : null}
111
+ {children ? <EmptyContent className={cn(small && 'gap-2')}>{children}</EmptyContent> : null}
108
112
  </Empty>
109
113
  );
110
114
  }
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  import { Button } from '@vendure-io/ui/components/atoms/button';
2
4
  import {
3
5
  Empty,
@@ -10,13 +12,15 @@ import {
10
12
  import { ErrorIllustration } from '@vendure-io/ui/components/molecules/illustrations/error';
11
13
  import { cn } from '@vendure-io/ui/lib/utils';
12
14
  import { TriangleAlertIcon } from 'lucide-react';
15
+ import { warnDeprecated } from '../../../lib/deprecated.ts';
16
+ import { useMessages } from '../../../lib/format-messages.ts';
13
17
 
14
18
  // `title` is redefined as `ReactNode`, so drop the native string `title` attr.
15
19
  export interface ErrorStateProps extends Omit<React.ComponentProps<typeof Empty>, 'title'> {
16
20
  /**
17
21
  * Leading icon, drawn bare like EmptyState's: 28px and a light stroke, in
18
22
  * the `text-destructive-text` tone. Defaults to an alert triangle. In a
19
- * `compact` state only an explicit icon renders. Ignored once
23
+ * `sm` state only an explicit icon renders. Ignored once
20
24
  * `illustration` renders (see below).
21
25
  */
22
26
  icon?: React.ReactNode;
@@ -26,13 +30,19 @@ export interface ErrorStateProps extends Omit<React.ComponentProps<typeof Empty>
26
30
  * for a 404), or `illustration={null}` to fall back to `icon`.
27
31
  */
28
32
  illustration?: React.ReactNode | null;
29
- /** The headline. Defaults to "Something went wrong". */
33
+ /**
34
+ * The headline.
35
+ * @default `messages.errorState.title`, "Something went wrong"
36
+ */
30
37
  title?: React.ReactNode;
31
38
  /** Optional supporting copy. */
32
39
  description?: React.ReactNode;
33
40
  /** When provided, renders a "Try again" button that calls this handler. */
34
41
  onRetry?: () => void;
35
- /** Label for the retry button. Defaults to "Try again". */
42
+ /**
43
+ * Label for the retry button.
44
+ * @default `messages.errorState.retry`, "Try again"
45
+ */
36
46
  retryLabel?: React.ReactNode;
37
47
  /** Extra actions (e.g. a not-found "Go back" link) rendered beside retry. */
38
48
  children?: React.ReactNode;
@@ -43,12 +53,13 @@ export interface ErrorStateProps extends Omit<React.ComponentProps<typeof Empty>
43
53
  */
44
54
  bordered?: boolean;
45
55
  /**
46
- * `compact` drops the illustration and tightens the spacing, for a small
56
+ * `sm` drops the illustration and tightens the spacing, for a small
47
57
  * panel or side column where the full state is too tall. An explicit `icon`
48
58
  * sits above a 14px title. Keep it to a title, a
49
59
  * description and at most one action. Defaults to `default`.
60
+ * `compact` is deprecated: use `sm`. It is removed in 4.0.
50
61
  */
51
- size?: 'default' | 'compact';
62
+ size?: 'default' | 'sm' | 'compact';
52
63
  }
53
64
 
54
65
  /**
@@ -60,29 +71,32 @@ export interface ErrorStateProps extends Omit<React.ComponentProps<typeof Empty>
60
71
  function ErrorState({
61
72
  icon,
62
73
  illustration,
63
- title = 'Something went wrong',
74
+ title,
64
75
  description,
65
76
  onRetry,
66
- retryLabel = 'Try again',
77
+ retryLabel,
67
78
  children,
68
79
  bordered = false,
69
- size = 'default',
80
+ size: sizeProp = 'default',
70
81
  className,
71
82
  ...props
72
83
  }: ErrorStateProps) {
73
- const compact = size === 'compact';
84
+ const t = useMessages('errorState');
85
+ if (sizeProp === 'compact') warnDeprecated('ErrorState', 'size="compact"', 'size="sm"');
86
+ const size = sizeProp === 'compact' ? 'sm' : sizeProp;
87
+ const small = size === 'sm';
74
88
  // Precedence: an explicit `illustration` (including `null`, to opt out)
75
89
  // always wins; otherwise an explicit `icon` (including `null`) keeps
76
90
  // rendering exactly as before. Only when neither is touched does the
77
91
  // default illustration replace the default triangle icon.
78
- const resolvedIllustration = compact ? null : illustration !== undefined ? (
92
+ const resolvedIllustration = small ? null : illustration !== undefined ? (
79
93
  illustration
80
94
  ) : icon === undefined ? (
81
95
  <ErrorIllustration />
82
96
  ) : null;
83
- // A compact state draws only an explicit icon: the default triangle stays
84
- // off, so a compact error in a small panel keeps to its text and retry.
85
- const resolvedIcon = compact ? icon : icon === undefined ? <TriangleAlertIcon /> : icon;
97
+ // A small state draws only an explicit icon: the default triangle stays
98
+ // off, so a small error in a small panel keeps to its text and retry.
99
+ const resolvedIcon = small ? icon : icon === undefined ? <TriangleAlertIcon /> : icon;
86
100
 
87
101
  return (
88
102
  <Empty
@@ -93,33 +107,35 @@ function ErrorState({
93
107
  // Unbordered clears the atom's dashed style, so a border the consumer
94
108
  // adds through `className` is solid.
95
109
  bordered ? 'border' : 'rounded-none border-solid',
96
- compact && 'gap-3 p-6 py-10',
110
+ small && 'gap-3 p-6 py-10',
97
111
  className,
98
112
  )}
99
113
  {...props}
100
114
  >
101
- <EmptyHeader className={cn(compact && 'gap-1')}>
115
+ <EmptyHeader className={cn(small && 'gap-1')}>
102
116
  {resolvedIllustration ? (
103
117
  <EmptyMedia>{resolvedIllustration}</EmptyMedia>
104
118
  ) : resolvedIcon ? (
105
119
  // 20px from the icon to the title in the default size.
106
120
  <EmptyMedia
107
121
  variant="bare"
108
- className={cn('text-destructive-text opacity-100', !compact && 'mb-3')}
122
+ className={cn('text-destructive-text opacity-100', !small && 'mb-3')}
109
123
  >
110
124
  {resolvedIcon}
111
125
  </EmptyMedia>
112
126
  ) : null}
113
- <EmptyTitle className={cn(compact && 'text-style-card-title')}>{title}</EmptyTitle>
127
+ <EmptyTitle className={cn(small && 'text-style-card-title')}>
128
+ {title !== undefined ? title : t.title}
129
+ </EmptyTitle>
114
130
  {description ? (
115
- <EmptyDescription className={cn(compact && 'text-sm')}>{description}</EmptyDescription>
131
+ <EmptyDescription className={cn(small && 'text-sm')}>{description}</EmptyDescription>
116
132
  ) : null}
117
133
  </EmptyHeader>
118
134
  {onRetry || children ? (
119
- <EmptyContent className={cn(compact && 'gap-2')}>
135
+ <EmptyContent className={cn(small && 'gap-2')}>
120
136
  {onRetry ? (
121
137
  <Button variant="outline" size="sm" onClick={onRetry}>
122
- {retryLabel}
138
+ {retryLabel !== undefined ? retryLabel : t.retry}
123
139
  </Button>
124
140
  ) : null}
125
141
  {children}