@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.
Files changed (86) hide show
  1. package/package.json +12 -10
  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 +124 -49
  6. package/src/components/atoms/button-group.tsx +1 -1
  7. package/src/components/atoms/button.tsx +4 -3
  8. package/src/components/atoms/calendar.tsx +2 -2
  9. package/src/components/atoms/card.tsx +15 -2
  10. package/src/components/atoms/chart.tsx +3 -3
  11. package/src/components/atoms/checkbox.tsx +1 -1
  12. package/src/components/atoms/combobox.tsx +37 -26
  13. package/src/components/atoms/command.tsx +3 -3
  14. package/src/components/atoms/context-menu.tsx +5 -5
  15. package/src/components/atoms/dialog.tsx +30 -14
  16. package/src/components/atoms/dropdown-menu.tsx +1 -1
  17. package/src/components/atoms/hover-card.tsx +1 -1
  18. package/src/components/atoms/input-group.tsx +30 -12
  19. package/src/components/atoms/input-otp.tsx +2 -2
  20. package/src/components/atoms/input.tsx +13 -3
  21. package/src/components/atoms/menubar.tsx +2 -2
  22. package/src/components/atoms/native-select.tsx +1 -1
  23. package/src/components/atoms/navigation-menu.tsx +3 -3
  24. package/src/components/atoms/pagination.tsx +9 -3
  25. package/src/components/atoms/popover.tsx +1 -1
  26. package/src/components/atoms/select.tsx +3 -3
  27. package/src/components/atoms/sheet.tsx +35 -15
  28. package/src/components/atoms/sidebar.tsx +200 -31
  29. package/src/components/atoms/skeleton.tsx +6 -3
  30. package/src/components/atoms/switch.tsx +1 -1
  31. package/src/components/atoms/tabs.tsx +6 -2
  32. package/src/components/atoms/textarea.tsx +1 -1
  33. package/src/components/atoms/toggle.tsx +1 -1
  34. package/src/components/molecules/action-needed.tsx +483 -0
  35. package/src/components/molecules/anonymized-token.tsx +52 -8
  36. package/src/components/molecules/chip.tsx +37 -18
  37. package/src/components/molecules/choice-card.tsx +114 -9
  38. package/src/components/molecules/code-block/package-manager-storage.ts +50 -0
  39. package/src/components/molecules/code-block/process-code.ts +1 -1
  40. package/src/components/molecules/code-block.tsx +58 -47
  41. package/src/components/molecules/combobox-free-text.tsx +75 -20
  42. package/src/components/molecules/confirm-dialog.tsx +11 -1
  43. package/src/components/molecules/copyable-text.tsx +10 -8
  44. package/src/components/molecules/data-table/data-table-filters.tsx +14 -2
  45. package/src/components/molecules/data-table/data-table-helpers.tsx +109 -3
  46. package/src/components/molecules/data-table/data-table-row-count-storage.tsx +88 -0
  47. package/src/components/molecules/data-table/data-table-selection-storage.tsx +33 -15
  48. package/src/components/molecules/data-table/data-table-types.tsx +123 -13
  49. package/src/components/molecules/data-table/data-table.tsx +112 -55
  50. package/src/components/molecules/data-table/table-pagination.tsx +96 -14
  51. package/src/components/molecules/date-picker.tsx +55 -24
  52. package/src/components/molecules/date-range-picker.tsx +54 -23
  53. package/src/components/molecules/date-time-picker.tsx +60 -24
  54. package/src/components/molecules/date-time.tsx +38 -3
  55. package/src/components/molecules/elapsed-time.tsx +61 -12
  56. package/src/components/molecules/file-dropzone.tsx +139 -39
  57. package/src/components/molecules/format-provider.tsx +14 -4
  58. package/src/components/molecules/id-chip-chrome.tsx +114 -0
  59. package/src/components/molecules/id-chip.tsx +3 -107
  60. package/src/components/molecules/issued-secret.tsx +1 -1
  61. package/src/components/molecules/live-indicator.tsx +1 -1
  62. package/src/components/molecules/money.tsx +46 -4
  63. package/src/components/molecules/multi-select.tsx +58 -15
  64. package/src/components/molecules/page-header.tsx +6 -2
  65. package/src/components/molecules/password-input.tsx +11 -10
  66. package/src/components/molecules/relative-time.tsx +88 -16
  67. package/src/components/molecules/search-trigger.tsx +5 -3
  68. package/src/components/molecules/secret-value.tsx +10 -2
  69. package/src/components/molecules/stat-card.tsx +143 -33
  70. package/src/components/molecules/state-views/empty-state.tsx +16 -12
  71. package/src/components/molecules/state-views/error-state.tsx +19 -15
  72. package/src/components/molecules/state-views/loading-state.tsx +16 -6
  73. package/src/components/molecules/state-views/skeleton-parts.tsx +6 -4
  74. package/src/components/molecules/status-badge.tsx +11 -35
  75. package/src/components/molecules/time-tooltip.tsx +55 -1
  76. package/src/hooks/use-copy.ts +3 -1
  77. package/src/lib/deprecated.ts +71 -0
  78. package/src/lib/env.ts +9 -0
  79. package/src/lib/field-surface.ts +7 -7
  80. package/src/lib/format-messages.ts +192 -0
  81. package/src/lib/highlight.ts +1 -1
  82. package/src/lib/menu-item.tsx +1 -1
  83. package/src/lib/state-dictionary.ts +2 -3
  84. package/src/lib/tint-recipes.ts +10 -5
  85. package/src/lib/utils.ts +19 -1
  86. package/src/lib/dialog-padding.ts +0 -48
