@vendure-io/ui 2.2.0 → 3.0.0-next.0
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/package.json +19 -5
- package/src/components/atoms/accordion.tsx +21 -6
- package/src/components/atoms/alert-dialog.tsx +31 -6
- package/src/components/atoms/alert.tsx +59 -12
- package/src/components/atoms/avatar.tsx +1 -1
- package/src/components/atoms/badge.tsx +7 -2
- package/src/components/atoms/breadcrumb.tsx +137 -4
- package/src/components/atoms/button-group.tsx +30 -6
- package/src/components/atoms/button.tsx +128 -18
- package/src/components/atoms/calendar.tsx +6 -6
- package/src/components/atoms/card.tsx +130 -16
- package/src/components/atoms/carousel.tsx +16 -9
- package/src/components/atoms/chart.tsx +87 -1
- package/src/components/atoms/checkbox.tsx +85 -7
- package/src/components/atoms/collapsible.tsx +2 -1
- package/src/components/atoms/combobox.tsx +147 -21
- package/src/components/atoms/command.tsx +414 -12
- package/src/components/atoms/context-menu.tsx +28 -23
- package/src/components/atoms/dialog.tsx +151 -29
- package/src/components/atoms/direction.tsx +23 -2
- package/src/components/atoms/drawer.tsx +15 -10
- package/src/components/atoms/dropdown-menu.tsx +43 -28
- package/src/components/atoms/empty.tsx +4 -0
- package/src/components/atoms/field.tsx +41 -15
- package/src/components/atoms/hover-card.tsx +61 -8
- package/src/components/atoms/input-group.tsx +17 -9
- package/src/components/atoms/input-otp.tsx +6 -6
- package/src/components/atoms/input.tsx +7 -1
- package/src/components/atoms/item.tsx +3 -3
- package/src/components/atoms/kbd.tsx +32 -3
- package/src/components/atoms/label-swap.tsx +82 -0
- package/src/components/atoms/label.tsx +1 -1
- package/src/components/atoms/menubar.tsx +28 -26
- package/src/components/atoms/native-select.tsx +3 -2
- package/src/components/atoms/navigation-menu.tsx +13 -8
- package/src/components/atoms/pagination.tsx +2 -2
- package/src/components/atoms/popover.tsx +23 -5
- package/src/components/atoms/progress.tsx +46 -33
- package/src/components/atoms/radio-group.tsx +9 -4
- package/src/components/atoms/resizable.tsx +1 -1
- package/src/components/atoms/scroll-area.tsx +2 -2
- package/src/components/atoms/select.tsx +258 -19
- package/src/components/atoms/sheet.tsx +59 -23
- package/src/components/atoms/sidebar.tsx +333 -23
- package/src/components/atoms/skeleton.tsx +1 -1
- package/src/components/atoms/slider.tsx +1 -1
- package/src/components/atoms/sonner.tsx +128 -38
- package/src/components/atoms/spinner.tsx +1 -1
- package/src/components/atoms/switch.tsx +10 -5
- package/src/components/atoms/table.tsx +147 -7
- package/src/components/atoms/tabs.tsx +3 -3
- package/src/components/atoms/textarea.tsx +3 -1
- package/src/components/atoms/toggle-group.tsx +4 -2
- package/src/components/atoms/toggle.tsx +28 -6
- package/src/components/atoms/tooltip.tsx +85 -15
- package/src/components/molecules/anonymized-token.tsx +24 -8
- package/src/components/molecules/app-shell.tsx +53 -20
- package/src/components/molecules/arrow-link.tsx +40 -0
- package/src/components/molecules/chip.tsx +2 -2
- package/src/components/molecules/code-block.tsx +54 -31
- package/src/components/molecules/collapsible-section.tsx +129 -0
- package/src/components/molecules/confirm-dialog.tsx +113 -9
- package/src/components/molecules/copyable-text.tsx +75 -11
- package/src/components/molecules/data-table/data-table-bulk-actions.tsx +32 -4
- package/src/components/molecules/data-table/data-table-column-header.tsx +20 -3
- package/src/components/molecules/data-table/data-table-filters.tsx +1 -1
- package/src/components/molecules/data-table/data-table-helpers.tsx +68 -1
- package/src/components/molecules/data-table/data-table-selection-storage.tsx +115 -0
- package/src/components/molecules/data-table/data-table-types.tsx +121 -4
- package/src/components/molecules/data-table/data-table-view-options.tsx +2 -2
- package/src/components/molecules/data-table/data-table.tsx +837 -80
- package/src/components/molecules/data-table/table-pagination.tsx +2 -2
- package/src/components/molecules/date-picker.tsx +13 -7
- package/src/components/molecules/date-range-picker.tsx +13 -6
- package/src/components/molecules/date-time-picker.tsx +13 -7
- package/src/components/molecules/date-time.tsx +8 -1
- package/src/components/molecules/direction-link.tsx +130 -0
- package/src/components/molecules/elapsed-time.tsx +223 -0
- package/src/components/molecules/file-dropzone.tsx +2 -2
- package/src/components/molecules/id-chip.tsx +169 -32
- package/src/components/molecules/inline-code.tsx +4 -0
- package/src/components/molecules/issued-secret.tsx +318 -0
- package/src/components/molecules/list-row.tsx +349 -0
- package/src/components/molecules/live-indicator.tsx +83 -0
- package/src/components/molecules/page-header.tsx +117 -5
- package/src/components/molecules/password-input.tsx +2 -2
- package/src/components/molecules/relative-time.tsx +85 -56
- package/src/components/molecules/search-trigger.tsx +127 -0
- package/src/components/molecules/secret-value.tsx +26 -9
- package/src/components/molecules/skip-link.tsx +1 -1
- package/src/components/molecules/stat-card.tsx +4 -4
- package/src/components/molecules/state-views/empty-state.tsx +35 -17
- package/src/components/molecules/state-views/error-state.tsx +32 -14
- package/src/components/molecules/status-badge.tsx +415 -49
- package/src/components/molecules/time-tooltip.tsx +140 -0
- package/src/components/molecules/timeline.tsx +246 -0
- package/src/components/molecules/visibility-icon.tsx +89 -0
- package/src/hooks/use-active-label-size.ts +32 -0
- package/src/hooks/use-pinned-height.ts +55 -0
- package/src/hooks/use-scrolled.ts +27 -0
- package/src/lib/content-inset.ts +17 -0
- package/src/lib/control-name.ts +55 -0
- package/src/lib/dialog-padding.ts +48 -0
- package/src/lib/field-surface.ts +31 -0
- package/src/lib/format-elapsed.ts +67 -0
- package/src/lib/format-relative.ts +29 -1
- package/src/lib/highlight.ts +3 -3
- package/src/lib/menu-item.tsx +72 -0
- package/src/lib/outline-edge.ts +21 -0
- package/src/lib/popup-align.ts +67 -0
- package/src/lib/popup-direction.ts +22 -0
- package/src/lib/popup-motion.ts +19 -0
- package/src/lib/state-dictionary.ts +42 -6
- package/src/lib/syntax-colors.ts +8 -0
- package/src/lib/tint-recipes.ts +68 -0
- package/src/lib/tone-icons.ts +24 -0
- package/src/lib/trigger-slot.ts +16 -0
- package/src/lib/utils.ts +104 -1
|
@@ -7,6 +7,7 @@ import useEmblaCarousel, {
|
|
|
7
7
|
|
|
8
8
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
9
9
|
import { Button } from "@vendure-io/ui/components/atoms/button"
|
|
10
|
+
import { useDirection } from "@vendure-io/ui/components/atoms/direction"
|
|
10
11
|
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
|
|
11
12
|
|
|
12
13
|
type CarouselApi = UseEmblaCarouselType[1]
|
|
@@ -51,8 +52,11 @@ function Carousel({
|
|
|
51
52
|
children,
|
|
52
53
|
...props
|
|
53
54
|
}: React.ComponentProps<"div"> & CarouselProps) {
|
|
55
|
+
// Embla scrolls the other way in right to left, so it needs the direction.
|
|
56
|
+
const direction = useDirection()
|
|
54
57
|
const [carouselRef, api] = useEmblaCarousel(
|
|
55
58
|
{
|
|
59
|
+
direction,
|
|
56
60
|
...opts,
|
|
57
61
|
axis: orientation === "horizontal" ? "x" : "y",
|
|
58
62
|
},
|
|
@@ -77,15 +81,18 @@ function Carousel({
|
|
|
77
81
|
|
|
78
82
|
const handleKeyDown = React.useCallback(
|
|
79
83
|
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
80
|
-
|
|
84
|
+
// The arrow toward the end side goes to the next slide.
|
|
85
|
+
const toEnd = direction === "rtl" && orientation === "horizontal" ? "ArrowLeft" : "ArrowRight"
|
|
86
|
+
const toStart = toEnd === "ArrowLeft" ? "ArrowRight" : "ArrowLeft"
|
|
87
|
+
if (event.key === toStart) {
|
|
81
88
|
event.preventDefault()
|
|
82
89
|
scrollPrev()
|
|
83
|
-
} else if (event.key ===
|
|
90
|
+
} else if (event.key === toEnd) {
|
|
84
91
|
event.preventDefault()
|
|
85
92
|
scrollNext()
|
|
86
93
|
}
|
|
87
94
|
},
|
|
88
|
-
[scrollPrev, scrollNext]
|
|
95
|
+
[scrollPrev, scrollNext, direction, orientation]
|
|
89
96
|
)
|
|
90
97
|
|
|
91
98
|
React.useEffect(() => {
|
|
@@ -144,7 +151,7 @@ function CarouselContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
144
151
|
<div
|
|
145
152
|
className={cn(
|
|
146
153
|
"flex",
|
|
147
|
-
orientation === "horizontal" ? "-
|
|
154
|
+
orientation === "horizontal" ? "-ms-4" : "-mt-4 flex-col",
|
|
148
155
|
className
|
|
149
156
|
)}
|
|
150
157
|
{...props}
|
|
@@ -163,7 +170,7 @@ function CarouselItem({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
163
170
|
data-slot="carousel-item"
|
|
164
171
|
className={cn(
|
|
165
172
|
"min-w-0 shrink-0 grow-0 basis-full",
|
|
166
|
-
orientation === "horizontal" ? "
|
|
173
|
+
orientation === "horizontal" ? "ps-4" : "pt-4",
|
|
167
174
|
className
|
|
168
175
|
)}
|
|
169
176
|
{...props}
|
|
@@ -187,7 +194,7 @@ function CarouselPrevious({
|
|
|
187
194
|
className={cn(
|
|
188
195
|
"absolute touch-manipulation rounded-full",
|
|
189
196
|
orientation === "horizontal"
|
|
190
|
-
? "top-1/2 -
|
|
197
|
+
? "top-1/2 -start-12 -translate-y-1/2"
|
|
191
198
|
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
192
199
|
className
|
|
193
200
|
)}
|
|
@@ -195,7 +202,7 @@ function CarouselPrevious({
|
|
|
195
202
|
onClick={scrollPrev}
|
|
196
203
|
{...props}
|
|
197
204
|
>
|
|
198
|
-
<ChevronLeftIcon />
|
|
205
|
+
<ChevronLeftIcon className={cn(orientation === "horizontal" && "rtl:rotate-180")} />
|
|
199
206
|
<span className="sr-only">Previous slide</span>
|
|
200
207
|
</Button>
|
|
201
208
|
)
|
|
@@ -217,7 +224,7 @@ function CarouselNext({
|
|
|
217
224
|
className={cn(
|
|
218
225
|
"absolute touch-manipulation rounded-full",
|
|
219
226
|
orientation === "horizontal"
|
|
220
|
-
? "top-1/2 -
|
|
227
|
+
? "top-1/2 -end-12 -translate-y-1/2"
|
|
221
228
|
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
222
229
|
className
|
|
223
230
|
)}
|
|
@@ -225,7 +232,7 @@ function CarouselNext({
|
|
|
225
232
|
onClick={scrollNext}
|
|
226
233
|
{...props}
|
|
227
234
|
>
|
|
228
|
-
<ChevronRightIcon />
|
|
235
|
+
<ChevronRightIcon className={cn(orientation === "horizontal" && "rtl:rotate-180")} />
|
|
229
236
|
<span className="sr-only">Next slide</span>
|
|
230
237
|
</Button>
|
|
231
238
|
)
|
|
@@ -34,6 +34,89 @@ function useChart() {
|
|
|
34
34
|
return context
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
// recharts marks some shapes as images (`role="img"`): the slices of a pie and
|
|
38
|
+
// a radial bar, scatter symbols, funnel trapezoids, treemap cells and sankey
|
|
39
|
+
// nodes. An image needs an accessible name. The chart gives each one a name from
|
|
40
|
+
// what it already has: the shape's `name` (a pie slice has its `nameKey` value),
|
|
41
|
+
// else the config key in its colour (`var(--color-card)`), through that key's
|
|
42
|
+
// config `label`. A shape that already has a name keeps it, so a consumer's
|
|
43
|
+
// `aria-label` (a `Cell`'s, say) wins and can carry the value too.
|
|
44
|
+
const CHART_SHAPES = '[role="img"]:not([aria-label]):not([aria-labelledby])'
|
|
45
|
+
|
|
46
|
+
function configLabel(config: ChartConfig, key: string | null | undefined) {
|
|
47
|
+
if (!key) return undefined
|
|
48
|
+
const label = config[key]?.label
|
|
49
|
+
return typeof label === "string" ? label : undefined
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Backgrounds that carry no data: the track behind a radial bar and the
|
|
53
|
+
// treemap's root rectangle. They are hidden from assistive technology.
|
|
54
|
+
const DECORATIVE_SHAPES =
|
|
55
|
+
".recharts-radial-bar-background-sector, .recharts-treemap-depth-0 > * > * > [role=img]"
|
|
56
|
+
|
|
57
|
+
function nameChartShapes(root: HTMLElement, config: ChartConfig) {
|
|
58
|
+
for (const shape of Array.from(root.querySelectorAll<SVGElement>(CHART_SHAPES))) {
|
|
59
|
+
if (shape.querySelector("title")) continue
|
|
60
|
+
if (shape.matches(DECORATIVE_SHAPES)) {
|
|
61
|
+
shape.setAttribute("aria-hidden", "true")
|
|
62
|
+
continue
|
|
63
|
+
}
|
|
64
|
+
// A scatter symbol and a funnel step are groups: the name and the colour
|
|
65
|
+
// sit on the path inside.
|
|
66
|
+
const source =
|
|
67
|
+
shape.getAttribute("name") || shape.getAttribute("fill")
|
|
68
|
+
? shape
|
|
69
|
+
: shape.querySelector("[name], [fill]")
|
|
70
|
+
if (!source) {
|
|
71
|
+
// A group that holds nothing yet, such as a funnel step before its first
|
|
72
|
+
// frame. There is nothing to describe: hide it until its path arrives.
|
|
73
|
+
if (shape instanceof SVGGElement) {
|
|
74
|
+
shape.setAttribute("aria-hidden", "true")
|
|
75
|
+
shape.setAttribute("data-chart-pending", "")
|
|
76
|
+
}
|
|
77
|
+
continue
|
|
78
|
+
}
|
|
79
|
+
const name = source.getAttribute("name")
|
|
80
|
+
const color = /--color-([\w-]+)/.exec(
|
|
81
|
+
source.getAttribute("fill") ?? source.getAttribute("stroke") ?? ""
|
|
82
|
+
)?.[1]
|
|
83
|
+
const label = configLabel(config, name) ?? name ?? configLabel(config, color)
|
|
84
|
+
if (label) {
|
|
85
|
+
shape.setAttribute("aria-label", label)
|
|
86
|
+
if (shape.hasAttribute("data-chart-pending")) {
|
|
87
|
+
shape.removeAttribute("data-chart-pending")
|
|
88
|
+
shape.removeAttribute("aria-hidden")
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Names the chart's image shapes, now and as the chart draws (recharts replaces
|
|
96
|
+
* shapes while it animates). It watches only the tree below the container, and
|
|
97
|
+
* setting `aria-label` or `aria-hidden` does not trigger it again.
|
|
98
|
+
*/
|
|
99
|
+
function useChartShapeNames(
|
|
100
|
+
ref: React.RefObject<HTMLElement | null>,
|
|
101
|
+
config: ChartConfig
|
|
102
|
+
) {
|
|
103
|
+
React.useLayoutEffect(() => {
|
|
104
|
+
const root = ref.current
|
|
105
|
+
if (!root) return
|
|
106
|
+
nameChartShapes(root, config)
|
|
107
|
+
if (typeof MutationObserver === "undefined") return
|
|
108
|
+
const observer = new MutationObserver(() => nameChartShapes(root, config))
|
|
109
|
+
observer.observe(root, {
|
|
110
|
+
childList: true,
|
|
111
|
+
subtree: true,
|
|
112
|
+
// A funnel step gets its name and colour after it is drawn.
|
|
113
|
+
attributes: true,
|
|
114
|
+
attributeFilter: ["name", "fill", "stroke"],
|
|
115
|
+
})
|
|
116
|
+
return () => observer.disconnect()
|
|
117
|
+
}, [ref, config])
|
|
118
|
+
}
|
|
119
|
+
|
|
37
120
|
function ChartContainer({
|
|
38
121
|
id,
|
|
39
122
|
className,
|
|
@@ -48,10 +131,13 @@ function ChartContainer({
|
|
|
48
131
|
}) {
|
|
49
132
|
const uniqueId = React.useId()
|
|
50
133
|
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`
|
|
134
|
+
const ref = React.useRef<HTMLDivElement>(null)
|
|
135
|
+
useChartShapeNames(ref, config)
|
|
51
136
|
|
|
52
137
|
return (
|
|
53
138
|
<ChartContext.Provider value={{ config }}>
|
|
54
139
|
<div
|
|
140
|
+
ref={ref}
|
|
55
141
|
data-slot="chart"
|
|
56
142
|
data-chart={chartId}
|
|
57
143
|
className={cn(
|
|
@@ -173,7 +259,7 @@ function ChartTooltipContent({
|
|
|
173
259
|
return (
|
|
174
260
|
<div
|
|
175
261
|
className={cn(
|
|
176
|
-
"
|
|
262
|
+
"bg-popover text-popover-foreground grid min-w-32 items-start gap-1.5 rounded-xl px-2.5 py-1.5 text-xs shadow-overlay",
|
|
177
263
|
className
|
|
178
264
|
)}
|
|
179
265
|
>
|
|
@@ -3,25 +3,103 @@
|
|
|
3
3
|
import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox"
|
|
4
4
|
|
|
5
5
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
useFieldControlProps,
|
|
8
|
+
useFieldLabelCheckedClass,
|
|
9
|
+
} from "@vendure-io/ui/components/atoms/field"
|
|
10
|
+
|
|
11
|
+
// Checking animates; unchecking plays back quicker.
|
|
12
|
+
// - The fill is the root's ::before, over the border. It closes in from the
|
|
13
|
+
// corners and edges to the middle: an even-odd clip-path is the box with a
|
|
14
|
+
// round hole, and the hole shrinks from just around the box (nothing shows)
|
|
15
|
+
// to a point in the middle (all of it shows). The corners fill first.
|
|
16
|
+
// Checking takes `moderate` on `ease-out`; unchecking opens the hole again
|
|
17
|
+
// in `fast`.
|
|
18
|
+
// - The fill reveals the mark: the mark is always drawn, in the fill's
|
|
19
|
+
// foreground, and its indicator takes the same clip with the same timing.
|
|
20
|
+
// So the mark shows only where the fill already is, and the hole hides it
|
|
21
|
+
// while it is open, on any background.
|
|
22
|
+
// - The check and the indeterminate line are two paths; only the one for the
|
|
23
|
+
// current state shows. Checking or going indeterminate swaps them at once
|
|
24
|
+
// (the hole hides the swap, or the fill is already whole). Unchecking keeps
|
|
25
|
+
// the mark until the hole has opened, then swaps.
|
|
26
|
+
// - A press shrinks the box to 95% (`fast`, `ease-press`).
|
|
27
|
+
// Checking ends after `moderate` (150ms), unchecking after `fast` (100ms).
|
|
28
|
+
// Only transitions, no keyframes, so a fast toggle or a range selection
|
|
29
|
+
// reverses from wherever it is. Reduced motion keeps fades only: the fill and
|
|
30
|
+
// the mark are whole and fade in and out together. The root also transitions
|
|
31
|
+
// opacity, so a caller that fades the box in (the DataTable's hidden
|
|
32
|
+
// checkboxes) needs no transition of its own, which would replace this list.
|
|
33
|
+
// The DataTable delays the root, the ::before and the indicator for its
|
|
34
|
+
// select-all ripple.
|
|
35
|
+
const rootTransition =
|
|
36
|
+
"[transition: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),scale_var(--transition-duration-fast)_var(--ease-press)] data-checked:[transition: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),scale_var(--transition-duration-fast)_var(--ease-press)] data-indeterminate:[transition: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),scale_var(--transition-duration-fast)_var(--ease-press)] not-data-disabled:active:scale-95 motion-reduce:active:scale-100"
|
|
37
|
+
|
|
38
|
+
// `--checkbox-hole` is how far open the hole is: 1 leaves no fill, 0 a full
|
|
39
|
+
// box. The root sets it and builds `--checkbox-clip` from it once; the fill
|
|
40
|
+
// and the mark's indicator both clip to that, each over the box plus its 1px
|
|
41
|
+
// border, and each transitions its own clip-path. The hole is a circle around
|
|
42
|
+
// the middle. At 1 its radius is half the box's diagonal plus 1px, so the
|
|
43
|
+
// corners are empty too; on the box's own edge, the clip's anti-aliasing left
|
|
44
|
+
// a hairline of fill at rest. The circle is a `shape()` with two half-circle
|
|
45
|
+
// arcs; their 1px radius is too small for the chord, so the browser scales it
|
|
46
|
+
// up to half the chord, a true circle at any size. A browser without `shape()`
|
|
47
|
+
// keeps a square hole that closes in from the edges over the same time.
|
|
48
|
+
const hole =
|
|
49
|
+
"[--checkbox-hole:1] data-checked:[--checkbox-hole:0] data-indeterminate:[--checkbox-hole:0] motion-reduce:[--checkbox-hole:0] [--checkbox-clip:polygon(evenodd,-1px_-1px,calc(100%_+_1px)_-1px,calc(100%_+_1px)_calc(100%_+_1px),-1px_calc(100%_+_1px),-1px_-1px,calc(50%_-_var(--checkbox-hole)*(50%_+_1px))_calc(50%_-_var(--checkbox-hole)*(50%_+_1px)),calc(50%_+_var(--checkbox-hole)*(50%_+_1px))_calc(50%_-_var(--checkbox-hole)*(50%_+_1px)),calc(50%_+_var(--checkbox-hole)*(50%_+_1px))_calc(50%_+_var(--checkbox-hole)*(50%_+_1px)),calc(50%_-_var(--checkbox-hole)*(50%_+_1px))_calc(50%_+_var(--checkbox-hole)*(50%_+_1px)),calc(50%_-_var(--checkbox-hole)*(50%_+_1px))_calc(50%_-_var(--checkbox-hole)*(50%_+_1px)))] supports-[clip-path:shape(from_0_0,line_to_1px_1px)]:[--checkbox-clip:shape(evenodd_from_-1px_-1px,line_to_calc(100%_+_1px)_-1px,line_to_calc(100%_+_1px)_calc(100%_+_1px),line_to_-1px_calc(100%_+_1px),close,move_to_calc(50%_-_var(--checkbox-hole)*(70.711%_+_1px))_50%,arc_to_calc(50%_+_var(--checkbox-hole)*(70.711%_+_1px))_50%_of_1px_cw,arc_to_calc(50%_-_var(--checkbox-hole)*(70.711%_+_1px))_50%_of_1px_cw,close)]"
|
|
50
|
+
|
|
51
|
+
const fill =
|
|
52
|
+
"before:absolute before:-inset-px before:rounded-[inherit] before:bg-primary before:[clip-path:var(--checkbox-clip)] before:[transition:clip-path_var(--transition-duration-fast)_var(--ease-soft)] data-checked:before:[transition:clip-path_var(--transition-duration-moderate)_var(--ease-out)] data-indeterminate:before:[transition:clip-path_var(--transition-duration-moderate)_var(--ease-out)] motion-reduce:before:opacity-0 motion-reduce:data-checked:before:opacity-100 motion-reduce:data-indeterminate:before:opacity-100 motion-reduce:before:[transition:opacity_var(--transition-duration-fast)_var(--ease-soft)] motion-reduce:data-checked:before:[transition:opacity_var(--transition-duration-normal)_var(--ease-soft)] motion-reduce:data-indeterminate:before:[transition:opacity_var(--transition-duration-normal)_var(--ease-soft)]"
|
|
53
|
+
|
|
54
|
+
// The indicator keys on its own state attributes, which Base UI sets to match the root's.
|
|
55
|
+
const indicator =
|
|
56
|
+
"absolute -inset-px grid place-content-center text-primary-foreground [clip-path:var(--checkbox-clip)] [transition:clip-path_var(--transition-duration-fast)_var(--ease-soft)] data-checked:[transition:clip-path_var(--transition-duration-moderate)_var(--ease-out)] data-indeterminate:[transition:clip-path_var(--transition-duration-moderate)_var(--ease-out)] motion-reduce:opacity-0 motion-reduce:data-checked:opacity-100 motion-reduce:data-indeterminate:opacity-100 motion-reduce:[transition:opacity_var(--transition-duration-fast)_var(--ease-soft)] motion-reduce:data-checked:[transition:opacity_var(--transition-duration-normal)_var(--ease-soft)] motion-reduce:data-indeterminate:[transition:opacity_var(--transition-duration-normal)_var(--ease-soft)]"
|
|
57
|
+
|
|
58
|
+
// The swap waits `fast` while unchecking, so the leaving mark stays until the
|
|
59
|
+
// hole has opened. A 0s transition with a delay is a step at the end.
|
|
60
|
+
const markSwap =
|
|
61
|
+
"[stroke-dasharray:1] [transition:opacity_0s_linear_var(--transition-duration-fast)] group-data-[checked]/checkbox:[transition-delay:0s] group-data-indeterminate/checkbox:[transition-delay:0s]"
|
|
62
|
+
|
|
63
|
+
// The check shows unless indeterminate (unchecked, the hole hides it), the line only while indeterminate.
|
|
64
|
+
const checkMark = "group-data-indeterminate/checkbox:opacity-0"
|
|
65
|
+
const lineMark = "opacity-0 group-data-indeterminate/checkbox:opacity-100"
|
|
8
66
|
|
|
9
67
|
function Checkbox({ className, indeterminate, ...props }: CheckboxPrimitive.Root.Props) {
|
|
68
|
+
const fieldLabelChecked = useFieldLabelCheckedClass()
|
|
10
69
|
return (
|
|
11
70
|
<CheckboxPrimitive.Root
|
|
12
71
|
data-slot="checkbox"
|
|
13
|
-
className={cn(
|
|
14
|
-
"border-control-border dark:bg-input/30 data-checked:
|
|
15
|
-
|
|
72
|
+
className={(state) => cn(
|
|
73
|
+
"group/checkbox border-control-border dark:bg-input/30 data-checked:text-primary-foreground data-checked:border-primary data-indeterminate:text-primary-foreground data-indeterminate:border-primary aria-invalid:aria-checked:border-primary aria-invalid:border-destructive 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 peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border outline-none group-has-disabled/field:opacity-50 after:absolute after:-inset-x-3 after:-inset-y-2 data-disabled:cursor-not-allowed data-disabled:opacity-50 aria-invalid:ring-3",
|
|
74
|
+
rootTransition,
|
|
75
|
+
hole,
|
|
76
|
+
fill,
|
|
77
|
+
fieldLabelChecked(state.checked && !state.indeterminate),
|
|
78
|
+
typeof className === "function" ? className(state) : className
|
|
16
79
|
)}
|
|
17
80
|
indeterminate={indeterminate}
|
|
18
81
|
{...useFieldControlProps(props)}
|
|
19
82
|
>
|
|
83
|
+
{/* Kept mounted: the fill reveals the mark while checking and hides it
|
|
84
|
+
again while unchecking. */}
|
|
20
85
|
<CheckboxPrimitive.Indicator
|
|
86
|
+
keepMounted
|
|
21
87
|
data-slot="checkbox-indicator"
|
|
22
|
-
className=
|
|
88
|
+
className={indicator}
|
|
23
89
|
>
|
|
24
|
-
|
|
90
|
+
<svg
|
|
91
|
+
viewBox="0 0 24 24"
|
|
92
|
+
fill="none"
|
|
93
|
+
stroke="currentColor"
|
|
94
|
+
strokeWidth="2"
|
|
95
|
+
strokeLinecap="round"
|
|
96
|
+
strokeLinejoin="round"
|
|
97
|
+
aria-hidden="true"
|
|
98
|
+
className="size-3.5"
|
|
99
|
+
>
|
|
100
|
+
<path d="M4 12l5 5L20 6" pathLength={1} className={`${markSwap} ${checkMark}`} />
|
|
101
|
+
<path d="M5 12h14" pathLength={1} className={`${markSwap} ${lineMark}`} />
|
|
102
|
+
</svg>
|
|
25
103
|
</CheckboxPrimitive.Indicator>
|
|
26
104
|
</CheckboxPrimitive.Root>
|
|
27
105
|
)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
3
|
import { Collapsible as CollapsiblePrimitive } from "@base-ui/react/collapsible"
|
|
4
|
+
import { triggerSlot } from "../../lib/trigger-slot.ts"
|
|
4
5
|
|
|
5
6
|
function Collapsible({ ...props }: CollapsiblePrimitive.Root.Props) {
|
|
6
7
|
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />
|
|
@@ -8,7 +9,7 @@ function Collapsible({ ...props }: CollapsiblePrimitive.Root.Props) {
|
|
|
8
9
|
|
|
9
10
|
function CollapsibleTrigger({ ...props }: CollapsiblePrimitive.Trigger.Props) {
|
|
10
11
|
return (
|
|
11
|
-
<CollapsiblePrimitive.Trigger
|
|
12
|
+
<CollapsiblePrimitive.Trigger {...triggerSlot("collapsible-trigger", props.render)} {...props} />
|
|
12
13
|
)
|
|
13
14
|
}
|
|
14
15
|
|