@whity/ui 0.0.0-stage → 1.0.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/README.md +106 -2
- package/package.json +219 -4
- package/src/access-denied.stories.tsx +179 -0
- package/src/access-denied.tsx +305 -0
- package/src/action-proposal.tsx +338 -0
- package/src/actor-chip.tsx +71 -0
- package/src/agent-activity.tsx +163 -0
- package/src/agent-collaboration.stories.tsx +156 -0
- package/src/agent-run-status.tsx +196 -0
- package/src/alert-dialog.stories.tsx +45 -0
- package/src/alert-dialog.tsx +147 -0
- package/src/alert.stories.tsx +91 -0
- package/src/alert.tsx +89 -0
- package/src/app-sidebar.stories.tsx +195 -0
- package/src/app-sidebar.tsx +604 -0
- package/src/approval-queue.tsx +109 -0
- package/src/audience-group-picker.stories.tsx +198 -0
- package/src/audience-group-picker.tsx +362 -0
- package/src/audience-people-picker.stories.tsx +102 -0
- package/src/audience-people-picker.tsx +279 -0
- package/src/avatar-pattern.ts +138 -0
- package/src/avatar.tsx +125 -0
- package/src/badge.stories.tsx +105 -0
- package/src/badge.tsx +68 -0
- package/src/beta-warning.stories.tsx +79 -0
- package/src/beta-warning.tsx +189 -0
- package/src/bilingual-input.stories.tsx +82 -0
- package/src/bilingual-input.tsx +188 -0
- package/src/board.tsx +216 -0
- package/src/breadcrumb.stories.tsx +51 -0
- package/src/breadcrumb.tsx +90 -0
- package/src/built-on-whity.tsx +52 -0
- package/src/button.stories.tsx +87 -0
- package/src/button.tsx +123 -0
- package/src/card.stories.tsx +423 -0
- package/src/card.tsx +180 -0
- package/src/chart.stories.tsx +66 -0
- package/src/chart.tsx +228 -0
- package/src/checkbox.stories.tsx +62 -0
- package/src/checkbox.tsx +54 -0
- package/src/collapsible.stories.tsx +48 -0
- package/src/collapsible.tsx +34 -0
- package/src/color-card.stories.tsx +61 -0
- package/src/color-card.tsx +270 -0
- package/src/color-picker.stories.tsx +65 -0
- package/src/color-picker.tsx +425 -0
- package/src/column-matcher.tsx +84 -0
- package/src/command-palette.tsx +398 -0
- package/src/confirm-action.tsx +98 -0
- package/src/copy-block.stories.tsx +38 -0
- package/src/copy-block.tsx +85 -0
- package/src/data-table.stories.tsx +200 -0
- package/src/data-table.tsx +1686 -0
- package/src/date-picker.stories.tsx +61 -0
- package/src/date-picker.tsx +456 -0
- package/src/design-cards.stories.tsx +551 -0
- package/src/dialog.stories.tsx +48 -0
- package/src/dialog.tsx +179 -0
- package/src/display-preferences.tsx +50 -0
- package/src/documents/barcode-svg.stories.tsx +72 -0
- package/src/documents/barcode-svg.tsx +79 -0
- package/src/dropdown-menu.stories.tsx +77 -0
- package/src/dropdown-menu.tsx +271 -0
- package/src/editor/agent-panel.tsx +222 -0
- package/src/editor/agents.stories.tsx +81 -0
- package/src/editor/agents.ts +55 -0
- package/src/editor/behaviour.ts +279 -0
- package/src/editor/block-ids.ts +44 -0
- package/src/editor/block-list.tsx +104 -0
- package/src/editor/block-toolbar.tsx +490 -0
- package/src/editor/bubble.tsx +119 -0
- package/src/editor/catalogue.ts +169 -0
- package/src/editor/collab-rail.tsx +746 -0
- package/src/editor/collab.stories.tsx +207 -0
- package/src/editor/collab.ts +87 -0
- package/src/editor/contract.ts +476 -0
- package/src/editor/convert.ts +414 -0
- package/src/editor/doc-editor.stories.tsx +98 -0
- package/src/editor/doc-editor.tsx +1492 -0
- package/src/editor/editor.css +636 -0
- package/src/editor/extensions.ts +86 -0
- package/src/editor/field-bar.tsx +154 -0
- package/src/editor/field-picker.tsx +109 -0
- package/src/editor/fields.ts +100 -0
- package/src/editor/gutter.tsx +443 -0
- package/src/editor/index.ts +23 -0
- package/src/editor/label-sheet.tsx +289 -0
- package/src/editor/labels.ts +394 -0
- package/src/editor/link-tools.tsx +141 -0
- package/src/editor/node-views.tsx +461 -0
- package/src/editor/page-view.tsx +372 -0
- package/src/editor/phone.tsx +310 -0
- package/src/editor/plugin-block-view.tsx +230 -0
- package/src/editor/plugin-blocks.stories.tsx +96 -0
- package/src/editor/plugin-blocks.ts +52 -0
- package/src/editor/publish-check.tsx +201 -0
- package/src/editor/rich-blocks.stories.tsx +146 -0
- package/src/editor/sample.ts +40 -0
- package/src/editor/save-block-dialog.tsx +141 -0
- package/src/editor/saved-block-view.tsx +205 -0
- package/src/editor/saved-blocks.stories.tsx +105 -0
- package/src/editor/saved-parts.ts +192 -0
- package/src/editor/schema-rich.ts +156 -0
- package/src/editor/schema.ts +368 -0
- package/src/editor/services.tsx +205 -0
- package/src/editor/slash.ts +64 -0
- package/src/editor/suggesting.ts +372 -0
- package/src/editor/suggestions.ts +763 -0
- package/src/editor/table-keys.ts +66 -0
- package/src/editor/templates.stories.tsx +324 -0
- package/src/editor/toolbar.tsx +364 -0
- package/src/empty-state.stories.tsx +51 -0
- package/src/empty-state.tsx +126 -0
- package/src/empty-state.usage-notes.md +30 -0
- package/src/form.stories.tsx +112 -0
- package/src/form.tsx +176 -0
- package/src/globals.css +20 -0
- package/src/icon-button.tsx +85 -0
- package/src/icon-map.ts +335 -0
- package/src/icon.tsx +41 -0
- package/src/index.ts +90 -0
- package/src/input.stories.tsx +157 -0
- package/src/input.tsx +768 -0
- package/src/kpi-strip.tsx +47 -0
- package/src/localized-text.ts +76 -0
- package/src/locked-screen.stories.tsx +29 -0
- package/src/locked-screen.tsx +75 -0
- package/src/lockup.tsx +42 -0
- package/src/lottie.tsx +441 -0
- package/src/mark.tsx +62 -0
- package/src/math-text.stories.tsx +33 -0
- package/src/math-text.tsx +43 -0
- package/src/menu-bar.stories.tsx +198 -0
- package/src/menu-bar.tsx +373 -0
- package/src/message-thread.tsx +181 -0
- package/src/money/currency.ts +244 -0
- package/src/money/money-input.tsx +131 -0
- package/src/money/money.tsx +33 -0
- package/src/open-on-computer.tsx +150 -0
- package/src/otp-input.tsx +161 -0
- package/src/page-header.stories.tsx +95 -0
- package/src/page-header.tsx +122 -0
- package/src/page-shell.stories.tsx +42 -0
- package/src/page-shell.tsx +32 -0
- package/src/page-states.tsx +277 -0
- package/src/pagination.stories.tsx +45 -0
- package/src/pagination.tsx +98 -0
- package/src/paper-sheet.stories.tsx +88 -0
- package/src/paper-sheet.tsx +85 -0
- package/src/phone-tab-bar.tsx +152 -0
- package/src/plugin-card.stories.tsx +208 -0
- package/src/plugin-card.tsx +931 -0
- package/src/popover.stories.tsx +48 -0
- package/src/popover.tsx +55 -0
- package/src/radio-group.stories.tsx +26 -0
- package/src/radio-group.tsx +44 -0
- package/src/route-flow/editor.tsx +1087 -0
- package/src/route-flow/model.ts +771 -0
- package/src/save-bar.tsx +94 -0
- package/src/scope-grant.tsx +139 -0
- package/src/screen-too-small.stories.tsx +61 -0
- package/src/screen-too-small.tsx +104 -0
- package/src/search-field.tsx +65 -0
- package/src/select.stories.tsx +44 -0
- package/src/select.tsx +197 -0
- package/src/separator.stories.tsx +34 -0
- package/src/separator.tsx +34 -0
- package/src/sheet.stories.tsx +49 -0
- package/src/sheet.tsx +168 -0
- package/src/skeleton.stories.tsx +28 -0
- package/src/skeleton.tsx +19 -0
- package/src/slider.stories.tsx +78 -0
- package/src/slider.tsx +300 -0
- package/src/spinner.stories.tsx +33 -0
- package/src/spinner.tsx +55 -0
- package/src/stepper.tsx +85 -0
- package/src/switch.stories.tsx +42 -0
- package/src/switch.tsx +41 -0
- package/src/switcher.stories.tsx +111 -0
- package/src/switcher.tsx +131 -0
- package/src/system-state.tsx +55 -0
- package/src/table.stories.tsx +48 -0
- package/src/table.tsx +121 -0
- package/src/tabs.stories.tsx +74 -0
- package/src/tabs.tsx +90 -0
- package/src/tag-input.stories.tsx +67 -0
- package/src/tag-input.tsx +117 -0
- package/src/tenant-logo.tsx +63 -0
- package/src/tenant-switcher.stories.tsx +38 -0
- package/src/tenant-switcher.tsx +164 -0
- package/src/textarea.stories.tsx +27 -0
- package/src/textarea.tsx +18 -0
- package/src/theme-mode.ts +52 -0
- package/src/time-grid.tsx +163 -0
- package/src/time-picker.stories.tsx +62 -0
- package/src/time-picker.tsx +615 -0
- package/src/toggle-group.tsx +138 -0
- package/src/tooltip.stories.tsx +43 -0
- package/src/tooltip.tsx +73 -0
- package/src/top-nav.stories.tsx +58 -0
- package/src/top-nav.tsx +324 -0
- package/src/undo-bar.tsx +107 -0
- package/src/utils.ts +45 -0
- package/src/view-toggle.stories.tsx +84 -0
- package/src/view-toggle.tsx +110 -0
package/src/input.tsx
ADDED
|
@@ -0,0 +1,768 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import {
|
|
3
|
+
IconCalendarTime,
|
|
4
|
+
IconCloudUpload,
|
|
5
|
+
IconEye,
|
|
6
|
+
IconEyeOff,
|
|
7
|
+
IconInfoCircle,
|
|
8
|
+
IconMinus,
|
|
9
|
+
IconPaperclip,
|
|
10
|
+
IconPlus,
|
|
11
|
+
IconSearch,
|
|
12
|
+
IconX,
|
|
13
|
+
} from "@tabler/icons-react"
|
|
14
|
+
|
|
15
|
+
import { cn } from "./utils"
|
|
16
|
+
import { DatePicker } from "./date-picker"
|
|
17
|
+
import { TimePicker } from "./time-picker"
|
|
18
|
+
import { ColorPicker } from "./color-picker"
|
|
19
|
+
import { Slider } from "./slider"
|
|
20
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./tooltip"
|
|
21
|
+
|
|
22
|
+
export interface InputProps extends React.ComponentProps<"input"> {
|
|
23
|
+
/**
|
|
24
|
+
* Field label text or node displayed statically above the input field.
|
|
25
|
+
*/
|
|
26
|
+
label?: React.ReactNode
|
|
27
|
+
/**
|
|
28
|
+
* Displays a required asterisk (*) next to the label.
|
|
29
|
+
*/
|
|
30
|
+
required?: boolean
|
|
31
|
+
/**
|
|
32
|
+
* Tooltip message displayed in an interactive info icon next to the label.
|
|
33
|
+
*/
|
|
34
|
+
tooltip?: React.ReactNode
|
|
35
|
+
/**
|
|
36
|
+
* Small informational note rendered below the input field.
|
|
37
|
+
*/
|
|
38
|
+
helperText?: React.ReactNode
|
|
39
|
+
/**
|
|
40
|
+
* Error text rendered below the input field in destructive red.
|
|
41
|
+
*/
|
|
42
|
+
errorText?: React.ReactNode
|
|
43
|
+
/**
|
|
44
|
+
* For type="password", automatically renders a toggle button to show/hide
|
|
45
|
+
* password text. Defaults to true. Set to false to disable the toggle button.
|
|
46
|
+
*/
|
|
47
|
+
showPasswordToggle?: boolean
|
|
48
|
+
/**
|
|
49
|
+
* For type="number", automatically removes default browser spinner arrows and
|
|
50
|
+
* renders custom +/- stepper buttons. Defaults to true. Set to false to disable.
|
|
51
|
+
*/
|
|
52
|
+
showNumberStepper?: boolean
|
|
53
|
+
/**
|
|
54
|
+
* For type="file", chooses between a prominent drag-and-drop upload zone ("dropzone", default)
|
|
55
|
+
* or a compact inline file picker ("compact").
|
|
56
|
+
*/
|
|
57
|
+
fileVariant?: "dropzone" | "compact"
|
|
58
|
+
/** Accessible name for a tooltip trigger. Defaults to "More information". */
|
|
59
|
+
tooltipTriggerLabel?: string
|
|
60
|
+
/** For type="date": the picker's own words, for hosts that translate them. */
|
|
61
|
+
datePickerLabels?: {
|
|
62
|
+
/** The language of the calendar's month and weekday names (see DatePicker). */
|
|
63
|
+
locale?: string
|
|
64
|
+
placeholder?: string
|
|
65
|
+
clear?: string
|
|
66
|
+
today?: string
|
|
67
|
+
clearButton?: string
|
|
68
|
+
previousMonth?: string
|
|
69
|
+
nextMonth?: string
|
|
70
|
+
}
|
|
71
|
+
/** Accessible name for the password reveal toggle, by state. */
|
|
72
|
+
showPasswordLabel?: string
|
|
73
|
+
hidePasswordLabel?: string
|
|
74
|
+
/** Accessible names for the number stepper buttons. */
|
|
75
|
+
decrementLabel?: string
|
|
76
|
+
incrementLabel?: string
|
|
77
|
+
/**
|
|
78
|
+
* Prompt inside the file dropzone. A NODE, not a string, because the
|
|
79
|
+
* default is one sentence with a link-styled span inside it ("Click to
|
|
80
|
+
* browse or drag and drop files"). Splitting that into two string props
|
|
81
|
+
* would hand a translator two fragments they cannot reorder, which is
|
|
82
|
+
* exactly what a whole-sentence key avoids — so the caller passes the
|
|
83
|
+
* finished node instead.
|
|
84
|
+
*/
|
|
85
|
+
dropzonePrompt?: React.ReactNode
|
|
86
|
+
/** Hint under the dropzone prompt, by `multiple`. */
|
|
87
|
+
multipleFilesHint?: string
|
|
88
|
+
singleFileHint?: string
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function formatBytes(bytes: number): string {
|
|
92
|
+
if (!bytes || bytes <= 0) return "0 B"
|
|
93
|
+
const k = 1024
|
|
94
|
+
const sizes = ["B", "KB", "MB", "GB"]
|
|
95
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
|
96
|
+
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}`
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The picked day as YYYY-MM-DD, as the person sees it. toISOString() would give UTC's day. */
|
|
100
|
+
function toDateValue(date: Date): string {
|
|
101
|
+
const month = String(date.getMonth() + 1).padStart(2, "0")
|
|
102
|
+
const day = String(date.getDate()).padStart(2, "0")
|
|
103
|
+
|
|
104
|
+
return `${String(date.getFullYear()).padStart(4, "0")}-${month}-${day}`
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
108
|
+
(
|
|
109
|
+
{
|
|
110
|
+
className,
|
|
111
|
+
type,
|
|
112
|
+
label,
|
|
113
|
+
required,
|
|
114
|
+
tooltip,
|
|
115
|
+
helperText,
|
|
116
|
+
errorText,
|
|
117
|
+
showPasswordToggle = true,
|
|
118
|
+
showNumberStepper = true,
|
|
119
|
+
fileVariant = "dropzone",
|
|
120
|
+
tooltipTriggerLabel = "More information",
|
|
121
|
+
datePickerLabels,
|
|
122
|
+
showPasswordLabel = "Show password",
|
|
123
|
+
hidePasswordLabel = "Hide password",
|
|
124
|
+
decrementLabel = "Decrease value",
|
|
125
|
+
incrementLabel = "Increase value",
|
|
126
|
+
dropzonePrompt,
|
|
127
|
+
multipleFilesHint = "Upload multiple files",
|
|
128
|
+
singleFileHint = "Upload single file",
|
|
129
|
+
disabled,
|
|
130
|
+
id,
|
|
131
|
+
...props
|
|
132
|
+
},
|
|
133
|
+
ref
|
|
134
|
+
) => {
|
|
135
|
+
const internalRef = React.useRef<HTMLInputElement>(null)
|
|
136
|
+
React.useImperativeHandle(ref, () => internalRef.current!)
|
|
137
|
+
|
|
138
|
+
// Generate a unique ID for the input if not provided and label exists.
|
|
139
|
+
// This ensures proper label association for accessibility.
|
|
140
|
+
// If id is provided, always use it. Otherwise, generate one only if label exists.
|
|
141
|
+
const inputId = React.useMemo(() => {
|
|
142
|
+
if (id) return id
|
|
143
|
+
if (label) {
|
|
144
|
+
return `input-${Math.random().toString(36).substr(2, 9)}`
|
|
145
|
+
}
|
|
146
|
+
return undefined
|
|
147
|
+
}, [id, label])
|
|
148
|
+
|
|
149
|
+
const [showPassword, setShowPassword] = React.useState(false)
|
|
150
|
+
const [selectedFiles, setSelectedFiles] = React.useState<File[]>([])
|
|
151
|
+
const [isDragging, setIsDragging] = React.useState(false)
|
|
152
|
+
|
|
153
|
+
const handleStep = (direction: 1 | -1) => {
|
|
154
|
+
const input = internalRef.current
|
|
155
|
+
if (!input || disabled) return
|
|
156
|
+
try {
|
|
157
|
+
if (direction === 1) {
|
|
158
|
+
input.stepUp()
|
|
159
|
+
} else {
|
|
160
|
+
input.stepDown()
|
|
161
|
+
}
|
|
162
|
+
} catch {
|
|
163
|
+
const current = Number(input.value) || 0
|
|
164
|
+
const step = Number(props.step) || 1
|
|
165
|
+
input.value = String(current + direction * step)
|
|
166
|
+
}
|
|
167
|
+
const nativeSetter = Object.getOwnPropertyDescriptor(
|
|
168
|
+
window.HTMLInputElement.prototype,
|
|
169
|
+
"value"
|
|
170
|
+
)?.set
|
|
171
|
+
nativeSetter?.call(input, input.value)
|
|
172
|
+
input.dispatchEvent(new Event("input", { bubbles: true }))
|
|
173
|
+
input.dispatchEvent(new Event("change", { bubbles: true }))
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
177
|
+
if (e.target.files) {
|
|
178
|
+
const filesArr = Array.from(e.target.files)
|
|
179
|
+
setSelectedFiles(filesArr)
|
|
180
|
+
}
|
|
181
|
+
props.onChange?.(e)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const handleDropFiles = (droppedFiles: File[]) => {
|
|
185
|
+
if (disabled || droppedFiles.length === 0) return
|
|
186
|
+
let nextFiles = droppedFiles
|
|
187
|
+
if (!props.multiple) {
|
|
188
|
+
nextFiles = [droppedFiles[0]]
|
|
189
|
+
} else {
|
|
190
|
+
const existingKeys = new Set(selectedFiles.map((f) => `${f.name}-${f.size}`))
|
|
191
|
+
const added = droppedFiles.filter((f) => !existingKeys.has(`${f.name}-${f.size}`))
|
|
192
|
+
nextFiles = [...selectedFiles, ...added]
|
|
193
|
+
}
|
|
194
|
+
setSelectedFiles(nextFiles)
|
|
195
|
+
|
|
196
|
+
const input = internalRef.current
|
|
197
|
+
if (input) {
|
|
198
|
+
const dt = new DataTransfer()
|
|
199
|
+
nextFiles.forEach((f) => dt.items.add(f))
|
|
200
|
+
const nativeSetter = Object.getOwnPropertyDescriptor(
|
|
201
|
+
window.HTMLInputElement.prototype,
|
|
202
|
+
"files"
|
|
203
|
+
)?.set
|
|
204
|
+
nativeSetter?.call(input, dt.files)
|
|
205
|
+
input.dispatchEvent(new Event("input", { bubbles: true }))
|
|
206
|
+
input.dispatchEvent(new Event("change", { bubbles: true }))
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const handleRemoveFile = (indexToRemove: number) => {
|
|
211
|
+
const nextFiles = selectedFiles.filter((_, i) => i !== indexToRemove)
|
|
212
|
+
setSelectedFiles(nextFiles)
|
|
213
|
+
|
|
214
|
+
const input = internalRef.current
|
|
215
|
+
if (input) {
|
|
216
|
+
const dt = new DataTransfer()
|
|
217
|
+
nextFiles.forEach((file) => dt.items.add(file))
|
|
218
|
+
const nativeSetter = Object.getOwnPropertyDescriptor(
|
|
219
|
+
window.HTMLInputElement.prototype,
|
|
220
|
+
"files"
|
|
221
|
+
)?.set
|
|
222
|
+
nativeSetter?.call(input, dt.files)
|
|
223
|
+
input.dispatchEvent(new Event("input", { bubbles: true }))
|
|
224
|
+
input.dispatchEvent(new Event("change", { bubbles: true }))
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const isPassword = type === "password" && showPasswordToggle
|
|
229
|
+
const isNumber = type === "number" && showNumberStepper
|
|
230
|
+
const isFile = type === "file"
|
|
231
|
+
const isDate = type === "date"
|
|
232
|
+
const isTime = type === "time"
|
|
233
|
+
const isColor = type === "color"
|
|
234
|
+
const isDateTime = type === "datetime-local"
|
|
235
|
+
const isSearch = type === "search"
|
|
236
|
+
const isSlider = type === "range" || type === "slider"
|
|
237
|
+
|
|
238
|
+
/*
|
|
239
|
+
HOW A PICKER REPORTS A CHOICE.
|
|
240
|
+
|
|
241
|
+
The pickers are not inputs, so a choice reaches the caller's onChange as a
|
|
242
|
+
real change event from a hidden input, which also carries `name` for a
|
|
243
|
+
plain form post. React compares the input's value with the last one it saw,
|
|
244
|
+
through its own wrapper around `.value`. So the value has to be written with
|
|
245
|
+
the browser's setter ONLY: writing `.value` first tells React about it, the
|
|
246
|
+
event then looks like no change, and the choice is dropped with no error.
|
|
247
|
+
*/
|
|
248
|
+
const reportPickerValue = (val: string) => {
|
|
249
|
+
const input = internalRef.current
|
|
250
|
+
if (!input) return
|
|
251
|
+
Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")?.set?.call(
|
|
252
|
+
input,
|
|
253
|
+
val
|
|
254
|
+
)
|
|
255
|
+
input.dispatchEvent(new Event("input", { bubbles: true }))
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/*
|
|
259
|
+
Follows the caller's value, so choosing the same day again after a form
|
|
260
|
+
reset still counts as a change.
|
|
261
|
+
|
|
262
|
+
Only a date keeps its own type. Time and colour pickers report forms a typed
|
|
263
|
+
input would blank ("03:30 PM"), and a range input would clamp to its limits.
|
|
264
|
+
*/
|
|
265
|
+
const pickerInput = (backingType: "date" | "text") => (
|
|
266
|
+
<input
|
|
267
|
+
ref={internalRef}
|
|
268
|
+
type={backingType}
|
|
269
|
+
hidden
|
|
270
|
+
name={props.name}
|
|
271
|
+
{...(props.value !== undefined
|
|
272
|
+
? { value: String(props.value), onChange: props.onChange ?? (() => undefined) }
|
|
273
|
+
: { defaultValue: props.defaultValue, onChange: props.onChange })}
|
|
274
|
+
/>
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
const renderInputControl = () => {
|
|
278
|
+
if (isSlider) {
|
|
279
|
+
return (
|
|
280
|
+
<>
|
|
281
|
+
{pickerInput("text")}
|
|
282
|
+
<Slider
|
|
283
|
+
disabled={disabled}
|
|
284
|
+
className={className}
|
|
285
|
+
min={props.min !== undefined ? Number(props.min) : 0}
|
|
286
|
+
max={props.max !== undefined ? Number(props.max) : 100}
|
|
287
|
+
step={props.step !== undefined ? Number(props.step) : 1}
|
|
288
|
+
defaultValue={props.defaultValue !== undefined ? [Number(props.defaultValue)] : [0]}
|
|
289
|
+
value={props.value !== undefined ? [Number(props.value)] : undefined}
|
|
290
|
+
onValueChange={(vals) => {
|
|
291
|
+
reportPickerValue(String(vals[0]))
|
|
292
|
+
}}
|
|
293
|
+
/>
|
|
294
|
+
</>
|
|
295
|
+
)
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (isColor) {
|
|
299
|
+
return (
|
|
300
|
+
<>
|
|
301
|
+
{pickerInput("text")}
|
|
302
|
+
<ColorPicker
|
|
303
|
+
id={inputId}
|
|
304
|
+
disabled={disabled}
|
|
305
|
+
className={className}
|
|
306
|
+
placeholder={props.placeholder}
|
|
307
|
+
defaultValue={props.defaultValue as string}
|
|
308
|
+
value={props.value as string}
|
|
309
|
+
onChange={(c) => {
|
|
310
|
+
reportPickerValue(c || "")
|
|
311
|
+
}}
|
|
312
|
+
/>
|
|
313
|
+
</>
|
|
314
|
+
)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (isDate) {
|
|
318
|
+
return (
|
|
319
|
+
<>
|
|
320
|
+
{pickerInput("date")}
|
|
321
|
+
<DatePicker
|
|
322
|
+
id={inputId}
|
|
323
|
+
disabled={disabled}
|
|
324
|
+
className={className}
|
|
325
|
+
placeholder={props.placeholder ?? datePickerLabels?.placeholder}
|
|
326
|
+
clearLabel={datePickerLabels?.clear}
|
|
327
|
+
todayLabel={datePickerLabels?.today}
|
|
328
|
+
clearButtonLabel={datePickerLabels?.clearButton}
|
|
329
|
+
previousMonthLabel={datePickerLabels?.previousMonth}
|
|
330
|
+
nextMonthLabel={datePickerLabels?.nextMonth}
|
|
331
|
+
locale={datePickerLabels?.locale}
|
|
332
|
+
defaultValue={props.defaultValue as string}
|
|
333
|
+
value={props.value as string}
|
|
334
|
+
onChange={(d) => {
|
|
335
|
+
reportPickerValue(d ? toDateValue(d) : "")
|
|
336
|
+
}}
|
|
337
|
+
/>
|
|
338
|
+
</>
|
|
339
|
+
)
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (isTime) {
|
|
343
|
+
return (
|
|
344
|
+
<>
|
|
345
|
+
{pickerInput("text")}
|
|
346
|
+
<TimePicker
|
|
347
|
+
id={inputId}
|
|
348
|
+
disabled={disabled}
|
|
349
|
+
className={className}
|
|
350
|
+
placeholder={props.placeholder}
|
|
351
|
+
defaultValue={props.defaultValue as string}
|
|
352
|
+
value={props.value as string}
|
|
353
|
+
onChange={(t) => {
|
|
354
|
+
reportPickerValue(t || "")
|
|
355
|
+
}}
|
|
356
|
+
/>
|
|
357
|
+
</>
|
|
358
|
+
)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (isDateTime) {
|
|
362
|
+
return (
|
|
363
|
+
<div className="relative flex items-center w-full">
|
|
364
|
+
<input
|
|
365
|
+
ref={internalRef}
|
|
366
|
+
id={inputId}
|
|
367
|
+
type={type}
|
|
368
|
+
data-slot="input"
|
|
369
|
+
disabled={disabled}
|
|
370
|
+
aria-invalid={!!errorText}
|
|
371
|
+
aria-describedby={[
|
|
372
|
+
errorText && inputId ? `${inputId}-error` : undefined,
|
|
373
|
+
helperText && inputId ? `${inputId}-helper` : undefined,
|
|
374
|
+
]
|
|
375
|
+
.filter(Boolean)
|
|
376
|
+
.join(" ") || undefined}
|
|
377
|
+
className={cn(
|
|
378
|
+
"h-10 w-full min-w-0 rounded-control border border-input bg-card ps-2.5 pe-8 py-0.5 text-sm transition-colors outline-none placeholder:text-muted-foreground placeholder:text-xs focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20 [&::-webkit-calendar-picker-indicator]:cursor-pointer [&::-webkit-calendar-picker-indicator]:opacity-0",
|
|
379
|
+
className
|
|
380
|
+
)}
|
|
381
|
+
{...props}
|
|
382
|
+
/>
|
|
383
|
+
<button
|
|
384
|
+
type="button"
|
|
385
|
+
tabIndex={-1}
|
|
386
|
+
disabled={disabled}
|
|
387
|
+
onClick={() => {
|
|
388
|
+
const input = internalRef.current
|
|
389
|
+
if (!input) return
|
|
390
|
+
if ("showPicker" in input && typeof (input as any).showPicker === "function") {
|
|
391
|
+
;(input as any).showPicker()
|
|
392
|
+
} else {
|
|
393
|
+
input.focus()
|
|
394
|
+
}
|
|
395
|
+
}}
|
|
396
|
+
className="absolute end-2.5 flex items-center justify-center size-3.5 text-muted-foreground hover:text-foreground focus-visible:outline-none rounded transition-colors disabled:pointer-events-none disabled:opacity-50 z-10"
|
|
397
|
+
>
|
|
398
|
+
<IconCalendarTime className="size-3.5 shrink-0" aria-hidden="true" />
|
|
399
|
+
</button>
|
|
400
|
+
</div>
|
|
401
|
+
)
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (isSearch) {
|
|
405
|
+
return (
|
|
406
|
+
<div className="relative flex items-center w-full">
|
|
407
|
+
<div className="absolute start-2.5 flex items-center justify-center size-3.5 text-muted-foreground pointer-events-none shrink-0 z-10">
|
|
408
|
+
<IconSearch className="size-3.5 shrink-0" aria-hidden="true" />
|
|
409
|
+
</div>
|
|
410
|
+
<input
|
|
411
|
+
ref={internalRef}
|
|
412
|
+
id={inputId}
|
|
413
|
+
type="search"
|
|
414
|
+
data-slot="input"
|
|
415
|
+
disabled={disabled}
|
|
416
|
+
aria-invalid={!!errorText}
|
|
417
|
+
aria-describedby={[
|
|
418
|
+
errorText && inputId ? `${inputId}-error` : undefined,
|
|
419
|
+
helperText && inputId ? `${inputId}-helper` : undefined,
|
|
420
|
+
]
|
|
421
|
+
.filter(Boolean)
|
|
422
|
+
.join(" ") || undefined}
|
|
423
|
+
className={cn(
|
|
424
|
+
"h-10 w-full min-w-0 rounded-control border border-input bg-card ps-8 pe-2.5 py-0.5 text-sm transition-colors outline-none placeholder:text-muted-foreground placeholder:text-xs focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20 [&::-webkit-search-cancel-button]:cursor-pointer",
|
|
425
|
+
className
|
|
426
|
+
)}
|
|
427
|
+
{...props}
|
|
428
|
+
/>
|
|
429
|
+
</div>
|
|
430
|
+
)
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (isPassword) {
|
|
434
|
+
const inputType = showPassword ? "text" : "password"
|
|
435
|
+
return (
|
|
436
|
+
<div className="relative flex items-center w-full">
|
|
437
|
+
<input
|
|
438
|
+
ref={internalRef}
|
|
439
|
+
id={inputId}
|
|
440
|
+
type={inputType}
|
|
441
|
+
data-slot="input"
|
|
442
|
+
disabled={disabled}
|
|
443
|
+
aria-invalid={!!errorText}
|
|
444
|
+
aria-describedby={[
|
|
445
|
+
errorText && inputId ? `${inputId}-error` : undefined,
|
|
446
|
+
helperText && inputId ? `${inputId}-helper` : undefined,
|
|
447
|
+
]
|
|
448
|
+
.filter(Boolean)
|
|
449
|
+
.join(" ") || undefined}
|
|
450
|
+
className={cn(
|
|
451
|
+
"h-10 w-full min-w-0 rounded-control border border-input bg-card ps-2.5 pe-8 py-0.5 text-sm transition-colors outline-none placeholder:text-muted-foreground placeholder:text-xs focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20",
|
|
452
|
+
className
|
|
453
|
+
)}
|
|
454
|
+
{...props}
|
|
455
|
+
/>
|
|
456
|
+
<button
|
|
457
|
+
type="button"
|
|
458
|
+
disabled={disabled}
|
|
459
|
+
onClick={() => setShowPassword((prev) => !prev)}
|
|
460
|
+
aria-label={showPassword ? hidePasswordLabel : showPasswordLabel}
|
|
461
|
+
title={showPassword ? hidePasswordLabel : showPasswordLabel}
|
|
462
|
+
className="absolute end-2.5 flex items-center justify-center size-3.5 text-muted-foreground hover:text-foreground focus-visible:outline-none rounded transition-colors disabled:pointer-events-none disabled:opacity-50 z-10"
|
|
463
|
+
>
|
|
464
|
+
{showPassword ? (
|
|
465
|
+
<IconEyeOff className="size-3.5 shrink-0" aria-hidden="true" />
|
|
466
|
+
) : (
|
|
467
|
+
<IconEye className="size-3.5 shrink-0" aria-hidden="true" />
|
|
468
|
+
)}
|
|
469
|
+
</button>
|
|
470
|
+
</div>
|
|
471
|
+
)
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
if (isNumber) {
|
|
475
|
+
return (
|
|
476
|
+
<div className="relative flex items-center w-full">
|
|
477
|
+
<button
|
|
478
|
+
type="button"
|
|
479
|
+
tabIndex={-1}
|
|
480
|
+
disabled={disabled}
|
|
481
|
+
onClick={() => handleStep(-1)}
|
|
482
|
+
aria-label={decrementLabel}
|
|
483
|
+
title={decrementLabel}
|
|
484
|
+
className="absolute start-2.5 flex items-center justify-center size-3.5 text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50 z-10"
|
|
485
|
+
>
|
|
486
|
+
<IconMinus className="size-3.5 shrink-0" aria-hidden="true" />
|
|
487
|
+
</button>
|
|
488
|
+
<input
|
|
489
|
+
ref={internalRef}
|
|
490
|
+
id={inputId}
|
|
491
|
+
type="number"
|
|
492
|
+
data-slot="input"
|
|
493
|
+
disabled={disabled}
|
|
494
|
+
aria-invalid={!!errorText}
|
|
495
|
+
aria-describedby={[
|
|
496
|
+
errorText && inputId ? `${inputId}-error` : undefined,
|
|
497
|
+
helperText && inputId ? `${inputId}-helper` : undefined,
|
|
498
|
+
]
|
|
499
|
+
.filter(Boolean)
|
|
500
|
+
.join(" ") || undefined}
|
|
501
|
+
className={cn(
|
|
502
|
+
"h-10 w-full min-w-0 rounded-control border border-input bg-card px-8 py-0.5 text-center text-sm transition-colors outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none placeholder:text-muted-foreground placeholder:text-xs focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20",
|
|
503
|
+
className
|
|
504
|
+
)}
|
|
505
|
+
{...props}
|
|
506
|
+
/>
|
|
507
|
+
<button
|
|
508
|
+
type="button"
|
|
509
|
+
tabIndex={-1}
|
|
510
|
+
disabled={disabled}
|
|
511
|
+
onClick={() => handleStep(1)}
|
|
512
|
+
aria-label={incrementLabel}
|
|
513
|
+
title={incrementLabel}
|
|
514
|
+
className="absolute end-2.5 flex items-center justify-center size-3.5 text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50 z-10"
|
|
515
|
+
>
|
|
516
|
+
<IconPlus className="size-3.5 shrink-0" aria-hidden="true" />
|
|
517
|
+
</button>
|
|
518
|
+
</div>
|
|
519
|
+
)
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
if (isFile && fileVariant === "dropzone") {
|
|
523
|
+
return (
|
|
524
|
+
<div className="flex flex-col gap-2.5 w-full">
|
|
525
|
+
<div
|
|
526
|
+
onDragOver={(e) => {
|
|
527
|
+
e.preventDefault()
|
|
528
|
+
e.stopPropagation()
|
|
529
|
+
if (!disabled) setIsDragging(true)
|
|
530
|
+
}}
|
|
531
|
+
onDragLeave={(e) => {
|
|
532
|
+
e.preventDefault()
|
|
533
|
+
e.stopPropagation()
|
|
534
|
+
setIsDragging(false)
|
|
535
|
+
}}
|
|
536
|
+
onDrop={(e) => {
|
|
537
|
+
e.preventDefault()
|
|
538
|
+
e.stopPropagation()
|
|
539
|
+
setIsDragging(false)
|
|
540
|
+
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
|
|
541
|
+
handleDropFiles(Array.from(e.dataTransfer.files))
|
|
542
|
+
}
|
|
543
|
+
}}
|
|
544
|
+
onClick={() => internalRef.current?.click()}
|
|
545
|
+
className={cn(
|
|
546
|
+
"group flex flex-col items-center justify-center rounded-xl border-2 border-dashed border-input bg-card/60 p-5 text-center transition-all cursor-pointer hover:border-primary/60 hover:bg-muted/30 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30",
|
|
547
|
+
isDragging && "border-primary bg-primary/10 ring-2 ring-primary/20",
|
|
548
|
+
disabled && "pointer-events-none opacity-50",
|
|
549
|
+
className
|
|
550
|
+
)}
|
|
551
|
+
>
|
|
552
|
+
<input
|
|
553
|
+
ref={internalRef}
|
|
554
|
+
id={inputId}
|
|
555
|
+
type="file"
|
|
556
|
+
data-slot="input"
|
|
557
|
+
disabled={disabled}
|
|
558
|
+
onChange={handleFileChange}
|
|
559
|
+
aria-invalid={!!errorText}
|
|
560
|
+
aria-describedby={[
|
|
561
|
+
errorText && inputId ? `${inputId}-error` : undefined,
|
|
562
|
+
helperText && inputId ? `${inputId}-helper` : undefined,
|
|
563
|
+
]
|
|
564
|
+
.filter(Boolean)
|
|
565
|
+
.join(" ") || undefined}
|
|
566
|
+
className="sr-only"
|
|
567
|
+
{...props}
|
|
568
|
+
/>
|
|
569
|
+
<div className="flex size-10 items-center justify-center rounded-full bg-primary/10 text-primary transition-transform group-hover:scale-105 mb-2">
|
|
570
|
+
<IconCloudUpload className="size-5 shrink-0" aria-hidden="true" />
|
|
571
|
+
</div>
|
|
572
|
+
<p className="text-xs font-semibold text-foreground">
|
|
573
|
+
{dropzonePrompt ?? (
|
|
574
|
+
<>
|
|
575
|
+
<span className="text-primary hover:underline">Click to browse</span> or drag
|
|
576
|
+
and drop files
|
|
577
|
+
</>
|
|
578
|
+
)}
|
|
579
|
+
</p>
|
|
580
|
+
<p className="mt-0.5 text-xs text-muted-foreground">
|
|
581
|
+
{props.multiple ? multipleFilesHint : singleFileHint}
|
|
582
|
+
</p>
|
|
583
|
+
</div>
|
|
584
|
+
|
|
585
|
+
{selectedFiles.length > 0 && (
|
|
586
|
+
<div className="flex flex-col gap-1.5 w-full">
|
|
587
|
+
{selectedFiles.map((file, idx) => (
|
|
588
|
+
<div
|
|
589
|
+
key={`${file.name}-${idx}`}
|
|
590
|
+
className="flex items-center justify-between gap-3 rounded-lg border border-border/70 bg-card p-2 shadow-2xs transition-colors"
|
|
591
|
+
>
|
|
592
|
+
<div className="flex items-center gap-2.5 min-w-0">
|
|
593
|
+
<div className="flex size-7 shrink-0 items-center justify-center rounded-md bg-primary/10 text-primary">
|
|
594
|
+
<IconPaperclip className="size-4" aria-hidden="true" />
|
|
595
|
+
</div>
|
|
596
|
+
<div className="flex flex-col min-w-0 text-start">
|
|
597
|
+
<span className="truncate text-xs font-semibold text-foreground" title={file.name}>
|
|
598
|
+
{file.name}
|
|
599
|
+
</span>
|
|
600
|
+
<span className="text-xs text-muted-foreground font-mono">
|
|
601
|
+
{formatBytes(file.size)}
|
|
602
|
+
</span>
|
|
603
|
+
</div>
|
|
604
|
+
</div>
|
|
605
|
+
<button
|
|
606
|
+
type="button"
|
|
607
|
+
disabled={disabled}
|
|
608
|
+
onClick={(e) => {
|
|
609
|
+
e.stopPropagation()
|
|
610
|
+
handleRemoveFile(idx)
|
|
611
|
+
}}
|
|
612
|
+
aria-label={`Remove ${file.name}`}
|
|
613
|
+
className="flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
614
|
+
>
|
|
615
|
+
<IconX className="size-3.5" aria-hidden="true" />
|
|
616
|
+
</button>
|
|
617
|
+
</div>
|
|
618
|
+
))}
|
|
619
|
+
</div>
|
|
620
|
+
)}
|
|
621
|
+
</div>
|
|
622
|
+
)
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
if (isFile && fileVariant === "compact") {
|
|
626
|
+
return (
|
|
627
|
+
<div
|
|
628
|
+
className={cn(
|
|
629
|
+
"flex min-h-10 w-full flex-wrap items-center gap-1.5 rounded-control border border-input bg-card p-1 text-sm transition-colors focus-within:border-ring focus-within:ring-2 focus-within:ring-ring/30",
|
|
630
|
+
disabled && "pointer-events-none opacity-50",
|
|
631
|
+
className
|
|
632
|
+
)}
|
|
633
|
+
>
|
|
634
|
+
<input
|
|
635
|
+
ref={internalRef}
|
|
636
|
+
id={inputId}
|
|
637
|
+
type="file"
|
|
638
|
+
data-slot="input"
|
|
639
|
+
disabled={disabled}
|
|
640
|
+
onChange={handleFileChange}
|
|
641
|
+
aria-invalid={!!errorText}
|
|
642
|
+
aria-describedby={[
|
|
643
|
+
errorText && inputId ? `${inputId}-error` : undefined,
|
|
644
|
+
helperText && inputId ? `${inputId}-helper` : undefined,
|
|
645
|
+
]
|
|
646
|
+
.filter(Boolean)
|
|
647
|
+
.join(" ") || undefined}
|
|
648
|
+
className="sr-only"
|
|
649
|
+
{...props}
|
|
650
|
+
/>
|
|
651
|
+
<button
|
|
652
|
+
type="button"
|
|
653
|
+
disabled={disabled}
|
|
654
|
+
onClick={() => internalRef.current?.click()}
|
|
655
|
+
className="flex h-6 items-center justify-center rounded border border-input/40 bg-muted px-2.5 text-xs font-semibold text-foreground transition-colors hover:bg-muted/80 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"
|
|
656
|
+
>
|
|
657
|
+
{props.multiple ? "Choose files" : "Choose file"}
|
|
658
|
+
</button>
|
|
659
|
+
{selectedFiles.length === 0 ? (
|
|
660
|
+
<span className="text-xs text-muted-foreground ps-1">
|
|
661
|
+
No {props.multiple ? "files" : "file"} chosen
|
|
662
|
+
</span>
|
|
663
|
+
) : (
|
|
664
|
+
<div className="flex flex-wrap items-center gap-1">
|
|
665
|
+
{selectedFiles.map((file, idx) => (
|
|
666
|
+
<span
|
|
667
|
+
key={`${file.name}-${idx}`}
|
|
668
|
+
className="inline-flex max-w-[200px] items-center gap-1 rounded-full border border-border/60 bg-muted/80 px-2 py-0.5 text-xs font-medium text-foreground"
|
|
669
|
+
>
|
|
670
|
+
<IconPaperclip className="size-3 shrink-0 text-muted-foreground" aria-hidden="true" />
|
|
671
|
+
<span className="truncate" title={file.name}>
|
|
672
|
+
{file.name}
|
|
673
|
+
</span>
|
|
674
|
+
<button
|
|
675
|
+
type="button"
|
|
676
|
+
tabIndex={-1}
|
|
677
|
+
disabled={disabled}
|
|
678
|
+
onClick={(e) => {
|
|
679
|
+
e.stopPropagation()
|
|
680
|
+
handleRemoveFile(idx)
|
|
681
|
+
}}
|
|
682
|
+
aria-label={`Remove ${file.name}`}
|
|
683
|
+
className="ms-0.5 flex size-3.5 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted-foreground/20 hover:text-foreground"
|
|
684
|
+
>
|
|
685
|
+
<IconX className="size-3 shrink-0" aria-hidden="true" />
|
|
686
|
+
</button>
|
|
687
|
+
</span>
|
|
688
|
+
))}
|
|
689
|
+
</div>
|
|
690
|
+
)}
|
|
691
|
+
</div>
|
|
692
|
+
)
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
return (
|
|
696
|
+
<input
|
|
697
|
+
ref={ref}
|
|
698
|
+
id={inputId}
|
|
699
|
+
type={type}
|
|
700
|
+
data-slot="input"
|
|
701
|
+
disabled={disabled}
|
|
702
|
+
aria-invalid={!!errorText}
|
|
703
|
+
aria-describedby={[
|
|
704
|
+
errorText && inputId ? `${inputId}-error` : undefined,
|
|
705
|
+
helperText && inputId ? `${inputId}-helper` : undefined,
|
|
706
|
+
]
|
|
707
|
+
.filter(Boolean)
|
|
708
|
+
.join(" ") || undefined}
|
|
709
|
+
className={cn(
|
|
710
|
+
"h-10 w-full min-w-0 rounded-control border border-input bg-card px-2.5 py-0.5 text-sm transition-colors outline-none file:inline-flex file:h-full file:items-center file:border-0 file:border-e file:border-input/40 file:bg-muted file:px-2.5 file:text-xs file:font-semibold file:text-foreground hover:file:bg-muted/80 file:transition-colors file:cursor-pointer file:me-2 placeholder:text-muted-foreground placeholder:text-xs focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20",
|
|
711
|
+
className
|
|
712
|
+
)}
|
|
713
|
+
{...props}
|
|
714
|
+
/>
|
|
715
|
+
)
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
const hasHeader = label || tooltip || required
|
|
719
|
+
const hasFooter = helperText || errorText
|
|
720
|
+
|
|
721
|
+
if (!hasHeader && !hasFooter) {
|
|
722
|
+
return renderInputControl()
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
return (
|
|
726
|
+
<div className="flex flex-col gap-1 w-full text-start">
|
|
727
|
+
{hasHeader && (
|
|
728
|
+
<div className="flex items-center gap-1 text-xs font-semibold text-foreground">
|
|
729
|
+
{label && inputId ? (
|
|
730
|
+
<label htmlFor={inputId} className="cursor-pointer">
|
|
731
|
+
{label}
|
|
732
|
+
</label>
|
|
733
|
+
) : (
|
|
734
|
+
label && <span>{label}</span>
|
|
735
|
+
)}
|
|
736
|
+
{required && <span className="text-destructive font-semibold ms-0.5">*</span>}
|
|
737
|
+
{tooltip && (
|
|
738
|
+
<TooltipProvider>
|
|
739
|
+
<Tooltip>
|
|
740
|
+
<TooltipTrigger asChild>
|
|
741
|
+
<button
|
|
742
|
+
type="button"
|
|
743
|
+
aria-label={tooltipTriggerLabel}
|
|
744
|
+
className="inline-flex items-center text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring rounded p-0.5"
|
|
745
|
+
>
|
|
746
|
+
<IconInfoCircle className="size-3.5 shrink-0" aria-hidden="true" />
|
|
747
|
+
</button>
|
|
748
|
+
</TooltipTrigger>
|
|
749
|
+
<TooltipContent>{tooltip}</TooltipContent>
|
|
750
|
+
</Tooltip>
|
|
751
|
+
</TooltipProvider>
|
|
752
|
+
)}
|
|
753
|
+
</div>
|
|
754
|
+
)}
|
|
755
|
+
{renderInputControl()}
|
|
756
|
+
{errorText ? (
|
|
757
|
+
<p id={inputId ? `${inputId}-error` : undefined} className="text-xs font-medium text-destructive">{errorText}</p>
|
|
758
|
+
) : (
|
|
759
|
+
helperText && <p id={inputId ? `${inputId}-helper` : undefined} className="text-xs text-muted-foreground">{helperText}</p>
|
|
760
|
+
)}
|
|
761
|
+
</div>
|
|
762
|
+
)
|
|
763
|
+
}
|
|
764
|
+
)
|
|
765
|
+
|
|
766
|
+
Input.displayName = "Input"
|
|
767
|
+
|
|
768
|
+
export { Input }
|