@@ -1,8 +1,12 @@
1
1
  import { Card, CardAction, CardContent, CardHeader } from '@vendure-io/ui/components/atoms/card';
2
- import { Skeleton } from '@vendure-io/ui/components/atoms/skeleton';
2
+ import { useFormatSettings } from '@vendure-io/ui/components/molecules/format-provider';
3
+ import { SkeletonLine } from '@vendure-io/ui/components/molecules/state-views/skeleton-parts';
4
+ import { cn } from '@vendure-io/ui/lib/utils';
3
5
  import { cva } from 'class-variance-authority';
4
6
  import { ArrowDown, ArrowUp } from 'lucide-react';
5
7
  import type { ComponentProps, ReactNode } from 'react';
8
+ import { warnDeprecated } from '../../lib/deprecated.ts';
9
+ import { useMessages } from '../../lib/format-messages.ts';
6
10
 
7
11
  // Delta color follows the outcome, not the direction: `goodWhen` says which
8
12
  // way is good for this metric (revenue up vs. refund-rate down), and the token
@@ -23,32 +27,114 @@ const statCardDeltaVariants = cva('inline-flex items-center gap-0.5 text-xs font
23
27
  });
24
28
 
25
29
  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 `'%'`. */
30
+ /**
31
+ * Percentage change, e.g. `-3.2` for −3.2 %. The sign drives the arrow and
32
+ * the color; a change that rounds to `0.0` has neither. `undefined` means
33
+ * not known yet: the delta draws a skeleton. `NaN` and `±Infinity` (a change
34
+ * from zero) show "—".
35
+ */
36
+ value: number | undefined;
37
+ /**
38
+ * A unit for a change that is not a percentage, e.g. `' pp'` for percentage
39
+ * points. The number is then a plain decimal in the `FormatProvider` locale,
40
+ * followed by this unit. `undefined` → a percent in that locale ("12.4%",
41
+ * "12,4 %").
42
+ */
43
+ unit?: string;
44
+ /**
45
+ * @deprecated Use `unit`. `'%'` (the 2.x default) is the locale percent,
46
+ * so leave `unit` out for it. Removed in 4.0.
47
+ */
29
48
  label?: string;
