@zabuti/components-mcp 0.0.0-stage → 0.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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +42 -2
  3. package/dist/index.js +527 -0
  4. package/dist/project-setup.js +424 -0
  5. package/dist/registry.js +73 -0
  6. package/dist/source.js +19 -0
  7. package/package.json +41 -4
  8. package/payload/registry.json +801 -0
  9. package/payload/src/components/ui/accordion.tsx +75 -0
  10. package/payload/src/components/ui/alert-dialog.tsx +151 -0
  11. package/payload/src/components/ui/alert.tsx +69 -0
  12. package/payload/src/components/ui/avatar.tsx +59 -0
  13. package/payload/src/components/ui/badge.tsx +57 -0
  14. package/payload/src/components/ui/breadcrumb.tsx +109 -0
  15. package/payload/src/components/ui/button.tsx +76 -0
  16. package/payload/src/components/ui/calendar.tsx +117 -0
  17. package/payload/src/components/ui/card.tsx +120 -0
  18. package/payload/src/components/ui/chart.tsx +249 -0
  19. package/payload/src/components/ui/checkbox.tsx +38 -0
  20. package/payload/src/components/ui/collapsible.tsx +30 -0
  21. package/payload/src/components/ui/combobox.tsx +127 -0
  22. package/payload/src/components/ui/command.tsx +186 -0
  23. package/payload/src/components/ui/context-menu.tsx +261 -0
  24. package/payload/src/components/ui/date-picker.tsx +140 -0
  25. package/payload/src/components/ui/dialog.tsx +176 -0
  26. package/payload/src/components/ui/dropdown-menu.tsx +277 -0
  27. package/payload/src/components/ui/form.tsx +151 -0
  28. package/payload/src/components/ui/hover-card.tsx +46 -0
  29. package/payload/src/components/ui/input-group.tsx +127 -0
  30. package/payload/src/components/ui/input.tsx +25 -0
  31. package/payload/src/components/ui/label.tsx +28 -0
  32. package/payload/src/components/ui/pagination.tsx +130 -0
  33. package/payload/src/components/ui/popover.tsx +97 -0
  34. package/payload/src/components/ui/progress.tsx +35 -0
  35. package/payload/src/components/ui/radio-group.tsx +49 -0
  36. package/payload/src/components/ui/scroll-area.tsx +67 -0
  37. package/payload/src/components/ui/select.tsx +199 -0
  38. package/payload/src/components/ui/separator.tsx +32 -0
  39. package/payload/src/components/ui/sheet.tsx +155 -0
  40. package/payload/src/components/ui/skeleton.tsx +21 -0
  41. package/payload/src/components/ui/slider.tsx +61 -0
  42. package/payload/src/components/ui/sonner.tsx +31 -0
  43. package/payload/src/components/ui/switch.tsx +40 -0
  44. package/payload/src/components/ui/table.tsx +108 -0
  45. package/payload/src/components/ui/tabs.tsx +98 -0
  46. package/payload/src/components/ui/textarea.tsx +24 -0
  47. package/payload/src/components/ui/toggle-group.tsx +72 -0
  48. package/payload/src/components/ui/toggle.tsx +54 -0
  49. package/payload/src/components/ui/tooltip.tsx +65 -0
  50. package/payload/src/lib/utils.ts +1 -0
  51. package/payload/src/themes/manifest.json +12 -0
  52. package/payload/src/themes/zabuti-ui-sky.css +14 -0
  53. package/payload/src/themes/zabuti-ui-teal.css +14 -0
  54. package/payload/src/zabuti-ui.css +272 -0
