@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,114 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
useFormContext,
|
|
4
|
+
type UseFormReturn,
|
|
5
|
+
useFormState,
|
|
6
|
+
} from 'react-hook-form';
|
|
7
|
+
|
|
8
|
+
type FormControlProps = {
|
|
9
|
+
id?: string;
|
|
10
|
+
};
|
|
11
|
+
type FormFieldContextValue = {
|
|
12
|
+
controlId?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
};
|
|
15
|
+
type UseFormControlPropsOptions = {
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
};
|
|
18
|
+
type WithoutAriaInvalid<Props> = Omit<Props, 'aria-invalid'> & {
|
|
19
|
+
'aria-invalid'?: never;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const FormFieldContext = React.createContext<FormFieldContextValue | null>(
|
|
23
|
+
null,
|
|
24
|
+
);
|
|
25
|
+
const FormInputGroupContext = React.createContext(false);
|
|
26
|
+
|
|
27
|
+
function getErrorMessage(error: unknown): React.ReactNode {
|
|
28
|
+
if (!error || typeof error !== 'object') {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const message = (error as { message?: unknown }).message;
|
|
33
|
+
|
|
34
|
+
if (
|
|
35
|
+
React.isValidElement(message) ||
|
|
36
|
+
typeof message === 'string' ||
|
|
37
|
+
typeof message === 'number'
|
|
38
|
+
) {
|
|
39
|
+
return message;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function useFieldName(name: string | undefined) {
|
|
46
|
+
const field = React.useContext(FormFieldContext);
|
|
47
|
+
|
|
48
|
+
return name ?? field?.name;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// React Hook Form exposes field state, but it does not attach DOM aria/id
|
|
52
|
+
// props to custom controls. This maps the current Form.Field onto the actual
|
|
53
|
+
// visible control.
|
|
54
|
+
function useFormControlProps(
|
|
55
|
+
props: FormControlProps = {},
|
|
56
|
+
{ enabled = true }: UseFormControlPropsOptions = {},
|
|
57
|
+
) {
|
|
58
|
+
const field = React.useContext(FormFieldContext);
|
|
59
|
+
const { control, getFieldState } = useFormMethods();
|
|
60
|
+
const name = enabled ? field?.name : undefined;
|
|
61
|
+
const formState = useFormState({
|
|
62
|
+
control,
|
|
63
|
+
disabled: !name,
|
|
64
|
+
exact: true,
|
|
65
|
+
name,
|
|
66
|
+
});
|
|
67
|
+
const controlId = enabled ? field?.controlId : undefined;
|
|
68
|
+
const invalid = name ? getFieldState(name, formState).invalid : false;
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
'aria-invalid': controlId && invalid ? true : undefined,
|
|
72
|
+
id: controlId ?? props.id,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function useFormMethods() {
|
|
77
|
+
const methods = useFormContext() as null | UseFormReturn;
|
|
78
|
+
|
|
79
|
+
if (!methods) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
'Form components must be rendered inside <Form form={form}>.',
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return methods;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function useRequiredFieldName(name: string | undefined, componentName: string) {
|
|
89
|
+
const fieldName = useFieldName(name);
|
|
90
|
+
|
|
91
|
+
if (!fieldName) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`${componentName} requires a name prop or a parent <Form.Field name="...">.`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return fieldName;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export {
|
|
101
|
+
FormFieldContext,
|
|
102
|
+
FormInputGroupContext,
|
|
103
|
+
getErrorMessage,
|
|
104
|
+
useFieldName,
|
|
105
|
+
useFormControlProps,
|
|
106
|
+
useFormMethods,
|
|
107
|
+
useRequiredFieldName,
|
|
108
|
+
};
|
|
109
|
+
export type {
|
|
110
|
+
FormControlProps,
|
|
111
|
+
FormFieldContextValue,
|
|
112
|
+
UseFormControlPropsOptions,
|
|
113
|
+
WithoutAriaInvalid,
|
|
114
|
+
};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
|
|
3
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { useForm } from 'react-hook-form';
|
|
6
|
+
import { z } from 'zod/v4';
|
|
7
|
+
|
|
8
|
+
import { Story } from '../_internal/Story';
|
|
9
|
+
import { Form } from './Form';
|
|
10
|
+
|
|
11
|
+
const meta = {
|
|
12
|
+
args: {},
|
|
13
|
+
component: Form,
|
|
14
|
+
parameters: {
|
|
15
|
+
layout: 'fullscreen',
|
|
16
|
+
},
|
|
17
|
+
title: 'components/Form',
|
|
18
|
+
} satisfies Meta<typeof Form>;
|
|
19
|
+
|
|
20
|
+
export default meta;
|
|
21
|
+
|
|
22
|
+
type StoryDefinition = StoryObj;
|
|
23
|
+
|
|
24
|
+
const roles = [
|
|
25
|
+
{ label: 'Designer', value: 'designer' },
|
|
26
|
+
{ label: 'Engineer', value: 'engineer' },
|
|
27
|
+
{ label: 'Manager', value: 'manager' },
|
|
28
|
+
] as const;
|
|
29
|
+
|
|
30
|
+
const notificationChannels: {
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
label: string;
|
|
33
|
+
value: string;
|
|
34
|
+
}[] = [
|
|
35
|
+
{ label: 'Email', value: 'email' },
|
|
36
|
+
{ label: 'SMS', value: 'sms' },
|
|
37
|
+
{ disabled: true, label: 'Push (coming soon)', value: 'push' },
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const defaultInterests = [
|
|
41
|
+
{ label: 'Design systems', value: 'design-systems' },
|
|
42
|
+
{ label: 'Accessibility', value: 'accessibility' },
|
|
43
|
+
{ label: 'Performance', value: 'performance' },
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
type Interest = (typeof defaultInterests)[number];
|
|
47
|
+
|
|
48
|
+
const signUpSchema = z.object({
|
|
49
|
+
bio: z.string().max(160, 'Keep it under 160 characters.'),
|
|
50
|
+
email: z.email('Enter a valid email address.'),
|
|
51
|
+
firstName: z.string().trim().min(1, 'Enter your first name.'),
|
|
52
|
+
interests: z
|
|
53
|
+
.array(z.object({ label: z.string(), value: z.string() }))
|
|
54
|
+
.min(1, 'Pick at least one interest.'),
|
|
55
|
+
lastName: z.string().trim().min(1, 'Enter your last name.'),
|
|
56
|
+
notificationChannel: z.enum(['email', 'sms']),
|
|
57
|
+
password: z.string().min(8, 'Use at least 8 characters.'),
|
|
58
|
+
productUpdates: z.boolean(),
|
|
59
|
+
role: z.enum(['designer', 'engineer', 'manager']),
|
|
60
|
+
terms: z.boolean().refine(Boolean, 'Accept the terms to continue.'),
|
|
61
|
+
username: z.string().trim().min(1, 'Enter a username.'),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
type SignUpValues = z.infer<typeof signUpSchema>;
|
|
65
|
+
|
|
66
|
+
function SignUpForm() {
|
|
67
|
+
const form = useForm<SignUpValues>({
|
|
68
|
+
defaultValues: {
|
|
69
|
+
bio: '',
|
|
70
|
+
email: '',
|
|
71
|
+
firstName: '',
|
|
72
|
+
interests: [],
|
|
73
|
+
lastName: '',
|
|
74
|
+
notificationChannel: 'email',
|
|
75
|
+
password: '',
|
|
76
|
+
productUpdates: true,
|
|
77
|
+
role: 'designer',
|
|
78
|
+
terms: false,
|
|
79
|
+
username: '',
|
|
80
|
+
},
|
|
81
|
+
resolver: zodResolver(signUpSchema),
|
|
82
|
+
});
|
|
83
|
+
const [interests, setInterests] = React.useState(defaultInterests);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<Form className="max-w-md" form={form} onSubmit={() => form.clearErrors()}>
|
|
87
|
+
<Form.Field
|
|
88
|
+
description="We'll send a confirmation link to this address."
|
|
89
|
+
label="Email"
|
|
90
|
+
name="email"
|
|
91
|
+
>
|
|
92
|
+
<Form.Input autoComplete="email" inputMode="email" />
|
|
93
|
+
</Form.Field>
|
|
94
|
+
|
|
95
|
+
<Form.Field label="Username" name="username">
|
|
96
|
+
<Form.Input autoComplete="username" />
|
|
97
|
+
</Form.Field>
|
|
98
|
+
|
|
99
|
+
<Form.Field
|
|
100
|
+
description="At least 8 characters."
|
|
101
|
+
label="Password"
|
|
102
|
+
name="password"
|
|
103
|
+
>
|
|
104
|
+
<Form.Input autoComplete="new-password" type="password" />
|
|
105
|
+
</Form.Field>
|
|
106
|
+
|
|
107
|
+
<Form.Field controlId="full-name" label="Full name">
|
|
108
|
+
<Form.InputGroup>
|
|
109
|
+
<Form.Input
|
|
110
|
+
aria-label="First name"
|
|
111
|
+
name="firstName"
|
|
112
|
+
placeholder="First"
|
|
113
|
+
/>
|
|
114
|
+
<Form.Input
|
|
115
|
+
aria-label="Last name"
|
|
116
|
+
name="lastName"
|
|
117
|
+
placeholder="Last"
|
|
118
|
+
/>
|
|
119
|
+
</Form.InputGroup>
|
|
120
|
+
</Form.Field>
|
|
121
|
+
|
|
122
|
+
<Form.Field label="Role" name="role">
|
|
123
|
+
<Form.Select>
|
|
124
|
+
<Form.Select.Trigger className="w-full">
|
|
125
|
+
<Form.Select.Value placeholder="Select a role" />
|
|
126
|
+
</Form.Select.Trigger>
|
|
127
|
+
<Form.Select.Content>
|
|
128
|
+
{roles.map((role) => (
|
|
129
|
+
<Form.Select.Item key={role.value} value={role.value}>
|
|
130
|
+
{role.label}
|
|
131
|
+
</Form.Select.Item>
|
|
132
|
+
))}
|
|
133
|
+
</Form.Select.Content>
|
|
134
|
+
</Form.Select>
|
|
135
|
+
</Form.Field>
|
|
136
|
+
|
|
137
|
+
<Form.Field
|
|
138
|
+
description="Pick from the list or type to add your own."
|
|
139
|
+
label="Interests"
|
|
140
|
+
name="interests"
|
|
141
|
+
>
|
|
142
|
+
<Form.Combobox
|
|
143
|
+
items={interests}
|
|
144
|
+
multiple
|
|
145
|
+
onCreate={(label) => {
|
|
146
|
+
const interest = { label, value: label.toLowerCase() };
|
|
147
|
+
setInterests((current) => [...current, interest]);
|
|
148
|
+
|
|
149
|
+
return interest;
|
|
150
|
+
}}
|
|
151
|
+
>
|
|
152
|
+
<Form.Combobox.Chips>
|
|
153
|
+
<Form.Combobox.Value>
|
|
154
|
+
{(value: Interest[]) => (
|
|
155
|
+
<>
|
|
156
|
+
{value.map((interest) => (
|
|
157
|
+
<Form.Combobox.Chip key={interest.value}>
|
|
158
|
+
{interest.label}
|
|
159
|
+
</Form.Combobox.Chip>
|
|
160
|
+
))}
|
|
161
|
+
<Form.Combobox.ChipsInput
|
|
162
|
+
placeholder={value.length > 0 ? '' : 'Add interests…'}
|
|
163
|
+
/>
|
|
164
|
+
</>
|
|
165
|
+
)}
|
|
166
|
+
</Form.Combobox.Value>
|
|
167
|
+
</Form.Combobox.Chips>
|
|
168
|
+
<Form.Combobox.Content>
|
|
169
|
+
<Form.Combobox.List>
|
|
170
|
+
{(interest: Interest) => (
|
|
171
|
+
<Form.Combobox.Item key={interest.value} value={interest}>
|
|
172
|
+
{interest.label}
|
|
173
|
+
</Form.Combobox.Item>
|
|
174
|
+
)}
|
|
175
|
+
</Form.Combobox.List>
|
|
176
|
+
</Form.Combobox.Content>
|
|
177
|
+
</Form.Combobox>
|
|
178
|
+
</Form.Field>
|
|
179
|
+
|
|
180
|
+
<Form.Field
|
|
181
|
+
description="A sentence or two for your public profile."
|
|
182
|
+
label="Bio"
|
|
183
|
+
name="bio"
|
|
184
|
+
>
|
|
185
|
+
<Form.Textarea placeholder="Tell us about yourself" />
|
|
186
|
+
</Form.Field>
|
|
187
|
+
|
|
188
|
+
<Form.Field name="productUpdates">
|
|
189
|
+
<Form.Switch label="Email me about new features and releases" />
|
|
190
|
+
</Form.Field>
|
|
191
|
+
|
|
192
|
+
<Form.Field
|
|
193
|
+
description="How should we reach you for account alerts?"
|
|
194
|
+
label="Notification channel"
|
|
195
|
+
name="notificationChannel"
|
|
196
|
+
>
|
|
197
|
+
<Form.RadioGroup>
|
|
198
|
+
{notificationChannels.map((channel) => (
|
|
199
|
+
<Form.RadioGroup.Item
|
|
200
|
+
disabled={channel.disabled}
|
|
201
|
+
key={channel.value}
|
|
202
|
+
label={channel.label}
|
|
203
|
+
value={channel.value}
|
|
204
|
+
/>
|
|
205
|
+
))}
|
|
206
|
+
</Form.RadioGroup>
|
|
207
|
+
</Form.Field>
|
|
208
|
+
|
|
209
|
+
<Form.Field name="terms">
|
|
210
|
+
<Form.Checkbox label="I agree to the terms of service and privacy policy" />
|
|
211
|
+
</Form.Field>
|
|
212
|
+
|
|
213
|
+
<Form.Button type="submit">Create account</Form.Button>
|
|
214
|
+
</Form>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export const SignUp: StoryDefinition = {
|
|
219
|
+
render: () => (
|
|
220
|
+
<Story.Layout className="max-w-lg" title="Form">
|
|
221
|
+
<Story.Section title="Sign up">
|
|
222
|
+
<SignUpForm />
|
|
223
|
+
</Story.Section>
|
|
224
|
+
</Story.Layout>
|
|
225
|
+
),
|
|
226
|
+
};
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useForm } from 'react-hook-form';
|
|
4
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
import { Form } from './Form';
|
|
7
|
+
|
|
8
|
+
type TestFormValues = {
|
|
9
|
+
channel: string;
|
|
10
|
+
email: string;
|
|
11
|
+
message: string;
|
|
12
|
+
productUpdates: boolean;
|
|
13
|
+
role: string;
|
|
14
|
+
terms: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const defaultValues: TestFormValues = {
|
|
18
|
+
channel: 'email',
|
|
19
|
+
email: '',
|
|
20
|
+
message: '',
|
|
21
|
+
productUpdates: false,
|
|
22
|
+
role: 'designer',
|
|
23
|
+
terms: false,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function TestForm({
|
|
27
|
+
fieldErrors,
|
|
28
|
+
onSubmit,
|
|
29
|
+
withEmailError,
|
|
30
|
+
}: {
|
|
31
|
+
fieldErrors?: Partial<Record<keyof TestFormValues, string>>;
|
|
32
|
+
onSubmit: (values: TestFormValues) => void;
|
|
33
|
+
withEmailError?: boolean;
|
|
34
|
+
}) {
|
|
35
|
+
const form = useForm<TestFormValues>({ defaultValues });
|
|
36
|
+
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
if (withEmailError) {
|
|
39
|
+
form.setError('email', {
|
|
40
|
+
message: 'Enter a valid email address.',
|
|
41
|
+
type: 'manual',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
for (const [name, message] of Object.entries(fieldErrors ?? {}) as [
|
|
46
|
+
keyof TestFormValues,
|
|
47
|
+
string,
|
|
48
|
+
][]) {
|
|
49
|
+
form.setError(name, {
|
|
50
|
+
message,
|
|
51
|
+
type: 'manual',
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}, [fieldErrors, form, withEmailError]);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Form form={form} onSubmit={onSubmit}>
|
|
58
|
+
<Form.Field label="Email" name="email">
|
|
59
|
+
<Form.Input autoComplete="email" />
|
|
60
|
+
</Form.Field>
|
|
61
|
+
|
|
62
|
+
<Form.Field label="Message" name="message">
|
|
63
|
+
<Form.Textarea />
|
|
64
|
+
</Form.Field>
|
|
65
|
+
|
|
66
|
+
<Form.Field label="Role" name="role">
|
|
67
|
+
<Form.Select>
|
|
68
|
+
<Form.Select.Trigger>
|
|
69
|
+
<Form.Select.Value placeholder="Select a role" />
|
|
70
|
+
</Form.Select.Trigger>
|
|
71
|
+
<Form.Select.Content>
|
|
72
|
+
<Form.Select.Item value="designer">Designer</Form.Select.Item>
|
|
73
|
+
<Form.Select.Item value="engineer">Engineer</Form.Select.Item>
|
|
74
|
+
</Form.Select.Content>
|
|
75
|
+
</Form.Select>
|
|
76
|
+
</Form.Field>
|
|
77
|
+
|
|
78
|
+
<Form.Field label="Notification channel" name="channel">
|
|
79
|
+
<Form.RadioGroup>
|
|
80
|
+
<Form.RadioGroup.Item label="Email" value="email" />
|
|
81
|
+
<Form.RadioGroup.Item label="SMS" value="sms" />
|
|
82
|
+
</Form.RadioGroup>
|
|
83
|
+
</Form.Field>
|
|
84
|
+
|
|
85
|
+
<Form.Field name="productUpdates">
|
|
86
|
+
<Form.Switch label="Product updates" />
|
|
87
|
+
</Form.Field>
|
|
88
|
+
|
|
89
|
+
<Form.Field name="terms">
|
|
90
|
+
<Form.Checkbox label="Accept terms" />
|
|
91
|
+
</Form.Field>
|
|
92
|
+
|
|
93
|
+
<Form.Button type="submit">Submit</Form.Button>
|
|
94
|
+
</Form>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
describe('Form', () => {
|
|
99
|
+
it('registers fields and submits React Hook Form values', async () => {
|
|
100
|
+
const handleSubmit = vi.fn();
|
|
101
|
+
render(<TestForm onSubmit={handleSubmit} />);
|
|
102
|
+
|
|
103
|
+
fireEvent.change(screen.getByRole('textbox', { name: 'Email' }), {
|
|
104
|
+
target: { value: 'ugo@example.com' },
|
|
105
|
+
});
|
|
106
|
+
fireEvent.change(screen.getByRole('textbox', { name: 'Message' }), {
|
|
107
|
+
target: { value: 'Hello' },
|
|
108
|
+
});
|
|
109
|
+
fireEvent.click(screen.getByRole('switch', { name: 'Product updates' }));
|
|
110
|
+
fireEvent.click(screen.getByRole('checkbox', { name: 'Accept terms' }));
|
|
111
|
+
fireEvent.click(screen.getByRole('radio', { name: 'SMS' }));
|
|
112
|
+
fireEvent.click(screen.getByRole('button', { name: 'Submit' }));
|
|
113
|
+
|
|
114
|
+
await waitFor(() => {
|
|
115
|
+
expect(handleSubmit).toHaveBeenCalledWith(
|
|
116
|
+
{
|
|
117
|
+
channel: 'sms',
|
|
118
|
+
email: 'ugo@example.com',
|
|
119
|
+
message: 'Hello',
|
|
120
|
+
productUpdates: true,
|
|
121
|
+
role: 'designer',
|
|
122
|
+
terms: true,
|
|
123
|
+
},
|
|
124
|
+
expect.anything(),
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('displays field errors from React Hook Form state', async () => {
|
|
130
|
+
render(<TestForm onSubmit={vi.fn()} withEmailError />);
|
|
131
|
+
|
|
132
|
+
expect(
|
|
133
|
+
await screen.findByText('Enter a valid email address.'),
|
|
134
|
+
).toBeInTheDocument();
|
|
135
|
+
expect(screen.getByRole('textbox', { name: 'Email' })).toHaveAttribute(
|
|
136
|
+
'aria-invalid',
|
|
137
|
+
'true',
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('marks controlled boolean fields invalid from React Hook Form state', async () => {
|
|
142
|
+
render(
|
|
143
|
+
<TestForm
|
|
144
|
+
fieldErrors={{
|
|
145
|
+
productUpdates: 'Choose a product update preference.',
|
|
146
|
+
terms: 'Accept the terms to continue.',
|
|
147
|
+
}}
|
|
148
|
+
onSubmit={vi.fn()}
|
|
149
|
+
/>,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
expect(
|
|
153
|
+
await screen.findByText('Choose a product update preference.'),
|
|
154
|
+
).toBeInTheDocument();
|
|
155
|
+
expect(
|
|
156
|
+
screen.getByRole('switch', { name: 'Product updates' }),
|
|
157
|
+
).toHaveAttribute('aria-invalid', 'true');
|
|
158
|
+
expect(
|
|
159
|
+
screen.getByRole('checkbox', { name: 'Accept terms' }),
|
|
160
|
+
).toHaveAttribute('aria-invalid', 'true');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('Form.Combobox', () => {
|
|
164
|
+
type Fruit = { label: string; value: string };
|
|
165
|
+
type FruitFormValues = { fruit: Fruit | null; tags: Fruit[] };
|
|
166
|
+
|
|
167
|
+
const FRUITS: Fruit[] = [
|
|
168
|
+
{ label: 'Apple', value: 'apple' },
|
|
169
|
+
{ label: 'Banana', value: 'banana' },
|
|
170
|
+
];
|
|
171
|
+
|
|
172
|
+
function FruitForm({
|
|
173
|
+
fruitError,
|
|
174
|
+
onSubmit,
|
|
175
|
+
}: {
|
|
176
|
+
fruitError?: string;
|
|
177
|
+
onSubmit: (values: FruitFormValues) => void;
|
|
178
|
+
}) {
|
|
179
|
+
const form = useForm<FruitFormValues>({
|
|
180
|
+
defaultValues: { fruit: null, tags: [] },
|
|
181
|
+
});
|
|
182
|
+
const [tags, setTags] = React.useState(FRUITS);
|
|
183
|
+
|
|
184
|
+
React.useEffect(() => {
|
|
185
|
+
if (fruitError) {
|
|
186
|
+
form.setError('fruit', { message: fruitError, type: 'manual' });
|
|
187
|
+
}
|
|
188
|
+
}, [form, fruitError]);
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<Form form={form} onSubmit={onSubmit}>
|
|
192
|
+
<Form.Field label="Fruit" name="fruit">
|
|
193
|
+
<Form.Combobox items={FRUITS}>
|
|
194
|
+
<Form.Combobox.Input />
|
|
195
|
+
<Form.Combobox.Content>
|
|
196
|
+
<Form.Combobox.List>
|
|
197
|
+
{(fruit: Fruit) => (
|
|
198
|
+
<Form.Combobox.Item key={fruit.value} value={fruit}>
|
|
199
|
+
{fruit.label}
|
|
200
|
+
</Form.Combobox.Item>
|
|
201
|
+
)}
|
|
202
|
+
</Form.Combobox.List>
|
|
203
|
+
</Form.Combobox.Content>
|
|
204
|
+
</Form.Combobox>
|
|
205
|
+
</Form.Field>
|
|
206
|
+
|
|
207
|
+
<Form.Field label="Tags" name="tags">
|
|
208
|
+
<Form.Combobox
|
|
209
|
+
items={tags}
|
|
210
|
+
multiple
|
|
211
|
+
onCreate={(label) => {
|
|
212
|
+
const tag = { label, value: label.toLowerCase() };
|
|
213
|
+
setTags((current) => [...current, tag]);
|
|
214
|
+
|
|
215
|
+
return tag;
|
|
216
|
+
}}
|
|
217
|
+
>
|
|
218
|
+
<Form.Combobox.Chips>
|
|
219
|
+
<Form.Combobox.Value>
|
|
220
|
+
{(value: Fruit[]) => (
|
|
221
|
+
<>
|
|
222
|
+
{value.map((tag) => (
|
|
223
|
+
<Form.Combobox.Chip key={tag.value}>
|
|
224
|
+
{tag.label}
|
|
225
|
+
</Form.Combobox.Chip>
|
|
226
|
+
))}
|
|
227
|
+
<Form.Combobox.ChipsInput />
|
|
228
|
+
</>
|
|
229
|
+
)}
|
|
230
|
+
</Form.Combobox.Value>
|
|
231
|
+
</Form.Combobox.Chips>
|
|
232
|
+
<Form.Combobox.Content>
|
|
233
|
+
<Form.Combobox.List>
|
|
234
|
+
{(tag: Fruit) => (
|
|
235
|
+
<Form.Combobox.Item key={tag.value} value={tag}>
|
|
236
|
+
{tag.label}
|
|
237
|
+
</Form.Combobox.Item>
|
|
238
|
+
)}
|
|
239
|
+
</Form.Combobox.List>
|
|
240
|
+
</Form.Combobox.Content>
|
|
241
|
+
</Form.Combobox>
|
|
242
|
+
</Form.Field>
|
|
243
|
+
|
|
244
|
+
<Form.Button type="submit">Submit</Form.Button>
|
|
245
|
+
</Form>
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function type(name: string, text: string) {
|
|
250
|
+
const input = screen.getByRole('combobox', { name });
|
|
251
|
+
fireEvent.focus(input);
|
|
252
|
+
fireEvent.input(input, {
|
|
253
|
+
inputType: 'insertText',
|
|
254
|
+
target: { value: text },
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
it('submits selected and created items', async () => {
|
|
259
|
+
const handleSubmit = vi.fn();
|
|
260
|
+
render(<FruitForm onSubmit={handleSubmit} />);
|
|
261
|
+
|
|
262
|
+
type('Fruit', 'Ban');
|
|
263
|
+
fireEvent.click(await screen.findByRole('option', { name: 'Banana' }));
|
|
264
|
+
|
|
265
|
+
type('Tags', 'Kiwi');
|
|
266
|
+
fireEvent.click(
|
|
267
|
+
await screen.findByRole('option', { name: 'Create "Kiwi"' }),
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
fireEvent.click(screen.getByRole('button', { name: 'Submit' }));
|
|
271
|
+
|
|
272
|
+
await waitFor(() => {
|
|
273
|
+
expect(handleSubmit).toHaveBeenCalledWith(
|
|
274
|
+
{
|
|
275
|
+
fruit: FRUITS[1],
|
|
276
|
+
tags: [{ label: 'Kiwi', value: 'kiwi' }],
|
|
277
|
+
},
|
|
278
|
+
expect.anything(),
|
|
279
|
+
);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('marks the input invalid from React Hook Form state', async () => {
|
|
284
|
+
render(<FruitForm fruitError="Pick a fruit." onSubmit={vi.fn()} />);
|
|
285
|
+
|
|
286
|
+
expect(await screen.findByText('Pick a fruit.')).toBeInTheDocument();
|
|
287
|
+
expect(screen.getByRole('combobox', { name: 'Fruit' })).toHaveAttribute(
|
|
288
|
+
'aria-invalid',
|
|
289
|
+
'true',
|
|
290
|
+
);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Button } from '@/components/Button';
|
|
4
|
+
|
|
5
|
+
import { FormCheckbox, type FormCheckboxProps } from './FormCheckbox';
|
|
6
|
+
import { FormCombobox, type FormComboboxProps } from './FormCombobox';
|
|
7
|
+
import { FormDescription, type FormDescriptionProps } from './FormDescription';
|
|
8
|
+
import { FormError, type FormErrorProps } from './FormError';
|
|
9
|
+
import { FormField, type FormFieldProps } from './FormField';
|
|
10
|
+
import { FormInput, type FormInputProps } from './FormInput';
|
|
11
|
+
import { FormInputGroup, type FormInputGroupProps } from './FormInputGroup';
|
|
12
|
+
import { FormLabel, type FormLabelProps } from './FormLabel';
|
|
13
|
+
import { FormRadioGroup, type FormRadioGroupProps } from './FormRadioGroup';
|
|
14
|
+
import { type FormProps, FormRoot } from './FormRoot';
|
|
15
|
+
import { FormSelect, type FormSelectProps } from './FormSelect';
|
|
16
|
+
import { FormSwitch, type FormSwitchProps } from './FormSwitch';
|
|
17
|
+
import { FormTextarea, type FormTextareaProps } from './FormTextarea';
|
|
18
|
+
|
|
19
|
+
const Form = Object.assign(FormRoot, {
|
|
20
|
+
Button,
|
|
21
|
+
Checkbox: FormCheckbox,
|
|
22
|
+
Combobox: FormCombobox,
|
|
23
|
+
Description: FormDescription,
|
|
24
|
+
Error: FormError,
|
|
25
|
+
Field: FormField,
|
|
26
|
+
Input: FormInput,
|
|
27
|
+
InputGroup: FormInputGroup,
|
|
28
|
+
Label: FormLabel,
|
|
29
|
+
RadioGroup: FormRadioGroup,
|
|
30
|
+
Select: FormSelect,
|
|
31
|
+
Switch: FormSwitch,
|
|
32
|
+
Textarea: FormTextarea,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export { Form };
|
|
36
|
+
export type {
|
|
37
|
+
FormCheckboxProps,
|
|
38
|
+
FormComboboxProps,
|
|
39
|
+
FormDescriptionProps,
|
|
40
|
+
FormErrorProps,
|
|
41
|
+
FormFieldProps,
|
|
42
|
+
FormInputGroupProps,
|
|
43
|
+
FormInputProps,
|
|
44
|
+
FormLabelProps,
|
|
45
|
+
FormProps,
|
|
46
|
+
FormRadioGroupProps,
|
|
47
|
+
FormSelectProps,
|
|
48
|
+
FormSwitchProps,
|
|
49
|
+
FormTextareaProps,
|
|
50
|
+
};
|