30
- /** Which direction is a good outcome for this metric. Default `'up'`. */
49
+ /** Which direction is a good outcome for this metric. @default "up" */
31
50
  goodWhen?: 'up' | 'down';
32
51
  }
33
52
 
34
53
  interface StatCardProps extends ComponentProps<typeof Card> {
35
54
  label: ReactNode;
36
- /** Pre-formatted display value — pass `<Money>`, `<AnimatedNumber>`, a string. */
37
- value: ReactNode;
55
+ /**
56
+ * Pre-formatted display value: `<Money>`, `<AnimatedNumber>`, a string.
57
+ * `undefined` means not known yet: a skeleton of the value's height draws
58
+ * under the real label, so nothing moves when the value arrives. `null`
59
+ * means there is no value and renders `fallback`. `0` and `''` are real
60
+ * values.
61
+ */
62
+ value?: ReactNode;
63
+ /** Rendered when `value` is `null`. @default "—" */
64
+ fallback?: ReactNode;
38
65
  /** Secondary line, e.g. "vs. previous period". */
39
66
  description?: ReactNode;
40
67
  icon?: ReactNode;
41
68
  delta?: StatCardDelta;
42
69
  /** Optional sparkline/chart slot. */
43
70
  chart?: ReactNode;
44
- isLoading?: boolean;
45
71
  /** Header-right slot, e.g. a menu or timeframe select. */
46
72
  action?: ReactNode;
73
+ /** Screen-reader text while the value loads. @default `messages.statCard.loading`, "Loading value" */
74
+ loadingLabel?: string;
75
+ /** Screen-reader word before a rising delta. @default `messages.statCard.up`, "up" */
76
+ deltaUpLabel?: string;
77
+ /** Screen-reader word before a falling delta. @default `messages.statCard.down`, "down" */
78
+ deltaDownLabel?: string;
79
+ /** @deprecated Leave `value` undefined while it loads. Removed in 4.0. */
80
+ isLoading?: boolean;
81
+ }
82
+
83
+ // One line of the surrounding text size, so the loaded text takes exactly its
84
+ // place. The value and the delta sit in a baseline-aligned row: the
85
+ // zero-width space gives the skeleton a text baseline, so the row keeps its
86
+ // height whether one, both or neither of them is loading.
87
+ function StatCardSkeleton({ className }: { className: string }) {
88
+ return (
89
+ <span aria-hidden="true" className={cn('inline-flex max-w-full', className)}>
90
+ <span>{'\u200b'}</span>
91
+ <SkeletonLine />
92
+ </span>
93
+ );
94
+ }
95
+
96
+ interface StatCardDeltaBadgeProps extends StatCardDelta {
97
+ upWord: string;
98
+ downWord: string;
47
99
  }
48
100
 
