@vendure-io/ui 3.0.0-next.0 → 3.0.0-next.2

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 (38) hide show
  1. package/package.json +2 -2
  2. package/src/components/atoms/alert.tsx +13 -6
  3. package/src/components/atoms/avatar.tsx +11 -3
  4. package/src/components/atoms/breadcrumb.tsx +467 -53
  5. package/src/components/atoms/button.tsx +1 -1
  6. package/src/components/atoms/calendar.tsx +11 -2
  7. package/src/components/atoms/combobox.tsx +220 -17
  8. package/src/components/atoms/command.tsx +51 -130
  9. package/src/components/atoms/dialog.tsx +23 -1
  10. package/src/components/atoms/empty.tsx +1 -1
  11. package/src/components/atoms/field.tsx +4 -1
  12. package/src/components/atoms/input-group.tsx +2 -2
  13. package/src/components/atoms/label-swap.tsx +59 -3
  14. package/src/components/atoms/popover.tsx +6 -1
  15. package/src/components/atoms/sheet.tsx +18 -1
  16. package/src/components/atoms/sidebar.tsx +73 -1
  17. package/src/components/atoms/sonner.tsx +1 -1
  18. package/src/components/atoms/table.tsx +133 -10
  19. package/src/components/atoms/tooltip.tsx +3 -3
  20. package/src/components/molecules/chip.tsx +43 -4
  21. package/src/components/molecules/confirm-dialog.tsx +9 -0
  22. package/src/components/molecules/count-badge.tsx +115 -0
  23. package/src/components/molecules/data-table/data-table-filters.tsx +61 -21
  24. package/src/components/molecules/data-table/data-table-helpers.tsx +26 -1
  25. package/src/components/molecules/data-table/data-table-types.tsx +66 -2
  26. package/src/components/molecules/data-table/data-table.tsx +190 -35
  27. package/src/components/molecules/direction-link.tsx +1 -1
  28. package/src/components/molecules/format-provider.tsx +12 -2
  29. package/src/components/molecules/page-header.tsx +1 -1
  30. package/src/components/molecules/search-trigger.tsx +2 -18
  31. package/src/components/molecules/secret-value.tsx +6 -3
  32. package/src/components/molecules/state-views/loading-state.tsx +37 -7
  33. package/src/components/molecules/state-views/skeleton-parts.tsx +245 -0
  34. package/src/components/molecules/status-badge.tsx +2 -2
  35. package/src/components/molecules/timeline.tsx +1 -1
  36. package/src/hooks/use-active-label-size.ts +39 -5
  37. package/src/hooks/use-apple-platform.ts +26 -0
  38. package/src/lib/utils.ts +0 -7
@@ -2,6 +2,7 @@ import { Skeleton } from '@vendure-io/ui/components/atoms/skeleton';
2
2
  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
+ import { Children } from 'react';
5
6
 
