@pickle-ui/react 0.0.0-stage → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +490 -2
- package/dist/components/Alert.d.ts +38 -0
- package/dist/components/Alert.d.ts.map +1 -0
- package/dist/components/Alert.js +54 -0
- package/dist/components/Alert.js.map +1 -0
- package/dist/components/AlertDialog.d.ts +41 -0
- package/dist/components/AlertDialog.d.ts.map +1 -0
- package/dist/components/AlertDialog.js +47 -0
- package/dist/components/AlertDialog.js.map +1 -0
- package/dist/components/Avatar.d.ts +18 -0
- package/dist/components/Avatar.d.ts.map +1 -0
- package/dist/components/Avatar.js +34 -0
- package/dist/components/Avatar.js.map +1 -0
- package/dist/components/Badge.d.ts +12 -0
- package/dist/components/Badge.d.ts.map +1 -0
- package/dist/components/Badge.js +37 -0
- package/dist/components/Badge.js.map +1 -0
- package/dist/components/Button.d.ts +19 -0
- package/dist/components/Button.d.ts.map +1 -0
- package/dist/components/Button.js +66 -0
- package/dist/components/Button.js.map +1 -0
- package/dist/components/Card.d.ts +27 -0
- package/dist/components/Card.d.ts.map +1 -0
- package/dist/components/Card.js +34 -0
- package/dist/components/Card.js.map +1 -0
- package/dist/components/Dialog.d.ts +38 -0
- package/dist/components/Dialog.d.ts.map +1 -0
- package/dist/components/Dialog.js +41 -0
- package/dist/components/Dialog.js.map +1 -0
- package/dist/components/Flex.d.ts +22 -0
- package/dist/components/Flex.d.ts.map +1 -0
- package/dist/components/Flex.js +20 -0
- package/dist/components/Flex.js.map +1 -0
- package/dist/components/Grid.d.ts +66 -0
- package/dist/components/Grid.d.ts.map +1 -0
- package/dist/components/Grid.js +63 -0
- package/dist/components/Grid.js.map +1 -0
- package/dist/components/Group.d.ts +20 -0
- package/dist/components/Group.d.ts.map +1 -0
- package/dist/components/Group.js +43 -0
- package/dist/components/Group.js.map +1 -0
- package/dist/components/Menu.d.ts +53 -0
- package/dist/components/Menu.d.ts.map +1 -0
- package/dist/components/Menu.js +78 -0
- package/dist/components/Menu.js.map +1 -0
- package/dist/components/Popover.d.ts +27 -0
- package/dist/components/Popover.d.ts.map +1 -0
- package/dist/components/Popover.js +34 -0
- package/dist/components/Popover.js.map +1 -0
- package/dist/components/Progress.d.ts +23 -0
- package/dist/components/Progress.d.ts.map +1 -0
- package/dist/components/Progress.js +26 -0
- package/dist/components/Progress.js.map +1 -0
- package/dist/components/ScrollArea.d.ts +32 -0
- package/dist/components/ScrollArea.d.ts.map +1 -0
- package/dist/components/ScrollArea.js +36 -0
- package/dist/components/ScrollArea.js.map +1 -0
- package/dist/components/Separator.d.ts +7 -0
- package/dist/components/Separator.d.ts.map +1 -0
- package/dist/components/Separator.js +8 -0
- package/dist/components/Separator.js.map +1 -0
- package/dist/components/Sidebar.d.ts +35 -0
- package/dist/components/Sidebar.d.ts.map +1 -0
- package/dist/components/Sidebar.js +45 -0
- package/dist/components/Sidebar.js.map +1 -0
- package/dist/components/Spinner.d.ts +11 -0
- package/dist/components/Spinner.d.ts.map +1 -0
- package/dist/components/Spinner.js +13 -0
- package/dist/components/Spinner.js.map +1 -0
- package/dist/components/Table.d.ts +32 -0
- package/dist/components/Table.d.ts.map +1 -0
- package/dist/components/Table.js +37 -0
- package/dist/components/Table.js.map +1 -0
- package/dist/components/Text.d.ts +14 -0
- package/dist/components/Text.d.ts.map +1 -0
- package/dist/components/Text.js +50 -0
- package/dist/components/Text.js.map +1 -0
- package/dist/components/Toast.d.ts +39 -0
- package/dist/components/Toast.d.ts.map +1 -0
- package/dist/components/Toast.js +97 -0
- package/dist/components/Toast.js.map +1 -0
- package/dist/components/Tooltip.d.ts +18 -0
- package/dist/components/Tooltip.d.ts.map +1 -0
- package/dist/components/Tooltip.js +22 -0
- package/dist/components/Tooltip.js.map +1 -0
- package/dist/components/XStack.d.ts +6 -0
- package/dist/components/XStack.d.ts.map +1 -0
- package/dist/components/XStack.js +8 -0
- package/dist/components/XStack.js.map +1 -0
- package/dist/components/YStack.d.ts +6 -0
- package/dist/components/YStack.d.ts.map +1 -0
- package/dist/components/YStack.js +8 -0
- package/dist/components/YStack.js.map +1 -0
- package/dist/components/_internal/VisuallyHiddenInput.d.ts +11 -0
- package/dist/components/_internal/VisuallyHiddenInput.d.ts.map +1 -0
- package/dist/components/_internal/VisuallyHiddenInput.js +105 -0
- package/dist/components/_internal/VisuallyHiddenInput.js.map +1 -0
- package/dist/components/_internal/dialog-styles.d.ts +15 -0
- package/dist/components/_internal/dialog-styles.d.ts.map +1 -0
- package/dist/components/_internal/dialog-styles.js +27 -0
- package/dist/components/_internal/dialog-styles.js.map +1 -0
- package/dist/components/_internal/layout.d.ts +46 -0
- package/dist/components/_internal/layout.d.ts.map +1 -0
- package/dist/components/_internal/layout.js +72 -0
- package/dist/components/_internal/layout.js.map +1 -0
- package/dist/components/form/Checkbox.d.ts +19 -0
- package/dist/components/form/Checkbox.d.ts.map +1 -0
- package/dist/components/form/Checkbox.js +27 -0
- package/dist/components/form/Checkbox.js.map +1 -0
- package/dist/components/form/ColorPicker.d.ts +25 -0
- package/dist/components/form/ColorPicker.d.ts.map +1 -0
- package/dist/components/form/ColorPicker.js +14 -0
- package/dist/components/form/ColorPicker.js.map +1 -0
- package/dist/components/form/ColorPickerPrimitive.d.ts +65 -0
- package/dist/components/form/ColorPickerPrimitive.d.ts.map +1 -0
- package/dist/components/form/ColorPickerPrimitive.js +486 -0
- package/dist/components/form/ColorPickerPrimitive.js.map +1 -0
- package/dist/components/form/Combobox.d.ts +86 -0
- package/dist/components/form/Combobox.d.ts.map +1 -0
- package/dist/components/form/Combobox.js +198 -0
- package/dist/components/form/Combobox.js.map +1 -0
- package/dist/components/form/Form.context.d.ts +28 -0
- package/dist/components/form/Form.context.d.ts.map +1 -0
- package/dist/components/form/Form.context.js +56 -0
- package/dist/components/form/Form.context.js.map +1 -0
- package/dist/components/form/Form.d.ts +68 -0
- package/dist/components/form/Form.d.ts.map +1 -0
- package/dist/components/form/Form.js +32 -0
- package/dist/components/form/Form.js.map +1 -0
- package/dist/components/form/FormCheckbox.d.ts +10 -0
- package/dist/components/form/FormCheckbox.d.ts.map +1 -0
- package/dist/components/form/FormCheckbox.js +24 -0
- package/dist/components/form/FormCheckbox.js.map +1 -0
- package/dist/components/form/FormCombobox.d.ts +28 -0
- package/dist/components/form/FormCombobox.d.ts.map +1 -0
- package/dist/components/form/FormCombobox.js +50 -0
- package/dist/components/form/FormCombobox.js.map +1 -0
- package/dist/components/form/FormDescription.d.ts +7 -0
- package/dist/components/form/FormDescription.d.ts.map +1 -0
- package/dist/components/form/FormDescription.js +9 -0
- package/dist/components/form/FormDescription.js.map +1 -0
- package/dist/components/form/FormError.d.ts +7 -0
- package/dist/components/form/FormError.d.ts.map +1 -0
- package/dist/components/form/FormError.js +9 -0
- package/dist/components/form/FormError.js.map +1 -0
- package/dist/components/form/FormField.d.ts +13 -0
- package/dist/components/form/FormField.d.ts.map +1 -0
- package/dist/components/form/FormField.js +45 -0
- package/dist/components/form/FormField.js.map +1 -0
- package/dist/components/form/FormInput.d.ts +8 -0
- package/dist/components/form/FormInput.d.ts.map +1 -0
- package/dist/components/form/FormInput.js +17 -0
- package/dist/components/form/FormInput.js.map +1 -0
- package/dist/components/form/FormInputGroup.d.ts +7 -0
- package/dist/components/form/FormInputGroup.d.ts.map +1 -0
- package/dist/components/form/FormInputGroup.js +30 -0
- package/dist/components/form/FormInputGroup.js.map +1 -0
- package/dist/components/form/FormLabel.d.ts +7 -0
- package/dist/components/form/FormLabel.d.ts.map +1 -0
- package/dist/components/form/FormLabel.js +9 -0
- package/dist/components/form/FormLabel.js.map +1 -0
- package/dist/components/form/FormRadioGroup.d.ts +14 -0
- package/dist/components/form/FormRadioGroup.d.ts.map +1 -0
- package/dist/components/form/FormRadioGroup.js +25 -0
- package/dist/components/form/FormRadioGroup.js.map +1 -0
- package/dist/components/form/FormRoot.d.ts +10 -0
- package/dist/components/form/FormRoot.d.ts.map +1 -0
- package/dist/components/form/FormRoot.js +10 -0
- package/dist/components/form/FormRoot.js.map +1 -0
- package/dist/components/form/FormSelect.d.ts +19 -0
- package/dist/components/form/FormSelect.d.ts.map +1 -0
- package/dist/components/form/FormSelect.js +34 -0
- package/dist/components/form/FormSelect.js.map +1 -0
- package/dist/components/form/FormSwitch.d.ts +10 -0
- package/dist/components/form/FormSwitch.d.ts.map +1 -0
- package/dist/components/form/FormSwitch.js +24 -0
- package/dist/components/form/FormSwitch.js.map +1 -0
- package/dist/components/form/FormTextarea.d.ts +8 -0
- package/dist/components/form/FormTextarea.d.ts.map +1 -0
- package/dist/components/form/FormTextarea.js +13 -0
- package/dist/components/form/FormTextarea.js.map +1 -0
- package/dist/components/form/Input.d.ts +14 -0
- package/dist/components/form/Input.d.ts.map +1 -0
- package/dist/components/form/Input.js +22 -0
- package/dist/components/form/Input.js.map +1 -0
- package/dist/components/form/InputGroup.d.ts +26 -0
- package/dist/components/form/InputGroup.d.ts.map +1 -0
- package/dist/components/form/InputGroup.js +58 -0
- package/dist/components/form/InputGroup.js.map +1 -0
- package/dist/components/form/RadioGroup.d.ts +23 -0
- package/dist/components/form/RadioGroup.d.ts.map +1 -0
- package/dist/components/form/RadioGroup.js +30 -0
- package/dist/components/form/RadioGroup.js.map +1 -0
- package/dist/components/form/Select.d.ts +42 -0
- package/dist/components/form/Select.d.ts.map +1 -0
- package/dist/components/form/Select.js +68 -0
- package/dist/components/form/Select.js.map +1 -0
- package/dist/components/form/Slider.d.ts +37 -0
- package/dist/components/form/Slider.d.ts.map +1 -0
- package/dist/components/form/Slider.js +35 -0
- package/dist/components/form/Slider.js.map +1 -0
- package/dist/components/form/Switch.d.ts +23 -0
- package/dist/components/form/Switch.d.ts.map +1 -0
- package/dist/components/form/Switch.js +21 -0
- package/dist/components/form/Switch.js.map +1 -0
- package/dist/components/form/Textarea.d.ts +16 -0
- package/dist/components/form/Textarea.d.ts.map +1 -0
- package/dist/components/form/Textarea.js +12 -0
- package/dist/components/form/Textarea.js.map +1 -0
- package/dist/entries/alert-dialog.d.ts +3 -0
- package/dist/entries/alert-dialog.d.ts.map +1 -0
- package/dist/entries/alert-dialog.js +2 -0
- package/dist/entries/alert-dialog.js.map +1 -0
- package/dist/entries/alert.d.ts +3 -0
- package/dist/entries/alert.d.ts.map +1 -0
- package/dist/entries/alert.js +2 -0
- package/dist/entries/alert.js.map +1 -0
- package/dist/entries/avatar.d.ts +3 -0
- package/dist/entries/avatar.d.ts.map +1 -0
- package/dist/entries/avatar.js +2 -0
- package/dist/entries/avatar.js.map +1 -0
- package/dist/entries/badge.d.ts +3 -0
- package/dist/entries/badge.d.ts.map +1 -0
- package/dist/entries/badge.js +2 -0
- package/dist/entries/badge.js.map +1 -0
- package/dist/entries/button.d.ts +3 -0
- package/dist/entries/button.d.ts.map +1 -0
- package/dist/entries/button.js +2 -0
- package/dist/entries/button.js.map +1 -0
- package/dist/entries/card.d.ts +3 -0
- package/dist/entries/card.d.ts.map +1 -0
- package/dist/entries/card.js +2 -0
- package/dist/entries/card.js.map +1 -0
- package/dist/entries/checkbox.d.ts +3 -0
- package/dist/entries/checkbox.d.ts.map +1 -0
- package/dist/entries/checkbox.js +2 -0
- package/dist/entries/checkbox.js.map +1 -0
- package/dist/entries/cn.d.ts +3 -0
- package/dist/entries/cn.d.ts.map +1 -0
- package/dist/entries/cn.js +2 -0
- package/dist/entries/cn.js.map +1 -0
- package/dist/entries/color-picker.d.ts +3 -0
- package/dist/entries/color-picker.d.ts.map +1 -0
- package/dist/entries/color-picker.js +2 -0
- package/dist/entries/color-picker.js.map +1 -0
- package/dist/entries/combobox.d.ts +3 -0
- package/dist/entries/combobox.d.ts.map +1 -0
- package/dist/entries/combobox.js +2 -0
- package/dist/entries/combobox.js.map +1 -0
- package/dist/entries/dialog.d.ts +3 -0
- package/dist/entries/dialog.d.ts.map +1 -0
- package/dist/entries/dialog.js +2 -0
- package/dist/entries/dialog.js.map +1 -0
- package/dist/entries/flex.d.ts +3 -0
- package/dist/entries/flex.d.ts.map +1 -0
- package/dist/entries/flex.js +2 -0
- package/dist/entries/flex.js.map +1 -0
- package/dist/entries/form.d.ts +3 -0
- package/dist/entries/form.d.ts.map +1 -0
- package/dist/entries/form.js +2 -0
- package/dist/entries/form.js.map +1 -0
- package/dist/entries/grid.d.ts +3 -0
- package/dist/entries/grid.d.ts.map +1 -0
- package/dist/entries/grid.js +2 -0
- package/dist/entries/grid.js.map +1 -0
- package/dist/entries/group.d.ts +3 -0
- package/dist/entries/group.d.ts.map +1 -0
- package/dist/entries/group.js +2 -0
- package/dist/entries/group.js.map +1 -0
- package/dist/entries/input-group.d.ts +3 -0
- package/dist/entries/input-group.d.ts.map +1 -0
- package/dist/entries/input-group.js +2 -0
- package/dist/entries/input-group.js.map +1 -0
- package/dist/entries/input.d.ts +3 -0
- package/dist/entries/input.d.ts.map +1 -0
- package/dist/entries/input.js +2 -0
- package/dist/entries/input.js.map +1 -0
- package/dist/entries/menu.d.ts +3 -0
- package/dist/entries/menu.d.ts.map +1 -0
- package/dist/entries/menu.js +2 -0
- package/dist/entries/menu.js.map +1 -0
- package/dist/entries/popover.d.ts +3 -0
- package/dist/entries/popover.d.ts.map +1 -0
- package/dist/entries/popover.js +2 -0
- package/dist/entries/popover.js.map +1 -0
- package/dist/entries/progress.d.ts +3 -0
- package/dist/entries/progress.d.ts.map +1 -0
- package/dist/entries/progress.js +2 -0
- package/dist/entries/progress.js.map +1 -0
- package/dist/entries/radio-group.d.ts +3 -0
- package/dist/entries/radio-group.d.ts.map +1 -0
- package/dist/entries/radio-group.js +2 -0
- package/dist/entries/radio-group.js.map +1 -0
- package/dist/entries/scroll-area.d.ts +3 -0
- package/dist/entries/scroll-area.d.ts.map +1 -0
- package/dist/entries/scroll-area.js +2 -0
- package/dist/entries/scroll-area.js.map +1 -0
- package/dist/entries/select.d.ts +3 -0
- package/dist/entries/select.d.ts.map +1 -0
- package/dist/entries/select.js +2 -0
- package/dist/entries/select.js.map +1 -0
- package/dist/entries/separator.d.ts +3 -0
- package/dist/entries/separator.d.ts.map +1 -0
- package/dist/entries/separator.js +2 -0
- package/dist/entries/separator.js.map +1 -0
- package/dist/entries/sidebar.d.ts +3 -0
- package/dist/entries/sidebar.d.ts.map +1 -0
- package/dist/entries/sidebar.js +2 -0
- package/dist/entries/sidebar.js.map +1 -0
- package/dist/entries/slider.d.ts +3 -0
- package/dist/entries/slider.d.ts.map +1 -0
- package/dist/entries/slider.js +2 -0
- package/dist/entries/slider.js.map +1 -0
- package/dist/entries/spinner.d.ts +3 -0
- package/dist/entries/spinner.d.ts.map +1 -0
- package/dist/entries/spinner.js +2 -0
- package/dist/entries/spinner.js.map +1 -0
- package/dist/entries/switch.d.ts +3 -0
- package/dist/entries/switch.d.ts.map +1 -0
- package/dist/entries/switch.js +2 -0
- package/dist/entries/switch.js.map +1 -0
- package/dist/entries/table.d.ts +3 -0
- package/dist/entries/table.d.ts.map +1 -0
- package/dist/entries/table.js +2 -0
- package/dist/entries/table.js.map +1 -0
- package/dist/entries/text.d.ts +3 -0
- package/dist/entries/text.d.ts.map +1 -0
- package/dist/entries/text.js +2 -0
- package/dist/entries/text.js.map +1 -0
- package/dist/entries/textarea.d.ts +3 -0
- package/dist/entries/textarea.d.ts.map +1 -0
- package/dist/entries/textarea.js +2 -0
- package/dist/entries/textarea.js.map +1 -0
- package/dist/entries/theme.d.ts +3 -0
- package/dist/entries/theme.d.ts.map +1 -0
- package/dist/entries/theme.js +2 -0
- package/dist/entries/theme.js.map +1 -0
- package/dist/entries/toast.d.ts +3 -0
- package/dist/entries/toast.d.ts.map +1 -0
- package/dist/entries/toast.js +2 -0
- package/dist/entries/toast.js.map +1 -0
- package/dist/entries/tooltip.d.ts +3 -0
- package/dist/entries/tooltip.d.ts.map +1 -0
- package/dist/entries/tooltip.js +2 -0
- package/dist/entries/tooltip.js.map +1 -0
- package/dist/entries/x-stack.d.ts +3 -0
- package/dist/entries/x-stack.d.ts.map +1 -0
- package/dist/entries/x-stack.js +2 -0
- package/dist/entries/x-stack.js.map +1 -0
- package/dist/entries/y-stack.d.ts +3 -0
- package/dist/entries/y-stack.d.ts.map +1 -0
- package/dist/entries/y-stack.js +2 -0
- package/dist/entries/y-stack.js.map +1 -0
- package/dist/hooks/use-as-ref.d.ts +4 -0
- package/dist/hooks/use-as-ref.d.ts.map +1 -0
- package/dist/hooks/use-as-ref.js +11 -0
- package/dist/hooks/use-as-ref.js.map +1 -0
- package/dist/hooks/use-isomorphic-layout-effect.d.ts +4 -0
- package/dist/hooks/use-isomorphic-layout-effect.d.ts.map +1 -0
- package/dist/hooks/use-isomorphic-layout-effect.js +4 -0
- package/dist/hooks/use-isomorphic-layout-effect.js.map +1 -0
- package/dist/hooks/use-lazy-ref.d.ts +4 -0
- package/dist/hooks/use-lazy-ref.d.ts.map +1 -0
- package/dist/hooks/use-lazy-ref.js +10 -0
- package/dist/hooks/use-lazy-ref.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/color.d.ts +42 -0
- package/dist/lib/color.d.ts.map +1 -0
- package/dist/lib/color.js +140 -0
- package/dist/lib/color.js.map +1 -0
- package/dist/lib/compose-refs.d.ts +14 -0
- package/dist/lib/compose-refs.d.ts.map +1 -0
- package/dist/lib/compose-refs.js +57 -0
- package/dist/lib/compose-refs.js.map +1 -0
- package/dist/lib/theme.d.ts +40 -0
- package/dist/lib/theme.d.ts.map +1 -0
- package/dist/lib/theme.js +82 -0
- package/dist/lib/theme.js.map +1 -0
- package/dist/lib/utils.d.ts +8 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +18 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/test-setup.d.ts +2 -0
- package/dist/test-setup.d.ts.map +1 -0
- package/dist/test-setup.js +2 -0
- package/dist/test-setup.js.map +1 -0
- package/package.json +107 -4
- package/src/base.css +99 -0
- package/src/components/Alert.stories.tsx +124 -0
- package/src/components/Alert.test.tsx +76 -0
- package/src/components/Alert.tsx +133 -0
- package/src/components/AlertDialog.stories.tsx +184 -0
- package/src/components/AlertDialog.test.tsx +142 -0
- package/src/components/AlertDialog.tsx +164 -0
- package/src/components/Avatar.stories.tsx +92 -0
- package/src/components/Avatar.test.tsx +26 -0
- package/src/components/Avatar.tsx +96 -0
- package/src/components/Badge.stories.tsx +52 -0
- package/src/components/Badge.test.tsx +35 -0
- package/src/components/Badge.tsx +65 -0
- package/src/components/Button.stories.tsx +171 -0
- package/src/components/Button.test.tsx +112 -0
- package/src/components/Button.tsx +114 -0
- package/src/components/Card.stories.tsx +62 -0
- package/src/components/Card.test.tsx +23 -0
- package/src/components/Card.tsx +129 -0
- package/src/components/Dialog.stories.tsx +133 -0
- package/src/components/Dialog.test.tsx +95 -0
- package/src/components/Dialog.tsx +147 -0
- package/src/components/Flex.stories.tsx +70 -0
- package/src/components/Flex.test.tsx +53 -0
- package/src/components/Flex.tsx +59 -0
- package/src/components/Grid.stories.tsx +70 -0
- package/src/components/Grid.test.tsx +46 -0
- package/src/components/Grid.tsx +114 -0
- package/src/components/Group.stories.tsx +130 -0
- package/src/components/Group.test.tsx +57 -0
- package/src/components/Group.tsx +92 -0
- package/src/components/Menu.stories.tsx +139 -0
- package/src/components/Menu.test.tsx +103 -0
- package/src/components/Menu.tsx +290 -0
- package/src/components/Popover.stories.tsx +72 -0
- package/src/components/Popover.tsx +117 -0
- package/src/components/Progress.stories.tsx +105 -0
- package/src/components/Progress.test.tsx +28 -0
- package/src/components/Progress.tsx +111 -0
- package/src/components/ScrollArea.stories.tsx +66 -0
- package/src/components/ScrollArea.test.tsx +32 -0
- package/src/components/ScrollArea.tsx +160 -0
- package/src/components/Separator.stories.tsx +39 -0
- package/src/components/Separator.test.tsx +24 -0
- package/src/components/Separator.tsx +27 -0
- package/src/components/Sidebar.stories.tsx +87 -0
- package/src/components/Sidebar.tsx +166 -0
- package/src/components/Spinner.stories.tsx +36 -0
- package/src/components/Spinner.test.tsx +25 -0
- package/src/components/Spinner.tsx +31 -0
- package/src/components/Table.stories.tsx +76 -0
- package/src/components/Table.tsx +151 -0
- package/src/components/Text.stories.tsx +148 -0
- package/src/components/Text.test.tsx +106 -0
- package/src/components/Text.tsx +85 -0
- package/src/components/Toast.stories.tsx +166 -0
- package/src/components/Toast.test.tsx +97 -0
- package/src/components/Toast.tsx +270 -0
- package/src/components/Tooltip.stories.tsx +116 -0
- package/src/components/Tooltip.test.tsx +51 -0
- package/src/components/Tooltip.tsx +80 -0
- package/src/components/XStack.stories.tsx +64 -0
- package/src/components/XStack.test.tsx +33 -0
- package/src/components/XStack.tsx +19 -0
- package/src/components/YStack.stories.tsx +65 -0
- package/src/components/YStack.test.tsx +31 -0
- package/src/components/YStack.tsx +19 -0
- package/src/components/_internal/Story.tsx +161 -0
- package/src/components/_internal/VisuallyHiddenInput.tsx +164 -0
- package/src/components/_internal/dialog-styles.ts +57 -0
- package/src/components/_internal/layout.ts +103 -0
- package/src/components/form/Checkbox.stories.tsx +78 -0
- package/src/components/form/Checkbox.test.tsx +107 -0
- package/src/components/form/Checkbox.tsx +95 -0
- package/src/components/form/ColorPicker.stories.tsx +160 -0
- package/src/components/form/ColorPicker.test.tsx +45 -0
- package/src/components/form/ColorPicker.tsx +55 -0
- package/src/components/form/ColorPickerPrimitive.test.tsx +14 -0
- package/src/components/form/ColorPickerPrimitive.tsx +1283 -0
- package/src/components/form/Combobox.stories.tsx +378 -0
- package/src/components/form/Combobox.test.tsx +334 -0
- package/src/components/form/Combobox.tsx +667 -0
- package/src/components/form/Form.context.ts +114 -0
- package/src/components/form/Form.stories.tsx +226 -0
- package/src/components/form/Form.test.tsx +293 -0
- package/src/components/form/Form.tsx +50 -0
- package/src/components/form/FormCheckbox.tsx +50 -0
- package/src/components/form/FormCombobox.tsx +92 -0
- package/src/components/form/FormDescription.tsx +21 -0
- package/src/components/form/FormError.tsx +21 -0
- package/src/components/form/FormField.tsx +109 -0
- package/src/components/form/FormInput.tsx +41 -0
- package/src/components/form/FormInputGroup.tsx +47 -0
- package/src/components/form/FormLabel.tsx +24 -0
- package/src/components/form/FormRadioGroup.tsx +46 -0
- package/src/components/form/FormRoot.tsx +41 -0
- package/src/components/form/FormSelect.tsx +60 -0
- package/src/components/form/FormSwitch.tsx +50 -0
- package/src/components/form/FormTextarea.tsx +34 -0
- package/src/components/form/Input.stories.tsx +114 -0
- package/src/components/form/Input.test.tsx +62 -0
- package/src/components/form/Input.tsx +93 -0
- package/src/components/form/InputGroup.stories.tsx +162 -0
- package/src/components/form/InputGroup.tsx +149 -0
- package/src/components/form/RadioGroup.stories.tsx +68 -0
- package/src/components/form/RadioGroup.test.tsx +171 -0
- package/src/components/form/RadioGroup.tsx +127 -0
- package/src/components/form/Select.stories.tsx +115 -0
- package/src/components/form/Select.test.tsx +115 -0
- package/src/components/form/Select.tsx +293 -0
- package/src/components/form/Slider.stories.tsx +121 -0
- package/src/components/form/Slider.test.tsx +33 -0
- package/src/components/form/Slider.tsx +200 -0
- package/src/components/form/Switch.stories.tsx +62 -0
- package/src/components/form/Switch.test.tsx +29 -0
- package/src/components/form/Switch.tsx +81 -0
- package/src/components/form/Textarea.stories.tsx +71 -0
- package/src/components/form/Textarea.test.tsx +31 -0
- package/src/components/form/Textarea.tsx +46 -0
- package/src/entries/alert-dialog.ts +11 -0
- package/src/entries/alert.ts +8 -0
- package/src/entries/avatar.ts +7 -0
- package/src/entries/badge.ts +2 -0
- package/src/entries/button.ts +2 -0
- package/src/entries/card.ts +10 -0
- package/src/entries/checkbox.ts +5 -0
- package/src/entries/cn.ts +2 -0
- package/src/entries/color-picker.ts +13 -0
- package/src/entries/combobox.ts +20 -0
- package/src/entries/dialog.ts +11 -0
- package/src/entries/entries.test.ts +65 -0
- package/src/entries/flex.ts +2 -0
- package/src/entries/form.ts +16 -0
- package/src/entries/grid.ts +2 -0
- package/src/entries/group.ts +6 -0
- package/src/entries/input-group.ts +8 -0
- package/src/entries/input.ts +2 -0
- package/src/entries/menu.ts +17 -0
- package/src/entries/popover.ts +10 -0
- package/src/entries/progress.ts +8 -0
- package/src/entries/radio-group.ts +5 -0
- package/src/entries/scroll-area.ts +10 -0
- package/src/entries/select.ts +12 -0
- package/src/entries/separator.ts +2 -0
- package/src/entries/sidebar.ts +13 -0
- package/src/entries/slider.ts +7 -0
- package/src/entries/spinner.ts +2 -0
- package/src/entries/switch.ts +2 -0
- package/src/entries/table.ts +11 -0
- package/src/entries/text.ts +2 -0
- package/src/entries/textarea.ts +2 -0
- package/src/entries/theme.ts +8 -0
- package/src/entries/toast.ts +2 -0
- package/src/entries/tooltip.ts +7 -0
- package/src/entries/x-stack.ts +2 -0
- package/src/entries/y-stack.ts +2 -0
- package/src/hooks/use-as-ref.ts +15 -0
- package/src/hooks/use-isomorphic-layout-effect.ts +6 -0
- package/src/hooks/use-lazy-ref.ts +13 -0
- package/src/index.ts +38 -0
- package/src/lib/color.test.ts +148 -0
- package/src/lib/color.ts +193 -0
- package/src/lib/compose-refs.ts +63 -0
- package/src/lib/theme.test.ts +64 -0
- package/src/lib/theme.ts +143 -0
- package/src/lib/utils.ts +25 -0
- package/src/public-api.test.ts +74 -0
- package/src/styles.css +2 -0
- package/src/test-setup.ts +1 -0
- package/src/theme.css +195 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
import { type ComponentMatrixCellProps, Story } from '../_internal/Story';
|
|
6
|
+
import { Combobox } from './Combobox';
|
|
7
|
+
|
|
8
|
+
const meta = {
|
|
9
|
+
component: Combobox,
|
|
10
|
+
parameters: {
|
|
11
|
+
layout: 'fullscreen',
|
|
12
|
+
},
|
|
13
|
+
title: 'components/form/Combobox',
|
|
14
|
+
} satisfies Meta<typeof Combobox>;
|
|
15
|
+
|
|
16
|
+
export default meta;
|
|
17
|
+
type Fruit = {
|
|
18
|
+
label: string;
|
|
19
|
+
value: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type FruitGroup = {
|
|
23
|
+
items: Fruit[];
|
|
24
|
+
value: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type StoryDefinition = StoryObj<typeof meta>;
|
|
28
|
+
|
|
29
|
+
const FRUITS: Fruit[] = [
|
|
30
|
+
{ label: 'Apple', value: 'apple' },
|
|
31
|
+
{ label: 'Banana', value: 'banana' },
|
|
32
|
+
{ label: 'Blueberry', value: 'blueberry' },
|
|
33
|
+
{ label: 'Cherry', value: 'cherry' },
|
|
34
|
+
{ label: 'Grape', value: 'grape' },
|
|
35
|
+
{ label: 'Kiwi', value: 'kiwi' },
|
|
36
|
+
{ label: 'Mango', value: 'mango' },
|
|
37
|
+
{ label: 'Orange', value: 'orange' },
|
|
38
|
+
{ label: 'Peach', value: 'peach' },
|
|
39
|
+
{ label: 'Pear', value: 'pear' },
|
|
40
|
+
{ label: 'Pineapple', value: 'pineapple' },
|
|
41
|
+
{ label: 'Strawberry', value: 'strawberry' },
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const PRODUCE: FruitGroup[] = [
|
|
45
|
+
{
|
|
46
|
+
items: [
|
|
47
|
+
{ label: 'Apple', value: 'apple' },
|
|
48
|
+
{ label: 'Banana', value: 'banana' },
|
|
49
|
+
{ label: 'Cherry', value: 'cherry' },
|
|
50
|
+
],
|
|
51
|
+
value: 'Fruits',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
items: [
|
|
55
|
+
{ label: 'Carrot', value: 'carrot' },
|
|
56
|
+
{ label: 'Leek', value: 'leek' },
|
|
57
|
+
{ label: 'Spinach', value: 'spinach' },
|
|
58
|
+
],
|
|
59
|
+
value: 'Vegetables',
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
type FruitComboboxStateProps = {
|
|
64
|
+
disabled?: boolean;
|
|
65
|
+
focus?: boolean;
|
|
66
|
+
invalid?: boolean;
|
|
67
|
+
value?: Fruit;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const STATE_COLUMNS: {
|
|
71
|
+
key: string;
|
|
72
|
+
label: string;
|
|
73
|
+
props: FruitComboboxStateProps;
|
|
74
|
+
}[] = [
|
|
75
|
+
{ key: 'placeholder', label: 'Placeholder', props: {} },
|
|
76
|
+
{ key: 'selected', label: 'Selected', props: { value: FRUITS[0] } },
|
|
77
|
+
{
|
|
78
|
+
key: 'focus',
|
|
79
|
+
label: 'Focus',
|
|
80
|
+
props: { focus: true, value: FRUITS[0] },
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
key: 'disabled',
|
|
84
|
+
label: 'Disabled',
|
|
85
|
+
props: { disabled: true, value: FRUITS[0] },
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
key: 'invalid',
|
|
89
|
+
label: 'Invalid',
|
|
90
|
+
props: { invalid: true, value: FRUITS[0] },
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
const STATE_PROPS = Object.fromEntries(
|
|
95
|
+
STATE_COLUMNS.map((state) => [state.key, state.props]),
|
|
96
|
+
) as Record<string, FruitComboboxStateProps>;
|
|
97
|
+
|
|
98
|
+
function ComboboxMatrixCell({ column }: ComponentMatrixCellProps) {
|
|
99
|
+
return <FruitCombobox {...STATE_PROPS[column.key]} />;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function CreatableFruit() {
|
|
103
|
+
const [fruits, setFruits] = React.useState(FRUITS);
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<Combobox
|
|
107
|
+
createLabel={(inputValue) => `Add "${inputValue}" to the list`}
|
|
108
|
+
items={fruits}
|
|
109
|
+
onCreate={(label) => {
|
|
110
|
+
const fruit = { label, value: label.toLowerCase() };
|
|
111
|
+
setFruits((current) => [...current, fruit]);
|
|
112
|
+
|
|
113
|
+
return fruit;
|
|
114
|
+
}}
|
|
115
|
+
>
|
|
116
|
+
<Combobox.Input
|
|
117
|
+
aria-label="Fruit"
|
|
118
|
+
className="w-64"
|
|
119
|
+
placeholder="Type a new fruit…"
|
|
120
|
+
/>
|
|
121
|
+
<Combobox.Content>
|
|
122
|
+
<Combobox.List>
|
|
123
|
+
{(fruit: Fruit) => (
|
|
124
|
+
<Combobox.Item key={fruit.value} value={fruit}>
|
|
125
|
+
{fruit.label}
|
|
126
|
+
</Combobox.Item>
|
|
127
|
+
)}
|
|
128
|
+
</Combobox.List>
|
|
129
|
+
</Combobox.Content>
|
|
130
|
+
</Combobox>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function CreatableTags() {
|
|
135
|
+
const [tags, setTags] = React.useState<Fruit[]>([
|
|
136
|
+
{ label: 'Design', value: 'design' },
|
|
137
|
+
{ label: 'Engineering', value: 'engineering' },
|
|
138
|
+
{ label: 'Marketing', value: 'marketing' },
|
|
139
|
+
]);
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<Combobox
|
|
143
|
+
defaultValue={[tags[0]]}
|
|
144
|
+
items={tags}
|
|
145
|
+
multiple
|
|
146
|
+
onCreate={(label) => {
|
|
147
|
+
const tag = { label, value: label.toLowerCase() };
|
|
148
|
+
setTags((current) => [...current, tag]);
|
|
149
|
+
|
|
150
|
+
return tag;
|
|
151
|
+
}}
|
|
152
|
+
>
|
|
153
|
+
<Combobox.Chips className="w-80">
|
|
154
|
+
<Combobox.Value>
|
|
155
|
+
{(value: Fruit[]) => (
|
|
156
|
+
<>
|
|
157
|
+
{value.map((tag) => (
|
|
158
|
+
<Combobox.Chip key={tag.value}>{tag.label}</Combobox.Chip>
|
|
159
|
+
))}
|
|
160
|
+
<Combobox.ChipsInput
|
|
161
|
+
aria-label="Tags"
|
|
162
|
+
placeholder={value.length > 0 ? '' : 'Add tags…'}
|
|
163
|
+
/>
|
|
164
|
+
</>
|
|
165
|
+
)}
|
|
166
|
+
</Combobox.Value>
|
|
167
|
+
</Combobox.Chips>
|
|
168
|
+
<Combobox.Content>
|
|
169
|
+
<Combobox.List>
|
|
170
|
+
{(tag: Fruit) => (
|
|
171
|
+
<Combobox.Item key={tag.value} value={tag}>
|
|
172
|
+
{tag.label}
|
|
173
|
+
</Combobox.Item>
|
|
174
|
+
)}
|
|
175
|
+
</Combobox.List>
|
|
176
|
+
</Combobox.Content>
|
|
177
|
+
</Combobox>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function FruitCombobox({
|
|
182
|
+
disabled,
|
|
183
|
+
focus,
|
|
184
|
+
invalid,
|
|
185
|
+
value,
|
|
186
|
+
}: FruitComboboxStateProps) {
|
|
187
|
+
return (
|
|
188
|
+
<Combobox defaultValue={value} disabled={disabled} items={FRUITS}>
|
|
189
|
+
<Combobox.Input
|
|
190
|
+
aria-invalid={invalid || undefined}
|
|
191
|
+
aria-label="Fruit"
|
|
192
|
+
className="w-48"
|
|
193
|
+
// Targeted by the pseudo-states parameter below: only the inner
|
|
194
|
+
// <input> gets :focus-visible, not the trigger or clear buttons.
|
|
195
|
+
data-pseudo-focus={focus || undefined}
|
|
196
|
+
placeholder="Select a fruit"
|
|
197
|
+
/>
|
|
198
|
+
<Combobox.Content>
|
|
199
|
+
<Combobox.Empty>No fruit found.</Combobox.Empty>
|
|
200
|
+
<Combobox.List>
|
|
201
|
+
{(fruit: Fruit) => (
|
|
202
|
+
<Combobox.Item key={fruit.value} value={fruit}>
|
|
203
|
+
{fruit.label}
|
|
204
|
+
</Combobox.Item>
|
|
205
|
+
)}
|
|
206
|
+
</Combobox.List>
|
|
207
|
+
</Combobox.Content>
|
|
208
|
+
</Combobox>
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function StartsWithFruit() {
|
|
213
|
+
return (
|
|
214
|
+
<Combobox
|
|
215
|
+
filter={(fruit: Fruit, query) =>
|
|
216
|
+
fruit.label.toLowerCase().startsWith(query.toLowerCase())
|
|
217
|
+
}
|
|
218
|
+
items={FRUITS}
|
|
219
|
+
>
|
|
220
|
+
<Combobox.Input
|
|
221
|
+
aria-label="Fruit (starts with)"
|
|
222
|
+
className="w-64"
|
|
223
|
+
placeholder="Matches the start of names"
|
|
224
|
+
/>
|
|
225
|
+
<Combobox.Content>
|
|
226
|
+
<Combobox.Empty>No fruit starts with that.</Combobox.Empty>
|
|
227
|
+
<Combobox.List>
|
|
228
|
+
{(fruit: Fruit) => (
|
|
229
|
+
<Combobox.Item key={fruit.value} value={fruit}>
|
|
230
|
+
{fruit.label}
|
|
231
|
+
</Combobox.Item>
|
|
232
|
+
)}
|
|
233
|
+
</Combobox.List>
|
|
234
|
+
</Combobox.Content>
|
|
235
|
+
</Combobox>
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export const All: StoryDefinition = {
|
|
240
|
+
parameters: {
|
|
241
|
+
pseudo: { focusVisible: ['[data-pseudo-focus]'] },
|
|
242
|
+
},
|
|
243
|
+
render: () => (
|
|
244
|
+
<Story.Layout className="max-w-5xl" title="Combobox">
|
|
245
|
+
<Story.Section title="States">
|
|
246
|
+
<Story.Matrix
|
|
247
|
+
Cell={ComboboxMatrixCell}
|
|
248
|
+
columns={STATE_COLUMNS}
|
|
249
|
+
rows={[{ key: 'combobox', label: 'Combobox' }]}
|
|
250
|
+
/>
|
|
251
|
+
</Story.Section>
|
|
252
|
+
|
|
253
|
+
<Story.Section title="Label and clear">
|
|
254
|
+
<Combobox defaultValue={FRUITS[6]} items={FRUITS}>
|
|
255
|
+
<div className="flex w-64 flex-col gap-2">
|
|
256
|
+
<label
|
|
257
|
+
className="text-sm leading-none font-medium"
|
|
258
|
+
htmlFor="favorite-fruit"
|
|
259
|
+
>
|
|
260
|
+
Favorite fruit
|
|
261
|
+
</label>
|
|
262
|
+
<Combobox.Input
|
|
263
|
+
id="favorite-fruit"
|
|
264
|
+
placeholder="Search fruits…"
|
|
265
|
+
showClear
|
|
266
|
+
/>
|
|
267
|
+
</div>
|
|
268
|
+
<Combobox.Content>
|
|
269
|
+
<Combobox.Empty>No fruit found.</Combobox.Empty>
|
|
270
|
+
<Combobox.List>
|
|
271
|
+
{(fruit: Fruit) => (
|
|
272
|
+
<Combobox.Item key={fruit.value} value={fruit}>
|
|
273
|
+
{fruit.label}
|
|
274
|
+
</Combobox.Item>
|
|
275
|
+
)}
|
|
276
|
+
</Combobox.List>
|
|
277
|
+
</Combobox.Content>
|
|
278
|
+
</Combobox>
|
|
279
|
+
</Story.Section>
|
|
280
|
+
|
|
281
|
+
<Story.Section title="Sizes">
|
|
282
|
+
<div className="flex flex-wrap items-center gap-4">
|
|
283
|
+
{(['sm', 'md', 'lg'] as const).map((size) => (
|
|
284
|
+
<Combobox items={FRUITS} key={size}>
|
|
285
|
+
<Combobox.Input
|
|
286
|
+
aria-label={`Fruit (${size})`}
|
|
287
|
+
className="w-48"
|
|
288
|
+
placeholder={`Size ${size}`}
|
|
289
|
+
size={size}
|
|
290
|
+
/>
|
|
291
|
+
<Combobox.Content>
|
|
292
|
+
<Combobox.Empty>No fruit found.</Combobox.Empty>
|
|
293
|
+
<Combobox.List>
|
|
294
|
+
{(fruit: Fruit) => (
|
|
295
|
+
<Combobox.Item key={fruit.value} value={fruit}>
|
|
296
|
+
{fruit.label}
|
|
297
|
+
</Combobox.Item>
|
|
298
|
+
)}
|
|
299
|
+
</Combobox.List>
|
|
300
|
+
</Combobox.Content>
|
|
301
|
+
</Combobox>
|
|
302
|
+
))}
|
|
303
|
+
</div>
|
|
304
|
+
</Story.Section>
|
|
305
|
+
|
|
306
|
+
<Story.Section title="Groups">
|
|
307
|
+
<Combobox items={PRODUCE}>
|
|
308
|
+
<Combobox.Input
|
|
309
|
+
aria-label="Produce"
|
|
310
|
+
className="w-64"
|
|
311
|
+
placeholder="Search produce…"
|
|
312
|
+
/>
|
|
313
|
+
<Combobox.Content>
|
|
314
|
+
<Combobox.Empty>Nothing found.</Combobox.Empty>
|
|
315
|
+
<Combobox.List>
|
|
316
|
+
{(group: FruitGroup, index: number) => (
|
|
317
|
+
<Combobox.Group items={group.items} key={group.value}>
|
|
318
|
+
{index > 0 ? <Combobox.Separator /> : null}
|
|
319
|
+
<Combobox.GroupLabel>{group.value}</Combobox.GroupLabel>
|
|
320
|
+
<Combobox.Collection>
|
|
321
|
+
{(item: Fruit) => (
|
|
322
|
+
<Combobox.Item key={item.value} value={item}>
|
|
323
|
+
{item.label}
|
|
324
|
+
</Combobox.Item>
|
|
325
|
+
)}
|
|
326
|
+
</Combobox.Collection>
|
|
327
|
+
</Combobox.Group>
|
|
328
|
+
)}
|
|
329
|
+
</Combobox.List>
|
|
330
|
+
</Combobox.Content>
|
|
331
|
+
</Combobox>
|
|
332
|
+
</Story.Section>
|
|
333
|
+
|
|
334
|
+
<Story.Section title="Multiple">
|
|
335
|
+
<Combobox defaultValue={[FRUITS[0], FRUITS[3]]} items={FRUITS} multiple>
|
|
336
|
+
<Combobox.Chips className="w-80">
|
|
337
|
+
<Combobox.Value>
|
|
338
|
+
{(value: Fruit[]) => (
|
|
339
|
+
<>
|
|
340
|
+
{value.map((fruit) => (
|
|
341
|
+
<Combobox.Chip key={fruit.value}>
|
|
342
|
+
{fruit.label}
|
|
343
|
+
</Combobox.Chip>
|
|
344
|
+
))}
|
|
345
|
+
<Combobox.ChipsInput
|
|
346
|
+
aria-label="Fruits"
|
|
347
|
+
placeholder={value.length > 0 ? '' : 'Select fruits…'}
|
|
348
|
+
/>
|
|
349
|
+
</>
|
|
350
|
+
)}
|
|
351
|
+
</Combobox.Value>
|
|
352
|
+
</Combobox.Chips>
|
|
353
|
+
<Combobox.Content>
|
|
354
|
+
<Combobox.Empty>No fruit found.</Combobox.Empty>
|
|
355
|
+
<Combobox.List>
|
|
356
|
+
{(fruit: Fruit) => (
|
|
357
|
+
<Combobox.Item key={fruit.value} value={fruit}>
|
|
358
|
+
{fruit.label}
|
|
359
|
+
</Combobox.Item>
|
|
360
|
+
)}
|
|
361
|
+
</Combobox.List>
|
|
362
|
+
</Combobox.Content>
|
|
363
|
+
</Combobox>
|
|
364
|
+
</Story.Section>
|
|
365
|
+
|
|
366
|
+
<Story.Section title="Custom filter">
|
|
367
|
+
<StartsWithFruit />
|
|
368
|
+
</Story.Section>
|
|
369
|
+
|
|
370
|
+
<Story.Section title="Creatable">
|
|
371
|
+
<div className="flex flex-wrap items-start gap-4">
|
|
372
|
+
<CreatableFruit />
|
|
373
|
+
<CreatableTags />
|
|
374
|
+
</div>
|
|
375
|
+
</Story.Section>
|
|
376
|
+
</Story.Layout>
|
|
377
|
+
),
|
|
378
|
+
};
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
|
|
5
|
+
import { Combobox } from './Combobox';
|
|
6
|
+
|
|
7
|
+
type Fruit = { label: string; value: string };
|
|
8
|
+
|
|
9
|
+
const FRUITS: Fruit[] = [
|
|
10
|
+
{ label: 'Apple', value: 'apple' },
|
|
11
|
+
{ label: 'Banana', value: 'banana' },
|
|
12
|
+
{ label: 'Cherry', value: 'cherry' },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
function renderList() {
|
|
16
|
+
return (
|
|
17
|
+
<Combobox.Content>
|
|
18
|
+
<Combobox.Empty>No fruit found.</Combobox.Empty>
|
|
19
|
+
<Combobox.List>
|
|
20
|
+
{(fruit: Fruit) => (
|
|
21
|
+
<Combobox.Item key={fruit.value} value={fruit}>
|
|
22
|
+
{fruit.label}
|
|
23
|
+
</Combobox.Item>
|
|
24
|
+
)}
|
|
25
|
+
</Combobox.List>
|
|
26
|
+
</Combobox.Content>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('Combobox', () => {
|
|
31
|
+
it('shows the selected item label in the input', () => {
|
|
32
|
+
render(
|
|
33
|
+
<Combobox defaultValue={FRUITS[1]} items={FRUITS}>
|
|
34
|
+
<Combobox.Input aria-label="Fruit" />
|
|
35
|
+
{renderList()}
|
|
36
|
+
</Combobox>,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect(screen.getByRole('combobox', { name: 'Fruit' })).toHaveValue(
|
|
40
|
+
'Banana',
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('filters items as the user types', () => {
|
|
45
|
+
render(
|
|
46
|
+
<Combobox defaultOpen items={FRUITS}>
|
|
47
|
+
<Combobox.Input aria-label="Fruit" />
|
|
48
|
+
{renderList()}
|
|
49
|
+
</Combobox>,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
fireEvent.change(screen.getByRole('combobox', { name: 'Fruit' }), {
|
|
53
|
+
target: { value: 'ch' },
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
expect(screen.getAllByRole('option').map((o) => o.textContent)).toEqual([
|
|
57
|
+
'Cherry',
|
|
58
|
+
]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('shows the empty state when nothing matches', () => {
|
|
62
|
+
render(
|
|
63
|
+
<Combobox defaultOpen items={FRUITS}>
|
|
64
|
+
<Combobox.Input aria-label="Fruit" />
|
|
65
|
+
{renderList()}
|
|
66
|
+
</Combobox>,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
fireEvent.change(screen.getByRole('combobox', { name: 'Fruit' }), {
|
|
70
|
+
target: { value: 'zzz' },
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
expect(screen.queryAllByRole('option')).toHaveLength(0);
|
|
74
|
+
expect(screen.getByText('No fruit found.')).toBeInTheDocument();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('renders the trigger by default and the clear button on demand', () => {
|
|
78
|
+
const { rerender } = render(
|
|
79
|
+
<Combobox defaultValue={FRUITS[0]} items={FRUITS}>
|
|
80
|
+
<Combobox.Input aria-label="Fruit" />
|
|
81
|
+
{renderList()}
|
|
82
|
+
</Combobox>,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
expect(screen.getByLabelText('Open popup')).toBeInTheDocument();
|
|
86
|
+
expect(screen.queryByLabelText('Clear')).not.toBeInTheDocument();
|
|
87
|
+
|
|
88
|
+
rerender(
|
|
89
|
+
<Combobox defaultValue={FRUITS[0]} items={FRUITS}>
|
|
90
|
+
<Combobox.Input aria-label="Fruit" showClear showTrigger={false} />
|
|
91
|
+
{renderList()}
|
|
92
|
+
</Combobox>,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
expect(screen.queryByLabelText('Open popup')).not.toBeInTheDocument();
|
|
96
|
+
expect(screen.getByLabelText('Clear')).toBeInTheDocument();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('renders removable chips for multiple selection', () => {
|
|
100
|
+
render(
|
|
101
|
+
<Combobox defaultValue={[FRUITS[0], FRUITS[2]]} items={FRUITS} multiple>
|
|
102
|
+
<Combobox.Chips>
|
|
103
|
+
<Combobox.Value>
|
|
104
|
+
{(value: Fruit[]) => (
|
|
105
|
+
<>
|
|
106
|
+
{value.map((fruit) => (
|
|
107
|
+
<Combobox.Chip key={fruit.value}>{fruit.label}</Combobox.Chip>
|
|
108
|
+
))}
|
|
109
|
+
<Combobox.ChipsInput aria-label="Fruits" />
|
|
110
|
+
</>
|
|
111
|
+
)}
|
|
112
|
+
</Combobox.Value>
|
|
113
|
+
</Combobox.Chips>
|
|
114
|
+
{renderList()}
|
|
115
|
+
</Combobox>,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
expect(screen.getByText('Apple')).toBeInTheDocument();
|
|
119
|
+
expect(screen.getByText('Cherry')).toBeInTheDocument();
|
|
120
|
+
|
|
121
|
+
fireEvent.click(screen.getAllByLabelText('Remove')[0]);
|
|
122
|
+
|
|
123
|
+
expect(screen.queryByText('Apple')).not.toBeInTheDocument();
|
|
124
|
+
expect(screen.getByText('Cherry')).toBeInTheDocument();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('onCreate', () => {
|
|
128
|
+
function CreatableFruit({
|
|
129
|
+
multiple = false,
|
|
130
|
+
onCreate,
|
|
131
|
+
}: {
|
|
132
|
+
multiple?: boolean;
|
|
133
|
+
onCreate: (label: string) => Fruit;
|
|
134
|
+
}) {
|
|
135
|
+
const [items, setItems] = React.useState(FRUITS);
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<Combobox
|
|
139
|
+
items={items}
|
|
140
|
+
multiple={multiple}
|
|
141
|
+
onCreate={(label) => {
|
|
142
|
+
const fruit = onCreate(label);
|
|
143
|
+
setItems((current) => [...current, fruit]);
|
|
144
|
+
|
|
145
|
+
return fruit;
|
|
146
|
+
}}
|
|
147
|
+
>
|
|
148
|
+
{multiple ? (
|
|
149
|
+
<Combobox.Chips>
|
|
150
|
+
<Combobox.Value>
|
|
151
|
+
{(value: Fruit[]) => (
|
|
152
|
+
<>
|
|
153
|
+
{value.map((fruit) => (
|
|
154
|
+
<Combobox.Chip key={fruit.value}>
|
|
155
|
+
{fruit.label}
|
|
156
|
+
</Combobox.Chip>
|
|
157
|
+
))}
|
|
158
|
+
<Combobox.ChipsInput aria-label="Fruit" />
|
|
159
|
+
</>
|
|
160
|
+
)}
|
|
161
|
+
</Combobox.Value>
|
|
162
|
+
</Combobox.Chips>
|
|
163
|
+
) : (
|
|
164
|
+
<Combobox.Input aria-label="Fruit" />
|
|
165
|
+
)}
|
|
166
|
+
{renderList()}
|
|
167
|
+
</Combobox>
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function type(text: string) {
|
|
172
|
+
const input = screen.getByRole('combobox', { name: 'Fruit' });
|
|
173
|
+
fireEvent.focus(input);
|
|
174
|
+
// Base UI only treats events with an inputType as typed queries.
|
|
175
|
+
fireEvent.input(input, {
|
|
176
|
+
inputType: 'insertText',
|
|
177
|
+
target: { value: text },
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const toFruit = (label: string): Fruit => ({
|
|
182
|
+
label,
|
|
183
|
+
value: label.toLowerCase(),
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('offers a create option when the input matches no item', () => {
|
|
187
|
+
render(<CreatableFruit onCreate={toFruit} />);
|
|
188
|
+
|
|
189
|
+
type('Papaya');
|
|
190
|
+
|
|
191
|
+
expect(screen.getAllByRole('option').map((o) => o.textContent)).toEqual([
|
|
192
|
+
'Create "Papaya"',
|
|
193
|
+
]);
|
|
194
|
+
expect(screen.queryByText('No fruit found.')).not.toBeInTheDocument();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('hides the create option on an exact, case-insensitive match', () => {
|
|
198
|
+
render(<CreatableFruit onCreate={toFruit} />);
|
|
199
|
+
|
|
200
|
+
type('cherry ');
|
|
201
|
+
|
|
202
|
+
expect(screen.getAllByRole('option').map((o) => o.textContent)).toEqual([
|
|
203
|
+
'Cherry',
|
|
204
|
+
]);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('creates and selects the new item', () => {
|
|
208
|
+
const handleCreate = vi.fn(toFruit);
|
|
209
|
+
render(<CreatableFruit onCreate={handleCreate} />);
|
|
210
|
+
|
|
211
|
+
type('Papaya');
|
|
212
|
+
fireEvent.click(screen.getByRole('option', { name: 'Create "Papaya"' }));
|
|
213
|
+
|
|
214
|
+
expect(handleCreate).toHaveBeenCalledWith('Papaya');
|
|
215
|
+
expect(screen.getByRole('combobox', { name: 'Fruit' })).toHaveValue(
|
|
216
|
+
'Papaya',
|
|
217
|
+
);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('adds the created item as a chip in multiple mode', () => {
|
|
221
|
+
render(<CreatableFruit multiple onCreate={toFruit} />);
|
|
222
|
+
|
|
223
|
+
type('Papaya');
|
|
224
|
+
fireEvent.click(screen.getByRole('option', { name: 'Create "Papaya"' }));
|
|
225
|
+
|
|
226
|
+
expect(screen.getByText('Papaya')).toHaveAttribute(
|
|
227
|
+
'data-slot',
|
|
228
|
+
'combobox-chip',
|
|
229
|
+
);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('appends the create option after grouped items', () => {
|
|
233
|
+
const groups = [{ items: FRUITS, value: 'Fruits' }];
|
|
234
|
+
|
|
235
|
+
render(
|
|
236
|
+
<Combobox items={groups} onCreate={toFruit}>
|
|
237
|
+
<Combobox.Input aria-label="Fruit" />
|
|
238
|
+
<Combobox.Content>
|
|
239
|
+
<Combobox.List>
|
|
240
|
+
{(group: (typeof groups)[number]) => (
|
|
241
|
+
<Combobox.Group items={group.items} key={group.value}>
|
|
242
|
+
<Combobox.GroupLabel>{group.value}</Combobox.GroupLabel>
|
|
243
|
+
<Combobox.Collection>
|
|
244
|
+
{(fruit: Fruit) => (
|
|
245
|
+
<Combobox.Item key={fruit.value} value={fruit}>
|
|
246
|
+
{fruit.label}
|
|
247
|
+
</Combobox.Item>
|
|
248
|
+
)}
|
|
249
|
+
</Combobox.Collection>
|
|
250
|
+
</Combobox.Group>
|
|
251
|
+
)}
|
|
252
|
+
</Combobox.List>
|
|
253
|
+
</Combobox.Content>
|
|
254
|
+
</Combobox>,
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
type('an');
|
|
258
|
+
|
|
259
|
+
expect(screen.getAllByRole('option').map((o) => o.textContent)).toEqual([
|
|
260
|
+
'Banana',
|
|
261
|
+
'Create "an"',
|
|
262
|
+
]);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
describe('filter', () => {
|
|
267
|
+
function typeQuery(text: string) {
|
|
268
|
+
const input = screen.getByRole('combobox', { name: 'Fruit' });
|
|
269
|
+
fireEvent.focus(input);
|
|
270
|
+
fireEvent.input(input, {
|
|
271
|
+
inputType: 'insertText',
|
|
272
|
+
target: { value: text },
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function options() {
|
|
277
|
+
return screen.queryAllByRole('option').map((o) => o.textContent);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const startsWith = (fruit: Fruit, query: string) =>
|
|
281
|
+
fruit.label.toLowerCase().startsWith(query.toLowerCase());
|
|
282
|
+
|
|
283
|
+
it('uses a custom filter function', () => {
|
|
284
|
+
const filter = vi.fn(startsWith);
|
|
285
|
+
render(
|
|
286
|
+
<Combobox filter={filter} items={FRUITS}>
|
|
287
|
+
<Combobox.Input aria-label="Fruit" />
|
|
288
|
+
{renderList()}
|
|
289
|
+
</Combobox>,
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
typeQuery('an');
|
|
293
|
+
expect(options()).toEqual([]);
|
|
294
|
+
expect(
|
|
295
|
+
filter.mock.calls.some(
|
|
296
|
+
([item, query]) => item === FRUITS[1] && query === 'an',
|
|
297
|
+
),
|
|
298
|
+
).toBe(true);
|
|
299
|
+
|
|
300
|
+
typeQuery('ba');
|
|
301
|
+
expect(options()).toEqual(['Banana']);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('disables filtering with filter={null}', () => {
|
|
305
|
+
render(
|
|
306
|
+
<Combobox filter={null} items={FRUITS}>
|
|
307
|
+
<Combobox.Input aria-label="Fruit" />
|
|
308
|
+
{renderList()}
|
|
309
|
+
</Combobox>,
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
typeQuery('zzz');
|
|
313
|
+
|
|
314
|
+
expect(options()).toEqual(['Apple', 'Banana', 'Cherry']);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('keeps the create option with a custom filter', () => {
|
|
318
|
+
render(
|
|
319
|
+
<Combobox
|
|
320
|
+
filter={startsWith}
|
|
321
|
+
items={FRUITS}
|
|
322
|
+
onCreate={(label) => ({ label, value: label })}
|
|
323
|
+
>
|
|
324
|
+
<Combobox.Input aria-label="Fruit" />
|
|
325
|
+
{renderList()}
|
|
326
|
+
</Combobox>,
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
typeQuery('an');
|
|
330
|
+
|
|
331
|
+
expect(options()).toEqual(['Create "an"']);
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
});
|