49
- function StatCardDeltaBadge({ value, label = '%', goodWhen = 'up' }: StatCardDelta) {
50
- const direction = value > 0 ? 'up' : value < 0 ? 'down' : 'flat';
101
+ function StatCardDeltaBadge({
102
+ value,
103
+ unit,
104
+ goodWhen = 'up',
105
+ upWord,
106
+ downWord,
107
+ }: StatCardDeltaBadgeProps) {
108
+ const { locale } = useFormatSettings();
109
+
110
+ if (value === undefined) {
111
+ return (
112
+ <span data-slot="stat-card-delta" className={statCardDeltaVariants({ outcome: 'flat' })}>
113
+ <StatCardSkeleton className="w-10" />
114
+ </span>
115
+ );
116
+ }
117
+
118
+ // A change from zero is ±Infinity: there is no percentage to show.
119
+ if (!Number.isFinite(value)) {
120
+ return (
121
+ <span data-slot="stat-card-delta" className={statCardDeltaVariants({ outcome: 'flat' })}>
122
+ —
123
+ </span>
124
+ );
125
+ }
126
+
127
+ // One fraction digit in the locale ("12.4%", "12,4 %"), or the decimal and
128
+ // the caller's unit. The direction follows the shown number, so a change
129
+ // that rounds to 0.0 has no arrow and a neutral tone.
130
+ const digits = { minimumFractionDigits: 1, maximumFractionDigits: 1 };
131
+ const shown = Math.round(Math.abs(value) * 10) / 10;
132
+ const direction = shown === 0 ? 'flat' : value > 0 ? 'up' : 'down';
51
133
  const outcome = direction === 'flat' ? 'flat' : direction === goodWhen ? 'good' : 'bad';
134
+ const formatted =
135
+ unit === undefined
136
+ ? new Intl.NumberFormat(locale, { style: 'unit', unit: 'percent', ...digits }).format(shown)
137
+ : new Intl.NumberFormat(locale, digits).format(shown);
52
138
 
53
139
  return (
54
140
  <span data-slot="stat-card-delta" className={statCardDeltaVariants({ outcome })}>
@@ -57,45 +143,60 @@ function StatCardDeltaBadge({ value, label = '%', goodWhen = 'up' }: StatCardDel
57
143
  ) : direction === 'down' ? (
58
144
  <ArrowDown aria-hidden="true" className="size-3" />
59
145
  ) : null}
60
- {/* Math.abs strips the sign and the arrow is visual-only, so screen
146
+ {/* The number has no sign and the arrow is visual-only, so screen
61
147
  readers need the direction spelled out. */}
62
148
  {direction !== 'flat' ? (
63
- <span className="sr-only">{direction === 'up' ? 'up' : 'down'} </span>
149
+ <span className="sr-only">{direction === 'up' ? upWord : downWord} </span>
64
150
  ) : null}
65
- {Math.abs(value).toFixed(1)}
66
- {label}
151
+ {formatted}
152
+ {unit}
67
153
  </span>
68
154
  );
69
155
  }
70
156
 
71
157
  function StatCard({
72
158
  label,
73
- value,
159
+ value: valueProp,
160
+ fallback = '—',
74
161
  description,
75
162
  icon,
76
- delta,
163
+ delta: deltaProp,
77
164
  chart,
78
- isLoading = false,
79
165
  action,
166
+ loadingLabel,
167
+ deltaUpLabel,
168
+ deltaDownLabel,
169
+ isLoading,
80
170
  className,
81
171
  ...props
82
172
  }: 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
- }
173
+ if (isLoading !== undefined) warnDeprecated('StatCard', 'isLoading', 'value={undefined}');
174
+ if (deltaProp?.label !== undefined) warnDeprecated('StatCard', 'delta.label', 'delta.unit');
175
+ // 2.x: `isLoading` hid the value and the delta; `label` was the unit, with
176
+ // `'%'` for a percent.
177
+ const value = isLoading ? undefined : valueProp;
178
+ const delta =
179
+ deltaProp === undefined
180
+ ? undefined
181
+ : {
182
+ ...deltaProp,
183
+ value: isLoading ? undefined : deltaProp.value,
184
+ unit: deltaProp.unit ?? (deltaProp.label === '%' ? undefined : deltaProp.label),
185
+ };
186
+ const t = useMessages('statCard', {
187
+ loading: loadingLabel,
188
+ up: deltaUpLabel,
189
+ down: deltaDownLabel,
190
+ });
191
+ const isBusy = value === undefined || (delta !== undefined && delta.value === undefined);
96
192
 
