@exsto/ds 0.0.1-rc.2 → 0.0.1-rc.22
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 +171 -28
- package/dist/date-picker.js +2 -0
- package/dist/ds/src/date-picker.d.ts +9 -0
- package/dist/ds/src/file-input.d.ts +9 -0
- package/dist/ds/src/index.d.ts +2 -3
- package/dist/ds/src/rich-text-editor.d.ts +8 -0
- package/dist/ds/src/time-field.d.ts +9 -0
- package/dist/file-input.js +2 -0
- package/dist/index.js +79 -2
- package/dist/rich-text-editor.js +4 -0
- package/dist/source-hash.txt +1 -0
- package/dist/styles.css +1201 -404
- package/dist/theme.css +125 -7
- package/dist/time-field.js +2 -0
- package/dist/ui/src/components/edyn/animated-number/animated-number.d.ts +30 -0
- package/dist/ui/src/components/edyn/animated-number/animated-number.js +108 -0
- package/dist/ui/src/components/edyn/animated-number/animated-number.js.map +1 -0
- package/dist/ui/src/components/edyn/animated-number/animated-number.test.d.ts +9 -0
- package/dist/ui/src/components/edyn/animated-number/index.d.ts +1 -0
- package/dist/ui/src/components/edyn/audio-player/audio-player.d.ts +3 -2
- package/dist/ui/src/components/edyn/audio-player/audio-player.js +86 -0
- package/dist/ui/src/components/edyn/audio-player/audio-player.js.map +1 -0
- package/dist/ui/src/components/edyn/date-picker/date-picker.d.ts +86 -0
- package/dist/ui/src/components/edyn/date-picker/date-picker.js +302 -0
- package/dist/ui/src/components/edyn/date-picker/date-picker.js.map +1 -0
- package/dist/ui/src/components/edyn/date-picker/date-picker.state.test.d.ts +9 -0
- package/dist/ui/src/components/edyn/date-picker/date-text.d.ts +40 -0
- package/dist/ui/src/components/edyn/date-picker/date-text.js +105 -0
- package/dist/ui/src/components/edyn/date-picker/date-text.js.map +1 -0
- package/dist/ui/src/components/edyn/date-picker/index.d.ts +2 -0
- package/dist/ui/src/components/edyn/date-range-picker/date-range-picker.d.ts +28 -0
- package/dist/ui/src/components/edyn/date-range-picker/date-range-picker.js +70 -0
- package/dist/ui/src/components/edyn/date-range-picker/date-range-picker.js.map +1 -0
- package/dist/ui/src/components/edyn/date-range-picker/date-range-picker.test.d.ts +9 -0
- package/dist/ui/src/components/edyn/date-range-picker/index.d.ts +1 -0
- package/dist/ui/src/components/edyn/file-input/file-input.d.ts +90 -0
- package/dist/ui/src/components/edyn/file-input/file-input.js +261 -0
- package/dist/ui/src/components/edyn/file-input/file-input.js.map +1 -0
- package/dist/ui/src/components/edyn/file-input/file-input.test.d.ts +8 -0
- package/dist/ui/src/components/edyn/file-input/index.d.ts +1 -0
- package/dist/ui/src/components/edyn/initials-avatar/index.d.ts +1 -0
- package/dist/ui/src/components/edyn/initials-avatar/initials-avatar.d.ts +54 -0
- package/dist/ui/src/components/edyn/initials-avatar/initials-avatar.js +86 -0
- package/dist/ui/src/components/edyn/initials-avatar/initials-avatar.js.map +1 -0
- package/dist/ui/src/components/edyn/initials-avatar/initials-avatar.test.d.ts +10 -0
- package/dist/ui/src/components/edyn/multi-select/index.d.ts +1 -0
- package/dist/ui/src/components/edyn/multi-select/multi-select.d.ts +117 -0
- package/dist/ui/src/components/edyn/multi-select/multi-select.js +342 -0
- package/dist/ui/src/components/edyn/multi-select/multi-select.js.map +1 -0
- package/dist/ui/src/components/edyn/multi-select/multi-select.test.d.ts +9 -0
- package/dist/ui/src/components/edyn/presence/index.d.ts +1 -0
- package/dist/ui/src/components/edyn/presence/presence.d.ts +15 -0
- package/dist/ui/src/components/edyn/presence/presence.js +58 -0
- package/dist/ui/src/components/edyn/presence/presence.js.map +1 -0
- package/dist/ui/src/components/edyn/presence/presence.test.d.ts +8 -0
- package/dist/ui/src/components/edyn/progress-line/index.d.ts +1 -0
- package/dist/ui/src/components/edyn/progress-line/progress-line.d.ts +23 -0
- package/dist/ui/src/components/edyn/progress-line/progress-line.js +100 -0
- package/dist/ui/src/components/edyn/progress-line/progress-line.js.map +1 -0
- package/dist/ui/src/components/edyn/progress-line/progress-line.test.d.ts +9 -0
- package/dist/ui/src/components/edyn/rich-text-content/allow-list.d.ts +11 -0
- package/dist/ui/src/components/edyn/rich-text-content/allow-list.js +37 -0
- package/dist/ui/src/components/edyn/rich-text-content/allow-list.js.map +1 -0
- package/dist/ui/src/components/edyn/rich-text-content/index.d.ts +2 -0
- package/dist/ui/src/components/edyn/rich-text-content/rich-text-content.d.ts +22 -0
- package/dist/ui/src/components/edyn/rich-text-content/rich-text-content.js +124 -0
- package/dist/ui/src/components/edyn/rich-text-content/rich-text-content.js.map +1 -0
- package/dist/ui/src/components/edyn/rich-text-content/rich-text-content.test.d.ts +8 -0
- package/dist/ui/src/components/edyn/rich-text-editor/extensions.d.ts +18 -0
- package/dist/ui/src/components/edyn/rich-text-editor/extensions.js +124 -0
- package/dist/ui/src/components/edyn/rich-text-editor/extensions.js.map +1 -0
- package/dist/ui/src/components/edyn/rich-text-editor/index.d.ts +3 -0
- package/dist/ui/src/components/edyn/rich-text-editor/mention-list.d.ts +17 -0
- package/dist/ui/src/components/edyn/rich-text-editor/mention-list.js +232 -0
- package/dist/ui/src/components/edyn/rich-text-editor/mention-list.js.map +1 -0
- package/dist/ui/src/components/edyn/rich-text-editor/rich-text-editor.d.ts +53 -0
- package/dist/ui/src/components/edyn/rich-text-editor/rich-text-editor.js +244 -0
- package/dist/ui/src/components/edyn/rich-text-editor/rich-text-editor.js.map +1 -0
- package/dist/ui/src/components/edyn/rich-text-editor/rich-text-editor.test.d.ts +6 -0
- package/dist/ui/src/components/edyn/rich-text-editor/serialize.d.ts +13 -0
- package/dist/ui/src/components/edyn/rich-text-editor/serialize.js +55 -0
- package/dist/ui/src/components/edyn/rich-text-editor/serialize.js.map +1 -0
- package/dist/ui/src/components/edyn/rich-text-editor/sync.d.ts +19 -0
- package/dist/ui/src/components/edyn/rich-text-editor/sync.js +34 -0
- package/dist/ui/src/components/edyn/rich-text-editor/sync.js.map +1 -0
- package/dist/ui/src/components/edyn/rich-text-editor/sync.test.d.ts +11 -0
- package/dist/ui/src/components/edyn/rich-text-editor/toolbar.d.ts +20 -0
- package/dist/ui/src/components/edyn/rich-text-editor/toolbar.js +235 -0
- package/dist/ui/src/components/edyn/rich-text-editor/toolbar.js.map +1 -0
- package/dist/ui/src/components/edyn/rich-text-editor/types.d.ts +68 -0
- package/dist/ui/src/components/edyn/rich-text-editor/types.js +26 -0
- package/dist/ui/src/components/edyn/rich-text-editor/types.js.map +1 -0
- package/dist/ui/src/components/edyn/time-field/index.d.ts +1 -0
- package/dist/ui/src/components/edyn/time-field/time-field.d.ts +85 -0
- package/dist/ui/src/components/edyn/time-field/time-field.js +337 -0
- package/dist/ui/src/components/edyn/time-field/time-field.js.map +1 -0
- package/dist/ui/src/components/edyn/time-field/time-field.test.d.ts +8 -0
- package/dist/ui/src/components/edyn/video-player/video-player.d.ts +2 -2
- package/dist/ui/src/components/edyn/video-player/video-player.js +132 -0
- package/dist/ui/src/components/edyn/video-player/video-player.js.map +1 -0
- package/dist/ui/src/components/forwarded-props.test.d.ts +8 -0
- package/dist/ui/src/components/ui/accordion/accordion.d.ts +9 -8
- package/dist/ui/src/components/ui/accordion/accordion.js +83 -0
- package/dist/ui/src/components/ui/accordion/accordion.js.map +1 -0
- package/dist/ui/src/components/ui/alert/alert.js +47 -0
- package/dist/ui/src/components/ui/alert/alert.js.map +1 -0
- package/dist/ui/src/components/ui/alert-dialog/alert-dialog.js +97 -0
- package/dist/ui/src/components/ui/alert-dialog/alert-dialog.js.map +1 -0
- package/dist/ui/src/components/ui/aspect-ratio/aspect-ratio.js +15 -0
- package/dist/ui/src/components/ui/aspect-ratio/aspect-ratio.js.map +1 -0
- package/dist/ui/src/components/ui/attachment/attachment.d.ts +1 -1
- package/dist/ui/src/components/ui/attachment/attachment.js +105 -0
- package/dist/ui/src/components/ui/attachment/attachment.js.map +1 -0
- package/dist/ui/src/components/ui/avatar/avatar.js +51 -0
- package/dist/ui/src/components/ui/avatar/avatar.js.map +1 -0
- package/dist/ui/src/components/ui/badge/badge.d.ts +1 -1
- package/dist/ui/src/components/ui/badge/badge.js +47 -0
- package/dist/ui/src/components/ui/badge/badge.js.map +1 -0
- package/dist/ui/src/components/ui/breadcrumb/breadcrumb.js +73 -0
- package/dist/ui/src/components/ui/breadcrumb/breadcrumb.js.map +1 -0
- package/dist/ui/src/components/ui/bubble/bubble.js +74 -0
- package/dist/ui/src/components/ui/bubble/bubble.js.map +1 -0
- package/dist/ui/src/components/ui/button/button.behavior.test.d.ts +8 -0
- package/dist/ui/src/components/ui/button/button.d.ts +1 -1
- package/dist/ui/src/components/ui/button/button.js +68 -0
- package/dist/ui/src/components/ui/button/button.js.map +1 -0
- package/dist/ui/src/components/ui/button-group/button-group.js +37 -0
- package/dist/ui/src/components/ui/button-group/button-group.js.map +1 -0
- package/dist/ui/src/components/ui/calendar/calendar.behavior.test.d.ts +9 -0
- package/dist/ui/src/components/ui/calendar/calendar.d.ts +1 -1
- package/dist/ui/src/components/ui/calendar/calendar.js +141 -0
- package/dist/ui/src/components/ui/calendar/calendar.js.map +1 -0
- package/dist/ui/src/components/ui/card/card.js +57 -0
- package/dist/ui/src/components/ui/card/card.js.map +1 -0
- package/dist/ui/src/components/ui/carousel/carousel.js +136 -0
- package/dist/ui/src/components/ui/carousel/carousel.js.map +1 -0
- package/dist/ui/src/components/ui/chart/chart.js +168 -0
- package/dist/ui/src/components/ui/chart/chart.js.map +1 -0
- package/dist/ui/src/components/ui/checkbox/checkbox.js +21 -0
- package/dist/ui/src/components/ui/checkbox/checkbox.js.map +1 -0
- package/dist/ui/src/components/ui/collapsible/collapsible.js +26 -0
- package/dist/ui/src/components/ui/collapsible/collapsible.js.map +1 -0
- package/dist/ui/src/components/ui/combobox/combobox.d.ts +15 -1
- package/dist/ui/src/components/ui/combobox/combobox.js +111 -0
- package/dist/ui/src/components/ui/combobox/combobox.js.map +1 -0
- package/dist/ui/src/components/ui/command/command.d.ts +17 -1
- package/dist/ui/src/components/ui/command/command.js +118 -0
- package/dist/ui/src/components/ui/command/command.js.map +1 -0
- package/dist/ui/src/components/ui/context-menu/context-menu.d.ts +1 -1
- package/dist/ui/src/components/ui/context-menu/context-menu.js +145 -0
- package/dist/ui/src/components/ui/context-menu/context-menu.js.map +1 -0
- package/dist/ui/src/components/ui/dialog/dialog.js +94 -0
- package/dist/ui/src/components/ui/dialog/dialog.js.map +1 -0
- package/dist/ui/src/components/ui/direction/direction.js +2 -0
- package/dist/ui/src/components/ui/drawer/drawer.js +88 -0
- package/dist/ui/src/components/ui/drawer/drawer.js.map +1 -0
- package/dist/ui/src/components/ui/dropdown-menu/dropdown-menu.d.ts +12 -1
- package/dist/ui/src/components/ui/dropdown-menu/dropdown-menu.js +159 -0
- package/dist/ui/src/components/ui/dropdown-menu/dropdown-menu.js.map +1 -0
- package/dist/ui/src/components/ui/empty/empty.d.ts +5 -1
- package/dist/ui/src/components/ui/empty/empty.js +72 -0
- package/dist/ui/src/components/ui/empty/empty.js.map +1 -0
- package/dist/ui/src/components/ui/field/field.js +36 -0
- package/dist/ui/src/components/ui/field/field.js.map +1 -0
- package/dist/ui/src/components/ui/hover-card/hover-card.js +39 -0
- package/dist/ui/src/components/ui/hover-card/hover-card.js.map +1 -0
- package/dist/ui/src/components/ui/indicator/indicator.js +79 -0
- package/dist/ui/src/components/ui/indicator/indicator.js.map +1 -0
- package/dist/ui/src/components/ui/input/input.js +16 -0
- package/dist/ui/src/components/ui/input/input.js.map +1 -0
- package/dist/ui/src/components/ui/input-group/input-group.d.ts +1 -1
- package/dist/ui/src/components/ui/input-group/input-group.js +77 -0
- package/dist/ui/src/components/ui/input-group/input-group.js.map +1 -0
- package/dist/ui/src/components/ui/input-otp/input-otp.js +48 -0
- package/dist/ui/src/components/ui/input-otp/input-otp.js.map +1 -0
- package/dist/ui/src/components/ui/item/item.d.ts +1 -1
- package/dist/ui/src/components/ui/item/item.js +122 -0
- package/dist/ui/src/components/ui/item/item.js.map +1 -0
- package/dist/ui/src/components/ui/kbd/kbd.js +21 -0
- package/dist/ui/src/components/ui/kbd/kbd.js.map +1 -0
- package/dist/ui/src/components/ui/label/label.js +14 -0
- package/dist/ui/src/components/ui/label/label.js.map +1 -0
- package/dist/ui/src/components/ui/marker/marker.js +44 -0
- package/dist/ui/src/components/ui/marker/marker.js.map +1 -0
- package/dist/ui/src/components/ui/menubar/menubar.js +140 -0
- package/dist/ui/src/components/ui/menubar/menubar.js.map +1 -0
- package/dist/ui/src/components/ui/message/message.js +50 -0
- package/dist/ui/src/components/ui/message/message.js.map +1 -0
- package/dist/ui/src/components/ui/message-scroller/message-scroller.js +61 -0
- package/dist/ui/src/components/ui/message-scroller/message-scroller.js.map +1 -0
- package/dist/ui/src/components/ui/native-select/native-select.js +39 -0
- package/dist/ui/src/components/ui/native-select/native-select.js.map +1 -0
- package/dist/ui/src/components/ui/navigation-menu/navigation-menu.js +87 -0
- package/dist/ui/src/components/ui/navigation-menu/navigation-menu.js.map +1 -0
- package/dist/ui/src/components/ui/pagination/pagination.d.ts +3 -2
- package/dist/ui/src/components/ui/pagination/pagination.js +104 -0
- package/dist/ui/src/components/ui/pagination/pagination.js.map +1 -0
- package/dist/ui/src/components/ui/popover/popover.d.ts +1 -1
- package/dist/ui/src/components/ui/popover/popover.js +59 -0
- package/dist/ui/src/components/ui/popover/popover.js.map +1 -0
- package/dist/ui/src/components/ui/progress/progress.behavior.test.d.ts +8 -0
- package/dist/ui/src/components/ui/progress/progress.d.ts +43 -1
- package/dist/ui/src/components/ui/progress/progress.js +70 -0
- package/dist/ui/src/components/ui/progress/progress.js.map +1 -0
- package/dist/ui/src/components/ui/questionnaire/questionnaire.js +171 -0
- package/dist/ui/src/components/ui/questionnaire/questionnaire.js.map +1 -0
- package/dist/ui/src/components/ui/radio-group/radio-group.js +29 -0
- package/dist/ui/src/components/ui/radio-group/radio-group.js.map +1 -0
- package/dist/ui/src/components/ui/resizable/resizable.js +29 -0
- package/dist/ui/src/components/ui/resizable/resizable.js.map +1 -0
- package/dist/ui/src/components/ui/scroll-area/index.d.ts +1 -0
- package/dist/ui/src/components/ui/scroll-area/popup-list-scroll.d.ts +13 -0
- package/dist/ui/src/components/ui/scroll-area/popup-list-scroll.js +69 -0
- package/dist/ui/src/components/ui/scroll-area/popup-list-scroll.js.map +1 -0
- package/dist/ui/src/components/ui/scroll-area/scroll-area.behavior.test.d.ts +12 -0
- package/dist/ui/src/components/ui/scroll-area/scroll-area.d.ts +57 -6
- package/dist/ui/src/components/ui/scroll-area/scroll-area.js +125 -0
- package/dist/ui/src/components/ui/scroll-area/scroll-area.js.map +1 -0
- package/dist/ui/src/components/ui/select/select.js +97 -0
- package/dist/ui/src/components/ui/select/select.js.map +1 -0
- package/dist/ui/src/components/ui/separator/separator.behavior.test.d.ts +14 -0
- package/dist/ui/src/components/ui/separator/separator.d.ts +14 -0
- package/dist/ui/src/components/ui/separator/separator.js +30 -0
- package/dist/ui/src/components/ui/separator/separator.js.map +1 -0
- package/dist/ui/src/components/ui/sheet/sheet.d.ts +8 -0
- package/dist/ui/src/components/ui/sheet/sheet.js +99 -0
- package/dist/ui/src/components/ui/sheet/sheet.js.map +1 -0
- package/dist/ui/src/components/ui/sidebar/sidebar.js +383 -0
- package/dist/ui/src/components/ui/sidebar/sidebar.js.map +1 -0
- package/dist/ui/src/components/ui/skeleton/skeleton.js +14 -0
- package/dist/ui/src/components/ui/skeleton/skeleton.js.map +1 -0
- package/dist/ui/src/components/ui/slider/slider.js +49 -0
- package/dist/ui/src/components/ui/slider/slider.js.map +1 -0
- package/dist/ui/src/components/ui/spinner/spinner.js +28 -0
- package/dist/ui/src/components/ui/spinner/spinner.js.map +1 -0
- package/dist/ui/src/components/ui/switch/switch.js +20 -0
- package/dist/ui/src/components/ui/switch/switch.js.map +1 -0
- package/dist/ui/src/components/ui/table/table.behavior.test.d.ts +4 -5
- package/dist/ui/src/components/ui/table/table.d.ts +15 -1
- package/dist/ui/src/components/ui/table/table.js +81 -0
- package/dist/ui/src/components/ui/table/table.js.map +1 -0
- package/dist/ui/src/components/ui/tabs/tabs.d.ts +14 -8
- package/dist/ui/src/components/ui/tabs/tabs.js +115 -0
- package/dist/ui/src/components/ui/tabs/tabs.js.map +1 -0
- package/dist/ui/src/components/ui/textarea/textarea.js +14 -0
- package/dist/ui/src/components/ui/textarea/textarea.js.map +1 -0
- package/dist/ui/src/components/ui/toast/toast.js +124 -0
- package/dist/ui/src/components/ui/toast/toast.js.map +1 -0
- package/dist/ui/src/components/ui/toggle/toggle.js +37 -0
- package/dist/ui/src/components/ui/toggle/toggle.js.map +1 -0
- package/dist/ui/src/components/ui/toggle-group/toggle-group.js +56 -0
- package/dist/ui/src/components/ui/toggle-group/toggle-group.js.map +1 -0
- package/dist/ui/src/components/ui/tooltip/tooltip.js +43 -0
- package/dist/ui/src/components/ui/tooltip/tooltip.js.map +1 -0
- package/dist/ui/src/hooks/use-holds-focusable.d.ts +3 -0
- package/dist/ui/src/hooks/use-holds-focusable.js +33 -0
- package/dist/ui/src/hooks/use-holds-focusable.js.map +1 -0
- package/dist/ui/src/hooks/use-media-player.js +140 -0
- package/dist/ui/src/hooks/use-media-player.js.map +1 -0
- package/dist/ui/src/hooks/use-merged-refs.js +18 -0
- package/dist/ui/src/hooks/use-merged-refs.js.map +1 -0
- package/dist/ui/src/hooks/use-mobile.js +20 -0
- package/dist/ui/src/hooks/use-mobile.js.map +1 -0
- package/dist/ui/src/index.d.ts +8 -0
- package/dist/ui/src/lib/first-weekday.d.ts +6 -0
- package/dist/ui/src/lib/first-weekday.js +34 -0
- package/dist/ui/src/lib/first-weekday.js.map +1 -0
- package/dist/ui/src/lib/focus-guards.d.ts +2 -0
- package/dist/ui/src/lib/focus-guards.js +44 -0
- package/dist/ui/src/lib/focus-guards.js.map +1 -0
- package/dist/ui/src/lib/focus-ring.test.d.ts +8 -0
- package/dist/ui/src/lib/popup-list.d.ts +75 -0
- package/dist/ui/src/lib/popup-list.js +48 -0
- package/dist/ui/src/lib/popup-list.js.map +1 -0
- package/dist/ui/src/lib/popup-list.test.d.ts +10 -0
- package/dist/ui/src/lib/utils.js +21 -0
- package/dist/ui/src/lib/utils.js.map +1 -0
- package/package.json +36 -8
- package/dist/chunks/toggle-group-ByNq8g7H.js +0 -4263
- package/dist/chunks/toggle-group-ByNq8g7H.js.map +0 -1
- package/dist/dom/src/context.d.ts +0 -34
- package/dist/dom/src/define-element.d.ts +0 -11
- package/dist/dom/src/field-control.d.ts +0 -5
- package/dist/dom/src/index.d.ts +0 -6
- package/dist/dom/src/mode.d.ts +0 -8
- package/dist/dom/src/styles.d.ts +0 -6
- package/dist/dom/src/theme-state.d.ts +0 -1
- package/dist/dom/src/types.d.ts +0 -65
- package/dist/ds/src/elements.d.ts +0 -12
- package/dist/elements/src/edx-accordion.d.ts +0 -14
- package/dist/elements/src/edx-accordion.test.d.ts +0 -1
- package/dist/elements/src/edx-alert.d.ts +0 -14
- package/dist/elements/src/edx-audio-player.d.ts +0 -11
- package/dist/elements/src/edx-avatar.d.ts +0 -10
- package/dist/elements/src/edx-badge.d.ts +0 -12
- package/dist/elements/src/edx-breadcrumb.d.ts +0 -11
- package/dist/elements/src/edx-button-group.d.ts +0 -7
- package/dist/elements/src/edx-button.d.ts +0 -20
- package/dist/elements/src/edx-calendar.d.ts +0 -21
- package/dist/elements/src/edx-card.d.ts +0 -8
- package/dist/elements/src/edx-checkbox.d.ts +0 -18
- package/dist/elements/src/edx-combobox.d.ts +0 -28
- package/dist/elements/src/edx-content-components.d.ts +0 -2
- package/dist/elements/src/edx-dialog.d.ts +0 -20
- package/dist/elements/src/edx-drawer.d.ts +0 -21
- package/dist/elements/src/edx-dropdown-menu.d.ts +0 -29
- package/dist/elements/src/edx-field.d.ts +0 -9
- package/dist/elements/src/edx-field.test.d.ts +0 -1
- package/dist/elements/src/edx-indicator.d.ts +0 -14
- package/dist/elements/src/edx-input-group.d.ts +0 -32
- package/dist/elements/src/edx-input-otp.d.ts +0 -19
- package/dist/elements/src/edx-input.d.ts +0 -31
- package/dist/elements/src/edx-interactive-components.d.ts +0 -2
- package/dist/elements/src/edx-label.d.ts +0 -6
- package/dist/elements/src/edx-pagination.d.ts +0 -8
- package/dist/elements/src/edx-popover.d.ts +0 -24
- package/dist/elements/src/edx-progress.d.ts +0 -10
- package/dist/elements/src/edx-radio-group.d.ts +0 -22
- package/dist/elements/src/edx-radio-group.test.d.ts +0 -1
- package/dist/elements/src/edx-scroll-area.d.ts +0 -15
- package/dist/elements/src/edx-scroll-area.test.d.ts +0 -1
- package/dist/elements/src/edx-select.d.ts +0 -34
- package/dist/elements/src/edx-separator.d.ts +0 -10
- package/dist/elements/src/edx-skeleton.d.ts +0 -8
- package/dist/elements/src/edx-slider.d.ts +0 -17
- package/dist/elements/src/edx-slider.test.d.ts +0 -1
- package/dist/elements/src/edx-switch.d.ts +0 -18
- package/dist/elements/src/edx-table.d.ts +0 -13
- package/dist/elements/src/edx-table.test.d.ts +0 -1
- package/dist/elements/src/edx-tabs.d.ts +0 -15
- package/dist/elements/src/edx-tabs.test.d.ts +0 -1
- package/dist/elements/src/edx-textarea.d.ts +0 -25
- package/dist/elements/src/edx-toggle-group.d.ts +0 -27
- package/dist/elements/src/edx-toggle-group.test.d.ts +0 -1
- package/dist/elements/src/edx-toggle.d.ts +0 -18
- package/dist/elements/src/edx-tooltip.d.ts +0 -28
- package/dist/elements/src/edx-video-player.d.ts +0 -16
- package/dist/elements/src/field-control-bridge.d.ts +0 -7
- package/dist/elements/src/index.d.ts +0 -14
- package/dist/elements/src/projected-content.test.d.ts +0 -1
- package/dist/elements/src/registry.d.ts +0 -39
- package/dist/elements/src/registry.test.d.ts +0 -1
- package/dist/elements.js +0 -4020
- package/dist/elements.js.map +0 -1
- /package/dist/{dom/src/define-element.test.d.ts → ui/src/components/edyn/date-picker/date-text.test.d.ts} +0 -0
- /package/dist/{dom/src/native-slot.test.d.ts → ui/src/lib/first-weekday.test.d.ts} +0 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { cn } from "../../../lib/utils.js";
|
|
2
|
+
import { Button } from "../../ui/button/button.js";
|
|
3
|
+
import { Calendar } from "../../ui/calendar/calendar.js";
|
|
4
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../../ui/popover/popover.js";
|
|
5
|
+
import { firstWeekdayOf } from "../../../lib/first-weekday.js";
|
|
6
|
+
import { dateToDay, dayToDate } from "../date-range-picker/date-range-picker.js";
|
|
7
|
+
import { Input } from "../../ui/input/input.js";
|
|
8
|
+
import { datePatternOf, dayProblem, formatDay, parseDateText } from "./date-text.js";
|
|
9
|
+
import { useEffect, useId, useMemo, useRef, useState } from "react";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { IconCalendar } from "@tabler/icons-react";
|
|
12
|
+
//#region ../ui/src/components/edyn/date-picker/date-picker.tsx
|
|
13
|
+
var DEFAULT_DATE_PICKER_LABELS = {
|
|
14
|
+
choose: "Choose date",
|
|
15
|
+
format: (pattern) => `Enter a date as ${pattern}.`,
|
|
16
|
+
notReal: "That date does not exist.",
|
|
17
|
+
beforeMin: (min) => `Choose ${min} or later.`,
|
|
18
|
+
afterMax: (max) => `Choose ${max} or earlier.`,
|
|
19
|
+
unavailable: "That date is not available."
|
|
20
|
+
};
|
|
21
|
+
var problemText = (problem, labels, locale, limits, pattern) => {
|
|
22
|
+
switch (problem) {
|
|
23
|
+
case "format": return labels.format(pattern);
|
|
24
|
+
case "notReal": return labels.notReal;
|
|
25
|
+
case "beforeMin": return labels.beforeMin(limits.min === void 0 ? "" : formatDay(limits.min, locale));
|
|
26
|
+
case "afterMax": return labels.afterMax(limits.max === void 0 ? "" : formatDay(limits.max, locale));
|
|
27
|
+
default: return labels.unavailable;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* One calendar day, typed or picked. The field takes the day in the locale's order (05/03/2026 in en-GB) and reads it
|
|
32
|
+
* when it loses focus, saying inline what is wrong with it; the button, or Alt+ArrowDown in the field, opens a calendar.
|
|
33
|
+
* Escape closes the calendar and gives the focus back to whichever of the two opened it; a day picked puts it on the field.
|
|
34
|
+
*/
|
|
35
|
+
var DatePicker = ({ id, value, onValueChange, min, max, disabledDates, disabled = false, locale = "en-GB", calendarLocale, placeholder, "aria-label": ariaLabel, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, labels: labelOverrides, className }) => {
|
|
36
|
+
const labels = useMemo(() => ({
|
|
37
|
+
...DEFAULT_DATE_PICKER_LABELS,
|
|
38
|
+
...labelOverrides
|
|
39
|
+
}), [labelOverrides]);
|
|
40
|
+
const pattern = useMemo(() => datePatternOf(locale), [locale]);
|
|
41
|
+
const current = value === "" ? void 0 : value;
|
|
42
|
+
const errorId = useId();
|
|
43
|
+
const refField = useRef(null);
|
|
44
|
+
const refInput = useRef(null);
|
|
45
|
+
const refButton = useRef(null);
|
|
46
|
+
const refOpener = useRef("button");
|
|
47
|
+
const refPicked = useRef(false);
|
|
48
|
+
const refPointer = useRef(false);
|
|
49
|
+
const refKnown = useRef(current);
|
|
50
|
+
const refRefused = useRef(null);
|
|
51
|
+
const [text, setText] = useState(current === void 0 ? "" : formatDay(current, locale));
|
|
52
|
+
const [problem, setProblem] = useState(null);
|
|
53
|
+
const [open, setOpen] = useState(false);
|
|
54
|
+
const [formError, setFormError] = useState(null);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
const field = refField.current?.closest("[data-slot=\"field\"]");
|
|
57
|
+
if (!field) return;
|
|
58
|
+
const read = () => setFormError(field.querySelector("[data-slot=\"field-error\"]")?.id || null);
|
|
59
|
+
read();
|
|
60
|
+
const observer = new MutationObserver(read);
|
|
61
|
+
observer.observe(field, {
|
|
62
|
+
childList: true,
|
|
63
|
+
subtree: true,
|
|
64
|
+
attributes: true,
|
|
65
|
+
attributeFilter: ["id"]
|
|
66
|
+
});
|
|
67
|
+
return () => {
|
|
68
|
+
observer.disconnect();
|
|
69
|
+
};
|
|
70
|
+
}, []);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (current !== refKnown.current) {
|
|
73
|
+
refKnown.current = current;
|
|
74
|
+
refRefused.current = null;
|
|
75
|
+
setText(current === void 0 ? "" : formatDay(current, locale));
|
|
76
|
+
setProblem(null);
|
|
77
|
+
}
|
|
78
|
+
}, [current, locale]);
|
|
79
|
+
const report = (day, state) => {
|
|
80
|
+
refKnown.current = day;
|
|
81
|
+
refRefused.current = state.kind === "refused" || state.kind === "out-of-range" ? `${state.text}\u0000${state.problem}` : null;
|
|
82
|
+
onValueChange(day, state);
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Reads the text: a day is reported and written back in full, anything else is said inline and reported as no day,
|
|
86
|
+
* with the state saying whether the field is empty or holds text it refused.
|
|
87
|
+
*/
|
|
88
|
+
const commit = (typed) => {
|
|
89
|
+
const parsed = parseDateText(typed, locale);
|
|
90
|
+
if (parsed.kind === "empty") {
|
|
91
|
+
setProblem(null);
|
|
92
|
+
if (current !== void 0 || refRefused.current !== null) report(void 0, { kind: "empty" });
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const found = parsed.kind === "problem" ? parsed.problem : dayProblem(parsed.day, {
|
|
96
|
+
min,
|
|
97
|
+
max,
|
|
98
|
+
disabledDates
|
|
99
|
+
});
|
|
100
|
+
if (found !== void 0) {
|
|
101
|
+
setProblem(found);
|
|
102
|
+
const message = problemText(found, labels, locale, {
|
|
103
|
+
min,
|
|
104
|
+
max
|
|
105
|
+
}, pattern);
|
|
106
|
+
const seen = refRefused.current === `${typed}\u0000${message}`;
|
|
107
|
+
if (parsed.kind === "day") {
|
|
108
|
+
if (parsed.day !== current || !seen) report(parsed.day, {
|
|
109
|
+
kind: "out-of-range",
|
|
110
|
+
day: parsed.day,
|
|
111
|
+
text: typed,
|
|
112
|
+
problem: message
|
|
113
|
+
});
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (current !== void 0 || !seen) report(void 0, {
|
|
117
|
+
kind: "refused",
|
|
118
|
+
text: typed,
|
|
119
|
+
problem: message
|
|
120
|
+
});
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (parsed.kind === "day") {
|
|
124
|
+
setProblem(null);
|
|
125
|
+
setText(formatDay(parsed.day, locale));
|
|
126
|
+
if (parsed.day !== current || refRefused.current !== null) report(parsed.day, { kind: "day" });
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const pick = (date) => {
|
|
130
|
+
const day = dateToDay(date);
|
|
131
|
+
if (day === void 0) return;
|
|
132
|
+
setProblem(null);
|
|
133
|
+
setText(formatDay(day, locale));
|
|
134
|
+
if (day !== current || refRefused.current !== null) report(day, { kind: "day" });
|
|
135
|
+
refPicked.current = true;
|
|
136
|
+
setOpen(false);
|
|
137
|
+
};
|
|
138
|
+
const openFrom = (opener) => {
|
|
139
|
+
refOpener.current = opener;
|
|
140
|
+
refPicked.current = false;
|
|
141
|
+
setOpen(true);
|
|
142
|
+
};
|
|
143
|
+
/** Where the focus goes when the calendar closes: the field after a day is chosen, else whatever opened it. */
|
|
144
|
+
const focusAfterClose = () => refPicked.current || refOpener.current === "field" ? refInput.current : refButton.current;
|
|
145
|
+
/**
|
|
146
|
+
* Text is read as the person leaves the field. A day (or nothing) is taken at once; a message about text that is not a
|
|
147
|
+
* day is shown too, unless they are only on the way to the calendar: a press of the mouse on the button, or focus
|
|
148
|
+
* going into the calendar that Alt+ArrowDown opened, with the text half typed. Leaving the picker for anywhere else
|
|
149
|
+
* reads whatever is typed.
|
|
150
|
+
*/
|
|
151
|
+
const handleBlur = (event) => {
|
|
152
|
+
const next = event.relatedTarget;
|
|
153
|
+
const intoCalendar = next?.closest("[data-slot=\"popover-content\"]") != null;
|
|
154
|
+
const intoButton = next?.closest("[data-slot=\"date-picker-trigger\"]") != null;
|
|
155
|
+
const typed = refInput.current?.value ?? "";
|
|
156
|
+
if (!(intoCalendar || intoButton || next !== null && refField.current?.contains(next) === true)) {
|
|
157
|
+
commit(typed);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (event.target !== refInput.current) return;
|
|
161
|
+
const onTheWay = intoCalendar || intoButton && refPointer.current;
|
|
162
|
+
const parsed = parseDateText(typed, locale);
|
|
163
|
+
if (parsed.kind === "empty" || parsed.kind === "day" && dayProblem(parsed.day, {
|
|
164
|
+
min,
|
|
165
|
+
max,
|
|
166
|
+
disabledDates
|
|
167
|
+
}) === void 0 || !onTheWay) commit(typed);
|
|
168
|
+
};
|
|
169
|
+
const handleKeyDown = (event) => {
|
|
170
|
+
if (event.key === "ArrowDown" && event.altKey && !disabled) {
|
|
171
|
+
event.preventDefault();
|
|
172
|
+
openFrom("field");
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (event.key === "Escape" && open) {
|
|
176
|
+
event.preventDefault();
|
|
177
|
+
event.stopPropagation();
|
|
178
|
+
refOpener.current = "field";
|
|
179
|
+
setOpen(false);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (event.key === "Enter") {
|
|
183
|
+
const parsed = parseDateText(event.currentTarget.value, locale);
|
|
184
|
+
if (parsed.kind !== "empty" && (parsed.kind === "problem" || dayProblem(parsed.day, {
|
|
185
|
+
min,
|
|
186
|
+
max,
|
|
187
|
+
disabledDates
|
|
188
|
+
}) !== void 0)) event.preventDefault();
|
|
189
|
+
commit(event.currentTarget.value);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
const selected = dayToDate(current);
|
|
193
|
+
const limits = {
|
|
194
|
+
min,
|
|
195
|
+
max
|
|
196
|
+
};
|
|
197
|
+
const invalid = problem !== null || ariaInvalid === true || ariaInvalid === "true";
|
|
198
|
+
const ownMessage = problem !== null && formError === null;
|
|
199
|
+
const describedBy = [...new Set([
|
|
200
|
+
ariaDescribedBy,
|
|
201
|
+
ownMessage ? errorId : void 0,
|
|
202
|
+
formError ?? void 0
|
|
203
|
+
].filter(Boolean))].join(" ") || void 0;
|
|
204
|
+
const isOff = (date) => {
|
|
205
|
+
const day = dateToDay(date);
|
|
206
|
+
return day !== void 0 && dayProblem(day, {
|
|
207
|
+
min,
|
|
208
|
+
max,
|
|
209
|
+
disabledDates
|
|
210
|
+
}) !== void 0;
|
|
211
|
+
};
|
|
212
|
+
const today = /* @__PURE__ */ new Date();
|
|
213
|
+
const start = dayToDate(min);
|
|
214
|
+
const end = dayToDate(max);
|
|
215
|
+
const month = selected ?? (start !== void 0 && today < start ? start : end !== void 0 && today > end ? end : today);
|
|
216
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
217
|
+
"data-slot": "date-picker",
|
|
218
|
+
className: cn("flex flex-col gap-1.5", className),
|
|
219
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
220
|
+
ref: refField,
|
|
221
|
+
className: "relative",
|
|
222
|
+
onPointerDownCapture: () => {
|
|
223
|
+
refPointer.current = true;
|
|
224
|
+
},
|
|
225
|
+
onPointerUpCapture: () => {
|
|
226
|
+
refPointer.current = false;
|
|
227
|
+
},
|
|
228
|
+
children: [/* @__PURE__ */ jsx(Input, {
|
|
229
|
+
ref: refInput,
|
|
230
|
+
id,
|
|
231
|
+
type: "text",
|
|
232
|
+
inputMode: "numeric",
|
|
233
|
+
autoComplete: "off",
|
|
234
|
+
"data-slot": "date-picker-input",
|
|
235
|
+
value: text,
|
|
236
|
+
placeholder: placeholder ?? pattern,
|
|
237
|
+
disabled,
|
|
238
|
+
"aria-label": ariaLabel,
|
|
239
|
+
"aria-invalid": invalid ? true : void 0,
|
|
240
|
+
"aria-describedby": describedBy,
|
|
241
|
+
className: "pr-9",
|
|
242
|
+
onChange: (event) => {
|
|
243
|
+
setText(event.target.value);
|
|
244
|
+
setProblem(null);
|
|
245
|
+
},
|
|
246
|
+
onBlur: handleBlur,
|
|
247
|
+
onKeyDown: handleKeyDown
|
|
248
|
+
}), /* @__PURE__ */ jsxs(Popover, {
|
|
249
|
+
open,
|
|
250
|
+
onOpenChange: (next) => {
|
|
251
|
+
if (next) {
|
|
252
|
+
openFrom("button");
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
setOpen(false);
|
|
256
|
+
},
|
|
257
|
+
children: [/* @__PURE__ */ jsx(PopoverTrigger, {
|
|
258
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
259
|
+
variant: "ghost",
|
|
260
|
+
size: "icon-sm",
|
|
261
|
+
ref: refButton,
|
|
262
|
+
"data-slot": "date-picker-trigger",
|
|
263
|
+
"aria-label": labels.choose,
|
|
264
|
+
disabled,
|
|
265
|
+
className: "absolute top-0.5 right-0.5",
|
|
266
|
+
onBlur: handleBlur
|
|
267
|
+
}),
|
|
268
|
+
children: /* @__PURE__ */ jsx(IconCalendar, { "aria-hidden": "true" })
|
|
269
|
+
}), /* @__PURE__ */ jsx(PopoverContent, {
|
|
270
|
+
anchor: refField,
|
|
271
|
+
align: "start",
|
|
272
|
+
className: "w-auto p-0",
|
|
273
|
+
finalFocus: focusAfterClose,
|
|
274
|
+
onBlur: handleBlur,
|
|
275
|
+
children: /* @__PURE__ */ jsx(Calendar, {
|
|
276
|
+
mode: "single",
|
|
277
|
+
required: true,
|
|
278
|
+
autoFocus: true,
|
|
279
|
+
locale: calendarLocale,
|
|
280
|
+
weekStartsOn: firstWeekdayOf(locale),
|
|
281
|
+
defaultMonth: month,
|
|
282
|
+
startMonth: start,
|
|
283
|
+
endMonth: end,
|
|
284
|
+
selected,
|
|
285
|
+
disabled: isOff,
|
|
286
|
+
onSelect: pick
|
|
287
|
+
})
|
|
288
|
+
})]
|
|
289
|
+
})]
|
|
290
|
+
}), ownMessage && /* @__PURE__ */ jsx("p", {
|
|
291
|
+
id: errorId,
|
|
292
|
+
"data-slot": "date-picker-error",
|
|
293
|
+
role: "alert",
|
|
294
|
+
className: "text-sm text-destructive",
|
|
295
|
+
children: problemText(problem, labels, locale, limits, pattern)
|
|
296
|
+
})]
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
//#endregion
|
|
300
|
+
export { DEFAULT_DATE_PICKER_LABELS, DatePicker };
|
|
301
|
+
|
|
302
|
+
//# sourceMappingURL=date-picker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-picker.js","names":[],"sources":["../../../../../../../ui/src/components/edyn/date-picker/date-picker.tsx"],"sourcesContent":["import { dateToDay, dayToDate } from '@edyn/ui/components/edyn/date-range-picker';\nimport { Button } from '@edyn/ui/components/ui/button';\nimport { Calendar } from '@edyn/ui/components/ui/calendar';\nimport { Input } from '@edyn/ui/components/ui/input';\nimport { Popover, PopoverContent, PopoverTrigger } from '@edyn/ui/components/ui/popover';\nimport { firstWeekdayOf } from '@edyn/ui/lib/first-weekday';\nimport { cn } from '@edyn/ui/lib/utils';\nimport { IconCalendar } from '@tabler/icons-react';\nimport { type ChangeEvent, type FocusEvent, type KeyboardEvent, useEffect, useId, useMemo, useRef, useState } from 'react';\nimport type { Locale } from 'react-day-picker';\nimport { datePatternOf, dayProblem, formatDay, parseDateText, type TDateProblem, type TDisabledDays } from './date-text';\n\n/** Every word the component prints, so a product can translate it. */\nexport interface IDatePickerLabels {\n /** The calendar button's accessible name. */\n choose: string;\n /** Said when the text is not a date; `pattern` is what to type, written the locale's way (`DD/MM/YYYY`). */\n format: (pattern: string) => string;\n notReal: string;\n /** `min` and `max` are written the locale's way. */\n beforeMin: (min: string) => string;\n afterMax: (max: string) => string;\n unavailable: string;\n}\n\nexport const DEFAULT_DATE_PICKER_LABELS: IDatePickerLabels = {\n choose: 'Choose date',\n format: (pattern) => `Enter a date as ${pattern}.`,\n notReal: 'That date does not exist.',\n beforeMin: (min) => `Choose ${min} or later.`,\n afterMax: (max) => `Choose ${max} or earlier.`,\n unavailable: 'That date is not available.',\n};\n\n/**\n * What the field holds when it reports, so a parent can tell apart things that would otherwise look alike:\n * - `day`: a usable day, typed or picked.\n * - `empty`: the field was emptied, or nothing has been put in it. A required field is right to ask for a date.\n * - `refused`: the field holds text that is not a day (not a day, or not a real one). The day reported is `undefined`.\n * `text` is what was typed and `problem` the message the picker shows under the field, in the picker's `labels`.\n * - `out-of-range`: the field holds a real day that `min`, `max` or `disabledDates` refuse. The day IS reported (as the\n * first argument and as `day`), so a form's own rule can judge it and show its message; the field is marked invalid.\n * Check `kind` before treating the day as a usable one.\n *\n * Inside a Field that renders a FieldError, that message is the only one: the picker does not show its own.\n */\nexport type TDatePickerState =\n | { kind: 'day' }\n | { kind: 'empty' }\n | { kind: 'refused'; text: string; problem: string }\n | { kind: 'out-of-range'; day: string; text: string; problem: string };\n\nexport interface IDatePickerProps {\n /** For a Label's htmlFor; inside a Field the Field's label is already wired. */\n id?: string;\n /**\n * The chosen day as `yyyy-mm-dd`, or `undefined` for none (an empty string counts as none, so a value kept for an\n * `<input type=\"date\">` drops in). A string and not a Date, on purpose: a Date is an instant, and the instant for\n * \"5 March\" is another calendar day in another time zone, so a Date serialised for an API drifts a day. The text is\n * what `<input type=\"date\">`, JSON and a .NET `DateOnly` use, and it compares as a day.\n */\n value: string | undefined;\n /**\n * Called with a valid day, or with `undefined` when the field is emptied or its text is not a usable day. The second\n * argument says which of the two it was (see `TDatePickerState`); a caller that has no use for it can ignore it.\n * Text that is refused is reported each time it changes, also when the field held no day before, so a form that\n * tracks the state hears about it. Emptying the field after that reports `empty`.\n */\n onValueChange: (value: string | undefined, state: TDatePickerState) => void;\n /** The earliest and latest day that can be chosen, as `yyyy-mm-dd`, both included. */\n min?: string;\n max?: string;\n /** Days that cannot be chosen: a list of `yyyy-mm-dd`, or a function that says so for one (weekends, say). */\n disabledDates?: TDisabledDays;\n disabled?: boolean;\n /** How a day is written and in which order it is typed (BCP 47); en-GB reads 05/03/2026. */\n locale?: string;\n /** The calendar's own words (month and weekday names), as a date-fns locale; English by default. The first weekday follows `locale`. */\n calendarLocale?: Locale;\n /** What the empty field shows; the pattern for the locale (`DD/MM/YYYY`) by default. */\n placeholder?: string;\n /** An accessible name, when there is no visible label to point at. */\n 'aria-label'?: string;\n /** Marks the field invalid (the kit's destructive border), as a Field's invalid state does. */\n 'aria-invalid'?: boolean | 'true' | 'false';\n /** The id of the text that explains it. Added to what a Field names already, and to the picker's own error. */\n 'aria-describedby'?: string;\n labels?: Partial<IDatePickerLabels>;\n /** Layout only (a width); the look is the kit's. */\n className?: string;\n}\n\nconst problemText = (\n problem: TDateProblem,\n labels: IDatePickerLabels,\n locale: string,\n limits: { min?: string; max?: string },\n pattern: string,\n): string => {\n switch (problem) {\n case 'format':\n return labels.format(pattern);\n case 'notReal':\n return labels.notReal;\n case 'beforeMin':\n return labels.beforeMin(limits.min === undefined ? '' : formatDay(limits.min, locale));\n case 'afterMax':\n return labels.afterMax(limits.max === undefined ? '' : formatDay(limits.max, locale));\n default:\n return labels.unavailable;\n }\n};\n\n/**\n * One calendar day, typed or picked. The field takes the day in the locale's order (05/03/2026 in en-GB) and reads it\n * when it loses focus, saying inline what is wrong with it; the button, or Alt+ArrowDown in the field, opens a calendar.\n * Escape closes the calendar and gives the focus back to whichever of the two opened it; a day picked puts it on the field.\n */\nexport const DatePicker = ({\n id,\n value,\n onValueChange,\n min,\n max,\n disabledDates,\n disabled = false,\n locale = 'en-GB',\n calendarLocale,\n placeholder,\n 'aria-label': ariaLabel,\n 'aria-invalid': ariaInvalid,\n 'aria-describedby': ariaDescribedBy,\n labels: labelOverrides,\n className,\n}: IDatePickerProps) => {\n const labels = useMemo(() => ({ ...DEFAULT_DATE_PICKER_LABELS, ...labelOverrides }), [labelOverrides]);\n const pattern = useMemo(() => datePatternOf(locale), [locale]);\n const current = value === '' ? undefined : value;\n const errorId = useId();\n const refField = useRef<HTMLDivElement | null>(null);\n const refInput = useRef<HTMLInputElement | null>(null);\n const refButton = useRef<HTMLButtonElement | null>(null);\n // What opened the calendar, so that Escape gives the focus back to it: the button when the button did it, the field\n // when Alt+ArrowDown did. Choosing a day is different (see `pick`): the field then shows the day, so it gets the focus.\n const refOpener = useRef<'button' | 'field'>('button');\n const refPicked = useRef(false);\n // The mouse is down inside the picker, so a blur of the field is a click on something in it, not a Tab.\n const refPointer = useRef(false);\n // The day the field last agreed on with the page, so a change from outside is told from our own report of it.\n const refKnown = useRef<string | undefined>(current);\n // The refused text last reported (with its message), or null: told apart from a fresh refusal so it is reported once,\n // and so that emptying a field that held a refused text is reported although it held no day.\n const refRefused = useRef<string | null>(null);\n const [text, setText] = useState(current === undefined ? '' : formatDay(current, locale));\n const [problem, setProblem] = useState<TDateProblem | null>(null);\n const [open, setOpen] = useState(false);\n // The id of the FieldError of the Field around the picker, when it renders one: that message is the only one for the field.\n const [formError, setFormError] = useState<string | null>(null);\n\n useEffect(() => {\n const field = refField.current?.closest('[data-slot=\"field\"]');\n if (!field) {\n return;\n }\n const read = () => setFormError(field.querySelector('[data-slot=\"field-error\"]')?.id || null);\n read();\n const observer = new MutationObserver(read);\n observer.observe(field, { childList: true, subtree: true, attributes: true, attributeFilter: ['id'] });\n return () => {\n observer.disconnect();\n };\n }, []);\n\n useEffect(() => {\n if (current !== refKnown.current) {\n refKnown.current = current;\n refRefused.current = null;\n setText(current === undefined ? '' : formatDay(current, locale));\n setProblem(null);\n }\n }, [current, locale]);\n\n const report = (day: string | undefined, state: TDatePickerState) => {\n refKnown.current = day;\n refRefused.current = state.kind === 'refused' || state.kind === 'out-of-range' ? `${state.text}\\u0000${state.problem}` : null;\n onValueChange(day, state);\n };\n\n /**\n * Reads the text: a day is reported and written back in full, anything else is said inline and reported as no day,\n * with the state saying whether the field is empty or holds text it refused.\n */\n const commit = (typed: string) => {\n const parsed = parseDateText(typed, locale);\n if (parsed.kind === 'empty') {\n setProblem(null);\n if (current !== undefined || refRefused.current !== null) {\n report(undefined, { kind: 'empty' });\n }\n return;\n }\n const found = parsed.kind === 'problem' ? parsed.problem : dayProblem(parsed.day, { min, max, disabledDates });\n if (found !== undefined) {\n setProblem(found);\n const message = problemText(found, labels, locale, { min, max }, pattern);\n const seen = refRefused.current === `${typed}\\u0000${message}`;\n if (parsed.kind === 'day') {\n // A real day that the limits refuse: the text stays as typed and the day is reported, flagged, so that the form's own\n // rule can show its message instead of seeing an empty field.\n if (parsed.day !== current || !seen) {\n report(parsed.day, { kind: 'out-of-range', day: parsed.day, text: typed, problem: message });\n }\n return;\n }\n if (current !== undefined || !seen) {\n report(undefined, { kind: 'refused', text: typed, problem: message });\n }\n return;\n }\n if (parsed.kind === 'day') {\n setProblem(null);\n setText(formatDay(parsed.day, locale));\n if (parsed.day !== current || refRefused.current !== null) {\n report(parsed.day, { kind: 'day' });\n }\n }\n };\n\n const pick = (date: Date | undefined) => {\n const day = dateToDay(date);\n if (day === undefined) {\n return;\n }\n setProblem(null);\n setText(formatDay(day, locale));\n if (day !== current || refRefused.current !== null) {\n report(day, { kind: 'day' });\n }\n refPicked.current = true;\n setOpen(false);\n };\n\n const openFrom = (opener: 'button' | 'field') => {\n refOpener.current = opener;\n refPicked.current = false;\n setOpen(true);\n };\n\n /** Where the focus goes when the calendar closes: the field after a day is chosen, else whatever opened it. */\n const focusAfterClose = (): HTMLElement | null => (refPicked.current || refOpener.current === 'field' ? refInput.current : refButton.current);\n\n /**\n * Text is read as the person leaves the field. A day (or nothing) is taken at once; a message about text that is not a\n * day is shown too, unless they are only on the way to the calendar: a press of the mouse on the button, or focus\n * going into the calendar that Alt+ArrowDown opened, with the text half typed. Leaving the picker for anywhere else\n * reads whatever is typed.\n */\n const handleBlur = (event: FocusEvent<HTMLElement>) => {\n const next = event.relatedTarget as Element | null;\n const intoCalendar = next?.closest('[data-slot=\"popover-content\"]') != null;\n const intoButton = next?.closest('[data-slot=\"date-picker-trigger\"]') != null;\n const typed = refInput.current?.value ?? '';\n if (!(intoCalendar || intoButton || (next !== null && refField.current?.contains(next) === true))) {\n commit(typed);\n return;\n }\n if (event.target !== refInput.current) {\n return;\n }\n const onTheWay = intoCalendar || (intoButton && refPointer.current);\n const parsed = parseDateText(typed, locale);\n const usable = parsed.kind === 'empty' || (parsed.kind === 'day' && dayProblem(parsed.day, { min, max, disabledDates }) === undefined);\n if (usable || !onTheWay) {\n commit(typed);\n }\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key === 'ArrowDown' && event.altKey && !disabled) {\n event.preventDefault();\n openFrom('field');\n return;\n }\n // The field has no key handler of Base UI's to close the calendar, so the key would reach the Sheet or Dialog around\n // it and close that too. While the calendar is open it is this field's key; when it is closed it is the page's.\n if (event.key === 'Escape' && open) {\n event.preventDefault();\n event.stopPropagation();\n // The focus is on the field already, whatever opened the calendar: it stays there.\n refOpener.current = 'field';\n setOpen(false);\n return;\n }\n if (event.key === 'Enter') {\n const parsed = parseDateText(event.currentTarget.value, locale);\n if (parsed.kind !== 'empty' && (parsed.kind === 'problem' || dayProblem(parsed.day, { min, max, disabledDates }) !== undefined)) {\n event.preventDefault();\n }\n commit(event.currentTarget.value);\n }\n };\n\n const selected = dayToDate(current);\n const limits = { min, max };\n const invalid = problem !== null || ariaInvalid === true || ariaInvalid === 'true';\n const ownMessage = problem !== null && formError === null;\n const describedBy =\n [...new Set([ariaDescribedBy, ownMessage ? errorId : undefined, formError ?? undefined].filter(Boolean))].join(' ') || undefined;\n const isOff = (date: Date): boolean => {\n const day = dateToDay(date);\n return day !== undefined && dayProblem(day, { min, max, disabledDates }) !== undefined;\n };\n const today = new Date();\n const start = dayToDate(min);\n const end = dayToDate(max);\n const month = selected ?? (start !== undefined && today < start ? start : end !== undefined && today > end ? end : today);\n\n return (\n <div data-slot=\"date-picker\" className={cn('flex flex-col gap-1.5', className)}>\n <div\n ref={refField}\n className=\"relative\"\n onPointerDownCapture={() => {\n refPointer.current = true;\n }}\n onPointerUpCapture={() => {\n refPointer.current = false;\n }}\n >\n <Input\n ref={refInput}\n id={id}\n type=\"text\"\n inputMode=\"numeric\"\n autoComplete=\"off\"\n data-slot=\"date-picker-input\"\n value={text}\n placeholder={placeholder ?? pattern}\n disabled={disabled}\n aria-label={ariaLabel}\n aria-invalid={invalid ? true : undefined}\n aria-describedby={describedBy}\n className=\"pr-9\"\n onChange={(event: ChangeEvent<HTMLInputElement>) => {\n setText(event.target.value);\n setProblem(null);\n }}\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n />\n <Popover\n open={open}\n onOpenChange={(next) => {\n // Only the button opens it from here (Alt+ArrowDown in the field sets the state itself, through `openFrom`).\n if (next) {\n openFrom('button');\n return;\n }\n setOpen(false);\n }}\n >\n <PopoverTrigger\n render={\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n ref={refButton}\n data-slot=\"date-picker-trigger\"\n aria-label={labels.choose}\n disabled={disabled}\n className=\"absolute top-0.5 right-0.5\"\n onBlur={handleBlur}\n />\n }\n >\n <IconCalendar aria-hidden=\"true\" />\n </PopoverTrigger>\n <PopoverContent anchor={refField} align=\"start\" className=\"w-auto p-0\" finalFocus={focusAfterClose} onBlur={handleBlur}>\n <Calendar\n mode=\"single\"\n required\n autoFocus\n locale={calendarLocale}\n weekStartsOn={firstWeekdayOf(locale)}\n defaultMonth={month}\n startMonth={start}\n endMonth={end}\n selected={selected}\n disabled={isOff}\n onSelect={pick}\n />\n </PopoverContent>\n </Popover>\n </div>\n {ownMessage && (\n <p id={errorId} data-slot=\"date-picker-error\" role=\"alert\" className=\"text-sm text-destructive\">\n {problemText(problem, labels, locale, limits, pattern)}\n </p>\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;AAyBA,IAAa,6BAAgD;CAC3D,QAAQ;CACR,SAAS,YAAY,mBAAmB,QAAQ;CAChD,SAAS;CACT,YAAY,QAAQ,UAAU,IAAI;CAClC,WAAW,QAAQ,UAAU,IAAI;CACjC,aAAa;AACf;AA4DA,IAAM,eACJ,SACA,QACA,QACA,QACA,YACW;CACX,QAAQ,SAAR;EACE,KAAK,UACH,OAAO,OAAO,OAAO,OAAO;EAC9B,KAAK,WACH,OAAO,OAAO;EAChB,KAAK,aACH,OAAO,OAAO,UAAU,OAAO,QAAQ,KAAA,IAAY,KAAK,UAAU,OAAO,KAAK,MAAM,CAAC;EACvF,KAAK,YACH,OAAO,OAAO,SAAS,OAAO,QAAQ,KAAA,IAAY,KAAK,UAAU,OAAO,KAAK,MAAM,CAAC;EACtF,SACE,OAAO,OAAO;CAClB;AACF;;;;;;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AD;IACE,KAAK;IACD;IACJ,MAAK;IACL,WAAU;IACV,cAAa;IACb,aAAU;IACV,OAAO;IACP,aAAa,eAAe;IAClB;IACV,cAAY;IACZ,gBAAc,UAAU,OAAO,KAAA;IAC/B,oBAAkB;IAClB,WAAU;IACV,WAAW,UAAyC;KAClD,QAAQ,MAAM,OAAO,KAAK;KAC1B,WAAW,IAAI;IACjB;IACA,QAAQ;IACR,WAAW;GACZ,CAAA,GACD,qBAAC,SAAD;IACQ;IACN,eAAe,SAAS;KAEtB,IAAI,MAAM;MACR,SAAS,QAAQ;MACjB;KACF;KACA,QAAQ,KAAK;IACf;IATF,UAAA,CAWE,oBAAC,gBAAD;KACE,QACE,oBAAC,QAAD;MACE,SAAQ;MACR,MAAK;MACL,KAAK;MACL,aAAU;MACV,cAAY,OAAO;MACT;MACV,WAAU;MACV,QAAQ;KACT,CAAA;KAGH,UAAA,oBAAC,cAAD,EAAc,eAAY,OAAQ,CAAA;IACpB,CAAA,GAChB,oBAAC,gBAAD;KAAgB,QAAQ;KAAU,OAAM;KAAQ,WAAU;KAAa,YAAY;KAAiB,QAAQ;KAC1G,UAAA,oBAAC,UAAD;MACE,MAAK;MACL,UAAA;MACA,WAAA;MACA,QAAQ;MACR,cAAc,eAAe,MAAM;MACnC,cAAc;MACd,YAAY;MACZ,UAAU;MACA;MACV,UAAU;MACV,UAAU;KACX,CAAA;IACa,CAAA,CACT;GACN,CAAA,CAAA;EACJ,CAAA,GAAA,cACC,oBAAC,KAAD;GAAG,IAAI;GAAS,aAAU;GAAoB,MAAK;GAAQ,WAAU;GAClE,UAAA,YAAY,SAAS,QAAQ,QAAQ,QAAQ,OAAO;EACpD,CAAA,CAEF;;AAET"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a DatePicker tells the page. `undefined` alone cannot say whether the field was emptied or holds text the picker
|
|
3
|
+
* refused, so a required field would add "Enter the date" under the picker's own message. The second argument of
|
|
4
|
+
* `onValueChange` says which, and these tests hold it.
|
|
5
|
+
*
|
|
6
|
+
* PATH TAKEN: the report and the attributes do not depend on layout, so happy-dom is enough. The Playwright spec
|
|
7
|
+
* (`e2e/date-picker.spec.ts`) covers it again in a browser, through a required Field.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading and writing a calendar day as the text a person types.
|
|
3
|
+
*
|
|
4
|
+
* A day is the string `yyyy-mm-dd` everywhere here, never a Date: a Date is an instant, and the instant for "5 March" is a
|
|
5
|
+
* different calendar day in another time zone (local midnight serialised as UTC lands on the 4th east of Greenwich). The
|
|
6
|
+
* string is also what `<input type="date">`, JSON and a .NET `DateOnly` use. Strings of that shape sort and compare as
|
|
7
|
+
* days, so min, max and disabled days are compared as plain strings with no Date involved.
|
|
8
|
+
*/
|
|
9
|
+
export type TDatePart = 'day' | 'month' | 'year';
|
|
10
|
+
/** Why a typed text is not a day the picker can use. */
|
|
11
|
+
export type TDateProblem = 'format' | 'notReal' | 'beforeMin' | 'afterMax' | 'unavailable';
|
|
12
|
+
export type TParsedDay = {
|
|
13
|
+
kind: 'empty';
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'day';
|
|
16
|
+
day: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'problem';
|
|
19
|
+
problem: 'format' | 'notReal';
|
|
20
|
+
};
|
|
21
|
+
/** The order a locale writes day, month and year in: en-GB is day, month, year; en-US month, day, year; sv year first. */
|
|
22
|
+
export declare const datePartsOf: (locale: string) => TDatePart[];
|
|
23
|
+
/** What to type, written the locale's way: `DD/MM/YYYY` for en-GB. */
|
|
24
|
+
export declare const datePatternOf: (locale: string) => string;
|
|
25
|
+
/** A day written the locale's way: `05/03/2026` for en-GB. */
|
|
26
|
+
export declare const formatDay: (day: string, locale: string) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Reads typed text as a day. The locale's order decides which number is the day; a first number of four digits is always
|
|
29
|
+
* a year (so `2026-03-05` is read the same everywhere); the separator can be anything that is not a digit, and eight
|
|
30
|
+
* digits with none (`05032026`) are split by the order. A year must have four digits: `5/3/26` is refused, not guessed.
|
|
31
|
+
*/
|
|
32
|
+
export declare const parseDateText: (text: string, locale: string) => TParsedDay;
|
|
33
|
+
export type TDisabledDays = readonly string[] | ((day: string) => boolean);
|
|
34
|
+
export interface IDayLimits {
|
|
35
|
+
min?: string;
|
|
36
|
+
max?: string;
|
|
37
|
+
disabledDates?: TDisabledDays;
|
|
38
|
+
}
|
|
39
|
+
/** Whether a day is allowed, and if not, which limit it breaks. */
|
|
40
|
+
export declare const dayProblem: (day: string, { min, max, disabledDates }: IDayLimits) => TDateProblem | undefined;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { dateToDay, dayToDate } from "../date-range-picker/date-range-picker.js";
|
|
2
|
+
//#region ../ui/src/components/edyn/date-picker/date-text.ts
|
|
3
|
+
/**
|
|
4
|
+
* Reading and writing a calendar day as the text a person types.
|
|
5
|
+
*
|
|
6
|
+
* A day is the string `yyyy-mm-dd` everywhere here, never a Date: a Date is an instant, and the instant for "5 March" is a
|
|
7
|
+
* different calendar day in another time zone (local midnight serialised as UTC lands on the 4th east of Greenwich). The
|
|
8
|
+
* string is also what `<input type="date">`, JSON and a .NET `DateOnly` use. Strings of that shape sort and compare as
|
|
9
|
+
* days, so min, max and disabled days are compared as plain strings with no Date involved.
|
|
10
|
+
*/
|
|
11
|
+
var SHAPE = {
|
|
12
|
+
day: "2-digit",
|
|
13
|
+
month: "2-digit",
|
|
14
|
+
year: "numeric"
|
|
15
|
+
};
|
|
16
|
+
/** The order a locale writes day, month and year in: en-GB is day, month, year; en-US month, day, year; sv year first. */
|
|
17
|
+
var datePartsOf = (locale) => new Intl.DateTimeFormat(locale, SHAPE).formatToParts(new Date(2e3, 0, 2, 12)).flatMap((part) => part.type === "day" || part.type === "month" || part.type === "year" ? [part.type] : []);
|
|
18
|
+
/** What to type, written the locale's way: `DD/MM/YYYY` for en-GB. */
|
|
19
|
+
var datePatternOf = (locale) => new Intl.DateTimeFormat(locale, SHAPE).formatToParts(new Date(2e3, 0, 2, 12)).map((part) => {
|
|
20
|
+
if (part.type === "day") return "DD";
|
|
21
|
+
if (part.type === "month") return "MM";
|
|
22
|
+
return part.type === "year" ? "YYYY" : part.value;
|
|
23
|
+
}).join("").trim();
|
|
24
|
+
/** A day written the locale's way: `05/03/2026` for en-GB. */
|
|
25
|
+
var formatDay = (day, locale) => {
|
|
26
|
+
const date = dayToDate(day);
|
|
27
|
+
return date === void 0 ? "" : new Intl.DateTimeFormat(locale, SHAPE).format(date);
|
|
28
|
+
};
|
|
29
|
+
var isRealDay = (year, month, dayOfMonth) => {
|
|
30
|
+
if (year < 1e3 || month < 1 || month > 12 || dayOfMonth < 1) return false;
|
|
31
|
+
const date = new Date(year, month - 1, dayOfMonth, 12);
|
|
32
|
+
return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === dayOfMonth;
|
|
33
|
+
};
|
|
34
|
+
var toDay = (year, month, dayOfMonth) => dateToDay(new Date(year, month - 1, dayOfMonth, 12)) ?? "";
|
|
35
|
+
/**
|
|
36
|
+
* Reads typed text as a day. The locale's order decides which number is the day; a first number of four digits is always
|
|
37
|
+
* a year (so `2026-03-05` is read the same everywhere); the separator can be anything that is not a digit, and eight
|
|
38
|
+
* digits with none (`05032026`) are split by the order. A year must have four digits: `5/3/26` is refused, not guessed.
|
|
39
|
+
*/
|
|
40
|
+
var parseDateText = (text, locale) => {
|
|
41
|
+
const trimmed = text.trim();
|
|
42
|
+
if (trimmed === "") return { kind: "empty" };
|
|
43
|
+
if (!/^[\d\s./\-,]+$/.test(trimmed)) return {
|
|
44
|
+
kind: "problem",
|
|
45
|
+
problem: "format"
|
|
46
|
+
};
|
|
47
|
+
const order = datePartsOf(locale);
|
|
48
|
+
let numbers = trimmed.match(/\d+/g) ?? [];
|
|
49
|
+
let parts = order;
|
|
50
|
+
if (numbers.length === 1 && numbers[0]?.length === 8) {
|
|
51
|
+
const digits = numbers[0];
|
|
52
|
+
numbers = order[0] === "year" ? [
|
|
53
|
+
digits.slice(0, 4),
|
|
54
|
+
digits.slice(4, 6),
|
|
55
|
+
digits.slice(6)
|
|
56
|
+
] : [
|
|
57
|
+
digits.slice(0, 2),
|
|
58
|
+
digits.slice(2, 4),
|
|
59
|
+
digits.slice(4)
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
if (numbers.length !== 3) return {
|
|
63
|
+
kind: "problem",
|
|
64
|
+
problem: "format"
|
|
65
|
+
};
|
|
66
|
+
if (numbers[0]?.length === 4) parts = [
|
|
67
|
+
"year",
|
|
68
|
+
"month",
|
|
69
|
+
"day"
|
|
70
|
+
];
|
|
71
|
+
const read = {
|
|
72
|
+
day: "",
|
|
73
|
+
month: "",
|
|
74
|
+
year: ""
|
|
75
|
+
};
|
|
76
|
+
parts.forEach((part, index) => {
|
|
77
|
+
read[part] = numbers[index] ?? "";
|
|
78
|
+
});
|
|
79
|
+
if (read.year.length !== 4 || read.day.length > 2 || read.month.length > 2) return {
|
|
80
|
+
kind: "problem",
|
|
81
|
+
problem: "format"
|
|
82
|
+
};
|
|
83
|
+
const [year, month, dayOfMonth] = [
|
|
84
|
+
Number(read.year),
|
|
85
|
+
Number(read.month),
|
|
86
|
+
Number(read.day)
|
|
87
|
+
];
|
|
88
|
+
return isRealDay(year, month, dayOfMonth) ? {
|
|
89
|
+
kind: "day",
|
|
90
|
+
day: toDay(year, month, dayOfMonth)
|
|
91
|
+
} : {
|
|
92
|
+
kind: "problem",
|
|
93
|
+
problem: "notReal"
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
/** Whether a day is allowed, and if not, which limit it breaks. */
|
|
97
|
+
var dayProblem = (day, { min, max, disabledDates }) => {
|
|
98
|
+
if (min !== void 0 && day < min) return "beforeMin";
|
|
99
|
+
if (max !== void 0 && day > max) return "afterMax";
|
|
100
|
+
return (typeof disabledDates === "function" ? disabledDates(day) : disabledDates?.includes(day) ?? false) ? "unavailable" : void 0;
|
|
101
|
+
};
|
|
102
|
+
//#endregion
|
|
103
|
+
export { datePartsOf, datePatternOf, dayProblem, formatDay, parseDateText };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=date-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-text.js","names":[],"sources":["../../../../../../../ui/src/components/edyn/date-picker/date-text.ts"],"sourcesContent":["/**\n * Reading and writing a calendar day as the text a person types.\n *\n * A day is the string `yyyy-mm-dd` everywhere here, never a Date: a Date is an instant, and the instant for \"5 March\" is a\n * different calendar day in another time zone (local midnight serialised as UTC lands on the 4th east of Greenwich). The\n * string is also what `<input type=\"date\">`, JSON and a .NET `DateOnly` use. Strings of that shape sort and compare as\n * days, so min, max and disabled days are compared as plain strings with no Date involved.\n */\n\nimport { dateToDay, dayToDate } from '@edyn/ui/components/edyn/date-range-picker';\n\nexport type TDatePart = 'day' | 'month' | 'year';\n\n/** Why a typed text is not a day the picker can use. */\nexport type TDateProblem = 'format' | 'notReal' | 'beforeMin' | 'afterMax' | 'unavailable';\n\nexport type TParsedDay = { kind: 'empty' } | { kind: 'day'; day: string } | { kind: 'problem'; problem: 'format' | 'notReal' };\n\nconst SHAPE = { day: '2-digit', month: '2-digit', year: 'numeric' } as const;\n\n/** The order a locale writes day, month and year in: en-GB is day, month, year; en-US month, day, year; sv year first. */\nexport const datePartsOf = (locale: string): TDatePart[] =>\n new Intl.DateTimeFormat(locale, SHAPE)\n .formatToParts(new Date(2000, 0, 2, 12))\n .flatMap((part) => (part.type === 'day' || part.type === 'month' || part.type === 'year' ? [part.type] : []));\n\n/** What to type, written the locale's way: `DD/MM/YYYY` for en-GB. */\nexport const datePatternOf = (locale: string): string =>\n new Intl.DateTimeFormat(locale, SHAPE)\n .formatToParts(new Date(2000, 0, 2, 12))\n .map((part) => {\n if (part.type === 'day') {\n return 'DD';\n }\n if (part.type === 'month') {\n return 'MM';\n }\n return part.type === 'year' ? 'YYYY' : part.value;\n })\n .join('')\n .trim();\n\n/** A day written the locale's way: `05/03/2026` for en-GB. */\nexport const formatDay = (day: string, locale: string): string => {\n const date = dayToDate(day);\n return date === undefined ? '' : new Intl.DateTimeFormat(locale, SHAPE).format(date);\n};\n\nconst isRealDay = (year: number, month: number, dayOfMonth: number): boolean => {\n if (year < 1000 || month < 1 || month > 12 || dayOfMonth < 1) {\n return false;\n }\n const date = new Date(year, month - 1, dayOfMonth, 12);\n return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === dayOfMonth;\n};\n\nconst toDay = (year: number, month: number, dayOfMonth: number): string => dateToDay(new Date(year, month - 1, dayOfMonth, 12)) ?? '';\n\n/**\n * Reads typed text as a day. The locale's order decides which number is the day; a first number of four digits is always\n * a year (so `2026-03-05` is read the same everywhere); the separator can be anything that is not a digit, and eight\n * digits with none (`05032026`) are split by the order. A year must have four digits: `5/3/26` is refused, not guessed.\n */\nexport const parseDateText = (text: string, locale: string): TParsedDay => {\n const trimmed = text.trim();\n if (trimmed === '') {\n return { kind: 'empty' };\n }\n if (!/^[\\d\\s./\\-,]+$/.test(trimmed)) {\n return { kind: 'problem', problem: 'format' };\n }\n const order = datePartsOf(locale);\n let numbers = trimmed.match(/\\d+/g) ?? [];\n let parts: readonly TDatePart[] = order;\n if (numbers.length === 1 && numbers[0]?.length === 8) {\n const digits = numbers[0];\n const yearFirst = order[0] === 'year';\n numbers = yearFirst ? [digits.slice(0, 4), digits.slice(4, 6), digits.slice(6)] : [digits.slice(0, 2), digits.slice(2, 4), digits.slice(4)];\n }\n if (numbers.length !== 3) {\n return { kind: 'problem', problem: 'format' };\n }\n if (numbers[0]?.length === 4) {\n parts = ['year', 'month', 'day'];\n }\n const read: Record<TDatePart, string> = { day: '', month: '', year: '' };\n parts.forEach((part, index) => {\n read[part] = numbers[index] ?? '';\n });\n if (read.year.length !== 4 || read.day.length > 2 || read.month.length > 2) {\n return { kind: 'problem', problem: 'format' };\n }\n const [year, month, dayOfMonth] = [Number(read.year), Number(read.month), Number(read.day)];\n return isRealDay(year, month, dayOfMonth) ? { kind: 'day', day: toDay(year, month, dayOfMonth) } : { kind: 'problem', problem: 'notReal' };\n};\n\nexport type TDisabledDays = readonly string[] | ((day: string) => boolean);\n\nexport interface IDayLimits {\n min?: string;\n max?: string;\n disabledDates?: TDisabledDays;\n}\n\n/** Whether a day is allowed, and if not, which limit it breaks. */\nexport const dayProblem = (day: string, { min, max, disabledDates }: IDayLimits): TDateProblem | undefined => {\n if (min !== undefined && day < min) {\n return 'beforeMin';\n }\n if (max !== undefined && day > max) {\n return 'afterMax';\n }\n const off = typeof disabledDates === 'function' ? disabledDates(day) : (disabledDates?.includes(day) ?? false);\n return off ? 'unavailable' : undefined;\n};\n"],"mappings":";;;;;;;;;;AAkBA,IAAM,QAAQ;CAAE,KAAK;CAAW,OAAO;CAAW,MAAM;AAAU;;AAGlE,IAAa,eAAe,WAC1B,IAAI,KAAK,eAAe,QAAQ,KAAK,CAAC,CACnC,cAAc,IAAI,KAAK,KAAM,GAAG,GAAG,EAAE,CAAC,CAAC,CACvC,SAAS,SAAU,KAAK,SAAS,SAAS,KAAK,SAAS,WAAW,KAAK,SAAS,SAAS,CAAC,KAAK,IAAI,IAAI,CAAC,CAAE;;AAGhH,IAAa,iBAAiB,WAC5B,IAAI,KAAK,eAAe,QAAQ,KAAK,CAAC,CACnC,cAAc,IAAI,KAAK,KAAM,GAAG,GAAG,EAAE,CAAC,CAAC,CACvC,KAAK,SAAS;CACb,IAAI,KAAK,SAAS,OAChB,OAAO;CAET,IAAI,KAAK,SAAS,SAChB,OAAO;CAET,OAAO,KAAK,SAAS,SAAS,SAAS,KAAK;AAC9C,CAAC,CAAC,CACD,KAAK,EAAE,CAAC,CACR,KAAK;;AAGV,IAAa,aAAa,KAAa,WAA2B;CAChE,MAAM,OAAO,UAAU,GAAG;CAC1B,OAAO,SAAS,KAAA,IAAY,KAAK,IAAI,KAAK,eAAe,QAAQ,KAAK,CAAC,CAAC,OAAO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,KAAK,QAAQ,QAAQ,UAAU;CACjC,CAAC;CACD,IAAI,KAAK,KAAK,WAAW,KAAK,KAAK,IAAI,SAAS,KAAK,KAAK,MAAM,SAAS,GACvE,OAAO;EAAE,MAAM;EAAW,SAAS;CAAS;CAE9C,MAAM,CAAC,MAAM,OAAO,cAAc;EAAC,OAAO,KAAK,IAAI;EAAG,OAAO,KAAK,KAAK;EAAG,OAAO,KAAK,GAAG;CAAC;CAC1F,OAAO,UAAU,MAAM,OAAO,UAAU,IAAI;EAAE,MAAM;EAAO,KAAK,MAAM,MAAM,OAAO,UAAU;CAAE,IAAI;EAAE,MAAM;EAAW,SAAS;CAAU;AAC3I;;AAWA,IAAa,cAAc,KAAa,EAAE,KAAK,KAAK,oBAA0D;CAC5G,IAAI,QAAQ,KAAA,KAAa,MAAM,KAC7B,OAAO;CAET,IAAI,QAAQ,KAAA,KAAa,MAAM,KAC7B,OAAO;CAGT,QADY,OAAO,kBAAkB,aAAa,cAAc,GAAG,IAAK,eAAe,SAAS,GAAG,KAAK,SAC3F,gBAAgB,KAAA;AAC/B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef } from 'react';
|
|
2
|
+
/** A range of calendar days as yyyy-mm-dd, either end optional. */
|
|
3
|
+
export type TDateRange = {
|
|
4
|
+
from?: string;
|
|
5
|
+
to?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const dayToDate: (value: string | undefined) => Date | undefined;
|
|
8
|
+
export declare const dateToDay: (date: Date | undefined) => string | undefined;
|
|
9
|
+
/** Anything else a button takes (data-*, aria-*, title) goes to the trigger. */
|
|
10
|
+
export interface IDateRangePickerProps extends Omit<ComponentPropsWithoutRef<'button'>, 'value' | 'defaultValue' | 'placeholder' | 'id' | 'className' | 'children' | 'onChange' | 'type'> {
|
|
11
|
+
id?: string;
|
|
12
|
+
value: TDateRange;
|
|
13
|
+
onValueChange: (value: TDateRange) => void;
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
/**
|
|
16
|
+
* What the trigger says once a range is set. `range` (default) writes the ends; `label` keeps the label, so a
|
|
17
|
+
* range the page shows elsewhere (as a removable chip, say) is not repeated here. In both, the trigger carries
|
|
18
|
+
* `data-set` while either end is set, for a look of its own.
|
|
19
|
+
*/
|
|
20
|
+
summary?: 'range' | 'label';
|
|
21
|
+
/** How the ends are written on the trigger, and which weekday the calendar starts on (BCP 47); en-GB reads 05 Mar 2026 and starts on Monday. */
|
|
22
|
+
locale?: string;
|
|
23
|
+
/** An accessible name for the trigger, when there is no visible label to point at. */
|
|
24
|
+
'aria-label'?: string;
|
|
25
|
+
className?: string;
|
|
26
|
+
}
|
|
27
|
+
/** A range of calendar days, either end optional; two months side by side, one on a phone. */
|
|
28
|
+
export declare const DateRangePicker: ({ id, value, onValueChange, placeholder, locale, summary, "aria-label": ariaLabel, className, ...props }: IDateRangePickerProps) => import('react').JSX.Element;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { cn } from "../../../lib/utils.js";
|
|
2
|
+
import { Button } from "../../ui/button/button.js";
|
|
3
|
+
import { Calendar } from "../../ui/calendar/calendar.js";
|
|
4
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../../ui/popover/popover.js";
|
|
5
|
+
import { useIsMobile } from "../../../hooks/use-mobile.js";
|
|
6
|
+
import { firstWeekdayOf } from "../../../lib/first-weekday.js";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { IconCalendar } from "@tabler/icons-react";
|
|
9
|
+
//#region ../ui/src/components/edyn/date-range-picker/date-range-picker.tsx
|
|
10
|
+
var dayToDate = (value) => value === void 0 ? void 0 : /* @__PURE__ */ new Date(`${value}T12:00:00`);
|
|
11
|
+
var dateToDay = (date) => date === void 0 ? void 0 : `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
|
12
|
+
/**
|
|
13
|
+
* The trigger's accessible name when it is given an `aria-label`: the label, then what the button shows ("Created between:
|
|
14
|
+
* 01 Mar 2026 – 05 Mar 2026"). An aria-label replaces the text inside the button, so on its own it hides the chosen dates from
|
|
15
|
+
* a screen reader and breaks WCAG 2.5.3 (Label in Name: the visible text must be part of the name, so that a person who says
|
|
16
|
+
* what they see can operate it). A label that already contains the visible text is left as it is.
|
|
17
|
+
*/
|
|
18
|
+
var nameWith = (label, shown) => {
|
|
19
|
+
if (label === void 0) return;
|
|
20
|
+
return label.toLowerCase().includes(shown.toLowerCase()) ? label : `${label}: ${shown}`;
|
|
21
|
+
};
|
|
22
|
+
/** A range of calendar days, either end optional; two months side by side, one on a phone. */
|
|
23
|
+
var DateRangePicker = ({ id, value, onValueChange, placeholder = "Select date range", locale = "en-GB", summary = "range", "aria-label": ariaLabel, className, ...props }) => {
|
|
24
|
+
const isMobile = useIsMobile();
|
|
25
|
+
const from = dayToDate(value.from);
|
|
26
|
+
const to = dayToDate(value.to);
|
|
27
|
+
const format = new Intl.DateTimeFormat(locale, {
|
|
28
|
+
day: "2-digit",
|
|
29
|
+
month: "short",
|
|
30
|
+
year: "numeric"
|
|
31
|
+
});
|
|
32
|
+
const ends = [from, to].filter((date) => date !== void 0).map((date) => format.format(date));
|
|
33
|
+
const shown = ends.length === 0 || summary === "label" ? placeholder : ends.join(" – ");
|
|
34
|
+
return /* @__PURE__ */ jsxs(Popover, { children: [/* @__PURE__ */ jsxs(PopoverTrigger, {
|
|
35
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
36
|
+
...props,
|
|
37
|
+
id,
|
|
38
|
+
"aria-label": nameWith(ariaLabel, shown),
|
|
39
|
+
"data-slot": "date-range-picker-trigger",
|
|
40
|
+
"data-set": ends.length > 0 ? "" : void 0,
|
|
41
|
+
variant: "outline",
|
|
42
|
+
className: cn("w-full min-w-0 justify-start font-normal", ends.length === 0 && "text-muted-foreground", className)
|
|
43
|
+
}),
|
|
44
|
+
children: [/* @__PURE__ */ jsx(IconCalendar, { "aria-hidden": "true" }), /* @__PURE__ */ jsx("span", {
|
|
45
|
+
className: "truncate",
|
|
46
|
+
children: shown
|
|
47
|
+
})]
|
|
48
|
+
}), /* @__PURE__ */ jsx(PopoverContent, {
|
|
49
|
+
align: "start",
|
|
50
|
+
className: "w-auto p-0",
|
|
51
|
+
children: /* @__PURE__ */ jsx(Calendar, {
|
|
52
|
+
mode: "range",
|
|
53
|
+
defaultMonth: from,
|
|
54
|
+
numberOfMonths: isMobile ? 1 : 2,
|
|
55
|
+
weekStartsOn: firstWeekdayOf(locale),
|
|
56
|
+
selected: {
|
|
57
|
+
from,
|
|
58
|
+
to
|
|
59
|
+
},
|
|
60
|
+
onSelect: (range) => onValueChange({
|
|
61
|
+
from: dateToDay(range?.from),
|
|
62
|
+
to: dateToDay(range?.to)
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
})] });
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { DateRangePicker, dateToDay, dayToDate };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=date-range-picker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-range-picker.js","names":[],"sources":["../../../../../../../ui/src/components/edyn/date-range-picker/date-range-picker.tsx"],"sourcesContent":["import { Button } from '@edyn/ui/components/ui/button';\nimport { Calendar } from '@edyn/ui/components/ui/calendar';\nimport { Popover, PopoverContent, PopoverTrigger } from '@edyn/ui/components/ui/popover';\nimport { useIsMobile } from '@edyn/ui/hooks/use-mobile';\nimport { firstWeekdayOf } from '@edyn/ui/lib/first-weekday';\nimport { cn } from '@edyn/ui/lib/utils';\nimport { IconCalendar } from '@tabler/icons-react';\nimport type { ComponentPropsWithoutRef } from 'react';\n\n/** A range of calendar days as yyyy-mm-dd, either end optional. */\nexport type TDateRange = { from?: string; to?: string };\n\n// A calendar day is read and written at midday local time, so no time zone or daylight\n// saving change can move it onto the day before or after.\nexport const dayToDate = (value: string | undefined): Date | undefined => (value === undefined ? undefined : new Date(`${value}T12:00:00`));\n\nexport const dateToDay = (date: Date | undefined): string | undefined =>\n date === undefined ? undefined : `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;\n\n/** Anything else a button takes (data-*, aria-*, title) goes to the trigger. */\nexport interface IDateRangePickerProps\n extends Omit<ComponentPropsWithoutRef<'button'>, 'value' | 'defaultValue' | 'placeholder' | 'id' | 'className' | 'children' | 'onChange' | 'type'> {\n id?: string;\n value: TDateRange;\n onValueChange: (value: TDateRange) => void;\n placeholder?: string;\n /**\n * What the trigger says once a range is set. `range` (default) writes the ends; `label` keeps the label, so a\n * range the page shows elsewhere (as a removable chip, say) is not repeated here. In both, the trigger carries\n * `data-set` while either end is set, for a look of its own.\n */\n summary?: 'range' | 'label';\n /** How the ends are written on the trigger, and which weekday the calendar starts on (BCP 47); en-GB reads 05 Mar 2026 and starts on Monday. */\n locale?: string;\n /** An accessible name for the trigger, when there is no visible label to point at. */\n 'aria-label'?: string;\n className?: string;\n}\n\n/**\n * The trigger's accessible name when it is given an `aria-label`: the label, then what the button shows (\"Created between:\n * 01 Mar 2026 – 05 Mar 2026\"). An aria-label replaces the text inside the button, so on its own it hides the chosen dates from\n * a screen reader and breaks WCAG 2.5.3 (Label in Name: the visible text must be part of the name, so that a person who says\n * what they see can operate it). A label that already contains the visible text is left as it is.\n */\nconst nameWith = (label: string | undefined, shown: string): string | undefined => {\n if (label === undefined) {\n return undefined;\n }\n return label.toLowerCase().includes(shown.toLowerCase()) ? label : `${label}: ${shown}`;\n};\n\n/** A range of calendar days, either end optional; two months side by side, one on a phone. */\nexport const DateRangePicker = ({\n id,\n value,\n onValueChange,\n placeholder = 'Select date range',\n locale = 'en-GB',\n summary = 'range',\n 'aria-label': ariaLabel,\n className,\n ...props\n}: IDateRangePickerProps) => {\n const isMobile = useIsMobile();\n const from = dayToDate(value.from);\n const to = dayToDate(value.to);\n const format = new Intl.DateTimeFormat(locale, { day: '2-digit', month: 'short', year: 'numeric' });\n const ends = [from, to].filter((date) => date !== undefined).map((date) => format.format(date));\n const shown = ends.length === 0 || summary === 'label' ? placeholder : ends.join(' – ');\n return (\n <Popover>\n <PopoverTrigger\n render={\n <Button\n {...props}\n id={id}\n aria-label={nameWith(ariaLabel, shown)}\n data-slot=\"date-range-picker-trigger\"\n data-set={ends.length > 0 ? '' : undefined}\n variant=\"outline\"\n className={cn('w-full min-w-0 justify-start font-normal', ends.length === 0 && 'text-muted-foreground', className)}\n />\n }\n >\n <IconCalendar aria-hidden=\"true\" />\n <span className=\"truncate\">{shown}</span>\n </PopoverTrigger>\n <PopoverContent align=\"start\" className=\"w-auto p-0\">\n <Calendar\n mode=\"range\"\n defaultMonth={from}\n numberOfMonths={isMobile ? 1 : 2}\n weekStartsOn={firstWeekdayOf(locale)}\n selected={{ from, to }}\n onSelect={(range) => onValueChange({ from: dateToDay(range?.from), to: dateToDay(range?.to) })}\n />\n </PopoverContent>\n </Popover>\n );\n};\n"],"mappings":";;;;;;;;;AAcA,IAAa,aAAa,UAAiD,UAAU,KAAA,IAAY,KAAA,oBAAY,IAAI,KAAK,GAAG,MAAM,UAAU;AAEzI,IAAa,aAAa,SACxB,SAAS,KAAA,IAAY,KAAA,IAAY,GAAG,KAAK,YAAY,EAAE,GAAG,OAAO,KAAK,SAAS,IAAI,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG,EAAE,GAAG,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG;;;;;;;AA4BlJ,IAAM,YAAY,OAA2B,UAAsC;CACjF,IAAI,UAAU,KAAA,GACZ;CAEF,OAAO,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,YAAY,CAAC,IAAI,QAAQ,GAAG,MAAM,IAAI;AAClF;;AAGA,IAAa,mBAAmB,EAC9B,IACA,OACA,eACA,cAAc,qBACd,SAAS,SACT,UAAU,SACV,cAAc,WACd,WACA,GAAG,YACwB;CAC3B,MAAM,WAAW,YAAY;CAC7B,MAAM,OAAO,UAAU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