@vendure-io/ui 3.0.0-next.1 → 3.0.0-next.3

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 (32) hide show
  1. package/THIRD_PARTY_NOTICES.md +38 -0
  2. package/package.json +6 -4
  3. package/src/components/atoms/breadcrumb.tsx +67 -9
  4. package/src/components/atoms/button.tsx +106 -9
  5. package/src/components/atoms/calendar.tsx +11 -2
  6. package/src/components/atoms/card.tsx +47 -0
  7. package/src/components/atoms/collapsible.tsx +22 -2
  8. package/src/components/atoms/field.tsx +4 -1
  9. package/src/components/atoms/label-swap.tsx +27 -2
  10. package/src/components/atoms/sonner.tsx +1 -1
  11. package/src/components/atoms/switch.tsx +59 -3
  12. package/src/components/atoms/table.tsx +133 -10
  13. package/src/components/atoms/text-link.tsx +125 -0
  14. package/src/components/molecules/app-shell.tsx +24 -2
  15. package/src/components/molecules/checklist/checklist.tsx +891 -0
  16. package/src/components/molecules/choice-card.tsx +377 -0
  17. package/src/components/molecules/collapsible-section.tsx +6 -5
  18. package/src/components/molecules/data-table/data-table-helpers.tsx +6 -1
  19. package/src/components/molecules/data-table/data-table-types.tsx +27 -2
  20. package/src/components/molecules/data-table/data-table.tsx +154 -30
  21. package/src/components/molecules/direction-link.tsx +1 -1
  22. package/src/components/molecules/format-provider.tsx +12 -2
  23. package/src/components/molecules/interactive-card.tsx +45 -0
  24. package/src/components/molecules/page-header.tsx +1 -1
  25. package/src/components/molecules/search-trigger.tsx +1 -1
  26. package/src/components/molecules/state-views/loading-state.tsx +37 -7
  27. package/src/components/molecules/state-views/skeleton-parts.tsx +245 -0
  28. package/src/components/molecules/status-badge.tsx +49 -16
  29. package/src/components/molecules/step-indicator.tsx +341 -0
  30. package/src/components/molecules/timeline.tsx +1 -1
  31. package/src/hooks/use-user-toggle-motion.ts +50 -0
  32. package/src/lib/state-dictionary.ts +9 -7