@@ -0,0 +1,186 @@
1
+ "use client"
2
+
3
+ /**
4
+ * Command — Zabuti UI primitive.
5
+ *
6
+ * A `cmdk` command palette / combobox list, styled over the `zabuti-ui.css`
7
+ * token layer. `CommandDialog` drops the list into the Dialog primitive for a
8
+ * ⌘K-style overlay. Zabuti-owned, no shadcn dependency; `cmdk` is a peer
9
+ * dependency and provides the filtering + keyboard behaviour.
10
+ */
11
+ import * as React from "react"
12
+ import { Command as CommandPrimitive } from "cmdk"
13
+ import { SearchIcon } from "lucide-react"
14
+ import { cn } from "cn"
15
+
16
+ import {
17
+ Dialog,
18
+ DialogContent,
19
+ DialogDescription,
20
+ DialogHeader,
21
+ DialogTitle,
22
+ } from "@/components/ui/dialog"
23
+
24
+ function Command({
25
+ className,
26
+ ...props
27
+ }: React.ComponentProps<typeof CommandPrimitive>) {
28
+ return (
29
+ <CommandPrimitive
30
+ data-slot="command"
31
+ className={cn(
32
+ "flex h-full w-full flex-col overflow-hidden rounded-lg bg-popover text-popover-foreground",
33
+ className
34
+ )}
35
+ {...props}
36
+ />
37
+ )
38
+ }
39
+
40
+ function CommandDialog({
41
+ title = "Command Palette",
42
+ description = "Search for a command to run…",
43
+ children,
44
+ className,
45
+ showCloseButton = true,
46
+ ...props
47
+ }: React.ComponentProps<typeof Dialog> & {
48
+ title?: string
49
+ description?: string
50
+ className?: string
51
+ showCloseButton?: boolean
52
+ }) {
53
+ return (
54
+ <Dialog {...props}>
55
+ <DialogHeader className="sr-only">
56
+ <DialogTitle>{title}</DialogTitle>
57
+ <DialogDescription>{description}</DialogDescription>
58
+ </DialogHeader>
59
+ <DialogContent
60
+ className={cn("overflow-hidden p-0", className)}
61
+ showCloseButton={showCloseButton}
62
+ >
63
+ <Command className="**:data-[slot=command-input-wrapper]:h-12 [&_[data-slot=command-group]]:px-2 [&_[data-slot=command-group]:not([hidden])_~[data-slot=command-group]]:pt-0 [&_[data-slot=command-group]_[data-slot=command-item]]:px-2 [&_[data-slot=command-input-wrapper]_svg]:h-5 [&_[data-slot=command-input-wrapper]_svg]:w-5 [&_[data-slot=command-item]]:py-2 [&_[data-slot=command-item]_svg]:h-5 [&_[data-slot=command-item]_svg]:w-5">
64
+ {children}
65
+ </Command>
66
+ </DialogContent>
67
+ </Dialog>
68
+ )
69
+ }
70
+
71
+ function CommandInput({
72
+ className,
73
+ ...props
74
+ }: React.ComponentProps<typeof CommandPrimitive.Input>) {
75
+ return (
76
+ <div data-slot="command-input-wrapper" className="flex h-9 items-center gap-2 border-b px-2.5">
77
+ <SearchIcon className="size-4 shrink-0 text-muted-foreground" />
78
+ <CommandPrimitive.Input
79
+ data-slot="command-input"
80
+ className={cn(
81
+ "flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
82
+ className
83
+ )}
84
+ {...props}
85
+ />
86
+ </div>
87
+ )
88
+ }
89
+
90
+ function CommandList({
91
+ className,
92
+ ...props
93
+ }: React.ComponentProps<typeof CommandPrimitive.List>) {
94
+ return (
95
+ <CommandPrimitive.List
96
+ data-slot="command-list"
97
+ className={cn(
98
+ "max-h-80 scroll-py-1 overflow-x-hidden overflow-y-auto",
99
+ className
100
+ )}
101
+ {...props}
102
+ />
103
+ )
104
+ }
105
+
106
+ function CommandEmpty({
107
+ ...props
108
+ }: React.ComponentProps<typeof CommandPrimitive.Empty>) {
109
+ return (
110
+ <CommandPrimitive.Empty
111
+ data-slot="command-empty"
112
+ className="py-6 text-center text-sm text-muted-foreground"
113
+ {...props}
114
+ />
115
+ )
116
+ }
117
+
118
+ function CommandGroup({
119
+ className,
120
+ ...props
121
+ }: React.ComponentProps<typeof CommandPrimitive.Group>) {
122
+ return (
123
+ <CommandPrimitive.Group
124
+ data-slot="command-group"
125
+ className={cn(
126
+ "overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-1.5 [&_[cmdk-group-heading]]:py-1 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
127
+ className
128
+ )}
129
+ {...props}
130
+ />
131
+ )
132
+ }
133
+
134
+ function CommandSeparator({
135
+ className,
136
+ ...props
137
+ }: React.ComponentProps<typeof CommandPrimitive.Separator>) {
138
+ return (
139
+ <CommandPrimitive.Separator
140
+ data-slot="command-separator"
141
+ className={cn("-mx-1 my-1 h-px bg-border", className)}
142
+ {...props}
143
+ />
144
+ )
145
+ }
146
+
147
+ function CommandItem({
148
+ className,
149
+ ...props
150
+ }: React.ComponentProps<typeof CommandPrimitive.Item>) {
151
+ return (
152
+ <CommandPrimitive.Item
153
+ data-slot="command-item"
154
+ className={cn(
155
+ "relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
156
+ className
157
+ )}
158
+ {...props}
159
+ />
160
+ )
161
+ }
162
+
163
+ function CommandShortcut({
164
+ className,
165
+ ...props
166
+ }: React.ComponentProps<"span">) {
167
+ return (
168
+ <span
169
+ data-slot="command-shortcut"
170
+ className={cn("ml-auto text-xs tracking-widest text-muted-foreground", className)}
171
+ {...props}
172
+ />
173
+ )
174
+ }
175
+
176
+ export {
177
+ Command,
178
+ CommandDialog,
179
+ CommandInput,
180
+ CommandList,
181
+ CommandEmpty,
182
+ CommandGroup,
183
+ CommandItem,
184
+ CommandShortcut,
185
+ CommandSeparator,
186
+ }
@@ -0,0 +1,261 @@
1
+ "use client"
2
+
3
+ /**
4
+ * Context Menu — Zabuti UI primitive.
5
+ *
6
+ * Radix ContextMenu + Tailwind over the `zabuti-ui.css` token layer — the
7
+ * right-click sibling of `dropdown-menu`, same item grammar. Zabuti-owned, no
8
+ * shadcn dependency; Radix is the behavioural base only.
9
+ *
10
+ * Local surface: `inset` and `variant="destructive"` on items,
11
+ * `ContextMenuShortcut`.
12
+ */
13
+ import * as React from "react"
14
+ import { cn } from "cn"
15
+ import { ContextMenu as ContextMenuPrimitive } from "radix-ui"
16
+ import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
17
+
18
+ function ContextMenu({
19
+ ...props
20
+ }: React.ComponentProps<typeof ContextMenuPrimitive.Root>) {
21
+ return <ContextMenuPrimitive.Root data-slot="context-menu" {...props} />
22
+ }
23
+
24
+ function ContextMenuTrigger({
25
+ ...props
26
+ }: React.ComponentProps<typeof ContextMenuPrimitive.Trigger>) {
27
+ return (
28
+ <ContextMenuPrimitive.Trigger data-slot="context-menu-trigger" {...props} />
29
+ )
30
+ }
31
+
32
+ function ContextMenuGroup({
33
+ ...props
34
+ }: React.ComponentProps<typeof ContextMenuPrimitive.Group>) {
35
+ return (
36
+ <ContextMenuPrimitive.Group data-slot="context-menu-group" {...props} />
37
+ )
38
+ }
39
+
40
+ function ContextMenuPortal({
41
+ ...props
42
+ }: React.ComponentProps<typeof ContextMenuPrimitive.Portal>) {
43
+ return (
44
+ <ContextMenuPrimitive.Portal data-slot="context-menu-portal" {...props} />
45
+ )
46
+ }
47
+
48
+ function ContextMenuSub({
49
+ ...props
50
+ }: React.ComponentProps<typeof ContextMenuPrimitive.Sub>) {
51
+ return <ContextMenuPrimitive.Sub data-slot="context-menu-sub" {...props} />
52
+ }
53
+
54
+ function ContextMenuRadioGroup({
55
+ ...props
56
+ }: React.ComponentProps<typeof ContextMenuPrimitive.RadioGroup>) {
57
+ return (
58
+ <ContextMenuPrimitive.RadioGroup
59
+ data-slot="context-menu-radio-group"
60
+ {...props}
61
+ />
62
+ )
63
+ }
64
+
65
+ function ContextMenuSubTrigger({
66
+ className,
67
+ inset,
68
+ children,
69
+ ...props
70
+ }: React.ComponentProps<typeof ContextMenuPrimitive.SubTrigger> & {
71
+ inset?: boolean
72
+ }) {
73
+ return (
74
+ <ContextMenuPrimitive.SubTrigger
75
+ data-slot="context-menu-sub-trigger"
76
+ data-inset={inset}
77
+ className={cn(
78
+ "flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-inset:pl-7 data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
79
+ className
80
+ )}
81
+ {...props}
82
+ >
83
+ {children}
84
+ <ChevronRightIcon className="ml-auto" />
85
+ </ContextMenuPrimitive.SubTrigger>
86
+ )
87
+ }
88
+
89
+ function ContextMenuSubContent({
90
+ className,
91
+ ...props
92
+ }: React.ComponentProps<typeof ContextMenuPrimitive.SubContent>) {
93
+ return (
94
+ <ContextMenuPrimitive.SubContent
95
+ data-slot="context-menu-sub-content"
96
+ className={cn(
97
+ "z-50 min-w-32 origin-(--radix-context-menu-content-transform-origin) overflow-hidden rounded-lg bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
98
+ className
99
+ )}
100
+ {...props}
101
+ />
102
+ )
103
+ }
104
+
105
+ function ContextMenuContent({
106
+ className,
107
+ ...props
108
+ }: React.ComponentProps<typeof ContextMenuPrimitive.Content>) {
109
+ return (
110
+ <ContextMenuPrimitive.Portal>
111
+ <ContextMenuPrimitive.Content
112
+ data-slot="context-menu-content"
113
+ className={cn(
114
+ "z-50 max-h-(--radix-context-menu-content-available-height) min-w-32 origin-(--radix-context-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
115
+ className
116
+ )}
117
+ {...props}
118
+ />
119
+ </ContextMenuPrimitive.Portal>
120
+ )
121
+ }
122
+
123
+ function ContextMenuItem({
124
+ className,
125
+ inset,
126
+ variant = "default",
127
+ ...props
128
+ }: React.ComponentProps<typeof ContextMenuPrimitive.Item> & {
129
+ inset?: boolean
130
+ variant?: "default" | "destructive"
131
+ }) {
132
+ return (
133
+ <ContextMenuPrimitive.Item
134
+ data-slot="context-menu-item"
135
+ data-inset={inset}
136
+ data-variant={variant}
137
+ className={cn(
138
+ "group/context-menu-item relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive",
139
+ className
140
+ )}
141
+ {...props}
142
+ />
143
+ )
144
+ }
145
+
146
+ function ContextMenuCheckboxItem({
147
+ className,
148
+ children,
149
+ checked,
150
+ ...props
151
+ }: React.ComponentProps<typeof ContextMenuPrimitive.CheckboxItem>) {
152
+ return (
153
+ <ContextMenuPrimitive.CheckboxItem
154
+ data-slot="context-menu-checkbox-item"
155
+ className={cn(
156
+ "relative flex cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
157
+ className
158
+ )}
159
+ checked={checked}
160
+ {...props}
161
+ >
162
+ <span className="pointer-events-none absolute right-2 flex items-center justify-center">
163
+ <ContextMenuPrimitive.ItemIndicator>
164
+ <CheckIcon className="size-4" />
165
+ </ContextMenuPrimitive.ItemIndicator>
166
+ </span>
167
+ {children}
168
+ </ContextMenuPrimitive.CheckboxItem>
169
+ )
170
+ }
171
+
172
+ function ContextMenuRadioItem({
173
+ className,
174
+ children,
175
+ ...props
176
+ }: React.ComponentProps<typeof ContextMenuPrimitive.RadioItem>) {
177
+ return (
178
+ <ContextMenuPrimitive.RadioItem
179
+ data-slot="context-menu-radio-item"
180
+ className={cn(
181
+ "relative flex cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
182
+ className
183
+ )}
184
+ {...props}
185
+ >
186
+ <span className="pointer-events-none absolute right-2 flex items-center justify-center">
187
+ <ContextMenuPrimitive.ItemIndicator>
188
+ <CircleIcon className="size-2 fill-current" />
189
+ </ContextMenuPrimitive.ItemIndicator>
190
+ </span>
191
+ {children}
192
+ </ContextMenuPrimitive.RadioItem>
193
+ )
194
+ }
195
+
196
+ function ContextMenuLabel({
197
+ className,
198
+ inset,
199
+ ...props
200
+ }: React.ComponentProps<typeof ContextMenuPrimitive.Label> & {
201
+ inset?: boolean
202
+ }) {
203
+ return (
204
+ <ContextMenuPrimitive.Label
205
+ data-slot="context-menu-label"
206
+ data-inset={inset}
207
+ className={cn(
208
+ "px-1.5 py-1 text-xs font-medium text-muted-foreground data-inset:pl-7",
209
+ className
210
+ )}
211
+ {...props}
212
+ />
213
+ )
214
+ }
215
+
216
+ function ContextMenuSeparator({
217
+ className,
218
+ ...props
219
+ }: React.ComponentProps<typeof ContextMenuPrimitive.Separator>) {
220
+ return (
221
+ <ContextMenuPrimitive.Separator
222
+ data-slot="context-menu-separator"
223
+ className={cn("-mx-1 my-1 h-px bg-border", className)}
224
+ {...props}
225
+ />
226
+ )
227
+ }
228
+
229
+ function ContextMenuShortcut({
230
+ className,
231
+ ...props
232
+ }: React.ComponentProps<"span">) {
233
+ return (
234
+ <span
235
+ data-slot="context-menu-shortcut"
236
+ className={cn(
237
+ "ml-auto text-xs tracking-widest text-muted-foreground",
238
+ className
239
+ )}
240
+ {...props}
241
+ />
242
+ )
243
+ }
244
+
245
+ export {
246
+ ContextMenu,
247
+ ContextMenuTrigger,
248
+ ContextMenuContent,
249
+ ContextMenuItem,
250
+ ContextMenuCheckboxItem,
251
+ ContextMenuRadioItem,
252
+ ContextMenuLabel,
253
+ ContextMenuSeparator,
254
+ ContextMenuShortcut,
255
+ ContextMenuGroup,
256
+ ContextMenuPortal,
257
+ ContextMenuSub,
258
+ ContextMenuSubContent,
259
+ ContextMenuSubTrigger,
260
+ ContextMenuRadioGroup,
261
+ }
@@ -0,0 +1,140 @@
1
+ "use client"
2
+
3
+ /**
4
+ * DatePicker — Zabuti UI primitive.
5
+ *
6
+ * A finished single-date field: the `calendar` (react-day-picker) dropped into a
7
+ * `popover` behind a `button` trigger that shows the formatted date. The wiring
8
+ * shadcn leaves as a copy-paste pattern is done here. Zabuti-owned; Radix +
9
+ * react-day-picker are the behavioural base.
10
+ *
11
+ * Controlled (`value` + `onValueChange`) or uncontrolled (`defaultValue`).
12
+ * Formatting uses the browser locale — pass `formatDate` to override.
13
+ * `disabledDates` takes any react-day-picker matcher (e.g. `{ before: today }`)
14
+ * to block out days that can't be picked.
15
+ *
16
+ * Pass `presets` for a rail of one-click shortcuts (Today, a relative range,
17
+ * a fiscal cutoff — whatever's common for the field) beside the calendar.
18
+ */
19
+ import * as React from "react"
20
+ import { cn } from "cn"
21
+ import { CalendarIcon } from "lucide-react"
22
+ import type { Matcher } from "react-day-picker"
23
+
24
+ import { Button } from "@/components/ui/button"
25
+ import { Calendar } from "@/components/ui/calendar"
26
+ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
27
+
28
+ interface DatePickerPreset {
29
+ label: string
30
+ value: Date
31
+ }
32
+
33
+ interface DatePickerProps {
34
+ value?: Date
35
+ defaultValue?: Date
36
+ onValueChange?: (date: Date | undefined) => void
37
+ placeholder?: string
38
+ disabled?: boolean
39
+ /** Render the trigger label from the selected date. */
40
+ formatDate?: (date: Date) => string
41
+ /** Days that can't be picked — any react-day-picker matcher, e.g. `{ before: today }`. */
42
+ disabledDates?: Matcher | Matcher[]
43
+ /** One-click shortcuts shown in a rail beside the calendar. */
44
+ presets?: DatePickerPreset[]
45
+ /** Width / classes for the trigger button. */
46
+ className?: string
47
+ id?: string
48
+ "aria-invalid"?: boolean
49
+ "aria-describedby"?: string
50
+ }
51
+
52
+ const defaultFormat = (date: Date) =>
53
+ date.toLocaleDateString(undefined, { year: "numeric", month: "long", day: "numeric" })
54
+
55
+ const isSameDay = (a: Date, b: Date) =>
56
+ a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate()
57
+
58
+ function DatePicker({
59
+ value,
60
+ defaultValue,
61
+ onValueChange,
62
+ placeholder = "Pick a date",
63
+ disabled,
64
+ formatDate = defaultFormat,
65
+ disabledDates,
66
+ presets,
67
+ className,
68
+ id,
69
+ "aria-invalid": ariaInvalid,
70
+ "aria-describedby": ariaDescribedby,
71
+ }: DatePickerProps) {
72
+ const [open, setOpen] = React.useState(false)
73
+ const [internal, setInternal] = React.useState(defaultValue)
74
+ // `value` (when provided) wins; `internal` is the uncontrolled fallback and is
75
+ // harmlessly shadowed while controlled.
76
+ const current = value !== undefined ? value : internal
77
+
78
+ function commit(next: Date | undefined) {
79
+ setInternal(next)
80
+ onValueChange?.(next)
81
+ }
82
+
83
+ return (
84
+ <Popover open={open} onOpenChange={setOpen}>
85
+ <PopoverTrigger asChild>
86
+ <Button
87
+ id={id}
88
+ type="button"
89
+ variant="outline"
90
+ disabled={disabled}
91
+ aria-invalid={ariaInvalid}
92
+ aria-describedby={ariaDescribedby}
93
+ className={cn(
94
+ "justify-start gap-2 font-normal",
95
+ !current && "text-muted-foreground",
96
+ className
97
+ )}
98
+ >
99
+ <CalendarIcon className="size-4 shrink-0 opacity-70" />
100
+ {current ? formatDate(current) : placeholder}
101
+ </Button>
102
+ </PopoverTrigger>
103
+ <PopoverContent className="flex-row items-start gap-0 w-auto p-0">
104
+ {presets && presets.length > 0 ? (
105
+ <div className="flex flex-col gap-0.5 border-r border-border p-2">
106
+ {presets.map((p) => (
107
+ <Button
108
+ key={p.label}
109
+ type="button"
110
+ variant={current && isSameDay(current, p.value) ? "secondary" : "ghost"}
111
+ size="sm"
112
+ className="justify-start"
113
+ onClick={() => {
114
+ commit(p.value)
115
+ setOpen(false)
116
+ }}
117
+ >
118
+ {p.label}
119
+ </Button>
120
+ ))}
121
+ </div>
122
+ ) : null}
123
+ <Calendar
124
+ mode="single"
125
+ selected={current}
126
+ disabled={disabledDates}
127
+ defaultMonth={current}
128
+ onSelect={(date) => {
129
+ commit(date)
130
+ setOpen(false)
131
+ }}
132
+ autoFocus
133
+ />
134
+ </PopoverContent>
135
+ </Popover>
136
+ )
137
+ }
138
+
139
+ export { DatePicker }
140
+ export type { DatePickerProps, DatePickerPreset }