@vendure-io/ui 2.0.1 → 2.2.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 +1 -1
- package/src/components/atoms/alert.tsx +21 -4
- package/src/components/atoms/checkbox.tsx +2 -1
- package/src/components/atoms/field.tsx +134 -11
- package/src/components/atoms/input.tsx +4 -1
- package/src/components/atoms/native-select.tsx +4 -1
- package/src/components/atoms/progress.tsx +60 -10
- package/src/components/atoms/radio-group.tsx +2 -1
- package/src/components/atoms/select.tsx +2 -1
- package/src/components/atoms/switch.tsx +2 -1
- package/src/components/atoms/textarea.tsx +4 -1
- package/src/components/molecules/confirm-dialog.tsx +25 -3
- package/src/components/molecules/copyable-text.tsx +6 -2
- package/src/components/molecules/data-table/data-table-filters.tsx +1 -1
- package/src/components/molecules/data-table/data-table-types.tsx +17 -0
- package/src/components/molecules/data-table/data-table-view-options.tsx +5 -2
- package/src/components/molecules/data-table/data-table.tsx +83 -8
- package/src/components/molecules/id-chip.tsx +39 -9
- package/src/components/molecules/relative-time.tsx +66 -11
- package/src/components/molecules/secret-value.tsx +183 -0
- package/src/components/molecules/state-views/empty-state.tsx +18 -10
- package/src/components/molecules/state-views/error-state.tsx +29 -6
- package/src/hooks/use-copy.ts +8 -4
- package/src/lib/clipboard.ts +38 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vendure-io/ui",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "React component library for Vendure, built on shadcn/ui and Tailwind v4",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"homepage": "https://github.com/vendurehq/design/tree/main/packages/ui",
|
|
@@ -3,14 +3,23 @@ import { cva, type VariantProps } from "class-variance-authority"
|
|
|
3
3
|
|
|
4
4
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
5
5
|
|
|
6
|
+
// Alert is an inline-size container so AlertAction can move under the text when
|
|
7
|
+
// the alert is narrow. A container cannot size to its content: an Alert inside a
|
|
8
|
+
// flex row needs a width (it is w-full by default), not w-fit.
|
|
9
|
+
// The grid has no column gap: the icon carries its own margin, so the empty
|
|
10
|
+
// action column of a narrow alert takes no space.
|
|
6
11
|
const alertVariants = cva(
|
|
7
|
-
"grid gap-0.5 rounded-lg border px-4 py-3 text-left text-sm has-
|
|
12
|
+
"@container/alert grid grid-cols-[minmax(0,1fr)] gap-y-0.5 rounded-lg border px-4 py-3 text-left text-sm has-[>svg]:grid-cols-[auto_minmax(0,1fr)] has-[>[data-slot=alert-action]]:grid-cols-[minmax(0,1fr)_auto] has-[>svg]:has-[>[data-slot=alert-action]]:grid-cols-[auto_minmax(0,1fr)_auto] *:[svg]:row-span-2 *:[svg]:me-2.5 *:[svg]:translate-y-0.5 *:[svg]:text-current *:[svg:not([class*='size-'])]:size-4 w-full relative group/alert",
|
|
8
13
|
{
|
|
9
14
|
variants: {
|
|
10
15
|
variant: {
|
|
11
16
|
default: "bg-card text-card-foreground",
|
|
12
17
|
destructive:
|
|
13
18
|
"text-destructive-subtle-foreground bg-card *:data-[slot=alert-description]:text-destructive-subtle-foreground *:[svg]:text-current",
|
|
19
|
+
warning:
|
|
20
|
+
"text-warning-subtle-foreground bg-card *:data-[slot=alert-description]:text-warning-subtle-foreground *:[svg]:text-current",
|
|
21
|
+
info:
|
|
22
|
+
"text-info-subtle-foreground bg-card *:data-[slot=alert-description]:text-info-subtle-foreground *:[svg]:text-current",
|
|
14
23
|
},
|
|
15
24
|
},
|
|
16
25
|
defaultVariants: {
|
|
@@ -39,7 +48,7 @@ function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
39
48
|
<div
|
|
40
49
|
data-slot="alert-title"
|
|
41
50
|
className={cn(
|
|
42
|
-
"[&_a]:hover:text-foreground font-medium group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3",
|
|
51
|
+
"[&_a]:hover:text-foreground col-start-1 font-medium group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3",
|
|
43
52
|
className
|
|
44
53
|
)}
|
|
45
54
|
{...props}
|
|
@@ -55,7 +64,7 @@ function AlertDescription({
|
|
|
55
64
|
<div
|
|
56
65
|
data-slot="alert-description"
|
|
57
66
|
className={cn(
|
|
58
|
-
"text-muted-foreground [&_a]:hover:text-foreground text-sm text-balance md:text-pretty [&_a]:underline [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-4",
|
|
67
|
+
"text-muted-foreground [&_a]:hover:text-foreground col-start-1 text-sm text-balance wrap-anywhere group-has-[>svg]/alert:col-start-2 md:text-pretty [&_a]:underline [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-4",
|
|
59
68
|
className
|
|
60
69
|
)}
|
|
61
70
|
{...props}
|
|
@@ -63,11 +72,19 @@ function AlertDescription({
|
|
|
63
72
|
)
|
|
64
73
|
}
|
|
65
74
|
|
|
75
|
+
// From a 28rem-wide alert up, the action takes the last grid column on the first
|
|
76
|
+
// row, so the text wraps before it. The action box is one text line high and
|
|
77
|
+
// centres its content, so a button lines up with the first line of the text and
|
|
78
|
+
// overflows into the alert padding instead of making the alert taller. In a
|
|
79
|
+
// narrower alert the action moves to its own row under the text.
|
|
66
80
|
function AlertAction({ className, ...props }: React.ComponentProps<"div">) {
|
|
67
81
|
return (
|
|
68
82
|
<div
|
|
69
83
|
data-slot="alert-action"
|
|
70
|
-
className={cn(
|
|
84
|
+
className={cn(
|
|
85
|
+
"col-end-[-1] flex flex-wrap content-center items-center gap-2 @max-md/alert:col-start-1 @max-md/alert:mt-2 @max-md/alert:group-has-[>svg]/alert:col-start-2 @md/alert:row-start-1 @md/alert:ms-3 @md/alert:h-lh @md/alert:self-start",
|
|
86
|
+
className
|
|
87
|
+
)}
|
|
71
88
|
{...props}
|
|
72
89
|
/>
|
|
73
90
|
)
|
|
@@ -3,6 +3,7 @@
|
|
|
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 { useFieldControlProps } from "@vendure-io/ui/components/atoms/field"
|
|
6
7
|
import { CheckIcon, MinusIcon } from "lucide-react"
|
|
7
8
|
|
|
8
9
|
function Checkbox({ className, indeterminate, ...props }: CheckboxPrimitive.Root.Props) {
|
|
@@ -14,7 +15,7 @@ function Checkbox({ className, indeterminate, ...props }: CheckboxPrimitive.Root
|
|
|
14
15
|
className
|
|
15
16
|
)}
|
|
16
17
|
indeterminate={indeterminate}
|
|
17
|
-
{...props}
|
|
18
|
+
{...useFieldControlProps(props)}
|
|
18
19
|
>
|
|
19
20
|
<CheckboxPrimitive.Indicator
|
|
20
21
|
data-slot="checkbox-indicator"
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useCallback,
|
|
6
|
+
useContext,
|
|
7
|
+
useEffect,
|
|
8
|
+
useId,
|
|
9
|
+
useMemo,
|
|
10
|
+
useState,
|
|
11
|
+
} from "react"
|
|
4
12
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
5
13
|
|
|
6
14
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
@@ -69,22 +77,107 @@ const fieldVariants = cva(
|
|
|
69
77
|
}
|
|
70
78
|
)
|
|
71
79
|
|
|
80
|
+
// Field links its control to the FieldDescription and FieldError it renders.
|
|
81
|
+
// Each message registers its id once mounted; controls read the context through
|
|
82
|
+
// useFieldControlProps and get aria-describedby (descriptions first, then
|
|
83
|
+
// errors) and aria-invalid while the Field is data-invalid. A control's own
|
|
84
|
+
// aria-describedby or aria-invalid wins.
|
|
85
|
+
type FieldMessageKind = "description" | "error"
|
|
86
|
+
|
|
87
|
+
type FieldContextValue = {
|
|
88
|
+
describedBy: string | undefined
|
|
89
|
+
invalid: boolean
|
|
90
|
+
register: (id: string, kind: FieldMessageKind) => () => void
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const FieldContext = createContext<FieldContextValue | null>(null)
|
|
94
|
+
|
|
95
|
+
/** Space-separated ids, descriptions before errors; undefined when empty. */
|
|
96
|
+
function fieldDescribedBy(
|
|
97
|
+
messages: ReadonlyArray<{ id: string; kind: FieldMessageKind }>
|
|
98
|
+
) {
|
|
99
|
+
const ids = [
|
|
100
|
+
...messages.filter((message) => message.kind === "description"),
|
|
101
|
+
...messages.filter((message) => message.kind === "error"),
|
|
102
|
+
].map((message) => message.id)
|
|
103
|
+
return ids.length ? ids.join(" ") : undefined
|
|
104
|
+
}
|
|
105
|
+
|
|
72
106
|
function Field({
|
|
73
107
|
className,
|
|
74
108
|
orientation = "vertical",
|
|
109
|
+
children,
|
|
75
110
|
...props
|
|
76
|
-
}: React.ComponentProps<"div"> &
|
|
111
|
+
}: React.ComponentProps<"div"> &
|
|
112
|
+
VariantProps<typeof fieldVariants> & {
|
|
113
|
+
"data-invalid"?: boolean | "true" | "false"
|
|
114
|
+
}) {
|
|
115
|
+
const [messages, setMessages] = useState<
|
|
116
|
+
Array<{ id: string; kind: FieldMessageKind }>
|
|
117
|
+
>([])
|
|
118
|
+
const register = useCallback((id: string, kind: FieldMessageKind) => {
|
|
119
|
+
setMessages((current) => [...current, { id, kind }])
|
|
120
|
+
return () =>
|
|
121
|
+
setMessages((current) => current.filter((message) => message.id !== id))
|
|
122
|
+
}, [])
|
|
123
|
+
const invalid =
|
|
124
|
+
props["data-invalid"] === true || props["data-invalid"] === "true"
|
|
125
|
+
const describedBy = fieldDescribedBy(messages)
|
|
126
|
+
const context = useMemo(
|
|
127
|
+
() => ({ describedBy, invalid, register }),
|
|
128
|
+
[describedBy, invalid, register]
|
|
129
|
+
)
|
|
130
|
+
|
|
77
131
|
return (
|
|
78
|
-
<
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
132
|
+
<FieldContext.Provider value={context}>
|
|
133
|
+
<div
|
|
134
|
+
role="group"
|
|
135
|
+
data-slot="field"
|
|
136
|
+
data-orientation={orientation}
|
|
137
|
+
className={cn(fieldVariants({ orientation }), className)}
|
|
138
|
+
{...props}
|
|
139
|
+
>
|
|
140
|
+
{children}
|
|
141
|
+
</div>
|
|
142
|
+
</FieldContext.Provider>
|
|
85
143
|
)
|
|
86
144
|
}
|
|
87
145
|
|
|
146
|
+
/** Gives a message a stable id and registers it with the enclosing Field. */
|
|
147
|
+
function useFieldMessageId(id: string | undefined, kind: FieldMessageKind) {
|
|
148
|
+
const generatedId = useId()
|
|
149
|
+
const messageId = id ?? generatedId
|
|
150
|
+
const register = useContext(FieldContext)?.register
|
|
151
|
+
useEffect(() => register?.(messageId, kind), [register, messageId, kind])
|
|
152
|
+
return messageId
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
type FieldControlAria = {
|
|
156
|
+
"aria-describedby"?: string
|
|
157
|
+
"aria-invalid"?: React.AriaAttributes["aria-invalid"]
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Merges a Field's state into control props. Explicit props win. */
|
|
161
|
+
function mergeFieldControlProps<P extends FieldControlAria>(
|
|
162
|
+
props: P,
|
|
163
|
+
field: Pick<FieldContextValue, "describedBy" | "invalid"> | null
|
|
164
|
+
): P {
|
|
165
|
+
if (!field) return props
|
|
166
|
+
return {
|
|
167
|
+
...props,
|
|
168
|
+
"aria-describedby": props["aria-describedby"] ?? field.describedBy,
|
|
169
|
+
"aria-invalid": props["aria-invalid"] ?? (field.invalid || undefined),
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Adds the enclosing Field's aria-describedby and aria-invalid to a control's
|
|
175
|
+
* props. Props the consumer passes explicitly win.
|
|
176
|
+
*/
|
|
177
|
+
function useFieldControlProps<P extends FieldControlAria>(props: P): P {
|
|
178
|
+
return mergeFieldControlProps(props, useContext(FieldContext))
|
|
179
|
+
}
|
|
180
|
+
|
|
88
181
|
function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
89
182
|
return (
|
|
90
183
|
<div
|
|
@@ -128,9 +221,15 @@ function FieldTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
128
221
|
)
|
|
129
222
|
}
|
|
130
223
|
|
|
131
|
-
function FieldDescription({
|
|
224
|
+
function FieldDescription({
|
|
225
|
+
className,
|
|
226
|
+
id,
|
|
227
|
+
...props
|
|
228
|
+
}: React.ComponentProps<"p">) {
|
|
229
|
+
const messageId = useFieldMessageId(id, "description")
|
|
132
230
|
return (
|
|
133
231
|
<p
|
|
232
|
+
id={messageId}
|
|
134
233
|
data-slot="field-description"
|
|
135
234
|
className={cn(
|
|
136
235
|
"text-muted-foreground text-left text-sm leading-normal font-normal group-has-data-horizontal/field:text-balance [[data-variant=legend]+&]:-mt-1.5",
|
|
@@ -177,6 +276,7 @@ function FieldError({
|
|
|
177
276
|
className,
|
|
178
277
|
children,
|
|
179
278
|
errors,
|
|
279
|
+
id,
|
|
180
280
|
...props
|
|
181
281
|
}: React.ComponentProps<"div"> & {
|
|
182
282
|
errors?: Array<{ message?: string } | undefined>
|
|
@@ -212,14 +312,34 @@ function FieldError({
|
|
|
212
312
|
return null
|
|
213
313
|
}
|
|
214
314
|
|
|
315
|
+
return (
|
|
316
|
+
<FieldErrorMessage
|
|
317
|
+
id={id}
|
|
318
|
+
className={className}
|
|
319
|
+
{...props}
|
|
320
|
+
>
|
|
321
|
+
{content}
|
|
322
|
+
</FieldErrorMessage>
|
|
323
|
+
)
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Split from FieldError so only a rendered error registers its id.
|
|
327
|
+
function FieldErrorMessage({
|
|
328
|
+
className,
|
|
329
|
+
children,
|
|
330
|
+
id,
|
|
331
|
+
...props
|
|
332
|
+
}: React.ComponentProps<"div">) {
|
|
333
|
+
const messageId = useFieldMessageId(id, "error")
|
|
215
334
|
return (
|
|
216
335
|
<div
|
|
336
|
+
id={messageId}
|
|
217
337
|
role="alert"
|
|
218
338
|
data-slot="field-error"
|
|
219
339
|
className={cn("text-destructive-subtle-foreground text-sm font-normal", className)}
|
|
220
340
|
{...props}
|
|
221
341
|
>
|
|
222
|
-
{
|
|
342
|
+
{children}
|
|
223
343
|
</div>
|
|
224
344
|
)
|
|
225
345
|
}
|
|
@@ -235,4 +355,7 @@ export {
|
|
|
235
355
|
FieldSet,
|
|
236
356
|
FieldContent,
|
|
237
357
|
FieldTitle,
|
|
358
|
+
fieldDescribedBy,
|
|
359
|
+
mergeFieldControlProps,
|
|
360
|
+
useFieldControlProps,
|
|
238
361
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
1
3
|
import * as React from "react"
|
|
2
4
|
import { Input as InputPrimitive } from "@base-ui/react/input"
|
|
3
5
|
|
|
4
6
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
7
|
+
import { useFieldControlProps } from "@vendure-io/ui/components/atoms/field"
|
|
5
8
|
|
|
6
9
|
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
|
7
10
|
return (
|
|
@@ -12,7 +15,7 @@ function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
|
|
12
15
|
"dark:bg-input/30 border-input focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive file:text-foreground placeholder:text-muted-foreground h-9 w-full min-w-0 rounded-md border bg-transparent px-2.5 py-1 text-base transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-3 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3 md:text-sm",
|
|
13
16
|
className
|
|
14
17
|
)}
|
|
15
|
-
{...props}
|
|
18
|
+
{...useFieldControlProps(props)}
|
|
16
19
|
/>
|
|
17
20
|
)
|
|
18
21
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
1
3
|
import * as React from "react"
|
|
2
4
|
|
|
3
5
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
6
|
+
import { useFieldControlProps } from "@vendure-io/ui/components/atoms/field"
|
|
4
7
|
import { ChevronDownIcon } from "lucide-react"
|
|
5
8
|
|
|
6
9
|
type NativeSelectProps = Omit<React.ComponentProps<"select">, "size"> & {
|
|
@@ -25,7 +28,7 @@ function NativeSelect({
|
|
|
25
28
|
data-slot="native-select"
|
|
26
29
|
data-size={size}
|
|
27
30
|
className="border-input placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 dark:hover:bg-input/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive h-9 w-full min-w-0 appearance-none rounded-md border bg-transparent py-1 pr-8 pl-2.5 text-sm transition-[color,box-shadow] outline-none select-none focus-visible:ring-3 disabled:pointer-events-none disabled:cursor-not-allowed aria-invalid:ring-3 data-[size=sm]:h-8"
|
|
28
|
-
{...props}
|
|
31
|
+
{...useFieldControlProps(props)}
|
|
29
32
|
/>
|
|
30
33
|
<ChevronDownIcon className="text-muted-foreground pointer-events-none absolute top-1/2 right-2.5 size-4 -translate-y-1/2 select-none" aria-hidden="true" data-slot="native-select-icon" />
|
|
31
34
|
</div>
|
|
@@ -1,37 +1,85 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
3
|
import { Progress as ProgressPrimitive } from "@base-ui/react/progress"
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
4
5
|
|
|
5
6
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
6
7
|
|
|
8
|
+
// Tone names follow the state dictionary; `critical` renders with the
|
|
9
|
+
// `destructive` slots. A toned bar sits on the tone's subtle track. The solid
|
|
10
|
+
// tone slots are too close to the neutral track in luminance (down to 1.1:1),
|
|
11
|
+
// so the fill uses a fixed ramp step in light mode (600: at least 3.97:1 on the
|
|
12
|
+
// track and 4.35:1 on the page) and the subtle foreground in dark mode (at
|
|
13
|
+
// least 8.58:1 on the track), meeting 3:1 non-text contrast in both.
|
|
14
|
+
const progressTrackVariants = cva(
|
|
15
|
+
"relative flex h-1.5 w-full items-center overflow-x-hidden rounded-full",
|
|
16
|
+
{
|
|
17
|
+
variants: {
|
|
18
|
+
tone: {
|
|
19
|
+
default: "bg-control-border",
|
|
20
|
+
success: "bg-success-subtle",
|
|
21
|
+
warning: "bg-warning-subtle",
|
|
22
|
+
critical: "bg-destructive-subtle",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
defaultVariants: {
|
|
26
|
+
tone: "default",
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
const progressIndicatorVariants = cva("h-full transition-all", {
|
|
32
|
+
variants: {
|
|
33
|
+
tone: {
|
|
34
|
+
default: "bg-primary",
|
|
35
|
+
success: "bg-success-600 dark:bg-success-subtle-foreground",
|
|
36
|
+
warning: "bg-warning-600 dark:bg-warning-subtle-foreground",
|
|
37
|
+
critical: "bg-destructive-600 dark:bg-destructive-subtle-foreground",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
defaultVariants: {
|
|
41
|
+
tone: "default",
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
type ProgressTone = NonNullable<
|
|
46
|
+
VariantProps<typeof progressIndicatorVariants>["tone"]
|
|
47
|
+
>
|
|
48
|
+
|
|
7
49
|
function Progress({
|
|
8
50
|
className,
|
|
9
51
|
children,
|
|
10
52
|
value,
|
|
53
|
+
tone = "default",
|
|
11
54
|
...props
|
|
12
|
-
}: ProgressPrimitive.Root.Props
|
|
55
|
+
}: ProgressPrimitive.Root.Props & {
|
|
56
|
+
/** Indicator tone. Follows consequence: see the Progress guidance. */
|
|
57
|
+
tone?: ProgressTone
|
|
58
|
+
}) {
|
|
13
59
|
return (
|
|
14
60
|
<ProgressPrimitive.Root
|
|
15
61
|
value={value}
|
|
16
62
|
data-slot="progress"
|
|
63
|
+
data-tone={tone}
|
|
17
64
|
className={cn("flex flex-wrap gap-3", className)}
|
|
18
65
|
{...props}
|
|
19
66
|
>
|
|
20
67
|
{children}
|
|
21
|
-
<ProgressTrack>
|
|
22
|
-
<ProgressIndicator />
|
|
68
|
+
<ProgressTrack tone={tone}>
|
|
69
|
+
<ProgressIndicator tone={tone} />
|
|
23
70
|
</ProgressTrack>
|
|
24
71
|
</ProgressPrimitive.Root>
|
|
25
72
|
)
|
|
26
73
|
}
|
|
27
74
|
|
|
28
|
-
function ProgressTrack({
|
|
75
|
+
function ProgressTrack({
|
|
76
|
+
className,
|
|
77
|
+
tone,
|
|
78
|
+
...props
|
|
79
|
+
}: ProgressPrimitive.Track.Props & { tone?: ProgressTone }) {
|
|
29
80
|
return (
|
|
30
81
|
<ProgressPrimitive.Track
|
|
31
|
-
className={cn(
|
|
32
|
-
"bg-control-border relative flex h-1.5 w-full items-center overflow-x-hidden rounded-full",
|
|
33
|
-
className
|
|
34
|
-
)}
|
|
82
|
+
className={cn(progressTrackVariants({ tone }), className)}
|
|
35
83
|
data-slot="progress-track"
|
|
36
84
|
{...props}
|
|
37
85
|
/>
|
|
@@ -40,12 +88,13 @@ function ProgressTrack({ className, ...props }: ProgressPrimitive.Track.Props) {
|
|
|
40
88
|
|
|
41
89
|
function ProgressIndicator({
|
|
42
90
|
className,
|
|
91
|
+
tone,
|
|
43
92
|
...props
|
|
44
|
-
}: ProgressPrimitive.Indicator.Props) {
|
|
93
|
+
}: ProgressPrimitive.Indicator.Props & { tone?: ProgressTone }) {
|
|
45
94
|
return (
|
|
46
95
|
<ProgressPrimitive.Indicator
|
|
47
96
|
data-slot="progress-indicator"
|
|
48
|
-
className={cn(
|
|
97
|
+
className={cn(progressIndicatorVariants({ tone }), className)}
|
|
49
98
|
{...props}
|
|
50
99
|
/>
|
|
51
100
|
)
|
|
@@ -80,4 +129,5 @@ export {
|
|
|
80
129
|
ProgressIndicator,
|
|
81
130
|
ProgressLabel,
|
|
82
131
|
ProgressValue,
|
|
132
|
+
type ProgressTone,
|
|
83
133
|
}
|
|
@@ -4,13 +4,14 @@ import { Radio as RadioPrimitive } from "@base-ui/react/radio"
|
|
|
4
4
|
import { RadioGroup as RadioGroupPrimitive } from "@base-ui/react/radio-group"
|
|
5
5
|
|
|
6
6
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
7
|
+
import { useFieldControlProps } from "@vendure-io/ui/components/atoms/field"
|
|
7
8
|
|
|
8
9
|
function RadioGroup({ className, ...props }: RadioGroupPrimitive.Props) {
|
|
9
10
|
return (
|
|
10
11
|
<RadioGroupPrimitive
|
|
11
12
|
data-slot="radio-group"
|
|
12
13
|
className={cn("grid w-full gap-3", className)}
|
|
13
|
-
{...props}
|
|
14
|
+
{...useFieldControlProps(props)}
|
|
14
15
|
/>
|
|
15
16
|
)
|
|
16
17
|
}
|
|
@@ -4,6 +4,7 @@ import * as React from "react"
|
|
|
4
4
|
import { Select as SelectPrimitive } from "@base-ui/react/select"
|
|
5
5
|
|
|
6
6
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
7
|
+
import { useFieldControlProps } from "@vendure-io/ui/components/atoms/field"
|
|
7
8
|
import { ChevronDownIcon, CheckIcon, ChevronUpIcon } from "lucide-react"
|
|
8
9
|
|
|
9
10
|
const Select = SelectPrimitive.Root
|
|
@@ -44,7 +45,7 @@ function SelectTrigger({
|
|
|
44
45
|
"border-input data-placeholder:text-muted-foreground dark:bg-input/30 dark:hover:bg-input/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive flex w-fit items-center justify-between gap-1.5 rounded-md border bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap transition-[color,box-shadow] outline-none focus-visible:ring-3 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
45
46
|
className
|
|
46
47
|
)}
|
|
47
|
-
{...props}
|
|
48
|
+
{...useFieldControlProps(props)}
|
|
48
49
|
>
|
|
49
50
|
{children}
|
|
50
51
|
<SelectPrimitive.Icon
|
|
@@ -3,6 +3,7 @@
|
|
|
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 { useFieldControlProps } from "@vendure-io/ui/components/atoms/field"
|
|
6
7
|
|
|
7
8
|
function Switch({
|
|
8
9
|
className,
|
|
@@ -19,7 +20,7 @@ function Switch({
|
|
|
19
20
|
"data-checked:bg-primary data-unchecked:bg-control-border focus-visible:border-ring focus-visible:ring-ring/50 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 transition-all outline-none after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:ring-3 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]",
|
|
20
21
|
className
|
|
21
22
|
)}
|
|
22
|
-
{...props}
|
|
23
|
+
{...useFieldControlProps(props)}
|
|
23
24
|
>
|
|
24
25
|
<SwitchPrimitive.Thumb
|
|
25
26
|
data-slot="switch-thumb"
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
1
3
|
import * as React from "react"
|
|
2
4
|
|
|
3
5
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
6
|
+
import { useFieldControlProps } from "@vendure-io/ui/components/atoms/field"
|
|
4
7
|
|
|
5
8
|
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
|
6
9
|
return (
|
|
@@ -10,7 +13,7 @@ function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
|
|
10
13
|
"border-input dark:bg-input/30 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive placeholder:text-muted-foreground flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-2.5 py-2 text-base transition-[color,box-shadow] outline-none focus-visible:ring-3 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3 md:text-sm",
|
|
11
14
|
className
|
|
12
15
|
)}
|
|
13
|
-
{...props}
|
|
16
|
+
{...useFieldControlProps(props)}
|
|
14
17
|
/>
|
|
15
18
|
)
|
|
16
19
|
}
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
AlertDialogTrigger,
|
|
13
13
|
} from '@vendure-io/ui/components/atoms/alert-dialog';
|
|
14
14
|
import { Spinner } from '@vendure-io/ui/components/atoms/spinner';
|
|
15
|
-
import { type ReactElement, type ReactNode, useRef, useState } from 'react';
|
|
15
|
+
import { type ReactElement, type ReactNode, useId, useRef, useState } from 'react';
|
|
16
16
|
|
|
17
17
|
interface ConfirmDialogProps {
|
|
18
18
|
title: ReactNode;
|
|
@@ -26,6 +26,14 @@ interface ConfirmDialogProps {
|
|
|
26
26
|
confirmLabel?: ReactNode;
|
|
27
27
|
cancelLabel?: ReactNode;
|
|
28
28
|
variant?: 'default' | 'destructive';
|
|
29
|
+
/**
|
|
30
|
+
* Hold the confirm button disabled while the dialog cannot be confirmed yet,
|
|
31
|
+
* e.g. while the consequences it describes are still loading. Cancel stays
|
|
32
|
+
* available.
|
|
33
|
+
*/
|
|
34
|
+
confirmDisabled?: boolean;
|
|
35
|
+
/** Why confirm is disabled, shown beside the buttons while `confirmDisabled` is set. */
|
|
36
|
+
confirmDisabledReason?: ReactNode;
|
|
29
37
|
/** Uncontrolled mode — the element that opens the dialog. */
|
|
30
38
|
children?: ReactElement;
|
|
31
39
|
/** Controlled mode — supply with `onOpenChange`. */
|
|
@@ -40,6 +48,8 @@ function ConfirmDialog({
|
|
|
40
48
|
confirmLabel = 'Confirm',
|
|
41
49
|
cancelLabel = 'Cancel',
|
|
42
50
|
variant = 'default',
|
|
51
|
+
confirmDisabled = false,
|
|
52
|
+
confirmDisabledReason,
|
|
43
53
|
children,
|
|
44
54
|
open,
|
|
45
55
|
onOpenChange,
|
|
@@ -51,6 +61,8 @@ function ConfirmDialog({
|
|
|
51
61
|
// re-render disables the button, so the in-flight flag lives in a ref too.
|
|
52
62
|
const pendingRef = useRef(false);
|
|
53
63
|
const actualOpen = isControlled ? open : internalOpen;
|
|
64
|
+
const reasonId = useId();
|
|
65
|
+
const showReason = confirmDisabled && !pending && Boolean(confirmDisabledReason);
|
|
54
66
|
|
|
55
67
|
const setOpen = (next: boolean) => {
|
|
56
68
|
if (!isControlled) setInternalOpen(next);
|
|
@@ -58,7 +70,7 @@ function ConfirmDialog({
|
|
|
58
70
|
};
|
|
59
71
|
|
|
60
72
|
const handleConfirm = async () => {
|
|
61
|
-
if (pendingRef.current) return;
|
|
73
|
+
if (pendingRef.current || confirmDisabled) return;
|
|
62
74
|
pendingRef.current = true;
|
|
63
75
|
try {
|
|
64
76
|
setPending(true);
|
|
@@ -87,13 +99,23 @@ function ConfirmDialog({
|
|
|
87
99
|
{description ? <AlertDialogDescription>{description}</AlertDialogDescription> : null}
|
|
88
100
|
</AlertDialogHeader>
|
|
89
101
|
<AlertDialogFooter>
|
|
102
|
+
{showReason ? (
|
|
103
|
+
<p
|
|
104
|
+
id={reasonId}
|
|
105
|
+
data-slot="confirm-dialog-disabled-reason"
|
|
106
|
+
className="text-muted-foreground self-center text-sm group-data-[size=sm]/alert-dialog-content:col-span-2 sm:mr-auto"
|
|
107
|
+
>
|
|
108
|
+
{confirmDisabledReason}
|
|
109
|
+
</p>
|
|
110
|
+
) : null}
|
|
90
111
|
<AlertDialogCancel disabled={pending}>{cancelLabel}</AlertDialogCancel>
|
|
91
112
|
{/* AlertDialogAction is a plain Button (not a Close), so closing stays
|
|
92
113
|
under our control — the promise decides when the dialog leaves. */}
|
|
93
114
|
<AlertDialogAction
|
|
94
115
|
variant={variant}
|
|
95
|
-
disabled={pending}
|
|
116
|
+
disabled={pending || confirmDisabled}
|
|
96
117
|
aria-busy={pending || undefined}
|
|
118
|
+
aria-describedby={showReason ? reasonId : undefined}
|
|
97
119
|
onClick={handleConfirm}
|
|
98
120
|
>
|
|
99
121
|
{pending ? <Spinner /> : null}
|
|
@@ -3,13 +3,17 @@
|
|
|
3
3
|
import { Button } from '@vendure-io/ui/components/atoms/button';
|
|
4
4
|
import { useCopyFeedback } from '@vendure-io/ui/components/molecules/copy-feedback-provider';
|
|
5
5
|
import { useCopy } from '@vendure-io/ui/hooks/use-copy';
|
|
6
|
+
import type { ClipboardSource } from '@vendure-io/ui/lib/clipboard';
|
|
6
7
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
7
8
|
import { CheckIcon, CopyIcon } from 'lucide-react';
|
|
8
9
|
import type * as React from 'react';
|
|
9
10
|
|
|
10
11
|
interface CopyButtonProps extends Omit<React.ComponentProps<typeof Button>, 'value' | 'children'> {
|
|
11
|
-
/**
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* The text written to the clipboard, or a callback that loads it when the
|
|
14
|
+
* button is clicked (for values the server returns only on request).
|
|
15
|
+
*/
|
|
16
|
+
value: ClipboardSource;
|
|
13
17
|
/** How long the check-mark feedback stays visible, in ms. @default 2000 */
|
|
14
18
|
timeout?: number;
|
|
15
19
|
/**
|
|
@@ -169,6 +169,23 @@ export interface DataTableProps<TData> {
|
|
|
169
169
|
|
|
170
170
|
isLoading?: boolean; // skeleton rows only while `rows` is empty; never blanks populated rows
|
|
171
171
|
skeletonRowCount?: number; // default 10
|
|
172
|
+
/**
|
|
173
|
+
* Per-column loading cells, keyed by column id, for cells that are not one
|
|
174
|
+
* text line tall (a title over a muted sub-line, an avatar, a button), so the
|
|
175
|
+
* loading rows keep the loaded row height and the table does not jump when
|
|
176
|
+
* data arrives. Stack `DataTableSkeletonLine`s for multi-line cells.
|
|
177
|
+
*
|
|
178
|
+
* Keys are TanStack column ids: the column's `id`, else its `accessorKey`
|
|
179
|
+
* with `.` replaced by `_` (`customer.name` → `customer_name`). Unknown keys
|
|
180
|
+
* warn in development.
|
|
181
|
+
*
|
|
182
|
+
* A missing or `undefined` entry renders the default: one
|
|
183
|
+
* `DataTableSkeletonLine`, as tall as one text line, so one-line columns
|
|
184
|
+
* (text, Money) need no entry. `null` renders an empty cell. The
|
|
185
|
+
* generated actions cell (key `actions`) defaults to an icon-button-sized
|
|
186
|
+
* block and can be overridden; the generated select cell is always empty.
|
|
187
|
+
*/
|
|
188
|
+
skeletonCells?: Record<string, React.ReactNode>;
|
|
172
189
|
|
|
173
190
|
// capability configs — omit → capability + its UI vanish
|
|
174
191
|
pagination?: DataTablePagination;
|