@dinachi/cli 0.12.0 → 1.1.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/CHANGELOG.md +131 -0
- package/dist/index.js +73 -7
- package/package.json +1 -1
- package/templates/accordion/accordion.tsx +70 -12
- package/templates/agent/agent.tsx +1865 -0
- package/templates/agent/index.ts +52 -0
- package/templates/alert-dialog/alert-dialog.tsx +59 -19
- package/templates/alert-dialog/index.ts +2 -0
- package/templates/animated-icon/animated-icon.tsx +1 -0
- package/templates/animated-list/animated-list.tsx +2 -1
- package/templates/animated-tabs/animated-tabs.tsx +69 -5
- package/templates/autocomplete/autocomplete.tsx +188 -21
- package/templates/avatar/avatar.tsx +3 -0
- package/templates/badge/badge.tsx +1 -0
- package/templates/button/button.tsx +1 -0
- package/templates/card/card.tsx +6 -1
- package/templates/carousel/carousel.tsx +109 -24
- package/templates/checkbox/checkbox.tsx +61 -4
- package/templates/checkbox-group/checkbox-group.tsx +83 -8
- package/templates/collapsible/collapsible.tsx +15 -4
- package/templates/combobox/combobox.tsx +312 -26
- package/templates/compare-slider/compare-slider.tsx +104 -28
- package/templates/compare-slider/index.ts +1 -1
- package/templates/context-menu/context-menu.tsx +93 -24
- package/templates/dialog/dialog.tsx +53 -14
- package/templates/drawer/drawer.tsx +36 -8
- package/templates/expandable-card/expandable-card.tsx +70 -43
- package/templates/field/field.tsx +7 -1
- package/templates/fieldset/fieldset.tsx +2 -0
- package/templates/form/form.tsx +1 -0
- package/templates/hold-to-confirm/hold-to-confirm.tsx +100 -16
- package/templates/hold-to-confirm/index.ts +1 -1
- package/templates/input/input.tsx +60 -1
- package/templates/label/label.tsx +1 -0
- package/templates/link/link.tsx +1 -0
- package/templates/load-transition/load-transition.tsx +1 -0
- package/templates/marquee/marquee.tsx +1 -0
- package/templates/menu/menu.tsx +45 -12
- package/templates/menubar/menubar.tsx +41 -11
- package/templates/meter/meter.tsx +5 -1
- package/templates/navigation-menu/navigation-menu.tsx +79 -24
- package/templates/number-field/index.ts +1 -0
- package/templates/number-field/number-field.tsx +77 -2
- package/templates/number-ticker/number-ticker.tsx +3 -0
- package/templates/otp-field/otp-field.tsx +61 -11
- package/templates/popover/popover.tsx +36 -7
- package/templates/preview-card/preview-card.tsx +27 -5
- package/templates/progress/progress.tsx +5 -1
- package/templates/progress-ring/progress-ring.tsx +1 -0
- package/templates/radio/radio.tsx +74 -6
- package/templates/scroll-area/scroll-area.tsx +14 -4
- package/templates/scroll-progress/scroll-progress.tsx +1 -0
- package/templates/scroll-reveal/scroll-reveal.tsx +1 -0
- package/templates/select/select.tsx +241 -12
- package/templates/separator/separator.tsx +1 -0
- package/templates/skeleton/skeleton.tsx +1 -0
- package/templates/slider/slider.tsx +84 -8
- package/templates/sortable/sortable.tsx +79 -9
- package/templates/stagger-list/stagger-list.tsx +2 -0
- package/templates/streaming-text/streaming-text.tsx +1 -0
- package/templates/swipeable-row/index.ts +1 -1
- package/templates/swipeable-row/swipeable-row.tsx +126 -41
- package/templates/switch/switch.tsx +43 -4
- package/templates/tabs/tabs.tsx +79 -10
- package/templates/text/text.tsx +1 -0
- package/templates/text-morph/text-morph.tsx +2 -0
- package/templates/text-shimmer/text-shimmer.tsx +1 -0
- package/templates/textarea/index.ts +1 -1
- package/templates/textarea/textarea.tsx +71 -4
- package/templates/toast/toast.tsx +13 -2
- package/templates/toggle/toggle.tsx +40 -7
- package/templates/toggle-group/toggle-group.tsx +98 -18
- package/templates/toolbar/toolbar.tsx +6 -0
- package/templates/tooltip/tooltip.tsx +9 -3
|
@@ -4,8 +4,73 @@ import * as React from "react"
|
|
|
4
4
|
import { NumberField as NumberFieldPrimitive } from "@base-ui/react/number-field"
|
|
5
5
|
import { Minus, Plus } from "lucide-react"
|
|
6
6
|
import { cn } from "@/lib/utils"
|
|
7
|
+
import { agentRound, changeAsAgent, createAgentChangeDetails, useAgentControl, useAgentState, useHasAgent, useMergedRef } from "@/components/ui/agent"
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
type NumberFieldProps = React.ComponentPropsWithoutRef<typeof NumberFieldPrimitive.Root>
|
|
10
|
+
|
|
11
|
+
const NumberFieldAgentContext = React.createContext<React.MutableRefObject<HTMLInputElement | null> | null>(null)
|
|
12
|
+
|
|
13
|
+
const clamp = (n: number, min = -Infinity, max = Infinity) => Math.min(max, Math.max(min, n))
|
|
14
|
+
|
|
15
|
+
function toNumber(value: unknown): number | string {
|
|
16
|
+
const n = typeof value === "number" ? value : Number(String(value ?? "").trim() || NaN)
|
|
17
|
+
return Number.isFinite(n) ? n : `"${String(value)}" is not a number.`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Base UI also takes "any", which has no size to step by, so the agent steps by 1.
|
|
21
|
+
const stepOf = ({ step }: NumberFieldProps) => (typeof step === "number" ? step : 1)
|
|
22
|
+
|
|
23
|
+
/** The agent's actions, each clamped to min and max the way Base UI clamps a person's. */
|
|
24
|
+
function numberActions(props: NumberFieldProps, value: number | null, set: (next: number) => string | undefined) {
|
|
25
|
+
const { min, max, readOnly } = props
|
|
26
|
+
const step = stepOf(props)
|
|
27
|
+
const to = (next: unknown, from = 0, scale = 1) => {
|
|
28
|
+
if (readOnly) return "The number field is read-only."
|
|
29
|
+
const n = toNumber(next)
|
|
30
|
+
return typeof n === "string" ? n : set(clamp(agentRound(from + n * scale, from, scale, n), min, max))
|
|
31
|
+
}
|
|
32
|
+
const from = value ?? min ?? 0
|
|
33
|
+
return {
|
|
34
|
+
setValue: (next: unknown) => to(next),
|
|
35
|
+
increment: (steps: unknown = 1) => to(steps, from, step),
|
|
36
|
+
decrement: (steps: unknown = 1) => to(steps, from, -step),
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Base UI's root, holding its own value so an agent can set it the way a parent would.
|
|
42
|
+
* `onValueChange` sees the agent's changes first and can cancel them.
|
|
43
|
+
*/
|
|
44
|
+
const NumberField = React.forwardRef<HTMLDivElement, NumberFieldProps>(
|
|
45
|
+
({ value: valueProp, defaultValue = null, onValueChange, ...props }, ref) => {
|
|
46
|
+
type Details = NumberFieldPrimitive.Root.ChangeEventDetails
|
|
47
|
+
const [value, changeValue] = useAgentState<number | null, Details>(valueProp, defaultValue, onValueChange)
|
|
48
|
+
const input = React.useRef<HTMLInputElement | null>(null)
|
|
49
|
+
|
|
50
|
+
useAgentControl(() => ({
|
|
51
|
+
kind: "number" as const,
|
|
52
|
+
element: input.current,
|
|
53
|
+
value: value ?? undefined,
|
|
54
|
+
min: props.min,
|
|
55
|
+
max: props.max,
|
|
56
|
+
step: stepOf(props),
|
|
57
|
+
disabled: props.disabled,
|
|
58
|
+
// An agent's change is whole at once, so it is committed too, as a person's is on blur.
|
|
59
|
+
actions: numberActions(
|
|
60
|
+
props,
|
|
61
|
+
value,
|
|
62
|
+
(next) => changeAsAgent(changeValue, next) ?? void props.onValueCommitted?.(next, createAgentChangeDetails("none"))
|
|
63
|
+
),
|
|
64
|
+
}))
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<NumberFieldAgentContext.Provider value={useHasAgent() ? input : null}>
|
|
68
|
+
<NumberFieldPrimitive.Root ref={ref} data-slot="number-field" {...props} value={value} onValueChange={changeValue} />
|
|
69
|
+
</NumberFieldAgentContext.Provider>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
NumberField.displayName = "NumberField"
|
|
9
74
|
|
|
10
75
|
const NumberFieldGroup = React.forwardRef<
|
|
11
76
|
React.ComponentRef<typeof NumberFieldPrimitive.Group>,
|
|
@@ -13,6 +78,7 @@ const NumberFieldGroup = React.forwardRef<
|
|
|
13
78
|
>(({ className, ...props }, ref) => (
|
|
14
79
|
<NumberFieldPrimitive.Group
|
|
15
80
|
ref={ref}
|
|
81
|
+
data-slot="number-field-group"
|
|
16
82
|
className={cn(
|
|
17
83
|
"inline-flex h-10 w-full items-stretch overflow-hidden rounded-md border border-input bg-background",
|
|
18
84
|
className
|
|
@@ -27,7 +93,8 @@ const NumberFieldInput = React.forwardRef<
|
|
|
27
93
|
React.ComponentPropsWithoutRef<typeof NumberFieldPrimitive.Input>
|
|
28
94
|
>(({ className, ...props }, ref) => (
|
|
29
95
|
<NumberFieldPrimitive.Input
|
|
30
|
-
ref={ref}
|
|
96
|
+
ref={useMergedRef(ref, React.useContext(NumberFieldAgentContext))}
|
|
97
|
+
data-slot="number-field-input"
|
|
31
98
|
className={cn(
|
|
32
99
|
"w-full bg-transparent px-3 text-sm outline-none placeholder:text-muted-foreground",
|
|
33
100
|
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
@@ -44,6 +111,8 @@ const NumberFieldIncrement = React.forwardRef<
|
|
|
44
111
|
>(({ className, children, ...props }, ref) => (
|
|
45
112
|
<NumberFieldPrimitive.Increment
|
|
46
113
|
ref={ref}
|
|
114
|
+
data-slot="number-field-increment"
|
|
115
|
+
data-agent-part={useHasAgent() ? "" : undefined}
|
|
47
116
|
className={cn(
|
|
48
117
|
"inline-flex h-full items-center justify-center border-l border-input px-3 text-muted-foreground transition-colors",
|
|
49
118
|
"hover:bg-accent hover:text-accent-foreground",
|
|
@@ -64,6 +133,8 @@ const NumberFieldDecrement = React.forwardRef<
|
|
|
64
133
|
>(({ className, children, ...props }, ref) => (
|
|
65
134
|
<NumberFieldPrimitive.Decrement
|
|
66
135
|
ref={ref}
|
|
136
|
+
data-slot="number-field-decrement"
|
|
137
|
+
data-agent-part={useHasAgent() ? "" : undefined}
|
|
67
138
|
className={cn(
|
|
68
139
|
"inline-flex h-full items-center justify-center border-r border-input px-3 text-muted-foreground transition-colors",
|
|
69
140
|
"hover:bg-accent hover:text-accent-foreground",
|
|
@@ -84,6 +155,7 @@ const NumberFieldScrubArea = React.forwardRef<
|
|
|
84
155
|
>(({ className, ...props }, ref) => (
|
|
85
156
|
<NumberFieldPrimitive.ScrubArea
|
|
86
157
|
ref={ref}
|
|
158
|
+
data-slot="number-field-scrub-area"
|
|
87
159
|
className={cn("cursor-ew-resize", className)}
|
|
88
160
|
{...props}
|
|
89
161
|
/>
|
|
@@ -96,12 +168,15 @@ const NumberFieldScrubAreaCursor = React.forwardRef<
|
|
|
96
168
|
>(({ className, ...props }, ref) => (
|
|
97
169
|
<NumberFieldPrimitive.ScrubAreaCursor
|
|
98
170
|
ref={ref}
|
|
171
|
+
data-slot="number-field-scrub-area-cursor"
|
|
99
172
|
className={cn("text-muted-foreground", className)}
|
|
100
173
|
{...props}
|
|
101
174
|
/>
|
|
102
175
|
))
|
|
103
176
|
NumberFieldScrubAreaCursor.displayName = "NumberFieldScrubAreaCursor"
|
|
104
177
|
|
|
178
|
+
export type { NumberFieldProps }
|
|
179
|
+
|
|
105
180
|
export {
|
|
106
181
|
NumberField,
|
|
107
182
|
NumberFieldGroup,
|
|
@@ -396,6 +396,7 @@ const NumberTicker = React.forwardRef<HTMLSpanElement, NumberTickerProps>(
|
|
|
396
396
|
<span
|
|
397
397
|
ref={innerRef}
|
|
398
398
|
className={cn("inline-block tabular-nums tracking-tight", className)}
|
|
399
|
+
data-slot="number-ticker"
|
|
399
400
|
{...props}
|
|
400
401
|
>
|
|
401
402
|
{formatted}
|
|
@@ -408,6 +409,7 @@ const NumberTicker = React.forwardRef<HTMLSpanElement, NumberTickerProps>(
|
|
|
408
409
|
<span
|
|
409
410
|
ref={innerRef}
|
|
410
411
|
className={cn("inline-block tabular-nums tracking-tight", className)}
|
|
412
|
+
data-slot="number-ticker"
|
|
411
413
|
{...props}
|
|
412
414
|
>
|
|
413
415
|
<CounterValue
|
|
@@ -430,6 +432,7 @@ const NumberTicker = React.forwardRef<HTMLSpanElement, NumberTickerProps>(
|
|
|
430
432
|
"inline-flex items-baseline tabular-nums tracking-tight",
|
|
431
433
|
className
|
|
432
434
|
)}
|
|
435
|
+
data-slot="number-ticker"
|
|
433
436
|
{...props}
|
|
434
437
|
>
|
|
435
438
|
{cells.map((cell, i) => {
|
|
@@ -3,21 +3,66 @@
|
|
|
3
3
|
import * as React from "react"
|
|
4
4
|
import { OTPField as OTPFieldPrimitive } from "@base-ui/react/otp-field"
|
|
5
5
|
import { cn } from "@/lib/utils"
|
|
6
|
+
import { changeAsAgent, useAgentControl, useAgentState, useHasAgent, useMergedRef } from "@/components/ui/agent"
|
|
6
7
|
|
|
8
|
+
const CODE_PATTERNS: Record<string, RegExp> = {
|
|
9
|
+
numeric: /^\d*$/,
|
|
10
|
+
alpha: /^[a-z]*$/i,
|
|
11
|
+
alphanumeric: /^[a-z\d]*$/i,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function checkCode(code: string, length: number, validationType = "numeric") {
|
|
15
|
+
if (code.length > length) return `The code is ${length} characters.`
|
|
16
|
+
if (!(CODE_PATTERNS[validationType]?.test(code) ?? true)) return `The code takes ${validationType} characters only.`
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Base UI's root, holding its own value so an agent can fill the code the way a parent
|
|
21
|
+
* would. `onValueChange` sees the agent's changes first and can cancel them.
|
|
22
|
+
*/
|
|
7
23
|
const OTPField = React.forwardRef<
|
|
8
24
|
React.ComponentRef<typeof OTPFieldPrimitive.Root>,
|
|
9
25
|
React.ComponentPropsWithoutRef<typeof OTPFieldPrimitive.Root>
|
|
10
|
-
>(({ className, ...props }, ref) =>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
))
|
|
26
|
+
>(({ className, value: valueProp, defaultValue = "", onValueChange, ...props }, ref) => {
|
|
27
|
+
type Details = OTPFieldPrimitive.Root.ChangeEventDetails
|
|
28
|
+
const [value, changeValue] = useAgentState<string, Details>(valueProp, defaultValue, onValueChange)
|
|
29
|
+
const element = React.useRef<HTMLDivElement>(null)
|
|
30
|
+
const mergedRef = useMergedRef(ref, element)
|
|
31
|
+
|
|
32
|
+
useAgentControl(() => {
|
|
33
|
+
const setValue = (next: unknown) => {
|
|
34
|
+
if (props.readOnly) return "The code is read-only."
|
|
35
|
+
const code = String(next ?? "").replace(/\s+/g, "")
|
|
36
|
+
return checkCode(code, props.length, props.validationType) ?? changeAsAgent(changeValue, code)
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
kind: "input" as const,
|
|
40
|
+
element: element.current,
|
|
41
|
+
value,
|
|
42
|
+
disabled: props.disabled,
|
|
43
|
+
length: props.length,
|
|
44
|
+
// A one-time code is a credential, like the autocomplete token Base UI gives it,
|
|
45
|
+
// and a masked one is hidden from the person too.
|
|
46
|
+
secret: Boolean(props.mask) || (props.autoComplete ?? "one-time-code") === "one-time-code",
|
|
47
|
+
actions: { setValue, clear: () => setValue("") },
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<OTPFieldPrimitive.Root
|
|
53
|
+
ref={mergedRef}
|
|
54
|
+
data-slot="otp-field"
|
|
55
|
+
className={cn(
|
|
56
|
+
"flex items-center gap-2",
|
|
57
|
+
"data-[disabled]:opacity-50",
|
|
58
|
+
className
|
|
59
|
+
)}
|
|
60
|
+
{...props}
|
|
61
|
+
value={value}
|
|
62
|
+
onValueChange={changeValue}
|
|
63
|
+
/>
|
|
64
|
+
)
|
|
65
|
+
})
|
|
21
66
|
OTPField.displayName = "OTPField"
|
|
22
67
|
|
|
23
68
|
const OTPFieldGroup = React.forwardRef<
|
|
@@ -26,6 +71,7 @@ const OTPFieldGroup = React.forwardRef<
|
|
|
26
71
|
>(({ className, ...props }, ref) => (
|
|
27
72
|
<div
|
|
28
73
|
ref={ref}
|
|
74
|
+
data-slot="otp-field-group"
|
|
29
75
|
className={cn("flex items-center", className)}
|
|
30
76
|
{...props}
|
|
31
77
|
/>
|
|
@@ -38,6 +84,9 @@ const OTPFieldInput = React.forwardRef<
|
|
|
38
84
|
>(({ className, ...props }, ref) => (
|
|
39
85
|
<OTPFieldPrimitive.Input
|
|
40
86
|
ref={ref}
|
|
87
|
+
data-slot="otp-field-input"
|
|
88
|
+
// The root reports the whole code, so a slot is part of it rather than a control.
|
|
89
|
+
data-agent-part={useHasAgent() ? "" : undefined}
|
|
41
90
|
className={cn(
|
|
42
91
|
"relative h-10 w-10 border-y border-r border-input bg-background text-center text-sm shadow-sm outline-none",
|
|
43
92
|
"transition-[color,background-color,border-color,box-shadow] duration-[var(--motion-duration-fast,150ms)]",
|
|
@@ -58,6 +107,7 @@ const OTPFieldSeparator = React.forwardRef<
|
|
|
58
107
|
>(({ className, ...props }, ref) => (
|
|
59
108
|
<OTPFieldPrimitive.Separator
|
|
60
109
|
ref={ref}
|
|
110
|
+
data-slot="otp-field-separator"
|
|
61
111
|
role="separator"
|
|
62
112
|
className={cn("text-muted-foreground", className)}
|
|
63
113
|
{...props}
|
|
@@ -3,11 +3,33 @@
|
|
|
3
3
|
import * as React from "react"
|
|
4
4
|
import { Popover as PopoverPrimitive } from "@base-ui/react/popover"
|
|
5
5
|
import { cn } from "@/lib/utils"
|
|
6
|
+
import { type AgentOpenParts, useAgentOpen, useHasAgent, useMergedRef } from "@/components/ui/agent"
|
|
7
|
+
|
|
8
|
+
const PopoverAgentContext = React.createContext<AgentOpenParts | null>(null)
|
|
9
|
+
|
|
10
|
+
/** Base UI's root, holding its own open state so an agent can open and close it. */
|
|
11
|
+
function Popover<Payload>({ open, defaultOpen, onOpenChange, ...props }: PopoverPrimitive.Root.Props<Payload>) {
|
|
12
|
+
const [state, change, parts] = useAgentOpen("popover", open, defaultOpen, onOpenChange)
|
|
13
|
+
return (
|
|
14
|
+
<PopoverAgentContext.Provider value={useHasAgent() ? parts : null}>
|
|
15
|
+
<PopoverPrimitive.Root<Payload> {...props} open={state} onOpenChange={change} />
|
|
16
|
+
</PopoverAgentContext.Provider>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function PopoverTrigger<Payload>({ ref, ...props }: PopoverPrimitive.Trigger.Props<Payload> & React.RefAttributes<HTMLElement>) {
|
|
21
|
+
const parts = React.useContext(PopoverAgentContext)
|
|
22
|
+
return <PopoverPrimitive.Trigger<Payload> ref={useMergedRef(ref, parts?.trigger)} data-slot="popover-trigger" {...props} />
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function PopoverPortal(props: React.ComponentProps<typeof PopoverPrimitive.Portal>) {
|
|
26
|
+
return <PopoverPrimitive.Portal data-slot="popover-portal" {...props} />
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function PopoverClose(props: React.ComponentProps<typeof PopoverPrimitive.Close>) {
|
|
30
|
+
return <PopoverPrimitive.Close data-slot="popover-close" {...props} />
|
|
31
|
+
}
|
|
6
32
|
|
|
7
|
-
const Popover = PopoverPrimitive.Root
|
|
8
|
-
const PopoverTrigger = PopoverPrimitive.Trigger
|
|
9
|
-
const PopoverPortal = PopoverPrimitive.Portal
|
|
10
|
-
const PopoverClose = PopoverPrimitive.Close
|
|
11
33
|
const createPopoverHandle = PopoverPrimitive.createHandle
|
|
12
34
|
|
|
13
35
|
const PopoverPositioner = React.forwardRef<
|
|
@@ -18,6 +40,7 @@ const PopoverPositioner = React.forwardRef<
|
|
|
18
40
|
ref={ref}
|
|
19
41
|
sideOffset={sideOffset}
|
|
20
42
|
className={cn("z-50", className)}
|
|
43
|
+
data-slot="popover-positioner"
|
|
21
44
|
{...props}
|
|
22
45
|
/>
|
|
23
46
|
))
|
|
@@ -28,7 +51,7 @@ const PopoverPopup = React.forwardRef<
|
|
|
28
51
|
React.ComponentProps<typeof PopoverPrimitive.Popup>
|
|
29
52
|
>(({ className, ...props }, ref) => (
|
|
30
53
|
<PopoverPrimitive.Popup
|
|
31
|
-
ref={ref}
|
|
54
|
+
ref={useMergedRef(ref, React.useContext(PopoverAgentContext)?.popup)}
|
|
32
55
|
className={cn(
|
|
33
56
|
"rounded-lg border bg-popover px-6 py-4 text-popover-foreground shadow-lg outline-none",
|
|
34
57
|
"origin-[var(--transform-origin)]",
|
|
@@ -38,6 +61,7 @@ const PopoverPopup = React.forwardRef<
|
|
|
38
61
|
"motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[ending-style]:scale-100",
|
|
39
62
|
className
|
|
40
63
|
)}
|
|
64
|
+
data-slot="popover-popup"
|
|
41
65
|
{...props}
|
|
42
66
|
/>
|
|
43
67
|
))
|
|
@@ -77,13 +101,13 @@ const PopoverContent = React.forwardRef<
|
|
|
77
101
|
collisionPadding={collisionPadding}
|
|
78
102
|
sticky={sticky}
|
|
79
103
|
>
|
|
80
|
-
<PopoverPopup ref={ref} className={className} {...props} />
|
|
104
|
+
<PopoverPopup ref={ref} className={className} data-slot="popover-content" {...props} />
|
|
81
105
|
</PopoverPositioner>
|
|
82
106
|
)
|
|
83
107
|
|
|
84
108
|
if (!portal) return content
|
|
85
109
|
|
|
86
|
-
return <
|
|
110
|
+
return <PopoverPortal>{content}</PopoverPortal>
|
|
87
111
|
})
|
|
88
112
|
PopoverContent.displayName = "PopoverContent"
|
|
89
113
|
|
|
@@ -100,6 +124,7 @@ const PopoverArrow = React.forwardRef<
|
|
|
100
124
|
"data-[side=top]:bottom-[-8px] data-[side=top]:rotate-180",
|
|
101
125
|
className
|
|
102
126
|
)}
|
|
127
|
+
data-slot="popover-arrow"
|
|
103
128
|
{...props}
|
|
104
129
|
>
|
|
105
130
|
{children || (
|
|
@@ -129,6 +154,7 @@ const PopoverViewport = React.forwardRef<
|
|
|
129
154
|
<PopoverPrimitive.Viewport
|
|
130
155
|
ref={ref}
|
|
131
156
|
className={cn("flex flex-col gap-2", className)}
|
|
157
|
+
data-slot="popover-viewport"
|
|
132
158
|
{...props}
|
|
133
159
|
/>
|
|
134
160
|
))
|
|
@@ -141,6 +167,7 @@ const PopoverTitle = React.forwardRef<
|
|
|
141
167
|
<PopoverPrimitive.Title
|
|
142
168
|
ref={ref}
|
|
143
169
|
className={cn("mb-2 text-base font-medium leading-none", className)}
|
|
170
|
+
data-slot="popover-title"
|
|
144
171
|
{...props}
|
|
145
172
|
/>
|
|
146
173
|
))
|
|
@@ -153,6 +180,7 @@ const PopoverDescription = React.forwardRef<
|
|
|
153
180
|
<PopoverPrimitive.Description
|
|
154
181
|
ref={ref}
|
|
155
182
|
className={cn("text-base text-muted-foreground", className)}
|
|
183
|
+
data-slot="popover-description"
|
|
156
184
|
{...props}
|
|
157
185
|
/>
|
|
158
186
|
))
|
|
@@ -170,6 +198,7 @@ const PopoverBackdrop = React.forwardRef<
|
|
|
170
198
|
"transition-opacity duration-[var(--motion-duration-fast,150ms)] ease-[var(--motion-ease-out,cubic-bezier(0.23,1,0.32,1))]",
|
|
171
199
|
className
|
|
172
200
|
)}
|
|
201
|
+
data-slot="popover-backdrop"
|
|
173
202
|
{...props}
|
|
174
203
|
/>
|
|
175
204
|
))
|
|
@@ -3,15 +3,29 @@
|
|
|
3
3
|
import * as React from "react"
|
|
4
4
|
import { PreviewCard as BasePreviewCard } from "@base-ui/react/preview-card"
|
|
5
5
|
import { cn } from "@/lib/utils"
|
|
6
|
+
import { type AgentOpenParts, useAgentOpen, useHasAgent, useMergedRef } from "@/components/ui/agent"
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
+
const PreviewCardAgentContext = React.createContext<AgentOpenParts | null>(null)
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Base UI's root, holding its own open state so an agent can open and close it. The agent
|
|
12
|
+
* sees the trigger either way: the card holds content to read, not a control.
|
|
13
|
+
*/
|
|
14
|
+
function PreviewCard<Payload>({ open, defaultOpen, onOpenChange, ...props }: BasePreviewCard.Root.Props<Payload>) {
|
|
15
|
+
const [state, change, parts] = useAgentOpen("popover", open, defaultOpen, onOpenChange)
|
|
16
|
+
return (
|
|
17
|
+
<PreviewCardAgentContext.Provider value={useHasAgent() ? parts : null}>
|
|
18
|
+
<BasePreviewCard.Root<Payload> {...props} open={state} onOpenChange={change} />
|
|
19
|
+
</PreviewCardAgentContext.Provider>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
8
22
|
|
|
9
23
|
const PreviewCardTrigger = React.forwardRef<
|
|
10
24
|
HTMLAnchorElement,
|
|
11
25
|
React.ComponentProps<typeof BasePreviewCard.Trigger>
|
|
12
26
|
>(({ className, ...props }, ref) => (
|
|
13
27
|
<BasePreviewCard.Trigger
|
|
14
|
-
ref={ref}
|
|
28
|
+
ref={useMergedRef(ref, React.useContext(PreviewCardAgentContext)?.trigger)}
|
|
15
29
|
className={cn(
|
|
16
30
|
"text-blue-600 no-underline decoration-blue-600/60 decoration-1 underline-offset-2 outline-none",
|
|
17
31
|
"hover:underline focus-visible:rounded-sm focus-visible:no-underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-blue-600",
|
|
@@ -19,12 +33,15 @@ const PreviewCardTrigger = React.forwardRef<
|
|
|
19
33
|
"dark:text-blue-400 dark:decoration-blue-400/60 dark:focus-visible:outline-blue-400",
|
|
20
34
|
className
|
|
21
35
|
)}
|
|
36
|
+
data-slot="preview-card-trigger"
|
|
22
37
|
{...props}
|
|
23
38
|
/>
|
|
24
39
|
))
|
|
25
40
|
PreviewCardTrigger.displayName = "PreviewCardTrigger"
|
|
26
41
|
|
|
27
|
-
|
|
42
|
+
function PreviewCardPortal(props: React.ComponentProps<typeof BasePreviewCard.Portal>) {
|
|
43
|
+
return <BasePreviewCard.Portal data-slot="preview-card-portal" {...props} />
|
|
44
|
+
}
|
|
28
45
|
|
|
29
46
|
const PreviewCardBackdrop = React.forwardRef<
|
|
30
47
|
React.ComponentRef<typeof BasePreviewCard.Backdrop>,
|
|
@@ -37,6 +54,7 @@ const PreviewCardBackdrop = React.forwardRef<
|
|
|
37
54
|
"data-[starting-style]:opacity-0 data-[ending-style]:opacity-0",
|
|
38
55
|
className
|
|
39
56
|
)}
|
|
57
|
+
data-slot="preview-card-backdrop"
|
|
40
58
|
{...props}
|
|
41
59
|
/>
|
|
42
60
|
))
|
|
@@ -50,6 +68,7 @@ const PreviewCardPositioner = React.forwardRef<
|
|
|
50
68
|
ref={ref}
|
|
51
69
|
sideOffset={sideOffset}
|
|
52
70
|
className={cn("z-50", className)}
|
|
71
|
+
data-slot="preview-card-positioner"
|
|
53
72
|
{...props}
|
|
54
73
|
/>
|
|
55
74
|
))
|
|
@@ -71,6 +90,7 @@ const PreviewCardPopup = React.forwardRef<
|
|
|
71
90
|
"backdrop-blur-sm dark:shadow-none dark:-outline-offset-1",
|
|
72
91
|
className
|
|
73
92
|
)}
|
|
93
|
+
data-slot="preview-card-popup"
|
|
74
94
|
{...props}
|
|
75
95
|
/>
|
|
76
96
|
))
|
|
@@ -88,6 +108,7 @@ const PreviewCardArrow = React.forwardRef<
|
|
|
88
108
|
"data-[side=top]:bottom-[-8px] data-[side=top]:rotate-180",
|
|
89
109
|
className
|
|
90
110
|
)}
|
|
111
|
+
data-slot="preview-card-arrow"
|
|
91
112
|
{...props}
|
|
92
113
|
>
|
|
93
114
|
{children || <PreviewCardArrowSvg />}
|
|
@@ -101,7 +122,7 @@ const PreviewCardContent = React.forwardRef<
|
|
|
101
122
|
>(({ className, children, ...props }, ref) => (
|
|
102
123
|
<PreviewCardPortal>
|
|
103
124
|
<PreviewCardPositioner>
|
|
104
|
-
<PreviewCardPopup ref={ref} className={className} {...props}>
|
|
125
|
+
<PreviewCardPopup ref={ref} className={className} data-slot="preview-card-content" {...props}>
|
|
105
126
|
<PreviewCardArrow />
|
|
106
127
|
{children}
|
|
107
128
|
</PreviewCardPopup>
|
|
@@ -117,6 +138,7 @@ const PreviewCardViewport = React.forwardRef<
|
|
|
117
138
|
<BasePreviewCard.Viewport
|
|
118
139
|
ref={ref}
|
|
119
140
|
className={cn("flex flex-col gap-3", className)}
|
|
141
|
+
data-slot="preview-card-viewport"
|
|
120
142
|
{...props}
|
|
121
143
|
/>
|
|
122
144
|
))
|
|
@@ -126,7 +148,7 @@ const createPreviewCardHandle = BasePreviewCard.createHandle
|
|
|
126
148
|
|
|
127
149
|
function PreviewCardArrowSvg(props: React.ComponentProps<'svg'>) {
|
|
128
150
|
return (
|
|
129
|
-
<svg width="20" height="10" viewBox="0 0 20 10" fill="none" {...props}>
|
|
151
|
+
<svg width="20" height="10" viewBox="0 0 20 10" fill="none" data-slot="preview-card-arrow-svg" {...props}>
|
|
130
152
|
<path
|
|
131
153
|
d="M9.66437 2.60207L4.80758 6.97318C4.07308 7.63423 3.11989 8 2.13172 8H0V10H20V8H18.5349C17.5468 8 16.5936 7.63423 15.8591 6.97318L11.0023 2.60207C10.622 2.2598 10.0447 2.25979 9.66437 2.60207Z"
|
|
132
154
|
className="fill-secondary"
|
|
@@ -8,7 +8,7 @@ const Progress = React.forwardRef<
|
|
|
8
8
|
React.ComponentRef<typeof ProgressPrimitive.Root>,
|
|
9
9
|
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>
|
|
10
10
|
>(({ className, ...props }, ref) => (
|
|
11
|
-
<ProgressPrimitive.Root ref={ref} className={cn("grid gap-2", className)} {...props} />
|
|
11
|
+
<ProgressPrimitive.Root data-slot="progress" ref={ref} className={cn("grid gap-2", className)} {...props} />
|
|
12
12
|
))
|
|
13
13
|
Progress.displayName = "Progress"
|
|
14
14
|
|
|
@@ -17,6 +17,7 @@ const ProgressTrack = React.forwardRef<
|
|
|
17
17
|
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Track>
|
|
18
18
|
>(({ className, ...props }, ref) => (
|
|
19
19
|
<ProgressPrimitive.Track
|
|
20
|
+
data-slot="progress-track"
|
|
20
21
|
ref={ref}
|
|
21
22
|
className={cn("relative h-2 w-full overflow-hidden rounded-full bg-secondary", className)}
|
|
22
23
|
{...props}
|
|
@@ -29,6 +30,7 @@ const ProgressIndicator = React.forwardRef<
|
|
|
29
30
|
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Indicator>
|
|
30
31
|
>(({ className, ...props }, ref) => (
|
|
31
32
|
<ProgressPrimitive.Indicator
|
|
33
|
+
data-slot="progress-indicator"
|
|
32
34
|
ref={ref}
|
|
33
35
|
className={cn("h-full rounded-full bg-primary transition-[width] duration-[var(--motion-duration-base,200ms)] ease-[var(--motion-ease-out,cubic-bezier(0.23,1,0.32,1))] motion-reduce:transition-none", className)}
|
|
34
36
|
{...props}
|
|
@@ -41,6 +43,7 @@ const ProgressLabel = React.forwardRef<
|
|
|
41
43
|
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Label>
|
|
42
44
|
>(({ className, ...props }, ref) => (
|
|
43
45
|
<ProgressPrimitive.Label
|
|
46
|
+
data-slot="progress-label"
|
|
44
47
|
ref={ref}
|
|
45
48
|
className={cn("text-sm font-medium leading-none", className)}
|
|
46
49
|
{...props}
|
|
@@ -53,6 +56,7 @@ const ProgressValue = React.forwardRef<
|
|
|
53
56
|
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Value>
|
|
54
57
|
>(({ className, ...props }, ref) => (
|
|
55
58
|
<ProgressPrimitive.Value
|
|
59
|
+
data-slot="progress-value"
|
|
56
60
|
ref={ref}
|
|
57
61
|
className={cn("text-xs text-muted-foreground", className)}
|
|
58
62
|
{...props}
|
|
@@ -4,13 +4,72 @@ import * as React from "react"
|
|
|
4
4
|
import { Radio as RadioPrimitive } from "@base-ui/react/radio"
|
|
5
5
|
import { RadioGroup as RadioGroupPrimitive } from "@base-ui/react/radio-group"
|
|
6
6
|
import { cn } from "@/lib/utils"
|
|
7
|
+
import {
|
|
8
|
+
agentChoicesOf,
|
|
9
|
+
changeAsAgent,
|
|
10
|
+
matchAgentChoice,
|
|
11
|
+
sameAgentValue,
|
|
12
|
+
useAgentControl,
|
|
13
|
+
useAgentItem,
|
|
14
|
+
useAgentState,
|
|
15
|
+
useHasAgent,
|
|
16
|
+
useMergedRef,
|
|
17
|
+
type AgentItems,
|
|
18
|
+
} from "@/components/ui/agent"
|
|
7
19
|
|
|
20
|
+
type RadioItems = AgentItems
|
|
21
|
+
|
|
22
|
+
const RadioAgentContext = React.createContext<RadioItems | null>(null)
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Base UI's group, holding its own value so an agent can choose a radio the way a parent
|
|
26
|
+
* would. Controlled use is unchanged, and `onValueChange` sees the agent's choice first
|
|
27
|
+
* and can cancel it.
|
|
28
|
+
*/
|
|
8
29
|
const RadioGroup = React.forwardRef<
|
|
9
30
|
React.ComponentRef<typeof RadioGroupPrimitive>,
|
|
10
31
|
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive>
|
|
11
|
-
>(({ className, ...props }, ref) =>
|
|
12
|
-
|
|
13
|
-
|
|
32
|
+
>(({ className, value: valueProp, defaultValue, onValueChange, ...props }, ref) => {
|
|
33
|
+
const [value, change] = useAgentState<unknown, RadioGroupPrimitive.ChangeEventDetails>(
|
|
34
|
+
valueProp,
|
|
35
|
+
defaultValue ?? null,
|
|
36
|
+
onValueChange
|
|
37
|
+
)
|
|
38
|
+
const element = React.useRef<HTMLDivElement | null>(null)
|
|
39
|
+
const mergedRef = useMergedRef(ref, element)
|
|
40
|
+
const [items] = React.useState<RadioItems>(() => new Map())
|
|
41
|
+
|
|
42
|
+
const choose = (wanted: unknown) => {
|
|
43
|
+
if (props.readOnly) return "The radio group is read-only."
|
|
44
|
+
const match = matchAgentChoice(agentChoicesOf(items), wanted)
|
|
45
|
+
return typeof match === "string" ? match : changeAsAgent(change, match.value)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
useAgentControl(() => {
|
|
49
|
+
const choices = agentChoicesOf(items)
|
|
50
|
+
return {
|
|
51
|
+
kind: "radio-group",
|
|
52
|
+
element: choices.length ? element.current : null,
|
|
53
|
+
value: choices.find((c) => sameAgentValue(c.value, value))?.label ?? "",
|
|
54
|
+
items: choices.map((c) => c.label),
|
|
55
|
+
disabled: props.disabled,
|
|
56
|
+
actions: { select: choose },
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<RadioAgentContext.Provider value={useHasAgent() ? items : null}>
|
|
62
|
+
<RadioGroupPrimitive
|
|
63
|
+
ref={mergedRef}
|
|
64
|
+
data-slot="radio-group"
|
|
65
|
+
className={cn("grid gap-2", className)}
|
|
66
|
+
{...props}
|
|
67
|
+
value={value}
|
|
68
|
+
onValueChange={change}
|
|
69
|
+
/>
|
|
70
|
+
</RadioAgentContext.Provider>
|
|
71
|
+
)
|
|
72
|
+
})
|
|
14
73
|
RadioGroup.displayName = "RadioGroup"
|
|
15
74
|
|
|
16
75
|
const RadioIndicator = React.forwardRef<
|
|
@@ -19,6 +78,7 @@ const RadioIndicator = React.forwardRef<
|
|
|
19
78
|
>(({ className, ...props }, ref) => (
|
|
20
79
|
<RadioPrimitive.Indicator
|
|
21
80
|
ref={ref}
|
|
81
|
+
data-slot="radio-indicator"
|
|
22
82
|
className={cn(
|
|
23
83
|
"flex items-center justify-center",
|
|
24
84
|
"after:h-2.5 after:w-2.5 after:rounded-full after:bg-current",
|
|
@@ -32,10 +92,17 @@ RadioIndicator.displayName = "RadioIndicator"
|
|
|
32
92
|
const Radio = React.forwardRef<
|
|
33
93
|
React.ComponentRef<typeof RadioPrimitive.Root>,
|
|
34
94
|
React.ComponentPropsWithoutRef<typeof RadioPrimitive.Root>
|
|
35
|
-
>(({ className, ...props }, ref) =>
|
|
95
|
+
>(({ className, ...props }, ref) => {
|
|
96
|
+
const items = React.useContext(RadioAgentContext)
|
|
97
|
+
const element = React.useRef<React.ComponentRef<typeof RadioPrimitive.Root> | null>(null)
|
|
98
|
+
const mergedRef = useMergedRef(ref, element)
|
|
99
|
+
useAgentItem(items, element, props.value)
|
|
100
|
+
|
|
101
|
+
return (
|
|
36
102
|
<span className="relative inline-flex [&>input]:!absolute">
|
|
37
103
|
<RadioPrimitive.Root
|
|
38
|
-
ref={
|
|
104
|
+
ref={mergedRef}
|
|
105
|
+
data-slot="radio"
|
|
39
106
|
className={cn(
|
|
40
107
|
"flex items-center justify-center aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background",
|
|
41
108
|
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
|
|
@@ -48,7 +115,8 @@ const Radio = React.forwardRef<
|
|
|
48
115
|
<RadioIndicator />
|
|
49
116
|
</RadioPrimitive.Root>
|
|
50
117
|
</span>
|
|
51
|
-
)
|
|
118
|
+
)
|
|
119
|
+
})
|
|
52
120
|
Radio.displayName = "Radio"
|
|
53
121
|
|
|
54
122
|
export { Radio, RadioGroup, RadioIndicator }
|