@appica/ui-react 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +91 -0
- package/dist/components/accordion/accordion.d.ts +29 -0
- package/dist/components/accordion/accordion.d.ts.map +1 -0
- package/dist/components/accordion/accordion.js +210 -0
- package/dist/components/accordion/accordion.js.map +1 -0
- package/dist/components/alert/alert.d.ts +32 -0
- package/dist/components/alert/alert.d.ts.map +1 -0
- package/dist/components/alert/alert.js +203 -0
- package/dist/components/alert/alert.js.map +1 -0
- package/dist/components/alert-dialog/alert-dialog.d.ts +28 -0
- package/dist/components/alert-dialog/alert-dialog.d.ts.map +1 -0
- package/dist/components/alert-dialog/alert-dialog.js +127 -0
- package/dist/components/alert-dialog/alert-dialog.js.map +1 -0
- package/dist/components/autocomplete/autocomplete.d.ts +48 -0
- package/dist/components/autocomplete/autocomplete.d.ts.map +1 -0
- package/dist/components/autocomplete/autocomplete.js +299 -0
- package/dist/components/autocomplete/autocomplete.js.map +1 -0
- package/dist/components/avatar/avatar.d.ts +29 -0
- package/dist/components/avatar/avatar.d.ts.map +1 -0
- package/dist/components/avatar/avatar.js +115 -0
- package/dist/components/avatar/avatar.js.map +1 -0
- package/dist/components/background-pattern/background-pattern-interactive.d.ts +10 -0
- package/dist/components/background-pattern/background-pattern-interactive.d.ts.map +1 -0
- package/dist/components/background-pattern/background-pattern-interactive.js +72 -0
- package/dist/components/background-pattern/background-pattern-interactive.js.map +1 -0
- package/dist/components/background-pattern/background-pattern-shared.d.ts +12 -0
- package/dist/components/background-pattern/background-pattern-shared.d.ts.map +1 -0
- package/dist/components/background-pattern/background-pattern-shared.js +73 -0
- package/dist/components/background-pattern/background-pattern-shared.js.map +1 -0
- package/dist/components/background-pattern/background-pattern.d.ts +23 -0
- package/dist/components/background-pattern/background-pattern.d.ts.map +1 -0
- package/dist/components/background-pattern/background-pattern.js +49 -0
- package/dist/components/background-pattern/background-pattern.js.map +1 -0
- package/dist/components/background-pattern/index.d.ts +4 -0
- package/dist/components/background-pattern/index.d.ts.map +1 -0
- package/dist/components/background-pattern/index.js +3 -0
- package/dist/components/background-pattern/index.js.map +1 -0
- package/dist/components/badge/badge.d.ts +17 -0
- package/dist/components/badge/badge.d.ts.map +1 -0
- package/dist/components/badge/badge.js +134 -0
- package/dist/components/badge/badge.js.map +1 -0
- package/dist/components/breadcrumb/breadcrumb.d.ts +24 -0
- package/dist/components/breadcrumb/breadcrumb.d.ts.map +1 -0
- package/dist/components/breadcrumb/breadcrumb.js +106 -0
- package/dist/components/breadcrumb/breadcrumb.js.map +1 -0
- package/dist/components/button/button-variants.d.ts +6 -0
- package/dist/components/button/button-variants.d.ts.map +1 -0
- package/dist/components/button/button-variants.js +69 -0
- package/dist/components/button/button-variants.js.map +1 -0
- package/dist/components/button/button.d.ts +10 -0
- package/dist/components/button/button.d.ts.map +1 -0
- package/dist/components/button/button.js +26 -0
- package/dist/components/button/button.js.map +1 -0
- package/dist/components/button/index.d.ts +3 -0
- package/dist/components/button/index.d.ts.map +1 -0
- package/dist/components/button/index.js +3 -0
- package/dist/components/button/index.js.map +1 -0
- package/dist/components/button-group/button-group-context.d.ts +13 -0
- package/dist/components/button-group/button-group-context.d.ts.map +1 -0
- package/dist/components/button-group/button-group-context.js +7 -0
- package/dist/components/button-group/button-group-context.js.map +1 -0
- package/dist/components/button-group/button-group.d.ts +12 -0
- package/dist/components/button-group/button-group.d.ts.map +1 -0
- package/dist/components/button-group/button-group.js +45 -0
- package/dist/components/button-group/button-group.js.map +1 -0
- package/dist/components/calendar/calendar.d.ts +14 -0
- package/dist/components/calendar/calendar.d.ts.map +1 -0
- package/dist/components/calendar/calendar.js +228 -0
- package/dist/components/calendar/calendar.js.map +1 -0
- package/dist/components/carousel/carousel.d.ts +128 -0
- package/dist/components/carousel/carousel.d.ts.map +1 -0
- package/dist/components/carousel/carousel.js +795 -0
- package/dist/components/carousel/carousel.js.map +1 -0
- package/dist/components/checkbox/checkbox.d.ts +7 -0
- package/dist/components/checkbox/checkbox.d.ts.map +1 -0
- package/dist/components/checkbox/checkbox.js +128 -0
- package/dist/components/checkbox/checkbox.js.map +1 -0
- package/dist/components/checkbox-group/checkbox-group.d.ts +9 -0
- package/dist/components/checkbox-group/checkbox-group.d.ts.map +1 -0
- package/dist/components/checkbox-group/checkbox-group.js +18 -0
- package/dist/components/checkbox-group/checkbox-group.js.map +1 -0
- package/dist/components/chip/chip.d.ts +36 -0
- package/dist/components/chip/chip.d.ts.map +1 -0
- package/dist/components/chip/chip.js +159 -0
- package/dist/components/chip/chip.js.map +1 -0
- package/dist/components/collapsible/collapsible.d.ts +11 -0
- package/dist/components/collapsible/collapsible.d.ts.map +1 -0
- package/dist/components/collapsible/collapsible.js +41 -0
- package/dist/components/collapsible/collapsible.js.map +1 -0
- package/dist/components/combobox/combobox.d.ts +57 -0
- package/dist/components/combobox/combobox.d.ts.map +1 -0
- package/dist/components/combobox/combobox.js +456 -0
- package/dist/components/combobox/combobox.js.map +1 -0
- package/dist/components/context-menu/context-menu.d.ts +43 -0
- package/dist/components/context-menu/context-menu.d.ts.map +1 -0
- package/dist/components/context-menu/context-menu.js +243 -0
- package/dist/components/context-menu/context-menu.js.map +1 -0
- package/dist/components/copy-button/copy-button.d.ts +15 -0
- package/dist/components/copy-button/copy-button.d.ts.map +1 -0
- package/dist/components/copy-button/copy-button.js +126 -0
- package/dist/components/copy-button/copy-button.js.map +1 -0
- package/dist/components/countdown/countdown.d.ts +26 -0
- package/dist/components/countdown/countdown.d.ts.map +1 -0
- package/dist/components/countdown/countdown.js +111 -0
- package/dist/components/countdown/countdown.js.map +1 -0
- package/dist/components/date-field/date-field.d.ts +25 -0
- package/dist/components/date-field/date-field.d.ts.map +1 -0
- package/dist/components/date-field/date-field.js +403 -0
- package/dist/components/date-field/date-field.js.map +1 -0
- package/dist/components/date-picker/date-picker.d.ts +58 -0
- package/dist/components/date-picker/date-picker.d.ts.map +1 -0
- package/dist/components/date-picker/date-picker.js +449 -0
- package/dist/components/date-picker/date-picker.js.map +1 -0
- package/dist/components/dialog/dialog.d.ts +30 -0
- package/dist/components/dialog/dialog.d.ts.map +1 -0
- package/dist/components/dialog/dialog.js +138 -0
- package/dist/components/dialog/dialog.js.map +1 -0
- package/dist/components/drawer/drawer.d.ts +39 -0
- package/dist/components/drawer/drawer.d.ts.map +1 -0
- package/dist/components/drawer/drawer.js +270 -0
- package/dist/components/drawer/drawer.js.map +1 -0
- package/dist/components/dropdown-menu/dropdown-menu.d.ts +43 -0
- package/dist/components/dropdown-menu/dropdown-menu.d.ts.map +1 -0
- package/dist/components/dropdown-menu/dropdown-menu.js +235 -0
- package/dist/components/dropdown-menu/dropdown-menu.js.map +1 -0
- package/dist/components/field/field.d.ts +15 -0
- package/dist/components/field/field.d.ts.map +1 -0
- package/dist/components/field/field.js +62 -0
- package/dist/components/field/field.js.map +1 -0
- package/dist/components/fieldset/fieldset.d.ts +9 -0
- package/dist/components/fieldset/fieldset.d.ts.map +1 -0
- package/dist/components/fieldset/fieldset.js +20 -0
- package/dist/components/fieldset/fieldset.js.map +1 -0
- package/dist/components/form/form.d.ts +7 -0
- package/dist/components/form/form.d.ts.map +1 -0
- package/dist/components/form/form.js +9 -0
- package/dist/components/form/form.js.map +1 -0
- package/dist/components/gradient-glow/gradient-glow.d.ts +21 -0
- package/dist/components/gradient-glow/gradient-glow.d.ts.map +1 -0
- package/dist/components/gradient-glow/gradient-glow.js +99 -0
- package/dist/components/gradient-glow/gradient-glow.js.map +1 -0
- package/dist/components/input/index.d.ts +3 -0
- package/dist/components/input/index.d.ts.map +1 -0
- package/dist/components/input/index.js +3 -0
- package/dist/components/input/index.js.map +1 -0
- package/dist/components/input/input-variants.d.ts +7 -0
- package/dist/components/input/input-variants.d.ts.map +1 -0
- package/dist/components/input/input-variants.js +52 -0
- package/dist/components/input/input-variants.js.map +1 -0
- package/dist/components/input/input.d.ts +19 -0
- package/dist/components/input/input.d.ts.map +1 -0
- package/dist/components/input/input.js +96 -0
- package/dist/components/input/input.js.map +1 -0
- package/dist/components/kbd/kbd.d.ts +13 -0
- package/dist/components/kbd/kbd.d.ts.map +1 -0
- package/dist/components/kbd/kbd.js +34 -0
- package/dist/components/kbd/kbd.js.map +1 -0
- package/dist/components/loader/loader.d.ts +10 -0
- package/dist/components/loader/loader.d.ts.map +1 -0
- package/dist/components/loader/loader.js +137 -0
- package/dist/components/loader/loader.js.map +1 -0
- package/dist/components/menubar/menubar.d.ts +44 -0
- package/dist/components/menubar/menubar.d.ts.map +1 -0
- package/dist/components/menubar/menubar.js +114 -0
- package/dist/components/menubar/menubar.js.map +1 -0
- package/dist/components/meter/meter.d.ts +24 -0
- package/dist/components/meter/meter.d.ts.map +1 -0
- package/dist/components/meter/meter.js +105 -0
- package/dist/components/meter/meter.js.map +1 -0
- package/dist/components/navigation/index.d.ts +4 -0
- package/dist/components/navigation/index.d.ts.map +1 -0
- package/dist/components/navigation/index.js +4 -0
- package/dist/components/navigation/index.js.map +1 -0
- package/dist/components/navigation/navigation-context.d.ts +16 -0
- package/dist/components/navigation/navigation-context.d.ts.map +1 -0
- package/dist/components/navigation/navigation-context.js +10 -0
- package/dist/components/navigation/navigation-context.js.map +1 -0
- package/dist/components/navigation/navigation-link-variants.d.ts +9 -0
- package/dist/components/navigation/navigation-link-variants.d.ts.map +1 -0
- package/dist/components/navigation/navigation-link-variants.js +189 -0
- package/dist/components/navigation/navigation-link-variants.js.map +1 -0
- package/dist/components/navigation/navigation-link.d.ts +20 -0
- package/dist/components/navigation/navigation-link.d.ts.map +1 -0
- package/dist/components/navigation/navigation-link.js +54 -0
- package/dist/components/navigation/navigation-link.js.map +1 -0
- package/dist/components/navigation/navigation.d.ts +21 -0
- package/dist/components/navigation/navigation.d.ts.map +1 -0
- package/dist/components/navigation/navigation.js +41 -0
- package/dist/components/navigation/navigation.js.map +1 -0
- package/dist/components/navigation-menu/navigation-menu.d.ts +41 -0
- package/dist/components/navigation-menu/navigation-menu.d.ts.map +1 -0
- package/dist/components/navigation-menu/navigation-menu.js +329 -0
- package/dist/components/navigation-menu/navigation-menu.js.map +1 -0
- package/dist/components/number-field/number-field.d.ts +17 -0
- package/dist/components/number-field/number-field.d.ts.map +1 -0
- package/dist/components/number-field/number-field.js +270 -0
- package/dist/components/number-field/number-field.js.map +1 -0
- package/dist/components/otp-field/otp-field.d.ts +19 -0
- package/dist/components/otp-field/otp-field.d.ts.map +1 -0
- package/dist/components/otp-field/otp-field.js +66 -0
- package/dist/components/otp-field/otp-field.js.map +1 -0
- package/dist/components/pagination/pagination.d.ts +29 -0
- package/dist/components/pagination/pagination.d.ts.map +1 -0
- package/dist/components/pagination/pagination.js +92 -0
- package/dist/components/pagination/pagination.js.map +1 -0
- package/dist/components/popover/popover.d.ts +22 -0
- package/dist/components/popover/popover.d.ts.map +1 -0
- package/dist/components/popover/popover.js +108 -0
- package/dist/components/popover/popover.js.map +1 -0
- package/dist/components/preview-card/preview-card.d.ts +16 -0
- package/dist/components/preview-card/preview-card.d.ts.map +1 -0
- package/dist/components/preview-card/preview-card.js +92 -0
- package/dist/components/preview-card/preview-card.js.map +1 -0
- package/dist/components/progress/progress.d.ts +18 -0
- package/dist/components/progress/progress.d.ts.map +1 -0
- package/dist/components/progress/progress.js +134 -0
- package/dist/components/progress/progress.js.map +1 -0
- package/dist/components/radio/radio.d.ts +7 -0
- package/dist/components/radio/radio.d.ts.map +1 -0
- package/dist/components/radio/radio.js +73 -0
- package/dist/components/radio/radio.js.map +1 -0
- package/dist/components/radio-group/radio-group.d.ts +9 -0
- package/dist/components/radio-group/radio-group.d.ts.map +1 -0
- package/dist/components/radio-group/radio-group.js +19 -0
- package/dist/components/radio-group/radio-group.js.map +1 -0
- package/dist/components/scroll-area/scroll-area.d.ts +14 -0
- package/dist/components/scroll-area/scroll-area.d.ts.map +1 -0
- package/dist/components/scroll-area/scroll-area.js +87 -0
- package/dist/components/scroll-area/scroll-area.js.map +1 -0
- package/dist/components/select/select.d.ts +36 -0
- package/dist/components/select/select.d.ts.map +1 -0
- package/dist/components/select/select.js +345 -0
- package/dist/components/select/select.js.map +1 -0
- package/dist/components/separator/separator.d.ts +10 -0
- package/dist/components/separator/separator.d.ts.map +1 -0
- package/dist/components/separator/separator.js +81 -0
- package/dist/components/separator/separator.js.map +1 -0
- package/dist/components/skeleton/skeleton.d.ts +9 -0
- package/dist/components/skeleton/skeleton.d.ts.map +1 -0
- package/dist/components/skeleton/skeleton.js +27 -0
- package/dist/components/skeleton/skeleton.js.map +1 -0
- package/dist/components/slider/slider.d.ts +11 -0
- package/dist/components/slider/slider.d.ts.map +1 -0
- package/dist/components/slider/slider.js +187 -0
- package/dist/components/slider/slider.js.map +1 -0
- package/dist/components/sparkline/sparkline.d.ts +39 -0
- package/dist/components/sparkline/sparkline.d.ts.map +1 -0
- package/dist/components/sparkline/sparkline.js +356 -0
- package/dist/components/sparkline/sparkline.js.map +1 -0
- package/dist/components/spinner/spinner.d.ts +10 -0
- package/dist/components/spinner/spinner.d.ts.map +1 -0
- package/dist/components/spinner/spinner.js +179 -0
- package/dist/components/spinner/spinner.js.map +1 -0
- package/dist/components/switch/switch.d.ts +33 -0
- package/dist/components/switch/switch.d.ts.map +1 -0
- package/dist/components/switch/switch.js +137 -0
- package/dist/components/switch/switch.js.map +1 -0
- package/dist/components/table/table.d.ts +34 -0
- package/dist/components/table/table.d.ts.map +1 -0
- package/dist/components/table/table.js +108 -0
- package/dist/components/table/table.js.map +1 -0
- package/dist/components/tabs/tabs.d.ts +35 -0
- package/dist/components/tabs/tabs.d.ts.map +1 -0
- package/dist/components/tabs/tabs.js +192 -0
- package/dist/components/tabs/tabs.js.map +1 -0
- package/dist/components/text-animate/text-animate.d.ts +31 -0
- package/dist/components/text-animate/text-animate.d.ts.map +1 -0
- package/dist/components/text-animate/text-animate.js +230 -0
- package/dist/components/text-animate/text-animate.js.map +1 -0
- package/dist/components/textarea/textarea.d.ts +17 -0
- package/dist/components/textarea/textarea.d.ts.map +1 -0
- package/dist/components/textarea/textarea.js +117 -0
- package/dist/components/textarea/textarea.js.map +1 -0
- package/dist/components/thumbnail/thumbnail.d.ts +26 -0
- package/dist/components/thumbnail/thumbnail.d.ts.map +1 -0
- package/dist/components/thumbnail/thumbnail.js +116 -0
- package/dist/components/thumbnail/thumbnail.js.map +1 -0
- package/dist/components/time-field/time-field.d.ts +25 -0
- package/dist/components/time-field/time-field.d.ts.map +1 -0
- package/dist/components/time-field/time-field.js +488 -0
- package/dist/components/time-field/time-field.js.map +1 -0
- package/dist/components/toast/toast.d.ts +59 -0
- package/dist/components/toast/toast.d.ts.map +1 -0
- package/dist/components/toast/toast.js +239 -0
- package/dist/components/toast/toast.js.map +1 -0
- package/dist/components/toc/toc.d.ts +21 -0
- package/dist/components/toc/toc.d.ts.map +1 -0
- package/dist/components/toc/toc.js +185 -0
- package/dist/components/toc/toc.js.map +1 -0
- package/dist/components/toggle/toggle.d.ts +7 -0
- package/dist/components/toggle/toggle.d.ts.map +1 -0
- package/dist/components/toggle/toggle.js +9 -0
- package/dist/components/toggle/toggle.js.map +1 -0
- package/dist/components/toggle-group/toggle-group.d.ts +7 -0
- package/dist/components/toggle-group/toggle-group.d.ts.map +1 -0
- package/dist/components/toggle-group/toggle-group.js +21 -0
- package/dist/components/toggle-group/toggle-group.js.map +1 -0
- package/dist/components/toolbar/toolbar.d.ts +23 -0
- package/dist/components/toolbar/toolbar.d.ts.map +1 -0
- package/dist/components/toolbar/toolbar.js +56 -0
- package/dist/components/toolbar/toolbar.js.map +1 -0
- package/dist/components/tooltip/tooltip.d.ts +16 -0
- package/dist/components/tooltip/tooltip.d.ts.map +1 -0
- package/dist/components/tooltip/tooltip.js +64 -0
- package/dist/components/tooltip/tooltip.js.map +1 -0
- package/dist/floating.d.ts +47 -0
- package/dist/floating.d.ts.map +1 -0
- package/dist/floating.js +35 -0
- package/dist/floating.js.map +1 -0
- package/dist/hooks/use-direction.d.ts +2 -0
- package/dist/hooks/use-direction.d.ts.map +1 -0
- package/dist/hooks/use-direction.js +3 -0
- package/dist/hooks/use-direction.js.map +1 -0
- package/dist/hooks/use-dismissible.d.ts +16 -0
- package/dist/hooks/use-dismissible.d.ts.map +1 -0
- package/dist/hooks/use-dismissible.js +17 -0
- package/dist/hooks/use-dismissible.js.map +1 -0
- package/dist/hooks/use-local-storage.d.ts +24 -0
- package/dist/hooks/use-local-storage.d.ts.map +1 -0
- package/dist/hooks/use-local-storage.js +127 -0
- package/dist/hooks/use-local-storage.js.map +1 -0
- package/dist/hooks/use-media-query.d.ts +20 -0
- package/dist/hooks/use-media-query.d.ts.map +1 -0
- package/dist/hooks/use-media-query.js +19 -0
- package/dist/hooks/use-media-query.js.map +1 -0
- package/dist/hooks/use-reduced-motion.d.ts +7 -0
- package/dist/hooks/use-reduced-motion.d.ts.map +1 -0
- package/dist/hooks/use-reduced-motion.js +13 -0
- package/dist/hooks/use-reduced-motion.js.map +1 -0
- package/dist/hooks/use-theme.d.ts +11 -0
- package/dist/hooks/use-theme.d.ts.map +1 -0
- package/dist/hooks/use-theme.js +9 -0
- package/dist/hooks/use-theme.js.map +1 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/dist/modal.d.ts +42 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +18 -0
- package/dist/modal.js.map +1 -0
- package/dist/providers/direction-provider.d.ts +21 -0
- package/dist/providers/direction-provider.d.ts.map +1 -0
- package/dist/providers/direction-provider.js +9 -0
- package/dist/providers/direction-provider.js.map +1 -0
- package/dist/providers/reduced-motion-provider.d.ts +30 -0
- package/dist/providers/reduced-motion-provider.d.ts.map +1 -0
- package/dist/providers/reduced-motion-provider.js +27 -0
- package/dist/providers/reduced-motion-provider.js.map +1 -0
- package/dist/providers/theme-provider/index.d.ts +5 -0
- package/dist/providers/theme-provider/index.d.ts.map +1 -0
- package/dist/providers/theme-provider/index.js +3 -0
- package/dist/providers/theme-provider/index.js.map +1 -0
- package/dist/providers/theme-provider/theme-provider.d.ts +39 -0
- package/dist/providers/theme-provider/theme-provider.d.ts.map +1 -0
- package/dist/providers/theme-provider/theme-provider.js +118 -0
- package/dist/providers/theme-provider/theme-provider.js.map +1 -0
- package/dist/providers/theme-provider/theme-script.d.ts +28 -0
- package/dist/providers/theme-provider/theme-script.d.ts.map +1 -0
- package/dist/providers/theme-provider/theme-script.js +59 -0
- package/dist/providers/theme-provider/theme-script.js.map +1 -0
- package/dist/utils.d.ts +17 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +51 -0
- package/dist/utils.js.map +1 -0
- package/package.json +479 -0
- package/src/components/accordion/accordion.test.tsx +220 -0
- package/src/components/accordion/accordion.tsx +269 -0
- package/src/components/alert/alert.test.tsx +188 -0
- package/src/components/alert/alert.tsx +243 -0
- package/src/components/alert-dialog/alert-dialog.test.tsx +141 -0
- package/src/components/alert-dialog/alert-dialog.tsx +179 -0
- package/src/components/autocomplete/autocomplete.test.tsx +384 -0
- package/src/components/autocomplete/autocomplete.tsx +442 -0
- package/src/components/avatar/avatar.test.tsx +368 -0
- package/src/components/avatar/avatar.tsx +142 -0
- package/src/components/background-pattern/background-pattern-interactive.tsx +93 -0
- package/src/components/background-pattern/background-pattern-shared.tsx +96 -0
- package/src/components/background-pattern/background-pattern.test.tsx +97 -0
- package/src/components/background-pattern/background-pattern.tsx +67 -0
- package/src/components/background-pattern/index.ts +3 -0
- package/src/components/badge/badge.test.tsx +58 -0
- package/src/components/badge/badge.tsx +149 -0
- package/src/components/breadcrumb/breadcrumb.test.tsx +174 -0
- package/src/components/breadcrumb/breadcrumb.tsx +146 -0
- package/src/components/button/button-variants.ts +69 -0
- package/src/components/button/button.test.tsx +79 -0
- package/src/components/button/button.tsx +28 -0
- package/src/components/button/index.ts +2 -0
- package/src/components/button-group/button-group-context.ts +18 -0
- package/src/components/button-group/button-group.test.tsx +223 -0
- package/src/components/button-group/button-group.tsx +59 -0
- package/src/components/calendar/calendar.test.tsx +69 -0
- package/src/components/calendar/calendar.tsx +295 -0
- package/src/components/carousel/carousel.test.tsx +493 -0
- package/src/components/carousel/carousel.tsx +1003 -0
- package/src/components/checkbox/checkbox.test.tsx +100 -0
- package/src/components/checkbox/checkbox.tsx +154 -0
- package/src/components/checkbox-group/checkbox-group.test.tsx +86 -0
- package/src/components/checkbox-group/checkbox-group.tsx +21 -0
- package/src/components/chip/chip.test.tsx +242 -0
- package/src/components/chip/chip.tsx +234 -0
- package/src/components/collapsible/collapsible.test.tsx +126 -0
- package/src/components/collapsible/collapsible.tsx +47 -0
- package/src/components/combobox/combobox.test.tsx +410 -0
- package/src/components/combobox/combobox.tsx +598 -0
- package/src/components/context-menu/context-menu.test.tsx +226 -0
- package/src/components/context-menu/context-menu.tsx +345 -0
- package/src/components/copy-button/copy-button.test.tsx +147 -0
- package/src/components/copy-button/copy-button.tsx +141 -0
- package/src/components/countdown/countdown.test.tsx +130 -0
- package/src/components/countdown/countdown.tsx +170 -0
- package/src/components/date-field/date-field.test.tsx +373 -0
- package/src/components/date-field/date-field.tsx +512 -0
- package/src/components/date-picker/date-picker.test.tsx +291 -0
- package/src/components/date-picker/date-picker.tsx +572 -0
- package/src/components/dialog/dialog.test.tsx +173 -0
- package/src/components/dialog/dialog.tsx +190 -0
- package/src/components/drawer/drawer.test.tsx +191 -0
- package/src/components/drawer/drawer.tsx +365 -0
- package/src/components/dropdown-menu/dropdown-menu.test.tsx +227 -0
- package/src/components/dropdown-menu/dropdown-menu.tsx +341 -0
- package/src/components/field/field.test.tsx +84 -0
- package/src/components/field/field.tsx +71 -0
- package/src/components/fieldset/fieldset.test.tsx +62 -0
- package/src/components/fieldset/fieldset.tsx +24 -0
- package/src/components/form/form.test.tsx +61 -0
- package/src/components/form/form.tsx +11 -0
- package/src/components/gradient-glow/gradient-glow.test.tsx +110 -0
- package/src/components/gradient-glow/gradient-glow.tsx +132 -0
- package/src/components/input/index.ts +2 -0
- package/src/components/input/input-variants.ts +52 -0
- package/src/components/input/input.test.tsx +118 -0
- package/src/components/input/input.tsx +120 -0
- package/src/components/kbd/kbd.test.tsx +119 -0
- package/src/components/kbd/kbd.tsx +48 -0
- package/src/components/loader/loader.test.tsx +57 -0
- package/src/components/loader/loader.tsx +163 -0
- package/src/components/menubar/menubar.test.tsx +162 -0
- package/src/components/menubar/menubar.tsx +226 -0
- package/src/components/meter/meter.test.tsx +172 -0
- package/src/components/meter/meter.tsx +144 -0
- package/src/components/navigation/index.ts +3 -0
- package/src/components/navigation/navigation-context.ts +24 -0
- package/src/components/navigation/navigation-link-variants.ts +197 -0
- package/src/components/navigation/navigation-link.tsx +90 -0
- package/src/components/navigation/navigation.test.tsx +253 -0
- package/src/components/navigation/navigation.tsx +74 -0
- package/src/components/navigation-menu/navigation-menu.test.tsx +258 -0
- package/src/components/navigation-menu/navigation-menu.tsx +410 -0
- package/src/components/number-field/number-field.test.tsx +224 -0
- package/src/components/number-field/number-field.tsx +310 -0
- package/src/components/otp-field/otp-field.test.tsx +113 -0
- package/src/components/otp-field/otp-field.tsx +105 -0
- package/src/components/pagination/pagination.test.tsx +147 -0
- package/src/components/pagination/pagination.tsx +139 -0
- package/src/components/popover/popover.test.tsx +135 -0
- package/src/components/popover/popover.tsx +134 -0
- package/src/components/preview-card/preview-card.test.tsx +99 -0
- package/src/components/preview-card/preview-card.tsx +103 -0
- package/src/components/progress/progress.test.tsx +109 -0
- package/src/components/progress/progress.tsx +151 -0
- package/src/components/radio/radio.test.tsx +141 -0
- package/src/components/radio/radio.tsx +94 -0
- package/src/components/radio-group/radio-group.test.tsx +80 -0
- package/src/components/radio-group/radio-group.tsx +22 -0
- package/src/components/scroll-area/scroll-area.test.tsx +133 -0
- package/src/components/scroll-area/scroll-area.tsx +101 -0
- package/src/components/select/select.test.tsx +251 -0
- package/src/components/select/select.tsx +446 -0
- package/src/components/separator/separator.test.tsx +46 -0
- package/src/components/separator/separator.tsx +95 -0
- package/src/components/skeleton/skeleton.test.tsx +55 -0
- package/src/components/skeleton/skeleton.tsx +33 -0
- package/src/components/slider/slider.test.tsx +123 -0
- package/src/components/slider/slider.tsx +262 -0
- package/src/components/sparkline/sparkline.test.tsx +249 -0
- package/src/components/sparkline/sparkline.tsx +446 -0
- package/src/components/spinner/spinner.test.tsx +57 -0
- package/src/components/spinner/spinner.tsx +219 -0
- package/src/components/switch/switch.test.tsx +100 -0
- package/src/components/switch/switch.tsx +166 -0
- package/src/components/table/table.test.tsx +175 -0
- package/src/components/table/table.tsx +157 -0
- package/src/components/tabs/tabs.test.tsx +165 -0
- package/src/components/tabs/tabs.tsx +246 -0
- package/src/components/text-animate/text-animate.test.tsx +125 -0
- package/src/components/text-animate/text-animate.tsx +354 -0
- package/src/components/textarea/textarea.test.tsx +188 -0
- package/src/components/textarea/textarea.tsx +144 -0
- package/src/components/thumbnail/thumbnail.test.tsx +217 -0
- package/src/components/thumbnail/thumbnail.tsx +139 -0
- package/src/components/time-field/time-field.test.tsx +376 -0
- package/src/components/time-field/time-field.tsx +625 -0
- package/src/components/toast/toast.test.tsx +277 -0
- package/src/components/toast/toast.tsx +377 -0
- package/src/components/toc/toc.test.tsx +197 -0
- package/src/components/toc/toc.tsx +233 -0
- package/src/components/toggle/toggle.test.tsx +109 -0
- package/src/components/toggle/toggle.tsx +10 -0
- package/src/components/toggle-group/toggle-group.test.tsx +95 -0
- package/src/components/toggle-group/toggle-group.tsx +21 -0
- package/src/components/toolbar/toolbar.test.tsx +78 -0
- package/src/components/toolbar/toolbar.tsx +77 -0
- package/src/components/tooltip/tooltip.test.tsx +100 -0
- package/src/components/tooltip/tooltip.tsx +78 -0
- package/src/floating.test.ts +40 -0
- package/src/floating.ts +103 -0
- package/src/globals.d.ts +34 -0
- package/src/hooks/use-direction.ts +3 -0
- package/src/hooks/use-dismissible.ts +33 -0
- package/src/hooks/use-local-storage.test.tsx +63 -0
- package/src/hooks/use-local-storage.ts +190 -0
- package/src/hooks/use-media-query.test.tsx +65 -0
- package/src/hooks/use-media-query.ts +38 -0
- package/src/hooks/use-reduced-motion.ts +17 -0
- package/src/hooks/use-theme.ts +16 -0
- package/src/index.ts +76 -0
- package/src/modal.test.ts +34 -0
- package/src/modal.ts +80 -0
- package/src/providers/direction-provider.test.tsx +20 -0
- package/src/providers/direction-provider.tsx +26 -0
- package/src/providers/reduced-motion-provider.test.tsx +42 -0
- package/src/providers/reduced-motion-provider.tsx +58 -0
- package/src/providers/theme-provider/index.ts +4 -0
- package/src/providers/theme-provider/theme-provider.test.tsx +97 -0
- package/src/providers/theme-provider/theme-provider.tsx +169 -0
- package/src/providers/theme-provider/theme-script.tsx +108 -0
- package/src/test/setup.ts +27 -0
- package/src/test/vitest-axe.d.ts +7 -0
- package/src/utils.test.tsx +63 -0
- package/src/utils.ts +57 -0
- package/styles.css +523 -0
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { type VariantProps } from 'class-variance-authority'
|
|
5
|
+
import { useFieldRootContext } from '@base-ui/react/internals/field-root-context'
|
|
6
|
+
import { cn } from '../../utils'
|
|
7
|
+
import { inputVariants } from '../input/input-variants'
|
|
8
|
+
|
|
9
|
+
type TimeFieldVariant = NonNullable<VariantProps<typeof inputVariants>['variant']>
|
|
10
|
+
type TimeFieldSize = NonNullable<VariantProps<typeof inputVariants>['size']>
|
|
11
|
+
|
|
12
|
+
type SegmentType = 'hour24' | 'hour12' | 'minute' | 'second' | 'period'
|
|
13
|
+
type SegmentToken = 'H' | 'HH' | 'h' | 'hh' | 'm' | 'mm' | 's' | 'ss' | 'a'
|
|
14
|
+
|
|
15
|
+
interface SegmentNode {
|
|
16
|
+
kind: 'segment'
|
|
17
|
+
type: SegmentType
|
|
18
|
+
token: SegmentToken
|
|
19
|
+
index: number
|
|
20
|
+
}
|
|
21
|
+
interface LiteralNode {
|
|
22
|
+
kind: 'literal'
|
|
23
|
+
text: string
|
|
24
|
+
}
|
|
25
|
+
type FormatNode = SegmentNode | LiteralNode
|
|
26
|
+
|
|
27
|
+
interface TimeFieldProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'defaultValue' | 'onChange'> {
|
|
28
|
+
value?: string | null
|
|
29
|
+
defaultValue?: string | null
|
|
30
|
+
onValueChange?: (time: string | null) => void
|
|
31
|
+
format?: string
|
|
32
|
+
variant?: TimeFieldVariant
|
|
33
|
+
size?: TimeFieldSize
|
|
34
|
+
startSlot?: React.ReactNode
|
|
35
|
+
endSlot?: React.ReactNode
|
|
36
|
+
disabled?: boolean
|
|
37
|
+
readOnly?: boolean
|
|
38
|
+
required?: boolean
|
|
39
|
+
name?: string
|
|
40
|
+
unstyled?: boolean
|
|
41
|
+
ref?: React.Ref<HTMLDivElement>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface Parts {
|
|
45
|
+
hours: number | null
|
|
46
|
+
minutes: number | null
|
|
47
|
+
seconds: number | null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const EMPTY_PARTS: Parts = { hours: null, minutes: null, seconds: null }
|
|
51
|
+
|
|
52
|
+
const TOKEN_PATTERN = 'HH|H|hh|h|mm|m|ss|s|a'
|
|
53
|
+
|
|
54
|
+
const PLACEHOLDERS: Record<SegmentToken, string> = {
|
|
55
|
+
H: 'HH',
|
|
56
|
+
HH: 'HH',
|
|
57
|
+
h: 'hh',
|
|
58
|
+
hh: 'hh',
|
|
59
|
+
m: 'mm',
|
|
60
|
+
mm: 'mm',
|
|
61
|
+
s: 'ss',
|
|
62
|
+
ss: 'ss',
|
|
63
|
+
a: 'AM',
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function tokenToType(token: SegmentToken): SegmentType {
|
|
67
|
+
if (token === 'H' || token === 'HH') return 'hour24'
|
|
68
|
+
if (token === 'h' || token === 'hh') return 'hour12'
|
|
69
|
+
if (token === 'm' || token === 'mm') return 'minute'
|
|
70
|
+
if (token === 's' || token === 'ss') return 'second'
|
|
71
|
+
return 'period'
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function parseFormat(formatStr: string): FormatNode[] {
|
|
75
|
+
const nodes: FormatNode[] = []
|
|
76
|
+
const re = new RegExp(TOKEN_PATTERN, 'g')
|
|
77
|
+
let lastIndex = 0
|
|
78
|
+
let segmentIndex = 0
|
|
79
|
+
let match: RegExpExecArray | null
|
|
80
|
+
while ((match = re.exec(formatStr)) !== null) {
|
|
81
|
+
if (match.index > lastIndex) {
|
|
82
|
+
nodes.push({ kind: 'literal', text: formatStr.slice(lastIndex, match.index) })
|
|
83
|
+
}
|
|
84
|
+
const token = match[0] as SegmentToken
|
|
85
|
+
nodes.push({ kind: 'segment', type: tokenToType(token), token, index: segmentIndex++ })
|
|
86
|
+
lastIndex = match.index + token.length
|
|
87
|
+
}
|
|
88
|
+
if (lastIndex < formatStr.length) {
|
|
89
|
+
nodes.push({ kind: 'literal', text: formatStr.slice(lastIndex) })
|
|
90
|
+
}
|
|
91
|
+
return nodes
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function pad2(n: number): string {
|
|
95
|
+
return String(n).padStart(2, '0')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function partsFromString(s: string | null | undefined): Parts {
|
|
99
|
+
if (!s) return EMPTY_PARTS
|
|
100
|
+
const m = /^(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?(?:\.\d+)?$/.exec(s)
|
|
101
|
+
if (!m) return EMPTY_PARTS
|
|
102
|
+
const hours = Number(m[1])
|
|
103
|
+
const minutes = Number(m[2])
|
|
104
|
+
const seconds = m[3] != null ? Number(m[3]) : null
|
|
105
|
+
if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59) return EMPTY_PARTS
|
|
106
|
+
if (seconds != null && (seconds < 0 || seconds > 59)) return EMPTY_PARTS
|
|
107
|
+
return { hours, minutes, seconds }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function partsToString(p: Parts, includeSeconds: boolean): string | null {
|
|
111
|
+
if (p.hours == null || p.minutes == null) return null
|
|
112
|
+
if (includeSeconds && p.seconds == null) return null
|
|
113
|
+
if (includeSeconds) return `${pad2(p.hours)}:${pad2(p.minutes)}:${pad2(p.seconds!)}`
|
|
114
|
+
return `${pad2(p.hours)}:${pad2(p.minutes)}`
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function to12(h24: number): { hour12: number; period: 'AM' | 'PM' } {
|
|
118
|
+
if (h24 === 0) return { hour12: 12, period: 'AM' }
|
|
119
|
+
if (h24 === 12) return { hour12: 12, period: 'PM' }
|
|
120
|
+
if (h24 > 12) return { hour12: h24 - 12, period: 'PM' }
|
|
121
|
+
return { hour12: h24, period: 'AM' }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function from12(hour12: number, period: 'AM' | 'PM'): number {
|
|
125
|
+
const h = hour12 % 12
|
|
126
|
+
return period === 'PM' ? h + 12 : h
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function periodOf(hours: number | null): 'AM' | 'PM' | null {
|
|
130
|
+
if (hours == null) return null
|
|
131
|
+
return hours >= 12 ? 'PM' : 'AM'
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function getSegmentRange(token: SegmentToken): { min: number; max: number; maxDigits: number } {
|
|
135
|
+
if (token === 'H' || token === 'HH') return { min: 0, max: 23, maxDigits: 2 }
|
|
136
|
+
if (token === 'h' || token === 'hh') return { min: 1, max: 12, maxDigits: 2 }
|
|
137
|
+
if (token === 'a') return { min: 0, max: 1, maxDigits: 1 }
|
|
138
|
+
return { min: 0, max: 59, maxDigits: 2 }
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function getDisplayHour12(hours: number | null): number | null {
|
|
142
|
+
if (hours == null) return null
|
|
143
|
+
return to12(hours).hour12
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function displayPart(part: number | null, token: SegmentToken, parts: Parts): string {
|
|
147
|
+
if (token === 'a') {
|
|
148
|
+
const period = periodOf(parts.hours)
|
|
149
|
+
return period ?? PLACEHOLDERS.a
|
|
150
|
+
}
|
|
151
|
+
if (token === 'h' || token === 'hh') {
|
|
152
|
+
const h12 = getDisplayHour12(parts.hours)
|
|
153
|
+
if (h12 == null) return PLACEHOLDERS[token]
|
|
154
|
+
return token === 'hh' ? pad2(h12) : String(h12)
|
|
155
|
+
}
|
|
156
|
+
if (part == null) return PLACEHOLDERS[token]
|
|
157
|
+
if (token === 'HH' || token === 'mm' || token === 'ss') return pad2(part)
|
|
158
|
+
return String(part)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function ariaText(token: SegmentToken, parts: Parts): string {
|
|
162
|
+
if (token === 'a') {
|
|
163
|
+
const period = periodOf(parts.hours)
|
|
164
|
+
return period ?? 'Empty'
|
|
165
|
+
}
|
|
166
|
+
if (token === 'h' || token === 'hh') {
|
|
167
|
+
const h12 = getDisplayHour12(parts.hours)
|
|
168
|
+
return h12 == null ? 'Empty' : String(h12)
|
|
169
|
+
}
|
|
170
|
+
const val =
|
|
171
|
+
token === 'H' || token === 'HH' ? parts.hours : token === 'm' || token === 'mm' ? parts.minutes : parts.seconds
|
|
172
|
+
return val == null ? 'Empty' : String(val)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function ariaLabel(type: SegmentType): string {
|
|
176
|
+
if (type === 'hour24' || type === 'hour12') return 'hour'
|
|
177
|
+
if (type === 'minute') return 'minute'
|
|
178
|
+
if (type === 'second') return 'second'
|
|
179
|
+
return 'period'
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function setHourFromInput(prev: Parts, token: SegmentToken, value: number): Parts {
|
|
183
|
+
if (token === 'h' || token === 'hh') {
|
|
184
|
+
const period = periodOf(prev.hours) ?? 'AM'
|
|
185
|
+
return { ...prev, hours: from12(value, period) }
|
|
186
|
+
}
|
|
187
|
+
return { ...prev, hours: value }
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function togglePeriod(prev: Parts, target?: 'AM' | 'PM'): Parts {
|
|
191
|
+
const current = periodOf(prev.hours)
|
|
192
|
+
if (prev.hours == null) {
|
|
193
|
+
const next: 'AM' | 'PM' = target ?? 'AM'
|
|
194
|
+
return { ...prev, hours: next === 'PM' ? 12 : 0 }
|
|
195
|
+
}
|
|
196
|
+
const next: 'AM' | 'PM' = target ?? (current === 'AM' ? 'PM' : 'AM')
|
|
197
|
+
if (next === current) return prev
|
|
198
|
+
return { ...prev, hours: next === 'PM' ? prev.hours + 12 : prev.hours - 12 }
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function TimeField({
|
|
202
|
+
className,
|
|
203
|
+
value,
|
|
204
|
+
defaultValue,
|
|
205
|
+
onValueChange,
|
|
206
|
+
format = 'HH:mm',
|
|
207
|
+
variant = 'outline',
|
|
208
|
+
size = 'md',
|
|
209
|
+
startSlot,
|
|
210
|
+
endSlot,
|
|
211
|
+
disabled: disabledProp,
|
|
212
|
+
readOnly,
|
|
213
|
+
required,
|
|
214
|
+
name: nameProp,
|
|
215
|
+
unstyled,
|
|
216
|
+
ref,
|
|
217
|
+
...rest
|
|
218
|
+
}: TimeFieldProps) {
|
|
219
|
+
const field = useFieldRootContext(true)
|
|
220
|
+
const disabled = disabledProp || field.disabled
|
|
221
|
+
const name = nameProp ?? field.name
|
|
222
|
+
const ariaInvalid = rest['aria-invalid']
|
|
223
|
+
const invalid = ariaInvalid === true || ariaInvalid === 'true' || field.invalid === true
|
|
224
|
+
|
|
225
|
+
const nodes = React.useMemo(() => parseFormat(format), [format])
|
|
226
|
+
const segmentCount = React.useMemo(() => nodes.reduce((n, x) => n + (x.kind === 'segment' ? 1 : 0), 0), [nodes])
|
|
227
|
+
const includeSeconds = React.useMemo(
|
|
228
|
+
() => nodes.some((n) => n.kind === 'segment' && (n.token === 's' || n.token === 'ss')),
|
|
229
|
+
[nodes],
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
const isControlled = value !== undefined
|
|
233
|
+
const [internalParts, setInternalParts] = React.useState<Parts>(() => partsFromString(value ?? defaultValue))
|
|
234
|
+
const [commitTick, setCommitTick] = React.useState(0)
|
|
235
|
+
|
|
236
|
+
const lastValueRef = React.useRef<string>(value ?? '')
|
|
237
|
+
const lastCommittedRef = React.useRef<string>(
|
|
238
|
+
partsToString(partsFromString(value ?? defaultValue), includeSeconds) ?? '',
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
React.useEffect(() => {
|
|
242
|
+
if (!isControlled) return
|
|
243
|
+
const v = value ?? ''
|
|
244
|
+
if (v !== lastValueRef.current) {
|
|
245
|
+
lastValueRef.current = v
|
|
246
|
+
lastCommittedRef.current = v
|
|
247
|
+
setInternalParts(partsFromString(value))
|
|
248
|
+
}
|
|
249
|
+
}, [isControlled, value])
|
|
250
|
+
|
|
251
|
+
const parts = internalParts
|
|
252
|
+
|
|
253
|
+
const partsRef = React.useRef(parts)
|
|
254
|
+
partsRef.current = parts
|
|
255
|
+
|
|
256
|
+
const onValueChangeRef = React.useRef(onValueChange)
|
|
257
|
+
onValueChangeRef.current = onValueChange
|
|
258
|
+
|
|
259
|
+
const includeSecondsRef = React.useRef(includeSeconds)
|
|
260
|
+
includeSecondsRef.current = includeSeconds
|
|
261
|
+
|
|
262
|
+
const commit = React.useCallback((updater: (prev: Parts) => Parts) => {
|
|
263
|
+
const next = updater(partsRef.current)
|
|
264
|
+
setInternalParts(next)
|
|
265
|
+
const serialized = partsToString(next, includeSecondsRef.current)
|
|
266
|
+
if (serialized) {
|
|
267
|
+
if (serialized !== lastCommittedRef.current) {
|
|
268
|
+
lastCommittedRef.current = serialized
|
|
269
|
+
onValueChangeRef.current?.(serialized)
|
|
270
|
+
setCommitTick((t) => t + 1)
|
|
271
|
+
}
|
|
272
|
+
return
|
|
273
|
+
}
|
|
274
|
+
const allEmpty = next.hours == null && next.minutes == null && next.seconds == null
|
|
275
|
+
if (allEmpty && lastCommittedRef.current !== '') {
|
|
276
|
+
lastCommittedRef.current = ''
|
|
277
|
+
onValueChangeRef.current?.(null)
|
|
278
|
+
setCommitTick((t) => t + 1)
|
|
279
|
+
}
|
|
280
|
+
}, [])
|
|
281
|
+
|
|
282
|
+
React.useEffect(() => {
|
|
283
|
+
if (commitTick === 0 || !isControlled) return
|
|
284
|
+
const v = value ?? ''
|
|
285
|
+
const serialized = partsToString(partsRef.current, includeSecondsRef.current) ?? ''
|
|
286
|
+
if (v !== serialized) {
|
|
287
|
+
lastValueRef.current = v
|
|
288
|
+
lastCommittedRef.current = v
|
|
289
|
+
setInternalParts(partsFromString(value))
|
|
290
|
+
}
|
|
291
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
292
|
+
}, [commitTick])
|
|
293
|
+
|
|
294
|
+
const segmentRefs = React.useRef<Array<HTMLSpanElement | null>>([])
|
|
295
|
+
const typingCountRef = React.useRef<Map<number, number>>(new Map())
|
|
296
|
+
|
|
297
|
+
const setSegmentRef = React.useMemo(() => {
|
|
298
|
+
const cache = new Map<number, (el: HTMLSpanElement | null) => void>()
|
|
299
|
+
return (index: number) => {
|
|
300
|
+
let cb = cache.get(index)
|
|
301
|
+
if (!cb) {
|
|
302
|
+
cb = (el) => {
|
|
303
|
+
segmentRefs.current[index] = el
|
|
304
|
+
}
|
|
305
|
+
cache.set(index, cb)
|
|
306
|
+
}
|
|
307
|
+
return cb
|
|
308
|
+
}
|
|
309
|
+
}, [])
|
|
310
|
+
|
|
311
|
+
const focusSegment = React.useCallback((idx: number) => {
|
|
312
|
+
segmentRefs.current[idx]?.focus()
|
|
313
|
+
}, [])
|
|
314
|
+
|
|
315
|
+
const onRootMouseDown = React.useCallback(
|
|
316
|
+
(e: React.MouseEvent<HTMLDivElement>) => {
|
|
317
|
+
if (disabled) return
|
|
318
|
+
const target = e.target as HTMLElement
|
|
319
|
+
if (target.closest('[data-slot="time-field-segment"]')) return
|
|
320
|
+
if (target.closest('button, a, input, select, textarea, label, [role="button"]')) return
|
|
321
|
+
e.preventDefault()
|
|
322
|
+
const p = partsRef.current
|
|
323
|
+
const isEmpty = (type: SegmentType) =>
|
|
324
|
+
type === 'minute' ? p.minutes == null : type === 'second' ? p.seconds == null : p.hours == null
|
|
325
|
+
const firstEmpty = nodes.find((n): n is SegmentNode => n.kind === 'segment' && isEmpty(n.type))
|
|
326
|
+
focusSegment(firstEmpty ? firstEmpty.index : 0)
|
|
327
|
+
},
|
|
328
|
+
[disabled, focusSegment, nodes],
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
const processCharInput = React.useCallback(
|
|
332
|
+
(seg: SegmentNode, ch: string) => {
|
|
333
|
+
if (disabled || readOnly) return
|
|
334
|
+
const p = partsRef.current
|
|
335
|
+
|
|
336
|
+
if (seg.token === 'a') {
|
|
337
|
+
if (/[aApP]/.test(ch)) {
|
|
338
|
+
typingCountRef.current.delete(seg.index)
|
|
339
|
+
const target: 'AM' | 'PM' = ch.toLowerCase() === 'a' ? 'AM' : 'PM'
|
|
340
|
+
commit((prev) => togglePeriod(prev, target))
|
|
341
|
+
return
|
|
342
|
+
}
|
|
343
|
+
if (ch === ':' || ch === '/' || ch === '-' || ch === '.' || ch === ',' || ch === ' ') {
|
|
344
|
+
if (seg.index < segmentCount - 1) focusSegment(seg.index + 1)
|
|
345
|
+
}
|
|
346
|
+
return
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (ch === ':' || ch === '/' || ch === '-' || ch === '.' || ch === ',' || ch === ' ') {
|
|
350
|
+
typingCountRef.current.delete(seg.index)
|
|
351
|
+
if (seg.index < segmentCount - 1) focusSegment(seg.index + 1)
|
|
352
|
+
return
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (ch < '0' || ch > '9') return
|
|
356
|
+
|
|
357
|
+
const range = getSegmentRange(seg.token)
|
|
358
|
+
const digit = Number(ch)
|
|
359
|
+
const count = typingCountRef.current.get(seg.index) ?? 0
|
|
360
|
+
const base =
|
|
361
|
+
seg.token === 'h' || seg.token === 'hh'
|
|
362
|
+
? getDisplayHour12(p.hours)
|
|
363
|
+
: seg.token === 'H' || seg.token === 'HH'
|
|
364
|
+
? p.hours
|
|
365
|
+
: seg.token === 'm' || seg.token === 'mm'
|
|
366
|
+
? p.minutes
|
|
367
|
+
: p.seconds
|
|
368
|
+
let displayVal: number
|
|
369
|
+
if (count === 0 || base == null) {
|
|
370
|
+
displayVal = digit
|
|
371
|
+
} else {
|
|
372
|
+
const tentative = base * 10 + digit
|
|
373
|
+
displayVal = tentative > range.max ? digit : tentative
|
|
374
|
+
}
|
|
375
|
+
if (displayVal < range.min) displayVal = range.min
|
|
376
|
+
typingCountRef.current.set(seg.index, count + 1)
|
|
377
|
+
|
|
378
|
+
commit((prev) => {
|
|
379
|
+
if (seg.type === 'hour24' || seg.type === 'hour12') return setHourFromInput(prev, seg.token, displayVal)
|
|
380
|
+
if (seg.type === 'minute') return { ...prev, minutes: displayVal }
|
|
381
|
+
return { ...prev, seconds: displayVal }
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
const reachedMaxDigits = (typingCountRef.current.get(seg.index) ?? 0) >= range.maxDigits
|
|
385
|
+
const cantFitAnother = displayVal * 10 > range.max
|
|
386
|
+
if (reachedMaxDigits || cantFitAnother) {
|
|
387
|
+
typingCountRef.current.delete(seg.index)
|
|
388
|
+
if (seg.index < segmentCount - 1) focusSegment(seg.index + 1)
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
[commit, disabled, focusSegment, readOnly, segmentCount],
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
const onSegmentKeyDown = React.useCallback(
|
|
395
|
+
(e: React.KeyboardEvent<HTMLSpanElement>, seg: SegmentNode) => {
|
|
396
|
+
if (disabled) return
|
|
397
|
+
const p = partsRef.current
|
|
398
|
+
|
|
399
|
+
if (e.key === 'Tab') return
|
|
400
|
+
|
|
401
|
+
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
|
|
402
|
+
e.preventDefault()
|
|
403
|
+
const goNext = e.key === 'ArrowRight'
|
|
404
|
+
typingCountRef.current.delete(seg.index)
|
|
405
|
+
const target = goNext ? seg.index + 1 : seg.index - 1
|
|
406
|
+
if (target >= 0 && target < segmentCount) focusSegment(target)
|
|
407
|
+
return
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (e.key === 'Home') {
|
|
411
|
+
e.preventDefault()
|
|
412
|
+
typingCountRef.current.delete(seg.index)
|
|
413
|
+
focusSegment(0)
|
|
414
|
+
return
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (e.key === 'End') {
|
|
418
|
+
e.preventDefault()
|
|
419
|
+
typingCountRef.current.delete(seg.index)
|
|
420
|
+
focusSegment(segmentCount - 1)
|
|
421
|
+
return
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (readOnly) return
|
|
425
|
+
|
|
426
|
+
if (seg.token === 'a') {
|
|
427
|
+
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
|
428
|
+
e.preventDefault()
|
|
429
|
+
typingCountRef.current.delete(seg.index)
|
|
430
|
+
commit((prev) => togglePeriod(prev))
|
|
431
|
+
return
|
|
432
|
+
}
|
|
433
|
+
if (e.key === 'Backspace' || e.key === 'Delete') {
|
|
434
|
+
e.preventDefault()
|
|
435
|
+
typingCountRef.current.delete(seg.index)
|
|
436
|
+
if (p.hours == null && e.key === 'Backspace' && seg.index > 0) {
|
|
437
|
+
focusSegment(seg.index - 1)
|
|
438
|
+
} else {
|
|
439
|
+
commit((prev) => ({ ...prev, hours: null }))
|
|
440
|
+
}
|
|
441
|
+
return
|
|
442
|
+
}
|
|
443
|
+
if (e.key.length === 1) {
|
|
444
|
+
e.preventDefault()
|
|
445
|
+
processCharInput(seg, e.key)
|
|
446
|
+
}
|
|
447
|
+
return
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const partVal =
|
|
451
|
+
seg.token === 'h' || seg.token === 'hh'
|
|
452
|
+
? getDisplayHour12(p.hours)
|
|
453
|
+
: seg.token === 'H' || seg.token === 'HH'
|
|
454
|
+
? p.hours
|
|
455
|
+
: seg.token === 'm' || seg.token === 'mm'
|
|
456
|
+
? p.minutes
|
|
457
|
+
: p.seconds
|
|
458
|
+
|
|
459
|
+
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
|
460
|
+
e.preventDefault()
|
|
461
|
+
typingCountRef.current.delete(seg.index)
|
|
462
|
+
const range = getSegmentRange(seg.token)
|
|
463
|
+
const stepUp = e.key === 'ArrowUp'
|
|
464
|
+
let next: number
|
|
465
|
+
if (partVal == null) {
|
|
466
|
+
next = stepUp ? range.min : range.max
|
|
467
|
+
} else {
|
|
468
|
+
let nb = stepUp ? partVal + 1 : partVal - 1
|
|
469
|
+
if (nb > range.max) nb = range.min
|
|
470
|
+
if (nb < range.min) nb = range.max
|
|
471
|
+
next = nb
|
|
472
|
+
}
|
|
473
|
+
commit((prev) => {
|
|
474
|
+
if (seg.type === 'hour24' || seg.type === 'hour12') return setHourFromInput(prev, seg.token, next)
|
|
475
|
+
if (seg.type === 'minute') return { ...prev, minutes: next }
|
|
476
|
+
return { ...prev, seconds: next }
|
|
477
|
+
})
|
|
478
|
+
return
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
if (e.key === 'Backspace' || e.key === 'Delete') {
|
|
482
|
+
e.preventDefault()
|
|
483
|
+
typingCountRef.current.delete(seg.index)
|
|
484
|
+
if (partVal == null && e.key === 'Backspace' && seg.index > 0) {
|
|
485
|
+
focusSegment(seg.index - 1)
|
|
486
|
+
} else {
|
|
487
|
+
commit((prev) => {
|
|
488
|
+
if (seg.type === 'hour24' || seg.type === 'hour12') return { ...prev, hours: null }
|
|
489
|
+
if (seg.type === 'minute') return { ...prev, minutes: null }
|
|
490
|
+
return { ...prev, seconds: null }
|
|
491
|
+
})
|
|
492
|
+
}
|
|
493
|
+
return
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
if (e.key.length === 1) {
|
|
497
|
+
e.preventDefault()
|
|
498
|
+
processCharInput(seg, e.key)
|
|
499
|
+
}
|
|
500
|
+
},
|
|
501
|
+
[commit, disabled, focusSegment, processCharInput, readOnly, segmentCount],
|
|
502
|
+
)
|
|
503
|
+
|
|
504
|
+
const onSegmentBeforeInput = React.useCallback(
|
|
505
|
+
(e: React.FormEvent<HTMLSpanElement>, seg: SegmentNode) => {
|
|
506
|
+
e.preventDefault()
|
|
507
|
+
const data = (e.nativeEvent as InputEvent).data
|
|
508
|
+
if (!data) return
|
|
509
|
+
for (const ch of data) processCharInput(seg, ch)
|
|
510
|
+
},
|
|
511
|
+
[processCharInput],
|
|
512
|
+
)
|
|
513
|
+
|
|
514
|
+
const onSegmentFocus = React.useCallback((seg: SegmentNode) => {
|
|
515
|
+
typingCountRef.current.delete(seg.index)
|
|
516
|
+
}, [])
|
|
517
|
+
|
|
518
|
+
const onSegmentBlur = React.useCallback((seg: SegmentNode) => {
|
|
519
|
+
typingCountRef.current.delete(seg.index)
|
|
520
|
+
}, [])
|
|
521
|
+
|
|
522
|
+
const hiddenValue = partsToString(parts, includeSeconds) ?? ''
|
|
523
|
+
|
|
524
|
+
return (
|
|
525
|
+
<div
|
|
526
|
+
data-slot="time-field"
|
|
527
|
+
data-disabled={disabled || undefined}
|
|
528
|
+
data-invalid={invalid || undefined}
|
|
529
|
+
aria-invalid={invalid || undefined}
|
|
530
|
+
aria-disabled={disabled || undefined}
|
|
531
|
+
role="group"
|
|
532
|
+
ref={ref}
|
|
533
|
+
className={cn(
|
|
534
|
+
unstyled
|
|
535
|
+
? 'inline-flex min-w-0 items-center select-none data-disabled:pointer-events-none data-disabled:cursor-not-allowed'
|
|
536
|
+
: cn(
|
|
537
|
+
inputVariants({ variant, size, state: 'within' }),
|
|
538
|
+
'select-none',
|
|
539
|
+
'data-disabled:border-border-strong! data-disabled:bg-background-subtle! data-disabled:opacity-disabled data-disabled:pointer-events-none data-disabled:cursor-not-allowed data-disabled:border-dashed',
|
|
540
|
+
),
|
|
541
|
+
className,
|
|
542
|
+
)}
|
|
543
|
+
{...rest}
|
|
544
|
+
onMouseDown={(e) => {
|
|
545
|
+
rest.onMouseDown?.(e)
|
|
546
|
+
if (!e.defaultPrevented) onRootMouseDown(e)
|
|
547
|
+
}}
|
|
548
|
+
>
|
|
549
|
+
{startSlot ? (
|
|
550
|
+
<div data-slot="time-field-start" className="-ms-1 shrink-0">
|
|
551
|
+
{startSlot}
|
|
552
|
+
</div>
|
|
553
|
+
) : null}
|
|
554
|
+
<div data-slot="time-field-segments" dir="ltr" className="text-foreground flex min-w-0 flex-1 items-center">
|
|
555
|
+
{nodes.map((node, i) => {
|
|
556
|
+
if (node.kind === 'literal') {
|
|
557
|
+
return (
|
|
558
|
+
<span key={`l-${i}`} aria-hidden="true" className="text-foreground-subtle whitespace-pre">
|
|
559
|
+
{node.text}
|
|
560
|
+
</span>
|
|
561
|
+
)
|
|
562
|
+
}
|
|
563
|
+
const isPeriod = node.token === 'a'
|
|
564
|
+
const range = getSegmentRange(node.token)
|
|
565
|
+
const partVal =
|
|
566
|
+
node.token === 'a'
|
|
567
|
+
? null
|
|
568
|
+
: node.token === 'h' || node.token === 'hh'
|
|
569
|
+
? getDisplayHour12(parts.hours)
|
|
570
|
+
: node.token === 'H' || node.token === 'HH'
|
|
571
|
+
? parts.hours
|
|
572
|
+
: node.token === 'm' || node.token === 'mm'
|
|
573
|
+
? parts.minutes
|
|
574
|
+
: parts.seconds
|
|
575
|
+
const isPlaceholder = isPeriod ? parts.hours == null : partVal == null
|
|
576
|
+
const editable = !disabled && !readOnly
|
|
577
|
+
const periodValue = isPeriod ? periodOf(parts.hours) : null
|
|
578
|
+
const periodAriaNow = periodValue === 'AM' ? 0 : periodValue === 'PM' ? 1 : undefined
|
|
579
|
+
return (
|
|
580
|
+
<span
|
|
581
|
+
key={`s-${node.index}`}
|
|
582
|
+
ref={setSegmentRef(node.index)}
|
|
583
|
+
role="spinbutton"
|
|
584
|
+
tabIndex={disabled ? -1 : 0}
|
|
585
|
+
contentEditable={editable}
|
|
586
|
+
suppressContentEditableWarning
|
|
587
|
+
inputMode={isPeriod ? 'text' : 'numeric'}
|
|
588
|
+
enterKeyHint="next"
|
|
589
|
+
autoCorrect="off"
|
|
590
|
+
spellCheck={false}
|
|
591
|
+
aria-label={ariaLabel(node.type)}
|
|
592
|
+
aria-readonly={readOnly || undefined}
|
|
593
|
+
aria-valuemin={isPeriod ? 0 : range.min}
|
|
594
|
+
aria-valuemax={isPeriod ? 1 : range.max}
|
|
595
|
+
aria-valuenow={isPeriod ? periodAriaNow : (partVal ?? undefined)}
|
|
596
|
+
aria-valuetext={ariaText(node.token, parts)}
|
|
597
|
+
data-slot="time-field-segment"
|
|
598
|
+
data-placeholder={isPlaceholder || undefined}
|
|
599
|
+
onBeforeInput={(e) => onSegmentBeforeInput(e, node)}
|
|
600
|
+
onKeyDown={(e) => onSegmentKeyDown(e, node)}
|
|
601
|
+
onFocus={() => onSegmentFocus(node)}
|
|
602
|
+
onBlur={() => onSegmentBlur(node)}
|
|
603
|
+
className={cn(
|
|
604
|
+
'rounded-3xs inline-block px-0.5 caret-transparent transition-colors duration-200 outline-none motion-reduce:transition-none',
|
|
605
|
+
'focus:bg-(--selection-color)',
|
|
606
|
+
'data-placeholder:text-foreground-subtle',
|
|
607
|
+
)}
|
|
608
|
+
>
|
|
609
|
+
{displayPart(partVal, node.token, parts)}
|
|
610
|
+
</span>
|
|
611
|
+
)
|
|
612
|
+
})}
|
|
613
|
+
</div>
|
|
614
|
+
{endSlot ? (
|
|
615
|
+
<div data-slot="time-field-end" className="-me-1 shrink-0">
|
|
616
|
+
{endSlot}
|
|
617
|
+
</div>
|
|
618
|
+
) : null}
|
|
619
|
+
{name ? <input type="hidden" name={name} value={hiddenValue} required={required} disabled={disabled} /> : null}
|
|
620
|
+
</div>
|
|
621
|
+
)
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export { TimeField }
|
|
625
|
+
export type { TimeFieldProps }
|