@vendure-io/ui 3.0.0-next.1 → 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.
@@ -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
  }