@whity/ui 0.5.0 → 1.0.1
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 +107 -107
- package/package.json +223 -192
- package/src/access-denied.stories.tsx +179 -179
- package/src/access-denied.tsx +305 -305
- package/src/action-proposal.tsx +338 -302
- package/src/actor-chip.tsx +71 -71
- package/src/agent-activity.tsx +163 -163
- package/src/agent-collaboration.stories.tsx +156 -156
- package/src/agent-run-status.tsx +196 -196
- package/src/alert-dialog.stories.tsx +45 -45
- package/src/alert-dialog.tsx +147 -147
- package/src/alert.stories.tsx +91 -91
- package/src/alert.tsx +89 -89
- package/src/app-sidebar.stories.tsx +195 -195
- package/src/app-sidebar.tsx +604 -500
- package/src/approval-queue.tsx +109 -108
- package/src/audience-group-picker.stories.tsx +198 -198
- package/src/audience-group-picker.tsx +362 -362
- package/src/audience-people-picker.stories.tsx +102 -102
- package/src/audience-people-picker.tsx +279 -279
- package/src/avatar-pattern.ts +138 -0
- package/src/avatar.tsx +125 -83
- package/src/badge.stories.tsx +105 -105
- package/src/badge.tsx +68 -68
- package/src/beta-warning.stories.tsx +79 -79
- package/src/beta-warning.tsx +189 -189
- package/src/bilingual-input.stories.tsx +82 -82
- package/src/bilingual-input.tsx +188 -183
- package/src/board.tsx +216 -0
- package/src/breadcrumb.stories.tsx +51 -51
- package/src/breadcrumb.tsx +90 -90
- package/src/built-on-whity.tsx +52 -0
- package/src/button.stories.tsx +87 -87
- package/src/button.tsx +125 -118
- package/src/card.stories.tsx +423 -423
- package/src/card.tsx +180 -180
- package/src/chart.stories.tsx +66 -66
- package/src/chart.tsx +228 -228
- package/src/checkbox.stories.tsx +62 -62
- package/src/checkbox.tsx +54 -54
- package/src/collapsible.stories.tsx +48 -48
- package/src/collapsible.tsx +34 -34
- package/src/color-card.stories.tsx +61 -61
- package/src/color-card.tsx +270 -270
- package/src/color-picker.stories.tsx +65 -65
- package/src/color-picker.tsx +425 -425
- package/src/column-matcher.tsx +84 -0
- package/src/command-palette.tsx +399 -306
- package/src/confirm-action.tsx +98 -0
- package/src/copy-block.stories.tsx +38 -38
- package/src/copy-block.tsx +85 -85
- package/src/data-table.stories.tsx +200 -200
- package/src/data-table.tsx +1687 -1106
- package/src/date-picker.stories.tsx +61 -61
- package/src/date-picker.tsx +457 -422
- package/src/design-cards.stories.tsx +551 -458
- package/src/dialog.stories.tsx +48 -48
- package/src/dialog.tsx +179 -166
- package/src/display-preferences.tsx +59 -0
- package/src/documents/barcode-svg.stories.tsx +72 -72
- package/src/documents/barcode-svg.tsx +79 -79
- package/src/dropdown-menu.stories.tsx +77 -77
- package/src/dropdown-menu.tsx +271 -271
- 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 -279
- package/src/editor/block-ids.ts +44 -44
- package/src/editor/block-list.tsx +104 -101
- package/src/editor/block-toolbar.tsx +490 -477
- package/src/editor/bubble.tsx +119 -93
- package/src/editor/catalogue.ts +169 -103
- package/src/editor/collab-rail.tsx +746 -746
- package/src/editor/collab.stories.tsx +207 -207
- package/src/editor/collab.ts +87 -87
- package/src/editor/contract.ts +476 -408
- package/src/editor/convert.ts +414 -362
- package/src/editor/doc-editor.stories.tsx +98 -98
- package/src/editor/doc-editor.tsx +1492 -1287
- package/src/editor/editor.css +636 -536
- package/src/editor/extensions.ts +86 -86
- package/src/editor/field-bar.tsx +154 -0
- package/src/editor/field-picker.tsx +109 -107
- package/src/editor/fields.ts +100 -100
- package/src/editor/gutter.tsx +443 -367
- package/src/editor/index.ts +23 -22
- package/src/editor/label-sheet.tsx +289 -289
- package/src/editor/labels.ts +394 -310
- package/src/editor/link-tools.tsx +141 -141
- package/src/editor/node-views.tsx +461 -450
- package/src/editor/page-view.tsx +372 -353
- 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 -182
- package/src/editor/rich-blocks.stories.tsx +146 -146
- package/src/editor/sample.ts +40 -40
- 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 -150
- package/src/editor/schema.ts +368 -315
- package/src/editor/services.tsx +205 -127
- package/src/editor/slash.ts +64 -64
- package/src/editor/suggesting.ts +372 -372
- package/src/editor/suggestions.ts +763 -763
- package/src/editor/table-keys.ts +66 -66
- package/src/editor/templates.stories.tsx +324 -324
- package/src/editor/toolbar.tsx +364 -358
- package/src/empty-state.stories.tsx +51 -51
- package/src/empty-state.tsx +126 -100
- package/src/empty-state.usage-notes.md +30 -30
- package/src/form.stories.tsx +112 -112
- package/src/form.tsx +176 -176
- package/src/globals.css +20 -20
- package/src/icon-button.tsx +85 -85
- package/src/icon-map.ts +335 -244
- package/src/icon.tsx +41 -41
- package/src/index.ts +92 -67
- package/src/input.stories.tsx +157 -157
- package/src/input.tsx +768 -759
- package/src/kpi-strip.tsx +47 -0
- package/src/localized-text.ts +76 -0
- package/src/locked-screen.stories.tsx +29 -29
- package/src/locked-screen.tsx +75 -61
- package/src/lockup.tsx +42 -0
- package/src/lottie.tsx +441 -0
- package/src/mark.tsx +62 -62
- package/src/math-text.stories.tsx +33 -33
- package/src/math-text.tsx +43 -43
- package/src/menu-bar.stories.tsx +198 -198
- package/src/menu-bar.tsx +373 -373
- package/src/message-thread.tsx +181 -0
- package/src/money/currency.ts +244 -230
- 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 -95
- package/src/page-header.tsx +122 -122
- package/src/page-shell.stories.tsx +42 -42
- package/src/page-shell.tsx +32 -32
- package/src/page-states.tsx +277 -0
- package/src/pagination.stories.tsx +45 -45
- package/src/pagination.tsx +98 -98
- package/src/paper-sheet.stories.tsx +88 -0
- package/src/paper-sheet.tsx +85 -0
- package/src/phone-input.tsx +252 -0
- package/src/phone-tab-bar.tsx +152 -0
- package/src/plugin-card.stories.tsx +208 -180
- package/src/plugin-card.tsx +931 -848
- package/src/popover.stories.tsx +48 -48
- package/src/popover.tsx +55 -55
- package/src/radio-group.stories.tsx +26 -26
- package/src/radio-group.tsx +44 -44
- package/src/role-summary.stories.tsx +143 -0
- package/src/role-summary.tsx +120 -0
- package/src/route-flow/editor.tsx +1087 -1014
- package/src/route-flow/model.ts +771 -716
- package/src/save-bar.tsx +94 -0
- package/src/scope-grant.tsx +139 -139
- package/src/screen-too-small.stories.tsx +61 -61
- package/src/screen-too-small.tsx +104 -104
- package/src/search-field.tsx +65 -0
- package/src/select.stories.tsx +44 -44
- package/src/select.tsx +197 -197
- package/src/separator.stories.tsx +34 -34
- package/src/separator.tsx +34 -34
- package/src/sheet.stories.tsx +49 -49
- package/src/sheet.tsx +168 -168
- package/src/skeleton.stories.tsx +28 -28
- package/src/skeleton.tsx +19 -19
- package/src/slider.stories.tsx +78 -78
- package/src/slider.tsx +300 -300
- package/src/spinner.stories.tsx +33 -33
- package/src/spinner.tsx +55 -55
- package/src/stepper.tsx +85 -0
- package/src/switch.stories.tsx +42 -42
- package/src/switch.tsx +41 -41
- package/src/switcher.stories.tsx +111 -111
- package/src/switcher.tsx +131 -131
- package/src/system-state.tsx +55 -0
- package/src/table.stories.tsx +48 -48
- package/src/table.tsx +121 -121
- package/src/tabs.stories.tsx +74 -74
- package/src/tabs.tsx +90 -90
- package/src/tag-input.stories.tsx +67 -67
- package/src/tag-input.tsx +117 -117
- package/src/tenant-logo.tsx +63 -63
- package/src/tenant-switcher.stories.tsx +38 -38
- package/src/tenant-switcher.tsx +185 -164
- package/src/textarea.stories.tsx +27 -27
- package/src/textarea.tsx +18 -18
- package/src/theme-mode.ts +74 -52
- package/src/time-grid.tsx +163 -0
- package/src/time-picker.stories.tsx +62 -62
- package/src/time-picker.tsx +616 -615
- package/src/toggle-group.tsx +139 -138
- package/src/tooltip.stories.tsx +43 -43
- package/src/tooltip.tsx +73 -73
- package/src/top-nav.stories.tsx +58 -58
- package/src/top-nav.tsx +324 -324
- package/src/undo-bar.tsx +107 -107
- package/src/utils.ts +45 -45
- package/src/view-toggle.stories.tsx +84 -84
- package/src/view-toggle.tsx +111 -110
package/src/date-picker.tsx
CHANGED
|
@@ -1,422 +1,457 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import * as React from "react"
|
|
4
|
-
import {
|
|
5
|
-
IconCalendar,
|
|
6
|
-
IconChevronDown,
|
|
7
|
-
IconChevronLeft,
|
|
8
|
-
IconChevronRight,
|
|
9
|
-
IconInfoCircle,
|
|
10
|
-
IconX,
|
|
11
|
-
} from "@tabler/icons-react"
|
|
12
|
-
|
|
13
|
-
import { cn } from "./utils"
|
|
14
|
-
import { Popover, PopoverContent, PopoverTrigger } from "./popover"
|
|
15
|
-
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./tooltip"
|
|
16
|
-
|
|
17
|
-
export interface DatePickerProps {
|
|
18
|
-
/**
|
|
19
|
-
* The selected Date object or ISO string.
|
|
20
|
-
*/
|
|
21
|
-
value?: Date | string
|
|
22
|
-
/**
|
|
23
|
-
* Default Date object or ISO string.
|
|
24
|
-
*/
|
|
25
|
-
defaultValue?: Date | string
|
|
26
|
-
/**
|
|
27
|
-
* Callback fired when a date is selected or cleared.
|
|
28
|
-
*/
|
|
29
|
-
onChange?: (date: Date | null) => void
|
|
30
|
-
/**
|
|
31
|
-
* Field label text displayed statically above the input field.
|
|
32
|
-
*/
|
|
33
|
-
label?: React.ReactNode
|
|
34
|
-
/**
|
|
35
|
-
* Displays a required asterisk (*) next to the label.
|
|
36
|
-
*/
|
|
37
|
-
required?: boolean
|
|
38
|
-
/**
|
|
39
|
-
* Tooltip message displayed in an interactive info icon next to the label.
|
|
40
|
-
*/
|
|
41
|
-
tooltip?: React.ReactNode
|
|
42
|
-
/**
|
|
43
|
-
* Small informational note rendered below the input field.
|
|
44
|
-
*/
|
|
45
|
-
helperText?: React.ReactNode
|
|
46
|
-
/**
|
|
47
|
-
* Error text rendered below the input field in destructive red.
|
|
48
|
-
*/
|
|
49
|
-
errorText?: React.ReactNode
|
|
50
|
-
/**
|
|
51
|
-
* Placeholder text when no date is selected. Defaults to "Select date...".
|
|
52
|
-
*/
|
|
53
|
-
placeholder?: string
|
|
54
|
-
/** Accessible name for the clear button. */
|
|
55
|
-
clearLabel?: string
|
|
56
|
-
/** Accessible name for a tooltip trigger. Defaults to "More information". */
|
|
57
|
-
tooltipTriggerLabel?: string
|
|
58
|
-
/** Accessible names for the month navigation buttons. */
|
|
59
|
-
previousMonthLabel?: string
|
|
60
|
-
nextMonthLabel?: string
|
|
61
|
-
/** Footer button text. */
|
|
62
|
-
todayLabel?: string
|
|
63
|
-
clearButtonLabel?: string
|
|
64
|
-
/**
|
|
65
|
-
* Disables the date picker control.
|
|
66
|
-
*/
|
|
67
|
-
disabled?: boolean
|
|
68
|
-
/**
|
|
69
|
-
* Allows clearing the selected date. Defaults to true.
|
|
70
|
-
*/
|
|
71
|
-
clearable?: boolean
|
|
72
|
-
/**
|
|
73
|
-
* Custom container class name.
|
|
74
|
-
*/
|
|
75
|
-
className?: string
|
|
76
|
-
id?: string
|
|
77
|
-
name?: string
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
<
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
>
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
)
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import {
|
|
5
|
+
IconCalendar,
|
|
6
|
+
IconChevronDown,
|
|
7
|
+
IconChevronLeft,
|
|
8
|
+
IconChevronRight,
|
|
9
|
+
IconInfoCircle,
|
|
10
|
+
IconX,
|
|
11
|
+
} from "@tabler/icons-react"
|
|
12
|
+
|
|
13
|
+
import { cn } from "./utils"
|
|
14
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./popover"
|
|
15
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./tooltip"
|
|
16
|
+
|
|
17
|
+
export interface DatePickerProps {
|
|
18
|
+
/**
|
|
19
|
+
* The selected Date object or ISO string.
|
|
20
|
+
*/
|
|
21
|
+
value?: Date | string
|
|
22
|
+
/**
|
|
23
|
+
* Default Date object or ISO string.
|
|
24
|
+
*/
|
|
25
|
+
defaultValue?: Date | string
|
|
26
|
+
/**
|
|
27
|
+
* Callback fired when a date is selected or cleared.
|
|
28
|
+
*/
|
|
29
|
+
onChange?: (date: Date | null) => void
|
|
30
|
+
/**
|
|
31
|
+
* Field label text displayed statically above the input field.
|
|
32
|
+
*/
|
|
33
|
+
label?: React.ReactNode
|
|
34
|
+
/**
|
|
35
|
+
* Displays a required asterisk (*) next to the label.
|
|
36
|
+
*/
|
|
37
|
+
required?: boolean
|
|
38
|
+
/**
|
|
39
|
+
* Tooltip message displayed in an interactive info icon next to the label.
|
|
40
|
+
*/
|
|
41
|
+
tooltip?: React.ReactNode
|
|
42
|
+
/**
|
|
43
|
+
* Small informational note rendered below the input field.
|
|
44
|
+
*/
|
|
45
|
+
helperText?: React.ReactNode
|
|
46
|
+
/**
|
|
47
|
+
* Error text rendered below the input field in destructive red.
|
|
48
|
+
*/
|
|
49
|
+
errorText?: React.ReactNode
|
|
50
|
+
/**
|
|
51
|
+
* Placeholder text when no date is selected. Defaults to "Select date...".
|
|
52
|
+
*/
|
|
53
|
+
placeholder?: string
|
|
54
|
+
/** Accessible name for the clear button. */
|
|
55
|
+
clearLabel?: string
|
|
56
|
+
/** Accessible name for a tooltip trigger. Defaults to "More information". */
|
|
57
|
+
tooltipTriggerLabel?: string
|
|
58
|
+
/** Accessible names for the month navigation buttons. */
|
|
59
|
+
previousMonthLabel?: string
|
|
60
|
+
nextMonthLabel?: string
|
|
61
|
+
/** Footer button text. */
|
|
62
|
+
todayLabel?: string
|
|
63
|
+
clearButtonLabel?: string
|
|
64
|
+
/**
|
|
65
|
+
* Disables the date picker control.
|
|
66
|
+
*/
|
|
67
|
+
disabled?: boolean
|
|
68
|
+
/**
|
|
69
|
+
* Allows clearing the selected date. Defaults to true.
|
|
70
|
+
*/
|
|
71
|
+
clearable?: boolean
|
|
72
|
+
/**
|
|
73
|
+
* Custom container class name.
|
|
74
|
+
*/
|
|
75
|
+
className?: string
|
|
76
|
+
id?: string
|
|
77
|
+
name?: string
|
|
78
|
+
/**
|
|
79
|
+
* The language the field and the calendar are written in (a BCP 47 tag, for
|
|
80
|
+
* example `ar`). Month and weekday names follow it; digits stay Western,
|
|
81
|
+
* as everywhere in Whity. Defaults to English.
|
|
82
|
+
*/
|
|
83
|
+
locale?: string
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const MONTH_NAMES = [
|
|
87
|
+
"January", "February", "March", "April", "May", "June",
|
|
88
|
+
"July", "August", "September", "October", "November", "December"
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
const DAY_NAMES = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]
|
|
92
|
+
|
|
93
|
+
function parseDateValue(val?: Date | string): Date | null {
|
|
94
|
+
if (!val) return null
|
|
95
|
+
if (val instanceof Date) return isNaN(val.getTime()) ? null : val
|
|
96
|
+
// A day with no time is that day here. new Date() would read it as midnight UTC,
|
|
97
|
+
// which is the day before anywhere west of UTC.
|
|
98
|
+
const day = /^(\d{4})-(\d{2})-(\d{2})$/.exec(val)
|
|
99
|
+
if (day) return new Date(Number(day[1]), Number(day[2]) - 1, Number(day[3]))
|
|
100
|
+
const parsed = new Date(val)
|
|
101
|
+
return isNaN(parsed.getTime()) ? null : parsed
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function formatDate(date: Date, locale?: string): string {
|
|
105
|
+
if (!locale || locale.startsWith("en")) {
|
|
106
|
+
const m = MONTH_NAMES[date.getMonth()].slice(0, 3)
|
|
107
|
+
return `${m} ${date.getDate()}, ${date.getFullYear()}`
|
|
108
|
+
}
|
|
109
|
+
// @date-display-ignore: the picker's own field and calendar in the interface language (Western digits); the chosen day is handed back as a Date, not displayed as a record timestamp.
|
|
110
|
+
return new Intl.DateTimeFormat(locale, {
|
|
111
|
+
day: "numeric",
|
|
112
|
+
month: "short",
|
|
113
|
+
year: "numeric",
|
|
114
|
+
numberingSystem: "latn",
|
|
115
|
+
}).format(date)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function formatMonthYear(year: number, month: number, locale?: string): string {
|
|
119
|
+
if (!locale || locale.startsWith("en")) return `${MONTH_NAMES[month]} ${year}`
|
|
120
|
+
// @date-display-ignore: the picker's own field and calendar in the interface language (Western digits); the chosen day is handed back as a Date, not displayed as a record timestamp.
|
|
121
|
+
return new Intl.DateTimeFormat(locale, { month: "long", year: "numeric", numberingSystem: "latn" }).format(
|
|
122
|
+
new Date(year, month, 1)
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Sunday first, as the grid is laid out. 1 January 2023 was a Sunday. */
|
|
127
|
+
function dayNames(locale?: string): string[] {
|
|
128
|
+
if (!locale || locale.startsWith("en")) return DAY_NAMES
|
|
129
|
+
// @date-display-ignore: the picker's own field and calendar in the interface language (Western digits); the chosen day is handed back as a Date, not displayed as a record timestamp.
|
|
130
|
+
const format = new Intl.DateTimeFormat(locale, { weekday: "narrow" })
|
|
131
|
+
return Array.from({ length: 7 }, (_, i) => format.format(new Date(2023, 0, 1 + i)))
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function isSameDay(d1: Date, d2: Date): boolean {
|
|
135
|
+
return (
|
|
136
|
+
d1.getFullYear() === d2.getFullYear() &&
|
|
137
|
+
d1.getMonth() === d2.getMonth() &&
|
|
138
|
+
d1.getDate() === d2.getDate()
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(
|
|
143
|
+
(
|
|
144
|
+
{
|
|
145
|
+
value,
|
|
146
|
+
defaultValue,
|
|
147
|
+
onChange,
|
|
148
|
+
label,
|
|
149
|
+
required,
|
|
150
|
+
tooltip,
|
|
151
|
+
helperText,
|
|
152
|
+
errorText,
|
|
153
|
+
placeholder = "Select date...",
|
|
154
|
+
clearLabel = "Clear date",
|
|
155
|
+
tooltipTriggerLabel = "More information",
|
|
156
|
+
previousMonthLabel = "Previous month",
|
|
157
|
+
nextMonthLabel = "Next month",
|
|
158
|
+
todayLabel = "Today",
|
|
159
|
+
clearButtonLabel = "Clear",
|
|
160
|
+
disabled,
|
|
161
|
+
clearable = true,
|
|
162
|
+
className,
|
|
163
|
+
id,
|
|
164
|
+
name,
|
|
165
|
+
locale,
|
|
166
|
+
},
|
|
167
|
+
ref
|
|
168
|
+
) => {
|
|
169
|
+
const [selectedDate, setSelectedDate] = React.useState<Date | null>(() => {
|
|
170
|
+
return parseDateValue(value ?? defaultValue)
|
|
171
|
+
})
|
|
172
|
+
const [open, setOpen] = React.useState(false)
|
|
173
|
+
|
|
174
|
+
React.useEffect(() => {
|
|
175
|
+
if (value !== undefined) {
|
|
176
|
+
setSelectedDate(parseDateValue(value))
|
|
177
|
+
}
|
|
178
|
+
}, [value])
|
|
179
|
+
|
|
180
|
+
const activeViewDate = selectedDate || new Date()
|
|
181
|
+
const [viewDate, setViewDate] = React.useState<Date>(activeViewDate)
|
|
182
|
+
|
|
183
|
+
const handleSelectDay = (day: Date) => {
|
|
184
|
+
setSelectedDate(day)
|
|
185
|
+
onChange?.(day)
|
|
186
|
+
setOpen(false)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const handleClear = (e: React.MouseEvent) => {
|
|
190
|
+
e.stopPropagation()
|
|
191
|
+
setSelectedDate(null)
|
|
192
|
+
onChange?.(null)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const today = new Date()
|
|
196
|
+
|
|
197
|
+
// Calendar grid math
|
|
198
|
+
const year = viewDate.getFullYear()
|
|
199
|
+
const month = viewDate.getMonth()
|
|
200
|
+
const firstDay = new Date(year, month, 1)
|
|
201
|
+
const startDayOfWeek = firstDay.getDay()
|
|
202
|
+
const daysInMonth = new Date(year, month + 1, 0).getDate()
|
|
203
|
+
|
|
204
|
+
const prevMonthLastDay = new Date(year, month, 0).getDate()
|
|
205
|
+
const prevDays: Date[] = Array.from({ length: startDayOfWeek }, (_, i) => {
|
|
206
|
+
const dayNum = prevMonthLastDay - startDayOfWeek + i + 1
|
|
207
|
+
return new Date(year, month - 1, dayNum)
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
const currentDays: Date[] = Array.from({ length: daysInMonth }, (_, i) => {
|
|
211
|
+
return new Date(year, month, i + 1)
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
const totalGrid = prevDays.length + currentDays.length <= 35 ? 35 : 42
|
|
215
|
+
const nextDaysCount = totalGrid - (prevDays.length + currentDays.length)
|
|
216
|
+
const nextDays: Date[] = Array.from({ length: nextDaysCount }, (_, i) => {
|
|
217
|
+
return new Date(year, month + 1, i + 1)
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
const hasHeader = label || tooltip || required
|
|
221
|
+
const hasFooter = helperText || errorText
|
|
222
|
+
|
|
223
|
+
const triggerButton = (
|
|
224
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
225
|
+
<PopoverTrigger asChild>
|
|
226
|
+
<button
|
|
227
|
+
type="button"
|
|
228
|
+
id={id}
|
|
229
|
+
data-slot="date-picker-trigger"
|
|
230
|
+
disabled={disabled}
|
|
231
|
+
className={cn(
|
|
232
|
+
"relative flex h-10 w-full items-center justify-start rounded-control border border-input bg-card ps-8 pe-8 py-0.5 text-sm text-foreground transition-colors outline-none 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",
|
|
233
|
+
!selectedDate && "text-muted-foreground font-normal",
|
|
234
|
+
className
|
|
235
|
+
)}
|
|
236
|
+
>
|
|
237
|
+
<div className="absolute start-2.5 flex items-center justify-center size-3.5 text-muted-foreground pointer-events-none shrink-0 z-10">
|
|
238
|
+
<IconCalendar className="size-3.5 shrink-0" aria-hidden="true" />
|
|
239
|
+
</div>
|
|
240
|
+
|
|
241
|
+
<span className="truncate">{selectedDate ? formatDate(selectedDate, locale) : placeholder}</span>
|
|
242
|
+
|
|
243
|
+
<div className="absolute end-2.5 flex items-center justify-center gap-1 shrink-0 z-10">
|
|
244
|
+
{clearable && selectedDate && !disabled && (
|
|
245
|
+
<span
|
|
246
|
+
role="button"
|
|
247
|
+
tabIndex={-1}
|
|
248
|
+
onClick={handleClear}
|
|
249
|
+
aria-label={clearLabel}
|
|
250
|
+
className="rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
|
|
251
|
+
>
|
|
252
|
+
<IconX className="size-3.5" aria-hidden="true" />
|
|
253
|
+
</span>
|
|
254
|
+
)}
|
|
255
|
+
<IconChevronDown className="size-3.5 text-muted-foreground transition-transform duration-200 group-data-[state=open]:rotate-180" />
|
|
256
|
+
</div>
|
|
257
|
+
</button>
|
|
258
|
+
</PopoverTrigger>
|
|
259
|
+
<PopoverContent align="start" className="w-64 p-3 shadow-lg border border-border bg-popover text-popover-foreground rounded-xl">
|
|
260
|
+
{/* Header Month / Year Nav */}
|
|
261
|
+
<div className="flex items-center justify-between pb-2 mb-2 border-b border-border/50">
|
|
262
|
+
<button
|
|
263
|
+
type="button"
|
|
264
|
+
onClick={() => setViewDate(new Date(year, month - 1, 1))}
|
|
265
|
+
aria-label={previousMonthLabel}
|
|
266
|
+
className="flex size-6 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground transition-colors"
|
|
267
|
+
>
|
|
268
|
+
<IconChevronLeft className="size-4 rtl:-scale-x-100" />
|
|
269
|
+
</button>
|
|
270
|
+
<span className="text-xs font-semibold text-foreground">
|
|
271
|
+
{formatMonthYear(year, month, locale)}
|
|
272
|
+
</span>
|
|
273
|
+
<button
|
|
274
|
+
type="button"
|
|
275
|
+
onClick={() => setViewDate(new Date(year, month + 1, 1))}
|
|
276
|
+
aria-label={nextMonthLabel}
|
|
277
|
+
className="flex size-6 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground transition-colors"
|
|
278
|
+
>
|
|
279
|
+
<IconChevronRight className="size-4 rtl:-scale-x-100" />
|
|
280
|
+
</button>
|
|
281
|
+
</div>
|
|
282
|
+
|
|
283
|
+
{/* Day Names Row */}
|
|
284
|
+
<div className="grid grid-cols-7 gap-1 text-center mb-1">
|
|
285
|
+
{dayNames(locale).map((dayName, index) => (
|
|
286
|
+
<span key={index} className="text-xs font-semibold text-muted-foreground uppercase">
|
|
287
|
+
{dayName}
|
|
288
|
+
</span>
|
|
289
|
+
))}
|
|
290
|
+
</div>
|
|
291
|
+
|
|
292
|
+
{/* Calendar Grid */}
|
|
293
|
+
<div className="grid grid-cols-7 gap-1 text-center">
|
|
294
|
+
{prevDays.map((d, idx) => (
|
|
295
|
+
<button
|
|
296
|
+
key={`prev-${idx}`}
|
|
297
|
+
type="button"
|
|
298
|
+
onClick={() => {
|
|
299
|
+
setViewDate(new Date(d.getFullYear(), d.getMonth(), 1))
|
|
300
|
+
handleSelectDay(d)
|
|
301
|
+
}}
|
|
302
|
+
className="flex h-9 w-full items-center justify-center rounded-md text-xs text-muted-foreground/35 hover:bg-muted/40 transition-colors"
|
|
303
|
+
>
|
|
304
|
+
{d.getDate()}
|
|
305
|
+
</button>
|
|
306
|
+
))}
|
|
307
|
+
|
|
308
|
+
{currentDays.map((d) => {
|
|
309
|
+
const isSelected = selectedDate ? isSameDay(d, selectedDate) : false
|
|
310
|
+
const isTodayDay = isSameDay(d, today)
|
|
311
|
+
return (
|
|
312
|
+
<button
|
|
313
|
+
key={d.toISOString()}
|
|
314
|
+
type="button"
|
|
315
|
+
onClick={() => handleSelectDay(d)}
|
|
316
|
+
className={cn(
|
|
317
|
+
"flex h-9 w-full items-center justify-center rounded-md text-xs font-medium transition-colors hover:bg-accent hover:text-accent-foreground",
|
|
318
|
+
isTodayDay && !isSelected && "border border-primary/40 font-semibold text-primary",
|
|
319
|
+
isSelected && "bg-primary text-primary-foreground font-semibold shadow-2xs hover:bg-primary/90"
|
|
320
|
+
)}
|
|
321
|
+
>
|
|
322
|
+
{d.getDate()}
|
|
323
|
+
</button>
|
|
324
|
+
)
|
|
325
|
+
})}
|
|
326
|
+
|
|
327
|
+
{nextDays.map((d, idx) => (
|
|
328
|
+
<button
|
|
329
|
+
key={`next-${idx}`}
|
|
330
|
+
type="button"
|
|
331
|
+
onClick={() => {
|
|
332
|
+
setViewDate(new Date(d.getFullYear(), d.getMonth(), 1))
|
|
333
|
+
handleSelectDay(d)
|
|
334
|
+
}}
|
|
335
|
+
className="flex h-9 w-full items-center justify-center rounded-md text-xs text-muted-foreground/35 hover:bg-muted/40 transition-colors"
|
|
336
|
+
>
|
|
337
|
+
{d.getDate()}
|
|
338
|
+
</button>
|
|
339
|
+
))}
|
|
340
|
+
</div>
|
|
341
|
+
|
|
342
|
+
{/* Footer Today Button */}
|
|
343
|
+
<div className="flex items-center justify-between pt-2 mt-2 border-t border-border/50">
|
|
344
|
+
<button
|
|
345
|
+
type="button"
|
|
346
|
+
onClick={() => {
|
|
347
|
+
const now = new Date()
|
|
348
|
+
setViewDate(now)
|
|
349
|
+
handleSelectDay(now)
|
|
350
|
+
}}
|
|
351
|
+
className="text-xs font-semibold text-primary hover:underline"
|
|
352
|
+
>
|
|
353
|
+
{todayLabel}
|
|
354
|
+
</button>
|
|
355
|
+
{selectedDate && (
|
|
356
|
+
<button
|
|
357
|
+
type="button"
|
|
358
|
+
onClick={() => {
|
|
359
|
+
setSelectedDate(null)
|
|
360
|
+
onChange?.(null)
|
|
361
|
+
setOpen(false)
|
|
362
|
+
}}
|
|
363
|
+
className="text-xs text-muted-foreground hover:text-foreground"
|
|
364
|
+
>
|
|
365
|
+
{clearButtonLabel}
|
|
366
|
+
</button>
|
|
367
|
+
)}
|
|
368
|
+
</div>
|
|
369
|
+
</PopoverContent>
|
|
370
|
+
</Popover>
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
if (name && selectedDate) {
|
|
374
|
+
const isoValue = selectedDate.toISOString().split("T")[0]
|
|
375
|
+
return (
|
|
376
|
+
<div ref={ref} className="w-full">
|
|
377
|
+
<input type="hidden" name={name} value={isoValue} />
|
|
378
|
+
{!hasHeader && !hasFooter ? (
|
|
379
|
+
triggerButton
|
|
380
|
+
) : (
|
|
381
|
+
<div className="flex flex-col gap-1 w-full text-start">
|
|
382
|
+
{hasHeader && (
|
|
383
|
+
<div className="flex items-center gap-1 text-xs font-semibold text-foreground">
|
|
384
|
+
{label && <span>{label}</span>}
|
|
385
|
+
{required && <span className="text-destructive font-semibold ms-0.5">*</span>}
|
|
386
|
+
{tooltip && (
|
|
387
|
+
<TooltipProvider>
|
|
388
|
+
<Tooltip>
|
|
389
|
+
<TooltipTrigger asChild>
|
|
390
|
+
<button
|
|
391
|
+
type="button"
|
|
392
|
+
aria-label={tooltipTriggerLabel}
|
|
393
|
+
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"
|
|
394
|
+
>
|
|
395
|
+
<IconInfoCircle className="size-3.5 shrink-0" aria-hidden="true" />
|
|
396
|
+
</button>
|
|
397
|
+
</TooltipTrigger>
|
|
398
|
+
<TooltipContent>{tooltip}</TooltipContent>
|
|
399
|
+
</Tooltip>
|
|
400
|
+
</TooltipProvider>
|
|
401
|
+
)}
|
|
402
|
+
</div>
|
|
403
|
+
)}
|
|
404
|
+
{triggerButton}
|
|
405
|
+
{errorText ? (
|
|
406
|
+
<p className="text-xs font-medium text-destructive">{errorText}</p>
|
|
407
|
+
) : (
|
|
408
|
+
helperText && <p className="text-xs text-muted-foreground">{helperText}</p>
|
|
409
|
+
)}
|
|
410
|
+
</div>
|
|
411
|
+
)}
|
|
412
|
+
</div>
|
|
413
|
+
)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (!hasHeader && !hasFooter) {
|
|
417
|
+
return <div ref={ref} className="w-full">{triggerButton}</div>
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return (
|
|
421
|
+
<div ref={ref} className="flex flex-col gap-1 w-full text-start">
|
|
422
|
+
{hasHeader && (
|
|
423
|
+
<div className="flex items-center gap-1 text-xs font-semibold text-foreground">
|
|
424
|
+
{label && <span>{label}</span>}
|
|
425
|
+
{required && <span className="text-destructive font-semibold ms-0.5">*</span>}
|
|
426
|
+
{tooltip && (
|
|
427
|
+
<TooltipProvider>
|
|
428
|
+
<Tooltip>
|
|
429
|
+
<TooltipTrigger asChild>
|
|
430
|
+
<button
|
|
431
|
+
type="button"
|
|
432
|
+
aria-label={tooltipTriggerLabel}
|
|
433
|
+
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"
|
|
434
|
+
>
|
|
435
|
+
<IconInfoCircle className="size-3.5 shrink-0" aria-hidden="true" />
|
|
436
|
+
</button>
|
|
437
|
+
</TooltipTrigger>
|
|
438
|
+
<TooltipContent>{tooltip}</TooltipContent>
|
|
439
|
+
</Tooltip>
|
|
440
|
+
</TooltipProvider>
|
|
441
|
+
)}
|
|
442
|
+
</div>
|
|
443
|
+
)}
|
|
444
|
+
{triggerButton}
|
|
445
|
+
{errorText ? (
|
|
446
|
+
<p className="text-xs font-medium text-destructive">{errorText}</p>
|
|
447
|
+
) : (
|
|
448
|
+
helperText && <p className="text-xs text-muted-foreground">{helperText}</p>
|
|
449
|
+
)}
|
|
450
|
+
</div>
|
|
451
|
+
)
|
|
452
|
+
}
|
|
453
|
+
)
|
|
454
|
+
|
|
455
|
+
DatePicker.displayName = "DatePicker"
|
|
456
|
+
|
|
457
|
+
export { DatePicker }
|