@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,213 @@
|
|
|
1
|
+
import type { VariantProps } from 'class-variance-authority'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import {
|
|
4
|
+
Combobox,
|
|
5
|
+
ComboboxChip,
|
|
6
|
+
ComboboxChips,
|
|
7
|
+
ComboboxChipsInput,
|
|
8
|
+
ComboboxContent,
|
|
9
|
+
ComboboxEmpty,
|
|
10
|
+
ComboboxItem,
|
|
11
|
+
ComboboxList,
|
|
12
|
+
ComboboxValue,
|
|
13
|
+
useComboboxAnchor,
|
|
14
|
+
} from '../_internal/combobox'
|
|
15
|
+
import { Field, FieldContent, FieldDescription, FieldError, FieldLabel } from '../_internal/field'
|
|
16
|
+
|
|
17
|
+
export interface FormMultiComboboxOption {
|
|
18
|
+
id: string
|
|
19
|
+
value: string
|
|
20
|
+
disabled?: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface FormMultiComboboxProps {
|
|
24
|
+
label?: string
|
|
25
|
+
description?: string
|
|
26
|
+
error?: string | string[] | Array<{ message?: string } | undefined>
|
|
27
|
+
placeholder?: string
|
|
28
|
+
options: FormMultiComboboxOption[]
|
|
29
|
+
value?: FormMultiComboboxOption[]
|
|
30
|
+
onValueChange?: (value: FormMultiComboboxOption[]) => void
|
|
31
|
+
disabled?: boolean
|
|
32
|
+
required?: boolean
|
|
33
|
+
orientation?: VariantProps<typeof Field>['orientation']
|
|
34
|
+
className?: string
|
|
35
|
+
// ComboboxContent props
|
|
36
|
+
side?: 'top' | 'bottom' | 'left' | 'right'
|
|
37
|
+
sideOffset?: number
|
|
38
|
+
align?: 'start' | 'center' | 'end'
|
|
39
|
+
alignOffset?: number
|
|
40
|
+
// Empty state
|
|
41
|
+
emptyText?: string
|
|
42
|
+
// Chip props
|
|
43
|
+
showRemove?: boolean
|
|
44
|
+
// Additional props
|
|
45
|
+
id?: string
|
|
46
|
+
name?: string
|
|
47
|
+
'aria-label'?: string
|
|
48
|
+
'aria-labelledby'?: string
|
|
49
|
+
// Additional Combobox props
|
|
50
|
+
defaultOpen?: boolean
|
|
51
|
+
open?: boolean
|
|
52
|
+
onOpenChange?: (open: boolean) => void
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function FormMultiCombobox({
|
|
56
|
+
label,
|
|
57
|
+
description,
|
|
58
|
+
error,
|
|
59
|
+
placeholder,
|
|
60
|
+
options,
|
|
61
|
+
value,
|
|
62
|
+
onValueChange,
|
|
63
|
+
disabled = false,
|
|
64
|
+
required = false,
|
|
65
|
+
orientation = 'vertical',
|
|
66
|
+
className,
|
|
67
|
+
side = 'bottom',
|
|
68
|
+
sideOffset = 4,
|
|
69
|
+
align = 'start',
|
|
70
|
+
alignOffset = 0,
|
|
71
|
+
emptyText = 'No results found.',
|
|
72
|
+
showRemove = true,
|
|
73
|
+
id,
|
|
74
|
+
name,
|
|
75
|
+
'aria-label': ariaLabel,
|
|
76
|
+
'aria-labelledby': ariaLabelledBy,
|
|
77
|
+
...comboboxProps
|
|
78
|
+
}: FormMultiComboboxProps) {
|
|
79
|
+
const errorArray = React.useMemo(() => {
|
|
80
|
+
if (!error) return undefined
|
|
81
|
+
if (Array.isArray(error)) {
|
|
82
|
+
return error.map((e) => (typeof e === 'string' ? { message: e } : e))
|
|
83
|
+
}
|
|
84
|
+
return [{ message: error }]
|
|
85
|
+
}, [error])
|
|
86
|
+
|
|
87
|
+
const hasError = Boolean(error)
|
|
88
|
+
const generatedId = React.useId()
|
|
89
|
+
const inputId = id || generatedId
|
|
90
|
+
const containerRef = useComboboxAnchor()
|
|
91
|
+
|
|
92
|
+
// Convert value array to the format expected by Combobox (array of option values)
|
|
93
|
+
// Always return an array to keep the component controlled
|
|
94
|
+
const comboboxValue = React.useMemo(() => {
|
|
95
|
+
if (!value || value.length === 0) return []
|
|
96
|
+
return value.map((item) => item.value)
|
|
97
|
+
}, [value])
|
|
98
|
+
|
|
99
|
+
// Handle value change from Combobox
|
|
100
|
+
const handleValueChange = React.useCallback(
|
|
101
|
+
(newValue: string[] | undefined) => {
|
|
102
|
+
if (!onValueChange) return
|
|
103
|
+
// Always ensure we pass an array, even if empty
|
|
104
|
+
if (!newValue || newValue.length === 0) {
|
|
105
|
+
onValueChange([])
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
// Map string values back to option objects
|
|
109
|
+
const selectedOptions = options.filter((option) => newValue.includes(option.value))
|
|
110
|
+
onValueChange(selectedOptions)
|
|
111
|
+
},
|
|
112
|
+
[onValueChange, options],
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<Field orientation={orientation} className={className} data-invalid={hasError}>
|
|
117
|
+
{label && (
|
|
118
|
+
<FieldLabel htmlFor={inputId}>
|
|
119
|
+
{label}
|
|
120
|
+
{required && <span className="text-danger">*</span>}
|
|
121
|
+
</FieldLabel>
|
|
122
|
+
)}
|
|
123
|
+
<FieldContent>
|
|
124
|
+
<Combobox
|
|
125
|
+
items={options}
|
|
126
|
+
multiple
|
|
127
|
+
value={comboboxValue}
|
|
128
|
+
onValueChange={handleValueChange}
|
|
129
|
+
disabled={disabled}
|
|
130
|
+
{...comboboxProps}
|
|
131
|
+
>
|
|
132
|
+
<ComboboxChips
|
|
133
|
+
ref={containerRef}
|
|
134
|
+
aria-invalid={hasError}
|
|
135
|
+
aria-required={required}
|
|
136
|
+
aria-label={ariaLabel}
|
|
137
|
+
aria-labelledby={ariaLabelledBy}
|
|
138
|
+
>
|
|
139
|
+
<ComboboxValue>
|
|
140
|
+
{(selectedValues: FormMultiComboboxOption[] | string[] | undefined) => {
|
|
141
|
+
// Handle undefined/null/empty array case when field is empty
|
|
142
|
+
if (!selectedValues || selectedValues.length === 0) {
|
|
143
|
+
return (
|
|
144
|
+
<ComboboxChipsInput
|
|
145
|
+
id={inputId}
|
|
146
|
+
name={name}
|
|
147
|
+
placeholder={placeholder}
|
|
148
|
+
disabled={disabled}
|
|
149
|
+
aria-invalid={hasError}
|
|
150
|
+
aria-required={required}
|
|
151
|
+
/>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Handle both cases: when items are provided (full objects) or when value is provided (strings)
|
|
156
|
+
// Check the first element to determine the type
|
|
157
|
+
const firstValue = selectedValues[0]
|
|
158
|
+
const selectedOptions =
|
|
159
|
+
firstValue && typeof firstValue === 'object'
|
|
160
|
+
? (selectedValues as FormMultiComboboxOption[])
|
|
161
|
+
: ((selectedValues as string[])
|
|
162
|
+
.map((val) => options.find((opt) => opt.value === val))
|
|
163
|
+
.filter(Boolean) as FormMultiComboboxOption[])
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<React.Fragment>
|
|
167
|
+
{selectedOptions.map((option) => (
|
|
168
|
+
<ComboboxChip
|
|
169
|
+
key={option.id}
|
|
170
|
+
showRemove={showRemove}
|
|
171
|
+
aria-label={`${option.value}, remove`}
|
|
172
|
+
>
|
|
173
|
+
{option.value}
|
|
174
|
+
</ComboboxChip>
|
|
175
|
+
))}
|
|
176
|
+
<ComboboxChipsInput
|
|
177
|
+
id={inputId}
|
|
178
|
+
name={name}
|
|
179
|
+
placeholder={selectedOptions.length > 0 ? '' : placeholder}
|
|
180
|
+
disabled={disabled}
|
|
181
|
+
aria-invalid={hasError}
|
|
182
|
+
aria-required={required}
|
|
183
|
+
/>
|
|
184
|
+
</React.Fragment>
|
|
185
|
+
)
|
|
186
|
+
}}
|
|
187
|
+
</ComboboxValue>
|
|
188
|
+
</ComboboxChips>
|
|
189
|
+
<ComboboxContent
|
|
190
|
+
side={side}
|
|
191
|
+
sideOffset={sideOffset}
|
|
192
|
+
align={align}
|
|
193
|
+
alignOffset={alignOffset}
|
|
194
|
+
anchor={containerRef}
|
|
195
|
+
>
|
|
196
|
+
<ComboboxList>
|
|
197
|
+
{options.length === 0 && emptyText && <ComboboxEmpty>{emptyText}</ComboboxEmpty>}
|
|
198
|
+
{options.map((option) => (
|
|
199
|
+
<ComboboxItem key={option.id} value={option.value} disabled={option.disabled}>
|
|
200
|
+
{option.value}
|
|
201
|
+
</ComboboxItem>
|
|
202
|
+
))}
|
|
203
|
+
</ComboboxList>
|
|
204
|
+
</ComboboxContent>
|
|
205
|
+
</Combobox>
|
|
206
|
+
{description && <FieldDescription>{description}</FieldDescription>}
|
|
207
|
+
{hasError && <FieldError errors={errorArray} />}
|
|
208
|
+
</FieldContent>
|
|
209
|
+
</Field>
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export { FormMultiCombobox }
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { VariantProps } from 'class-variance-authority'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ACCEPT_PRESETS,
|
|
6
|
+
type Accept,
|
|
7
|
+
DEFAULT_ACCEPT,
|
|
8
|
+
DEFAULT_MAX_SIZE,
|
|
9
|
+
DropZone,
|
|
10
|
+
DropZoneArea,
|
|
11
|
+
DropZoneContent,
|
|
12
|
+
DropZoneFileList,
|
|
13
|
+
DropZoneInput,
|
|
14
|
+
type FileRejection,
|
|
15
|
+
getRejectionMessage,
|
|
16
|
+
} from '../_internal/dropzone'
|
|
17
|
+
import { Field, FieldContent, FieldDescription, FieldError, FieldLabel } from '../_internal/field'
|
|
18
|
+
|
|
19
|
+
export interface FormMultiDropZoneProps {
|
|
20
|
+
value: File[]
|
|
21
|
+
onChange: (files: File[]) => void
|
|
22
|
+
label?: string
|
|
23
|
+
description?: string
|
|
24
|
+
prompt?: string
|
|
25
|
+
error?: string | string[] | Array<{ message?: string } | undefined>
|
|
26
|
+
maxSizeBytes?: number
|
|
27
|
+
maxFiles?: number
|
|
28
|
+
accept?: Accept
|
|
29
|
+
disabled?: boolean
|
|
30
|
+
required?: boolean
|
|
31
|
+
orientation?: VariantProps<typeof Field>['orientation']
|
|
32
|
+
className?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function FormMultiDropZone({
|
|
36
|
+
value,
|
|
37
|
+
onChange,
|
|
38
|
+
label,
|
|
39
|
+
description,
|
|
40
|
+
prompt,
|
|
41
|
+
error,
|
|
42
|
+
maxSizeBytes = DEFAULT_MAX_SIZE,
|
|
43
|
+
maxFiles,
|
|
44
|
+
accept = DEFAULT_ACCEPT,
|
|
45
|
+
disabled = false,
|
|
46
|
+
required = false,
|
|
47
|
+
orientation = 'vertical',
|
|
48
|
+
className,
|
|
49
|
+
}: FormMultiDropZoneProps) {
|
|
50
|
+
const [rejectionError, setRejectionError] = React.useState<string | null>(null)
|
|
51
|
+
|
|
52
|
+
const remainingSlots = maxFiles ? maxFiles - value.length : undefined
|
|
53
|
+
|
|
54
|
+
const onDrop = React.useCallback(
|
|
55
|
+
(acceptedFiles: File[], fileRejections: FileRejection[]) => {
|
|
56
|
+
if (acceptedFiles.length > 0) {
|
|
57
|
+
const newFiles = [...value, ...acceptedFiles]
|
|
58
|
+
// Limit to maxFiles if specified (handles cumulative selection)
|
|
59
|
+
const limitedFiles = maxFiles ? newFiles.slice(0, maxFiles) : newFiles
|
|
60
|
+
onChange(limitedFiles)
|
|
61
|
+
setRejectionError(null)
|
|
62
|
+
}
|
|
63
|
+
if (fileRejections.length > 0) {
|
|
64
|
+
const code = fileRejections[0].errors[0]?.code
|
|
65
|
+
if (code) {
|
|
66
|
+
setRejectionError(getRejectionMessage(code, maxSizeBytes, accept, maxFiles))
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
[onChange, value, maxFiles, maxSizeBytes, accept],
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
const handleRemove = React.useCallback(
|
|
74
|
+
(index: number) => {
|
|
75
|
+
const newFiles = value.filter((_, i) => i !== index)
|
|
76
|
+
onChange(newFiles)
|
|
77
|
+
setRejectionError(null)
|
|
78
|
+
},
|
|
79
|
+
[onChange, value],
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
const errorArray = React.useMemo(() => {
|
|
83
|
+
if (error) {
|
|
84
|
+
if (Array.isArray(error)) {
|
|
85
|
+
return error.map((e) => (typeof e === 'string' ? { message: e } : e))
|
|
86
|
+
}
|
|
87
|
+
return [{ message: error }]
|
|
88
|
+
}
|
|
89
|
+
if (rejectionError) {
|
|
90
|
+
return [{ message: rejectionError }]
|
|
91
|
+
}
|
|
92
|
+
return undefined
|
|
93
|
+
}, [error, rejectionError])
|
|
94
|
+
|
|
95
|
+
const hasError = Boolean(errorArray?.length)
|
|
96
|
+
const hasFiles = value.length > 0
|
|
97
|
+
const canAddMore = !maxFiles || value.length < maxFiles
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<Field orientation={orientation} className={className} data-invalid={hasError}>
|
|
101
|
+
{label && (
|
|
102
|
+
<FieldLabel>
|
|
103
|
+
{label}
|
|
104
|
+
{required && <span className="text-danger">*</span>}
|
|
105
|
+
</FieldLabel>
|
|
106
|
+
)}
|
|
107
|
+
<FieldContent>
|
|
108
|
+
<DropZone
|
|
109
|
+
onDrop={onDrop}
|
|
110
|
+
accept={accept}
|
|
111
|
+
maxSizeBytes={maxSizeBytes}
|
|
112
|
+
maxFiles={remainingSlots}
|
|
113
|
+
multiple
|
|
114
|
+
disabled={disabled || !canAddMore}
|
|
115
|
+
hasError={hasError}
|
|
116
|
+
hasFiles={hasFiles}
|
|
117
|
+
>
|
|
118
|
+
<DropZoneArea>
|
|
119
|
+
<DropZoneInput />
|
|
120
|
+
{hasFiles ? (
|
|
121
|
+
<div className="flex flex-col gap-4">
|
|
122
|
+
<DropZoneFileList files={value} onRemove={handleRemove} disabled={disabled} />
|
|
123
|
+
{canAddMore && (
|
|
124
|
+
<div className="text-muted-foreground border-t pt-4 text-center text-xs">
|
|
125
|
+
Drop more files or click to add
|
|
126
|
+
</div>
|
|
127
|
+
)}
|
|
128
|
+
</div>
|
|
129
|
+
) : (
|
|
130
|
+
<DropZoneContent description={prompt} />
|
|
131
|
+
)}
|
|
132
|
+
</DropZoneArea>
|
|
133
|
+
</DropZone>
|
|
134
|
+
{description && <FieldDescription>{description}</FieldDescription>}
|
|
135
|
+
{hasError && <FieldError errors={errorArray} />}
|
|
136
|
+
</FieldContent>
|
|
137
|
+
</Field>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export { FormMultiDropZone, ACCEPT_PRESETS }
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { RadioGroup as RadioGroupPrimitive } from '@base-ui/react/radio-group'
|
|
2
|
+
import type { VariantProps } from 'class-variance-authority'
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { Field, FieldContent, FieldDescription, FieldError, FieldLabel } from '../_internal/field'
|
|
5
|
+
import { Label } from '../_internal/label'
|
|
6
|
+
import { RadioGroup, RadioGroupItem } from '../_internal/radio-group'
|
|
7
|
+
|
|
8
|
+
export interface FormRadioGroupOption {
|
|
9
|
+
label: string
|
|
10
|
+
value: string
|
|
11
|
+
disabled?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface FormRadioGroupProps extends Omit<
|
|
15
|
+
RadioGroupPrimitive.Props,
|
|
16
|
+
'value' | 'onValueChange'
|
|
17
|
+
> {
|
|
18
|
+
label?: string
|
|
19
|
+
description?: string
|
|
20
|
+
error?: string | string[] | Array<{ message?: string } | undefined>
|
|
21
|
+
options: FormRadioGroupOption[]
|
|
22
|
+
value?: string | null
|
|
23
|
+
onValueChange?: (value: string | null) => void
|
|
24
|
+
disabled?: boolean
|
|
25
|
+
required?: boolean
|
|
26
|
+
orientation?: VariantProps<typeof Field>['orientation']
|
|
27
|
+
className?: string
|
|
28
|
+
// Additional props
|
|
29
|
+
id?: string
|
|
30
|
+
name?: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function FormRadioGroup({
|
|
34
|
+
label,
|
|
35
|
+
description,
|
|
36
|
+
error,
|
|
37
|
+
options,
|
|
38
|
+
value,
|
|
39
|
+
onValueChange,
|
|
40
|
+
disabled = false,
|
|
41
|
+
required = false,
|
|
42
|
+
orientation = 'vertical',
|
|
43
|
+
className,
|
|
44
|
+
id,
|
|
45
|
+
name,
|
|
46
|
+
...radioGroupProps
|
|
47
|
+
}: FormRadioGroupProps) {
|
|
48
|
+
const errorArray = React.useMemo(() => {
|
|
49
|
+
if (!error) return undefined
|
|
50
|
+
if (Array.isArray(error)) {
|
|
51
|
+
return error.map((e) => (typeof e === 'string' ? { message: e } : e))
|
|
52
|
+
}
|
|
53
|
+
return [{ message: error }]
|
|
54
|
+
}, [error])
|
|
55
|
+
|
|
56
|
+
const hasError = Boolean(error)
|
|
57
|
+
const generatedId = React.useId()
|
|
58
|
+
const radioGroupId = id || generatedId
|
|
59
|
+
|
|
60
|
+
// Wrap onValueChange to match the primitive's signature
|
|
61
|
+
const handleValueChange = React.useCallback(
|
|
62
|
+
(newValue: unknown) => {
|
|
63
|
+
if (onValueChange) {
|
|
64
|
+
onValueChange(typeof newValue === 'string' ? newValue : null)
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
[onValueChange],
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<Field orientation={orientation} className={className} data-invalid={hasError}>
|
|
72
|
+
{label && (
|
|
73
|
+
<FieldLabel id={`${radioGroupId}-label`}>
|
|
74
|
+
{label}
|
|
75
|
+
{required && <span className="text-danger">*</span>}
|
|
76
|
+
</FieldLabel>
|
|
77
|
+
)}
|
|
78
|
+
<FieldContent>
|
|
79
|
+
<RadioGroup
|
|
80
|
+
id={radioGroupId}
|
|
81
|
+
value={value ?? undefined}
|
|
82
|
+
onValueChange={handleValueChange}
|
|
83
|
+
disabled={disabled}
|
|
84
|
+
aria-invalid={hasError}
|
|
85
|
+
aria-required={required}
|
|
86
|
+
aria-labelledby={label ? `${radioGroupId}-label` : undefined}
|
|
87
|
+
{...radioGroupProps}
|
|
88
|
+
>
|
|
89
|
+
{options.map((option) => {
|
|
90
|
+
const optionId = `${radioGroupId}-${option.value}`
|
|
91
|
+
return (
|
|
92
|
+
<div key={option.value} className="flex items-center space-x-2">
|
|
93
|
+
<RadioGroupItem
|
|
94
|
+
value={option.value}
|
|
95
|
+
id={optionId}
|
|
96
|
+
disabled={disabled || option.disabled}
|
|
97
|
+
aria-invalid={hasError}
|
|
98
|
+
/>
|
|
99
|
+
<Label htmlFor={optionId} className="text-sm font-normal cursor-pointer">
|
|
100
|
+
{option.label}
|
|
101
|
+
</Label>
|
|
102
|
+
</div>
|
|
103
|
+
)
|
|
104
|
+
})}
|
|
105
|
+
</RadioGroup>
|
|
106
|
+
{name && (
|
|
107
|
+
<input type="hidden" name={name} value={value ?? ''} aria-hidden="true" tabIndex={-1} />
|
|
108
|
+
)}
|
|
109
|
+
{description && <FieldDescription>{description}</FieldDescription>}
|
|
110
|
+
{hasError && <FieldError errors={errorArray} />}
|
|
111
|
+
</FieldContent>
|
|
112
|
+
</Field>
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { FormRadioGroup }
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type { VariantProps } from 'class-variance-authority'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import { Field, FieldContent, FieldDescription, FieldError, FieldLabel } from '../_internal/field'
|
|
5
|
+
import {
|
|
6
|
+
Select,
|
|
7
|
+
SelectContent,
|
|
8
|
+
SelectItem,
|
|
9
|
+
SelectScrollDownButton,
|
|
10
|
+
SelectScrollUpButton,
|
|
11
|
+
SelectTrigger,
|
|
12
|
+
SelectValue,
|
|
13
|
+
} from '../_internal/select'
|
|
14
|
+
|
|
15
|
+
/** A single option in a FormSelect. */
|
|
16
|
+
export interface FormSelectOption {
|
|
17
|
+
/** Display label shown in the dropdown. */
|
|
18
|
+
label: string
|
|
19
|
+
/** Value submitted when this option is selected. */
|
|
20
|
+
value: string
|
|
21
|
+
/** Prevents this option from being selected. */
|
|
22
|
+
disabled?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Props for the opinionated FormSelect component.
|
|
27
|
+
*
|
|
28
|
+
* Wraps a Select dropdown with a Field (label + description + error) and
|
|
29
|
+
* accepts a flat `options` array rather than requiring manual `SelectItem` assembly.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* <FormSelect
|
|
34
|
+
* label="Country"
|
|
35
|
+
* options={[
|
|
36
|
+
* { label: 'United Kingdom', value: 'gb' },
|
|
37
|
+
* { label: 'United States', value: 'us' },
|
|
38
|
+
* ]}
|
|
39
|
+
* value={country}
|
|
40
|
+
* onValueChange={setCountry}
|
|
41
|
+
* />
|
|
42
|
+
*
|
|
43
|
+
* // With error and placeholder
|
|
44
|
+
* <FormSelect
|
|
45
|
+
* label="Status"
|
|
46
|
+
* placeholder="Choose a status..."
|
|
47
|
+
* options={statusOptions}
|
|
48
|
+
* error={errors.status?.message}
|
|
49
|
+
* required
|
|
50
|
+
* />
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export interface FormSelectProps {
|
|
54
|
+
ref?: React.Ref<HTMLButtonElement>
|
|
55
|
+
/** Label text rendered above the select. */
|
|
56
|
+
label?: string
|
|
57
|
+
/** Helper text rendered below the select. */
|
|
58
|
+
description?: string
|
|
59
|
+
/** Error message(s). Accepts a string, array, or react-hook-form error array. */
|
|
60
|
+
error?: string | string[] | Array<{ message?: string } | undefined>
|
|
61
|
+
/** Placeholder text shown when no value is selected. @default 'Select an option...' */
|
|
62
|
+
placeholder?: string
|
|
63
|
+
/** Array of selectable options. */
|
|
64
|
+
options: FormSelectOption[]
|
|
65
|
+
/** Controlled selected value. Pass `null` to clear selection. */
|
|
66
|
+
value?: string | null
|
|
67
|
+
/** Called when the user selects an option. Passes `null` when cleared. */
|
|
68
|
+
onValueChange?: (value: string | null) => void
|
|
69
|
+
/** Disables the select. @default false */
|
|
70
|
+
disabled?: boolean
|
|
71
|
+
/** Marks the field as required. @default false */
|
|
72
|
+
required?: boolean
|
|
73
|
+
/** Label/select layout direction. @default 'vertical' */
|
|
74
|
+
orientation?: VariantProps<typeof Field>['orientation']
|
|
75
|
+
/** Trigger size variant. @default 'default' */
|
|
76
|
+
size?: 'sm' | 'default'
|
|
77
|
+
className?: string
|
|
78
|
+
/** Which side of the trigger the dropdown opens on. @default 'bottom' */
|
|
79
|
+
side?: 'top' | 'bottom' | 'left' | 'right'
|
|
80
|
+
sideOffset?: number
|
|
81
|
+
align?: 'start' | 'center' | 'end'
|
|
82
|
+
alignOffset?: number
|
|
83
|
+
alignItemWithTrigger?: boolean
|
|
84
|
+
id?: string
|
|
85
|
+
name?: string
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function FormSelect({
|
|
89
|
+
ref,
|
|
90
|
+
label,
|
|
91
|
+
description,
|
|
92
|
+
error,
|
|
93
|
+
placeholder = 'Select an option...',
|
|
94
|
+
options,
|
|
95
|
+
value,
|
|
96
|
+
onValueChange,
|
|
97
|
+
disabled = false,
|
|
98
|
+
required = false,
|
|
99
|
+
orientation = 'vertical',
|
|
100
|
+
size = 'default',
|
|
101
|
+
className,
|
|
102
|
+
side = 'bottom',
|
|
103
|
+
sideOffset = 4,
|
|
104
|
+
align = 'center',
|
|
105
|
+
alignOffset = 0,
|
|
106
|
+
alignItemWithTrigger = true,
|
|
107
|
+
...selectProps
|
|
108
|
+
}: FormSelectProps) {
|
|
109
|
+
const errorArray = React.useMemo(() => {
|
|
110
|
+
if (!error) return undefined
|
|
111
|
+
if (Array.isArray(error)) {
|
|
112
|
+
return error.map((e) => (typeof e === 'string' ? { message: e } : e))
|
|
113
|
+
}
|
|
114
|
+
return [{ message: error }]
|
|
115
|
+
}, [error])
|
|
116
|
+
|
|
117
|
+
const hasError = Boolean(error)
|
|
118
|
+
const generatedId = React.useId()
|
|
119
|
+
const selectId = selectProps.id || generatedId
|
|
120
|
+
|
|
121
|
+
// Find the selected option's label to display instead of the value
|
|
122
|
+
const selectedOption = React.useMemo(() => {
|
|
123
|
+
if (!value) return null
|
|
124
|
+
return options.find((option) => option.value === value) ?? null
|
|
125
|
+
}, [value, options])
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<Field orientation={orientation} className={className} data-invalid={hasError}>
|
|
129
|
+
{label && (
|
|
130
|
+
<FieldLabel id={`${selectId}-label`} htmlFor={selectId}>
|
|
131
|
+
{label}
|
|
132
|
+
{required && <span className="text-danger">*</span>}
|
|
133
|
+
</FieldLabel>
|
|
134
|
+
)}
|
|
135
|
+
<FieldContent>
|
|
136
|
+
<Select value={value ?? undefined} onValueChange={onValueChange} disabled={disabled}>
|
|
137
|
+
<SelectTrigger
|
|
138
|
+
ref={ref}
|
|
139
|
+
size={size}
|
|
140
|
+
aria-invalid={hasError}
|
|
141
|
+
aria-required={required}
|
|
142
|
+
id={selectId}
|
|
143
|
+
name={selectProps.name}
|
|
144
|
+
aria-labelledby={label ? `${selectId}-label` : undefined}
|
|
145
|
+
className="w-full"
|
|
146
|
+
>
|
|
147
|
+
<SelectValue>
|
|
148
|
+
{selectedOption === null || selectedOption === undefined
|
|
149
|
+
? placeholder
|
|
150
|
+
: selectedOption.label}
|
|
151
|
+
</SelectValue>
|
|
152
|
+
</SelectTrigger>
|
|
153
|
+
<SelectContent
|
|
154
|
+
side={side}
|
|
155
|
+
sideOffset={sideOffset}
|
|
156
|
+
align={align}
|
|
157
|
+
alignOffset={alignOffset}
|
|
158
|
+
alignItemWithTrigger={alignItemWithTrigger}
|
|
159
|
+
>
|
|
160
|
+
<SelectScrollUpButton />
|
|
161
|
+
{options.map((option) => (
|
|
162
|
+
<SelectItem key={option.value} value={option.value} disabled={option.disabled}>
|
|
163
|
+
{option.label}
|
|
164
|
+
</SelectItem>
|
|
165
|
+
))}
|
|
166
|
+
<SelectScrollDownButton />
|
|
167
|
+
</SelectContent>
|
|
168
|
+
</Select>
|
|
169
|
+
{description && <FieldDescription>{description}</FieldDescription>}
|
|
170
|
+
{hasError && <FieldError errors={errorArray} />}
|
|
171
|
+
</FieldContent>
|
|
172
|
+
</Field>
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export { FormSelect }
|