@timeax/form-palette 0.0.1
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/.scaffold-cache.json +537 -0
- package/package.json +42 -0
- package/src/.scaffold-cache.json +544 -0
- package/src/adapters/axios.ts +117 -0
- package/src/adapters/index.ts +91 -0
- package/src/adapters/inertia.ts +187 -0
- package/src/core/adapter-registry.ts +87 -0
- package/src/core/bound/bind-host.ts +14 -0
- package/src/core/bound/observe-bound-field.ts +172 -0
- package/src/core/bound/wait-for-bound-field.ts +57 -0
- package/src/core/context.ts +23 -0
- package/src/core/core-provider.tsx +818 -0
- package/src/core/core-root.tsx +72 -0
- package/src/core/core-shell.tsx +44 -0
- package/src/core/errors/error-strip.tsx +71 -0
- package/src/core/errors/index.ts +2 -0
- package/src/core/errors/map-error-bag.ts +51 -0
- package/src/core/errors/map-zod.ts +39 -0
- package/src/core/hooks/use-button.ts +220 -0
- package/src/core/hooks/use-core-context.ts +20 -0
- package/src/core/hooks/use-core-utility.ts +0 -0
- package/src/core/hooks/use-core.ts +13 -0
- package/src/core/hooks/use-field.ts +497 -0
- package/src/core/hooks/use-optional-field.ts +28 -0
- package/src/core/index.ts +0 -0
- package/src/core/registry/binder-registry.ts +82 -0
- package/src/core/registry/field-registry.ts +187 -0
- package/src/core/test.tsx +17 -0
- package/src/global.d.ts +14 -0
- package/src/index.ts +68 -0
- package/src/input/index.ts +4 -0
- package/src/input/input-field.tsx +854 -0
- package/src/input/input-layout-graph.ts +230 -0
- package/src/input/input-props.ts +190 -0
- package/src/lib/get-global-countries.ts +87 -0
- package/src/lib/utils.ts +6 -0
- package/src/presets/index.ts +0 -0
- package/src/presets/shadcn-preset.ts +0 -0
- package/src/presets/shadcn-variants/checkbox.tsx +849 -0
- package/src/presets/shadcn-variants/chips.tsx +756 -0
- package/src/presets/shadcn-variants/color.tsx +284 -0
- package/src/presets/shadcn-variants/custom.tsx +227 -0
- package/src/presets/shadcn-variants/date.tsx +796 -0
- package/src/presets/shadcn-variants/file.tsx +764 -0
- package/src/presets/shadcn-variants/keyvalue.tsx +556 -0
- package/src/presets/shadcn-variants/multiselect.tsx +1132 -0
- package/src/presets/shadcn-variants/number.tsx +176 -0
- package/src/presets/shadcn-variants/password.tsx +737 -0
- package/src/presets/shadcn-variants/phone.tsx +628 -0
- package/src/presets/shadcn-variants/radio.tsx +578 -0
- package/src/presets/shadcn-variants/select.tsx +956 -0
- package/src/presets/shadcn-variants/slider.tsx +622 -0
- package/src/presets/shadcn-variants/text.tsx +343 -0
- package/src/presets/shadcn-variants/textarea.tsx +66 -0
- package/src/presets/shadcn-variants/toggle.tsx +218 -0
- package/src/presets/shadcn-variants/treeselect.tsx +784 -0
- package/src/presets/ui/badge.tsx +46 -0
- package/src/presets/ui/button.tsx +60 -0
- package/src/presets/ui/calendar.tsx +214 -0
- package/src/presets/ui/checkbox.tsx +115 -0
- package/src/presets/ui/custom.tsx +0 -0
- package/src/presets/ui/dialog.tsx +141 -0
- package/src/presets/ui/field.tsx +246 -0
- package/src/presets/ui/input-mask.tsx +739 -0
- package/src/presets/ui/input-otp.tsx +77 -0
- package/src/presets/ui/input.tsx +1011 -0
- package/src/presets/ui/label.tsx +22 -0
- package/src/presets/ui/number.tsx +1370 -0
- package/src/presets/ui/popover.tsx +46 -0
- package/src/presets/ui/radio-group.tsx +43 -0
- package/src/presets/ui/scroll-area.tsx +56 -0
- package/src/presets/ui/select.tsx +190 -0
- package/src/presets/ui/separator.tsx +28 -0
- package/src/presets/ui/slider.tsx +61 -0
- package/src/presets/ui/switch.tsx +32 -0
- package/src/presets/ui/textarea.tsx +634 -0
- package/src/presets/ui/time-dropdowns.tsx +350 -0
- package/src/schema/adapter.ts +217 -0
- package/src/schema/core.ts +429 -0
- package/src/schema/field-map.ts +0 -0
- package/src/schema/field.ts +224 -0
- package/src/schema/index.ts +0 -0
- package/src/schema/input-field.ts +260 -0
- package/src/schema/presets.ts +0 -0
- package/src/schema/variant.ts +216 -0
- package/src/variants/core/checkbox.tsx +54 -0
- package/src/variants/core/chips.tsx +22 -0
- package/src/variants/core/color.tsx +16 -0
- package/src/variants/core/custom.tsx +18 -0
- package/src/variants/core/date.tsx +25 -0
- package/src/variants/core/file.tsx +9 -0
- package/src/variants/core/keyvalue.tsx +12 -0
- package/src/variants/core/multiselect.tsx +28 -0
- package/src/variants/core/number.tsx +115 -0
- package/src/variants/core/password.tsx +35 -0
- package/src/variants/core/phone.tsx +16 -0
- package/src/variants/core/radio.tsx +38 -0
- package/src/variants/core/select.tsx +15 -0
- package/src/variants/core/slider.tsx +55 -0
- package/src/variants/core/text.tsx +114 -0
- package/src/variants/core/textarea.tsx +22 -0
- package/src/variants/core/toggle.tsx +50 -0
- package/src/variants/core/treeselect.tsx +11 -0
- package/src/variants/helpers/selection-summary.tsx +236 -0
- package/src/variants/index.ts +75 -0
- package/src/variants/registry.ts +38 -0
- package/src/variants/select-shared.ts +0 -0
- package/src/variants/shared.ts +126 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { Slot } from "@radix-ui/react-slot"
|
|
3
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
4
|
+
|
|
5
|
+
import { cn } from "@/lib/utils"
|
|
6
|
+
|
|
7
|
+
const badgeVariants = cva(
|
|
8
|
+
"inline-flex items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default:
|
|
13
|
+
"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
|
14
|
+
secondary:
|
|
15
|
+
"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
|
16
|
+
destructive:
|
|
17
|
+
"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
18
|
+
outline:
|
|
19
|
+
"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
defaultVariants: {
|
|
23
|
+
variant: "default",
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
function Badge({
|
|
29
|
+
className,
|
|
30
|
+
variant,
|
|
31
|
+
asChild = false,
|
|
32
|
+
...props
|
|
33
|
+
}: React.ComponentProps<"span"> &
|
|
34
|
+
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
|
35
|
+
const Comp = asChild ? Slot : "span"
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Comp
|
|
39
|
+
data-slot="badge"
|
|
40
|
+
className={cn(badgeVariants({ variant }), className)}
|
|
41
|
+
{...props}
|
|
42
|
+
/>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { Badge, badgeVariants }
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { Slot } from "@radix-ui/react-slot"
|
|
3
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
4
|
+
|
|
5
|
+
import { cn } from "@/lib/utils"
|
|
6
|
+
|
|
7
|
+
const buttonVariants = cva(
|
|
8
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
13
|
+
destructive:
|
|
14
|
+
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
15
|
+
outline:
|
|
16
|
+
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
17
|
+
secondary:
|
|
18
|
+
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
19
|
+
ghost:
|
|
20
|
+
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
21
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
22
|
+
},
|
|
23
|
+
size: {
|
|
24
|
+
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
25
|
+
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
26
|
+
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
27
|
+
icon: "size-9",
|
|
28
|
+
"icon-sm": "size-8",
|
|
29
|
+
"icon-lg": "size-10",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
defaultVariants: {
|
|
33
|
+
variant: "default",
|
|
34
|
+
size: "default",
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
function Button({
|
|
40
|
+
className,
|
|
41
|
+
variant,
|
|
42
|
+
size,
|
|
43
|
+
asChild = false,
|
|
44
|
+
...props
|
|
45
|
+
}: React.ComponentProps<"button"> &
|
|
46
|
+
VariantProps<typeof buttonVariants> & {
|
|
47
|
+
asChild?: boolean
|
|
48
|
+
}) {
|
|
49
|
+
const Comp = asChild ? Slot : "button"
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Comp
|
|
53
|
+
data-slot="button"
|
|
54
|
+
className={cn(buttonVariants({ variant, size, className }))}
|
|
55
|
+
{...props}
|
|
56
|
+
/>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { Button, buttonVariants }
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import {
|
|
3
|
+
ChevronDownIcon,
|
|
4
|
+
ChevronLeftIcon,
|
|
5
|
+
ChevronRightIcon,
|
|
6
|
+
} from "lucide-react"
|
|
7
|
+
import { DayButton, DayPicker, getDefaultClassNames } from "react-day-picker"
|
|
8
|
+
|
|
9
|
+
import { cn } from "@/lib/utils"
|
|
10
|
+
import { Button, buttonVariants } from "@/presets/ui/button"
|
|
11
|
+
|
|
12
|
+
function Calendar({
|
|
13
|
+
className,
|
|
14
|
+
classNames,
|
|
15
|
+
showOutsideDays = true,
|
|
16
|
+
captionLayout = "label",
|
|
17
|
+
buttonVariant = "ghost",
|
|
18
|
+
formatters,
|
|
19
|
+
components,
|
|
20
|
+
...props
|
|
21
|
+
}: React.ComponentProps<typeof DayPicker> & {
|
|
22
|
+
buttonVariant?: React.ComponentProps<typeof Button>["variant"]
|
|
23
|
+
}) {
|
|
24
|
+
const defaultClassNames = getDefaultClassNames()
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<DayPicker
|
|
28
|
+
showOutsideDays={showOutsideDays}
|
|
29
|
+
className={cn(
|
|
30
|
+
"bg-background group/calendar p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",
|
|
31
|
+
String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,
|
|
32
|
+
String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,
|
|
33
|
+
className
|
|
34
|
+
)}
|
|
35
|
+
captionLayout={captionLayout}
|
|
36
|
+
formatters={{
|
|
37
|
+
formatMonthDropdown: (date) =>
|
|
38
|
+
date.toLocaleString("default", { month: "short" }),
|
|
39
|
+
...formatters,
|
|
40
|
+
}}
|
|
41
|
+
classNames={{
|
|
42
|
+
root: cn("w-fit", defaultClassNames.root),
|
|
43
|
+
months: cn(
|
|
44
|
+
"flex gap-4 flex-col md:flex-row relative",
|
|
45
|
+
defaultClassNames.months
|
|
46
|
+
),
|
|
47
|
+
month: cn("flex flex-col w-full gap-4", defaultClassNames.month),
|
|
48
|
+
nav: cn(
|
|
49
|
+
"flex items-center gap-1 w-full absolute top-0 inset-x-0 justify-between",
|
|
50
|
+
defaultClassNames.nav
|
|
51
|
+
),
|
|
52
|
+
button_previous: cn(
|
|
53
|
+
buttonVariants({ variant: buttonVariant }),
|
|
54
|
+
"size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",
|
|
55
|
+
defaultClassNames.button_previous
|
|
56
|
+
),
|
|
57
|
+
button_next: cn(
|
|
58
|
+
buttonVariants({ variant: buttonVariant }),
|
|
59
|
+
"size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",
|
|
60
|
+
defaultClassNames.button_next
|
|
61
|
+
),
|
|
62
|
+
month_caption: cn(
|
|
63
|
+
"flex items-center justify-center h-(--cell-size) w-full px-(--cell-size)",
|
|
64
|
+
defaultClassNames.month_caption
|
|
65
|
+
),
|
|
66
|
+
dropdowns: cn(
|
|
67
|
+
"w-full flex items-center text-sm font-medium justify-center h-(--cell-size) gap-1.5",
|
|
68
|
+
defaultClassNames.dropdowns
|
|
69
|
+
),
|
|
70
|
+
dropdown_root: cn(
|
|
71
|
+
"relative has-focus:border-ring border border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] rounded-md",
|
|
72
|
+
defaultClassNames.dropdown_root
|
|
73
|
+
),
|
|
74
|
+
dropdown: cn(
|
|
75
|
+
"absolute bg-popover inset-0 opacity-0",
|
|
76
|
+
defaultClassNames.dropdown
|
|
77
|
+
),
|
|
78
|
+
caption_label: cn(
|
|
79
|
+
"select-none font-medium",
|
|
80
|
+
captionLayout === "label"
|
|
81
|
+
? "text-sm"
|
|
82
|
+
: "rounded-md pl-2 pr-1 flex items-center gap-1 text-sm h-8 [&>svg]:text-muted-foreground [&>svg]:size-3.5",
|
|
83
|
+
defaultClassNames.caption_label
|
|
84
|
+
),
|
|
85
|
+
table: "w-full border-collapse",
|
|
86
|
+
weekdays: cn("flex", defaultClassNames.weekdays),
|
|
87
|
+
weekday: cn(
|
|
88
|
+
"text-muted-foreground rounded-md flex-1 font-normal text-[0.8rem] select-none",
|
|
89
|
+
defaultClassNames.weekday
|
|
90
|
+
),
|
|
91
|
+
week: cn("flex w-full mt-2", defaultClassNames.week),
|
|
92
|
+
week_number_header: cn(
|
|
93
|
+
"select-none w-(--cell-size)",
|
|
94
|
+
defaultClassNames.week_number_header
|
|
95
|
+
),
|
|
96
|
+
week_number: cn(
|
|
97
|
+
"text-[0.8rem] select-none text-muted-foreground",
|
|
98
|
+
defaultClassNames.week_number
|
|
99
|
+
),
|
|
100
|
+
day: cn(
|
|
101
|
+
"relative w-full h-full p-0 text-center [&:last-child[data-selected=true]_button]:rounded-r-md group/day aspect-square select-none",
|
|
102
|
+
props.showWeekNumber
|
|
103
|
+
? "[&:nth-child(2)[data-selected=true]_button]:rounded-l-md"
|
|
104
|
+
: "[&:first-child[data-selected=true]_button]:rounded-l-md",
|
|
105
|
+
defaultClassNames.day
|
|
106
|
+
),
|
|
107
|
+
range_start: cn(
|
|
108
|
+
"rounded-l-md bg-accent",
|
|
109
|
+
defaultClassNames.range_start
|
|
110
|
+
),
|
|
111
|
+
range_middle: cn("rounded-none", defaultClassNames.range_middle),
|
|
112
|
+
range_end: cn("rounded-r-md bg-accent", defaultClassNames.range_end),
|
|
113
|
+
today: cn(
|
|
114
|
+
"bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",
|
|
115
|
+
defaultClassNames.today
|
|
116
|
+
),
|
|
117
|
+
outside: cn(
|
|
118
|
+
"text-muted-foreground aria-selected:text-muted-foreground",
|
|
119
|
+
defaultClassNames.outside
|
|
120
|
+
),
|
|
121
|
+
disabled: cn(
|
|
122
|
+
"text-muted-foreground opacity-50",
|
|
123
|
+
defaultClassNames.disabled
|
|
124
|
+
),
|
|
125
|
+
hidden: cn("invisible", defaultClassNames.hidden),
|
|
126
|
+
...classNames,
|
|
127
|
+
}}
|
|
128
|
+
components={{
|
|
129
|
+
Root: ({ className, rootRef, ...props }) => {
|
|
130
|
+
return (
|
|
131
|
+
<div
|
|
132
|
+
data-slot="calendar"
|
|
133
|
+
ref={rootRef}
|
|
134
|
+
className={cn(className)}
|
|
135
|
+
{...props}
|
|
136
|
+
/>
|
|
137
|
+
)
|
|
138
|
+
},
|
|
139
|
+
Chevron: ({ className, orientation, ...props }) => {
|
|
140
|
+
if (orientation === "left") {
|
|
141
|
+
return (
|
|
142
|
+
<ChevronLeftIcon className={cn("size-4", className)} {...props} />
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (orientation === "right") {
|
|
147
|
+
return (
|
|
148
|
+
<ChevronRightIcon
|
|
149
|
+
className={cn("size-4", className)}
|
|
150
|
+
{...props}
|
|
151
|
+
/>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<ChevronDownIcon className={cn("size-4", className)} {...props} />
|
|
157
|
+
)
|
|
158
|
+
},
|
|
159
|
+
DayButton: CalendarDayButton,
|
|
160
|
+
WeekNumber: ({ children, ...props }) => {
|
|
161
|
+
return (
|
|
162
|
+
<td {...props}>
|
|
163
|
+
<div className="flex size-(--cell-size) items-center justify-center text-center">
|
|
164
|
+
{children}
|
|
165
|
+
</div>
|
|
166
|
+
</td>
|
|
167
|
+
)
|
|
168
|
+
},
|
|
169
|
+
...components,
|
|
170
|
+
}}
|
|
171
|
+
{...props}
|
|
172
|
+
/>
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function CalendarDayButton({
|
|
177
|
+
className,
|
|
178
|
+
day,
|
|
179
|
+
modifiers,
|
|
180
|
+
...props
|
|
181
|
+
}: React.ComponentProps<typeof DayButton>) {
|
|
182
|
+
const defaultClassNames = getDefaultClassNames()
|
|
183
|
+
|
|
184
|
+
const ref = React.useRef<HTMLButtonElement>(null)
|
|
185
|
+
React.useEffect(() => {
|
|
186
|
+
if (modifiers.focused) ref.current?.focus()
|
|
187
|
+
}, [modifiers.focused])
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
<Button
|
|
191
|
+
ref={ref}
|
|
192
|
+
variant="ghost"
|
|
193
|
+
size="icon"
|
|
194
|
+
data-day={day.date.toLocaleDateString()}
|
|
195
|
+
data-selected-single={
|
|
196
|
+
modifiers.selected &&
|
|
197
|
+
!modifiers.range_start &&
|
|
198
|
+
!modifiers.range_end &&
|
|
199
|
+
!modifiers.range_middle
|
|
200
|
+
}
|
|
201
|
+
data-range-start={modifiers.range_start}
|
|
202
|
+
data-range-end={modifiers.range_end}
|
|
203
|
+
data-range-middle={modifiers.range_middle}
|
|
204
|
+
className={cn(
|
|
205
|
+
"data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 dark:hover:text-accent-foreground flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md [&>span]:text-xs [&>span]:opacity-70",
|
|
206
|
+
defaultClassNames.day,
|
|
207
|
+
className
|
|
208
|
+
)}
|
|
209
|
+
{...props}
|
|
210
|
+
/>
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export { Calendar, CalendarDayButton }
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
|
|
5
|
+
import { CheckIcon, MinusIcon } from "lucide-react"
|
|
6
|
+
|
|
7
|
+
import { cn } from "@/lib/utils"
|
|
8
|
+
|
|
9
|
+
type TriState = boolean | "none"
|
|
10
|
+
type BaseProps = React.ComponentProps<typeof CheckboxPrimitive.Root>
|
|
11
|
+
|
|
12
|
+
export interface CheckboxProps
|
|
13
|
+
extends Omit<BaseProps, "checked" | "onCheckedChange"> {
|
|
14
|
+
checked?: TriState
|
|
15
|
+
onCheckedChange?: (checked: TriState) => void
|
|
16
|
+
/**
|
|
17
|
+
* Enable tri-state behaviour:
|
|
18
|
+
* - true → checked (✓)
|
|
19
|
+
* - false → partial (−)
|
|
20
|
+
* - "none" → unchecked (empty)
|
|
21
|
+
*/
|
|
22
|
+
tristate?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function Checkbox({
|
|
26
|
+
className,
|
|
27
|
+
checked = false,
|
|
28
|
+
onCheckedChange,
|
|
29
|
+
tristate = false,
|
|
30
|
+
...props
|
|
31
|
+
}: CheckboxProps) {
|
|
32
|
+
// Map our states → Radix checked value
|
|
33
|
+
// - in tri-state mode:
|
|
34
|
+
// true → true
|
|
35
|
+
// false → "indeterminate" (minus)
|
|
36
|
+
// "none" → false (unchecked)
|
|
37
|
+
// - non-tristate: normal boolean
|
|
38
|
+
const internalChecked: boolean | "indeterminate" =
|
|
39
|
+
tristate
|
|
40
|
+
? checked === true
|
|
41
|
+
? true
|
|
42
|
+
: checked === false
|
|
43
|
+
? "indeterminate"
|
|
44
|
+
: false // "none"
|
|
45
|
+
: checked === true
|
|
46
|
+
|
|
47
|
+
const handleCheckedChange: CheckboxPrimitive.CheckboxProps["onCheckedChange"] =
|
|
48
|
+
() => {
|
|
49
|
+
if (!onCheckedChange) return
|
|
50
|
+
|
|
51
|
+
if (tristate) {
|
|
52
|
+
// Cycle: "none" (empty) → true (check) → false (minus) → "none"
|
|
53
|
+
const prev: TriState = checked ?? "none"
|
|
54
|
+
const next: TriState =
|
|
55
|
+
prev === "none"
|
|
56
|
+
? true
|
|
57
|
+
: prev === true
|
|
58
|
+
? false
|
|
59
|
+
: "none"
|
|
60
|
+
|
|
61
|
+
onCheckedChange(next)
|
|
62
|
+
} else {
|
|
63
|
+
// Simple toggle boolean (treat "none" as false)
|
|
64
|
+
const next = checked === true ? false : true
|
|
65
|
+
onCheckedChange(next)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Icon mapping:
|
|
70
|
+
// - tri-state:
|
|
71
|
+
// false → minus
|
|
72
|
+
// true → check
|
|
73
|
+
// "none" → nothing
|
|
74
|
+
// - non-tristate:
|
|
75
|
+
// true → check
|
|
76
|
+
// else → nothing
|
|
77
|
+
const icon = tristate
|
|
78
|
+
? checked === false
|
|
79
|
+
? <MinusIcon className="size-3.5" />
|
|
80
|
+
: checked === true
|
|
81
|
+
? <CheckIcon className="size-3.5" />
|
|
82
|
+
: null
|
|
83
|
+
: checked
|
|
84
|
+
? <CheckIcon className="size-3.5" />
|
|
85
|
+
: null
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<CheckboxPrimitive.Root
|
|
89
|
+
data-slot="checkbox"
|
|
90
|
+
checked={internalChecked}
|
|
91
|
+
onCheckedChange={handleCheckedChange}
|
|
92
|
+
className={cn(
|
|
93
|
+
"peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs outline-none transition-shadow",
|
|
94
|
+
"dark:bg-input/30",
|
|
95
|
+
// checked & indeterminate share "selected" styling
|
|
96
|
+
"data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=checked]:border-primary",
|
|
97
|
+
"data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground data-[state=indeterminate]:border-primary",
|
|
98
|
+
"focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
99
|
+
"aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40",
|
|
100
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
101
|
+
className,
|
|
102
|
+
)}
|
|
103
|
+
{...props}
|
|
104
|
+
>
|
|
105
|
+
<CheckboxPrimitive.Indicator
|
|
106
|
+
data-slot="checkbox-indicator"
|
|
107
|
+
className="grid place-content-center text-current transition-none"
|
|
108
|
+
>
|
|
109
|
+
{icon}
|
|
110
|
+
</CheckboxPrimitive.Indicator>
|
|
111
|
+
</CheckboxPrimitive.Root>
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { Checkbox }
|
|
File without changes
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import * as DialogPrimitive from "@radix-ui/react-dialog"
|
|
3
|
+
import { XIcon } from "lucide-react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "@/lib/utils"
|
|
6
|
+
|
|
7
|
+
function Dialog({
|
|
8
|
+
...props
|
|
9
|
+
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
|
10
|
+
return <DialogPrimitive.Root data-slot="dialog" {...props} />
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function DialogTrigger({
|
|
14
|
+
...props
|
|
15
|
+
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
|
|
16
|
+
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function DialogPortal({
|
|
20
|
+
...props
|
|
21
|
+
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
|
22
|
+
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function DialogClose({
|
|
26
|
+
...props
|
|
27
|
+
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
|
|
28
|
+
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function DialogOverlay({
|
|
32
|
+
className,
|
|
33
|
+
...props
|
|
34
|
+
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
|
|
35
|
+
return (
|
|
36
|
+
<DialogPrimitive.Overlay
|
|
37
|
+
data-slot="dialog-overlay"
|
|
38
|
+
className={cn(
|
|
39
|
+
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
|
40
|
+
className
|
|
41
|
+
)}
|
|
42
|
+
{...props}
|
|
43
|
+
/>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function DialogContent({
|
|
48
|
+
className,
|
|
49
|
+
children,
|
|
50
|
+
showCloseButton = true,
|
|
51
|
+
...props
|
|
52
|
+
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
|
53
|
+
showCloseButton?: boolean
|
|
54
|
+
}) {
|
|
55
|
+
return (
|
|
56
|
+
<DialogPortal data-slot="dialog-portal">
|
|
57
|
+
<DialogOverlay />
|
|
58
|
+
<DialogPrimitive.Content
|
|
59
|
+
data-slot="dialog-content"
|
|
60
|
+
className={cn(
|
|
61
|
+
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
|
|
62
|
+
className
|
|
63
|
+
)}
|
|
64
|
+
{...props}
|
|
65
|
+
>
|
|
66
|
+
{children}
|
|
67
|
+
{showCloseButton && (
|
|
68
|
+
<DialogPrimitive.Close
|
|
69
|
+
data-slot="dialog-close"
|
|
70
|
+
className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
|
|
71
|
+
>
|
|
72
|
+
<XIcon />
|
|
73
|
+
<span className="sr-only">Close</span>
|
|
74
|
+
</DialogPrimitive.Close>
|
|
75
|
+
)}
|
|
76
|
+
</DialogPrimitive.Content>
|
|
77
|
+
</DialogPortal>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
82
|
+
return (
|
|
83
|
+
<div
|
|
84
|
+
data-slot="dialog-header"
|
|
85
|
+
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
|
86
|
+
{...props}
|
|
87
|
+
/>
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|
92
|
+
return (
|
|
93
|
+
<div
|
|
94
|
+
data-slot="dialog-footer"
|
|
95
|
+
className={cn(
|
|
96
|
+
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
|
97
|
+
className
|
|
98
|
+
)}
|
|
99
|
+
{...props}
|
|
100
|
+
/>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function DialogTitle({
|
|
105
|
+
className,
|
|
106
|
+
...props
|
|
107
|
+
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
|
108
|
+
return (
|
|
109
|
+
<DialogPrimitive.Title
|
|
110
|
+
data-slot="dialog-title"
|
|
111
|
+
className={cn("text-lg leading-none font-semibold", className)}
|
|
112
|
+
{...props}
|
|
113
|
+
/>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function DialogDescription({
|
|
118
|
+
className,
|
|
119
|
+
...props
|
|
120
|
+
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
|
|
121
|
+
return (
|
|
122
|
+
<DialogPrimitive.Description
|
|
123
|
+
data-slot="dialog-description"
|
|
124
|
+
className={cn("text-muted-foreground text-sm", className)}
|
|
125
|
+
{...props}
|
|
126
|
+
/>
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export {
|
|
131
|
+
Dialog,
|
|
132
|
+
DialogClose,
|
|
133
|
+
DialogContent,
|
|
134
|
+
DialogDescription,
|
|
135
|
+
DialogFooter,
|
|
136
|
+
DialogHeader,
|
|
137
|
+
DialogOverlay,
|
|
138
|
+
DialogPortal,
|
|
139
|
+
DialogTitle,
|
|
140
|
+
DialogTrigger,
|
|
141
|
+
}
|