@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
|
@@ -3,33 +3,89 @@
|
|
|
3
3
|
import { Switch as SwitchPrimitive } from "@base-ui/react/switch"
|
|
4
4
|
|
|
5
5
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
6
|
+
import { useUserToggleMotion } from "../../hooks/use-user-toggle-motion"
|
|
6
7
|
import {
|
|
7
8
|
useFieldControlProps,
|
|
8
9
|
useFieldLabelCheckedClass,
|
|
9
10
|
} from "@vendure-io/ui/components/atoms/field"
|
|
10
11
|
|
|
12
|
+
// The thumb slides with `translate` and widens a little while pressed, both
|
|
13
|
+
// with the Checkbox's tokens. Only `translate`, `scale` and colours move, so
|
|
14
|
+
// nothing changes layout.
|
|
15
|
+
// - Checking: the track fills in `normal` on `ease-out` and the thumb slides
|
|
16
|
+
// in `normal` on `ease-out`. Unchecking is quicker: `fast` on `ease-soft`
|
|
17
|
+
// for the track, `moderate` on `ease-out` for the thumb.
|
|
18
|
+
// - A press stretches the thumb to 115% of its width (`fast`, `ease-press`)
|
|
19
|
+
// toward the middle of the track: it grows from the side it rests on. The
|
|
20
|
+
// scale is its own property, so it adds to the slide instead of replacing
|
|
21
|
+
// it. A disabled switch does not respond.
|
|
22
|
+
// - Transitions only, no keyframes: a fast double toggle reverses from where
|
|
23
|
+
// the thumb is, and nothing plays on first render, where there is no
|
|
24
|
+
// previous value to move from.
|
|
25
|
+
// - Reduced motion: no slide and no stretch. The thumb is at its place at
|
|
26
|
+
// once; only the colours fade.
|
|
27
|
+
// - Only the user moves it. A controlled `checked` that changes from code
|
|
28
|
+
// (data loads after render, a form reset, another control) shows at once:
|
|
29
|
+
// the thumb and the track colours drop their transitions, and only the
|
|
30
|
+
// press stretch and the focus and disabled fades stay. A change after a
|
|
31
|
+
// pointer or keyboard toggle keeps the motion above. An uncontrolled switch
|
|
32
|
+
// only changes by the user, so it always moves.
|
|
33
|
+
const trackTransition =
|
|
34
|
+
"[transition:background-color_var(--transition-duration-fast)_var(--ease-soft),border-color_var(--transition-duration-fast)_var(--ease-soft),box-shadow_var(--transition-duration-fast)_var(--ease-soft),opacity_var(--transition-duration-moderate)_var(--ease-default)] data-checked:[transition:background-color_var(--transition-duration-normal)_var(--ease-out),border-color_var(--transition-duration-normal)_var(--ease-out),box-shadow_var(--transition-duration-fast)_var(--ease-soft),opacity_var(--transition-duration-moderate)_var(--ease-default)]"
|
|
35
|
+
|
|
36
|
+
const thumbTransition =
|
|
37
|
+
"[transition:translate_var(--transition-duration-moderate)_var(--ease-out),scale_var(--transition-duration-fast)_var(--ease-press),background-color_var(--transition-duration-fast)_var(--ease-soft)] data-checked:[transition:translate_var(--transition-duration-normal)_var(--ease-out),scale_var(--transition-duration-fast)_var(--ease-press),background-color_var(--transition-duration-normal)_var(--ease-out)] motion-reduce:[transition:background-color_var(--transition-duration-fast)_var(--ease-soft)] motion-reduce:data-checked:[transition:background-color_var(--transition-duration-normal)_var(--ease-soft)]"
|
|
38
|
+
|
|
39
|
+
const trackInstant =
|
|
40
|
+
"[transition:box-shadow_var(--transition-duration-fast)_var(--ease-soft),opacity_var(--transition-duration-moderate)_var(--ease-default)]"
|
|
41
|
+
|
|
42
|
+
const thumbInstant =
|
|
43
|
+
"[transition:scale_var(--transition-duration-fast)_var(--ease-press)] motion-reduce:[transition:none]"
|
|
44
|
+
|
|
45
|
+
const thumbPress =
|
|
46
|
+
"origin-left data-checked:origin-right motion-safe:group-[:active:not([data-disabled])]/switch:scale-x-[1.15]"
|
|
47
|
+
|
|
11
48
|
function Switch({
|
|
12
49
|
className,
|
|
13
50
|
size = "default",
|
|
51
|
+
checked,
|
|
52
|
+
onCheckedChange,
|
|
14
53
|
...props
|
|
15
54
|
}: SwitchPrimitive.Root.Props & {
|
|
16
55
|
size?: "sm" | "default"
|
|
17
56
|
}) {
|
|
18
57
|
const fieldLabelChecked = useFieldLabelCheckedClass()
|
|
58
|
+
const { animate, markUserToggled } = useUserToggleMotion(checked)
|
|
59
|
+
const handleCheckedChange: SwitchPrimitive.Root.Props["onCheckedChange"] = (
|
|
60
|
+
value,
|
|
61
|
+
details
|
|
62
|
+
) => {
|
|
63
|
+
markUserToggled()
|
|
64
|
+
onCheckedChange?.(value, details)
|
|
65
|
+
}
|
|
19
66
|
return (
|
|
20
67
|
<SwitchPrimitive.Root
|
|
21
68
|
data-slot="switch"
|
|
22
69
|
data-size={size}
|
|
23
70
|
className={(state) => cn(
|
|
24
|
-
"data-checked:bg-primary data-unchecked:bg-control-border focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring aria-invalid:focus-visible:outline-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent
|
|
71
|
+
"data-checked:bg-primary data-unchecked:bg-control-border focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring aria-invalid:focus-visible:outline-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent outline-none after:absolute after:-inset-x-3 after:-inset-y-2 aria-invalid:ring-3 data-disabled:cursor-not-allowed data-disabled:opacity-50 data-[size=default]:h-[18.4px] data-[size=default]:w-[32px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px]",
|
|
72
|
+
animate ? trackTransition : trackInstant,
|
|
25
73
|
fieldLabelChecked(state.checked),
|
|
26
74
|
typeof className === "function" ? className(state) : className
|
|
27
75
|
)}
|
|
28
|
-
{...useFieldControlProps(
|
|
76
|
+
{...useFieldControlProps({
|
|
77
|
+
...props,
|
|
78
|
+
checked,
|
|
79
|
+
onCheckedChange: handleCheckedChange,
|
|
80
|
+
})}
|
|
29
81
|
>
|
|
30
82
|
<SwitchPrimitive.Thumb
|
|
31
83
|
data-slot="switch-thumb"
|
|
32
|
-
className=
|
|
84
|
+
className={cn(
|
|
85
|
+
animate ? thumbTransition : thumbInstant,
|
|
86
|
+
thumbPress,
|
|
87
|
+
"bg-background dark:data-unchecked:bg-foreground dark:data-checked:bg-primary-foreground pointer-events-none block rounded-full ring-0 group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0"
|
|
88
|
+
)}
|
|
33
89
|
/>
|
|
34
90
|
</SwitchPrimitive.Root>
|
|
35
91
|
)
|
|
@@ -4,32 +4,153 @@ import * as React from "react"
|
|
|
4
4
|
|
|
5
5
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
6
6
|
|
|
7
|
+
// How far the table runs past each edge of its scroll container, in px.
|
|
8
|
+
// Start and end follow the reading direction. Right to left, browsers report
|
|
9
|
+
// `scrollLeft` from 0 at the start down to a negative number at the end, so
|
|
10
|
+
// the distance from the start is its absolute value.
|
|
11
|
+
function overflowAtEdges(container: HTMLElement) {
|
|
12
|
+
const overflow = Math.max(container.scrollWidth - container.clientWidth, 0)
|
|
13
|
+
const start = Math.min(Math.abs(container.scrollLeft), overflow)
|
|
14
|
+
return { start, end: overflow - start }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// The scroll cue: when the table is wider than its container, each edge with
|
|
18
|
+
// hidden content past it fades out, so the column cut at the edge reads as
|
|
19
|
+
// cut, not as the last column. The fade is a mask on the container, so it
|
|
20
|
+
// needs no background colour and works on any surface (page, card). Each fade
|
|
21
|
+
// is as wide as the content hidden past its edge, up to 32px, so it shrinks
|
|
22
|
+
// with the scroll and is gone when that edge is reached; it follows the
|
|
23
|
+
// scroll and has no transition of its own. `data-overflow-start` and
|
|
24
|
+
// `data-overflow-end` mark the edges that fade. A table that fits has no mask.
|
|
25
|
+
// The focus ring is drawn inside the container, where the mask would fade it,
|
|
26
|
+
// so while it shows, a 2px frame under it stays opaque.
|
|
27
|
+
const scrollCue = [
|
|
28
|
+
"[--table-fade-start:min(var(--table-overflow-start,0px),calc(var(--spacing)*8))] [--table-fade-end:min(var(--table-overflow-end,0px),calc(var(--spacing)*8))]",
|
|
29
|
+
"[--table-fade:linear-gradient(to_right,transparent,black_var(--table-fade-start),black_calc(100%_-_var(--table-fade-end)),transparent)]",
|
|
30
|
+
"rtl:[--table-fade:linear-gradient(to_left,transparent,black_var(--table-fade-start),black_calc(100%_-_var(--table-fade-end)),transparent)]",
|
|
31
|
+
"data-overflow-start:[mask-image:var(--table-fade)] data-overflow-end:[mask-image:var(--table-fade)]",
|
|
32
|
+
"focus-visible:[mask-image:var(--table-fade),var(--table-ring-strip),var(--table-ring-strip),var(--table-ring-strip),var(--table-ring-strip)]! [--table-ring-strip:linear-gradient(black,black)]",
|
|
33
|
+
"focus-visible:[mask-position:0_0,left,right,top,bottom] focus-visible:[mask-size:100%_100%,2px_100%,2px_100%,100%_2px,100%_2px] focus-visible:[mask-repeat:no-repeat]",
|
|
34
|
+
].join(" ")
|
|
35
|
+
|
|
36
|
+
// Pinning (`pinFirstColumn`): the first cell of every row (header, body,
|
|
37
|
+
// footer) stays at the inline-start edge while the other columns scroll under
|
|
38
|
+
// it. A cell marked `data-pinned` is pinned with it, at the same inline-start
|
|
39
|
+
// 0: the DataTable marks its leading column, whose content starts in the
|
|
40
|
+
// zero-width select cell's gutter, so the checkbox and the name stay together.
|
|
41
|
+
// The pinned cells stack above the other cells and above their raised
|
|
42
|
+
// controls (`z-10`, the stretched-link convention): the first cell at 12, a
|
|
43
|
+
// `data-pinned` cell at 11, so the first cell (the select checkbox) stays on
|
|
44
|
+
// top. The container is isolated, so this order stays inside the table;
|
|
45
|
+
// popovers and menus render in a portal and stay above. The other cells are
|
|
46
|
+
// not isolated: a row-wide link layer in them (DataTableRowLink's overlay)
|
|
47
|
+
// must stay under the controls of every cell.
|
|
48
|
+
// A pinned cell must be opaque. It paints `--table-surface` (default: the card
|
|
49
|
+
// surface; set it on an ancestor when the table sits on another surface) and
|
|
50
|
+
// layers the row's state fill over it (`--table-row-fill`, set by TableRow on
|
|
51
|
+
// hover and selection and by TableFooter), so hover and selection still show.
|
|
52
|
+
// While content is scrolled under it (`data-overflow-start`), the pinned cell
|
|
53
|
+
// shows a 1px edge in the input colour on its inline-end side, the sideways
|
|
54
|
+
// twin of `shadow-scrolled` on a sticky header. It is an inset shadow: a
|
|
55
|
+
// table cell with collapsed borders does not paint an outer one. The edge fades in and out
|
|
56
|
+
// (`fast`) and switches at once under reduced motion. The start fade is off
|
|
57
|
+
// when pinned: it would fade the pinned cell, and the edge replaces it. The
|
|
58
|
+
// end fade stays. The pinned cell stacks above the container's focus ring,
|
|
59
|
+
// so while the container has keyboard focus the pinned cells draw their part
|
|
60
|
+
// of the ring (inline-start side, and top and bottom on the first and last row).
|
|
61
|
+
// The selected-row bar of a row sits on the row's start edge, which scrolls
|
|
62
|
+
// away. While pinned, the first cell draws the bar instead (pinnedBar below,
|
|
63
|
+
// the same recipe as selectedBar on the cell's own pseudo-elements) and the
|
|
64
|
+
// row's bar is hidden.
|
|
65
|
+
// Tailwind reads class names from this source as written, so each one is
|
|
66
|
+
// spelled out in full.
|
|
67
|
+
const pinnedColumn = [
|
|
68
|
+
"[&[data-pin-first-column]]:isolate",
|
|
69
|
+
"[&[data-pin-first-column]_tr>:is(:first-child,[data-pinned])]:sticky [&[data-pin-first-column]_tr>:is(:first-child,[data-pinned])]:start-0 [&[data-pin-first-column]_tr>:is(:first-child,[data-pinned])]:z-12 [&[data-pin-first-column]_tr>:is(:first-child,[data-pinned])]:[background-color:var(--table-surface,var(--card))] [&[data-pin-first-column]_tr>:is(:first-child,[data-pinned])]:[background-image:linear-gradient(var(--table-row-fill,transparent),var(--table-row-fill,transparent))]",
|
|
70
|
+
"[&[data-pin-first-column]_tr>[data-pinned]:not(:first-child)]:z-11",
|
|
71
|
+
"[&[data-pin-first-column]_tr]:before:hidden [&[data-pin-first-column]_tr]:after:hidden",
|
|
72
|
+
"[&[data-pin-first-column]_tr>:is(:first-child,[data-pinned])]:[box-shadow:var(--table-pin-edge),var(--table-pin-ring-x,inset_0_0_0_transparent),var(--table-pin-ring-top,inset_0_0_0_transparent),var(--table-pin-ring-bottom,inset_0_0_0_transparent)] [--table-pin-edge:inset_0_0_0_transparent] data-overflow-start:[--table-pin-edge:inset_-1px_0_0_var(--input)] rtl:data-overflow-start:[--table-pin-edge:inset_1px_0_0_var(--input)]",
|
|
73
|
+
"motion-safe:[&[data-pin-first-column]_tr>:is(:first-child,[data-pinned])]:[transition:box-shadow_var(--transition-duration-fast)_var(--ease-soft)]",
|
|
74
|
+
"[&[data-pin-first-column]]:[--table-fade-start:0px]",
|
|
75
|
+
"[&[data-pin-first-column]:focus-visible]:[--table-pin-ring-x:inset_2px_0_0_var(--ring)] rtl:[&[data-pin-first-column]:focus-visible]:[--table-pin-ring-x:inset_-2px_0_0_var(--ring)]",
|
|
76
|
+
"[&[data-pin-first-column]:focus-visible_table>:is(thead,tbody,tfoot):not(:is(thead,tbody,tfoot)~*)>tr:first-child]:[--table-pin-ring-top:inset_0_2px_0_var(--ring)]",
|
|
77
|
+
"[&[data-pin-first-column]:focus-visible_table>:is(thead,tbody,tfoot):not(:has(~:is(thead,tbody,tfoot)))>tr:last-child]:[--table-pin-ring-bottom:inset_0_-2px_0_var(--ring)]",
|
|
78
|
+
].join(" ")
|
|
79
|
+
|
|
80
|
+
// The selected-row bar on the first pinned cell: selectedBar's recipe, with
|
|
81
|
+
// each row state read from the cell's row.
|
|
82
|
+
const pinnedBar = [
|
|
83
|
+
"[&[data-pin-first-column]_tr>:first-child]:before:pointer-events-none [&[data-pin-first-column]_tr>:first-child]:before:absolute [&[data-pin-first-column]_tr>:first-child]:before:inset-y-0 [&[data-pin-first-column]_tr>:first-child]:before:start-0 [&[data-pin-first-column]_tr>:first-child]:before:w-0.5 [&[data-pin-first-column]_tr>:first-child]:before:bg-brand-indicator",
|
|
84
|
+
"[&[data-pin-first-column]_tr>:first-child]:after:pointer-events-none [&[data-pin-first-column]_tr>:first-child]:after:absolute [&[data-pin-first-column]_tr>:first-child]:after:inset-y-0 [&[data-pin-first-column]_tr>:first-child]:after:start-0 [&[data-pin-first-column]_tr>:first-child]:after:w-0.5 [&[data-pin-first-column]_tr>:first-child]:after:bg-brand-indicator",
|
|
85
|
+
"[&[data-pin-first-column]_tr>:first-child]:before:[clip-path:inset(50%_0_50%_0)] [&[data-pin-first-column]_tr>:first-child]:after:[clip-path:inset(50%_0_50%_0)]",
|
|
86
|
+
"[&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:before:[clip-path:inset(0_0_100%_0)] [&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:after:[clip-path:inset(0_0_100%_0)]",
|
|
87
|
+
"[&[data-pin-first-column]_tr[data-next-selected]>:first-child]:before:[clip-path:inset(100%_0_0_0)] [&[data-pin-first-column]_tr[data-next-selected]>:first-child]:after:[clip-path:inset(100%_0_0_0)]",
|
|
88
|
+
"[&[data-pin-first-column]_[data-state=selected]+tr[data-next-selected]>:first-child]:before:[clip-path:inset(0_0_100%_0)] [&[data-pin-first-column]_[data-state=selected]+tr[data-next-selected]>:first-child]:after:[clip-path:inset(100%_0_0_0)]",
|
|
89
|
+
"[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:before:[clip-path:inset(0_0_calc(50%_-_0.5px)_0)]! [&[data-pin-first-column]_tr[data-state=selected]>:first-child]:after:[clip-path:inset(calc(50%_-_0.5px)_0_0_0)]!",
|
|
90
|
+
"[&[data-pin-first-column]_tr>:first-child]:before:origin-left [&[data-pin-first-column]_tr>:first-child]:after:origin-left rtl:[&[data-pin-first-column]_tr>:first-child]:before:origin-right rtl:[&[data-pin-first-column]_tr>:first-child]:after:origin-right",
|
|
91
|
+
"motion-safe:[&[data-pin-first-column]_tr>:first-child]:before:opacity-0 motion-safe:[&[data-pin-first-column]_tr>:first-child]:after:opacity-0 motion-safe:[&[data-pin-first-column]_tr>:first-child]:before:[scale:0.5_1] motion-safe:[&[data-pin-first-column]_tr>:first-child]:after:[scale:0.5_1]",
|
|
92
|
+
"motion-safe:[&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:before:opacity-100 motion-safe:[&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:after:opacity-100 motion-safe:[&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:before:[scale:none] motion-safe:[&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:after:[scale:none]",
|
|
93
|
+
"motion-safe:[&[data-pin-first-column]_tr[data-next-selected]>:first-child]:before:opacity-100 motion-safe:[&[data-pin-first-column]_tr[data-next-selected]>:first-child]:after:opacity-100 motion-safe:[&[data-pin-first-column]_tr[data-next-selected]>:first-child]:before:[scale:none] motion-safe:[&[data-pin-first-column]_tr[data-next-selected]>:first-child]:after:[scale:none]",
|
|
94
|
+
"motion-safe:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:before:opacity-100 motion-safe:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:after:opacity-100 motion-safe:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:before:[scale:none] motion-safe:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:after:[scale:none]",
|
|
95
|
+
"[&[data-pin-first-column]_tr>:first-child]:before:[--bar-clip-duration:0s] [&[data-pin-first-column]_tr>:first-child]:after:[--bar-clip-duration:0s] [&[data-pin-first-column]_tr>:first-child]:before:[--bar-clip-delay:var(--transition-duration-fast)] [&[data-pin-first-column]_tr>:first-child]:after:[--bar-clip-delay:var(--transition-duration-fast)]",
|
|
96
|
+
"[&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:before:[--bar-clip-duration:var(--transition-duration-moderate)] [&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:after:[--bar-clip-duration:var(--transition-duration-moderate)] [&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:before:[--bar-clip-delay:0s] [&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:after:[--bar-clip-delay:0s] [&[data-pin-first-column]_tr[data-next-selected]>:first-child]:before:[--bar-clip-duration:var(--transition-duration-moderate)] [&[data-pin-first-column]_tr[data-next-selected]>:first-child]:after:[--bar-clip-duration:var(--transition-duration-moderate)] [&[data-pin-first-column]_tr[data-next-selected]>:first-child]:before:[--bar-clip-delay:0s] [&[data-pin-first-column]_tr[data-next-selected]>:first-child]:after:[--bar-clip-delay:0s]",
|
|
97
|
+
"[&[data-pin-first-column]_tr>:first-child]:before:[transition:clip-path_var(--bar-clip-duration)_var(--ease-out)_var(--bar-clip-delay),opacity_var(--transition-duration-fast)_var(--ease-soft),scale_var(--transition-duration-fast)_var(--ease-soft)] [&[data-pin-first-column]_tr>:first-child]:after:[transition:clip-path_var(--bar-clip-duration)_var(--ease-out)_var(--bar-clip-delay),opacity_var(--transition-duration-fast)_var(--ease-soft),scale_var(--transition-duration-fast)_var(--ease-soft)]",
|
|
98
|
+
"motion-safe:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:before:[transition:clip-path_var(--transition-duration-moderate)_var(--ease-out),opacity_var(--transition-duration-moderate)_var(--ease-soft),scale_var(--transition-duration-moderate)_var(--ease-out)] motion-safe:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:after:[transition:clip-path_var(--transition-duration-moderate)_var(--ease-out),opacity_var(--transition-duration-moderate)_var(--ease-soft),scale_var(--transition-duration-moderate)_var(--ease-out)]",
|
|
99
|
+
"motion-reduce:[&[data-pin-first-column]_tr>:first-child]:before:opacity-0 motion-reduce:[&[data-pin-first-column]_tr>:first-child]:after:opacity-0 motion-reduce:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:before:opacity-100 motion-reduce:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:after:opacity-100",
|
|
100
|
+
"motion-reduce:[&[data-pin-first-column]_tr>:first-child]:before:[transition:opacity_var(--transition-duration-fast)_var(--ease-soft),clip-path_0s_linear_var(--transition-duration-fast)] motion-reduce:[&[data-pin-first-column]_tr>:first-child]:after:[transition:opacity_var(--transition-duration-fast)_var(--ease-soft),clip-path_0s_linear_var(--transition-duration-fast)]",
|
|
101
|
+
"motion-reduce:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:before:[transition:opacity_var(--transition-duration-moderate)_var(--ease-soft)] motion-reduce:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:after:[transition:opacity_var(--transition-duration-moderate)_var(--ease-soft)]",
|
|
102
|
+
].join(" ")
|
|
103
|
+
|
|
7
104
|
// When the table is wider than its container, the container scrolls and must
|
|
8
105
|
// be reachable by keyboard (axe scrollable-region-focusable), so it becomes a
|
|
9
106
|
// tab stop with a focus ring. A table that fits adds no tab stop.
|
|
10
|
-
function Table({
|
|
107
|
+
function Table({
|
|
108
|
+
className,
|
|
109
|
+
pinFirstColumn = false,
|
|
110
|
+
...props
|
|
111
|
+
}: React.ComponentProps<"table"> & {
|
|
112
|
+
/** Keeps the first column in place while the others scroll sideways. */
|
|
113
|
+
pinFirstColumn?: boolean
|
|
114
|
+
}) {
|
|
11
115
|
const containerRef = React.useRef<HTMLDivElement>(null)
|
|
12
116
|
const [scrollable, setScrollable] = React.useState(false)
|
|
13
117
|
|
|
14
|
-
// Measure before the first paint, so an overflowing table is a tab stop
|
|
15
|
-
// from the start; the observer then tracks later size
|
|
118
|
+
// Measure before the first paint, so an overflowing table is a tab stop and
|
|
119
|
+
// shows its cue from the start; the observer then tracks later size
|
|
120
|
+
// changes, and the scroll listener moves the cue. The cue is written to the
|
|
121
|
+
// container directly, not through state, so a scroll does not re-render.
|
|
16
122
|
React.useLayoutEffect(() => {
|
|
17
123
|
const container = containerRef.current
|
|
18
124
|
if (!container) {
|
|
19
125
|
return
|
|
20
126
|
}
|
|
21
|
-
const
|
|
127
|
+
const updateCue = () => {
|
|
128
|
+
const { start, end } = overflowAtEdges(container)
|
|
129
|
+
// `scrollWidth` and `clientWidth` are rounded, so at the end of the
|
|
130
|
+
// scroll up to 1px can still seem hidden. That is not worth a cue.
|
|
131
|
+
container.toggleAttribute("data-overflow-start", start > 1)
|
|
132
|
+
container.toggleAttribute("data-overflow-end", end > 1)
|
|
133
|
+
container.style.setProperty("--table-overflow-start", `${start}px`)
|
|
134
|
+
container.style.setProperty("--table-overflow-end", `${end}px`)
|
|
135
|
+
}
|
|
136
|
+
const update = () => {
|
|
22
137
|
setScrollable(container.scrollWidth > container.clientWidth)
|
|
138
|
+
updateCue()
|
|
139
|
+
}
|
|
23
140
|
update()
|
|
141
|
+
container.addEventListener("scroll", updateCue, { passive: true })
|
|
24
142
|
if (typeof ResizeObserver === "undefined") {
|
|
25
|
-
return
|
|
143
|
+
return () => container.removeEventListener("scroll", updateCue)
|
|
26
144
|
}
|
|
27
145
|
const observer = new ResizeObserver(update)
|
|
28
146
|
observer.observe(container)
|
|
29
147
|
if (container.firstElementChild) {
|
|
30
148
|
observer.observe(container.firstElementChild)
|
|
31
149
|
}
|
|
32
|
-
return () =>
|
|
150
|
+
return () => {
|
|
151
|
+
observer.disconnect()
|
|
152
|
+
container.removeEventListener("scroll", updateCue)
|
|
153
|
+
}
|
|
33
154
|
}, [])
|
|
34
155
|
|
|
35
156
|
return (
|
|
@@ -37,7 +158,8 @@ function Table({ className, ...props }: React.ComponentProps<"table">) {
|
|
|
37
158
|
ref={containerRef}
|
|
38
159
|
data-slot="table-container"
|
|
39
160
|
tabIndex={scrollable ? 0 : undefined}
|
|
40
|
-
|
|
161
|
+
data-pin-first-column={pinFirstColumn ? "" : undefined}
|
|
162
|
+
className={`focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring relative w-full overflow-x-auto rounded-[inherit] outline-none ${scrollCue} ${pinnedColumn} ${pinnedBar}`}
|
|
41
163
|
>
|
|
42
164
|
<table
|
|
43
165
|
data-slot="table"
|
|
@@ -141,7 +263,7 @@ function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
|
|
|
141
263
|
<tfoot
|
|
142
264
|
data-slot="table-footer"
|
|
143
265
|
className={cn(
|
|
144
|
-
"bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",
|
|
266
|
+
"bg-muted/50 border-t font-medium [&>tr]:last:border-b-0 [--table-row-fill:color-mix(in_oklab,var(--muted)_50%,transparent)]",
|
|
145
267
|
className
|
|
146
268
|
)}
|
|
147
269
|
{...props}
|
|
@@ -189,7 +311,8 @@ function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
|
|
|
189
311
|
// table then drops frames. At rest
|
|
190
312
|
// the bar is the same as without the motion: opacity 1, no scale. Under
|
|
191
313
|
// reduced motion the bar is whole and only fades: the clip jumps on select and
|
|
192
|
-
// waits for the fade on deselect.
|
|
314
|
+
// waits for the fade on deselect. With `pinFirstColumn` the first cell draws
|
|
315
|
+
// the bar instead (pinnedBar), so it stays on the pinned edge.
|
|
193
316
|
const selectedBar = [
|
|
194
317
|
"before:pointer-events-none before:absolute before:inset-y-0 before:start-0 before:w-0.5 before:bg-brand-indicator",
|
|
195
318
|
"after:pointer-events-none after:absolute after:inset-y-0 after:start-0 after:w-0.5 after:bg-brand-indicator",
|
|
@@ -217,7 +340,7 @@ function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
|
|
|
217
340
|
<tr
|
|
218
341
|
data-slot="table-row"
|
|
219
342
|
className={cn(
|
|
220
|
-
"hover:bg-muted/50 data-[state=selected]:bg-muted relative border-b border-border/50 transition-colors",
|
|
343
|
+
"hover:bg-muted/50 data-[state=selected]:bg-muted relative border-b border-border/50 transition-colors hover:[--table-row-fill:color-mix(in_oklab,var(--muted)_50%,transparent)] data-[state=selected]:[--table-row-fill:var(--muted)]",
|
|
221
344
|
selectedBar,
|
|
222
345
|
className
|
|
223
346
|
)}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { mergeProps } from "@base-ui/react/merge-props"
|
|
2
|
+
import { useRender } from "@base-ui/react/use-render"
|
|
3
|
+
import { cva } from "class-variance-authority"
|
|
4
|
+
import { ArrowUpRight } from "lucide-react"
|
|
5
|
+
|
|
6
|
+
import { cn } from "@vendure-io/ui/lib/utils"
|
|
7
|
+
|
|
8
|
+
// A link for running text and for small standalone links. It is `inline`,
|
|
9
|
+
// not `inline-flex`, so a long label wraps with the sentence, and it sets no
|
|
10
|
+
// font size, weight or line height: it takes them from the text around it.
|
|
11
|
+
// `w-fit` keeps it to its label when it is a flex or grid item, where it
|
|
12
|
+
// would otherwise stretch, and has no effect inline.
|
|
13
|
+
//
|
|
14
|
+
// The underline sits 4px under the baseline (`underline-offset-4`, as the
|
|
15
|
+
// Button link look) and is 1px.
|
|
16
|
+
//
|
|
17
|
+
// The focus ring is the design-system ring, 2px solid `ring`, but at offset 0
|
|
18
|
+
// instead of 2px: the space between two words is about 4px, so an outset ring
|
|
19
|
+
// would touch the next word, and the ring of one line would touch the next
|
|
20
|
+
// line. While the ring shows, the underline is hidden: at offset 0 it would
|
|
21
|
+
// run into the ring's lower edge, and the ring already marks the link.
|
|
22
|
+
// `box-decoration-clone` closes the ring on each line of a wrapped link.
|
|
23
|
+
//
|
|
24
|
+
// `default`: `primary` text, always underlined in `brand-indicator`. The text
|
|
25
|
+
// colour alone is too close to body text to mark a link inside a sentence,
|
|
26
|
+
// so the underline is the cue. On hover the text and the underline turn
|
|
27
|
+
// `brand-text`; on keyboard focus the text turns `brand-text`.
|
|
28
|
+
// `quiet`: `muted-foreground` text with no underline at rest, for a small
|
|
29
|
+
// standalone link that must not compete with the actions next to it
|
|
30
|
+
// ("Forgot password?", "Terms"). On hover the text reaches `foreground` and
|
|
31
|
+
// the underline appears in the text colour; on keyboard focus the text
|
|
32
|
+
// reaches `foreground`. Without an
|
|
33
|
+
// underline at rest it is not marked as a link inside a sentence: use
|
|
34
|
+
// `default` there.
|
|
35
|
+
//
|
|
36
|
+
// Colour and underline colour ease in `quick` on `soft`. Nothing moves, so
|
|
37
|
+
// reduced motion needs no other look.
|
|
38
|
+
//
|
|
39
|
+
// `external`: opens in a new tab with `rel="noopener noreferrer"`, ends with a
|
|
40
|
+
// decorative up-right arrow sized to the text (60%, full on hover or focus),
|
|
41
|
+
// and adds "(opens in a new tab)" for screen readers. A word joiner keeps the
|
|
42
|
+
// arrow on the line of the last word; it is hidden with the arrow, so it
|
|
43
|
+
// stays out of the accessible name. In right-to-left the arrow points
|
|
44
|
+
// up-left.
|
|
45
|
+
|
|
46
|
+
const textLinkVariants = cva(
|
|
47
|
+
"group/text-link inline w-fit cursor-pointer rounded-sm underline decoration-1 underline-offset-4 box-decoration-clone transition-colors duration-quick ease-soft outline-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-0 focus-visible:outline-ring focus-visible:decoration-transparent",
|
|
48
|
+
{
|
|
49
|
+
variants: {
|
|
50
|
+
tone: {
|
|
51
|
+
default:
|
|
52
|
+
"text-primary decoration-brand-indicator hover:text-brand-text hover:decoration-brand-text focus-visible:text-brand-text",
|
|
53
|
+
quiet:
|
|
54
|
+
"text-muted-foreground decoration-transparent hover:text-foreground hover:decoration-current focus-visible:text-foreground",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
defaultVariants: {
|
|
58
|
+
tone: "default",
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
type TextLinkProps = useRender.ComponentProps<"a"> & {
|
|
64
|
+
/**
|
|
65
|
+
* - `'default'`: link colour, always underlined. Use it inside a sentence.
|
|
66
|
+
* - `'quiet'`: muted text, underlined on hover. Use it for a small
|
|
67
|
+
* standalone link next to more important actions.
|
|
68
|
+
*/
|
|
69
|
+
tone?: "default" | "quiet"
|
|
70
|
+
/**
|
|
71
|
+
* Opens another site in a new tab: sets `target="_blank"` and
|
|
72
|
+
* `rel="noopener noreferrer"` (your own `target` and `rel` win) and adds a
|
|
73
|
+
* trailing arrow and a screen-reader note.
|
|
74
|
+
*/
|
|
75
|
+
external?: boolean
|
|
76
|
+
/** The screen-reader note of an `external` link. */
|
|
77
|
+
externalLabel?: string
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A link inside running text, or a small standalone link. Renders an `<a>`;
|
|
82
|
+
* pass `render` to use a router link. It always keeps the link role.
|
|
83
|
+
*/
|
|
84
|
+
function TextLink({
|
|
85
|
+
tone = "default",
|
|
86
|
+
external = false,
|
|
87
|
+
externalLabel = "(opens in a new tab)",
|
|
88
|
+
className,
|
|
89
|
+
render,
|
|
90
|
+
children,
|
|
91
|
+
...props
|
|
92
|
+
}: TextLinkProps) {
|
|
93
|
+
return useRender({
|
|
94
|
+
defaultTagName: "a",
|
|
95
|
+
render,
|
|
96
|
+
props: mergeProps<"a">(
|
|
97
|
+
{
|
|
98
|
+
className: cn(textLinkVariants({ tone }), className),
|
|
99
|
+
...(external ? { target: "_blank", rel: "noopener noreferrer" } : {}),
|
|
100
|
+
children: external ? (
|
|
101
|
+
<>
|
|
102
|
+
{children}
|
|
103
|
+
<span className="sr-only"> {externalLabel}</span>
|
|
104
|
+
<span aria-hidden="true">
|
|
105
|
+
{""}
|
|
106
|
+
<ArrowUpRight
|
|
107
|
+
aria-hidden="true"
|
|
108
|
+
data-slot="text-link-external-icon"
|
|
109
|
+
strokeWidth={1.75}
|
|
110
|
+
className="ms-0.5 inline-block size-[0.875em] align-[-0.0625em] opacity-60 transition-opacity duration-moderate ease-soft group-hover/text-link:opacity-100 group-focus-visible/text-link:opacity-100 rtl:-scale-x-100"
|
|
111
|
+
/>
|
|
112
|
+
</span>
|
|
113
|
+
</>
|
|
114
|
+
) : (
|
|
115
|
+
children
|
|
116
|
+
),
|
|
117
|
+
},
|
|
118
|
+
props
|
|
119
|
+
),
|
|
120
|
+
state: { slot: "text-link", tone },
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export { TextLink }
|
|
125
|
+
export type { TextLinkProps }
|
|
@@ -116,7 +116,21 @@ function AppShellMain({
|
|
|
116
116
|
// it on the element that wraps the page and changes its `key` with the route.
|
|
117
117
|
const pageEnterClassName = 'animate-page-enter motion-reduce:animate-page-fade';
|
|
118
118
|
|
|
119
|
-
//
|
|
119
|
+
// The page frame: one frame for every app on AppShell. The page is centred in
|
|
120
|
+
// AppShellMain, its content is at most 1180px wide, and a gutter of 32px (16px
|
|
121
|
+
// below 768px) sits on every side, the top and bottom included. The gutter is
|
|
122
|
+
// outside the 1180px, so the frame is at most 1180px plus two gutters wide.
|
|
123
|
+
//
|
|
124
|
+
// The values are CSS variables on the frame, `--app-shell-page-width` and
|
|
125
|
+
// `--app-shell-page-gutter`, so a descendant can read them (a full-bleed band
|
|
126
|
+
// pulls out by the gutter). The app sets no page padding or width of its own.
|
|
127
|
+
// A page that wants a narrower column, such as a settings form at `max-w-4xl`,
|
|
128
|
+
// puts it inside the frame; it stays left-aligned there.
|
|
129
|
+
const pageFrameClassName =
|
|
130
|
+
'[--app-shell-page-width:1180px] [--app-shell-page-gutter:--spacing(4)] md:[--app-shell-page-gutter:--spacing(8)] mx-auto w-full min-w-0 max-w-[calc(var(--app-shell-page-width)+2*var(--app-shell-page-gutter))] p-(--app-shell-page-gutter)';
|
|
131
|
+
|
|
132
|
+
// AppShellPage wraps the page inside AppShellMain. It is the page frame (see
|
|
133
|
+
// pageFrameClassName), and it is the page enter: when it mounts, the page
|
|
120
134
|
// fades in (220ms) and rises 6px into place (260ms) on the `out` curve; with
|
|
121
135
|
// reduced motion it only fades. The header and the sidebar stay still.
|
|
122
136
|
//
|
|
@@ -125,9 +139,16 @@ const pageEnterClassName = 'animate-page-enter motion-reduce:animate-page-fade';
|
|
|
125
139
|
// it a `key` that changes with the route (the pathname) so a new page mounts a
|
|
126
140
|
// new element. Only opacity and transform move: no layout shift, and the page
|
|
127
141
|
// takes clicks while it settles.
|
|
142
|
+
//
|
|
143
|
+
// A layout that keeps its own wrapper takes the frame from pageFrameClassName
|
|
144
|
+
// and, if it wants the motion, the enter from pageEnterClassName.
|
|
128
145
|
function AppShellPage({ className, ...props }: React.ComponentProps<'div'>) {
|
|
129
146
|
return (
|
|
130
|
-
<div
|
|
147
|
+
<div
|
|
148
|
+
data-slot="app-shell-page"
|
|
149
|
+
className={cn(pageFrameClassName, pageEnterClassName, className)}
|
|
150
|
+
{...props}
|
|
151
|
+
/>
|
|
131
152
|
);
|
|
132
153
|
}
|
|
133
154
|
|
|
@@ -139,5 +160,6 @@ export {
|
|
|
139
160
|
AppShellMain,
|
|
140
161
|
AppShellPage,
|
|
141
162
|
pageEnterClassName,
|
|
163
|
+
pageFrameClassName,
|
|
142
164
|
type AppShellMainProps,
|
|
143
165
|
};
|