@whity/ui 0.0.0-stage → 0.5.0

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