@leitware/composables 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.
- package/LICENSE +21 -0
- package/README.md +387 -0
- package/dist/presets/brutalist.css +298 -0
- package/dist/presets/default.css +298 -0
- package/dist/presets/signal-pop.css +369 -0
- package/dist/styles.css +2 -0
- package/package.json +216 -0
- package/rules/composables.md +244 -0
- package/src/_internal/accordion.tsx +93 -0
- package/src/_internal/ai-elements/attachments.tsx +385 -0
- package/src/_internal/ai-elements/chain-of-thought.tsx +197 -0
- package/src/_internal/ai-elements/code-block.tsx +516 -0
- package/src/_internal/ai-elements/confirmation.tsx +150 -0
- package/src/_internal/ai-elements/conversation.tsx +148 -0
- package/src/_internal/ai-elements/inline-citation.tsx +248 -0
- package/src/_internal/ai-elements/message.tsx +292 -0
- package/src/_internal/ai-elements/plan.tsx +126 -0
- package/src/_internal/ai-elements/prompt-input.tsx +1285 -0
- package/src/_internal/ai-elements/reasoning.tsx +208 -0
- package/src/_internal/ai-elements/shimmer.tsx +72 -0
- package/src/_internal/ai-elements/sources.tsx +53 -0
- package/src/_internal/ai-elements/suggestion.tsx +48 -0
- package/src/_internal/ai-elements/task.tsx +64 -0
- package/src/_internal/ai-elements/tool.tsx +156 -0
- package/src/_internal/alert-dialog.tsx +159 -0
- package/src/_internal/alert.tsx +88 -0
- package/src/_internal/aspect-ratio.tsx +23 -0
- package/src/_internal/avatar.tsx +58 -0
- package/src/_internal/badge.tsx +60 -0
- package/src/_internal/breadcrumb.tsx +104 -0
- package/src/_internal/bubble.tsx +125 -0
- package/src/_internal/button-group.tsx +78 -0
- package/src/_internal/button.tsx +62 -0
- package/src/_internal/calendar.tsx +179 -0
- package/src/_internal/card.tsx +83 -0
- package/src/_internal/carousel.tsx +215 -0
- package/src/_internal/checkbox.tsx +26 -0
- package/src/_internal/code-block.tsx +53 -0
- package/src/_internal/collapsible.tsx +15 -0
- package/src/_internal/combobox.tsx +264 -0
- package/src/_internal/command.tsx +155 -0
- package/src/_internal/container.tsx +35 -0
- package/src/_internal/dialog.tsx +132 -0
- package/src/_internal/direction.tsx +12 -0
- package/src/_internal/divider.tsx +162 -0
- package/src/_internal/dropdown-menu.tsx +247 -0
- package/src/_internal/dropzone.tsx +481 -0
- package/src/_internal/empty.tsx +94 -0
- package/src/_internal/field.tsx +221 -0
- package/src/_internal/grid-overlay.tsx +48 -0
- package/src/_internal/grid.tsx +109 -0
- package/src/_internal/hover-card.tsx +47 -0
- package/src/_internal/icon.tsx +45 -0
- package/src/_internal/input-group.tsx +146 -0
- package/src/_internal/input.tsx +24 -0
- package/src/_internal/item.tsx +187 -0
- package/src/_internal/kbd.tsx +28 -0
- package/src/_internal/label.tsx +18 -0
- package/src/_internal/layout-bento.tsx +386 -0
- package/src/_internal/layout.tsx +174 -0
- package/src/_internal/marker.tsx +66 -0
- package/src/_internal/message.tsx +85 -0
- package/src/_internal/native-select.tsx +50 -0
- package/src/_internal/pagination.tsx +108 -0
- package/src/_internal/popover.tsx +83 -0
- package/src/_internal/progress.tsx +59 -0
- package/src/_internal/radio-group.tsx +36 -0
- package/src/_internal/resizable.tsx +44 -0
- package/src/_internal/scroll-area.tsx +48 -0
- package/src/_internal/select.tsx +187 -0
- package/src/_internal/separator.tsx +19 -0
- package/src/_internal/sheet.tsx +122 -0
- package/src/_internal/sidebar.tsx +687 -0
- package/src/_internal/skeleton.tsx +13 -0
- package/src/_internal/slider.tsx +60 -0
- package/src/_internal/sonner.tsx +51 -0
- package/src/_internal/spacer.tsx +42 -0
- package/src/_internal/spinner.tsx +16 -0
- package/src/_internal/stack.tsx +78 -0
- package/src/_internal/switch.tsx +31 -0
- package/src/_internal/table.tsx +84 -0
- package/src/_internal/tabs.tsx +74 -0
- package/src/_internal/textarea.tsx +19 -0
- package/src/_internal/toggle-group.tsx +99 -0
- package/src/_internal/toggle.tsx +42 -0
- package/src/_internal/tooltip.tsx +55 -0
- package/src/_internal/typography.tsx +129 -0
- package/src/hooks/use-mobile.ts +19 -0
- package/src/hooks/use-numeric-input.ts +119 -0
- package/src/index.ts +443 -0
- package/src/lib/numeric-input.ts +88 -0
- package/src/lib/utils.ts +39 -0
- package/src/opinionated/accordion.tsx +92 -0
- package/src/opinionated/ai/attachments.tsx +27 -0
- package/src/opinionated/ai/chain-of-thought.tsx +16 -0
- package/src/opinionated/ai/code-block.tsx +22 -0
- package/src/opinionated/ai/confirmation.tsx +16 -0
- package/src/opinionated/ai/conversation.tsx +13 -0
- package/src/opinionated/ai/index.ts +15 -0
- package/src/opinionated/ai/inline-citation.tsx +30 -0
- package/src/opinionated/ai/message.tsx +26 -0
- package/src/opinionated/ai/plan.tsx +18 -0
- package/src/opinionated/ai/prompt-input.tsx +29 -0
- package/src/opinionated/ai/reasoning.tsx +9 -0
- package/src/opinionated/ai/shimmer.tsx +4 -0
- package/src/opinionated/ai/sources.tsx +10 -0
- package/src/opinionated/ai/suggestion.tsx +6 -0
- package/src/opinionated/ai/task.tsx +12 -0
- package/src/opinionated/ai/tool.tsx +14 -0
- package/src/opinionated/alert-dialog.tsx +143 -0
- package/src/opinionated/alert.tsx +99 -0
- package/src/opinionated/aspect-ratio.tsx +12 -0
- package/src/opinionated/avatar.tsx +59 -0
- package/src/opinionated/badge.tsx +33 -0
- package/src/opinionated/breadcrumb.tsx +99 -0
- package/src/opinionated/bubble.tsx +9 -0
- package/src/opinionated/button.tsx +59 -0
- package/src/opinionated/calendar.tsx +20 -0
- package/src/opinionated/card.tsx +83 -0
- package/src/opinionated/carousel.tsx +99 -0
- package/src/opinionated/checkbox.tsx +11 -0
- package/src/opinionated/code-block.tsx +12 -0
- package/src/opinionated/collapsible.tsx +123 -0
- package/src/opinionated/combobox.tsx +123 -0
- package/src/opinionated/container.tsx +12 -0
- package/src/opinionated/dialog.tsx +124 -0
- package/src/opinionated/direction.tsx +6 -0
- package/src/opinionated/divider.tsx +13 -0
- package/src/opinionated/dropdown-menu.tsx +131 -0
- package/src/opinionated/dropzone.tsx +39 -0
- package/src/opinionated/empty.tsx +191 -0
- package/src/opinionated/field.tsx +26 -0
- package/src/opinionated/form-calendar-popover.tsx +138 -0
- package/src/opinionated/form-checkbox.tsx +107 -0
- package/src/opinionated/form-combobox.tsx +181 -0
- package/src/opinionated/form-date-of-birth.tsx +193 -0
- package/src/opinionated/form-dropzone.tsx +126 -0
- package/src/opinionated/form-input-group.tsx +184 -0
- package/src/opinionated/form-input.tsx +118 -0
- package/src/opinionated/form-multi-combobox.tsx +213 -0
- package/src/opinionated/form-multi-dropzone.tsx +141 -0
- package/src/opinionated/form-radiogroup.tsx +116 -0
- package/src/opinionated/form-select.tsx +176 -0
- package/src/opinionated/form-slider.tsx +100 -0
- package/src/opinionated/form-switch.tsx +117 -0
- package/src/opinionated/form-textarea.tsx +79 -0
- package/src/opinionated/grid-overlay.tsx +11 -0
- package/src/opinionated/grid.tsx +14 -0
- package/src/opinionated/hover-card.tsx +59 -0
- package/src/opinionated/icon.tsx +14 -0
- package/src/opinionated/input-group.tsx +20 -0
- package/src/opinionated/input.tsx +11 -0
- package/src/opinionated/item.tsx +182 -0
- package/src/opinionated/kbd.tsx +16 -0
- package/src/opinionated/label.tsx +11 -0
- package/src/opinionated/layout-bento.tsx +29 -0
- package/src/opinionated/layout.tsx +26 -0
- package/src/opinionated/list.tsx +94 -0
- package/src/opinionated/marker.tsx +7 -0
- package/src/opinionated/message.tsx +8 -0
- package/src/opinionated/native-select.tsx +51 -0
- package/src/opinionated/pagination.tsx +204 -0
- package/src/opinionated/popover.tsx +68 -0
- package/src/opinionated/progress.tsx +48 -0
- package/src/opinionated/radio-group.tsx +13 -0
- package/src/opinionated/resizable.tsx +2 -0
- package/src/opinionated/scroll-area.tsx +82 -0
- package/src/opinionated/select.tsx +101 -0
- package/src/opinionated/separator.tsx +11 -0
- package/src/opinionated/sheet.tsx +120 -0
- package/src/opinionated/sidebar.tsx +68 -0
- package/src/opinionated/skeleton.tsx +246 -0
- package/src/opinionated/slider.tsx +11 -0
- package/src/opinionated/sonner.tsx +15 -0
- package/src/opinionated/spacer.tsx +11 -0
- package/src/opinionated/stack.tsx +18 -0
- package/src/opinionated/switch.tsx +11 -0
- package/src/opinionated/table.tsx +11 -0
- package/src/opinionated/tabs.tsx +68 -0
- package/src/opinionated/textarea.tsx +11 -0
- package/src/opinionated/theme-injector.tsx +31 -0
- package/src/opinionated/toggle-group.tsx +63 -0
- package/src/opinionated/toggle.tsx +75 -0
- package/src/opinionated/token-config-panel/color-editor.tsx +85 -0
- package/src/opinionated/token-config-panel/helpers.ts +31 -0
- package/src/opinionated/token-config-panel/index.tsx +398 -0
- package/src/opinionated/token-config-panel/json-import-export.tsx +89 -0
- package/src/opinionated/token-config-panel/preset-manager.ts +31 -0
- package/src/opinionated/token-config-panel/presets-data.ts +23 -0
- package/src/opinionated/token-config-panel/spacing-editor.tsx +325 -0
- package/src/opinionated/token-config-panel/types.ts +39 -0
- package/src/opinionated/token-config-panel/typography-editor.tsx +145 -0
- package/src/opinionated/tooltip.tsx +62 -0
- package/src/opinionated/typography.tsx +7 -0
- package/src/scripts/lint-no-arbitrary.ts +155 -0
- package/src/styles/composable.css +68 -0
- package/src/styles/presets/brutalist.css +298 -0
- package/src/styles/presets/default.css +298 -0
- package/src/styles/presets/signal-pop.css +369 -0
- package/src/styles/presets-data/brutalist.ts +325 -0
- package/src/styles/presets-data/default.ts +315 -0
- package/src/styles/presets-data/index.ts +45 -0
- package/src/styles/presets-data/signal-pop.ts +393 -0
- package/src/styles/tokens/base.css +71 -0
- package/src/styles/tokens/components.css +150 -0
- package/src/styles/tokens/palette.css +795 -0
- package/src/styles/tokens/registry.ts +324 -0
- package/src/styles/tokens/semantic.css +266 -0
- package/src/styles/tokens/tailwind-theme.css +247 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type * as React from 'react'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
EmptyContent,
|
|
5
|
+
EmptyDescription,
|
|
6
|
+
EmptyHeader,
|
|
7
|
+
EmptyMedia,
|
|
8
|
+
Empty as EmptyPrimitive,
|
|
9
|
+
EmptyTitle,
|
|
10
|
+
} from '../_internal/empty'
|
|
11
|
+
import { TableCell, TableRow } from './table'
|
|
12
|
+
import { Typography } from './typography'
|
|
13
|
+
|
|
14
|
+
export interface EmptyProps {
|
|
15
|
+
/**
|
|
16
|
+
* Title text for the empty state
|
|
17
|
+
*/
|
|
18
|
+
title?: React.ReactNode
|
|
19
|
+
/**
|
|
20
|
+
* Description text for the empty state
|
|
21
|
+
*/
|
|
22
|
+
description?: React.ReactNode
|
|
23
|
+
/**
|
|
24
|
+
* Icon or media content to display
|
|
25
|
+
*/
|
|
26
|
+
icon?: React.ReactNode
|
|
27
|
+
/**
|
|
28
|
+
* Additional content to display below the description
|
|
29
|
+
*/
|
|
30
|
+
children?: React.ReactNode
|
|
31
|
+
/**
|
|
32
|
+
* Additional className
|
|
33
|
+
*/
|
|
34
|
+
className?: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Opinionated Empty component with sensible defaults and common patterns.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* // Basic usage
|
|
43
|
+
* <Empty title="No items found" description="There are no items to display." />
|
|
44
|
+
*
|
|
45
|
+
* // With icon
|
|
46
|
+
* <Empty
|
|
47
|
+
* title="No proposals"
|
|
48
|
+
* description="Create your first proposal to get started."
|
|
49
|
+
* icon={<Icon />}
|
|
50
|
+
* />
|
|
51
|
+
*
|
|
52
|
+
* // With action
|
|
53
|
+
* <Empty title="No data" description="Get started by adding some data.">
|
|
54
|
+
* <Button>Add Data</Button>
|
|
55
|
+
* </Empty>
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
function Empty({
|
|
59
|
+
title,
|
|
60
|
+
description,
|
|
61
|
+
icon,
|
|
62
|
+
children,
|
|
63
|
+
className,
|
|
64
|
+
...props
|
|
65
|
+
}: EmptyProps & Omit<React.ComponentProps<typeof EmptyPrimitive>, 'children'>) {
|
|
66
|
+
return (
|
|
67
|
+
<EmptyPrimitive className={className} {...props}>
|
|
68
|
+
{icon && <EmptyMedia variant="icon">{icon}</EmptyMedia>}
|
|
69
|
+
{(title || description) && (
|
|
70
|
+
<EmptyHeader>
|
|
71
|
+
{title && (
|
|
72
|
+
<EmptyTitle>
|
|
73
|
+
{typeof title === 'string' ? (
|
|
74
|
+
<Typography variant="heading-100">{title}</Typography>
|
|
75
|
+
) : (
|
|
76
|
+
title
|
|
77
|
+
)}
|
|
78
|
+
</EmptyTitle>
|
|
79
|
+
)}
|
|
80
|
+
{description && (
|
|
81
|
+
<EmptyDescription>
|
|
82
|
+
{typeof description === 'string' ? (
|
|
83
|
+
<Typography variant="body-100" className="text-muted-foreground">
|
|
84
|
+
{description}
|
|
85
|
+
</Typography>
|
|
86
|
+
) : (
|
|
87
|
+
description
|
|
88
|
+
)}
|
|
89
|
+
</EmptyDescription>
|
|
90
|
+
)}
|
|
91
|
+
</EmptyHeader>
|
|
92
|
+
)}
|
|
93
|
+
{children && <EmptyContent>{children}</EmptyContent>}
|
|
94
|
+
</EmptyPrimitive>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface EmptyTableStateProps {
|
|
99
|
+
/**
|
|
100
|
+
* Number of columns to span
|
|
101
|
+
*/
|
|
102
|
+
colSpan: number
|
|
103
|
+
/**
|
|
104
|
+
* Title text for the empty state
|
|
105
|
+
*/
|
|
106
|
+
title?: React.ReactNode
|
|
107
|
+
/**
|
|
108
|
+
* Subtitle/description text for the empty state
|
|
109
|
+
*/
|
|
110
|
+
subtitle?: React.ReactNode
|
|
111
|
+
/**
|
|
112
|
+
* Icon or media content to display
|
|
113
|
+
*/
|
|
114
|
+
icon?: React.ReactNode
|
|
115
|
+
/**
|
|
116
|
+
* Additional content to display below the description
|
|
117
|
+
*/
|
|
118
|
+
children?: React.ReactNode
|
|
119
|
+
/**
|
|
120
|
+
* Additional className
|
|
121
|
+
*/
|
|
122
|
+
className?: string
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Opinionated Empty state component specifically for tables.
|
|
127
|
+
* Renders as a table row with a cell spanning all columns.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```tsx
|
|
131
|
+
* <TableBody>
|
|
132
|
+
* {isEmpty ? (
|
|
133
|
+
* <EmptyTableState
|
|
134
|
+
* colSpan={columns.length}
|
|
135
|
+
* title="No proposals found"
|
|
136
|
+
* subtitle="There are no proposals matching your criteria."
|
|
137
|
+
* />
|
|
138
|
+
* ) : (
|
|
139
|
+
* // ... table rows
|
|
140
|
+
* )}
|
|
141
|
+
* </TableBody>
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
function EmptyTableState({
|
|
145
|
+
colSpan,
|
|
146
|
+
title,
|
|
147
|
+
subtitle,
|
|
148
|
+
icon,
|
|
149
|
+
children,
|
|
150
|
+
className,
|
|
151
|
+
}: EmptyTableStateProps) {
|
|
152
|
+
return (
|
|
153
|
+
<TableRow>
|
|
154
|
+
<TableCell colSpan={colSpan} className={className}>
|
|
155
|
+
<EmptyPrimitive>
|
|
156
|
+
{icon && <EmptyMedia variant="icon">{icon}</EmptyMedia>}
|
|
157
|
+
{(title || subtitle) && (
|
|
158
|
+
<EmptyHeader>
|
|
159
|
+
{title && (
|
|
160
|
+
<EmptyTitle>
|
|
161
|
+
{typeof title === 'string' ? (
|
|
162
|
+
<Typography variant="heading-100">{title}</Typography>
|
|
163
|
+
) : (
|
|
164
|
+
title
|
|
165
|
+
)}
|
|
166
|
+
</EmptyTitle>
|
|
167
|
+
)}
|
|
168
|
+
{subtitle && (
|
|
169
|
+
<EmptyDescription>
|
|
170
|
+
{typeof subtitle === 'string' ? (
|
|
171
|
+
<Typography variant="body-100" className="text-muted-foreground">
|
|
172
|
+
{subtitle}
|
|
173
|
+
</Typography>
|
|
174
|
+
) : (
|
|
175
|
+
subtitle
|
|
176
|
+
)}
|
|
177
|
+
</EmptyDescription>
|
|
178
|
+
)}
|
|
179
|
+
</EmptyHeader>
|
|
180
|
+
)}
|
|
181
|
+
{children && <EmptyContent>{children}</EmptyContent>}
|
|
182
|
+
</EmptyPrimitive>
|
|
183
|
+
</TableCell>
|
|
184
|
+
</TableRow>
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Export individual components for advanced usage
|
|
189
|
+
export { EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle }
|
|
190
|
+
|
|
191
|
+
export { Empty, EmptyTableState }
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opinionated Field component.
|
|
3
|
+
* Re-exports the primitive as the API is already clean.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* <Field>
|
|
8
|
+
* <FieldLabel>Email</FieldLabel>
|
|
9
|
+
* <Input type="email" />
|
|
10
|
+
* <FieldDescription>Enter your email address</FieldDescription>
|
|
11
|
+
* <FieldError>Email is required</FieldError>
|
|
12
|
+
* </Field>
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export {
|
|
16
|
+
Field,
|
|
17
|
+
FieldDescription,
|
|
18
|
+
FieldError,
|
|
19
|
+
FieldLabel,
|
|
20
|
+
FieldGroup,
|
|
21
|
+
FieldLegend,
|
|
22
|
+
FieldSeparator,
|
|
23
|
+
FieldSet,
|
|
24
|
+
FieldContent,
|
|
25
|
+
FieldTitle,
|
|
26
|
+
} from '../_internal/field'
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { VariantProps } from 'class-variance-authority'
|
|
2
|
+
import { ChevronDownIcon } from 'lucide-react'
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { Button as ButtonPrimitive } from '../_internal/button'
|
|
5
|
+
import { Calendar } from '../_internal/calendar'
|
|
6
|
+
import { Field, FieldContent, FieldDescription, FieldError, FieldLabel } from '../_internal/field'
|
|
7
|
+
import { Popover, PopoverContent, PopoverTrigger } from '../_internal/popover'
|
|
8
|
+
import { cn } from '../lib/utils'
|
|
9
|
+
|
|
10
|
+
export interface FormCalendarPopoverProps {
|
|
11
|
+
label?: string
|
|
12
|
+
description?: string
|
|
13
|
+
error?: string | string[] | Array<{ message?: string } | undefined>
|
|
14
|
+
value?: Date
|
|
15
|
+
onChange?: (value: Date | undefined) => void
|
|
16
|
+
onBlur?: () => void
|
|
17
|
+
disabled?: boolean
|
|
18
|
+
required?: boolean
|
|
19
|
+
orientation?: VariantProps<typeof Field>['orientation']
|
|
20
|
+
className?: string
|
|
21
|
+
// Additional props
|
|
22
|
+
id?: string
|
|
23
|
+
name?: string
|
|
24
|
+
'aria-label'?: string
|
|
25
|
+
'aria-labelledby'?: string
|
|
26
|
+
placeholder?: string
|
|
27
|
+
/** Minimum selectable date - dates before this will be disabled */
|
|
28
|
+
minDate?: Date
|
|
29
|
+
/** Maximum selectable date - dates after this will be disabled */
|
|
30
|
+
maxDate?: Date
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function FormCalendarPopover({
|
|
34
|
+
label,
|
|
35
|
+
description,
|
|
36
|
+
error,
|
|
37
|
+
value,
|
|
38
|
+
onChange,
|
|
39
|
+
onBlur,
|
|
40
|
+
disabled = false,
|
|
41
|
+
required = false,
|
|
42
|
+
orientation = 'vertical',
|
|
43
|
+
className,
|
|
44
|
+
id,
|
|
45
|
+
name,
|
|
46
|
+
'aria-label': ariaLabel,
|
|
47
|
+
'aria-labelledby': ariaLabelledBy,
|
|
48
|
+
placeholder = 'Select date',
|
|
49
|
+
minDate,
|
|
50
|
+
maxDate,
|
|
51
|
+
...props
|
|
52
|
+
}: FormCalendarPopoverProps) {
|
|
53
|
+
const errorArray = React.useMemo(() => {
|
|
54
|
+
if (!error) return undefined
|
|
55
|
+
if (Array.isArray(error)) {
|
|
56
|
+
return error.map((e) => (typeof e === 'string' ? { message: e } : e))
|
|
57
|
+
}
|
|
58
|
+
return [{ message: error }]
|
|
59
|
+
}, [error])
|
|
60
|
+
|
|
61
|
+
const hasError = Boolean(error)
|
|
62
|
+
const generatedId = React.useId()
|
|
63
|
+
const inputId = id || generatedId
|
|
64
|
+
|
|
65
|
+
const [open, setOpen] = React.useState(false)
|
|
66
|
+
|
|
67
|
+
const disabledDates = React.useMemo(() => {
|
|
68
|
+
const matchers: Array<{ before: Date } | { after: Date }> = []
|
|
69
|
+
if (minDate) {
|
|
70
|
+
matchers.push({ before: minDate })
|
|
71
|
+
}
|
|
72
|
+
if (maxDate) {
|
|
73
|
+
matchers.push({ after: maxDate })
|
|
74
|
+
}
|
|
75
|
+
return matchers.length > 0 ? matchers : undefined
|
|
76
|
+
}, [minDate, maxDate])
|
|
77
|
+
|
|
78
|
+
const handleDateSelect = (date: Date | undefined) => {
|
|
79
|
+
onChange?.(date)
|
|
80
|
+
setOpen(false)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const handleBlur = () => {
|
|
84
|
+
onBlur?.()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<Field orientation={orientation} className={className} data-invalid={hasError}>
|
|
89
|
+
{label && (
|
|
90
|
+
<FieldLabel htmlFor={inputId}>
|
|
91
|
+
{label}
|
|
92
|
+
{required && <span className="text-danger">*</span>}
|
|
93
|
+
</FieldLabel>
|
|
94
|
+
)}
|
|
95
|
+
<FieldContent>
|
|
96
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
97
|
+
<PopoverTrigger
|
|
98
|
+
render={
|
|
99
|
+
<ButtonPrimitive
|
|
100
|
+
id={inputId}
|
|
101
|
+
name={name}
|
|
102
|
+
variant="outline"
|
|
103
|
+
disabled={disabled}
|
|
104
|
+
aria-invalid={hasError}
|
|
105
|
+
aria-required={required}
|
|
106
|
+
aria-label={ariaLabel}
|
|
107
|
+
aria-labelledby={ariaLabelledBy || (label ? inputId : undefined)}
|
|
108
|
+
onBlur={handleBlur}
|
|
109
|
+
className={cn(
|
|
110
|
+
'w-full justify-between font-normal',
|
|
111
|
+
!value && 'text-muted-foreground',
|
|
112
|
+
)}
|
|
113
|
+
{...props}
|
|
114
|
+
>
|
|
115
|
+
{value ? value.toLocaleDateString() : placeholder}
|
|
116
|
+
<ChevronDownIcon className="ml-2 h-4 w-4 opacity-50" />
|
|
117
|
+
</ButtonPrimitive>
|
|
118
|
+
}
|
|
119
|
+
/>
|
|
120
|
+
<PopoverContent className="w-auto p-0" align="start">
|
|
121
|
+
<Calendar
|
|
122
|
+
mode="single"
|
|
123
|
+
selected={value}
|
|
124
|
+
defaultMonth={value || undefined}
|
|
125
|
+
captionLayout="dropdown"
|
|
126
|
+
onSelect={handleDateSelect}
|
|
127
|
+
disabled={disabledDates}
|
|
128
|
+
/>
|
|
129
|
+
</PopoverContent>
|
|
130
|
+
</Popover>
|
|
131
|
+
{description && <FieldDescription>{description}</FieldDescription>}
|
|
132
|
+
{hasError && <FieldError errors={errorArray} />}
|
|
133
|
+
</FieldContent>
|
|
134
|
+
</Field>
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { FormCalendarPopover }
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { Checkbox as CheckboxPrimitive } from '@base-ui/react/checkbox'
|
|
2
|
+
import type { VariantProps } from 'class-variance-authority'
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { Checkbox } from '../_internal/checkbox'
|
|
5
|
+
import { Field, FieldContent, FieldDescription, FieldError, FieldLabel } from '../_internal/field'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Props for the opinionated FormCheckbox component.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <FormCheckbox label="I agree to the terms" checked={agreed} onCheckedChange={setAgreed} />
|
|
13
|
+
* <FormCheckbox
|
|
14
|
+
* label="Subscribe to newsletter"
|
|
15
|
+
* description="We'll send you updates once a week."
|
|
16
|
+
* checked={subscribed}
|
|
17
|
+
* onCheckedChange={setSubscribed}
|
|
18
|
+
* />
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export interface FormCheckboxProps extends Omit<
|
|
22
|
+
CheckboxPrimitive.Root.Props,
|
|
23
|
+
'checked' | 'onCheckedChange'
|
|
24
|
+
> {
|
|
25
|
+
/** Label text rendered beside the checkbox. */
|
|
26
|
+
label?: string
|
|
27
|
+
/** Helper text rendered below the label. */
|
|
28
|
+
description?: string
|
|
29
|
+
/** Error message(s). Accepts a string, array, or react-hook-form error array. */
|
|
30
|
+
error?: string | string[] | Array<{ message?: string } | undefined>
|
|
31
|
+
/** Controlled checked state. @default false */
|
|
32
|
+
checked?: boolean
|
|
33
|
+
/** Called when the user toggles the checkbox. */
|
|
34
|
+
onCheckedChange?: (checked: boolean) => void
|
|
35
|
+
/** Disables the checkbox. @default false */
|
|
36
|
+
disabled?: boolean
|
|
37
|
+
/** Marks the field as required. @default false */
|
|
38
|
+
required?: boolean
|
|
39
|
+
/** Label/checkbox layout direction. @default 'horizontal' */
|
|
40
|
+
orientation?: VariantProps<typeof Field>['orientation']
|
|
41
|
+
className?: string
|
|
42
|
+
id?: string
|
|
43
|
+
name?: string
|
|
44
|
+
'aria-label'?: string
|
|
45
|
+
'aria-labelledby'?: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function FormCheckbox({
|
|
49
|
+
label,
|
|
50
|
+
description,
|
|
51
|
+
error,
|
|
52
|
+
checked = false,
|
|
53
|
+
onCheckedChange,
|
|
54
|
+
disabled = false,
|
|
55
|
+
required = false,
|
|
56
|
+
orientation = 'horizontal',
|
|
57
|
+
className,
|
|
58
|
+
id,
|
|
59
|
+
name,
|
|
60
|
+
'aria-label': ariaLabel,
|
|
61
|
+
'aria-labelledby': ariaLabelledBy,
|
|
62
|
+
...checkboxProps
|
|
63
|
+
}: FormCheckboxProps) {
|
|
64
|
+
const errorArray = React.useMemo(() => {
|
|
65
|
+
if (!error) return undefined
|
|
66
|
+
if (Array.isArray(error)) {
|
|
67
|
+
return error.map((e) => (typeof e === 'string' ? { message: e } : e))
|
|
68
|
+
}
|
|
69
|
+
return [{ message: error }]
|
|
70
|
+
}, [error])
|
|
71
|
+
|
|
72
|
+
const hasError = Boolean(error)
|
|
73
|
+
const generatedId = React.useId()
|
|
74
|
+
const checkboxId = id || generatedId
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<Field orientation={orientation} className={className} data-invalid={hasError}>
|
|
78
|
+
<FieldContent>
|
|
79
|
+
<div className="flex flex-row items-center gap-2">
|
|
80
|
+
<Checkbox
|
|
81
|
+
id={checkboxId}
|
|
82
|
+
name={name}
|
|
83
|
+
checked={checked}
|
|
84
|
+
onCheckedChange={onCheckedChange}
|
|
85
|
+
disabled={disabled}
|
|
86
|
+
required={required}
|
|
87
|
+
aria-invalid={hasError}
|
|
88
|
+
aria-required={required}
|
|
89
|
+
aria-label={ariaLabel}
|
|
90
|
+
aria-labelledby={ariaLabelledBy || (label ? checkboxId : undefined)}
|
|
91
|
+
{...checkboxProps}
|
|
92
|
+
/>
|
|
93
|
+
{label && (
|
|
94
|
+
<FieldLabel htmlFor={checkboxId}>
|
|
95
|
+
{label}
|
|
96
|
+
{required && <span className="text-danger">*</span>}
|
|
97
|
+
</FieldLabel>
|
|
98
|
+
)}
|
|
99
|
+
</div>
|
|
100
|
+
{description && <FieldDescription>{description}</FieldDescription>}
|
|
101
|
+
{hasError && <FieldError errors={errorArray} />}
|
|
102
|
+
</FieldContent>
|
|
103
|
+
</Field>
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { FormCheckbox }
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { VariantProps } from 'class-variance-authority'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import {
|
|
4
|
+
Combobox,
|
|
5
|
+
ComboboxContent,
|
|
6
|
+
ComboboxEmpty,
|
|
7
|
+
ComboboxInput,
|
|
8
|
+
ComboboxItem,
|
|
9
|
+
ComboboxList,
|
|
10
|
+
} from '../_internal/combobox'
|
|
11
|
+
import { Field, FieldContent, FieldDescription, FieldError, FieldLabel } from '../_internal/field'
|
|
12
|
+
|
|
13
|
+
/** A single option in a FormCombobox. */
|
|
14
|
+
export interface FormComboboxOption {
|
|
15
|
+
/** Display label shown in the dropdown and as the input value when selected. */
|
|
16
|
+
label: string
|
|
17
|
+
/** Value submitted when this option is selected. */
|
|
18
|
+
value: string
|
|
19
|
+
/** Prevents this option from being selected. */
|
|
20
|
+
disabled?: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Props for the opinionated FormCombobox component.
|
|
25
|
+
*
|
|
26
|
+
* Wraps a searchable combobox with a Field (label + description + error) and
|
|
27
|
+
* accepts a flat `options` array. The user can type to filter the list.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* <FormCombobox
|
|
32
|
+
* label="Assign to"
|
|
33
|
+
* placeholder="Search users..."
|
|
34
|
+
* options={users.map(u => ({ label: u.name, value: u.id }))}
|
|
35
|
+
* value={assignee}
|
|
36
|
+
* onValueChange={setAssignee}
|
|
37
|
+
* />
|
|
38
|
+
*
|
|
39
|
+
* // With clear button and error
|
|
40
|
+
* <FormCombobox
|
|
41
|
+
* label="Category"
|
|
42
|
+
* options={categoryOptions}
|
|
43
|
+
* showClear
|
|
44
|
+
* error={errors.category?.message}
|
|
45
|
+
* />
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export interface FormComboboxProps extends Omit<
|
|
49
|
+
React.ComponentProps<typeof Combobox>,
|
|
50
|
+
'value' | 'onValueChange' | 'children'
|
|
51
|
+
> {
|
|
52
|
+
/** Label text rendered above the combobox. */
|
|
53
|
+
label?: string
|
|
54
|
+
/** Helper text rendered below the combobox. */
|
|
55
|
+
description?: string
|
|
56
|
+
/** Error message(s). Accepts a string, array, or react-hook-form error array. */
|
|
57
|
+
error?: string | string[] | Array<{ message?: string } | undefined>
|
|
58
|
+
/** Placeholder text in the search input. */
|
|
59
|
+
placeholder?: string
|
|
60
|
+
/** Array of selectable options. */
|
|
61
|
+
options: FormComboboxOption[]
|
|
62
|
+
/** Controlled selected value. Pass `null` to clear selection. */
|
|
63
|
+
value?: string | null
|
|
64
|
+
/** Called when the user selects an option. Passes `null` when cleared. */
|
|
65
|
+
onValueChange?: (value: string | null) => void
|
|
66
|
+
/** Disables the combobox. @default false */
|
|
67
|
+
disabled?: boolean
|
|
68
|
+
/** Marks the field as required. @default false */
|
|
69
|
+
required?: boolean
|
|
70
|
+
/** Label/combobox layout direction. @default 'vertical' */
|
|
71
|
+
orientation?: VariantProps<typeof Field>['orientation']
|
|
72
|
+
className?: string
|
|
73
|
+
/** Shows a dropdown chevron button. @default true */
|
|
74
|
+
showTrigger?: boolean
|
|
75
|
+
/** Shows a clear (×) button when a value is selected. @default false */
|
|
76
|
+
showClear?: boolean
|
|
77
|
+
/** Which side of the trigger the dropdown opens on. @default 'bottom' */
|
|
78
|
+
side?: 'top' | 'bottom' | 'left' | 'right'
|
|
79
|
+
sideOffset?: number
|
|
80
|
+
align?: 'start' | 'center' | 'end'
|
|
81
|
+
alignOffset?: number
|
|
82
|
+
/** Text displayed when no options match the search query. @default 'No results found.' */
|
|
83
|
+
emptyText?: string
|
|
84
|
+
id?: string
|
|
85
|
+
name?: string
|
|
86
|
+
'aria-label'?: string
|
|
87
|
+
'aria-labelledby'?: string
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function FormCombobox({
|
|
91
|
+
label,
|
|
92
|
+
description,
|
|
93
|
+
error,
|
|
94
|
+
placeholder,
|
|
95
|
+
options,
|
|
96
|
+
value,
|
|
97
|
+
onValueChange,
|
|
98
|
+
disabled = false,
|
|
99
|
+
required = false,
|
|
100
|
+
orientation = 'vertical',
|
|
101
|
+
className,
|
|
102
|
+
showTrigger = true,
|
|
103
|
+
showClear = false,
|
|
104
|
+
side = 'bottom',
|
|
105
|
+
sideOffset = 6,
|
|
106
|
+
align = 'start',
|
|
107
|
+
alignOffset = 0,
|
|
108
|
+
emptyText = 'No results found.',
|
|
109
|
+
id,
|
|
110
|
+
name,
|
|
111
|
+
'aria-label': ariaLabel,
|
|
112
|
+
'aria-labelledby': ariaLabelledBy,
|
|
113
|
+
...comboboxProps
|
|
114
|
+
}: FormComboboxProps) {
|
|
115
|
+
const errorArray = React.useMemo(() => {
|
|
116
|
+
if (!error) return undefined
|
|
117
|
+
if (Array.isArray(error)) {
|
|
118
|
+
return error.map((e) => (typeof e === 'string' ? { message: e } : e))
|
|
119
|
+
}
|
|
120
|
+
return [{ message: error }]
|
|
121
|
+
}, [error])
|
|
122
|
+
|
|
123
|
+
const hasError = Boolean(error)
|
|
124
|
+
const generatedId = React.useId()
|
|
125
|
+
const inputId = id || generatedId
|
|
126
|
+
|
|
127
|
+
const handleValueChange = React.useCallback(
|
|
128
|
+
(newValue: unknown) => {
|
|
129
|
+
if (onValueChange) {
|
|
130
|
+
onValueChange(newValue === undefined ? null : (newValue as string))
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
[onValueChange],
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<Field orientation={orientation} className={className} data-invalid={hasError}>
|
|
138
|
+
{label && (
|
|
139
|
+
<FieldLabel htmlFor={inputId}>
|
|
140
|
+
{label}
|
|
141
|
+
{required && <span className="text-danger">*</span>}
|
|
142
|
+
</FieldLabel>
|
|
143
|
+
)}
|
|
144
|
+
<FieldContent>
|
|
145
|
+
<Combobox value={value ?? undefined} onValueChange={handleValueChange} {...comboboxProps}>
|
|
146
|
+
<ComboboxInput
|
|
147
|
+
id={inputId}
|
|
148
|
+
name={name}
|
|
149
|
+
placeholder={placeholder}
|
|
150
|
+
disabled={disabled}
|
|
151
|
+
showTrigger={showTrigger}
|
|
152
|
+
showClear={showClear}
|
|
153
|
+
aria-label={ariaLabel}
|
|
154
|
+
aria-labelledby={ariaLabelledBy}
|
|
155
|
+
aria-invalid={hasError}
|
|
156
|
+
aria-required={required}
|
|
157
|
+
/>
|
|
158
|
+
<ComboboxContent
|
|
159
|
+
side={side}
|
|
160
|
+
sideOffset={sideOffset}
|
|
161
|
+
align={align}
|
|
162
|
+
alignOffset={alignOffset}
|
|
163
|
+
>
|
|
164
|
+
<ComboboxList>
|
|
165
|
+
{options.length === 0 && emptyText && <ComboboxEmpty>{emptyText}</ComboboxEmpty>}
|
|
166
|
+
{options.map((option) => (
|
|
167
|
+
<ComboboxItem key={option.value} value={option.value} disabled={option.disabled}>
|
|
168
|
+
{option.label}
|
|
169
|
+
</ComboboxItem>
|
|
170
|
+
))}
|
|
171
|
+
</ComboboxList>
|
|
172
|
+
</ComboboxContent>
|
|
173
|
+
</Combobox>
|
|
174
|
+
{description && <FieldDescription>{description}</FieldDescription>}
|
|
175
|
+
{hasError && <FieldError errors={errorArray} />}
|
|
176
|
+
</FieldContent>
|
|
177
|
+
</Field>
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export { FormCombobox }
|