@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,1003 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import useEmblaCarousel from 'embla-carousel-react'
|
|
5
|
+
import { mergeProps } from '@base-ui/react/merge-props'
|
|
6
|
+
import { useRender } from '@base-ui/react/use-render'
|
|
7
|
+
import Accessibility, { type AccessibilityOptionsType } from 'embla-carousel-accessibility'
|
|
8
|
+
import Autoplay, { type AutoplayOptionsType } from 'embla-carousel-autoplay'
|
|
9
|
+
import AutoScroll, { type AutoScrollOptionsType } from 'embla-carousel-auto-scroll'
|
|
10
|
+
import AutoHeight, { type AutoHeightOptionsType } from 'embla-carousel-auto-height'
|
|
11
|
+
import ClassNames, { type ClassNamesOptionsType } from 'embla-carousel-class-names'
|
|
12
|
+
import Fade, { type FadeOptionsType } from 'embla-carousel-fade'
|
|
13
|
+
import { WheelGesturesPlugin, type WheelGesturesPluginOptions } from 'embla-carousel-wheel-gestures'
|
|
14
|
+
import type { EmblaCarouselType, EmblaOptionsType, EmblaPluginType } from 'embla-carousel'
|
|
15
|
+
import { cn } from '../../utils'
|
|
16
|
+
import { useDirection } from '../../hooks/use-direction'
|
|
17
|
+
import { useReducedMotion } from '../../hooks/use-reduced-motion'
|
|
18
|
+
|
|
19
|
+
type CarouselOrientation = 'horizontal' | 'vertical'
|
|
20
|
+
|
|
21
|
+
type CarouselApi = EmblaCarouselType
|
|
22
|
+
type CarouselOptions = EmblaOptionsType
|
|
23
|
+
type CarouselPlugin = EmblaPluginType
|
|
24
|
+
|
|
25
|
+
type CarouselAutoplayOptions = AutoplayOptionsType & { resumeAfter?: number }
|
|
26
|
+
type CarouselAutoScrollOptions = AutoScrollOptionsType & { resumeAfter?: number }
|
|
27
|
+
type CarouselAutoHeightOptions = AutoHeightOptionsType
|
|
28
|
+
type CarouselFadeOptions = FadeOptionsType
|
|
29
|
+
type CarouselClassNamesOptions = ClassNamesOptionsType
|
|
30
|
+
type CarouselAccessibilityOptions = AccessibilityOptionsType
|
|
31
|
+
type CarouselWheelGesturesOptions = WheelGesturesPluginOptions
|
|
32
|
+
|
|
33
|
+
interface CarouselAutoplayState {
|
|
34
|
+
delay: number
|
|
35
|
+
cycleId: number
|
|
36
|
+
isPlaying: boolean
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface CarouselContextValue {
|
|
40
|
+
api: CarouselApi | undefined
|
|
41
|
+
viewportRef: (node: HTMLDivElement | null) => void
|
|
42
|
+
orientation: CarouselOrientation
|
|
43
|
+
direction: 'ltr' | 'rtl'
|
|
44
|
+
light: boolean
|
|
45
|
+
autoHeight: boolean
|
|
46
|
+
loop: boolean
|
|
47
|
+
reducedMotion: boolean
|
|
48
|
+
selectedIndex: number
|
|
49
|
+
scrollSnaps: number[]
|
|
50
|
+
canScrollPrev: boolean
|
|
51
|
+
canScrollNext: boolean
|
|
52
|
+
subscribeScrollProgress: (onChange: () => void) => () => void
|
|
53
|
+
getScrollProgress: () => number
|
|
54
|
+
autoplay: CarouselAutoplayState | null
|
|
55
|
+
scrollPrev: () => void
|
|
56
|
+
scrollNext: () => void
|
|
57
|
+
scrollTo: (index: number) => void
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const CarouselContext = React.createContext<CarouselContextValue | null>(null)
|
|
61
|
+
|
|
62
|
+
function useCarousel(): CarouselContextValue {
|
|
63
|
+
const ctx = React.useContext(CarouselContext)
|
|
64
|
+
if (!ctx) {
|
|
65
|
+
throw new Error('Carousel sub-components must be rendered inside <Carousel>')
|
|
66
|
+
}
|
|
67
|
+
return ctx
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface CarouselProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'onSelect' | 'onScroll' | 'children'> {
|
|
71
|
+
orientation?: CarouselOrientation
|
|
72
|
+
loop?: boolean
|
|
73
|
+
align?: 'start' | 'center' | 'end'
|
|
74
|
+
slidesToScroll?: number | 'auto'
|
|
75
|
+
containScroll?: false | 'trimSnaps' | 'keepSnaps'
|
|
76
|
+
dragFree?: boolean
|
|
77
|
+
startSnap?: number
|
|
78
|
+
active?: boolean
|
|
79
|
+
draggable?: boolean
|
|
80
|
+
duration?: number
|
|
81
|
+
options?: CarouselOptions
|
|
82
|
+
autoplay?: boolean | CarouselAutoplayOptions
|
|
83
|
+
autoScroll?: boolean | CarouselAutoScrollOptions
|
|
84
|
+
autoHeight?: boolean | CarouselAutoHeightOptions
|
|
85
|
+
fade?: boolean | CarouselFadeOptions
|
|
86
|
+
classNames?: boolean | CarouselClassNamesOptions
|
|
87
|
+
accessibility?: boolean | CarouselAccessibilityOptions
|
|
88
|
+
wheelGestures?: boolean | CarouselWheelGesturesOptions
|
|
89
|
+
plugins?: CarouselPlugin[]
|
|
90
|
+
setApi?: (api: CarouselApi) => void
|
|
91
|
+
onReInit?: (api: CarouselApi) => void
|
|
92
|
+
onSelect?: (api: CarouselApi) => void
|
|
93
|
+
onScroll?: (api: CarouselApi) => void
|
|
94
|
+
light?: boolean
|
|
95
|
+
children: React.ReactNode
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function Carousel({
|
|
99
|
+
orientation = 'horizontal',
|
|
100
|
+
loop = false,
|
|
101
|
+
align = 'start',
|
|
102
|
+
slidesToScroll = 1,
|
|
103
|
+
containScroll = 'trimSnaps',
|
|
104
|
+
dragFree,
|
|
105
|
+
startSnap,
|
|
106
|
+
active = true,
|
|
107
|
+
draggable,
|
|
108
|
+
duration,
|
|
109
|
+
options,
|
|
110
|
+
autoplay,
|
|
111
|
+
autoScroll,
|
|
112
|
+
autoHeight,
|
|
113
|
+
fade,
|
|
114
|
+
classNames,
|
|
115
|
+
accessibility = true,
|
|
116
|
+
wheelGestures = false,
|
|
117
|
+
plugins: userPlugins,
|
|
118
|
+
setApi,
|
|
119
|
+
onReInit,
|
|
120
|
+
onSelect,
|
|
121
|
+
onScroll,
|
|
122
|
+
light = false,
|
|
123
|
+
className,
|
|
124
|
+
children,
|
|
125
|
+
...rest
|
|
126
|
+
}: CarouselProps) {
|
|
127
|
+
const direction = useDirection()
|
|
128
|
+
|
|
129
|
+
const reducedMotion = useReducedMotion()
|
|
130
|
+
|
|
131
|
+
const autoplayEnabled = !!autoplay
|
|
132
|
+
const autoScrollEnabled = !!autoScroll
|
|
133
|
+
|
|
134
|
+
const warnedMutualExclusive = React.useRef(false)
|
|
135
|
+
React.useEffect(() => {
|
|
136
|
+
if (
|
|
137
|
+
process.env.NODE_ENV !== 'production' &&
|
|
138
|
+
autoplayEnabled &&
|
|
139
|
+
autoScrollEnabled &&
|
|
140
|
+
!warnedMutualExclusive.current
|
|
141
|
+
) {
|
|
142
|
+
warnedMutualExclusive.current = true
|
|
143
|
+
// eslint-disable-next-line no-console
|
|
144
|
+
console.warn('[Carousel] `autoplay` and `autoScroll` are mutually exclusive — preferring `autoplay`.')
|
|
145
|
+
}
|
|
146
|
+
}, [autoplayEnabled, autoScrollEnabled])
|
|
147
|
+
|
|
148
|
+
const resumeAfterMs =
|
|
149
|
+
(typeof autoplay === 'object' && typeof autoplay.resumeAfter === 'number' && autoplay.resumeAfter) ||
|
|
150
|
+
(typeof autoScroll === 'object' && typeof autoScroll.resumeAfter === 'number' && autoScroll.resumeAfter) ||
|
|
151
|
+
0
|
|
152
|
+
|
|
153
|
+
const plugins = React.useMemo<CarouselPlugin[]>(() => {
|
|
154
|
+
const list: CarouselPlugin[] = []
|
|
155
|
+
if (accessibility !== false) {
|
|
156
|
+
list.push(Accessibility(typeof accessibility === 'object' ? accessibility : undefined))
|
|
157
|
+
}
|
|
158
|
+
if (wheelGestures !== false) {
|
|
159
|
+
list.push(WheelGesturesPlugin(typeof wheelGestures === 'object' ? wheelGestures : undefined))
|
|
160
|
+
}
|
|
161
|
+
if (autoplay) {
|
|
162
|
+
const opts = typeof autoplay === 'object' ? autoplay : undefined
|
|
163
|
+
const { resumeAfter, ...emblaOpts } = opts ?? {}
|
|
164
|
+
const autoResume = typeof resumeAfter === 'number' && resumeAfter > 0
|
|
165
|
+
list.push(Autoplay(autoResume ? { ...emblaOpts, defaultInteraction: false } : emblaOpts))
|
|
166
|
+
} else if (autoScroll && !reducedMotion) {
|
|
167
|
+
const opts = typeof autoScroll === 'object' ? autoScroll : undefined
|
|
168
|
+
const { resumeAfter, ...emblaOpts } = opts ?? {}
|
|
169
|
+
const autoResume = typeof resumeAfter === 'number' && resumeAfter > 0
|
|
170
|
+
list.push(AutoScroll(autoResume ? { ...emblaOpts, defaultInteraction: false } : emblaOpts))
|
|
171
|
+
}
|
|
172
|
+
if (autoHeight) {
|
|
173
|
+
list.push(AutoHeight(typeof autoHeight === 'object' ? autoHeight : undefined))
|
|
174
|
+
}
|
|
175
|
+
if (fade) {
|
|
176
|
+
list.push(Fade(typeof fade === 'object' ? fade : undefined))
|
|
177
|
+
}
|
|
178
|
+
if (classNames) {
|
|
179
|
+
list.push(ClassNames(typeof classNames === 'object' ? classNames : undefined))
|
|
180
|
+
}
|
|
181
|
+
if (userPlugins) list.push(...userPlugins)
|
|
182
|
+
return list
|
|
183
|
+
}, [accessibility, wheelGestures, autoplay, autoScroll, autoHeight, fade, classNames, userPlugins, reducedMotion])
|
|
184
|
+
|
|
185
|
+
const emblaOptions = React.useMemo<CarouselOptions>(() => {
|
|
186
|
+
const merged: CarouselOptions = {
|
|
187
|
+
axis: orientation === 'vertical' ? 'y' : 'x',
|
|
188
|
+
loop,
|
|
189
|
+
align,
|
|
190
|
+
slidesToScroll,
|
|
191
|
+
containScroll,
|
|
192
|
+
active,
|
|
193
|
+
}
|
|
194
|
+
if (dragFree !== undefined) merged.dragFree = dragFree
|
|
195
|
+
if (startSnap !== undefined) merged.startSnap = startSnap
|
|
196
|
+
if (duration !== undefined) merged.duration = duration
|
|
197
|
+
if (draggable !== undefined) merged.draggable = draggable
|
|
198
|
+
if (orientation === 'horizontal') merged.direction = direction
|
|
199
|
+
if (reducedMotion) merged.duration = 0
|
|
200
|
+
return { ...merged, ...options }
|
|
201
|
+
}, [
|
|
202
|
+
orientation,
|
|
203
|
+
direction,
|
|
204
|
+
loop,
|
|
205
|
+
align,
|
|
206
|
+
slidesToScroll,
|
|
207
|
+
containScroll,
|
|
208
|
+
dragFree,
|
|
209
|
+
startSnap,
|
|
210
|
+
active,
|
|
211
|
+
draggable,
|
|
212
|
+
duration,
|
|
213
|
+
options,
|
|
214
|
+
reducedMotion,
|
|
215
|
+
])
|
|
216
|
+
|
|
217
|
+
const [viewportRef, emblaApi] = useEmblaCarousel(emblaOptions, plugins)
|
|
218
|
+
|
|
219
|
+
const setApiRef = React.useRef(setApi)
|
|
220
|
+
const onReInitRef = React.useRef(onReInit)
|
|
221
|
+
const onSelectRef = React.useRef(onSelect)
|
|
222
|
+
const onScrollRef = React.useRef(onScroll)
|
|
223
|
+
React.useEffect(() => {
|
|
224
|
+
setApiRef.current = setApi
|
|
225
|
+
})
|
|
226
|
+
React.useEffect(() => {
|
|
227
|
+
onReInitRef.current = onReInit
|
|
228
|
+
})
|
|
229
|
+
React.useEffect(() => {
|
|
230
|
+
onSelectRef.current = onSelect
|
|
231
|
+
})
|
|
232
|
+
React.useEffect(() => {
|
|
233
|
+
onScrollRef.current = onScroll
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
React.useEffect(() => {
|
|
237
|
+
if (!emblaApi || !reducedMotion) return
|
|
238
|
+
const snapToTargetInstantly = () => {
|
|
239
|
+
emblaApi.internalEngine().scrollBody.useDuration(0)
|
|
240
|
+
}
|
|
241
|
+
emblaApi.on('pointerup', snapToTargetInstantly)
|
|
242
|
+
return () => {
|
|
243
|
+
emblaApi.off('pointerup', snapToTargetInstantly)
|
|
244
|
+
}
|
|
245
|
+
}, [emblaApi, reducedMotion])
|
|
246
|
+
|
|
247
|
+
const [state, setState] = React.useState({
|
|
248
|
+
selectedIndex: 0,
|
|
249
|
+
scrollSnaps: [] as number[],
|
|
250
|
+
canScrollPrev: false,
|
|
251
|
+
canScrollNext: false,
|
|
252
|
+
})
|
|
253
|
+
const [autoplayState, setAutoplayState] = React.useState<CarouselAutoplayState | null>(null)
|
|
254
|
+
|
|
255
|
+
const scrollProgressRef = React.useRef(0)
|
|
256
|
+
const scrollListenersRef = React.useRef<Set<() => void>>(new Set())
|
|
257
|
+
const subscribeScrollProgress = React.useCallback((onChange: () => void) => {
|
|
258
|
+
scrollListenersRef.current.add(onChange)
|
|
259
|
+
return () => {
|
|
260
|
+
scrollListenersRef.current.delete(onChange)
|
|
261
|
+
}
|
|
262
|
+
}, [])
|
|
263
|
+
const getScrollProgress = React.useCallback(() => scrollProgressRef.current, [])
|
|
264
|
+
|
|
265
|
+
React.useEffect(() => {
|
|
266
|
+
if (!emblaApi) return
|
|
267
|
+
|
|
268
|
+
const notifyScroll = () => {
|
|
269
|
+
scrollProgressRef.current = emblaApi.scrollProgress()
|
|
270
|
+
scrollListenersRef.current.forEach((cb) => cb())
|
|
271
|
+
}
|
|
272
|
+
const syncFull = () => {
|
|
273
|
+
notifyScroll()
|
|
274
|
+
setState({
|
|
275
|
+
selectedIndex: emblaApi.selectedSnap(),
|
|
276
|
+
scrollSnaps: emblaApi.snapList(),
|
|
277
|
+
canScrollPrev: emblaApi.canGoToPrev(),
|
|
278
|
+
canScrollNext: emblaApi.canGoToNext(),
|
|
279
|
+
})
|
|
280
|
+
}
|
|
281
|
+
const syncSelection = () => {
|
|
282
|
+
setState((s) => ({
|
|
283
|
+
...s,
|
|
284
|
+
selectedIndex: emblaApi.selectedSnap(),
|
|
285
|
+
canScrollPrev: emblaApi.canGoToPrev(),
|
|
286
|
+
canScrollNext: emblaApi.canGoToNext(),
|
|
287
|
+
}))
|
|
288
|
+
}
|
|
289
|
+
const syncScroll = () => {
|
|
290
|
+
notifyScroll()
|
|
291
|
+
}
|
|
292
|
+
const syncInView = () => {}
|
|
293
|
+
|
|
294
|
+
syncFull()
|
|
295
|
+
setApiRef.current?.(emblaApi)
|
|
296
|
+
onReInitRef.current?.(emblaApi)
|
|
297
|
+
|
|
298
|
+
const handleReInit = () => {
|
|
299
|
+
const autoplayWasPlaying = emblaApi.plugins().autoplay?.isPlaying()
|
|
300
|
+
const autoScrollWasPlaying = emblaApi.plugins().autoScroll?.isPlaying()
|
|
301
|
+
syncFull()
|
|
302
|
+
onReInitRef.current?.(emblaApi)
|
|
303
|
+
if (autoplayEnabled && autoplayWasPlaying) emblaApi.plugins().autoplay?.play()
|
|
304
|
+
else if (autoScrollEnabled && autoScrollWasPlaying) emblaApi.plugins().autoScroll?.play()
|
|
305
|
+
}
|
|
306
|
+
const handleSelect = () => {
|
|
307
|
+
syncSelection()
|
|
308
|
+
onSelectRef.current?.(emblaApi)
|
|
309
|
+
}
|
|
310
|
+
const handleScroll = () => {
|
|
311
|
+
syncScroll()
|
|
312
|
+
onScrollRef.current?.(emblaApi)
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
emblaApi.on('reinit', handleReInit)
|
|
316
|
+
emblaApi.on('select', handleSelect)
|
|
317
|
+
emblaApi.on('scroll', handleScroll)
|
|
318
|
+
emblaApi.on('slidesinview', syncInView)
|
|
319
|
+
emblaApi.on('slideschanged', syncFull)
|
|
320
|
+
|
|
321
|
+
const autoplayPlugin = emblaApi.plugins().autoplay
|
|
322
|
+
const autoScrollPlugin = emblaApi.plugins().autoScroll
|
|
323
|
+
|
|
324
|
+
const resumeAfter = resumeAfterMs
|
|
325
|
+
|
|
326
|
+
let resumeTimer: ReturnType<typeof setTimeout> | undefined
|
|
327
|
+
const clearResumeTimer = () => {
|
|
328
|
+
if (resumeTimer !== undefined) {
|
|
329
|
+
clearTimeout(resumeTimer)
|
|
330
|
+
resumeTimer = undefined
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const scheduleResume = (play: () => void) => {
|
|
334
|
+
if (resumeAfter <= 0) return
|
|
335
|
+
clearResumeTimer()
|
|
336
|
+
resumeTimer = setTimeout(() => {
|
|
337
|
+
resumeTimer = undefined
|
|
338
|
+
play()
|
|
339
|
+
}, resumeAfter)
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
let cleanupAutoplay: (() => void) | undefined
|
|
343
|
+
if (autoplayPlugin) {
|
|
344
|
+
const rawDelay = autoplayPlugin.options.delay
|
|
345
|
+
const initialDelay = typeof rawDelay === 'number' ? rawDelay : 4000
|
|
346
|
+
setAutoplayState({
|
|
347
|
+
delay: initialDelay,
|
|
348
|
+
cycleId: 0,
|
|
349
|
+
isPlaying: autoplayPlugin.isPlaying(),
|
|
350
|
+
})
|
|
351
|
+
const onPlay = () => {
|
|
352
|
+
clearResumeTimer()
|
|
353
|
+
setAutoplayState((s) => (s ? { ...s, isPlaying: true } : s))
|
|
354
|
+
}
|
|
355
|
+
const onStop = () => setAutoplayState((s) => (s ? { ...s, isPlaying: false } : s))
|
|
356
|
+
const onTimerSet = () => setAutoplayState((s) => (s ? { ...s, cycleId: s.cycleId + 1, isPlaying: true } : s))
|
|
357
|
+
const onTimerStopped = () => setAutoplayState((s) => (s ? { ...s, isPlaying: false } : s))
|
|
358
|
+
const resetOnSelect = () => autoplayPlugin.reset()
|
|
359
|
+
const onInteraction = (_api: CarouselApi, event: { detail: { interaction: string } }) => {
|
|
360
|
+
if (event.detail.interaction === 'pointerdown' || event.detail.interaction === 'slidefocus') {
|
|
361
|
+
autoplayPlugin.stop()
|
|
362
|
+
scheduleResume(() => emblaApi.plugins().autoplay?.play())
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
emblaApi.on('autoplay:play', onPlay)
|
|
366
|
+
emblaApi.on('autoplay:stop', onStop)
|
|
367
|
+
emblaApi.on('autoplay:timerset', onTimerSet)
|
|
368
|
+
emblaApi.on('autoplay:timerstopped', onTimerStopped)
|
|
369
|
+
emblaApi.on('select', resetOnSelect)
|
|
370
|
+
if (resumeAfter > 0) emblaApi.on('autoplay:interaction', onInteraction)
|
|
371
|
+
if (autoplayEnabled) autoplayPlugin.play()
|
|
372
|
+
cleanupAutoplay = () => {
|
|
373
|
+
emblaApi.off('autoplay:play', onPlay)
|
|
374
|
+
emblaApi.off('autoplay:stop', onStop)
|
|
375
|
+
emblaApi.off('autoplay:timerset', onTimerSet)
|
|
376
|
+
emblaApi.off('autoplay:timerstopped', onTimerStopped)
|
|
377
|
+
emblaApi.off('select', resetOnSelect)
|
|
378
|
+
if (resumeAfter > 0) emblaApi.off('autoplay:interaction', onInteraction)
|
|
379
|
+
}
|
|
380
|
+
} else {
|
|
381
|
+
setAutoplayState(null)
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
let cleanupAutoScroll: (() => void) | undefined
|
|
385
|
+
if (autoScrollPlugin && autoScrollEnabled && !autoplayEnabled) {
|
|
386
|
+
autoScrollPlugin.play()
|
|
387
|
+
const onInteraction = (_api: CarouselApi, event: { detail: { interaction: string } }) => {
|
|
388
|
+
if (event.detail.interaction === 'pointerdown' || event.detail.interaction === 'slidefocus') {
|
|
389
|
+
autoScrollPlugin.stop()
|
|
390
|
+
scheduleResume(() => emblaApi.plugins().autoScroll?.play())
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (resumeAfter > 0) {
|
|
394
|
+
emblaApi.on('autoscroll:interaction', onInteraction)
|
|
395
|
+
cleanupAutoScroll = () => emblaApi.off('autoscroll:interaction', onInteraction)
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return () => {
|
|
400
|
+
emblaApi.off('reinit', handleReInit)
|
|
401
|
+
emblaApi.off('select', handleSelect)
|
|
402
|
+
emblaApi.off('scroll', handleScroll)
|
|
403
|
+
emblaApi.off('slidesinview', syncInView)
|
|
404
|
+
emblaApi.off('slideschanged', syncFull)
|
|
405
|
+
cleanupAutoplay?.()
|
|
406
|
+
cleanupAutoScroll?.()
|
|
407
|
+
clearResumeTimer()
|
|
408
|
+
}
|
|
409
|
+
}, [emblaApi, autoplayEnabled, autoScrollEnabled, resumeAfterMs])
|
|
410
|
+
|
|
411
|
+
const scrollPrev = React.useCallback(() => emblaApi?.goToPrev(), [emblaApi])
|
|
412
|
+
const scrollNext = React.useCallback(() => emblaApi?.goToNext(), [emblaApi])
|
|
413
|
+
const scrollTo = React.useCallback((i: number) => emblaApi?.goTo(i), [emblaApi])
|
|
414
|
+
|
|
415
|
+
const isAutoHeight = !!autoHeight
|
|
416
|
+
const contextValue = React.useMemo<CarouselContextValue>(
|
|
417
|
+
() => ({
|
|
418
|
+
api: emblaApi,
|
|
419
|
+
viewportRef,
|
|
420
|
+
orientation,
|
|
421
|
+
direction,
|
|
422
|
+
light,
|
|
423
|
+
autoHeight: isAutoHeight,
|
|
424
|
+
loop,
|
|
425
|
+
reducedMotion,
|
|
426
|
+
selectedIndex: state.selectedIndex,
|
|
427
|
+
scrollSnaps: state.scrollSnaps,
|
|
428
|
+
canScrollPrev: state.canScrollPrev,
|
|
429
|
+
canScrollNext: state.canScrollNext,
|
|
430
|
+
subscribeScrollProgress,
|
|
431
|
+
getScrollProgress,
|
|
432
|
+
autoplay: autoplayState,
|
|
433
|
+
scrollPrev,
|
|
434
|
+
scrollNext,
|
|
435
|
+
scrollTo,
|
|
436
|
+
}),
|
|
437
|
+
[
|
|
438
|
+
emblaApi,
|
|
439
|
+
viewportRef,
|
|
440
|
+
orientation,
|
|
441
|
+
direction,
|
|
442
|
+
light,
|
|
443
|
+
isAutoHeight,
|
|
444
|
+
loop,
|
|
445
|
+
reducedMotion,
|
|
446
|
+
state,
|
|
447
|
+
subscribeScrollProgress,
|
|
448
|
+
getScrollProgress,
|
|
449
|
+
autoplayState,
|
|
450
|
+
scrollPrev,
|
|
451
|
+
scrollNext,
|
|
452
|
+
scrollTo,
|
|
453
|
+
],
|
|
454
|
+
)
|
|
455
|
+
|
|
456
|
+
return (
|
|
457
|
+
<CarouselContext.Provider value={contextValue}>
|
|
458
|
+
<div
|
|
459
|
+
data-slot="carousel"
|
|
460
|
+
data-orientation={orientation}
|
|
461
|
+
role="region"
|
|
462
|
+
aria-roledescription="carousel"
|
|
463
|
+
aria-label="Carousel"
|
|
464
|
+
className={cn('relative', className)}
|
|
465
|
+
{...rest}
|
|
466
|
+
>
|
|
467
|
+
{children}
|
|
468
|
+
</div>
|
|
469
|
+
</CarouselContext.Provider>
|
|
470
|
+
)
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
type CarouselContentProps = React.ComponentPropsWithoutRef<'div'>
|
|
474
|
+
|
|
475
|
+
function CarouselContent({ className, children, ...rest }: CarouselContentProps) {
|
|
476
|
+
const { viewportRef, orientation, autoHeight } = useCarousel()
|
|
477
|
+
return (
|
|
478
|
+
<div
|
|
479
|
+
ref={viewportRef}
|
|
480
|
+
data-slot="carousel-viewport"
|
|
481
|
+
data-orientation={orientation}
|
|
482
|
+
data-auto-height={autoHeight || undefined}
|
|
483
|
+
className={cn(
|
|
484
|
+
'overflow-hidden',
|
|
485
|
+
autoHeight && 'motion-safe:transition-[height] motion-safe:duration-300 motion-safe:ease-out',
|
|
486
|
+
)}
|
|
487
|
+
>
|
|
488
|
+
<div
|
|
489
|
+
data-slot="carousel-content"
|
|
490
|
+
data-orientation={orientation}
|
|
491
|
+
className={cn(
|
|
492
|
+
'flex',
|
|
493
|
+
orientation === 'horizontal'
|
|
494
|
+
? '-ms-4 touch-pan-y touch-pinch-zoom items-start'
|
|
495
|
+
: '-mt-4 h-full touch-pan-x touch-pinch-zoom flex-col',
|
|
496
|
+
className,
|
|
497
|
+
)}
|
|
498
|
+
{...rest}
|
|
499
|
+
>
|
|
500
|
+
{children}
|
|
501
|
+
</div>
|
|
502
|
+
</div>
|
|
503
|
+
)
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
type CarouselSlideProps = React.ComponentPropsWithoutRef<'div'>
|
|
507
|
+
|
|
508
|
+
function CarouselSlide({ className, ...rest }: CarouselSlideProps) {
|
|
509
|
+
const { orientation } = useCarousel()
|
|
510
|
+
return (
|
|
511
|
+
<div
|
|
512
|
+
data-slot="carousel-slide"
|
|
513
|
+
data-orientation={orientation}
|
|
514
|
+
role="group"
|
|
515
|
+
aria-roledescription="slide"
|
|
516
|
+
className={cn(
|
|
517
|
+
'min-h-0 min-w-0 shrink-0 grow-0 basis-full',
|
|
518
|
+
orientation === 'horizontal' ? 'ps-4' : 'pt-4',
|
|
519
|
+
className,
|
|
520
|
+
)}
|
|
521
|
+
{...rest}
|
|
522
|
+
/>
|
|
523
|
+
)
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
type CarouselButtonState = { disabled: boolean; direction: 'prev' | 'next' }
|
|
527
|
+
|
|
528
|
+
type CarouselNavPosition = 'inside' | 'outside' | 'outside-half' | 'none'
|
|
529
|
+
|
|
530
|
+
const PREV_POSITION_CLASSES: Record<CarouselNavPosition, string> = {
|
|
531
|
+
inside: cn(
|
|
532
|
+
'absolute z-10',
|
|
533
|
+
'data-[orientation=horizontal]:inset-s-4 data-[orientation=horizontal]:top-1/2 data-[orientation=horizontal]:-translate-y-1/2',
|
|
534
|
+
'data-[orientation=vertical]:inset-s-1/2 data-[orientation=vertical]:top-4 data-[orientation=vertical]:-translate-x-1/2',
|
|
535
|
+
),
|
|
536
|
+
outside: cn(
|
|
537
|
+
'absolute z-10',
|
|
538
|
+
'data-[orientation=horizontal]:-inset-s-14 data-[orientation=horizontal]:top-1/2 data-[orientation=horizontal]:-translate-y-1/2',
|
|
539
|
+
'data-[orientation=vertical]:inset-s-1/2 data-[orientation=vertical]:-top-14 data-[orientation=vertical]:-translate-x-1/2',
|
|
540
|
+
),
|
|
541
|
+
'outside-half': cn(
|
|
542
|
+
'absolute z-10',
|
|
543
|
+
'data-[orientation=horizontal]:inset-s-0 data-[orientation=horizontal]:top-1/2 data-[orientation=horizontal]:-translate-y-1/2',
|
|
544
|
+
'data-[orientation=horizontal]:ltr:-translate-x-1/2 data-[orientation=horizontal]:rtl:translate-x-1/2',
|
|
545
|
+
'data-[orientation=vertical]:inset-s-1/2 data-[orientation=vertical]:top-0 data-[orientation=vertical]:-translate-x-1/2 data-[orientation=vertical]:-translate-y-1/2',
|
|
546
|
+
),
|
|
547
|
+
none: '',
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const NEXT_POSITION_CLASSES: Record<CarouselNavPosition, string> = {
|
|
551
|
+
inside: cn(
|
|
552
|
+
'absolute z-10',
|
|
553
|
+
'data-[orientation=horizontal]:inset-e-4 data-[orientation=horizontal]:top-1/2 data-[orientation=horizontal]:-translate-y-1/2',
|
|
554
|
+
'data-[orientation=vertical]:inset-s-1/2 data-[orientation=vertical]:bottom-4 data-[orientation=vertical]:-translate-x-1/2',
|
|
555
|
+
),
|
|
556
|
+
outside: cn(
|
|
557
|
+
'absolute z-10',
|
|
558
|
+
'data-[orientation=horizontal]:-inset-e-14 data-[orientation=horizontal]:top-1/2 data-[orientation=horizontal]:-translate-y-1/2',
|
|
559
|
+
'data-[orientation=vertical]:inset-s-1/2 data-[orientation=vertical]:-bottom-14 data-[orientation=vertical]:-translate-x-1/2',
|
|
560
|
+
),
|
|
561
|
+
'outside-half': cn(
|
|
562
|
+
'absolute z-10',
|
|
563
|
+
'data-[orientation=horizontal]:inset-e-0 data-[orientation=horizontal]:top-1/2 data-[orientation=horizontal]:-translate-y-1/2',
|
|
564
|
+
'data-[orientation=horizontal]:ltr:translate-x-1/2 data-[orientation=horizontal]:rtl:-translate-x-1/2',
|
|
565
|
+
'data-[orientation=vertical]:inset-s-1/2 data-[orientation=vertical]:bottom-0 data-[orientation=vertical]:-translate-x-1/2 data-[orientation=vertical]:translate-y-1/2',
|
|
566
|
+
),
|
|
567
|
+
none: '',
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
interface CarouselPrevProps extends useRender.ComponentProps<'button', CarouselButtonState> {
|
|
571
|
+
position?: CarouselNavPosition
|
|
572
|
+
disabled?: boolean
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function CarouselPrev({ className, position = 'inside', disabled: disabledProp, render, ...props }: CarouselPrevProps) {
|
|
576
|
+
const { scrollPrev, canScrollPrev, orientation } = useCarousel()
|
|
577
|
+
const disabled = (disabledProp ?? false) || !canScrollPrev
|
|
578
|
+
const state: CarouselButtonState = { disabled, direction: 'prev' }
|
|
579
|
+
|
|
580
|
+
const trigger = useRender({
|
|
581
|
+
defaultTagName: 'button',
|
|
582
|
+
render,
|
|
583
|
+
state,
|
|
584
|
+
props: mergeProps<'button'>(
|
|
585
|
+
{
|
|
586
|
+
type: 'button',
|
|
587
|
+
'data-slot': 'carousel-prev',
|
|
588
|
+
'data-disabled': disabled || undefined,
|
|
589
|
+
'aria-label': 'Previous slide',
|
|
590
|
+
disabled,
|
|
591
|
+
onClick: scrollPrev,
|
|
592
|
+
suppressHydrationWarning: true,
|
|
593
|
+
} as unknown as React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
594
|
+
props,
|
|
595
|
+
),
|
|
596
|
+
})
|
|
597
|
+
|
|
598
|
+
return (
|
|
599
|
+
<div
|
|
600
|
+
data-slot="carousel-prev-positioner"
|
|
601
|
+
data-orientation={orientation}
|
|
602
|
+
className={cn(PREV_POSITION_CLASSES[position], className)}
|
|
603
|
+
suppressHydrationWarning
|
|
604
|
+
>
|
|
605
|
+
{trigger}
|
|
606
|
+
</div>
|
|
607
|
+
)
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
interface CarouselNextProps extends useRender.ComponentProps<'button', CarouselButtonState> {
|
|
611
|
+
position?: CarouselNavPosition
|
|
612
|
+
disabled?: boolean
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function CarouselNext({ className, position = 'inside', disabled: disabledProp, render, ...props }: CarouselNextProps) {
|
|
616
|
+
const { scrollNext, canScrollNext, orientation } = useCarousel()
|
|
617
|
+
const disabled = (disabledProp ?? false) || !canScrollNext
|
|
618
|
+
const state: CarouselButtonState = { disabled, direction: 'next' }
|
|
619
|
+
|
|
620
|
+
const trigger = useRender({
|
|
621
|
+
defaultTagName: 'button',
|
|
622
|
+
render,
|
|
623
|
+
state,
|
|
624
|
+
props: mergeProps<'button'>(
|
|
625
|
+
{
|
|
626
|
+
type: 'button',
|
|
627
|
+
'data-slot': 'carousel-next',
|
|
628
|
+
'data-disabled': disabled || undefined,
|
|
629
|
+
'aria-label': 'Next slide',
|
|
630
|
+
disabled,
|
|
631
|
+
onClick: scrollNext,
|
|
632
|
+
suppressHydrationWarning: true,
|
|
633
|
+
} as unknown as React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
634
|
+
props,
|
|
635
|
+
),
|
|
636
|
+
})
|
|
637
|
+
|
|
638
|
+
return (
|
|
639
|
+
<div
|
|
640
|
+
data-slot="carousel-next-positioner"
|
|
641
|
+
data-orientation={orientation}
|
|
642
|
+
className={cn(NEXT_POSITION_CLASSES[position], className)}
|
|
643
|
+
suppressHydrationWarning
|
|
644
|
+
>
|
|
645
|
+
{trigger}
|
|
646
|
+
</div>
|
|
647
|
+
)
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
interface CarouselPaginationProps extends React.ComponentPropsWithoutRef<'div'> {
|
|
651
|
+
orientation?: CarouselOrientation
|
|
652
|
+
light?: boolean
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
function CarouselPagination({
|
|
656
|
+
className,
|
|
657
|
+
orientation = 'horizontal',
|
|
658
|
+
light: lightProp,
|
|
659
|
+
...rest
|
|
660
|
+
}: CarouselPaginationProps) {
|
|
661
|
+
const { scrollSnaps, selectedIndex, scrollTo, autoplay, reducedMotion, light: ctxLight } = useCarousel()
|
|
662
|
+
const light = lightProp ?? ctxLight
|
|
663
|
+
|
|
664
|
+
if (scrollSnaps.length <= 1) return null
|
|
665
|
+
const isHorizontal = orientation === 'horizontal'
|
|
666
|
+
|
|
667
|
+
return (
|
|
668
|
+
<div
|
|
669
|
+
data-slot="carousel-pagination"
|
|
670
|
+
data-orientation={orientation}
|
|
671
|
+
role="group"
|
|
672
|
+
aria-label="Choose slide to display"
|
|
673
|
+
className={cn('flex gap-2 data-[orientation=vertical]:flex-col', className)}
|
|
674
|
+
{...rest}
|
|
675
|
+
>
|
|
676
|
+
{scrollSnaps.map((_, index) => {
|
|
677
|
+
const isActive = index === selectedIndex
|
|
678
|
+
const renderAutoplay = isActive && autoplay !== null && autoplay.isPlaying && !reducedMotion
|
|
679
|
+
return (
|
|
680
|
+
<button
|
|
681
|
+
key={index}
|
|
682
|
+
type="button"
|
|
683
|
+
aria-current={isActive ? 'true' : undefined}
|
|
684
|
+
aria-label={`Go to slide ${index + 1}`}
|
|
685
|
+
data-slot="carousel-pagination-bullet"
|
|
686
|
+
data-orientation={orientation}
|
|
687
|
+
data-active={isActive || undefined}
|
|
688
|
+
data-autoplay={renderAutoplay || undefined}
|
|
689
|
+
onClick={() => scrollTo(index)}
|
|
690
|
+
className={cn(
|
|
691
|
+
'cursor-pointer rounded-full outline-offset-1',
|
|
692
|
+
isHorizontal ? 'h-1.5' : 'w-1.5',
|
|
693
|
+
light ? 'outline-ring-light' : 'outline-ring',
|
|
694
|
+
'motion-safe:transition-[width,height,background-color] motion-safe:duration-300',
|
|
695
|
+
!isActive && (light ? 'bg-white/25' : 'bg-border-strong'),
|
|
696
|
+
!isActive && (isHorizontal ? 'w-1.5' : 'h-1.5'),
|
|
697
|
+
isActive && !renderAutoplay && (light ? 'bg-white' : 'bg-primary'),
|
|
698
|
+
isActive && !renderAutoplay && (isHorizontal ? 'w-5' : 'h-5'),
|
|
699
|
+
renderAutoplay && 'relative overflow-hidden',
|
|
700
|
+
renderAutoplay && (light ? 'bg-white/25' : 'bg-border-strong'),
|
|
701
|
+
renderAutoplay && (isHorizontal ? 'w-10' : 'h-10'),
|
|
702
|
+
)}
|
|
703
|
+
>
|
|
704
|
+
{renderAutoplay && autoplay ? (
|
|
705
|
+
<CarouselAutoplayIndicator
|
|
706
|
+
key={autoplay.cycleId}
|
|
707
|
+
delay={autoplay.delay}
|
|
708
|
+
isPlaying={autoplay.isPlaying}
|
|
709
|
+
light={light}
|
|
710
|
+
orientation={orientation}
|
|
711
|
+
/>
|
|
712
|
+
) : null}
|
|
713
|
+
</button>
|
|
714
|
+
)
|
|
715
|
+
})}
|
|
716
|
+
</div>
|
|
717
|
+
)
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
interface CarouselAutoplayIndicatorProps {
|
|
721
|
+
delay: number
|
|
722
|
+
isPlaying: boolean
|
|
723
|
+
light: boolean
|
|
724
|
+
orientation: CarouselOrientation
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function CarouselAutoplayIndicator({ delay, isPlaying, light, orientation }: CarouselAutoplayIndicatorProps) {
|
|
728
|
+
const [armed, setArmed] = React.useState(false)
|
|
729
|
+
|
|
730
|
+
React.useEffect(() => {
|
|
731
|
+
let raf2 = 0
|
|
732
|
+
const raf1 = requestAnimationFrame(() => {
|
|
733
|
+
raf2 = requestAnimationFrame(() => setArmed(true))
|
|
734
|
+
})
|
|
735
|
+
return () => {
|
|
736
|
+
cancelAnimationFrame(raf1)
|
|
737
|
+
cancelAnimationFrame(raf2)
|
|
738
|
+
}
|
|
739
|
+
}, [])
|
|
740
|
+
|
|
741
|
+
const isHorizontal = orientation === 'horizontal'
|
|
742
|
+
const fillValue = armed && isPlaying ? '100%' : '0%'
|
|
743
|
+
|
|
744
|
+
return (
|
|
745
|
+
<span
|
|
746
|
+
aria-hidden="true"
|
|
747
|
+
data-slot="carousel-pagination-indicator"
|
|
748
|
+
data-orientation={orientation}
|
|
749
|
+
data-playing={isPlaying || undefined}
|
|
750
|
+
className={cn(
|
|
751
|
+
'absolute rounded-full',
|
|
752
|
+
isHorizontal ? 'inset-y-0 inset-s-0' : 'inset-x-0 top-0',
|
|
753
|
+
isHorizontal ? 'motion-safe:transition-[width]' : 'motion-safe:transition-[height]',
|
|
754
|
+
'motion-safe:ease-linear',
|
|
755
|
+
light ? 'bg-white' : 'bg-primary',
|
|
756
|
+
)}
|
|
757
|
+
style={{
|
|
758
|
+
transitionDuration: `${delay}ms`,
|
|
759
|
+
width: isHorizontal ? fillValue : undefined,
|
|
760
|
+
height: isHorizontal ? undefined : fillValue,
|
|
761
|
+
}}
|
|
762
|
+
/>
|
|
763
|
+
)
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
interface CarouselProgressProps extends React.ComponentPropsWithoutRef<'div'> {
|
|
767
|
+
source?: 'auto' | 'autoplay' | 'scroll'
|
|
768
|
+
variant?: 'bar' | 'circular'
|
|
769
|
+
orientation?: CarouselOrientation
|
|
770
|
+
light?: boolean
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
const CAROUSEL_PROGRESS_CIRCULAR_VIEWBOX = 40
|
|
774
|
+
const CAROUSEL_PROGRESS_CIRCULAR_THICKNESS = 4
|
|
775
|
+
const CAROUSEL_PROGRESS_CIRCULAR_RADIUS =
|
|
776
|
+
(CAROUSEL_PROGRESS_CIRCULAR_VIEWBOX - CAROUSEL_PROGRESS_CIRCULAR_THICKNESS) / 2
|
|
777
|
+
const CAROUSEL_PROGRESS_CIRCULAR_CIRCUMFERENCE = 2 * Math.PI * CAROUSEL_PROGRESS_CIRCULAR_RADIUS
|
|
778
|
+
|
|
779
|
+
function CarouselProgress({
|
|
780
|
+
source = 'auto',
|
|
781
|
+
variant = 'bar',
|
|
782
|
+
orientation = 'horizontal',
|
|
783
|
+
light: lightProp,
|
|
784
|
+
className,
|
|
785
|
+
...rest
|
|
786
|
+
}: CarouselProgressProps) {
|
|
787
|
+
const { subscribeScrollProgress, getScrollProgress, autoplay, reducedMotion, light: ctxLight } = useCarousel()
|
|
788
|
+
const scrollProgress = React.useSyncExternalStore(subscribeScrollProgress, getScrollProgress, getScrollProgress)
|
|
789
|
+
const light = lightProp ?? ctxLight
|
|
790
|
+
const resolvedSource = source === 'auto' ? (autoplay && autoplay.isPlaying ? 'autoplay' : 'scroll') : source
|
|
791
|
+
const showAutoplay = resolvedSource === 'autoplay' && autoplay !== null && !reducedMotion
|
|
792
|
+
|
|
793
|
+
if (variant === 'circular') {
|
|
794
|
+
const center = CAROUSEL_PROGRESS_CIRCULAR_VIEWBOX / 2
|
|
795
|
+
const offset = CAROUSEL_PROGRESS_CIRCULAR_CIRCUMFERENCE * (1 - scrollProgress)
|
|
796
|
+
return (
|
|
797
|
+
<div
|
|
798
|
+
data-slot="carousel-progress"
|
|
799
|
+
data-variant="circular"
|
|
800
|
+
data-source={resolvedSource}
|
|
801
|
+
data-light={light || undefined}
|
|
802
|
+
className={cn('relative size-10', className)}
|
|
803
|
+
{...rest}
|
|
804
|
+
>
|
|
805
|
+
<svg
|
|
806
|
+
aria-hidden="true"
|
|
807
|
+
viewBox={`0 0 ${CAROUSEL_PROGRESS_CIRCULAR_VIEWBOX} ${CAROUSEL_PROGRESS_CIRCULAR_VIEWBOX}`}
|
|
808
|
+
className="size-full -rotate-90 overflow-visible"
|
|
809
|
+
>
|
|
810
|
+
<circle
|
|
811
|
+
data-slot="carousel-progress-track"
|
|
812
|
+
cx={center}
|
|
813
|
+
cy={center}
|
|
814
|
+
r={CAROUSEL_PROGRESS_CIRCULAR_RADIUS}
|
|
815
|
+
fill="none"
|
|
816
|
+
strokeWidth={CAROUSEL_PROGRESS_CIRCULAR_THICKNESS}
|
|
817
|
+
className={light ? 'stroke-white/25' : 'stroke-border-strong'}
|
|
818
|
+
/>
|
|
819
|
+
{showAutoplay && autoplay ? (
|
|
820
|
+
<CarouselAutoplayCircularIndicator
|
|
821
|
+
key={autoplay.cycleId}
|
|
822
|
+
delay={autoplay.delay}
|
|
823
|
+
isPlaying={autoplay.isPlaying}
|
|
824
|
+
light={light}
|
|
825
|
+
center={center}
|
|
826
|
+
radius={CAROUSEL_PROGRESS_CIRCULAR_RADIUS}
|
|
827
|
+
circumference={CAROUSEL_PROGRESS_CIRCULAR_CIRCUMFERENCE}
|
|
828
|
+
thickness={CAROUSEL_PROGRESS_CIRCULAR_THICKNESS}
|
|
829
|
+
/>
|
|
830
|
+
) : (
|
|
831
|
+
<circle
|
|
832
|
+
data-slot="carousel-progress-indicator"
|
|
833
|
+
cx={center}
|
|
834
|
+
cy={center}
|
|
835
|
+
r={CAROUSEL_PROGRESS_CIRCULAR_RADIUS}
|
|
836
|
+
fill="none"
|
|
837
|
+
strokeWidth={CAROUSEL_PROGRESS_CIRCULAR_THICKNESS}
|
|
838
|
+
strokeLinecap="round"
|
|
839
|
+
strokeDasharray={CAROUSEL_PROGRESS_CIRCULAR_CIRCUMFERENCE}
|
|
840
|
+
strokeDashoffset={offset}
|
|
841
|
+
className={light ? 'stroke-white' : 'stroke-primary'}
|
|
842
|
+
/>
|
|
843
|
+
)}
|
|
844
|
+
</svg>
|
|
845
|
+
</div>
|
|
846
|
+
)
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
const isHorizontal = orientation === 'horizontal'
|
|
850
|
+
return (
|
|
851
|
+
<div
|
|
852
|
+
data-slot="carousel-progress"
|
|
853
|
+
data-variant="bar"
|
|
854
|
+
data-orientation={orientation}
|
|
855
|
+
data-source={resolvedSource}
|
|
856
|
+
data-light={light || undefined}
|
|
857
|
+
className={cn(
|
|
858
|
+
'relative overflow-hidden rounded-full',
|
|
859
|
+
isHorizontal ? 'h-1.5 w-full' : 'h-full w-1.5',
|
|
860
|
+
light ? 'bg-white/25' : 'bg-border-strong',
|
|
861
|
+
className,
|
|
862
|
+
)}
|
|
863
|
+
{...rest}
|
|
864
|
+
>
|
|
865
|
+
{showAutoplay && autoplay ? (
|
|
866
|
+
<CarouselAutoplayIndicator
|
|
867
|
+
key={autoplay.cycleId}
|
|
868
|
+
delay={autoplay.delay}
|
|
869
|
+
isPlaying={autoplay.isPlaying}
|
|
870
|
+
light={light}
|
|
871
|
+
orientation={orientation}
|
|
872
|
+
/>
|
|
873
|
+
) : (
|
|
874
|
+
<span
|
|
875
|
+
aria-hidden="true"
|
|
876
|
+
data-slot="carousel-progress-indicator"
|
|
877
|
+
data-orientation={orientation}
|
|
878
|
+
className={cn('block rounded-full', isHorizontal ? 'h-full' : 'w-full', light ? 'bg-white' : 'bg-primary')}
|
|
879
|
+
style={isHorizontal ? { width: `${scrollProgress * 100}%` } : { height: `${scrollProgress * 100}%` }}
|
|
880
|
+
/>
|
|
881
|
+
)}
|
|
882
|
+
</div>
|
|
883
|
+
)
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
interface CarouselAutoplayCircularIndicatorProps {
|
|
887
|
+
delay: number
|
|
888
|
+
isPlaying: boolean
|
|
889
|
+
light: boolean
|
|
890
|
+
center: number
|
|
891
|
+
radius: number
|
|
892
|
+
circumference: number
|
|
893
|
+
thickness: number
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
function CarouselAutoplayCircularIndicator({
|
|
897
|
+
delay,
|
|
898
|
+
isPlaying,
|
|
899
|
+
light,
|
|
900
|
+
center,
|
|
901
|
+
radius,
|
|
902
|
+
circumference,
|
|
903
|
+
thickness,
|
|
904
|
+
}: CarouselAutoplayCircularIndicatorProps) {
|
|
905
|
+
const [armed, setArmed] = React.useState(false)
|
|
906
|
+
|
|
907
|
+
React.useEffect(() => {
|
|
908
|
+
let raf2 = 0
|
|
909
|
+
const raf1 = requestAnimationFrame(() => {
|
|
910
|
+
raf2 = requestAnimationFrame(() => setArmed(true))
|
|
911
|
+
})
|
|
912
|
+
return () => {
|
|
913
|
+
cancelAnimationFrame(raf1)
|
|
914
|
+
cancelAnimationFrame(raf2)
|
|
915
|
+
}
|
|
916
|
+
}, [])
|
|
917
|
+
|
|
918
|
+
const offset = armed && isPlaying ? 0 : circumference
|
|
919
|
+
|
|
920
|
+
return (
|
|
921
|
+
<circle
|
|
922
|
+
data-slot="carousel-progress-indicator"
|
|
923
|
+
data-playing={isPlaying || undefined}
|
|
924
|
+
cx={center}
|
|
925
|
+
cy={center}
|
|
926
|
+
r={radius}
|
|
927
|
+
fill="none"
|
|
928
|
+
strokeWidth={thickness}
|
|
929
|
+
strokeLinecap="round"
|
|
930
|
+
strokeDasharray={circumference}
|
|
931
|
+
strokeDashoffset={offset}
|
|
932
|
+
className={cn(
|
|
933
|
+
'motion-safe:transition-[stroke-dashoffset] motion-safe:ease-linear',
|
|
934
|
+
light ? 'stroke-white' : 'stroke-primary',
|
|
935
|
+
)}
|
|
936
|
+
style={{ transitionDuration: `${delay}ms` }}
|
|
937
|
+
/>
|
|
938
|
+
)
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* Bidirectionally sync the selected snap between two carousels — the classic
|
|
943
|
+
* "main + thumbnails" pattern. Wires `select` on each so navigating either
|
|
944
|
+
* one drives the other. Both apis can be undefined initially (e.g. waiting on
|
|
945
|
+
* `setApi`); the effect re-runs once both resolve.
|
|
946
|
+
*
|
|
947
|
+
* @example
|
|
948
|
+
* const [mainApi, setMainApi] = useState<CarouselApi>()
|
|
949
|
+
* const [thumbsApi, setThumbsApi] = useState<CarouselApi>()
|
|
950
|
+
* useLinkedCarousels(mainApi, thumbsApi)
|
|
951
|
+
*
|
|
952
|
+
* <Carousel setApi={setMainApi}>…</Carousel>
|
|
953
|
+
* <Carousel setApi={setThumbsApi} align="start" containScroll="keepSnaps">…</Carousel>
|
|
954
|
+
*/
|
|
955
|
+
function useLinkedCarousels(mainApi: CarouselApi | undefined, thumbsApi: CarouselApi | undefined): void {
|
|
956
|
+
React.useEffect(() => {
|
|
957
|
+
if (!mainApi || !thumbsApi) return
|
|
958
|
+
const syncThumbsFromMain = () => {
|
|
959
|
+
thumbsApi.goTo(mainApi.selectedSnap())
|
|
960
|
+
}
|
|
961
|
+
const syncMainFromThumbs = () => {
|
|
962
|
+
mainApi.goTo(thumbsApi.selectedSnap())
|
|
963
|
+
}
|
|
964
|
+
syncThumbsFromMain()
|
|
965
|
+
mainApi.on('select', syncThumbsFromMain)
|
|
966
|
+
thumbsApi.on('select', syncMainFromThumbs)
|
|
967
|
+
return () => {
|
|
968
|
+
mainApi.off('select', syncThumbsFromMain)
|
|
969
|
+
thumbsApi.off('select', syncMainFromThumbs)
|
|
970
|
+
}
|
|
971
|
+
}, [mainApi, thumbsApi])
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
export {
|
|
975
|
+
Carousel,
|
|
976
|
+
CarouselContent,
|
|
977
|
+
CarouselSlide,
|
|
978
|
+
CarouselPrev,
|
|
979
|
+
CarouselNext,
|
|
980
|
+
CarouselPagination,
|
|
981
|
+
CarouselProgress,
|
|
982
|
+
useCarousel,
|
|
983
|
+
useLinkedCarousels,
|
|
984
|
+
}
|
|
985
|
+
export type {
|
|
986
|
+
CarouselProps,
|
|
987
|
+
CarouselContentProps,
|
|
988
|
+
CarouselSlideProps,
|
|
989
|
+
CarouselPrevProps,
|
|
990
|
+
CarouselNextProps,
|
|
991
|
+
CarouselPaginationProps,
|
|
992
|
+
CarouselProgressProps,
|
|
993
|
+
CarouselApi,
|
|
994
|
+
CarouselOptions,
|
|
995
|
+
CarouselPlugin,
|
|
996
|
+
CarouselAutoplayOptions,
|
|
997
|
+
CarouselAutoScrollOptions,
|
|
998
|
+
CarouselAutoHeightOptions,
|
|
999
|
+
CarouselFadeOptions,
|
|
1000
|
+
CarouselClassNamesOptions,
|
|
1001
|
+
CarouselAccessibilityOptions,
|
|
1002
|
+
CarouselWheelGesturesOptions,
|
|
1003
|
+
}
|