@@ -0,0 +1,245 @@
1
+ import {
2
+ Card,
3
+ CardAction,
4
+ CardContent,
5
+ CardDescription,
6
+ CardHeader,
7
+ CardTitle,
8
+ } from '@vendure-io/ui/components/atoms/card';
9
+ import { Skeleton } from '@vendure-io/ui/components/atoms/skeleton';
10
+ import {
11
+ ListRow,
12
+ ListRowContent,
13
+ ListRowLeading,
14
+ ListRowTrailing,
15
+ } from '@vendure-io/ui/components/molecules/list-row';
16
+ import { cn } from '@vendure-io/ui/lib/utils';
17
+ import * as React from 'react';
18
+
19
+ // Skeleton parts: placeholders in the shape of a real component, at its height
20
+ // and spacing, so content fills in place when data arrives. Compose them inside
21
+ // a LoadingState: the LoadingState is the one live region that announces the
22
+ // wait, and every part is aria-hidden, so a screen reader hears "Loading…" once
23
+ // and never the parts one by one.
24
+ //
25
+ // Heights come from the same tokens as the real component, never from pixel
26
+ // font sizes: a text line is `1lh` of the text style it stands in for, so a
27
+ // change to a font size or line height moves the skeleton with the text. Where
28
+ // the real component can be reused as is (Card, ListRow), the part renders it.
29
+ // Where the real component carries semantics a placeholder must not have
30
+ // (PageHeader's <header> and <h1>, Field's role="group"), the part repeats its
31
+ // layout classes. The height play tests in `loading-state.stories.tsx` keep
32
+ // every part equal to its real component.
33
+
34
+ /**
35
+ * One text line of placeholder: a box exactly one line box tall (`1lh` of the
36
+ * inherited text style) with a bar centred in it. Size it with a text utility
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.
39
+ */
40
+ function SkeletonLine({ className, ...props }: React.ComponentProps<'div'>) {
41
+ return (
42
+ <div
43
+ data-skeleton="line"
44
+ aria-hidden="true"
45
+ className={cn('flex h-lh w-full items-center', className)}
46
+ {...props}
47
+ >
48
+ <Skeleton className="h-[0.8lh] w-full" />
49
+ </div>
50
+ );
51
+ }
52
+
53
+ interface SkeletonListRowProps extends React.ComponentProps<'div'> {
54
+ /** The leading media: a 16px icon, a default (32px) Avatar, or none. @default "icon" */
55
+ leading?: 'icon' | 'avatar' | 'none';
56
+ /** A second, muted line under the title (ListRowMeta). @default true */
57
+ meta?: boolean;
58
+ /** An action at the end of the row (a small button). @default true */
59
+ action?: boolean;
60
+ }
61
+
62
+ /**
63
+ * A ListRow placeholder: leading icon or avatar, a title line, an optional
64
+ * meta line and an end action. Renders the real ListRow, so it is 48px tall
65
+ * with one line and 60px with the meta line, like the row it stands in for.
66
+ */
67
+ function SkeletonListRow({
68
+ leading = 'icon',
69
+ meta = true,
70
+ action = true,
71
+ className,
72
+ ...props
73
+ }: SkeletonListRowProps) {
74
+ return (
75
+ <ListRow data-skeleton="list-row" aria-hidden="true" className={className} {...props}>
76
+ {leading === 'none' ? null : (
77
+ <ListRowLeading>
78
+ <Skeleton
79
+ className={leading === 'avatar' ? 'size-8 rounded-full' : 'size-4 rounded-sm'}
80
+ />
81
+ </ListRowLeading>
82
+ )}
83
+ <ListRowContent>
84
+ <SkeletonLine className="w-2/5 max-w-60" />
85
+ {meta ? (
86
+ // ListRowMeta is a <span> and a skeleton bar is a <div>, so the meta
87
+ // line is a <div> with the same slot (ListRow's two-line padding keys
88
+ // on it) and the same text style (`1lh` stays 18px).
89
+ <div data-slot="list-row-meta" className="text-xs leading-4.5">
90
+ <SkeletonLine className="w-1/4 max-w-40" />
91
+ </div>
92
+ ) : null}
93
+ </ListRowContent>
94
+ {action ? (
95
+ <ListRowTrailing>
96
+ <Skeleton className="h-7 w-16 rounded-xl" />
97
+ </ListRowTrailing>
98
+ ) : null}
99
+ </ListRow>
100
+ );
101
+ }
102
+
103
+ interface SkeletonCardProps extends Omit<React.ComponentProps<typeof Card>, 'variant'> {
104
+ /** A description line under the title (CardDescription). @default false */
105
+ description?: boolean;
106
+ /** A small button in the header (CardAction). @default false */
107
+ action?: boolean;
108
+ /** Body text lines in CardContent. Ignored when children are given. @default 3 */
109
+ lines?: number;
110
+ }
111
+
112
+ /**
113
+ * A Card placeholder: title, optional description and header action, and body
114
+ * lines. Renders the real Card parts, so the header and the body keep the
115
+ * card's padding, gap and one-line header height. Pass children to replace the
116
+ * body lines with another shape (SkeletonField, SkeletonFact, SkeletonLine).
117
+ * Children are wrapped in a CardContent stack (gap-4), so they keep the card
118
+ * padding: do not add your own CardContent. Children that render nothing
119
+ * (`false`, `null`, `undefined`, `[]`) count as no children.
120
+ */
121
+ function SkeletonCard({
122
+ description = false,
123
+ action = false,
124
+ lines = 3,
125
+ children,
126
+ ...props
127
+ }: SkeletonCardProps) {
128
+ const hasChildren = React.Children.toArray(children).length > 0;
129
+ return (
130
+ <Card data-skeleton="card" aria-hidden="true" {...props}>
131
+ <CardHeader>
132
+ <CardTitle>
133
+ <SkeletonLine className="w-1/3 max-w-40" />
134
+ </CardTitle>
135
+ {description ? (
136
+ <CardDescription>
137
+ <SkeletonLine className="w-2/3 max-w-80" />
138
+ </CardDescription>
139
+ ) : null}
140
+ {action ? (
141
+ <CardAction>
142
+ <Skeleton className="h-7 w-16 rounded-xl" />
143
+ </CardAction>
144
+ ) : null}
145
+ </CardHeader>
146
+ {hasChildren ? (
147
+ <CardContent className="flex flex-col gap-4">{children}</CardContent>
148
+ ) : lines > 0 ? (
149
+ <CardContent>
150
+ {Array.from({ length: lines }).map((_, i) => (
151
+ <SkeletonLine key={i} className={i === lines - 1 && lines > 1 ? 'w-3/5' : undefined} />
152
+ ))}
153
+ </CardContent>
154
+ ) : null}
155
+ </Card>
156
+ );
157
+ }
158
+
159
+ /**
160
+ * A form row placeholder: the label above a 34px control, like a vertical
161
+ * Field with an Input (12px label, snug line height, 6px gap).
162
+ */
163
+ function SkeletonField({ className, ...props }: React.ComponentProps<'div'>) {
164
+ return (
165
+ <div
166
+ data-skeleton="field"
167
+ aria-hidden="true"
168
+ className={cn('flex w-full flex-col gap-1.5', className)}
169
+ {...props}
170
+ >
171
+ <SkeletonLine className="w-24 text-xs leading-snug" />
172
+ <Skeleton className="h-8.5 w-full rounded-lg" />
173
+ </div>
174
+ );
175
+ }
176
+
177
+ /**
178
+ * A key-value fact placeholder: the label above the value, like a
179
+ * DescriptionListItem in a vertical DescriptionList.
180
+ */
181
+ function SkeletonFact({ className, ...props }: React.ComponentProps<'div'>) {
182
+ return (
183
+ <div
184
+ data-skeleton="fact"
185
+ aria-hidden="true"
186
+ className={cn('flex flex-col gap-0.5 text-sm', className)}
187
+ {...props}
188
+ >
189
+ <SkeletonLine className="w-20" />
190
+ <SkeletonLine className="w-32" />
191
+ </div>
192
+ );
193
+ }
194
+
195
+ interface SkeletonPageHeaderProps extends React.ComponentProps<'div'> {
196
+ /** A description line under the title. @default true */
197
+ description?: boolean;
198
+ /** Number of default-size buttons on the end. @default 1 */
199
+ actions?: number;
200
+ }
201
+
202
+ /**
203
+ * A PageHeader placeholder: the page title, an optional description and the
204
+ * actions on the end, with PageHeader's layout. The title line is one line of
205
+ * the page-title text style.
206
+ */
207
+ function SkeletonPageHeader({
208
+ description = true,
209
+ actions = 1,
210
+ className,
211
+ ...props
212
+ }: SkeletonPageHeaderProps) {
213
+ return (
214
+ <div
215
+ data-skeleton="page-header"
216
+ aria-hidden="true"
217
+ className={cn('flex flex-wrap items-start justify-between gap-4', className)}
218
+ {...props}
219
+ >
220
+ <div className="flex min-w-0 flex-col gap-1">
221
+ <SkeletonLine className="text-style-page-title w-48 max-w-full" />
222
+ {description ? <SkeletonLine className="w-80 max-w-full text-sm" /> : null}
223
+ </div>
224
+ {actions > 0 ? (
225
+ <div className="flex shrink-0 items-center gap-2">
226
+ {Array.from({ length: actions }).map((_, i) => (
227
+ <Skeleton key={i} className="h-8.5 w-24 rounded-xl" />
228
+ ))}
229
+ </div>
230
+ ) : null}
231
+ </div>
232
+ );
233
+ }
234
+
235
+ export {
236
+ SkeletonCard,
237
+ SkeletonFact,
238
+ SkeletonField,
239
+ SkeletonLine,
240
+ SkeletonListRow,
241
+ SkeletonPageHeader,
242
+ type SkeletonCardProps,
243
+ type SkeletonListRowProps,
244
+ type SkeletonPageHeaderProps,
245
+ };
@@ -199,7 +199,8 @@ const triggerFocus =
199
199
  const spinnerClass = 'animate-spin-slow motion-reduce:animate-none';