6
7
  const loadingStateVariants = cva('flex w-full min-w-0 flex-col gap-3', {
7
8
  variants: {
@@ -20,7 +21,7 @@ const loadingStateVariants = cva('flex w-full min-w-0 flex-col gap-3', {
20
21
  export interface LoadingStateProps
21
22
  extends React.ComponentProps<'output'>,
22
23
  VariantProps<typeof loadingStateVariants> {
23
- /** Number of skeleton rows. `skeleton` variant only; defaults to 5. */
24
+ /** Number of skeleton rows. `skeleton` variant without children only; defaults to 5. */
24
25
  rows?: number;
25
26
  /** Classes applied to each skeleton row (e.g. `h-10` for tighter lists). */
26
27
  rowClassName?: string;
@@ -28,14 +29,33 @@ export interface LoadingStateProps
28
29
  label?: React.ReactNode;
29
30
  /** Sr-only label announced to assistive tech. Override for host i18n. @default "Loading…" */
30
31
  srLabel?: string;
32
+ /**
33
+ * Milliseconds before the placeholder appears. A load that ends sooner never
34
+ * shows it, so fast loads do not flash. `0` shows it at once. @default 150
35
+ */
36
+ delay?: number;
37
+ /**
38
+ * Skeleton parts in the shape of the page (`SkeletonPageHeader`,
39
+ * `SkeletonCard`, `SkeletonListRow`, …). Replace the `rows` bars.
40
+ * `skeleton` variant only. Children that render nothing (`false`, `null`,
41
+ * an empty array) fall back to the `rows` bars.
42
+ */
43
+ children?: React.ReactNode;
31
44
  }
32
45
 
46
+ // The placeholder holds its space at once but stays transparent for `delay`,
47
+ // then fades in. Under reduced motion it appears without the fade, still after
48
+ // the delay: the delay is not motion, it keeps fast loads from flashing.
49
+ const DELAYED_ENTRY =
50
+ '[animation:page-fade_var(--transition-duration-page-fade)_var(--ease-out)_var(--loading-state-delay)_both] motion-reduce:[animation-duration:0s]';
51
+
33
52
  /**
34
53
  * Placeholder shell for in-flight list/detail queries. Renders as an
35
54
  * `aria-live` `<output>` with an always-present sr-only `srLabel` (defaults to
36
55
  * "Loading…", overridable for host i18n).
37
- * `skeleton` (default) draws N shimmer rows; `spinner` centers the `Spinner`
38
- * atom for compact or unknown-height regions.
56
+ * `skeleton` (default) draws N shimmer rows, or the skeleton parts passed as
57
+ * children; `spinner` centers the `Spinner` atom for compact or unknown-height
58
+ * regions. Nothing shows for the first `delay` ms (150 by default).
39
59
  */
40
60
  function LoadingState({
41
61
  variant = 'skeleton',
@@ -43,14 +63,22 @@ function LoadingState({
43
63
  rowClassName,
44
64
  label,
45
65
  srLabel = 'Loading…',
66
+ delay = 150,
67
+ children,
46
68
  className,
69
+ style,
47
70
  ...props
48
71
  }: LoadingStateProps) {
49
72
  return (
50
73
  <output
51
74
  data-slot="loading-state"
52
75
  aria-live="polite"
53
- className={cn(loadingStateVariants({ variant }), className)}
76
+ className={cn(loadingStateVariants({ variant }), delay > 0 && DELAYED_ENTRY, className)}
77
+ style={
78
+ delay > 0
79
+ ? ({ '--loading-state-delay': `${delay}ms`, ...style } as React.CSSProperties)
80
+ : style
81
+ }
54
82
  {...props}
55
83
  >
56
84
  <span className="sr-only">{srLabel}</span>
@@ -72,9 +100,11 @@ function LoadingState({
72
100
  {label}
73
101
  </span>
74
102
  ) : null}
75
- {Array.from({ length: rows }).map((_, i) => (
76
- <Skeleton key={i} className={cn('h-14 w-full rounded-md', rowClassName)} />
77
- ))}
103
+ {Children.toArray(children).length > 0
104
+ ? children
105
+ : Array.from({ length: rows }).map((_, i) => (
106
+ <Skeleton key={i} className={cn('h-14 w-full rounded-md', rowClassName)} />
107
+ ))}
78
108
  </>
79
109
  )}
80
110
  </output>
@@ -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
+ };
@@ -405,8 +405,8 @@ function StatusBadgeMarker({
405
405
  icon: React.ReactNode;
406
406
  className?: string;
407
407
  }) {
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
408
+ // 13px icons in the 12px chip, 14px in the 14px chip, 16px beside the
409
+ // 14px label of the `icon` appearance, all at stroke 2. The
410
410
  // marker eases to a new tone with the outline, when a status changes in place.
411
411
  // Size and stroke are `!important`: a Button sizes every icon inside it to
412
412
  // 16px at stroke 1.75, with a selector that outranks this one, and a badge
@@ -164,7 +164,7 @@ function TimelineContent({ className, ...props }: React.ComponentProps<'div'>) {
164
164
 
165
165
  const titleClassName = 'text-sm leading-5 text-foreground text-pretty';
166
166
 
167
- /** The sentence of an entry: what happened, in 13px on a 20px line. */
167
+ /** The sentence of an entry: what happened, in 14px on a 20px line. */
168
168
  function TimelineTitle({ className, ...props }: React.ComponentProps<'p'>) {
169
169
  return <p data-slot="timeline-title" className={cn(titleClassName, className)} {...props} />;
170
170
  }
@@ -8,25 +8,59 @@ import * as React from 'react';
8
8
  * first paint, or a label whose text changes, resizes the swap too.
9
9
  * `offsetWidth` ignores a scale on an ancestor (a tooltip's entrance, a
10
10
  * pressed card), which `getBoundingClientRect` would include.
11
+ *
12
+ * With `natural`, the width is the label's full text width, rounded up,
13
+ * also while the label is cut with an ellipsis: the swap keeps that width and
14
+ * its container shrinks it, so the cut never feeds back into the size.
11
15
  */
12
- export function useActiveLabelSize(active: number) {
16
+ export function useActiveLabelSize(
17
+ active: number,
18
+ { natural = false, key }: { natural?: boolean; key?: string } = {},
19
+ ) {
13
20
  const refs = React.useRef<(HTMLSpanElement | null)[]>([]);
14
21
  const [size, setSize] = React.useState<{ width: number; height: number }>();
22
+ // biome-ignore lint/correctness/useExhaustiveDependencies: `key` only re-runs the measure when the active label's text changes.
15
23
  React.useLayoutEffect(() => {
16
24
  const label = refs.current[active];
17
25
  if (!label) return;
18
26
  const measure = () => {
19
- const width = label.offsetWidth;
27
+ const width = natural ? naturalWidth(label) : label.offsetWidth;
20
28
  const height = label.offsetHeight;
21
29
  setSize((last) =>
22
30
  last?.width === width && last.height === height ? last : { width, height },
23
31
  );
24
32
  };
25
33
  measure();
26
- if (typeof ResizeObserver === 'undefined') return;
34
+ // A cut label's box does not grow when a web font arrives, so the
35
+ // ResizeObserver misses it: measure again when fonts load.
36
+ const fonts = natural && typeof document !== 'undefined' ? document.fonts : undefined;
37
+ fonts?.addEventListener('loadingdone', measure);
38
+ void fonts?.ready.then(measure);
39
+ if (typeof ResizeObserver === 'undefined') {
40
+ return () => fonts?.removeEventListener('loadingdone', measure);
41
+ }
27
42
  const observer = new ResizeObserver(measure);
28
43
  observer.observe(label);
29
- return () => observer.disconnect();
30
- }, [active]);
44
+ return () => {
45
+ observer.disconnect();
46
+ fonts?.removeEventListener('loadingdone', measure);
47
+ };
48
+ }, [active, natural, key]);
31
49
  return { refs, width: size?.width, height: size?.height };
32
50
  }
51
+
52
+ /**
53
+ * The full width of a label's text, also while it is cut, rounded up to a
54
+ * whole pixel: `scrollWidth` rounds down, and a text 0.4px wider than its
55
+ * box shows an ellipsis. A scale on an ancestor is taken out.
56
+ */
57
+ function naturalWidth(label: HTMLElement) {
58
+ const range = document.createRange();
59
+ range.selectNodeContents(label);
60
+ // The scale from the unrounded layout width: offsetWidth rounds, and a
61
+ // scale read from it moves the result by a pixel on every measure.
62
+ const box = label.getBoundingClientRect().width;
63
+ const layout = Number.parseFloat(getComputedStyle(label).width);
64
+ const scale = layout > 0 && box > 0 ? box / layout : 1;
65
+ return Math.max(label.offsetWidth, Math.ceil(range.getBoundingClientRect().width / scale - 0.01));
66
+ }
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+
3
+ import { useSyncExternalStore } from 'react';
4
+
5
+ const subscribe = () => () => {};
6
+
7
+ // Apple platforms show ⌘, the rest show Ctrl. The server and the first
8
+ // hydration render have no platform, so they get false (Ctrl); React swaps in
9
+ // the client value right after hydration without a mismatch error.
10
+ function isApplePlatform() {
11
+ if (typeof navigator === 'undefined') return false;
12
+ const nav = navigator as Navigator & { userAgentData?: { platform?: string } };
13
+ const platform = nav.userAgentData?.platform || nav.platform || nav.userAgent;
14
+ return /mac|iphone|ipad|ipod/i.test(platform);
15
+ }
16
+
17
+ /**
18
+ * Whether the browser runs on an Apple platform, to label a shortcut with ⌘
19
+ * there and Ctrl elsewhere. False on the server and in the first hydration
20
+ * render.
21
+ */
22
+ function useIsApplePlatform() {
23
+ return useSyncExternalStore(subscribe, isApplePlatform, () => false);
24
+ }
25
+
26
+ export { useIsApplePlatform };
package/src/lib/utils.ts CHANGED
@@ -37,16 +37,9 @@ const twMerge = extendTailwindMerge<'text-style'>({
37
37
  'normal',
38
38
  'slow',
39
39
  'slower',
40
- 'palette-detail-delay',
41
- 'palette-result-delay',
42
- 'palette-detail-exit',
43
40
  'palette-exit',
44
- 'palette-tint',
45
- 'palette-result-exit',
46
41
  'palette-enter',
47
42
  'palette-move',
48
- 'palette-detail-move',
49
- 'palette-result-blur',
50
43
  'tooltip-enter',
51
44
  'tooltip-delay',
52
45
  'tooltip-label-fade',