@appica/ui-react 1.0.0 → 1.1.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 +46 -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 +1 -1
- package/dist/components/accordion/accordion.js.map +1 -1
- package/dist/components/alert/alert.d.ts +29 -1
- package/dist/components/alert/alert.d.ts.map +1 -1
- package/dist/components/alert/alert.js +1 -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 +9 -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 +2 -2
- package/dist/components/autocomplete/autocomplete.js.map +1 -1
- package/dist/components/avatar/avatar.d.ts +16 -0
- package/dist/components/avatar/avatar.d.ts.map +1 -1
- package/dist/components/avatar/avatar.js +1 -1
- package/dist/components/avatar/avatar.js.map +1 -1
- package/dist/components/background-pattern/background-pattern-interactive.js +1 -1
- package/dist/components/background-pattern/background-pattern-interactive.js.map +1 -1
- package/dist/components/background-pattern/background-pattern-shared.js +1 -1
- 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 +1 -1
- package/dist/components/background-pattern/background-pattern.js.map +1 -1
- package/dist/components/badge/badge.d.ts +11 -1
- package/dist/components/badge/badge.d.ts.map +1 -1
- package/dist/components/badge/badge.js +1 -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 +67 -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 +1 -1
- package/dist/components/breadcrumb/breadcrumb.js.map +1 -1
- package/dist/components/button/button-variants.js +1 -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 +1 -1
- package/dist/components/button/button.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 +1 -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 +1 -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 +103 -0
- package/dist/components/card/card.js.map +1 -0
- package/dist/components/carousel/carousel.d.ts +105 -5
- package/dist/components/carousel/carousel.d.ts.map +1 -1
- package/dist/components/carousel/carousel.js +157 -5
- package/dist/components/carousel/carousel.js.map +1 -1
- package/dist/components/checkbox/checkbox.js +1 -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 +1 -1
- package/dist/components/checkbox-group/checkbox-group.js.map +1 -1
- package/dist/components/chip/chip.d.ts +32 -0
- package/dist/components/chip/chip.d.ts.map +1 -1
- package/dist/components/chip/chip.js +1 -1
- package/dist/components/chip/chip.js.map +1 -1
- package/dist/components/collapsible/collapsible.js +1 -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 +245 -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 +327 -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 +216 -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 +66 -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 +202 -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 +2 -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 +5 -5
- package/dist/components/context-menu/context-menu.js.map +1 -1
- package/dist/components/copy-button/copy-button.d.ts +15 -0
- package/dist/components/copy-button/copy-button.d.ts.map +1 -1
- package/dist/components/copy-button/copy-button.js +1 -1
- 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 +1 -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 +1 -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 +1 -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 +8 -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 +13 -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 +5 -5
- package/dist/components/dropdown-menu/dropdown-menu.js.map +1 -1
- package/dist/components/field/field.js +1 -1
- package/dist/components/field/field.js.map +1 -1
- package/dist/components/fieldset/fieldset.js +1 -1
- package/dist/components/fieldset/fieldset.js.map +1 -1
- package/dist/components/gradient-glow/gradient-glow.d.ts +45 -0
- package/dist/components/gradient-glow/gradient-glow.d.ts.map +1 -1
- package/dist/components/gradient-glow/gradient-glow.js +1 -1
- package/dist/components/gradient-glow/gradient-glow.js.map +1 -1
- package/dist/components/input/input-variants.js +1 -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 +3 -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 +1 -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 +1 -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 +1 -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 +1 -1
- package/dist/components/meter/meter.js.map +1 -1
- package/dist/components/navigation/navigation-link-variants.d.ts +1 -1
- package/dist/components/navigation/navigation-link-variants.js +1 -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 +1 -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 +1 -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 +1 -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 +1 -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 +1 -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 +1 -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 +2 -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 +2 -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 +1 -1
- package/dist/components/progress/progress.js.map +1 -1
- package/dist/components/radio/radio.js +1 -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 +1 -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 +301 -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 +1 -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 +2 -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 +1 -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 +1 -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 +1 -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 +1 -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 +1 -1
- package/dist/components/spinner/spinner.js.map +1 -1
- package/dist/components/switch/switch.d.ts +4 -0
- package/dist/components/switch/switch.d.ts.map +1 -1
- package/dist/components/switch/switch.js +1 -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 +1 -1
- package/dist/components/table/table.js.map +1 -1
- package/dist/components/tabs/tabs.d.ts +31 -1
- package/dist/components/tabs/tabs.d.ts.map +1 -1
- package/dist/components/tabs/tabs.js +1 -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 +26 -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 +1 -1
- package/dist/components/textarea/textarea.js.map +1 -1
- package/dist/components/thumbnail/thumbnail.d.ts +20 -0
- package/dist/components/thumbnail/thumbnail.d.ts.map +1 -1
- package/dist/components/thumbnail/thumbnail.js +1 -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 +1 -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 +1 -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 +1 -1
- package/dist/components/toc/toc.js.map +1 -1
- package/dist/components/toggle-group/toggle-group.js +1 -1
- package/dist/components/toggle-group/toggle-group.js.map +1 -1
- package/dist/components/toolbar/toolbar.js +1 -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 +2 -2
- package/dist/components/tooltip/tooltip.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.map +1 -1
- package/dist/hooks/use-local-storage.js.map +1 -1
- package/dist/hooks/use-reduced-motion.d.ts +1 -1
- 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.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -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 +78 -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 +34 -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 +41 -0
- package/dist/internal/color-picker-context.js.map +1 -0
- package/dist/{floating.d.ts → internal/floating.d.ts} +1 -1
- package/dist/internal/floating.d.ts.map +1 -0
- package/dist/internal/floating.js.map +1 -0
- package/dist/{modal.d.ts → internal/modal.d.ts} +1 -1
- package/dist/internal/modal.d.ts.map +1 -0
- package/dist/internal/modal.js.map +1 -0
- package/dist/internal/utils.d.ts.map +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 +328 -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.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.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.map +1 -1
- package/dist/providers/theme-provider/theme-script.js.map +1 -1
- package/package.json +75 -17
- 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 +1 -1
- package/src/components/background-pattern/background-pattern-shared.tsx +1 -1
- package/src/components/background-pattern/background-pattern.test.tsx +1 -1
- package/src/components/background-pattern/background-pattern.tsx +14 -6
- 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 +155 -0
- package/src/components/carousel/carousel.tsx +305 -5
- 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.tsx +11 -5
- package/src/components/copy-button/copy-button.test.tsx +1 -1
- package/src/components/copy-button/copy-button.tsx +16 -1
- 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.tsx +11 -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 +1 -1
- package/src/components/gradient-glow/gradient-glow.tsx +46 -1
- 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/dist/{floating.js → internal/floating.js} +0 -0
- /package/dist/{modal.js → internal/modal.js} +0 -0
- /package/dist/{utils.d.ts → internal/utils.d.ts} +0 -0
- /package/dist/{utils.js → internal/utils.js} +0 -0
- /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,242 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { render, screen } from '@testing-library/react'
|
|
3
|
+
import userEvent from '@testing-library/user-event'
|
|
4
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
5
|
+
import { axe } from 'vitest-axe'
|
|
6
|
+
import { ColorArea } from './color-area'
|
|
7
|
+
import { type Color, convertColor, formatColor, getChannelValue, parseColor } from '../../lib/color'
|
|
8
|
+
import { DirectionProvider } from '../../providers/direction-provider'
|
|
9
|
+
|
|
10
|
+
const AREA_RECT = { x: 0, y: 0, top: 0, left: 0, right: 200, bottom: 200, width: 200, height: 200 }
|
|
11
|
+
|
|
12
|
+
function stubAreaSize() {
|
|
13
|
+
vi.spyOn(HTMLDivElement.prototype, 'getBoundingClientRect').mockImplementation(
|
|
14
|
+
() => ({ ...AREA_RECT, toJSON: () => AREA_RECT }) as DOMRect,
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function inputs() {
|
|
19
|
+
return screen.getAllByRole('slider') as HTMLInputElement[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('ColorArea', () => {
|
|
23
|
+
it('exposes one range input per axis, labeled by channel', () => {
|
|
24
|
+
render(<ColorArea defaultValue="hsb(0, 100%, 100%)" xChannel="saturation" yChannel="brightness" />)
|
|
25
|
+
const [x, y] = inputs()
|
|
26
|
+
|
|
27
|
+
expect(x).toHaveAttribute('aria-label', 'Color picker, Saturation')
|
|
28
|
+
expect(x).toHaveAttribute('aria-orientation', 'horizontal')
|
|
29
|
+
expect(y).toHaveAttribute('aria-label', 'Color picker, Brightness')
|
|
30
|
+
expect(y).toHaveAttribute('aria-orientation', 'vertical')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('derives the color space from the value, and the free channel from the axes', () => {
|
|
34
|
+
render(<ColorArea defaultValue="hsl(200, 50%, 50%)" />)
|
|
35
|
+
expect(screen.getByRole('group')).toHaveAttribute('data-space', 'hsl')
|
|
36
|
+
// Unspecified axes take the first free channels: hue on x, saturation on y.
|
|
37
|
+
expect(inputs()[0]).toHaveValue('200')
|
|
38
|
+
expect(inputs()[1]).toHaveValue('50')
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('honors an explicit colorSpace over the space of the value', () => {
|
|
42
|
+
render(<ColorArea defaultValue="#ff0000" colorSpace="hsb" xChannel="saturation" yChannel="brightness" />)
|
|
43
|
+
expect(screen.getByRole('group')).toHaveAttribute('data-space', 'hsb')
|
|
44
|
+
expect(inputs()[0]).toHaveValue('100')
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('announces all three channels in aria-valuetext', () => {
|
|
48
|
+
render(<ColorArea defaultValue="hsb(120, 40%, 60%)" xChannel="saturation" yChannel="brightness" />)
|
|
49
|
+
expect(inputs()[0]).toHaveAttribute('aria-valuetext', 'Hue 120°, Saturation 40%, Brightness 60%')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('moves the x channel on ArrowRight and the y channel on ArrowUp', async () => {
|
|
53
|
+
const user = userEvent.setup()
|
|
54
|
+
const onValueChange = vi.fn<(value: Color) => void>()
|
|
55
|
+
render(
|
|
56
|
+
<ColorArea
|
|
57
|
+
defaultValue="hsb(0, 50%, 50%)"
|
|
58
|
+
xChannel="saturation"
|
|
59
|
+
yChannel="brightness"
|
|
60
|
+
onValueChange={onValueChange}
|
|
61
|
+
/>,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
inputs()[0]?.focus()
|
|
65
|
+
await user.keyboard('{ArrowRight}')
|
|
66
|
+
expect(getChannelValue(onValueChange.mock.lastCall![0], 'saturation')).toBe(51)
|
|
67
|
+
|
|
68
|
+
await user.keyboard('{ArrowUp}')
|
|
69
|
+
expect(getChannelValue(onValueChange.mock.lastCall![0], 'brightness')).toBe(51)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('uses the page step when shift is held', async () => {
|
|
73
|
+
const user = userEvent.setup()
|
|
74
|
+
const onValueChange = vi.fn<(value: Color) => void>()
|
|
75
|
+
render(
|
|
76
|
+
<ColorArea
|
|
77
|
+
defaultValue="hsb(0, 50%, 50%)"
|
|
78
|
+
xChannel="saturation"
|
|
79
|
+
yChannel="brightness"
|
|
80
|
+
onValueChange={onValueChange}
|
|
81
|
+
/>,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
inputs()[0]?.focus()
|
|
85
|
+
await user.keyboard('{Shift>}{ArrowRight}{/Shift}')
|
|
86
|
+
expect(getChannelValue(onValueChange.mock.lastCall![0], 'saturation')).toBe(60)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('clamps at the ends of each channel range', async () => {
|
|
90
|
+
const user = userEvent.setup()
|
|
91
|
+
const onValueChange = vi.fn<(value: Color) => void>()
|
|
92
|
+
render(
|
|
93
|
+
<ColorArea
|
|
94
|
+
defaultValue="hsb(0, 0%, 100%)"
|
|
95
|
+
xChannel="saturation"
|
|
96
|
+
yChannel="brightness"
|
|
97
|
+
onValueChange={onValueChange}
|
|
98
|
+
/>,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
inputs()[0]?.focus()
|
|
102
|
+
await user.keyboard('{ArrowLeft}{ArrowUp}')
|
|
103
|
+
expect(onValueChange).not.toHaveBeenCalled()
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('reverses the horizontal axis in RTL', async () => {
|
|
107
|
+
const user = userEvent.setup()
|
|
108
|
+
const onValueChange = vi.fn<(value: Color) => void>()
|
|
109
|
+
render(
|
|
110
|
+
<DirectionProvider dir="rtl">
|
|
111
|
+
<ColorArea
|
|
112
|
+
defaultValue="hsb(0, 50%, 50%)"
|
|
113
|
+
xChannel="saturation"
|
|
114
|
+
yChannel="brightness"
|
|
115
|
+
onValueChange={onValueChange}
|
|
116
|
+
/>
|
|
117
|
+
</DirectionProvider>,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
inputs()[0]?.focus()
|
|
121
|
+
await user.keyboard('{ArrowRight}')
|
|
122
|
+
expect(getChannelValue(onValueChange.mock.lastCall![0], 'saturation')).toBe(49)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it('sets both channels from a pointer press, with y increasing upwards', async () => {
|
|
126
|
+
stubAreaSize()
|
|
127
|
+
const user = userEvent.setup()
|
|
128
|
+
const onValueChange = vi.fn<(value: Color) => void>()
|
|
129
|
+
render(
|
|
130
|
+
<ColorArea
|
|
131
|
+
defaultValue="hsb(0, 0%, 0%)"
|
|
132
|
+
xChannel="saturation"
|
|
133
|
+
yChannel="brightness"
|
|
134
|
+
onValueChange={onValueChange}
|
|
135
|
+
/>,
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
// A quarter in from the left, a quarter down from the top.
|
|
139
|
+
await user.pointer({ target: screen.getByRole('group'), coords: { clientX: 50, clientY: 50 }, keys: '[MouseLeft]' })
|
|
140
|
+
|
|
141
|
+
const value = onValueChange.mock.lastCall![0]
|
|
142
|
+
expect(getChannelValue(value, 'saturation')).toBe(25)
|
|
143
|
+
expect(getChannelValue(value, 'brightness')).toBe(75)
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it('fires onValueCommitted once the pointer is released', async () => {
|
|
147
|
+
stubAreaSize()
|
|
148
|
+
const user = userEvent.setup()
|
|
149
|
+
const onValueCommitted = vi.fn<(value: Color) => void>()
|
|
150
|
+
render(
|
|
151
|
+
<ColorArea
|
|
152
|
+
defaultValue="hsb(0, 0%, 0%)"
|
|
153
|
+
xChannel="saturation"
|
|
154
|
+
yChannel="brightness"
|
|
155
|
+
onValueCommitted={onValueCommitted}
|
|
156
|
+
/>,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
await user.pointer({ target: screen.getByRole('group'), coords: { clientX: 50, clientY: 50 }, keys: '[MouseLeft]' })
|
|
160
|
+
expect(onValueCommitted).toHaveBeenCalledTimes(1)
|
|
161
|
+
expect(formatColor(onValueCommitted.mock.lastCall![0], 'hsb')).toBe('hsb(0, 25%, 75%)')
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
it('stays on the controlled value when the parent ignores the change', async () => {
|
|
165
|
+
const user = userEvent.setup()
|
|
166
|
+
const onValueChange = vi.fn<(value: Color) => void>()
|
|
167
|
+
render(
|
|
168
|
+
<ColorArea value="hsb(0, 50%, 50%)" xChannel="saturation" yChannel="brightness" onValueChange={onValueChange} />,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
inputs()[0]?.focus()
|
|
172
|
+
await user.keyboard('{ArrowRight}')
|
|
173
|
+
expect(onValueChange).toHaveBeenCalledTimes(1)
|
|
174
|
+
expect(inputs()[0]).toHaveValue('50')
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
it('follows a controlled value that the parent does update', async () => {
|
|
178
|
+
function Controlled() {
|
|
179
|
+
const [color, setColor] = React.useState<Color>(() => parseColor('hsb(0, 50%, 50%)'))
|
|
180
|
+
return <ColorArea value={color} onValueChange={setColor} xChannel="saturation" yChannel="brightness" />
|
|
181
|
+
}
|
|
182
|
+
const user = userEvent.setup()
|
|
183
|
+
render(<Controlled />)
|
|
184
|
+
|
|
185
|
+
inputs()[0]?.focus()
|
|
186
|
+
await user.keyboard('{ArrowRight}{ArrowRight}')
|
|
187
|
+
expect(inputs()[0]).toHaveValue('52')
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('ignores interaction when disabled', async () => {
|
|
191
|
+
const user = userEvent.setup()
|
|
192
|
+
const onValueChange = vi.fn<(value: Color) => void>()
|
|
193
|
+
render(<ColorArea defaultValue="hsb(0, 50%, 50%)" disabled onValueChange={onValueChange} />)
|
|
194
|
+
|
|
195
|
+
expect(screen.getByRole('group')).toHaveAttribute('data-disabled')
|
|
196
|
+
expect(inputs()[0]).toBeDisabled()
|
|
197
|
+
await user.click(screen.getByRole('group'))
|
|
198
|
+
expect(onValueChange).not.toHaveBeenCalled()
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
it('drops the gradient when disabled, so the flat fill can show', () => {
|
|
202
|
+
render(<ColorArea defaultValue="hsb(0, 50%, 50%)" disabled />)
|
|
203
|
+
const area = screen.getByRole('group')
|
|
204
|
+
// An inline background-image would paint straight over the disabled class.
|
|
205
|
+
expect(area.style.backgroundImage).toBe('')
|
|
206
|
+
const knob = area.querySelector('[data-slot="color-area-thumb"]') as HTMLElement
|
|
207
|
+
expect(knob.style.backgroundColor).toBe('')
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
it('defaults to an rgb plane, including for a value whose space has none', () => {
|
|
211
|
+
const { rerender } = render(<ColorArea />)
|
|
212
|
+
expect(screen.getByRole('group')).toHaveAttribute('data-space', 'rgb')
|
|
213
|
+
|
|
214
|
+
rerender(<ColorArea defaultValue="oklch(62.31% 0.188 259.81)" />)
|
|
215
|
+
expect(screen.getByRole('group')).toHaveAttribute('data-space', 'rgb')
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
it('leaves the picked color unchanged when converted to another format', async () => {
|
|
219
|
+
const user = userEvent.setup()
|
|
220
|
+
const onValueChange = vi.fn<(value: Color) => void>()
|
|
221
|
+
render(<ColorArea defaultValue="#3b82f6" onValueChange={onValueChange} />)
|
|
222
|
+
|
|
223
|
+
inputs()[0]?.focus()
|
|
224
|
+
await user.keyboard('{ArrowRight}{ArrowLeft}')
|
|
225
|
+
// Format is independent of the space the area works in: a round trip through
|
|
226
|
+
// the plane has to survive being written out in any of them.
|
|
227
|
+
const picked = onValueChange.mock.lastCall![0]
|
|
228
|
+
expect(formatColor(picked, 'hex')).toBe('#3b82f6')
|
|
229
|
+
expect(convertColor(picked, 'hsb').space).toBe('hsb')
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
it('names the hidden inputs for form submission', () => {
|
|
233
|
+
render(<ColorArea defaultValue="#ff0000" xName="red" yName="green" />)
|
|
234
|
+
expect(inputs()[0]).toHaveAttribute('name', 'red')
|
|
235
|
+
expect(inputs()[1]).toHaveAttribute('name', 'green')
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
it('has no accessibility violations', async () => {
|
|
239
|
+
const { container } = render(<ColorArea defaultValue="hsb(0, 50%, 50%)" aria-label="Background color" />)
|
|
240
|
+
expect(await axe(container)).toHaveNoViolations()
|
|
241
|
+
})
|
|
242
|
+
})
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { cn } from '../../internal/utils'
|
|
5
|
+
import { useDirection } from '../../hooks/use-direction'
|
|
6
|
+
import {
|
|
7
|
+
COLOR_CONTROL_GROUP,
|
|
8
|
+
type ColorControlSpace,
|
|
9
|
+
colorControlRootClasses,
|
|
10
|
+
colorControlSurfaceClasses,
|
|
11
|
+
colorControlThumbClasses,
|
|
12
|
+
resolveControlSpace,
|
|
13
|
+
snapToStep,
|
|
14
|
+
} from '../../internal/color-control'
|
|
15
|
+
import { useColorControl } from '../../internal/color-picker-context'
|
|
16
|
+
import {
|
|
17
|
+
type Color,
|
|
18
|
+
type ColorChannel,
|
|
19
|
+
convertColor,
|
|
20
|
+
formatChannelValue,
|
|
21
|
+
formatColor,
|
|
22
|
+
getChannelName,
|
|
23
|
+
getChannelRange,
|
|
24
|
+
getChannelValue,
|
|
25
|
+
getColorChannels,
|
|
26
|
+
getColorSpaceAxes,
|
|
27
|
+
parseColor,
|
|
28
|
+
withChannelValue,
|
|
29
|
+
} from '../../lib/color'
|
|
30
|
+
|
|
31
|
+
const DEFAULT_VALUE = '#ffffff'
|
|
32
|
+
|
|
33
|
+
interface PlaneProps {
|
|
34
|
+
space: ColorControlSpace
|
|
35
|
+
xChannel: ColorChannel
|
|
36
|
+
yChannel: ColorChannel
|
|
37
|
+
zChannel: ColorChannel
|
|
38
|
+
zValue: number
|
|
39
|
+
mirrored: boolean
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function gradientBackground({
|
|
43
|
+
space,
|
|
44
|
+
xChannel,
|
|
45
|
+
yChannel,
|
|
46
|
+
zChannel,
|
|
47
|
+
zValue,
|
|
48
|
+
mirrored,
|
|
49
|
+
}: PlaneProps): React.CSSProperties {
|
|
50
|
+
const end = mirrored ? 'left' : 'right'
|
|
51
|
+
|
|
52
|
+
if (space === 'rgb') {
|
|
53
|
+
const black = parseColor('rgb(0, 0, 0)')
|
|
54
|
+
const only = (channel: ColorChannel, value: number) => formatColor(withChannelValue(black, channel, value))
|
|
55
|
+
return {
|
|
56
|
+
// `screen` multiplies the inverses, so one channel per layer recombines them.
|
|
57
|
+
backgroundImage: [
|
|
58
|
+
`linear-gradient(to ${end}, ${only(xChannel, 0)}, ${only(xChannel, 255)})`,
|
|
59
|
+
`linear-gradient(to top, ${only(yChannel, 0)}, ${only(yChannel, 255)})`,
|
|
60
|
+
`linear-gradient(${only(zChannel, zValue)}, ${only(zChannel, zValue)})`,
|
|
61
|
+
].join(', '),
|
|
62
|
+
backgroundBlendMode: 'screen',
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const base = withChannelValue(
|
|
67
|
+
parseColor(space === 'hsl' ? 'hsl(0, 100%, 50%)' : 'hsb(0, 100%, 100%)'),
|
|
68
|
+
zChannel,
|
|
69
|
+
zValue,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
const stops = (channel: ColorChannel): string => {
|
|
73
|
+
switch (channel) {
|
|
74
|
+
case 'hue':
|
|
75
|
+
return [0, 60, 120, 180, 240, 300, 360].map((hue) => formatColor(withChannelValue(base, 'hue', hue))).join(', ')
|
|
76
|
+
case 'saturation':
|
|
77
|
+
return `${formatColor(withChannelValue(base, 'saturation', 0))}, transparent`
|
|
78
|
+
case 'lightness':
|
|
79
|
+
return 'black, transparent, white'
|
|
80
|
+
default:
|
|
81
|
+
return 'black, transparent'
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Later layers paint underneath: the vertical one goes first so the horizontal
|
|
86
|
+
// one shows through where it fades to transparent.
|
|
87
|
+
const layers = [`linear-gradient(to top, ${stops(yChannel)})`, `linear-gradient(to ${end}, ${stops(xChannel)})`]
|
|
88
|
+
if (zChannel === 'hue') layers.push(`linear-gradient(${formatColor(base)}, ${formatColor(base)})`)
|
|
89
|
+
|
|
90
|
+
return { backgroundImage: layers.join(', ') }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const rootClasses = `${COLOR_CONTROL_GROUP} ${colorControlRootClasses} size-56 rounded-lg`
|
|
94
|
+
|
|
95
|
+
interface ColorAreaProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'color' | 'defaultValue' | 'onChange'> {
|
|
96
|
+
/**
|
|
97
|
+
* Selected color. Pass a `Color` or any CSS color string to control the component.
|
|
98
|
+
* Inside a `ColorPicker` it can be left off: the control then reads and writes the
|
|
99
|
+
* picker's color.
|
|
100
|
+
*/
|
|
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. */
|
|
108
|
+
onValueChange?: (value: Color) => void
|
|
109
|
+
/** Fires once a drag ends or a key press settles, with the color that was landed on. */
|
|
110
|
+
onValueCommitted?: (value: Color) => void
|
|
111
|
+
/**
|
|
112
|
+
* Color space the axes operate in. Defaults to the space of the value, so a color
|
|
113
|
+
* parsed from `hsl(...)` gives an HSL area and a hex one gives an RGB area. The
|
|
114
|
+
* space is independent of the format you store: convert on the way out.
|
|
115
|
+
*/
|
|
116
|
+
colorSpace?: ColorControlSpace
|
|
117
|
+
/**
|
|
118
|
+
* Channel mapped to the horizontal axis. Defaults to the first channel of the color
|
|
119
|
+
* space that `yChannel` has not taken.
|
|
120
|
+
*/
|
|
121
|
+
xChannel?: ColorChannel
|
|
122
|
+
/**
|
|
123
|
+
* Channel mapped to the vertical axis, increasing upwards. Defaults to the first
|
|
124
|
+
* channel of the color space left free by `xChannel`.
|
|
125
|
+
*/
|
|
126
|
+
yChannel?: ColorChannel
|
|
127
|
+
/**
|
|
128
|
+
* Prevent interaction and dim the area.
|
|
129
|
+
* @default false
|
|
130
|
+
*/
|
|
131
|
+
disabled?: boolean
|
|
132
|
+
/** Name of the hidden horizontal input, used when submitting an HTML form. */
|
|
133
|
+
xName?: string
|
|
134
|
+
/** Name of the hidden vertical input, used when submitting an HTML form. */
|
|
135
|
+
yName?: string
|
|
136
|
+
/** `id` of the `<form>` the hidden inputs belong to, when they sit outside it. */
|
|
137
|
+
form?: string
|
|
138
|
+
/** Props for the thumb element, for styling or a test id. */
|
|
139
|
+
thumbProps?: React.ComponentPropsWithoutRef<'span'>
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function ColorArea({
|
|
143
|
+
value,
|
|
144
|
+
defaultValue = DEFAULT_VALUE,
|
|
145
|
+
onValueChange,
|
|
146
|
+
onValueCommitted,
|
|
147
|
+
colorSpace,
|
|
148
|
+
xChannel: xChannelProp,
|
|
149
|
+
yChannel: yChannelProp,
|
|
150
|
+
disabled: disabledProp,
|
|
151
|
+
xName,
|
|
152
|
+
yName,
|
|
153
|
+
form,
|
|
154
|
+
thumbProps,
|
|
155
|
+
className,
|
|
156
|
+
children,
|
|
157
|
+
'aria-label': ariaLabel = 'Color picker',
|
|
158
|
+
...props
|
|
159
|
+
}: ColorAreaProps) {
|
|
160
|
+
const mirrored = useDirection() === 'rtl'
|
|
161
|
+
|
|
162
|
+
const containerRef = React.useRef<HTMLDivElement>(null)
|
|
163
|
+
const xInputRef = React.useRef<HTMLInputElement>(null)
|
|
164
|
+
const yInputRef = React.useRef<HTMLInputElement>(null)
|
|
165
|
+
|
|
166
|
+
const [dragging, setDragging] = React.useState(false)
|
|
167
|
+
const [focusedAxis, setFocusedAxis] = React.useState<'x' | 'y'>('x')
|
|
168
|
+
|
|
169
|
+
const control = useColorControl({ value, defaultValue, onValueChange, onValueCommitted, disabled: disabledProp })
|
|
170
|
+
const disabled = control.disabled
|
|
171
|
+
const space = resolveControlSpace(control.color.space, undefined, colorSpace)
|
|
172
|
+
const color = convertColor(control.color, space)
|
|
173
|
+
|
|
174
|
+
const { xChannel, yChannel, zChannel } = getColorSpaceAxes(space, {
|
|
175
|
+
xChannel: xChannelProp,
|
|
176
|
+
yChannel: yChannelProp,
|
|
177
|
+
})
|
|
178
|
+
const xRange = getChannelRange(space, xChannel)
|
|
179
|
+
const yRange = getChannelRange(space, yChannel)
|
|
180
|
+
const xValue = getChannelValue(color, xChannel)
|
|
181
|
+
const yValue = getChannelValue(color, yChannel)
|
|
182
|
+
const zValue = getChannelValue(color, zChannel)
|
|
183
|
+
|
|
184
|
+
const latestRef = React.useRef<Color>(color)
|
|
185
|
+
latestRef.current = color
|
|
186
|
+
|
|
187
|
+
const setColor = (next: Color) => {
|
|
188
|
+
latestRef.current = next
|
|
189
|
+
control.setColor(next)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const setChannel = (channel: ColorChannel, next: number) => {
|
|
193
|
+
const range = getChannelRange(space, channel)
|
|
194
|
+
const snapped = snapToStep(next, range.minValue, range.maxValue, range.step)
|
|
195
|
+
if (snapped === getChannelValue(latestRef.current, channel)) return
|
|
196
|
+
setColor(withChannelValue(latestRef.current, channel, snapped))
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const setFromPoint = (clientX: number, clientY: number) => {
|
|
200
|
+
const rect = containerRef.current?.getBoundingClientRect()
|
|
201
|
+
if (!rect?.width || !rect.height) return
|
|
202
|
+
|
|
203
|
+
const ratioX = (clientX - rect.left) / rect.width
|
|
204
|
+
const x = Math.min(Math.max(mirrored ? 1 - ratioX : ratioX, 0), 1)
|
|
205
|
+
const y = Math.min(Math.max((clientY - rect.top) / rect.height, 0), 1)
|
|
206
|
+
|
|
207
|
+
const nextX = snapToStep(
|
|
208
|
+
xRange.minValue + x * (xRange.maxValue - xRange.minValue),
|
|
209
|
+
xRange.minValue,
|
|
210
|
+
xRange.maxValue,
|
|
211
|
+
xRange.step,
|
|
212
|
+
)
|
|
213
|
+
const nextY = snapToStep(
|
|
214
|
+
yRange.minValue + (1 - y) * (yRange.maxValue - yRange.minValue),
|
|
215
|
+
yRange.minValue,
|
|
216
|
+
yRange.maxValue,
|
|
217
|
+
yRange.step,
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
const current = latestRef.current
|
|
221
|
+
if (nextX === getChannelValue(current, xChannel) && nextY === getChannelValue(current, yChannel)) return
|
|
222
|
+
setColor(withChannelValue(withChannelValue(current, xChannel, nextX), yChannel, nextY))
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const handlePointerDown = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
226
|
+
if (disabled || event.button !== 0) return
|
|
227
|
+
setDragging(true)
|
|
228
|
+
setFromPoint(event.clientX, event.clientY)
|
|
229
|
+
xInputRef.current?.focus({ preventScroll: true })
|
|
230
|
+
try {
|
|
231
|
+
// Capture last: it throws when the pointer is already gone, by which point the
|
|
232
|
+
// press has been applied and a failure only costs tracking outside the element.
|
|
233
|
+
event.currentTarget.setPointerCapture(event.pointerId)
|
|
234
|
+
} catch {}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const handlePointerMove = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
238
|
+
if (dragging) setFromPoint(event.clientX, event.clientY)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const endDrag = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
242
|
+
if (!dragging) return
|
|
243
|
+
if (event.currentTarget.hasPointerCapture?.(event.pointerId)) {
|
|
244
|
+
event.currentTarget.releasePointerCapture(event.pointerId)
|
|
245
|
+
}
|
|
246
|
+
setDragging(false)
|
|
247
|
+
control.commitColor(latestRef.current)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
251
|
+
if (disabled) return
|
|
252
|
+
const xStep = event.shiftKey ? xRange.pageSize : xRange.step
|
|
253
|
+
const yStep = event.shiftKey ? yRange.pageSize : yRange.step
|
|
254
|
+
const sign = mirrored ? -1 : 1
|
|
255
|
+
|
|
256
|
+
const moves: Record<string, [ColorChannel, number, 'x' | 'y'] | undefined> = {
|
|
257
|
+
ArrowLeft: [xChannel, -sign * xStep, 'x'],
|
|
258
|
+
ArrowRight: [xChannel, sign * xStep, 'x'],
|
|
259
|
+
ArrowUp: [yChannel, yStep, 'y'],
|
|
260
|
+
ArrowDown: [yChannel, -yStep, 'y'],
|
|
261
|
+
PageUp: [yChannel, yRange.pageSize, 'y'],
|
|
262
|
+
PageDown: [yChannel, -yRange.pageSize, 'y'],
|
|
263
|
+
Home: [xChannel, -sign * xRange.pageSize, 'x'],
|
|
264
|
+
End: [xChannel, sign * xRange.pageSize, 'x'],
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const move = moves[event.key]
|
|
268
|
+
if (!move) return
|
|
269
|
+
event.preventDefault()
|
|
270
|
+
const [channel, delta, axis] = move
|
|
271
|
+
setChannel(channel, getChannelValue(latestRef.current, channel) + delta)
|
|
272
|
+
setFocusedAxis(axis)
|
|
273
|
+
;(axis === 'x' ? xInputRef : yInputRef).current?.focus({ preventScroll: true })
|
|
274
|
+
control.commitColor(latestRef.current)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const background = React.useMemo(
|
|
278
|
+
() => gradientBackground({ space, xChannel, yChannel, zChannel, zValue, mirrored }),
|
|
279
|
+
[space, xChannel, yChannel, zChannel, zValue, mirrored],
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
const valueText = getColorChannels(space)
|
|
283
|
+
.map((channel) => `${getChannelName(channel)} ${formatChannelValue(color, channel)}`)
|
|
284
|
+
.join(', ')
|
|
285
|
+
|
|
286
|
+
const state = {
|
|
287
|
+
'data-disabled': disabled ? '' : undefined,
|
|
288
|
+
'data-dragging': dragging ? '' : undefined,
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const axisInputProps = (axis: 'x' | 'y') => {
|
|
292
|
+
const channel = axis === 'x' ? xChannel : yChannel
|
|
293
|
+
const range = axis === 'x' ? xRange : yRange
|
|
294
|
+
return {
|
|
295
|
+
type: 'range' as const,
|
|
296
|
+
className: 'sr-only',
|
|
297
|
+
form,
|
|
298
|
+
disabled,
|
|
299
|
+
name: axis === 'x' ? xName : yName,
|
|
300
|
+
min: range.minValue,
|
|
301
|
+
max: range.maxValue,
|
|
302
|
+
step: range.step,
|
|
303
|
+
value: axis === 'x' ? xValue : yValue,
|
|
304
|
+
tabIndex: focusedAxis === axis ? 0 : -1,
|
|
305
|
+
'aria-label': `${ariaLabel}, ${getChannelName(channel)}`,
|
|
306
|
+
'aria-valuetext': valueText,
|
|
307
|
+
'aria-orientation': axis === 'x' ? ('horizontal' as const) : ('vertical' as const),
|
|
308
|
+
'aria-roledescription': 'two-dimensional slider',
|
|
309
|
+
onFocus: () => setFocusedAxis(axis),
|
|
310
|
+
onKeyDown: handleKeyDown,
|
|
311
|
+
onChange: (event: React.ChangeEvent<HTMLInputElement>) =>
|
|
312
|
+
setChannel(channel, Number.parseFloat(event.target.value)),
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return (
|
|
317
|
+
<div
|
|
318
|
+
ref={containerRef}
|
|
319
|
+
role="group"
|
|
320
|
+
aria-label={ariaLabel}
|
|
321
|
+
{...props}
|
|
322
|
+
data-slot="color-area"
|
|
323
|
+
data-space={space}
|
|
324
|
+
{...state}
|
|
325
|
+
className={cn(rootClasses, className)}
|
|
326
|
+
style={{ ...(disabled ? undefined : background), ...props.style }}
|
|
327
|
+
onPointerDown={handlePointerDown}
|
|
328
|
+
onPointerMove={handlePointerMove}
|
|
329
|
+
onPointerUp={endDrag}
|
|
330
|
+
onPointerCancel={endDrag}
|
|
331
|
+
>
|
|
332
|
+
<span data-slot="color-area-surface" aria-hidden="true" className={colorControlSurfaceClasses} />
|
|
333
|
+
|
|
334
|
+
<input ref={xInputRef} {...axisInputProps('x')} />
|
|
335
|
+
<input ref={yInputRef} {...axisInputProps('y')} />
|
|
336
|
+
|
|
337
|
+
<span
|
|
338
|
+
data-slot="color-area-thumb"
|
|
339
|
+
{...state}
|
|
340
|
+
{...thumbProps}
|
|
341
|
+
className={cn(colorControlThumbClasses, thumbProps?.className)}
|
|
342
|
+
style={{
|
|
343
|
+
insetInlineStart: `${((xValue - xRange.minValue) / (xRange.maxValue - xRange.minValue)) * 100}%`,
|
|
344
|
+
top: `${(1 - (yValue - yRange.minValue) / (yRange.maxValue - yRange.minValue)) * 100}%`,
|
|
345
|
+
backgroundColor: disabled ? undefined : formatColor(withChannelValue(color, 'alpha', 1)),
|
|
346
|
+
...thumbProps?.style,
|
|
347
|
+
}}
|
|
348
|
+
/>
|
|
349
|
+
|
|
350
|
+
{children}
|
|
351
|
+
</div>
|
|
352
|
+
)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export { ColorArea }
|
|
356
|
+
export type { ColorAreaProps }
|