@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.
- package/THIRD_PARTY_NOTICES.md +38 -0
- package/package.json +6 -4
- package/src/components/atoms/breadcrumb.tsx +67 -9
- package/src/components/atoms/button.tsx +106 -9
- package/src/components/atoms/calendar.tsx +11 -2
- package/src/components/atoms/card.tsx +47 -0
- package/src/components/atoms/collapsible.tsx +22 -2
- package/src/components/atoms/field.tsx +4 -1
- package/src/components/atoms/label-swap.tsx +27 -2
- package/src/components/atoms/sonner.tsx +1 -1
- package/src/components/atoms/switch.tsx +59 -3
- package/src/components/atoms/table.tsx +133 -10
- package/src/components/atoms/text-link.tsx +125 -0
- package/src/components/molecules/app-shell.tsx +24 -2
- package/src/components/molecules/checklist/checklist.tsx +891 -0
- package/src/components/molecules/choice-card.tsx +377 -0
- package/src/components/molecules/collapsible-section.tsx +6 -5
- package/src/components/molecules/data-table/data-table-helpers.tsx +6 -1
- package/src/components/molecules/data-table/data-table-types.tsx +27 -2
- package/src/components/molecules/data-table/data-table.tsx +154 -30
- package/src/components/molecules/direction-link.tsx +1 -1
- package/src/components/molecules/format-provider.tsx +12 -2
- package/src/components/molecules/interactive-card.tsx +45 -0
- package/src/components/molecules/page-header.tsx +1 -1
- package/src/components/molecules/search-trigger.tsx +1 -1
- package/src/components/molecules/state-views/loading-state.tsx +37 -7
- package/src/components/molecules/state-views/skeleton-parts.tsx +245 -0
- package/src/components/molecules/status-badge.tsx +49 -16
- package/src/components/molecules/step-indicator.tsx +341 -0
- package/src/components/molecules/timeline.tsx +1 -1
- package/src/hooks/use-user-toggle-motion.ts +50 -0
- package/src/lib/state-dictionary.ts +9 -7
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Checkbox as CheckboxPrimitive } from '@base-ui/react/checkbox';
|
|
4
|
+
import { CheckboxGroup as CheckboxGroupPrimitive } from '@base-ui/react/checkbox-group';
|
|
5
|
+
import { Radio as RadioPrimitive } from '@base-ui/react/radio';
|
|
6
|
+
import { RadioGroup as RadioGroupPrimitive } from '@base-ui/react/radio-group';
|
|
7
|
+
import { Badge } from '@vendure-io/ui/components/atoms/badge';
|
|
8
|
+
import { useFieldControlProps } from '@vendure-io/ui/components/atoms/field';
|
|
9
|
+
import { cn } from '@vendure-io/ui/lib/utils';
|
|
10
|
+
import { cva } from 'class-variance-authority';
|
|
11
|
+
import { CheckIcon } from 'lucide-react';
|
|
12
|
+
import * as React from 'react';
|
|
13
|
+
|
|
14
|
+
import { interactiveCardVariants } from './interactive-card.tsx';
|
|
15
|
+
|
|
16
|
+
// A card the user picks from a set: a plan, a shipping method, an address, an
|
|
17
|
+
// asset. The card itself is the control. In a single-choice group it is a Base
|
|
18
|
+
// UI Radio (arrow keys move the choice, role="radio"); in a multiple-choice
|
|
19
|
+
// group a Base UI Checkbox (Space toggles, role="checkbox"). Base UI sets the
|
|
20
|
+
// role, aria-checked, the disabled state and the hidden form input.
|
|
21
|
+
//
|
|
22
|
+
// The look is the shared interactive card (interactive-card.tsx). Selected
|
|
23
|
+
// draws one 2px primary edge on ::after, on the border box, so it reads as one
|
|
24
|
+
// stroke with no layout shift and stays over a media image; the focus
|
|
25
|
+
// ring is an outline outside it, so both show together. The indicator (a radio
|
|
26
|
+
// dot or a check box) shows the state in shape too, not only in colour.
|
|
27
|
+
//
|
|
28
|
+
// The card's accessible name is its title, and its description is the
|
|
29
|
+
// description plus the meta. Slots hold text and images only: a card is one
|
|
30
|
+
// control, so a link or button inside it is not reachable as its own control.
|
|
31
|
+
|
|
32
|
+
type ChoiceCardMode = 'single' | 'multiple';
|
|
33
|
+
|
|
34
|
+
const ChoiceCardGroupContext = React.createContext<ChoiceCardMode>('single');
|
|
35
|
+
|
|
36
|
+
type ChoiceCardGroupProps =
|
|
37
|
+
| ({ multiple?: false } & RadioGroupPrimitive.Props)
|
|
38
|
+
| ({ multiple: true } & CheckboxGroupPrimitive.Props);
|
|
39
|
+
|
|
40
|
+
const groupClassName = 'grid w-full gap-3';
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A set of ChoiceCards. Single choice by default (a radio group); `multiple`
|
|
44
|
+
* makes it a checkbox group, with `value` as an array. Give it an
|
|
45
|
+
* `aria-label` or `aria-labelledby`.
|
|
46
|
+
*/
|
|
47
|
+
function ChoiceCardGroup(props: ChoiceCardGroupProps) {
|
|
48
|
+
const fieldProps = useFieldControlProps(props);
|
|
49
|
+
if (fieldProps.multiple) {
|
|
50
|
+
const { multiple: _, className, ...rest } = fieldProps;
|
|
51
|
+
return (
|
|
52
|
+
<ChoiceCardGroupContext.Provider value="multiple">
|
|
53
|
+
<CheckboxGroupPrimitive
|
|
54
|
+
data-slot="choice-card-group"
|
|
55
|
+
data-mode="multiple"
|
|
56
|
+
className={(state) =>
|
|
57
|
+
cn(groupClassName, typeof className === 'function' ? className(state) : className)
|
|
58
|
+
}
|
|
59
|
+
{...rest}
|
|
60
|
+
/>
|
|
61
|
+
</ChoiceCardGroupContext.Provider>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
const { multiple: _, className, ...rest } = fieldProps;
|
|
65
|
+
return (
|
|
66
|
+
<ChoiceCardGroupContext.Provider value="single">
|
|
67
|
+
<RadioGroupPrimitive
|
|
68
|
+
data-slot="choice-card-group"
|
|
69
|
+
data-mode="single"
|
|
70
|
+
className={(state) =>
|
|
71
|
+
cn(groupClassName, typeof className === 'function' ? className(state) : className)
|
|
72
|
+
}
|
|
73
|
+
{...rest}
|
|
74
|
+
/>
|
|
75
|
+
</ChoiceCardGroupContext.Provider>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// The ids the card points its aria-labelledby and aria-describedby at. The
|
|
80
|
+
// title is the name from the first render, so a card without a ChoiceCardTitle
|
|
81
|
+
// needs an aria-label (the media variant). The description and the meta
|
|
82
|
+
// register their ids once they mount, so the card never points at a missing
|
|
83
|
+
// element.
|
|
84
|
+
interface ChoiceCardParts {
|
|
85
|
+
titleId: string;
|
|
86
|
+
descriptionId: string;
|
|
87
|
+
metaId: string;
|
|
88
|
+
register: (part: 'title' | 'description' | 'meta') => () => void;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const ChoiceCardPartsContext = React.createContext<ChoiceCardParts | null>(null);
|
|
92
|
+
|
|
93
|
+
function useChoiceCardPart(part: 'title' | 'description' | 'meta') {
|
|
94
|
+
const parts = React.useContext(ChoiceCardPartsContext);
|
|
95
|
+
const register = parts?.register;
|
|
96
|
+
React.useEffect(() => register?.(part), [register, part]);
|
|
97
|
+
if (!parts) return undefined;
|
|
98
|
+
return part === 'title'
|
|
99
|
+
? parts.titleId
|
|
100
|
+
: part === 'description'
|
|
101
|
+
? parts.descriptionId
|
|
102
|
+
: parts.metaId;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const choiceCardVariants = cva(
|
|
106
|
+
[
|
|
107
|
+
'group/choice-card flex text-start',
|
|
108
|
+
// Selected: one 2px inset primary stroke on ::after. The ::after sits on
|
|
109
|
+
// the border box (-inset-px) with the card's radius, so it covers the
|
|
110
|
+
// border and adds the inner pixel in one curve. On the padding box
|
|
111
|
+
// (inset-0) its corners would take the outer radius and leave a gap
|
|
112
|
+
// between two strokes. So the card never clips its children: the media
|
|
113
|
+
// variant rounds the image itself to the padding box instead.
|
|
114
|
+
'after:pointer-events-none after:absolute after:-inset-px after:z-10 after:rounded-[inherit] after:[transition:box-shadow_var(--transition-duration-fast)_var(--ease-soft)] data-checked:border-primary data-checked:hover:border-primary data-checked:after:shadow-[inset_0_0_0_2px_var(--primary)]',
|
|
115
|
+
],
|
|
116
|
+
{
|
|
117
|
+
variants: {
|
|
118
|
+
variant: {
|
|
119
|
+
default: 'items-start gap-3',
|
|
120
|
+
// An image tile: the image fills the card, the indicator sits in the
|
|
121
|
+
// start corner over it. The image takes the padding-box radius (the
|
|
122
|
+
// card radius minus the 1px border) rather than the card clipping it,
|
|
123
|
+
// which would cut the selected stroke at the border's inner edge.
|
|
124
|
+
media:
|
|
125
|
+
'aspect-square p-0 [&_img]:size-full [&_img]:rounded-[calc(var(--radius-2xl)-1px)] [&_img]:object-cover [&_video]:size-full [&_video]:rounded-[calc(var(--radius-2xl)-1px)] [&_video]:object-cover',
|
|
126
|
+
},
|
|
127
|
+
size: {
|
|
128
|
+
default: '',
|
|
129
|
+
sm: '',
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
compoundVariants: [
|
|
133
|
+
{ variant: 'default', size: 'default', className: 'p-4' },
|
|
134
|
+
{ variant: 'default', size: 'sm', className: 'gap-2.5 p-3' },
|
|
135
|
+
],
|
|
136
|
+
defaultVariants: { variant: 'default', size: 'default' },
|
|
137
|
+
},
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
// The indicator box: a radio circle or a check box, 16px like the form
|
|
141
|
+
// controls. Unchecked it is the control outline; checked it fills primary. In
|
|
142
|
+
// the media variant it sits in the corner on a background disc so it reads on
|
|
143
|
+
// any image, and while unchecked it shows only on hover or keyboard focus
|
|
144
|
+
// (always on a touch screen, where there is no hover).
|
|
145
|
+
// Motion: colours and the corner reveal fade in `fast`. The radio dot grows
|
|
146
|
+
// from half size on the strong ease-out (never from 0) while it fades in;
|
|
147
|
+
// reduced motion keeps the fade and drops the growth.
|
|
148
|
+
const indicatorClassName = [
|
|
149
|
+
'relative z-20 flex size-4 shrink-0 items-center justify-center border border-control-border bg-background text-primary-foreground [transition:background-color_var(--transition-duration-fast)_var(--ease-soft),border-color_var(--transition-duration-fast)_var(--ease-soft),opacity_var(--transition-duration-fast)_var(--ease-soft)] group-data-checked/choice-card:border-primary group-data-checked/choice-card:bg-primary',
|
|
150
|
+
// Lines the box up with the first line of the title.
|
|
151
|
+
'group-data-[variant=default]/choice-card:mt-0.5',
|
|
152
|
+
'group-data-[variant=media]/choice-card:absolute group-data-[variant=media]/choice-card:top-2 group-data-[variant=media]/choice-card:start-2 group-data-[variant=media]/choice-card:shadow-control group-data-[variant=media]/choice-card:group-data-unchecked/choice-card:opacity-0 group-hover/choice-card:opacity-100! group-focus-visible/choice-card:opacity-100! pointer-coarse:opacity-100!',
|
|
153
|
+
].join(' ');
|
|
154
|
+
|
|
155
|
+
function ChoiceCardIndicator({ mode }: { mode: ChoiceCardMode }) {
|
|
156
|
+
if (mode === 'single') {
|
|
157
|
+
return (
|
|
158
|
+
<span
|
|
159
|
+
data-slot="choice-card-indicator"
|
|
160
|
+
aria-hidden="true"
|
|
161
|
+
className={cn(indicatorClassName, 'rounded-full')}
|
|
162
|
+
>
|
|
163
|
+
<span className="size-1.5 scale-50 rounded-full bg-primary-foreground opacity-0 [transition:scale_var(--transition-duration-moderate)_var(--ease-out),opacity_var(--transition-duration-fast)_var(--ease-soft)] group-data-checked/choice-card:scale-100 group-data-checked/choice-card:opacity-100 motion-reduce:scale-100" />
|
|
164
|
+
</span>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
return (
|
|
168
|
+
<span
|
|
169
|
+
data-slot="choice-card-indicator"
|
|
170
|
+
aria-hidden="true"
|
|
171
|
+
className={cn(indicatorClassName, 'rounded-md')}
|
|
172
|
+
>
|
|
173
|
+
<CheckIcon
|
|
174
|
+
aria-hidden="true"
|
|
175
|
+
strokeWidth={2.5}
|
|
176
|
+
className="size-3.5 opacity-0 [transition:opacity_var(--transition-duration-fast)_var(--ease-soft)] group-data-checked/choice-card:opacity-100"
|
|
177
|
+
/>
|
|
178
|
+
</span>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// The props both Base UI roots share. State-function forms of className and
|
|
183
|
+
// style are left out: the card renders either root.
|
|
184
|
+
type ChoiceCardProps = Omit<
|
|
185
|
+
RadioPrimitive.Root.Props<string>,
|
|
186
|
+
'value' | 'render' | 'className' | 'style' | 'nativeButton' | 'inputRef'
|
|
187
|
+
> & {
|
|
188
|
+
className?: string;
|
|
189
|
+
style?: React.CSSProperties;
|
|
190
|
+
/** Identifies the card in its group. */
|
|
191
|
+
value: string;
|
|
192
|
+
disabled?: boolean;
|
|
193
|
+
/** `media`: an image tile that the image fills. Give it an `aria-label`. */
|
|
194
|
+
variant?: 'default' | 'media';
|
|
195
|
+
size?: 'default' | 'sm';
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* One choice in a ChoiceCardGroup: a radio card in a single-choice group, a
|
|
200
|
+
* checkbox card in a multiple-choice group.
|
|
201
|
+
*/
|
|
202
|
+
function ChoiceCard({
|
|
203
|
+
className,
|
|
204
|
+
variant = 'default',
|
|
205
|
+
size = 'default',
|
|
206
|
+
value,
|
|
207
|
+
disabled,
|
|
208
|
+
children,
|
|
209
|
+
...props
|
|
210
|
+
}: ChoiceCardProps) {
|
|
211
|
+
const mode = React.useContext(ChoiceCardGroupContext);
|
|
212
|
+
const id = React.useId();
|
|
213
|
+
const [mounted, setMounted] = React.useState<ReadonlySet<string>>(new Set());
|
|
214
|
+
const register = React.useCallback((part: string) => {
|
|
215
|
+
setMounted((current) => new Set(current).add(part));
|
|
216
|
+
return () =>
|
|
217
|
+
setMounted((current) => {
|
|
218
|
+
const next = new Set(current);
|
|
219
|
+
next.delete(part);
|
|
220
|
+
return next;
|
|
221
|
+
});
|
|
222
|
+
}, []);
|
|
223
|
+
const parts = React.useMemo(
|
|
224
|
+
() => ({
|
|
225
|
+
titleId: `${id}-title`,
|
|
226
|
+
descriptionId: `${id}-description`,
|
|
227
|
+
metaId: `${id}-meta`,
|
|
228
|
+
register,
|
|
229
|
+
}),
|
|
230
|
+
[id, register],
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
const describedBy = [
|
|
234
|
+
props['aria-describedby'],
|
|
235
|
+
mounted.has('description') ? parts.descriptionId : undefined,
|
|
236
|
+
mounted.has('meta') ? parts.metaId : undefined,
|
|
237
|
+
]
|
|
238
|
+
.filter(Boolean)
|
|
239
|
+
.join(' ');
|
|
240
|
+
const ariaProps = {
|
|
241
|
+
'aria-labelledby':
|
|
242
|
+
props['aria-labelledby'] ?? (props['aria-label'] ? undefined : parts.titleId),
|
|
243
|
+
'aria-describedby': describedBy || undefined,
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const rootProps = {
|
|
247
|
+
...props,
|
|
248
|
+
...ariaProps,
|
|
249
|
+
'data-slot': 'choice-card',
|
|
250
|
+
'data-variant': variant,
|
|
251
|
+
'data-size': size,
|
|
252
|
+
className: cn(interactiveCardVariants(), choiceCardVariants({ variant, size }), className),
|
|
253
|
+
render: <div />,
|
|
254
|
+
value,
|
|
255
|
+
disabled,
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const content = (
|
|
259
|
+
<ChoiceCardPartsContext.Provider value={parts}>
|
|
260
|
+
<ChoiceCardIndicator mode={mode} />
|
|
261
|
+
{children}
|
|
262
|
+
</ChoiceCardPartsContext.Provider>
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
return mode === 'multiple' ? (
|
|
266
|
+
<CheckboxPrimitive.Root {...rootProps}>{content}</CheckboxPrimitive.Root>
|
|
267
|
+
) : (
|
|
268
|
+
<RadioPrimitive.Root {...rootProps}>{content}</RadioPrimitive.Root>
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const choiceCardMediaVariants = cva('flex shrink-0 items-center justify-center', {
|
|
273
|
+
variants: {
|
|
274
|
+
variant: {
|
|
275
|
+
// A product image or logo beside the text.
|
|
276
|
+
image: 'size-10 overflow-hidden rounded-lg [&_img]:size-full [&_img]:object-cover',
|
|
277
|
+
// An icon, quieter than the title.
|
|
278
|
+
icon: 'mt-px [&_svg]:pointer-events-none [&_svg:not([class*=size-])]:size-4 [&_svg:not([class*=stroke-])]:stroke-[1.75] text-muted-foreground',
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
defaultVariants: { variant: 'icon' },
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
/** Leading media of a default card: an icon, or an image or logo. */
|
|
285
|
+
function ChoiceCardMedia({
|
|
286
|
+
className,
|
|
287
|
+
variant = 'icon',
|
|
288
|
+
...props
|
|
289
|
+
}: React.ComponentProps<'div'> & { variant?: 'icon' | 'image' }) {
|
|
290
|
+
return (
|
|
291
|
+
<div
|
|
292
|
+
data-slot="choice-card-media"
|
|
293
|
+
data-variant={variant}
|
|
294
|
+
className={cn(choiceCardMediaVariants({ variant }), className)}
|
|
295
|
+
{...props}
|
|
296
|
+
/>
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Holds the title and the description. Takes the free width. */
|
|
301
|
+
function ChoiceCardContent({ className, ...props }: React.ComponentProps<'div'>) {
|
|
302
|
+
return (
|
|
303
|
+
<div
|
|
304
|
+
data-slot="choice-card-content"
|
|
305
|
+
className={cn('flex min-w-0 flex-1 flex-col gap-0.5', className)}
|
|
306
|
+
{...props}
|
|
307
|
+
/>
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** The card's name. A ChoiceCardBadge inside it sits on the title line. */
|
|
312
|
+
function ChoiceCardTitle({ className, id, ...props }: React.ComponentProps<'div'>) {
|
|
313
|
+
const partId = useChoiceCardPart('title');
|
|
314
|
+
return (
|
|
315
|
+
<div
|
|
316
|
+
id={id ?? partId}
|
|
317
|
+
data-slot="choice-card-title"
|
|
318
|
+
className={cn(
|
|
319
|
+
'flex flex-wrap items-center gap-x-2 gap-y-1 text-sm font-medium text-foreground',
|
|
320
|
+
className,
|
|
321
|
+
)}
|
|
322
|
+
{...props}
|
|
323
|
+
/>
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function ChoiceCardDescription({ className, id, ...props }: React.ComponentProps<'p'>) {
|
|
328
|
+
const partId = useChoiceCardPart('description');
|
|
329
|
+
return (
|
|
330
|
+
<p
|
|
331
|
+
id={id ?? partId}
|
|
332
|
+
data-slot="choice-card-description"
|
|
333
|
+
className={cn('text-sm text-muted-foreground', className)}
|
|
334
|
+
{...props}
|
|
335
|
+
/>
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** Trailing detail, such as a price or a delivery time. */
|
|
340
|
+
function ChoiceCardMeta({ className, id, ...props }: React.ComponentProps<'div'>) {
|
|
341
|
+
const partId = useChoiceCardPart('meta');
|
|
342
|
+
return (
|
|
343
|
+
<div
|
|
344
|
+
id={id ?? partId}
|
|
345
|
+
data-slot="choice-card-meta"
|
|
346
|
+
className={cn(
|
|
347
|
+
'ms-auto shrink-0 text-end text-sm text-foreground-secondary tabular-nums',
|
|
348
|
+
className,
|
|
349
|
+
)}
|
|
350
|
+
{...props}
|
|
351
|
+
/>
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* A marker on the title line, such as "Current" on the plan the customer is
|
|
357
|
+
* on. It says nothing about selection: the current plan can be unselected
|
|
358
|
+
* while the user picks another one.
|
|
359
|
+
*/
|
|
360
|
+
function ChoiceCardBadge({ className, ...props }: React.ComponentProps<typeof Badge>) {
|
|
361
|
+
return (
|
|
362
|
+
<Badge data-slot="choice-card-badge" className={cn('font-medium', className)} {...props} />
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export {
|
|
367
|
+
ChoiceCard,
|
|
368
|
+
ChoiceCardBadge,
|
|
369
|
+
ChoiceCardContent,
|
|
370
|
+
ChoiceCardDescription,
|
|
371
|
+
ChoiceCardGroup,
|
|
372
|
+
ChoiceCardMedia,
|
|
373
|
+
ChoiceCardMeta,
|
|
374
|
+
ChoiceCardTitle,
|
|
375
|
+
type ChoiceCardGroupProps,
|
|
376
|
+
type ChoiceCardProps,
|
|
377
|
+
};
|
|
@@ -107,17 +107,18 @@ function CollapsibleSection({
|
|
|
107
107
|
/>
|
|
108
108
|
</CollapsibleTrigger>
|
|
109
109
|
</Heading>
|
|
110
|
-
{/*
|
|
111
|
-
|
|
110
|
+
{/* The panel's height motion comes from CollapsibleContent; the card
|
|
111
|
+
clips the rows to its corners. */}
|
|
112
112
|
<CollapsibleContent
|
|
113
113
|
data-slot="collapsible-section-panel"
|
|
114
|
-
className="group/collapsible-section-panel
|
|
114
|
+
className="group/collapsible-section-panel border-t border-border"
|
|
115
115
|
>
|
|
116
116
|
{/* Opening, the rows fade in over the second half of the height;
|
|
117
|
-
closing, they leave at once so the height settles on nothing.
|
|
117
|
+
closing, they leave at once so the height settles on nothing.
|
|
118
|
+
Under reduced motion the panel's own fade replaces this. */}
|
|
118
119
|
<div
|
|
119
120
|
data-slot="collapsible-section-rows"
|
|
120
|
-
className="transition-opacity delay-(--transition-duration-moderate) duration-moderate ease-out group-data-ending-style/collapsible-section-panel:opacity-0 group-data-ending-style/collapsible-section-panel:delay-0 group-data-ending-style/collapsible-section-panel:duration-fast group-data-starting-style/collapsible-section-panel:opacity-0"
|
|
121
|
+
className="motion-safe:transition-opacity motion-safe:delay-(--transition-duration-moderate) motion-safe:duration-moderate motion-safe:ease-out motion-safe:group-data-ending-style/collapsible-section-panel:opacity-0 motion-safe:group-data-ending-style/collapsible-section-panel:delay-0 motion-safe:group-data-ending-style/collapsible-section-panel:duration-fast motion-safe:group-data-starting-style/collapsible-section-panel:opacity-0"
|
|
121
122
|
>
|
|
122
123
|
{children}
|
|
123
124
|
</div>
|
|
@@ -123,7 +123,12 @@ export function measureColumnIndents(table: HTMLTableElement): Record<string, nu
|
|
|
123
123
|
for (const cell of cells) {
|
|
124
124
|
const id = cell.dataset.columnId;
|
|
125
125
|
const first = cell.firstElementChild;
|
|
126
|
-
|
|
126
|
+
// A pinned table's row-link overlay host comes after the content, so it is
|
|
127
|
+
// first only in a cell without content elements. It is not content: its
|
|
128
|
+
// overlay spans the whole row.
|
|
129
|
+
const host =
|
|
130
|
+
(first as HTMLElement | null)?.dataset?.slot === 'data-table-row-link-overlay-host';
|
|
131
|
+
if (id == null || first == null || host) continue;
|
|
127
132
|
const style = getComputedStyle(cell);
|
|
128
133
|
const rtl = style.direction === 'rtl';
|
|
129
134
|
const start = (rect: DOMRect) => (rtl ? -rect.right : rect.left);
|
|
@@ -225,11 +225,14 @@ export interface DataTableRowRipple {
|
|
|
225
225
|
* (`<TableCell {...cellProps(cell.column.id)}>`) and the cell matches the
|
|
226
226
|
* built-in row: the select cell is the zero-width cell the checkbox floats
|
|
227
227
|
* over, the leading data cell carries the checkbox gutter, and every cell
|
|
228
|
-
* lines its content up with the header.
|
|
228
|
+
* lines its content up with the header. With `pinFirstColumn`, the leading
|
|
229
|
+
* data cell carries `data-pinned`, so it stays at the edge with the select
|
|
230
|
+
* cell. Merge your own classes with `cn`.
|
|
229
231
|
*/
|
|
230
232
|
export interface DataTableRowCellProps {
|
|
231
233
|
'data-column-id': string;
|
|
232
234
|
'data-content-inset-cell': string;
|
|
235
|
+
'data-pinned': '' | undefined;
|
|
233
236
|
className: string;
|
|
234
237
|
style: React.CSSProperties | undefined;
|
|
235
238
|
}
|
|
@@ -381,7 +384,9 @@ export interface DataTableProps<TData> {
|
|
|
381
384
|
* are selected; a row without it keeps opening the item from anywhere on it.
|
|
382
385
|
* A row with a `DataTableRowLink` needs nothing more: the table raises its
|
|
383
386
|
* buttons, links, inputs and copy chips above the stretched link, as it does
|
|
384
|
-
* on a built-in row.
|
|
387
|
+
* on a built-in row. With `pinFirstColumn`, render `ctx.rowLinkHost(columnId)`
|
|
388
|
+
* at the end of every cell too, so the whole row opens the item (see
|
|
389
|
+
* `pinFirstColumn`).
|
|
385
390
|
*/
|
|
386
391
|
renderRow?: (
|
|
387
392
|
row: Row<TData>,
|
|
@@ -391,6 +396,13 @@ export interface DataTableProps<TData> {
|
|
|
391
396
|
defaultRow: React.ReactNode;
|
|
392
397
|
ripple: DataTableRowRipple;
|
|
393
398
|
cellProps: (columnId: string) => DataTableRowCellProps;
|
|
399
|
+
/**
|
|
400
|
+
* Where a `DataTableRowLink` draws the anchor that opens the item from
|
|
401
|
+
* the cells on the other side of the pinned edge. Render it as the last
|
|
402
|
+
* child of every cell: `{ctx.rowLinkHost(cell.column.id)}`. It is `null`
|
|
403
|
+
* without `pinFirstColumn`, and in the cells that need no host.
|
|
404
|
+
*/
|
|
405
|
+
rowLinkHost: (columnId: string) => React.ReactNode;
|
|
394
406
|
selectProps: DataTableRowSelectProps;
|
|
395
407
|
},
|
|
396
408
|
) => React.ReactNode;
|
|
@@ -435,6 +447,19 @@ export interface DataTableProps<TData> {
|
|
|
435
447
|
* edge-cell alignment — the host card is the frame.
|
|
436
448
|
*/
|
|
437
449
|
frame?: 'card' | 'plain';
|
|
450
|
+
/**
|
|
451
|
+
* Keeps the first column in place while the others scroll sideways (Table's
|
|
452
|
+
* `pinFirstColumn`). The select checkbox is pinned with it, and a selected
|
|
453
|
+
* row's bar stays on the pinned edge. A `DataTableRowLink` still opens the
|
|
454
|
+
* item from every cell: the name stays the row's one link, and the cells
|
|
455
|
+
* that scroll under the pinned column open it through a second anchor with
|
|
456
|
+
* the same href, hidden from assistive technology and the tab order. A row
|
|
457
|
+
* from `renderRow` that renders its own cells gets that anchor when it
|
|
458
|
+
* renders `ctx.rowLinkHost(cell.column.id)` after the content of every cell;
|
|
459
|
+
* without it, only the cells on the link's side of the pinned edge open the
|
|
460
|
+
* item.
|
|
461
|
+
*/
|
|
462
|
+
pinFirstColumn?: boolean;
|
|
438
463
|
/**
|
|
439
464
|
* Extra `<TableRow>`s appended inside `TableBody` after the data rows — e.g.
|
|
440
465
|
* an order table's subtotal/shipping/total rows. Rendered only alongside
|