200
200
 
201
201
  // The icon a chip shows when the caller passes none comes from `toneIcons`,
202
- // the map the toast reads too. `progress` always spins its loader.
202
+ // the map the toast reads too. `progress` spins its loader unless the caller
203
+ // passes `icon={false}`: that is pending, blue and without an icon.
203
204
  const ProgressIcon = toneIcons.progress;
204
205
 
205
206
  interface StatusBadgeProps extends useRender.ComponentProps<'span'> {
@@ -227,19 +228,22 @@ interface StatusBadgeProps extends useRender.ComponentProps<'span'> {
227
228
  * Show a leading dot in the tone colour in place of the tone icon, for a
228
229
  * group of chips that is not a list column (a list column uses
229
230
  * `appearance="icon"`). Only for `appearance="chip"` and `"bare"`. `progress` keeps its
230
- * spinner, regardless of this prop.
231
+ * spinner, regardless of this prop, unless `icon={false}`.
231
232
  */
232
233
  dot?: boolean;
233
234
  /**
234
235
  * The leading icon, in the tone colour. Only for `appearance="chip"`, `"bare"` and `"icon"`.
235
236
  * - Leave it out for the tone's own icon: `CircleCheck` (success),
236
237
  * `TriangleAlert` (warning), `CircleX` (critical), `CircleDot` (info),
237
- * `CircleDashed` (neutral) and a spinning `Loader` (progress).
238
+ * `CircleDashed` (neutral) and a spinning `Loader` (progress, for work that
239
+ * runs right now).
238
240
  * - Pass a lucide icon element for a state whose shape says more, e.g.
239
241
  * `<MoonStarIcon />` for Asleep. It replaces the dot and the spinner too.
240
242
  * - Pass `false` or `null` for no icon, on an inline chip whose label
241
- * already names the tone. `progress` still shows its spinner, and `dot`
242
- * still shows the dot. `appearance="icon"` always shows an icon.
243
+ * already names the tone, or for pending (`progress` without its spinner:
244
+ * waiting on the system or another person, not running). `dot` still
245
+ * shows the dot. `appearance="icon"` always shows a marker: the tone icon,
246
+ * or for pending a still dot. A `bare` pending badge shows that dot too.
243
247
  *
244
248
  * Put the icon here, not in `children`: the chip sizes and colours it. An
245
249
  * `<svg>` in `children` (code written for 2.x) hides the tone icon, so the
@@ -287,6 +291,7 @@ function StatusBadge({
287
291
  // dictionary is a fallback the caller resolves, not something rendered here.
288
292
  let classes: string;
289
293
  let content: React.ReactNode;
294
+ const isPending = tone === 'progress' && icon !== undefined && !isValidElement(icon);
290
295
  const hasDetail =
291
296
  appearance === 'icon' && detail !== undefined && detail !== null && detail !== false;
292
297
 
@@ -306,9 +311,10 @@ function StatusBadge({
306
311
  <StatusBadgeMarker
307
312
  tone={tone}
308
313
  size="icon"
309
- dot={false}
310
- // The icon always shows here: it carries the tone.
311
- icon={isValidElement(icon) ? icon : undefined}
314
+ // The icon always shows here: it carries the tone. Pending
315
+ // (`progress` with `icon={false}`) shows a still dot in its place.
316
+ icon={isValidElement(icon) ? icon : isPending ? false : undefined}
317
+ dot={isPending}
312
318
  className={hasDetail ? 'row-span-2' : undefined}
313
319
  />
314
320
  <span data-slot="status-badge-label" className={hasDetail ? 'leading-4.5' : undefined}>
@@ -337,7 +343,7 @@ function StatusBadge({
337
343
  content = (
338
344
  <>
339
345
  {children}
340
- {tone === 'progress' ? (
346
+ {tone === 'progress' && icon === undefined ? (
341
347
  <ProgressIcon aria-hidden className={cn('size-3 shrink-0 stroke-2', spinnerClass)} />
342
348
  ) : null}
343
349
  </>
@@ -351,7 +357,15 @@ function StatusBadge({
351
357
  );
352
358
  content = (
353
359
  <>
354
- <StatusBadgeMarker tone={tone} size={size} dot={dot} icon={icon} />
360
+ <StatusBadgeMarker
361
+ tone={tone}
362
+ size={size}
363
+ dot={dot || (isPending && appearance === 'bare')}
364
+ // Pending in a bare badge has no box to carry the blue, so its dot
365
+ // takes the icon's slot.
366
+ slot={isPending && appearance === 'bare'}
367
+ icon={icon}
368
+ />
355
369
  {children}
356
370
  </>
357
371
  );
@@ -396,17 +410,20 @@ function StatusBadgeMarker({
396
410
  tone,
397
411
  size,
398
412
  dot,
413
+ slot = false,
399
414
  icon,
400
415
  className,
401
416
  }: {
402
417
  tone: Tone;
403
418
  size: StatusBadgeSize | 'icon';
404
419
  dot: boolean;
420
+ /** The dot takes the size of an icon, so it sits where the spinner would. */
421
+ slot?: boolean;
405
422
  icon: React.ReactNode;
406
423
  className?: string;
407
424
  }) {
408
- // 13px icons in the 12px chip, 14px in the 13px chip, 16px beside the
409
- // 13px label of the `icon` appearance, all at stroke 2. The
425
+ // 13px icons in the 12px chip, 14px in the 14px chip, 16px beside the
426
+ // 14px label of the `icon` appearance, all at stroke 2. The
410
427
  // marker eases to a new tone with the outline, when a status changes in place.
411
428
  // Size and stroke are `!important`: a Button sizes every icon inside it to
412
429
  // 16px at stroke 1.75, with a selector that outranks this one, and a badge
@@ -430,9 +447,9 @@ function StatusBadgeMarker({
430
447
  );
431
448
  }
432
449
 
433
- // `progress` keeps its spinner over a dot and without an icon: the motion is
434
- // its meaning, and without it the chip looks like `info`.
435
- if (tone === 'progress') {
450
+ // `progress` keeps its spinner over a dot and when no icon is passed: the
451
+ // motion is its meaning. `icon={false}` is pending: the blue tone, no spinner.
452
+ if (tone === 'progress' && icon === undefined) {
436
453
  return (
437
454
  <span aria-hidden data-marker="icon" data-slot="status-badge-marker" className={iconClasses}>
438
455
  <ProgressIcon className={spinnerClass} />
@@ -452,7 +469,7 @@ function StatusBadgeMarker({
452
469
  );
453
470
  }
454
471
 
455
- return (
472
+ const dotMarker = (
456
473
  <span
457
474
  aria-hidden
458
475
  data-marker="dot"
@@ -460,6 +477,22 @@ function StatusBadgeMarker({
460
477
  className={cn('size-1.5 shrink-0 rounded-full bg-current', toneDot[tone])}
461
478
  />
462
479
  );
480
+ // In the `icon` appearance and in a bare pending badge the dot takes the
481
+ // slot of an icon, so the labels start on the same edge as with a spinner.
482
+ return size === 'icon' || slot ? (
483
+ <span
484
+ aria-hidden
485
+ className={cn(
486
+ 'inline-flex shrink-0 items-center justify-center',
487
+ size === 'icon' ? 'size-4' : size === 'lg' ? 'size-3.5' : 'size-3.25',
488
+ className,
489
+ )}
490
+ >
491
+ {dotMarker}
492
+ </span>
493
+ ) : (
494
+ dotMarker
495
+ );
463
496
  }
464
497
 
465
498
  export { StatusBadge, statusBadgeVariants };