97
193
  return (
98
- <Card data-slot="stat-card" className={className} {...props}>
194
+ <Card
195
+ data-slot="stat-card"
196
+ aria-busy={isBusy ? true : undefined}
197
+ className={className}
198
+ {...props}
199
+ >
99
200
  <CardHeader>
100
201
  <div
101
202
  data-slot="stat-card-label"
@@ -113,9 +214,18 @@ function StatCard({
113
214
  <CardContent className="flex flex-col gap-1">
114
215
  <div className="flex items-baseline gap-2">
115
216
  <span data-slot="stat-card-value" className="text-2xl font-semibold tabular-nums">
116
- {value}
217
+ {value === undefined ? (
218
+ <>
219
+ <StatCardSkeleton className="w-24" />
220
+ <span className="sr-only">{t.loading}</span>
221
+ </>
222
+ ) : value === null ? (
223
+ fallback
224
+ ) : (
225
+ value
226
+ )}
117
227
  </span>
118
- {delta ? <StatCardDeltaBadge {...delta} /> : null}
228
+ {delta ? <StatCardDeltaBadge {...delta} upWord={t.up} downWord={t.down} /> : null}
119
229
  </div>
120
230
  {description ? (
121
231
  <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
  }
@@ -10,13 +10,14 @@ import {
10
10
  import { ErrorIllustration } from '@vendure-io/ui/components/molecules/illustrations/error';
11
11
  import { cn } from '@vendure-io/ui/lib/utils';
12
12
  import { TriangleAlertIcon } from 'lucide-react';
13
+ import { warnDeprecated } from '../../../lib/deprecated.ts';
13
14
 
14
15
  // `title` is redefined as `ReactNode`, so drop the native string `title` attr.
15
16
  export interface ErrorStateProps extends Omit<React.ComponentProps<typeof Empty>, 'title'> {
16
17
  /**
17
18
  * Leading icon, drawn bare like EmptyState's: 28px and a light stroke, in
18
19
  * the `text-destructive-text` tone. Defaults to an alert triangle. In a
19
- * `compact` state only an explicit icon renders. Ignored once
20
+ * `sm` state only an explicit icon renders. Ignored once
20
21
  * `illustration` renders (see below).
21
22
  */
22
23
  icon?: React.ReactNode;
@@ -43,12 +44,13 @@ export interface ErrorStateProps extends Omit<React.ComponentProps<typeof Empty>
43
44
  */
44
45
  bordered?: boolean;
45
46
  /**
46
- * `compact` drops the illustration and tightens the spacing, for a small
47
+ * `sm` drops the illustration and tightens the spacing, for a small
47
48
  * panel or side column where the full state is too tall. An explicit `icon`
48
49
  * sits above a 14px title. Keep it to a title, a
49
50
  * description and at most one action. Defaults to `default`.
51
+ * `compact` is deprecated: use `sm`. It is removed in 4.0.
50
52
  */
51
- size?: 'default' | 'compact';
53
+ size?: 'default' | 'sm' | 'compact';
52
54
  }
53
55
 
54
56
  /**
@@ -66,23 +68,25 @@ function ErrorState({
66
68
  retryLabel = 'Try again',
67
69
  children,
68
70
  bordered = false,
69
- size = 'default',
71
+ size: sizeProp = 'default',
70
72
  className,
71
73
  ...props
72
74
  }: ErrorStateProps) {
73
- const compact = size === 'compact';
75
+ if (sizeProp === 'compact') warnDeprecated('ErrorState', 'size="compact"', 'size="sm"');
76
+ const size = sizeProp === 'compact' ? 'sm' : sizeProp;
77
+ const small = size === 'sm';
74
78
  // Precedence: an explicit `illustration` (including `null`, to opt out)
75
79
  // always wins; otherwise an explicit `icon` (including `null`) keeps
76
80
  // rendering exactly as before. Only when neither is touched does the
77
81
  // default illustration replace the default triangle icon.
78
- const resolvedIllustration = compact ? null : illustration !== undefined ? (
82
+ const resolvedIllustration = small ? null : illustration !== undefined ? (
79
83
  illustration
80
84
  ) : icon === undefined ? (
81
85
  <ErrorIllustration />
82
86
  ) : 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;
87
+ // A small state draws only an explicit icon: the default triangle stays
88
+ // off, so a small error in a small panel keeps to its text and retry.
89
+ const resolvedIcon = small ? icon : icon === undefined ? <TriangleAlertIcon /> : icon;
86
90
 
87
91
  return (
88
92
  <Empty
@@ -93,30 +97,30 @@ function ErrorState({
93
97
  // Unbordered clears the atom's dashed style, so a border the consumer
94
98
  // adds through `className` is solid.
95
99
  bordered ? 'border' : 'rounded-none border-solid',
96
- compact && 'gap-3 p-6 py-10',
100
+ small && 'gap-3 p-6 py-10',
97
101
  className,
98
102
  )}
99
103
  {...props}
100
104
  >
101
- <EmptyHeader className={cn(compact && 'gap-1')}>
105
+ <EmptyHeader className={cn(small && 'gap-1')}>
102
106
  {resolvedIllustration ? (
103
107
  <EmptyMedia>{resolvedIllustration}</EmptyMedia>
104
108
  ) : resolvedIcon ? (
105
109
  // 20px from the icon to the title in the default size.
106
110
  <EmptyMedia
107
111
  variant="bare"
108
- className={cn('text-destructive-text opacity-100', !compact && 'mb-3')}
112
+ className={cn('text-destructive-text opacity-100', !small && 'mb-3')}
109
113
  >
110
114
  {resolvedIcon}
111
115
  </EmptyMedia>
112
116
  ) : null}
113
- <EmptyTitle className={cn(compact && 'text-style-card-title')}>{title}</EmptyTitle>
117
+ <EmptyTitle className={cn(small && 'text-style-card-title')}>{title}</EmptyTitle>
114
118
  {description ? (
115
- <EmptyDescription className={cn(compact && 'text-sm')}>{description}</EmptyDescription>
119
+ <EmptyDescription className={cn(small && 'text-sm')}>{description}</EmptyDescription>
116
120
  ) : null}
117
121
  </EmptyHeader>
118
122
  {onRetry || children ? (
119
- <EmptyContent className={cn(compact && 'gap-2')}>
123
+ <EmptyContent className={cn(small && 'gap-2')}>
120
124
  {onRetry ? (
121
125
  <Button variant="outline" size="sm" onClick={onRetry}>
122
126
  {retryLabel}
@@ -3,6 +3,8 @@ import { Spinner } from '@vendure-io/ui/components/atoms/spinner';
3
3
  import { cn } from '@vendure-io/ui/lib/utils';
4
4
  import { cva, type VariantProps } from 'class-variance-authority';
5
5
  import { Children } from 'react';
6
+ import { warnDeprecated } from '../../../lib/deprecated.ts';
7
+ import { useMessages } from '../../../lib/format-messages.ts';
6
8
 
7
9
  const loadingStateVariants = cva('flex w-full min-w-0 flex-col gap-3', {
8
10
  variants: {
@@ -25,9 +27,14 @@ export interface LoadingStateProps
25
27
  rows?: number;
26
28
  /** Classes applied to each skeleton row (e.g. `h-10` for tighter lists). */
27
29
  rowClassName?: string;
28
- /** Visible label. An sr-only `srLabel` is always rendered for assistive tech. */
30
+ /** Visible label. An sr-only `loadingLabel` is always rendered for assistive tech. */
29
31
  label?: React.ReactNode;
30
- /** Sr-only label announced to assistive tech. Override for host i18n. @default "Loading…" */
32
+ /**
33
+ * Sr-only text announced to assistive tech.
34
+ * @default `messages.loadingState.loading`, "Loading…"
35
+ */
36
+ loadingLabel?: string;
37
+ /** @deprecated Use `loadingLabel`. Removed in 4.0. */
31
38
  srLabel?: string;
32
39
  /**
33
40
  * Milliseconds before the placeholder appears. A load that ends sooner never
@@ -51,8 +58,8 @@ const DELAYED_ENTRY =
51
58
 
52
59
  /**
53
60
  * Placeholder shell for in-flight list/detail queries. Renders as an
54
- * `aria-live` `<output>` with an always-present sr-only `srLabel` (defaults to
55
- * "Loading…", overridable for host i18n).
61
+ * `aria-live` `<output>` with an always-present sr-only `loadingLabel` (defaults to
62
+ * "Loading…", or `FormatProvider`'s `messages.loadingState.loading`).
56
63
  * `skeleton` (default) draws N shimmer rows, or the skeleton parts passed as
57
64
  * children; `spinner` centers the `Spinner` atom for compact or unknown-height
58
65
  * regions. Nothing shows for the first `delay` ms (150 by default).
@@ -62,13 +69,16 @@ function LoadingState({
62
69
  rows = 5,
63
70
  rowClassName,
64
71
  label,
65
- srLabel = 'Loading…',
72
+ loadingLabel,
73
+ srLabel,
66
74
  delay = 150,
67
75
  children,
68
76
  className,
69
77
  style,
70
78
  ...props
71
79
  }: LoadingStateProps) {
80
+ if (srLabel !== undefined) warnDeprecated('LoadingState', 'srLabel', 'loadingLabel');
81
+ const t = useMessages('loadingState', { loading: loadingLabel ?? srLabel });
72
82
  return (
73
83
  <output
74
84
  data-slot="loading-state"
@@ -81,7 +91,7 @@ function LoadingState({
81
91
  }
82
92
  {...props}
83
93
  >
84
- <span className="sr-only">{srLabel}</span>
94
+ <span className="sr-only">{t.loading}</span>
85
95
  {variant === 'spinner' ? (
86
96
  <>
87
97
  {/* aria-hidden overrides the atom's role="status": the <output> is
@@ -35,18 +35,20 @@ import * as React from 'react';
35
35
  * One text line of placeholder: a box exactly one line box tall (`1lh` of the
36
36
  * inherited text style) with a bar centred in it. Size it with a text utility
37
37
  * (`text-xs`, `text-style-page-title`) and its width with `w-*`. The building
38
- * block of every other part; stack several for a paragraph.
38
+ * block of every other part; stack several for a paragraph. It is a <span>, so
39
+ * it can also stand in for a value inside a paragraph: give it `inline-flex`
40
+ * and a width there.
39
41
  */
40
- function SkeletonLine({ className, ...props }: React.ComponentProps<'div'>) {
42
+ function SkeletonLine({ className, ...props }: React.ComponentProps<'span'>) {
41
43
  return (
42
- <div
44
+ <span
43
45
  data-skeleton="line"
44
46
  aria-hidden="true"
45
47
  className={cn('flex h-lh w-full items-center', className)}
46
48
  {...props}
47
49
  >
48
50
  <Skeleton className="h-[0.8lh] w-full" />
49
- </div>
51
+ </span>
50
52
  );
51
53
  }
52
54
 
@@ -1,19 +1,19 @@
1
1
  import { mergeProps } from '@base-ui/react/merge-props';
2
2
  import { useRender } from '@base-ui/react/use-render';
3
- import { contentInsetPull } from '@vendure-io/ui/lib/content-inset';
4
3
  import type { Tone } from '@vendure-io/ui/lib/state-dictionary';
4
+ import { toneIcons } from '@vendure-io/ui/lib/tone-icons';
5
+ import { cn } from '@vendure-io/ui/lib/utils';
6
+ import { cva } from 'class-variance-authority';
7
+ import type * as React from 'react';
8
+ import { isValidElement } from 'react';
9
+ import { contentInsetPull } from '../../lib/content-inset.ts';
5
10
  import {
6
11
  statusChipFill,
7
12
  statusChipLabel,
8
13
  statusChipRing,
9
14
  statusToneText,
10
15
  statusToneVars,
11
- } from '@vendure-io/ui/lib/tint-recipes';
12
- import { toneIcons } from '@vendure-io/ui/lib/tone-icons';
13
- import { cn } from '@vendure-io/ui/lib/utils';
14
- import { cva } from 'class-variance-authority';
15
- import type * as React from 'react';
16
- import { isValidElement } from 'react';
16
+ } from '../../lib/tint-recipes.ts';
17
17
  // Relative: `time-tooltip` is internal.
18
18
  import { InStatusDetail } from './time-tooltip.tsx';
19
19
 
@@ -62,31 +62,12 @@ const rowRevealClass = [
62
62
 
63
63
  const chipLabel = statusChipLabel;
64
64
 
65
- // Code written for 2.x puts its own icon in `children`. Its `<svg>` is then a
66
- // direct child of the badge, and the tone icon (or spinner) hides, so the
67
- // badge shows one icon. A dot stays: 2.x had it too.
68
- const ownIconHidesToneIcon = '[&:has(>svg)>[data-marker=icon]]:hidden';
69
-
70
- // That own icon takes the tone colour, as the tone icon does, so two badges
71
- // of one state look the same. The rule is in `:where()`, so it has no
72
- // specificity: a colour class on the icon wins. Static per tone for
73
- // Tailwind's scanner, matching `statusToneText`.
74
- const ownIconToneText: Record<Tone, string> = {
75
- neutral: '[:where(&>svg)]:text-neutral-text',
76
- info: '[:where(&>svg)]:text-info-text',
77
- success: '[:where(&>svg)]:text-success-text',
78
- warning: '[:where(&>svg)]:text-warning-text',
79
- critical: '[:where(&>svg)]:text-destructive-text',
80
- progress: '[:where(&>svg)]:text-info-text',
81
- };
82
-
83
65
  const statusBadgeVariants = cva(
84
66
  [
85
67
  'inline-flex w-fit shrink-0 items-center justify-center overflow-hidden whitespace-nowrap rounded-lg font-medium',
86
68
  statusChipFill,
87
69
  statusChipRing,
88
70
  chipLabel,
89
- ownIconHidesToneIcon,
90
71
  'outline-1 outline-transparent -outline-offset-1',
91
72
  contentInsetPull,
92
73
  ],
@@ -126,7 +107,6 @@ const bareVariants = cva(
126
107
  [
127
108
  'inline-flex w-fit shrink-0 items-center gap-1.5 whitespace-nowrap font-medium',
128
109
  chipLabel,
129
- ownIconHidesToneIcon,
130
110
  contentInsetPull,
131
111
  ],
132
112
  {
@@ -245,10 +225,8 @@ interface StatusBadgeProps extends useRender.ComponentProps<'span'> {
245
225
  * shows the dot. `appearance="icon"` always shows a marker: the tone icon,
246
226
  * or for pending a still dot. A `bare` pending badge shows that dot too.
247
227
  *
248
- * Put the icon here, not in `children`: the chip sizes and colours it. An
249
- * `<svg>` in `children` (code written for 2.x) hides the tone icon, so the
250
- * chip still shows one icon, in the tone colour unless you give it one,
251
- * at the size you gave it.
228
+ * Put the icon here, not in `children`: the chip sizes and colours it, and
229
+ * an icon in `children` shows next to the tone icon.
252
230
  */
253
231
  icon?: React.ReactNode;
254
232
  /**
@@ -349,12 +327,10 @@ function StatusBadge({
349
327
  </>
350
328
  );
351
329
  } else {
352
- classes = cn(
330
+ classes =
353
331
  appearance === 'bare'
354
332
  ? bareVariants({ tone, size, reveal })
355
- : statusBadgeVariants({ tone, size, reveal }),
356
- ownIconToneText[tone],
357
- );
333
+ : statusBadgeVariants({ tone, size, reveal });
358
334
  content = (
359
335
  <>
360
336
  <StatusBadgeMarker