@appica/ui-react 1.0.0 → 1.2.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/CHANGELOG.md +72 -0
- package/README.md +47 -5
- package/agent-rules.md +41 -0
- package/appica.css +7 -0
- package/dist/components/accordion/accordion.d.ts +24 -0
- package/dist/components/accordion/accordion.d.ts.map +1 -1
- package/dist/components/accordion/accordion.js +2 -1
- package/dist/components/accordion/accordion.js.map +1 -1
- package/dist/components/alert/alert.d.ts +30 -2
- package/dist/components/alert/alert.d.ts.map +1 -1
- package/dist/components/alert/alert.js +2 -1
- package/dist/components/alert/alert.js.map +1 -1
- package/dist/components/alert-dialog/alert-dialog.d.ts +12 -2
- package/dist/components/alert-dialog/alert-dialog.d.ts.map +1 -1
- package/dist/components/alert-dialog/alert-dialog.js +10 -5
- package/dist/components/alert-dialog/alert-dialog.js.map +1 -1
- package/dist/components/autocomplete/autocomplete.d.ts +21 -1
- package/dist/components/autocomplete/autocomplete.d.ts.map +1 -1
- package/dist/components/autocomplete/autocomplete.js +3 -2
- package/dist/components/autocomplete/autocomplete.js.map +1 -1
- package/dist/components/avatar/avatar.d.ts +17 -1
- package/dist/components/avatar/avatar.d.ts.map +1 -1
- package/dist/components/avatar/avatar.js +2 -1
- package/dist/components/avatar/avatar.js.map +1 -1
- package/dist/components/background-pattern/background-pattern-interactive.d.ts +2 -1
- package/dist/components/background-pattern/background-pattern-interactive.d.ts.map +1 -1
- package/dist/components/background-pattern/background-pattern-interactive.js +4 -2
- package/dist/components/background-pattern/background-pattern-interactive.js.map +1 -1
- package/dist/components/background-pattern/background-pattern-shared.d.ts +3 -2
- package/dist/components/background-pattern/background-pattern-shared.d.ts.map +1 -1
- package/dist/components/background-pattern/background-pattern-shared.js +48 -16
- package/dist/components/background-pattern/background-pattern-shared.js.map +1 -1
- package/dist/components/background-pattern/background-pattern.d.ts +13 -5
- package/dist/components/background-pattern/background-pattern.d.ts.map +1 -1
- package/dist/components/background-pattern/background-pattern.js +13 -4
- package/dist/components/background-pattern/background-pattern.js.map +1 -1
- package/dist/components/background-pattern/index.js +1 -0
- package/dist/components/background-pattern/index.js.map +1 -1
- package/dist/components/badge/badge.d.ts +13 -3
- package/dist/components/badge/badge.d.ts.map +1 -1
- package/dist/components/badge/badge.js +2 -1
- package/dist/components/badge/badge.js.map +1 -1
- package/dist/components/border-beam/border-beam.d.ts +52 -0
- package/dist/components/border-beam/border-beam.d.ts.map +1 -0
- package/dist/components/border-beam/border-beam.js +68 -0
- package/dist/components/border-beam/border-beam.js.map +1 -0
- package/dist/components/breadcrumb/breadcrumb.d.ts +8 -0
- package/dist/components/breadcrumb/breadcrumb.d.ts.map +1 -1
- package/dist/components/breadcrumb/breadcrumb.js +2 -1
- package/dist/components/breadcrumb/breadcrumb.js.map +1 -1
- package/dist/components/button/button-variants.d.ts +2 -2
- package/dist/components/button/button-variants.js +2 -1
- package/dist/components/button/button-variants.js.map +1 -1
- package/dist/components/button/button.d.ts +11 -1
- package/dist/components/button/button.d.ts.map +1 -1
- package/dist/components/button/button.js +2 -1
- package/dist/components/button/button.js.map +1 -1
- package/dist/components/button/index.js +1 -0
- package/dist/components/button/index.js.map +1 -1
- package/dist/components/button-group/button-group-context.js +1 -0
- package/dist/components/button-group/button-group-context.js.map +1 -1
- package/dist/components/button-group/button-group.d.ts +10 -0
- package/dist/components/button-group/button-group.d.ts.map +1 -1
- package/dist/components/button-group/button-group.js +2 -1
- package/dist/components/button-group/button-group.js.map +1 -1
- package/dist/components/calendar/calendar.d.ts +5 -0
- package/dist/components/calendar/calendar.d.ts.map +1 -1
- package/dist/components/calendar/calendar.js +2 -1
- package/dist/components/calendar/calendar.js.map +1 -1
- package/dist/components/card/card.d.ts +43 -0
- package/dist/components/card/card.d.ts.map +1 -0
- package/dist/components/card/card.js +104 -0
- package/dist/components/card/card.js.map +1 -0
- package/dist/components/carousel/carousel.d.ts +106 -6
- package/dist/components/carousel/carousel.d.ts.map +1 -1
- package/dist/components/carousel/carousel.js +180 -5
- package/dist/components/carousel/carousel.js.map +1 -1
- package/dist/components/checkbox/checkbox.js +2 -1
- package/dist/components/checkbox/checkbox.js.map +1 -1
- package/dist/components/checkbox-group/checkbox-group.d.ts +4 -0
- package/dist/components/checkbox-group/checkbox-group.d.ts.map +1 -1
- package/dist/components/checkbox-group/checkbox-group.js +2 -1
- package/dist/components/checkbox-group/checkbox-group.js.map +1 -1
- package/dist/components/chip/chip.d.ts +33 -1
- package/dist/components/chip/chip.d.ts.map +1 -1
- package/dist/components/chip/chip.js +2 -1
- package/dist/components/chip/chip.js.map +1 -1
- package/dist/components/collapsible/collapsible.js +2 -1
- package/dist/components/collapsible/collapsible.js.map +1 -1
- package/dist/components/color-area/color-area.d.ts +53 -0
- package/dist/components/color-area/color-area.d.ts.map +1 -0
- package/dist/components/color-area/color-area.js +246 -0
- package/dist/components/color-area/color-area.js.map +1 -0
- package/dist/components/color-picker/color-picker.d.ts +152 -0
- package/dist/components/color-picker/color-picker.d.ts.map +1 -0
- package/dist/components/color-picker/color-picker.js +328 -0
- package/dist/components/color-picker/color-picker.js.map +1 -0
- package/dist/components/color-slider/color-slider.d.ts +48 -0
- package/dist/components/color-slider/color-slider.d.ts.map +1 -0
- package/dist/components/color-slider/color-slider.js +217 -0
- package/dist/components/color-slider/color-slider.js.map +1 -0
- package/dist/components/color-swatch/color-swatch.d.ts +47 -0
- package/dist/components/color-swatch/color-swatch.d.ts.map +1 -0
- package/dist/components/color-swatch/color-swatch.js +67 -0
- package/dist/components/color-swatch/color-swatch.js.map +1 -0
- package/dist/components/color-swatch-picker/color-swatch-picker.d.ts +62 -0
- package/dist/components/color-swatch-picker/color-swatch-picker.d.ts.map +1 -0
- package/dist/components/color-swatch-picker/color-swatch-picker.js +203 -0
- package/dist/components/color-swatch-picker/color-swatch-picker.js.map +1 -0
- package/dist/components/combobox/combobox.d.ts +25 -1
- package/dist/components/combobox/combobox.d.ts.map +1 -1
- package/dist/components/combobox/combobox.js +3 -2
- package/dist/components/combobox/combobox.js.map +1 -1
- package/dist/components/context-menu/context-menu.d.ts +7 -1
- package/dist/components/context-menu/context-menu.d.ts.map +1 -1
- package/dist/components/context-menu/context-menu.js +11 -5
- package/dist/components/context-menu/context-menu.js.map +1 -1
- package/dist/components/copy-button/copy-button.d.ts +18 -1
- package/dist/components/copy-button/copy-button.d.ts.map +1 -1
- package/dist/components/copy-button/copy-button.js +6 -5
- package/dist/components/copy-button/copy-button.js.map +1 -1
- package/dist/components/countdown/countdown.d.ts +14 -0
- package/dist/components/countdown/countdown.d.ts.map +1 -1
- package/dist/components/countdown/countdown.js +2 -1
- package/dist/components/countdown/countdown.js.map +1 -1
- package/dist/components/date-field/date-field.d.ts +35 -0
- package/dist/components/date-field/date-field.d.ts.map +1 -1
- package/dist/components/date-field/date-field.js +2 -1
- package/dist/components/date-field/date-field.js.map +1 -1
- package/dist/components/date-picker/date-picker.d.ts +94 -0
- package/dist/components/date-picker/date-picker.d.ts.map +1 -1
- package/dist/components/date-picker/date-picker.js +2 -1
- package/dist/components/date-picker/date-picker.js.map +1 -1
- package/dist/components/dialog/dialog.d.ts +20 -2
- package/dist/components/dialog/dialog.d.ts.map +1 -1
- package/dist/components/dialog/dialog.js +9 -4
- package/dist/components/dialog/dialog.js.map +1 -1
- package/dist/components/drawer/drawer.d.ts +22 -2
- package/dist/components/drawer/drawer.d.ts.map +1 -1
- package/dist/components/drawer/drawer.js +14 -7
- package/dist/components/drawer/drawer.js.map +1 -1
- package/dist/components/dropdown-menu/dropdown-menu.d.ts +7 -1
- package/dist/components/dropdown-menu/dropdown-menu.d.ts.map +1 -1
- package/dist/components/dropdown-menu/dropdown-menu.js +11 -5
- package/dist/components/dropdown-menu/dropdown-menu.js.map +1 -1
- package/dist/components/field/field.js +2 -1
- package/dist/components/field/field.js.map +1 -1
- package/dist/components/fieldset/fieldset.js +2 -1
- package/dist/components/fieldset/fieldset.js.map +1 -1
- package/dist/components/form/form.js +1 -0
- package/dist/components/form/form.js.map +1 -1
- package/dist/components/gradient-glow/gradient-glow.d.ts +51 -1
- package/dist/components/gradient-glow/gradient-glow.d.ts.map +1 -1
- package/dist/components/gradient-glow/gradient-glow.js +5 -3
- package/dist/components/gradient-glow/gradient-glow.js.map +1 -1
- package/dist/components/input/index.js +1 -0
- package/dist/components/input/index.js.map +1 -1
- package/dist/components/input/input-variants.d.ts +1 -1
- package/dist/components/input/input-variants.js +2 -1
- package/dist/components/input/input-variants.js.map +1 -1
- package/dist/components/input/input.d.ts +21 -1
- package/dist/components/input/input.d.ts.map +1 -1
- package/dist/components/input/input.js +4 -3
- package/dist/components/input/input.js.map +1 -1
- package/dist/components/kbd/kbd.d.ts +8 -0
- package/dist/components/kbd/kbd.d.ts.map +1 -1
- package/dist/components/kbd/kbd.js +2 -1
- package/dist/components/kbd/kbd.js.map +1 -1
- package/dist/components/loader/loader.d.ts +8 -0
- package/dist/components/loader/loader.d.ts.map +1 -1
- package/dist/components/loader/loader.js +2 -1
- package/dist/components/loader/loader.js.map +1 -1
- package/dist/components/menubar/menubar.d.ts +8 -0
- package/dist/components/menubar/menubar.d.ts.map +1 -1
- package/dist/components/menubar/menubar.js +2 -1
- package/dist/components/menubar/menubar.js.map +1 -1
- package/dist/components/meter/meter.d.ts +4 -0
- package/dist/components/meter/meter.d.ts.map +1 -1
- package/dist/components/meter/meter.js +2 -1
- package/dist/components/meter/meter.js.map +1 -1
- package/dist/components/navigation/index.js +1 -0
- package/dist/components/navigation/index.js.map +1 -1
- package/dist/components/navigation/navigation-context.js +1 -0
- package/dist/components/navigation/navigation-context.js.map +1 -1
- package/dist/components/navigation/navigation-link-variants.d.ts +2 -2
- package/dist/components/navigation/navigation-link-variants.js +2 -1
- package/dist/components/navigation/navigation-link-variants.js.map +1 -1
- package/dist/components/navigation/navigation-link.d.ts +22 -0
- package/dist/components/navigation/navigation-link.d.ts.map +1 -1
- package/dist/components/navigation/navigation-link.js +2 -1
- package/dist/components/navigation/navigation-link.js.map +1 -1
- package/dist/components/navigation/navigation.d.ts +12 -0
- package/dist/components/navigation/navigation.d.ts.map +1 -1
- package/dist/components/navigation/navigation.js +2 -1
- package/dist/components/navigation/navigation.js.map +1 -1
- package/dist/components/navigation-menu/navigation-menu.d.ts +33 -0
- package/dist/components/navigation-menu/navigation-menu.d.ts.map +1 -1
- package/dist/components/navigation-menu/navigation-menu.js +2 -1
- package/dist/components/navigation-menu/navigation-menu.js.map +1 -1
- package/dist/components/number-field/number-field.d.ts +14 -0
- package/dist/components/number-field/number-field.d.ts.map +1 -1
- package/dist/components/number-field/number-field.js +2 -1
- package/dist/components/number-field/number-field.js.map +1 -1
- package/dist/components/otp-field/otp-field.d.ts +9 -0
- package/dist/components/otp-field/otp-field.d.ts.map +1 -1
- package/dist/components/otp-field/otp-field.js +2 -1
- package/dist/components/otp-field/otp-field.js.map +1 -1
- package/dist/components/pagination/pagination.d.ts +16 -0
- package/dist/components/pagination/pagination.d.ts.map +1 -1
- package/dist/components/pagination/pagination.js +2 -1
- package/dist/components/pagination/pagination.js.map +1 -1
- package/dist/components/popover/popover.d.ts +5 -1
- package/dist/components/popover/popover.d.ts.map +1 -1
- package/dist/components/popover/popover.js +3 -2
- package/dist/components/popover/popover.js.map +1 -1
- package/dist/components/preview-card/preview-card.d.ts +5 -1
- package/dist/components/preview-card/preview-card.d.ts.map +1 -1
- package/dist/components/preview-card/preview-card.js +3 -2
- package/dist/components/preview-card/preview-card.js.map +1 -1
- package/dist/components/progress/progress.d.ts +17 -0
- package/dist/components/progress/progress.d.ts.map +1 -1
- package/dist/components/progress/progress.js +2 -1
- package/dist/components/progress/progress.js.map +1 -1
- package/dist/components/radio/radio.js +2 -1
- package/dist/components/radio/radio.js.map +1 -1
- package/dist/components/radio-group/radio-group.d.ts +4 -0
- package/dist/components/radio-group/radio-group.d.ts.map +1 -1
- package/dist/components/radio-group/radio-group.js +2 -1
- package/dist/components/radio-group/radio-group.js.map +1 -1
- package/dist/components/rating/rating.d.ts +79 -0
- package/dist/components/rating/rating.d.ts.map +1 -0
- package/dist/components/rating/rating.js +302 -0
- package/dist/components/rating/rating.js.map +1 -0
- package/dist/components/scroll-area/scroll-area.d.ts +13 -0
- package/dist/components/scroll-area/scroll-area.d.ts.map +1 -1
- package/dist/components/scroll-area/scroll-area.js +2 -1
- package/dist/components/scroll-area/scroll-area.js.map +1 -1
- package/dist/components/select/select.d.ts +20 -1
- package/dist/components/select/select.d.ts.map +1 -1
- package/dist/components/select/select.js +3 -2
- package/dist/components/select/select.js.map +1 -1
- package/dist/components/separator/separator.d.ts +4 -0
- package/dist/components/separator/separator.d.ts.map +1 -1
- package/dist/components/separator/separator.js +2 -1
- package/dist/components/separator/separator.js.map +1 -1
- package/dist/components/skeleton/skeleton.d.ts +4 -0
- package/dist/components/skeleton/skeleton.d.ts.map +1 -1
- package/dist/components/skeleton/skeleton.js +2 -1
- package/dist/components/skeleton/skeleton.js.map +1 -1
- package/dist/components/slider/slider.d.ts +5 -0
- package/dist/components/slider/slider.d.ts.map +1 -1
- package/dist/components/slider/slider.js +2 -1
- package/dist/components/slider/slider.js.map +1 -1
- package/dist/components/sparkline/sparkline.d.ts +44 -0
- package/dist/components/sparkline/sparkline.d.ts.map +1 -1
- package/dist/components/sparkline/sparkline.js +2 -1
- package/dist/components/sparkline/sparkline.js.map +1 -1
- package/dist/components/spinner/spinner.d.ts +8 -0
- package/dist/components/spinner/spinner.d.ts.map +1 -1
- package/dist/components/spinner/spinner.js +2 -1
- package/dist/components/spinner/spinner.js.map +1 -1
- package/dist/components/switch/switch.d.ts +19 -15
- package/dist/components/switch/switch.d.ts.map +1 -1
- package/dist/components/switch/switch.js +2 -1
- package/dist/components/switch/switch.js.map +1 -1
- package/dist/components/table/table.d.ts +28 -0
- package/dist/components/table/table.d.ts.map +1 -1
- package/dist/components/table/table.js +2 -1
- package/dist/components/table/table.js.map +1 -1
- package/dist/components/tabs/tabs.d.ts +32 -2
- package/dist/components/tabs/tabs.d.ts.map +1 -1
- package/dist/components/tabs/tabs.js +2 -1
- package/dist/components/tabs/tabs.js.map +1 -1
- package/dist/components/text-animate/text-animate.d.ts +31 -0
- package/dist/components/text-animate/text-animate.d.ts.map +1 -1
- package/dist/components/text-animate/text-animate.js +27 -9
- package/dist/components/text-animate/text-animate.js.map +1 -1
- package/dist/components/textarea/textarea.d.ts +15 -0
- package/dist/components/textarea/textarea.d.ts.map +1 -1
- package/dist/components/textarea/textarea.js +2 -1
- package/dist/components/textarea/textarea.js.map +1 -1
- package/dist/components/thumbnail/thumbnail.d.ts +22 -2
- package/dist/components/thumbnail/thumbnail.d.ts.map +1 -1
- package/dist/components/thumbnail/thumbnail.js +2 -1
- package/dist/components/thumbnail/thumbnail.js.map +1 -1
- package/dist/components/time-field/time-field.d.ts +35 -0
- package/dist/components/time-field/time-field.d.ts.map +1 -1
- package/dist/components/time-field/time-field.js +2 -1
- package/dist/components/time-field/time-field.js.map +1 -1
- package/dist/components/toast/toast.d.ts +18 -0
- package/dist/components/toast/toast.d.ts.map +1 -1
- package/dist/components/toast/toast.js +2 -1
- package/dist/components/toast/toast.js.map +1 -1
- package/dist/components/toc/toc.d.ts +10 -0
- package/dist/components/toc/toc.d.ts.map +1 -1
- package/dist/components/toc/toc.js +2 -1
- package/dist/components/toc/toc.js.map +1 -1
- package/dist/components/toggle/toggle.js +1 -0
- package/dist/components/toggle/toggle.js.map +1 -1
- package/dist/components/toggle-group/toggle-group.js +2 -1
- package/dist/components/toggle-group/toggle-group.js.map +1 -1
- package/dist/components/toolbar/toolbar.js +2 -1
- package/dist/components/toolbar/toolbar.js.map +1 -1
- package/dist/components/tooltip/tooltip.d.ts +5 -1
- package/dist/components/tooltip/tooltip.d.ts.map +1 -1
- package/dist/components/tooltip/tooltip.js +3 -2
- package/dist/components/tooltip/tooltip.js.map +1 -1
- package/dist/hooks/use-direction.js +1 -0
- package/dist/hooks/use-direction.js.map +1 -1
- package/dist/hooks/use-dismissible.d.ts +4 -0
- package/dist/hooks/use-dismissible.d.ts.map +1 -1
- package/dist/hooks/use-dismissible.js +1 -0
- package/dist/hooks/use-dismissible.js.map +1 -1
- package/dist/hooks/use-local-storage.js +1 -0
- package/dist/hooks/use-local-storage.js.map +1 -1
- package/dist/hooks/use-media-query.js +1 -0
- package/dist/hooks/use-media-query.js.map +1 -1
- package/dist/hooks/use-reduced-motion.d.ts +1 -1
- package/dist/hooks/use-reduced-motion.js +1 -0
- package/dist/hooks/use-reduced-motion.js.map +1 -1
- package/dist/hooks/use-theme.d.ts +1 -1
- package/dist/hooks/use-theme.js +1 -0
- package/dist/hooks/use-theme.js.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/color-control.d.ts +75 -0
- package/dist/internal/color-control.d.ts.map +1 -0
- package/dist/internal/color-control.js +79 -0
- package/dist/internal/color-control.js.map +1 -0
- package/dist/internal/color-math.d.ts +9 -0
- package/dist/internal/color-math.d.ts.map +1 -0
- package/dist/internal/color-math.js +35 -0
- package/dist/internal/color-math.js.map +1 -0
- package/dist/internal/color-picker-context.d.ts +34 -0
- package/dist/internal/color-picker-context.d.ts.map +1 -0
- package/dist/internal/color-picker-context.js +42 -0
- package/dist/internal/color-picker-context.js.map +1 -0
- package/dist/{floating.d.ts → internal/floating.d.ts} +3 -3
- package/dist/internal/floating.d.ts.map +1 -0
- package/dist/{floating.js → internal/floating.js} +1 -0
- package/dist/internal/floating.js.map +1 -0
- package/dist/{modal.d.ts → internal/modal.d.ts} +2 -2
- package/dist/internal/modal.d.ts.map +1 -0
- package/dist/{modal.js → internal/modal.js} +1 -0
- package/dist/internal/modal.js.map +1 -0
- package/dist/{utils.d.ts → internal/utils.d.ts} +2 -2
- package/dist/internal/utils.d.ts.map +1 -0
- package/dist/{utils.js → internal/utils.js} +1 -0
- package/dist/internal/utils.js.map +1 -0
- package/dist/lib/color.d.ts +95 -0
- package/dist/lib/color.d.ts.map +1 -0
- package/dist/lib/color.js +329 -0
- package/dist/lib/color.js.map +1 -0
- package/dist/providers/direction-provider.d.ts +4 -4
- package/dist/providers/direction-provider.d.ts.map +1 -1
- package/dist/providers/direction-provider.js +1 -0
- package/dist/providers/direction-provider.js.map +1 -1
- package/dist/providers/reduced-motion-provider.d.ts +4 -8
- package/dist/providers/reduced-motion-provider.d.ts.map +1 -1
- package/dist/providers/reduced-motion-provider.js +1 -0
- package/dist/providers/reduced-motion-provider.js.map +1 -1
- package/dist/providers/theme-provider/index.js +1 -0
- package/dist/providers/theme-provider/index.js.map +1 -1
- package/dist/providers/theme-provider/theme-provider.d.ts +28 -12
- package/dist/providers/theme-provider/theme-provider.d.ts.map +1 -1
- package/dist/providers/theme-provider/theme-provider.js +1 -0
- package/dist/providers/theme-provider/theme-provider.js.map +1 -1
- package/dist/providers/theme-provider/theme-script.js +1 -0
- package/dist/providers/theme-provider/theme-script.js.map +1 -1
- package/package.json +91 -31
- package/src/components/accordion/accordion.tsx +25 -1
- package/src/components/alert/alert.tsx +30 -2
- package/src/components/alert-dialog/alert-dialog.test.tsx +34 -2
- package/src/components/alert-dialog/alert-dialog.tsx +21 -5
- package/src/components/autocomplete/autocomplete.test.tsx +1 -1
- package/src/components/autocomplete/autocomplete.tsx +22 -2
- package/src/components/avatar/avatar.test.tsx +2 -2
- package/src/components/avatar/avatar.tsx +17 -1
- package/src/components/background-pattern/background-pattern-interactive.tsx +4 -2
- package/src/components/background-pattern/background-pattern-shared.tsx +56 -19
- package/src/components/background-pattern/background-pattern.test.tsx +36 -1
- package/src/components/background-pattern/background-pattern.tsx +24 -9
- package/src/components/badge/badge.tsx +14 -2
- package/src/components/border-beam/border-beam.test.tsx +91 -0
- package/src/components/border-beam/border-beam.tsx +131 -0
- package/src/components/breadcrumb/breadcrumb.tsx +9 -1
- package/src/components/button/button-variants.ts +1 -1
- package/src/components/button/button.tsx +13 -2
- package/src/components/button-group/button-group.tsx +11 -1
- package/src/components/calendar/calendar.tsx +6 -1
- package/src/components/card/card.test.tsx +98 -0
- package/src/components/card/card.tsx +154 -0
- package/src/components/carousel/carousel.test.tsx +179 -0
- package/src/components/carousel/carousel.tsx +329 -6
- package/src/components/checkbox/checkbox.test.tsx +2 -2
- package/src/components/checkbox/checkbox.tsx +1 -1
- package/src/components/checkbox-group/checkbox-group.tsx +5 -1
- package/src/components/chip/chip.tsx +33 -1
- package/src/components/collapsible/collapsible.tsx +1 -1
- package/src/components/color-area/color-area.test.tsx +242 -0
- package/src/components/color-area/color-area.tsx +356 -0
- package/src/components/color-picker/color-picker.test.tsx +286 -0
- package/src/components/color-picker/color-picker.tsx +546 -0
- package/src/components/color-slider/color-slider.test.tsx +222 -0
- package/src/components/color-slider/color-slider.tsx +330 -0
- package/src/components/color-swatch/color-swatch.test.tsx +117 -0
- package/src/components/color-swatch/color-swatch.tsx +119 -0
- package/src/components/color-swatch-picker/color-swatch-picker.test.tsx +287 -0
- package/src/components/color-swatch-picker/color-swatch-picker.tsx +327 -0
- package/src/components/combobox/combobox.test.tsx +1 -1
- package/src/components/combobox/combobox.tsx +26 -2
- package/src/components/context-menu/context-menu.test.tsx +28 -0
- package/src/components/context-menu/context-menu.tsx +16 -5
- package/src/components/copy-button/copy-button.test.tsx +14 -1
- package/src/components/copy-button/copy-button.tsx +27 -6
- package/src/components/countdown/countdown.tsx +15 -1
- package/src/components/date-field/date-field.tsx +36 -1
- package/src/components/date-picker/date-picker.test.tsx +1 -1
- package/src/components/date-picker/date-picker.tsx +95 -1
- package/src/components/dialog/dialog.test.tsx +30 -1
- package/src/components/dialog/dialog.tsx +28 -6
- package/src/components/drawer/drawer.test.tsx +32 -1
- package/src/components/drawer/drawer.tsx +37 -7
- package/src/components/dropdown-menu/dropdown-menu.test.tsx +28 -0
- package/src/components/dropdown-menu/dropdown-menu.tsx +16 -5
- package/src/components/field/field.tsx +1 -1
- package/src/components/fieldset/fieldset.tsx +1 -1
- package/src/components/gradient-glow/gradient-glow.test.tsx +7 -1
- package/src/components/gradient-glow/gradient-glow.tsx +64 -11
- package/src/components/input/input-variants.ts +1 -1
- package/src/components/input/input.tsx +24 -4
- package/src/components/kbd/kbd.tsx +9 -1
- package/src/components/loader/loader.tsx +9 -1
- package/src/components/menubar/menubar.tsx +9 -1
- package/src/components/meter/meter.tsx +5 -1
- package/src/components/navigation/navigation-link-variants.ts +1 -1
- package/src/components/navigation/navigation-link.tsx +23 -1
- package/src/components/navigation/navigation.tsx +23 -3
- package/src/components/navigation-menu/navigation-menu.tsx +34 -1
- package/src/components/number-field/number-field.tsx +15 -1
- package/src/components/otp-field/otp-field.tsx +10 -1
- package/src/components/pagination/pagination.tsx +17 -1
- package/src/components/popover/popover.test.tsx +1 -1
- package/src/components/popover/popover.tsx +6 -2
- package/src/components/preview-card/preview-card.tsx +6 -2
- package/src/components/progress/progress.tsx +18 -1
- package/src/components/radio/radio.test.tsx +1 -1
- package/src/components/radio/radio.tsx +1 -1
- package/src/components/radio-group/radio-group.test.tsx +1 -1
- package/src/components/radio-group/radio-group.tsx +5 -1
- package/src/components/rating/rating.test.tsx +246 -0
- package/src/components/rating/rating.tsx +457 -0
- package/src/components/scroll-area/scroll-area.test.tsx +1 -1
- package/src/components/scroll-area/scroll-area.tsx +14 -1
- package/src/components/select/select.tsx +21 -2
- package/src/components/separator/separator.tsx +5 -1
- package/src/components/skeleton/skeleton.tsx +5 -1
- package/src/components/slider/slider.test.tsx +1 -1
- package/src/components/slider/slider.tsx +6 -1
- package/src/components/sparkline/sparkline.test.tsx +1 -1
- package/src/components/sparkline/sparkline.tsx +45 -1
- package/src/components/spinner/spinner.tsx +9 -1
- package/src/components/switch/switch.test.tsx +1 -1
- package/src/components/switch/switch.tsx +5 -1
- package/src/components/table/table.tsx +29 -1
- package/src/components/tabs/tabs.test.tsx +1 -1
- package/src/components/tabs/tabs.tsx +33 -2
- package/src/components/text-animate/text-animate.test.tsx +62 -0
- package/src/components/text-animate/text-animate.tsx +77 -9
- package/src/components/textarea/textarea.tsx +16 -1
- package/src/components/thumbnail/thumbnail.test.tsx +1 -1
- package/src/components/thumbnail/thumbnail.tsx +21 -1
- package/src/components/time-field/time-field.tsx +36 -1
- package/src/components/toast/toast.test.tsx +1 -1
- package/src/components/toast/toast.tsx +19 -1
- package/src/components/toc/toc.tsx +11 -1
- package/src/components/toggle/toggle.test.tsx +1 -1
- package/src/components/toggle-group/toggle-group.tsx +1 -1
- package/src/components/toolbar/toolbar.tsx +1 -1
- package/src/components/tooltip/tooltip.test.tsx +1 -1
- package/src/components/tooltip/tooltip.tsx +6 -2
- package/src/hooks/use-dismissible.ts +4 -0
- package/src/hooks/use-local-storage.ts +3 -3
- package/src/hooks/use-reduced-motion.ts +1 -1
- package/src/hooks/use-theme.ts +1 -1
- package/src/index.ts +11 -2
- package/src/internal/color-control.ts +178 -0
- package/src/internal/color-math.ts +44 -0
- package/src/internal/color-picker-context.ts +80 -0
- package/src/{floating.ts → internal/floating.ts} +3 -3
- package/src/{modal.ts → internal/modal.ts} +3 -3
- package/src/lib/color.test.ts +178 -0
- package/src/lib/color.ts +471 -0
- package/src/providers/direction-provider.tsx +4 -4
- package/src/providers/reduced-motion-provider.tsx +4 -8
- package/src/providers/theme-provider/theme-provider.tsx +28 -12
- package/src/providers/theme-provider/theme-script.tsx +2 -2
- package/src/test/setup.ts +1 -1
- package/styles.css +28 -4
- package/dist/floating.d.ts.map +0 -1
- package/dist/floating.js.map +0 -1
- package/dist/modal.d.ts.map +0 -1
- package/dist/modal.js.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js.map +0 -1
- /package/src/{floating.test.ts → internal/floating.test.ts} +0 -0
- /package/src/{modal.test.ts → internal/modal.test.ts} +0 -0
- /package/src/{utils.test.tsx → internal/utils.test.tsx} +0 -0
- /package/src/{utils.ts → internal/utils.ts} +0 -0
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { type VariantProps } from 'class-variance-authority'
|
|
5
|
+
import { cn } from '../../internal/utils'
|
|
6
|
+
import { describeColor, normalizeColor } from '../../internal/color-control'
|
|
7
|
+
import {
|
|
8
|
+
ColorPickerContext,
|
|
9
|
+
type ColorPickerContextValue,
|
|
10
|
+
useRequiredColorPickerContext,
|
|
11
|
+
} from '../../internal/color-picker-context'
|
|
12
|
+
import { ColorArea } from '../color-area/color-area'
|
|
13
|
+
import { ColorSlider } from '../color-slider/color-slider'
|
|
14
|
+
import { ColorSwatch, type ColorSwatchProps } from '../color-swatch/color-swatch'
|
|
15
|
+
import { buttonVariants } from '../button/button-variants'
|
|
16
|
+
import { Input, type InputProps } from '../input'
|
|
17
|
+
import {
|
|
18
|
+
Popover,
|
|
19
|
+
PopoverContent,
|
|
20
|
+
PopoverTrigger,
|
|
21
|
+
type PopoverContentProps,
|
|
22
|
+
type PopoverProps,
|
|
23
|
+
} from '../popover/popover'
|
|
24
|
+
import { type Color, type ColorFormat, formatColor, safeParseColor, withChannelValue } from '../../lib/color'
|
|
25
|
+
|
|
26
|
+
const DEFAULT_VALUE = '#ffffff'
|
|
27
|
+
|
|
28
|
+
type ColorPickerSize = 'sm' | 'md' | 'lg'
|
|
29
|
+
type ColorPickerVariant = 'ghost' | 'outline' | 'soft' | 'flush'
|
|
30
|
+
type ColorPickerSwatchPosition = 'start' | 'end'
|
|
31
|
+
type ColorPickerSwatchShape = NonNullable<ColorSwatchProps['shape']>
|
|
32
|
+
|
|
33
|
+
const TRIGGER_SIZES: Record<ColorPickerSize, { button: ColorPickerSize; swatch: number; iconSwatch: number }> = {
|
|
34
|
+
// A swatch-only trigger is square, so its swatch takes the next size up.
|
|
35
|
+
sm: { button: 'sm', swatch: 20, iconSwatch: 24 },
|
|
36
|
+
md: { button: 'md', swatch: 24, iconSwatch: 28 },
|
|
37
|
+
lg: { button: 'lg', swatch: 28, iconSwatch: 32 },
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const ICON_BUTTON_SIZES: Record<ColorPickerSize, 'icon-sm' | 'icon-md' | 'icon-lg'> = {
|
|
41
|
+
sm: 'icon-sm',
|
|
42
|
+
md: 'icon-md',
|
|
43
|
+
lg: 'icon-lg',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* `flush` is `ghost` with the button shell taken off: no box, no padding, no corner and
|
|
48
|
+
* no hover fill, so the swatch lines up with whatever sits above or below it.
|
|
49
|
+
*/
|
|
50
|
+
const FLUSH_CLASSES =
|
|
51
|
+
'size-auto rounded-none p-0 hover:before:bg-transparent data-popup-open:before:bg-transparent data-pressed:before:bg-transparent'
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Pulls the swatch back out of the button's `px-*` so the gap beside it matches the one
|
|
55
|
+
* the button's height leaves above and below it: half the difference between the two,
|
|
56
|
+
* at every size. A swatch-only trigger is already square, so it needs none of this.
|
|
57
|
+
*/
|
|
58
|
+
const SWATCH_OFFSETS: Record<ColorPickerSize, Record<ColorPickerSwatchPosition, string>> = {
|
|
59
|
+
sm: { start: '-ms-2.5', end: '-me-2.5' },
|
|
60
|
+
md: { start: '-ms-3', end: '-me-3' },
|
|
61
|
+
lg: { start: '-ms-3.5', end: '-me-3.5' },
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const FORMAT_LABELS: Record<ColorFormat, string> = {
|
|
65
|
+
hex: 'Hex',
|
|
66
|
+
hexa: 'Hex',
|
|
67
|
+
rgb: 'RGB',
|
|
68
|
+
rgba: 'RGB',
|
|
69
|
+
hsl: 'HSL',
|
|
70
|
+
hsla: 'HSL',
|
|
71
|
+
hsb: 'HSB',
|
|
72
|
+
hsba: 'HSB',
|
|
73
|
+
oklch: 'OKLCH',
|
|
74
|
+
oklcha: 'OKLCH',
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const OPAQUE_FORMATS: Partial<Record<ColorFormat, ColorFormat>> = {
|
|
78
|
+
hexa: 'hex',
|
|
79
|
+
rgba: 'rgb',
|
|
80
|
+
hsla: 'hsl',
|
|
81
|
+
hsba: 'hsb',
|
|
82
|
+
oklcha: 'oklch',
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* An alpha-carrying format drops back to its opaque twin at full opacity, so a solid
|
|
87
|
+
* color is written `#a855f7` rather than `#a855f7ff` and only grows the alpha when
|
|
88
|
+
* there is one to show.
|
|
89
|
+
*/
|
|
90
|
+
function displayFormat(format: ColorFormat, color: Color): ColorFormat {
|
|
91
|
+
return color.alpha < 1 ? format : (OPAQUE_FORMATS[format] ?? format)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const panelClasses = 'flex w-fit min-w-50 flex-col gap-3'
|
|
95
|
+
|
|
96
|
+
interface ColorPickerProps extends Omit<
|
|
97
|
+
React.HTMLAttributes<HTMLElement>,
|
|
98
|
+
'color' | 'defaultValue' | 'onChange' | 'children'
|
|
99
|
+
> {
|
|
100
|
+
/** Selected color. Pass a `Color` or any CSS color string to control the component. */
|
|
101
|
+
value?: Color | string
|
|
102
|
+
/**
|
|
103
|
+
* Color selected before any interaction, when the component is uncontrolled.
|
|
104
|
+
* @default '#ffffff'
|
|
105
|
+
*/
|
|
106
|
+
defaultValue?: Color | string
|
|
107
|
+
/** Fires on every change, including each frame of a drag inside the panel. */
|
|
108
|
+
onValueChange?: (value: Color) => void
|
|
109
|
+
/** Fires once a gesture ends, with the color that was landed on. */
|
|
110
|
+
onValueCommitted?: (value: Color) => void
|
|
111
|
+
/**
|
|
112
|
+
* Panel contents. Any `ColorArea`, `ColorSlider`, `ColorSwatch` or `ColorSwatchPicker`
|
|
113
|
+
* in here reads and writes the picker's color, so no value wiring is needed. Leave it
|
|
114
|
+
* off for the default panel: an HSB area, a hue slider and a text input, plus a preview
|
|
115
|
+
* swatch when `inline` leaves no trigger to show one.
|
|
116
|
+
*/
|
|
117
|
+
children?: React.ReactNode
|
|
118
|
+
/**
|
|
119
|
+
* Format the trigger and the text input write the color in. Defaults to `'hexa'` when
|
|
120
|
+
* `alpha` is set. An alpha format collapses to its opaque twin whenever the color is
|
|
121
|
+
* fully opaque, so a solid color never picks up a trailing `ff`.
|
|
122
|
+
* @default 'hex'
|
|
123
|
+
*/
|
|
124
|
+
format?: ColorFormat
|
|
125
|
+
/**
|
|
126
|
+
* Add an alpha slider to the default panel, and back the preview with a checkerboard.
|
|
127
|
+
* @default false
|
|
128
|
+
*/
|
|
129
|
+
alpha?: boolean
|
|
130
|
+
/**
|
|
131
|
+
* Add a screen color-sampling button to the default panel. It renders only where the
|
|
132
|
+
* browser supports the EyeDropper API, so there is no dead control on Firefox or Safari.
|
|
133
|
+
* @default false
|
|
134
|
+
*/
|
|
135
|
+
eyedropper?: boolean
|
|
136
|
+
/**
|
|
137
|
+
* Render the panel in place instead of behind a trigger and a popover. The trigger
|
|
138
|
+
* props (`label`, `trigger`, `size`, the popover ones) do nothing in this mode.
|
|
139
|
+
* @default false
|
|
140
|
+
*/
|
|
141
|
+
inline?: boolean
|
|
142
|
+
/**
|
|
143
|
+
* Prevent interaction and dim the trigger and every control in the panel.
|
|
144
|
+
* @default false
|
|
145
|
+
*/
|
|
146
|
+
disabled?: boolean
|
|
147
|
+
/**
|
|
148
|
+
* Height and text scale of the default trigger.
|
|
149
|
+
* @default 'md'
|
|
150
|
+
*/
|
|
151
|
+
size?: ColorPickerSize
|
|
152
|
+
/**
|
|
153
|
+
* Visual style of the default trigger, from `Button`'s set. `flush` takes the button
|
|
154
|
+
* shell off entirely, leaving the swatch and the label on their own.
|
|
155
|
+
* @default 'ghost'
|
|
156
|
+
*/
|
|
157
|
+
variant?: ColorPickerVariant
|
|
158
|
+
/**
|
|
159
|
+
* Text beside the swatch in the default trigger. Defaults to the color, formatted with
|
|
160
|
+
* `format`. Pass `null` for a swatch-only square button, and pair a non-string node
|
|
161
|
+
* with `aria-label`.
|
|
162
|
+
*/
|
|
163
|
+
label?: React.ReactNode
|
|
164
|
+
/**
|
|
165
|
+
* Rounded square or full circle, for the swatch on the default trigger.
|
|
166
|
+
* @default 'rounded'
|
|
167
|
+
*/
|
|
168
|
+
swatchShape?: ColorPickerSwatchShape
|
|
169
|
+
/**
|
|
170
|
+
* Which side of the label the default trigger's swatch sits on. It is inset from that
|
|
171
|
+
* edge by the same gap the button's height leaves above and below it.
|
|
172
|
+
* @default 'start'
|
|
173
|
+
*/
|
|
174
|
+
swatchPosition?: ColorPickerSwatchPosition
|
|
175
|
+
/**
|
|
176
|
+
* Element to open the panel from, in place of the default swatch button. `null` renders
|
|
177
|
+
* no trigger at all, for a panel driven by `open` and pointed at something you own with
|
|
178
|
+
* `popoverProps.anchor`. `className` and the forwarded attributes land on the trigger,
|
|
179
|
+
* so they have nowhere to go in that mode.
|
|
180
|
+
*/
|
|
181
|
+
trigger?: React.ReactElement | null
|
|
182
|
+
/** Controlled open state of the popover. Pair with `onOpenChange`. */
|
|
183
|
+
open?: boolean
|
|
184
|
+
/**
|
|
185
|
+
* Uncontrolled initial open state of the popover.
|
|
186
|
+
* @default false
|
|
187
|
+
*/
|
|
188
|
+
defaultOpen?: boolean
|
|
189
|
+
/**
|
|
190
|
+
* Fires when the popover opens or closes. The second argument carries the `reason` and
|
|
191
|
+
* a `cancel()` that stops Base UI acting on the event.
|
|
192
|
+
*/
|
|
193
|
+
onOpenChange?: PopoverProps['onOpenChange']
|
|
194
|
+
/**
|
|
195
|
+
* Preferred popover side.
|
|
196
|
+
* @default 'bottom'
|
|
197
|
+
*/
|
|
198
|
+
side?: PopoverContentProps['side']
|
|
199
|
+
/**
|
|
200
|
+
* Popover alignment.
|
|
201
|
+
* @default 'start'
|
|
202
|
+
*/
|
|
203
|
+
align?: PopoverContentProps['align']
|
|
204
|
+
/**
|
|
205
|
+
* Gap between the trigger and the popover.
|
|
206
|
+
* @default 6
|
|
207
|
+
*/
|
|
208
|
+
sideOffset?: number
|
|
209
|
+
/** Escape hatch forwarded to the inner `PopoverContent` (collision props, `className`, …). */
|
|
210
|
+
popoverProps?: Partial<PopoverContentProps>
|
|
211
|
+
/** Name of the hidden input, used when submitting an HTML form. */
|
|
212
|
+
name?: string
|
|
213
|
+
/** `id` of the `<form>` the hidden input belongs to, when it sits outside it. */
|
|
214
|
+
form?: string
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function ColorPicker({
|
|
218
|
+
value,
|
|
219
|
+
defaultValue = DEFAULT_VALUE,
|
|
220
|
+
onValueChange,
|
|
221
|
+
onValueCommitted,
|
|
222
|
+
children,
|
|
223
|
+
format: formatProp,
|
|
224
|
+
alpha = false,
|
|
225
|
+
eyedropper = false,
|
|
226
|
+
inline = false,
|
|
227
|
+
disabled = false,
|
|
228
|
+
size = 'md',
|
|
229
|
+
variant = 'ghost',
|
|
230
|
+
label,
|
|
231
|
+
swatchShape = 'rounded',
|
|
232
|
+
swatchPosition = 'start',
|
|
233
|
+
trigger,
|
|
234
|
+
open,
|
|
235
|
+
defaultOpen = false,
|
|
236
|
+
onOpenChange,
|
|
237
|
+
side = 'bottom',
|
|
238
|
+
align = 'start',
|
|
239
|
+
sideOffset = 6,
|
|
240
|
+
popoverProps,
|
|
241
|
+
name,
|
|
242
|
+
form,
|
|
243
|
+
className,
|
|
244
|
+
'aria-label': ariaLabel,
|
|
245
|
+
...props
|
|
246
|
+
}: ColorPickerProps) {
|
|
247
|
+
const [uncontrolled, setUncontrolled] = React.useState<Color>(() => normalizeColor(defaultValue))
|
|
248
|
+
const [internalOpen, setInternalOpen] = React.useState(defaultOpen)
|
|
249
|
+
|
|
250
|
+
const controlled = value !== undefined
|
|
251
|
+
const color = controlled ? normalizeColor(value) : uncontrolled
|
|
252
|
+
const format = formatProp ?? (alpha ? 'hexa' : 'hex')
|
|
253
|
+
|
|
254
|
+
// Kept in a ref so the context object only changes with the color, not with a caller
|
|
255
|
+
// that re-creates its handlers on every render.
|
|
256
|
+
const latestRef = React.useRef({ controlled, onValueChange, onValueCommitted })
|
|
257
|
+
latestRef.current = { controlled, onValueChange, onValueCommitted }
|
|
258
|
+
|
|
259
|
+
const context = React.useMemo<ColorPickerContextValue>(
|
|
260
|
+
() => ({
|
|
261
|
+
value: color,
|
|
262
|
+
format,
|
|
263
|
+
disabled,
|
|
264
|
+
setValue: (next) => {
|
|
265
|
+
if (!latestRef.current.controlled) setUncontrolled(next)
|
|
266
|
+
latestRef.current.onValueChange?.(next)
|
|
267
|
+
},
|
|
268
|
+
commitValue: (next) => latestRef.current.onValueCommitted?.(next),
|
|
269
|
+
}),
|
|
270
|
+
[color, format, disabled],
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
const panel = children ?? (
|
|
274
|
+
<>
|
|
275
|
+
<ColorArea colorSpace="hsb" xChannel="saturation" yChannel="brightness" aria-label="Saturation and brightness" />
|
|
276
|
+
<div className="flex items-center gap-3">
|
|
277
|
+
{eyedropper && <ColorPickerEyeDropper />}
|
|
278
|
+
<div className="flex min-w-0 flex-1 flex-col gap-2">
|
|
279
|
+
<ColorSlider channel="hue" />
|
|
280
|
+
{alpha && <ColorSlider channel="alpha" />}
|
|
281
|
+
</div>
|
|
282
|
+
{/* The trigger already previews the color; only an inline panel has to. */}
|
|
283
|
+
{inline && <ColorSwatch size="sm" shape="circle" className="shrink-0" />}
|
|
284
|
+
</div>
|
|
285
|
+
<ColorPickerInput />
|
|
286
|
+
</>
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
const valueText = formatColor(color, displayFormat(format, color))
|
|
290
|
+
const hiddenInput = name ? <input type="hidden" name={name} form={form} value={valueText} /> : null
|
|
291
|
+
|
|
292
|
+
if (inline) {
|
|
293
|
+
return (
|
|
294
|
+
<ColorPickerContext.Provider value={context}>
|
|
295
|
+
<div
|
|
296
|
+
role="group"
|
|
297
|
+
aria-label={ariaLabel}
|
|
298
|
+
{...props}
|
|
299
|
+
data-slot="color-picker"
|
|
300
|
+
{...(disabled ? { 'data-disabled': '' } : {})}
|
|
301
|
+
className={cn(panelClasses, className)}
|
|
302
|
+
>
|
|
303
|
+
{panel}
|
|
304
|
+
{hiddenInput}
|
|
305
|
+
</div>
|
|
306
|
+
</ColorPickerContext.Provider>
|
|
307
|
+
)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const description = describeColor(color)
|
|
311
|
+
const iconOnly = label === null
|
|
312
|
+
const sizes = TRIGGER_SIZES[size]
|
|
313
|
+
const swatch = (
|
|
314
|
+
<ColorSwatch
|
|
315
|
+
aria-hidden="true"
|
|
316
|
+
size={iconOnly ? sizes.iconSwatch : sizes.swatch}
|
|
317
|
+
shape={swatchShape}
|
|
318
|
+
className={iconOnly || variant === 'flush' ? undefined : SWATCH_OFFSETS[size][swatchPosition]}
|
|
319
|
+
/>
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
const defaultTrigger = (
|
|
323
|
+
<button type="button">
|
|
324
|
+
{swatchPosition === 'start' && swatch}
|
|
325
|
+
{!iconOnly && <span>{label ?? valueText}</span>}
|
|
326
|
+
{swatchPosition === 'end' && swatch}
|
|
327
|
+
{!ariaLabel && <span className="sr-only">{description}</span>}
|
|
328
|
+
</button>
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
return (
|
|
332
|
+
<ColorPickerContext.Provider value={context}>
|
|
333
|
+
<Popover
|
|
334
|
+
open={open ?? internalOpen}
|
|
335
|
+
onOpenChange={(next, details) => {
|
|
336
|
+
onOpenChange?.(next, details)
|
|
337
|
+
if (open === undefined && !details.isCanceled) setInternalOpen(next)
|
|
338
|
+
}}
|
|
339
|
+
>
|
|
340
|
+
{trigger !== null && (
|
|
341
|
+
<PopoverTrigger
|
|
342
|
+
aria-label={ariaLabel && `${ariaLabel}, ${description}`}
|
|
343
|
+
{...props}
|
|
344
|
+
data-slot="color-picker-trigger"
|
|
345
|
+
disabled={disabled}
|
|
346
|
+
// The variant classes ride on the wrapper so `cn` resolves them against a
|
|
347
|
+
// consumer `className`; the rendered element carries none of its own.
|
|
348
|
+
className={cn(
|
|
349
|
+
!trigger && [
|
|
350
|
+
buttonVariants({
|
|
351
|
+
variant: variant === 'flush' ? 'ghost' : variant,
|
|
352
|
+
size: iconOnly ? ICON_BUTTON_SIZES[size] : sizes.button,
|
|
353
|
+
}),
|
|
354
|
+
variant === 'flush' && FLUSH_CLASSES,
|
|
355
|
+
],
|
|
356
|
+
className,
|
|
357
|
+
)}
|
|
358
|
+
render={trigger ?? defaultTrigger}
|
|
359
|
+
/>
|
|
360
|
+
)}
|
|
361
|
+
<PopoverContent
|
|
362
|
+
side={side}
|
|
363
|
+
align={align}
|
|
364
|
+
sideOffset={sideOffset}
|
|
365
|
+
arrow={false}
|
|
366
|
+
// The popup is a dialog, and a dialog with no title still needs a name.
|
|
367
|
+
aria-label={ariaLabel ?? 'Color picker'}
|
|
368
|
+
{...popoverProps}
|
|
369
|
+
data-slot="color-picker-panel"
|
|
370
|
+
className={cn(panelClasses, 'max-w-none p-3', popoverProps?.className)}
|
|
371
|
+
>
|
|
372
|
+
{panel}
|
|
373
|
+
</PopoverContent>
|
|
374
|
+
</Popover>
|
|
375
|
+
{hiddenInput}
|
|
376
|
+
</ColorPickerContext.Provider>
|
|
377
|
+
)
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
interface ColorPickerInputProps extends Omit<
|
|
381
|
+
InputProps,
|
|
382
|
+
'value' | 'defaultValue' | 'onChange' | 'color' | 'clearable' | 'onClear'
|
|
383
|
+
> {
|
|
384
|
+
/** Format the color is written in. Defaults to the enclosing picker's `format`. */
|
|
385
|
+
format?: ColorFormat
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Reads any CSS color string the library can parse, not just the format it prints, so
|
|
390
|
+
* pasting `rgb(…)` into a hex field works. A bare `ff0080` is accepted as hex too.
|
|
391
|
+
*/
|
|
392
|
+
function parseInputColor(text: string): Color | undefined {
|
|
393
|
+
const trimmed = text.trim()
|
|
394
|
+
return safeParseColor(/^[0-9a-f]{3,8}$/i.test(trimmed) ? `#${trimmed}` : trimmed)
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function ColorPickerInput({ format: formatProp, className, ...props }: ColorPickerInputProps) {
|
|
398
|
+
const picker = useRequiredColorPickerContext('ColorPickerInput')
|
|
399
|
+
const format = formatProp ?? picker.format
|
|
400
|
+
const [draft, setDraft] = React.useState<string | null>(null)
|
|
401
|
+
|
|
402
|
+
const commit = () => {
|
|
403
|
+
const parsed = draft === null ? undefined : parseInputColor(draft)
|
|
404
|
+
if (parsed) picker.commitValue(parsed)
|
|
405
|
+
setDraft(null)
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return (
|
|
409
|
+
<Input
|
|
410
|
+
inputSize="sm"
|
|
411
|
+
spellCheck={false}
|
|
412
|
+
autoComplete="off"
|
|
413
|
+
autoCorrect="off"
|
|
414
|
+
autoCapitalize="off"
|
|
415
|
+
aria-label={FORMAT_LABELS[format]}
|
|
416
|
+
{...props}
|
|
417
|
+
data-slot="color-picker-input"
|
|
418
|
+
// An <input> is intrinsically 20 characters wide, and `w-full` cannot resolve
|
|
419
|
+
// during intrinsic sizing - so in the panel's `w-fit` column those 20 characters,
|
|
420
|
+
// not the color area, would decide how wide the panel is. Worse on a coarse
|
|
421
|
+
// pointer, where the field steps up to 16px type.
|
|
422
|
+
inputProps={{ size: 1, ...props.inputProps }}
|
|
423
|
+
disabled={props.disabled ?? picker.disabled}
|
|
424
|
+
value={draft ?? formatColor(picker.value, displayFormat(format, picker.value))}
|
|
425
|
+
className={cn('font-mono', className)}
|
|
426
|
+
onChange={(event) => {
|
|
427
|
+
const next = event.target.value
|
|
428
|
+
setDraft(next)
|
|
429
|
+
const parsed = parseInputColor(next)
|
|
430
|
+
if (parsed) picker.setValue(parsed)
|
|
431
|
+
}}
|
|
432
|
+
onBlur={(event) => {
|
|
433
|
+
props.onBlur?.(event)
|
|
434
|
+
commit()
|
|
435
|
+
}}
|
|
436
|
+
onKeyDown={(event) => {
|
|
437
|
+
props.onKeyDown?.(event)
|
|
438
|
+
if (event.defaultPrevented) return
|
|
439
|
+
if (event.key === 'Enter') {
|
|
440
|
+
event.preventDefault()
|
|
441
|
+
commit()
|
|
442
|
+
} else if (event.key === 'Escape') {
|
|
443
|
+
setDraft(null)
|
|
444
|
+
}
|
|
445
|
+
}}
|
|
446
|
+
/>
|
|
447
|
+
)
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
interface EyeDropperApi {
|
|
451
|
+
new (): { open: (options?: { signal?: AbortSignal }) => Promise<{ sRGBHex: string }> }
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
interface ColorPickerEyeDropperProps extends Omit<React.ComponentPropsWithoutRef<'button'>, 'color' | 'children'> {
|
|
455
|
+
/**
|
|
456
|
+
* Visual style, from the same set `Button` offers.
|
|
457
|
+
* @default 'ghost'
|
|
458
|
+
*/
|
|
459
|
+
variant?: VariantProps<typeof buttonVariants>['variant']
|
|
460
|
+
/**
|
|
461
|
+
* Height and padding, from the same set `Button` offers.
|
|
462
|
+
* @default 'icon-sm'
|
|
463
|
+
*/
|
|
464
|
+
size?: VariantProps<typeof buttonVariants>['size']
|
|
465
|
+
/** Icon rendered inside the button. */
|
|
466
|
+
children?: React.ReactNode
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function ColorPickerEyeDropper({
|
|
470
|
+
variant = 'ghost',
|
|
471
|
+
size = 'icon-sm',
|
|
472
|
+
className,
|
|
473
|
+
disabled,
|
|
474
|
+
children = <PipetteIcon />,
|
|
475
|
+
'aria-label': ariaLabel = 'Pick a color from the screen',
|
|
476
|
+
...props
|
|
477
|
+
}: ColorPickerEyeDropperProps) {
|
|
478
|
+
const picker = useRequiredColorPickerContext('ColorPickerEyeDropper')
|
|
479
|
+
// Resolved after mount rather than during render: the server has no `window`, and a
|
|
480
|
+
// guess either way would mismatch the client on hydration.
|
|
481
|
+
const [supported, setSupported] = React.useState(false)
|
|
482
|
+
React.useEffect(() => setSupported('EyeDropper' in window), [])
|
|
483
|
+
|
|
484
|
+
if (!supported) return null
|
|
485
|
+
|
|
486
|
+
const off = disabled ?? picker.disabled
|
|
487
|
+
|
|
488
|
+
const sample = async () => {
|
|
489
|
+
const EyeDropper = (window as unknown as { EyeDropper: EyeDropperApi }).EyeDropper
|
|
490
|
+
let result: { sRGBHex: string }
|
|
491
|
+
try {
|
|
492
|
+
result = await new EyeDropper().open()
|
|
493
|
+
} catch {
|
|
494
|
+
return
|
|
495
|
+
}
|
|
496
|
+
const sampled = safeParseColor(result.sRGBHex)
|
|
497
|
+
if (!sampled) return
|
|
498
|
+
// The API only reports opaque colors, so carry the picker's own alpha across.
|
|
499
|
+
const next = withChannelValue(sampled, 'alpha', picker.value.alpha)
|
|
500
|
+
picker.setValue(next)
|
|
501
|
+
picker.commitValue(next)
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
return (
|
|
505
|
+
<button
|
|
506
|
+
type="button"
|
|
507
|
+
aria-label={ariaLabel}
|
|
508
|
+
{...props}
|
|
509
|
+
data-slot="color-picker-eyedropper"
|
|
510
|
+
disabled={off}
|
|
511
|
+
{...(off ? { 'data-disabled': '' } : {})}
|
|
512
|
+
className={cn(
|
|
513
|
+
buttonVariants({ variant, size }),
|
|
514
|
+
'text-foreground-muted hover:text-foreground shrink-0',
|
|
515
|
+
className,
|
|
516
|
+
)}
|
|
517
|
+
onClick={(event) => {
|
|
518
|
+
props.onClick?.(event)
|
|
519
|
+
if (!event.defaultPrevented) void sample()
|
|
520
|
+
}}
|
|
521
|
+
>
|
|
522
|
+
{children}
|
|
523
|
+
</button>
|
|
524
|
+
)
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
function PipetteIcon() {
|
|
528
|
+
return (
|
|
529
|
+
<svg
|
|
530
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
531
|
+
viewBox="0 0 24 24"
|
|
532
|
+
fill="none"
|
|
533
|
+
stroke="currentColor"
|
|
534
|
+
strokeLinecap="round"
|
|
535
|
+
strokeLinejoin="round"
|
|
536
|
+
aria-hidden="true"
|
|
537
|
+
>
|
|
538
|
+
<path d="m2 22 1-1h3l9-9" />
|
|
539
|
+
<path d="M3 21v-3l9-9" />
|
|
540
|
+
<path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a1 1 0 1 1-3 3l-3.8-3.8a1 1 0 1 1 3-3l.4.4Z" />
|
|
541
|
+
</svg>
|
|
542
|
+
)
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export { ColorPicker, ColorPickerInput, ColorPickerEyeDropper }
|
|
546
|
+
export type { ColorPickerProps, ColorPickerInputProps, ColorPickerEyeDropperProps }
|