@byldpartners/ui 0.0.1
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 +284 -0
- package/dist/chunk-464G63BO.cjs +224 -0
- package/dist/chunk-464G63BO.cjs.map +1 -0
- package/dist/chunk-JFJY6DZZ.js +224 -0
- package/dist/chunk-JFJY6DZZ.js.map +1 -0
- package/dist/index.cjs +3894 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1543 -0
- package/dist/index.d.ts +1543 -0
- package/dist/index.js +3894 -0
- package/dist/index.js.map +1 -0
- package/dist/theme/web.cjs +16 -0
- package/dist/theme/web.cjs.map +1 -0
- package/dist/theme/web.d.cts +81 -0
- package/dist/theme/web.d.ts +81 -0
- package/dist/theme/web.js +16 -0
- package/dist/theme/web.js.map +1 -0
- package/package.json +117 -0
- package/src/components/Accordion/Accordion.native.tsx +195 -0
- package/src/components/Accordion/Accordion.stories.tsx +49 -0
- package/src/components/Accordion/Accordion.types.ts +28 -0
- package/src/components/Accordion/Accordion.web.tsx +61 -0
- package/src/components/Accordion/index.native.ts +12 -0
- package/src/components/Accordion/index.ts +12 -0
- package/src/components/Accordion/useAccordion.test.ts +114 -0
- package/src/components/Accordion/useAccordion.ts +65 -0
- package/src/components/Alert/Alert.native.tsx +86 -0
- package/src/components/Alert/Alert.stories.tsx +43 -0
- package/src/components/Alert/Alert.types.ts +17 -0
- package/src/components/Alert/Alert.web.test.tsx +49 -0
- package/src/components/Alert/Alert.web.tsx +59 -0
- package/src/components/Alert/index.native.ts +2 -0
- package/src/components/Alert/index.ts +2 -0
- package/src/components/Alert/useAlert.test.ts +19 -0
- package/src/components/Alert/useAlert.ts +10 -0
- package/src/components/AlertDialog/AlertDialog.native.tsx +281 -0
- package/src/components/AlertDialog/AlertDialog.stories.tsx +49 -0
- package/src/components/AlertDialog/AlertDialog.types.ts +49 -0
- package/src/components/AlertDialog/AlertDialog.web.tsx +138 -0
- package/src/components/AlertDialog/index.native.ts +22 -0
- package/src/components/AlertDialog/index.ts +24 -0
- package/src/components/AlertDialog/useAlertDialog.test.ts +40 -0
- package/src/components/AlertDialog/useAlertDialog.ts +36 -0
- package/src/components/AspectRatio/AspectRatio.native.tsx +37 -0
- package/src/components/AspectRatio/AspectRatio.stories.tsx +44 -0
- package/src/components/AspectRatio/AspectRatio.types.ts +5 -0
- package/src/components/AspectRatio/AspectRatio.web.tsx +5 -0
- package/src/components/AspectRatio/index.native.ts +2 -0
- package/src/components/AspectRatio/index.ts +2 -0
- package/src/components/AspectRatio/useAspectRatio.test.ts +40 -0
- package/src/components/AspectRatio/useAspectRatio.ts +12 -0
- package/src/components/Avatar/Avatar.native.tsx +95 -0
- package/src/components/Avatar/Avatar.stories.tsx +31 -0
- package/src/components/Avatar/Avatar.types.ts +17 -0
- package/src/components/Avatar/Avatar.web.tsx +47 -0
- package/src/components/Avatar/index.native.ts +2 -0
- package/src/components/Avatar/index.ts +2 -0
- package/src/components/Avatar/useAvatarImage.test.ts +66 -0
- package/src/components/Avatar/useAvatarImage.ts +31 -0
- package/src/components/Badge/Badge.native.tsx +64 -0
- package/src/components/Badge/Badge.stories.tsx +42 -0
- package/src/components/Badge/Badge.types.ts +7 -0
- package/src/components/Badge/Badge.web.test.tsx +40 -0
- package/src/components/Badge/Badge.web.tsx +41 -0
- package/src/components/Badge/index.native.ts +2 -0
- package/src/components/Badge/index.ts +2 -0
- package/src/components/Breadcrumb/Breadcrumb.native.tsx +158 -0
- package/src/components/Breadcrumb/Breadcrumb.stories.tsx +41 -0
- package/src/components/Breadcrumb/Breadcrumb.types.ts +37 -0
- package/src/components/Breadcrumb/Breadcrumb.web.tsx +125 -0
- package/src/components/Breadcrumb/index.native.ts +18 -0
- package/src/components/Breadcrumb/index.ts +18 -0
- package/src/components/Button/Button.native.tsx +118 -0
- package/src/components/Button/Button.stories.tsx +97 -0
- package/src/components/Button/Button.types.ts +19 -0
- package/src/components/Button/Button.web.test.tsx +69 -0
- package/src/components/Button/Button.web.tsx +55 -0
- package/src/components/Button/index.native.ts +2 -0
- package/src/components/Button/index.ts +2 -0
- package/src/components/Calendar/Calendar.native.tsx +108 -0
- package/src/components/Calendar/Calendar.stories.tsx +18 -0
- package/src/components/Calendar/Calendar.types.ts +8 -0
- package/src/components/Calendar/Calendar.web.tsx +143 -0
- package/src/components/Calendar/index.native.ts +2 -0
- package/src/components/Calendar/index.ts +2 -0
- package/src/components/Calendar/useCalendar.test.ts +145 -0
- package/src/components/Calendar/useCalendar.ts +94 -0
- package/src/components/Card/Card.native.tsx +42 -0
- package/src/components/Card/Card.stories.tsx +41 -0
- package/src/components/Card/Card.types.ts +4 -0
- package/src/components/Card/Card.web.test.tsx +29 -0
- package/src/components/Card/Card.web.tsx +23 -0
- package/src/components/Card/index.native.ts +2 -0
- package/src/components/Card/index.ts +2 -0
- package/src/components/Carousel/Carousel.native.tsx +193 -0
- package/src/components/Carousel/Carousel.stories.tsx +51 -0
- package/src/components/Carousel/Carousel.types.ts +29 -0
- package/src/components/Carousel/Carousel.web.tsx +272 -0
- package/src/components/Carousel/index.native.ts +2 -0
- package/src/components/Carousel/index.ts +2 -0
- package/src/components/Carousel/useCarousel.test.ts +111 -0
- package/src/components/Carousel/useCarousel.ts +48 -0
- package/src/components/Chart/Chart.native.tsx +7 -0
- package/src/components/Chart/Chart.stories.tsx +57 -0
- package/src/components/Chart/Chart.types.ts +13 -0
- package/src/components/Chart/Chart.web.tsx +36 -0
- package/src/components/Chart/index.native.ts +2 -0
- package/src/components/Chart/index.ts +3 -0
- package/src/components/Checkbox/Checkbox.native.tsx +47 -0
- package/src/components/Checkbox/Checkbox.stories.tsx +30 -0
- package/src/components/Checkbox/Checkbox.types.ts +12 -0
- package/src/components/Checkbox/Checkbox.web.tsx +37 -0
- package/src/components/Checkbox/index.native.ts +2 -0
- package/src/components/Checkbox/index.ts +2 -0
- package/src/components/Checkbox/useCheckbox.test.ts +66 -0
- package/src/components/Checkbox/useCheckbox.ts +37 -0
- package/src/components/Collapsible/Collapsible.native.tsx +111 -0
- package/src/components/Collapsible/Collapsible.stories.tsx +35 -0
- package/src/components/Collapsible/Collapsible.types.ts +19 -0
- package/src/components/Collapsible/Collapsible.web.tsx +9 -0
- package/src/components/Collapsible/index.native.ts +2 -0
- package/src/components/Collapsible/index.ts +2 -0
- package/src/components/Collapsible/useCollapsible.test.ts +53 -0
- package/src/components/Collapsible/useCollapsible.ts +38 -0
- package/src/components/Combobox/Combobox.native.tsx +146 -0
- package/src/components/Combobox/Combobox.stories.tsx +43 -0
- package/src/components/Combobox/Combobox.types.ts +15 -0
- package/src/components/Combobox/Combobox.web.tsx +145 -0
- package/src/components/Combobox/index.native.ts +2 -0
- package/src/components/Combobox/index.ts +2 -0
- package/src/components/Combobox/useCombobox.test.ts +59 -0
- package/src/components/Combobox/useCombobox.ts +42 -0
- package/src/components/Command/Command.native.tsx +7 -0
- package/src/components/Command/Command.stories.tsx +37 -0
- package/src/components/Command/Command.types.ts +43 -0
- package/src/components/Command/Command.web.tsx +134 -0
- package/src/components/Command/index.native.ts +2 -0
- package/src/components/Command/index.ts +18 -0
- package/src/components/ContextMenu/ContextMenu.native.tsx +241 -0
- package/src/components/ContextMenu/ContextMenu.stories.tsx +43 -0
- package/src/components/ContextMenu/ContextMenu.types.ts +69 -0
- package/src/components/ContextMenu/ContextMenu.web.tsx +220 -0
- package/src/components/ContextMenu/index.native.ts +28 -0
- package/src/components/ContextMenu/index.ts +2 -0
- package/src/components/ContextMenu/useContextMenu.test.ts +44 -0
- package/src/components/ContextMenu/useContextMenu.ts +36 -0
- package/src/components/DataTable/DataTable.native.tsx +85 -0
- package/src/components/DataTable/DataTable.stories.tsx +72 -0
- package/src/components/DataTable/DataTable.types.ts +16 -0
- package/src/components/DataTable/DataTable.web.tsx +135 -0
- package/src/components/DataTable/index.native.ts +2 -0
- package/src/components/DataTable/index.ts +3 -0
- package/src/components/DataTable/useDataTable.test.ts +98 -0
- package/src/components/DataTable/useDataTable.ts +68 -0
- package/src/components/DatePicker/DatePicker.native.tsx +82 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +68 -0
- package/src/components/DatePicker/DatePicker.types.ts +7 -0
- package/src/components/DatePicker/DatePicker.web.tsx +85 -0
- package/src/components/DatePicker/index.native.ts +2 -0
- package/src/components/DatePicker/index.ts +2 -0
- package/src/components/DatePicker/useDatePicker.test.ts +62 -0
- package/src/components/DatePicker/useDatePicker.ts +54 -0
- package/src/components/Dialog/Dialog.native.tsx +188 -0
- package/src/components/Dialog/Dialog.stories.tsx +42 -0
- package/src/components/Dialog/Dialog.types.ts +45 -0
- package/src/components/Dialog/Dialog.web.tsx +126 -0
- package/src/components/Dialog/index.native.ts +2 -0
- package/src/components/Dialog/index.ts +2 -0
- package/src/components/Dialog/useDialog.test.ts +44 -0
- package/src/components/Dialog/useDialog.ts +36 -0
- package/src/components/Drawer/Drawer.native.tsx +244 -0
- package/src/components/Drawer/Drawer.stories.tsx +39 -0
- package/src/components/Drawer/Drawer.types.ts +44 -0
- package/src/components/Drawer/Drawer.web.tsx +133 -0
- package/src/components/Drawer/index.native.ts +2 -0
- package/src/components/Drawer/index.ts +2 -0
- package/src/components/Drawer/useDrawer.test.ts +33 -0
- package/src/components/Drawer/useDrawer.ts +19 -0
- package/src/components/DropdownMenu/DropdownMenu.native.tsx +272 -0
- package/src/components/DropdownMenu/DropdownMenu.stories.tsx +36 -0
- package/src/components/DropdownMenu/DropdownMenu.types.ts +73 -0
- package/src/components/DropdownMenu/DropdownMenu.web.tsx +225 -0
- package/src/components/DropdownMenu/index.native.ts +2 -0
- package/src/components/DropdownMenu/index.ts +2 -0
- package/src/components/DropdownMenu/useDropdownMenu.test.ts +44 -0
- package/src/components/DropdownMenu/useDropdownMenu.ts +36 -0
- package/src/components/Form/Form.native.tsx +98 -0
- package/src/components/Form/Form.stories.tsx +83 -0
- package/src/components/Form/Form.types.ts +35 -0
- package/src/components/Form/Form.web.test.tsx +73 -0
- package/src/components/Form/Form.web.tsx +111 -0
- package/src/components/Form/index.native.ts +18 -0
- package/src/components/Form/index.ts +18 -0
- package/src/components/Form/useFormField.test.ts +25 -0
- package/src/components/Form/useFormField.ts +22 -0
- package/src/components/HoverCard/HoverCard.native.tsx +15 -0
- package/src/components/HoverCard/HoverCard.stories.tsx +34 -0
- package/src/components/HoverCard/HoverCard.types.ts +18 -0
- package/src/components/HoverCard/HoverCard.web.test.tsx +35 -0
- package/src/components/HoverCard/HoverCard.web.tsx +26 -0
- package/src/components/HoverCard/index.native.ts +2 -0
- package/src/components/HoverCard/index.ts +2 -0
- package/src/components/Icon/Icon.native.tsx +27 -0
- package/src/components/Icon/index.native.ts +2 -0
- package/src/components/Input/Input.native.tsx +32 -0
- package/src/components/Input/Input.stories.tsx +42 -0
- package/src/components/Input/Input.types.ts +10 -0
- package/src/components/Input/Input.web.test.tsx +39 -0
- package/src/components/Input/Input.web.tsx +21 -0
- package/src/components/Input/index.native.ts +2 -0
- package/src/components/Input/index.ts +2 -0
- package/src/components/InputOTP/InputOTP.native.tsx +93 -0
- package/src/components/InputOTP/InputOTP.stories.tsx +56 -0
- package/src/components/InputOTP/InputOTP.types.ts +14 -0
- package/src/components/InputOTP/InputOTP.web.tsx +128 -0
- package/src/components/InputOTP/index.native.ts +2 -0
- package/src/components/InputOTP/index.ts +2 -0
- package/src/components/InputOTP/useInputOTP.test.ts +97 -0
- package/src/components/InputOTP/useInputOTP.ts +69 -0
- package/src/components/Label/Label.native.tsx +25 -0
- package/src/components/Label/Label.stories.tsx +20 -0
- package/src/components/Label/Label.types.ts +6 -0
- package/src/components/Label/Label.web.test.tsx +27 -0
- package/src/components/Label/Label.web.tsx +23 -0
- package/src/components/Label/index.native.ts +2 -0
- package/src/components/Label/index.ts +2 -0
- package/src/components/Menubar/Menubar.native.tsx +287 -0
- package/src/components/Menubar/Menubar.stories.tsx +46 -0
- package/src/components/Menubar/Menubar.types.ts +70 -0
- package/src/components/Menubar/Menubar.web.tsx +256 -0
- package/src/components/Menubar/index.native.ts +28 -0
- package/src/components/Menubar/index.ts +2 -0
- package/src/components/Menubar/useMenubar.test.ts +35 -0
- package/src/components/Menubar/useMenubar.ts +19 -0
- package/src/components/NavigationMenu/NavigationMenu.native.tsx +128 -0
- package/src/components/NavigationMenu/NavigationMenu.stories.tsx +35 -0
- package/src/components/NavigationMenu/NavigationMenu.types.ts +35 -0
- package/src/components/NavigationMenu/NavigationMenu.web.test.tsx +56 -0
- package/src/components/NavigationMenu/NavigationMenu.web.tsx +134 -0
- package/src/components/NavigationMenu/index.native.ts +16 -0
- package/src/components/NavigationMenu/index.ts +2 -0
- package/src/components/Pagination/Pagination.native.tsx +192 -0
- package/src/components/Pagination/Pagination.stories.tsx +49 -0
- package/src/components/Pagination/Pagination.types.ts +41 -0
- package/src/components/Pagination/Pagination.web.test.tsx +101 -0
- package/src/components/Pagination/Pagination.web.tsx +185 -0
- package/src/components/Pagination/index.native.ts +19 -0
- package/src/components/Pagination/index.ts +2 -0
- package/src/components/Popover/Popover.native.tsx +97 -0
- package/src/components/Popover/Popover.stories.tsx +25 -0
- package/src/components/Popover/Popover.types.ts +20 -0
- package/src/components/Popover/Popover.web.tsx +30 -0
- package/src/components/Popover/index.native.ts +2 -0
- package/src/components/Popover/index.ts +2 -0
- package/src/components/Popover/usePopover.test.ts +40 -0
- package/src/components/Popover/usePopover.ts +36 -0
- package/src/components/Progress/Progress.native.tsx +65 -0
- package/src/components/Progress/Progress.stories.tsx +36 -0
- package/src/components/Progress/Progress.types.ts +6 -0
- package/src/components/Progress/Progress.web.test.tsx +27 -0
- package/src/components/Progress/Progress.web.tsx +30 -0
- package/src/components/Progress/index.native.ts +2 -0
- package/src/components/Progress/index.ts +2 -0
- package/src/components/Progress/useProgress.test.ts +44 -0
- package/src/components/Progress/useProgress.ts +11 -0
- package/src/components/RadioGroup/RadioGroup.native.tsx +96 -0
- package/src/components/RadioGroup/RadioGroup.stories.tsx +31 -0
- package/src/components/RadioGroup/RadioGroup.types.ts +16 -0
- package/src/components/RadioGroup/RadioGroup.web.tsx +47 -0
- package/src/components/RadioGroup/index.native.ts +2 -0
- package/src/components/RadioGroup/index.ts +2 -0
- package/src/components/RadioGroup/useRadioGroup.test.ts +50 -0
- package/src/components/RadioGroup/useRadioGroup.ts +40 -0
- package/src/components/ResizablePanel/ResizablePanel.native.tsx +75 -0
- package/src/components/ResizablePanel/ResizablePanel.stories.tsx +84 -0
- package/src/components/ResizablePanel/ResizablePanel.types.ts +20 -0
- package/src/components/ResizablePanel/ResizablePanel.web.test.tsx +52 -0
- package/src/components/ResizablePanel/ResizablePanel.web.tsx +77 -0
- package/src/components/ResizablePanel/index.native.ts +2 -0
- package/src/components/ResizablePanel/index.ts +2 -0
- package/src/components/ScrollArea/ScrollArea.native.tsx +43 -0
- package/src/components/ScrollArea/ScrollArea.stories.tsx +46 -0
- package/src/components/ScrollArea/ScrollArea.types.ts +11 -0
- package/src/components/ScrollArea/ScrollArea.web.test.tsx +19 -0
- package/src/components/ScrollArea/ScrollArea.web.tsx +45 -0
- package/src/components/ScrollArea/index.native.ts +2 -0
- package/src/components/ScrollArea/index.ts +2 -0
- package/src/components/Select/Select.native.tsx +203 -0
- package/src/components/Select/Select.stories.tsx +33 -0
- package/src/components/Select/Select.types.ts +14 -0
- package/src/components/Select/Select.web.tsx +204 -0
- package/src/components/Select/index.native.ts +11 -0
- package/src/components/Select/index.ts +2 -0
- package/src/components/Select/useSelect.test.ts +38 -0
- package/src/components/Select/useSelect.ts +33 -0
- package/src/components/Separator/Separator.native.tsx +38 -0
- package/src/components/Separator/Separator.stories.tsx +34 -0
- package/src/components/Separator/Separator.types.ts +7 -0
- package/src/components/Separator/Separator.web.test.tsx +32 -0
- package/src/components/Separator/Separator.web.tsx +38 -0
- package/src/components/Separator/index.native.ts +2 -0
- package/src/components/Separator/index.ts +2 -0
- package/src/components/Sheet/Sheet.native.tsx +246 -0
- package/src/components/Sheet/Sheet.stories.tsx +43 -0
- package/src/components/Sheet/Sheet.types.ts +47 -0
- package/src/components/Sheet/Sheet.web.tsx +144 -0
- package/src/components/Sheet/index.native.ts +2 -0
- package/src/components/Sheet/index.ts +2 -0
- package/src/components/Sheet/useSheet.test.ts +40 -0
- package/src/components/Sheet/useSheet.ts +19 -0
- package/src/components/Sidebar/Sidebar.native.tsx +7 -0
- package/src/components/Sidebar/Sidebar.stories.tsx +100 -0
- package/src/components/Sidebar/Sidebar.types.ts +30 -0
- package/src/components/Sidebar/Sidebar.web.test.tsx +74 -0
- package/src/components/Sidebar/Sidebar.web.tsx +200 -0
- package/src/components/Sidebar/index.native.ts +2 -0
- package/src/components/Sidebar/index.ts +2 -0
- package/src/components/Sidebar/useSidebar.test.ts +51 -0
- package/src/components/Sidebar/useSidebar.ts +26 -0
- package/src/components/Skeleton/Skeleton.native.tsx +45 -0
- package/src/components/Skeleton/Skeleton.stories.tsx +32 -0
- package/src/components/Skeleton/Skeleton.types.ts +6 -0
- package/src/components/Skeleton/Skeleton.web.test.tsx +35 -0
- package/src/components/Skeleton/Skeleton.web.tsx +18 -0
- package/src/components/Skeleton/index.native.ts +2 -0
- package/src/components/Skeleton/index.ts +2 -0
- package/src/components/Slider/Slider.native.tsx +98 -0
- package/src/components/Slider/Slider.stories.tsx +23 -0
- package/src/components/Slider/Slider.types.ts +10 -0
- package/src/components/Slider/Slider.web.tsx +25 -0
- package/src/components/Slider/index.native.ts +2 -0
- package/src/components/Slider/index.ts +2 -0
- package/src/components/Slider/useSlider.test.ts +68 -0
- package/src/components/Slider/useSlider.ts +55 -0
- package/src/components/Switch/Switch.native.tsx +36 -0
- package/src/components/Switch/Switch.stories.tsx +28 -0
- package/src/components/Switch/Switch.types.ts +7 -0
- package/src/components/Switch/Switch.web.test.tsx +44 -0
- package/src/components/Switch/Switch.web.tsx +26 -0
- package/src/components/Switch/index.native.ts +2 -0
- package/src/components/Switch/index.ts +2 -0
- package/src/components/Table/Table.native.tsx +165 -0
- package/src/components/Table/Table.stories.tsx +54 -0
- package/src/components/Table/Table.types.ts +41 -0
- package/src/components/Table/Table.web.test.tsx +77 -0
- package/src/components/Table/Table.web.tsx +119 -0
- package/src/components/Table/index.native.ts +2 -0
- package/src/components/Table/index.ts +2 -0
- package/src/components/Tabs/Tabs.native.tsx +136 -0
- package/src/components/Tabs/Tabs.stories.tsx +35 -0
- package/src/components/Tabs/Tabs.types.ts +25 -0
- package/src/components/Tabs/Tabs.web.tsx +52 -0
- package/src/components/Tabs/index.native.ts +2 -0
- package/src/components/Tabs/index.ts +2 -0
- package/src/components/Tabs/useTabs.test.ts +40 -0
- package/src/components/Tabs/useTabs.ts +20 -0
- package/src/components/Textarea/Textarea.native.tsx +33 -0
- package/src/components/Textarea/Textarea.stories.tsx +27 -0
- package/src/components/Textarea/Textarea.types.ts +10 -0
- package/src/components/Textarea/Textarea.web.test.tsx +33 -0
- package/src/components/Textarea/Textarea.web.tsx +21 -0
- package/src/components/Textarea/index.native.ts +2 -0
- package/src/components/Textarea/index.ts +2 -0
- package/src/components/Toast/Toast.native.tsx +267 -0
- package/src/components/Toast/Toast.stories.tsx +34 -0
- package/src/components/Toast/Toast.types.ts +50 -0
- package/src/components/Toast/Toast.web.tsx +282 -0
- package/src/components/Toast/index.native.ts +17 -0
- package/src/components/Toast/index.ts +11 -0
- package/src/components/Toast/useToast.test.ts +122 -0
- package/src/components/Toast/useToast.ts +64 -0
- package/src/components/Toggle/Toggle.native.tsx +70 -0
- package/src/components/Toggle/Toggle.stories.tsx +34 -0
- package/src/components/Toggle/Toggle.types.ts +13 -0
- package/src/components/Toggle/Toggle.web.tsx +42 -0
- package/src/components/Toggle/index.native.ts +2 -0
- package/src/components/Toggle/index.ts +2 -0
- package/src/components/Toggle/useToggle.test.ts +48 -0
- package/src/components/Toggle/useToggle.ts +37 -0
- package/src/components/ToggleGroup/ToggleGroup.native.tsx +103 -0
- package/src/components/ToggleGroup/ToggleGroup.stories.tsx +24 -0
- package/src/components/ToggleGroup/ToggleGroup.types.ts +22 -0
- package/src/components/ToggleGroup/ToggleGroup.web.tsx +56 -0
- package/src/components/ToggleGroup/index.native.ts +2 -0
- package/src/components/ToggleGroup/index.ts +2 -0
- package/src/components/ToggleGroup/useToggleGroup.test.ts +79 -0
- package/src/components/ToggleGroup/useToggleGroup.ts +63 -0
- package/src/components/Tooltip/Tooltip.native.tsx +7 -0
- package/src/components/Tooltip/Tooltip.stories.tsx +32 -0
- package/src/components/Tooltip/Tooltip.types.ts +27 -0
- package/src/components/Tooltip/Tooltip.web.test.tsx +42 -0
- package/src/components/Tooltip/Tooltip.web.tsx +29 -0
- package/src/components/Tooltip/index.native.ts +2 -0
- package/src/components/Tooltip/index.ts +2 -0
- package/src/components/index.native.ts +50 -0
- package/src/components/index.ts +49 -0
- package/src/hooks/useControllableState.test.ts +89 -0
- package/src/hooks/useControllableState.ts +37 -0
- package/src/index.native.ts +20 -0
- package/src/index.ts +12 -0
- package/src/theme/native.ts +211 -0
- package/src/theme/presets/aurora.ts +56 -0
- package/src/theme/presets/dark.ts +30 -0
- package/src/theme/presets/default.ts +30 -0
- package/src/theme/theme.types.ts +64 -0
- package/src/theme/tokens.ts +31 -0
- package/src/theme/web.ts +123 -0
- package/src/uniwind.d.ts +38 -0
- package/src/utils/cn.native.ts +10 -0
- package/src/utils/cn.test.ts +28 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/glass.native.ts +22 -0
- package/src/utils/withGlass.native.tsx +59 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useRef,
|
|
3
|
+
useEffect,
|
|
4
|
+
createContext,
|
|
5
|
+
useContext,
|
|
6
|
+
type ReactNode,
|
|
7
|
+
} from "react";
|
|
8
|
+
import {
|
|
9
|
+
View,
|
|
10
|
+
Text,
|
|
11
|
+
Modal,
|
|
12
|
+
Pressable,
|
|
13
|
+
Animated,
|
|
14
|
+
Dimensions,
|
|
15
|
+
PanResponder,
|
|
16
|
+
type ViewProps,
|
|
17
|
+
type TextProps,
|
|
18
|
+
} from "react-native";
|
|
19
|
+
import { cn } from "../../utils/cn";
|
|
20
|
+
import type {
|
|
21
|
+
DrawerProps,
|
|
22
|
+
DrawerTriggerProps,
|
|
23
|
+
DrawerContentProps,
|
|
24
|
+
DrawerHeaderProps,
|
|
25
|
+
DrawerFooterProps,
|
|
26
|
+
DrawerTitleProps,
|
|
27
|
+
DrawerDescriptionProps,
|
|
28
|
+
DrawerCloseProps,
|
|
29
|
+
} from "./Drawer.types";
|
|
30
|
+
import { useDrawer } from "./useDrawer";
|
|
31
|
+
|
|
32
|
+
const { height: SCREEN_HEIGHT } = Dimensions.get("window");
|
|
33
|
+
|
|
34
|
+
interface DrawerContextValue {
|
|
35
|
+
open: boolean;
|
|
36
|
+
onOpenChange: (open: boolean) => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const DrawerContext = createContext<DrawerContextValue>({
|
|
40
|
+
open: false,
|
|
41
|
+
onOpenChange: () => {},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
function Drawer({
|
|
45
|
+
children,
|
|
46
|
+
open: controlledOpen,
|
|
47
|
+
onOpenChange: controlledOnOpenChange,
|
|
48
|
+
}: DrawerProps) {
|
|
49
|
+
const { open, onOpenChange } = useDrawer({
|
|
50
|
+
open: controlledOpen,
|
|
51
|
+
onOpenChange: controlledOnOpenChange,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<DrawerContext.Provider value={{ open, onOpenChange }}>
|
|
56
|
+
{children}
|
|
57
|
+
</DrawerContext.Provider>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
Drawer.displayName = "Drawer";
|
|
61
|
+
|
|
62
|
+
interface DrawerTriggerNativeProps extends DrawerTriggerProps {
|
|
63
|
+
onPress?: () => void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function DrawerTrigger({ children, onPress }: DrawerTriggerNativeProps) {
|
|
67
|
+
const { onOpenChange } = useContext(DrawerContext);
|
|
68
|
+
return (
|
|
69
|
+
<Pressable
|
|
70
|
+
onPress={() => {
|
|
71
|
+
onOpenChange(true);
|
|
72
|
+
onPress?.();
|
|
73
|
+
}}
|
|
74
|
+
>
|
|
75
|
+
{children}
|
|
76
|
+
</Pressable>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
DrawerTrigger.displayName = "DrawerTrigger";
|
|
80
|
+
|
|
81
|
+
interface DrawerContentNativeProps extends DrawerContentProps {}
|
|
82
|
+
|
|
83
|
+
const CLOSE_THRESHOLD = 100;
|
|
84
|
+
|
|
85
|
+
function DrawerContent({ children, className }: DrawerContentNativeProps) {
|
|
86
|
+
const { open, onOpenChange } = useContext(DrawerContext);
|
|
87
|
+
const translateY = useRef(new Animated.Value(SCREEN_HEIGHT)).current;
|
|
88
|
+
|
|
89
|
+
const panResponder = useRef(
|
|
90
|
+
PanResponder.create({
|
|
91
|
+
onStartShouldSetPanResponder: () => false,
|
|
92
|
+
onMoveShouldSetPanResponder: (_, gestureState) =>
|
|
93
|
+
gestureState.dy > 10,
|
|
94
|
+
onPanResponderMove: (_, gestureState) => {
|
|
95
|
+
if (gestureState.dy > 0) {
|
|
96
|
+
translateY.setValue(gestureState.dy);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
onPanResponderRelease: (_, gestureState) => {
|
|
100
|
+
if (gestureState.dy > CLOSE_THRESHOLD || gestureState.vy > 0.5) {
|
|
101
|
+
Animated.timing(translateY, {
|
|
102
|
+
toValue: SCREEN_HEIGHT,
|
|
103
|
+
duration: 250,
|
|
104
|
+
useNativeDriver: true,
|
|
105
|
+
}).start(() => onOpenChange(false));
|
|
106
|
+
} else {
|
|
107
|
+
Animated.spring(translateY, {
|
|
108
|
+
toValue: 0,
|
|
109
|
+
useNativeDriver: true,
|
|
110
|
+
damping: 20,
|
|
111
|
+
stiffness: 150,
|
|
112
|
+
}).start();
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
).current;
|
|
117
|
+
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (open) {
|
|
120
|
+
Animated.spring(translateY, {
|
|
121
|
+
toValue: 0,
|
|
122
|
+
useNativeDriver: true,
|
|
123
|
+
damping: 20,
|
|
124
|
+
stiffness: 150,
|
|
125
|
+
}).start();
|
|
126
|
+
} else {
|
|
127
|
+
Animated.timing(translateY, {
|
|
128
|
+
toValue: SCREEN_HEIGHT,
|
|
129
|
+
duration: 250,
|
|
130
|
+
useNativeDriver: true,
|
|
131
|
+
}).start();
|
|
132
|
+
}
|
|
133
|
+
}, [open, translateY]);
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<Modal
|
|
137
|
+
visible={open}
|
|
138
|
+
transparent
|
|
139
|
+
animationType="none"
|
|
140
|
+
onRequestClose={() => onOpenChange(false)}
|
|
141
|
+
>
|
|
142
|
+
<Pressable
|
|
143
|
+
className="flex-1 bg-black/50 justify-end"
|
|
144
|
+
onPress={() => onOpenChange(false)}
|
|
145
|
+
>
|
|
146
|
+
<Animated.View
|
|
147
|
+
className={cn(
|
|
148
|
+
"bg-background rounded-t-xl pb-8",
|
|
149
|
+
className,
|
|
150
|
+
)}
|
|
151
|
+
style={{
|
|
152
|
+
maxHeight: SCREEN_HEIGHT * 0.85,
|
|
153
|
+
transform: [{ translateY }],
|
|
154
|
+
}}
|
|
155
|
+
{...panResponder.panHandlers}
|
|
156
|
+
>
|
|
157
|
+
<Pressable onPress={(e) => e.stopPropagation()}>
|
|
158
|
+
<View className="w-[100px] h-1.5 bg-border rounded-full self-center mt-3 mb-2" />
|
|
159
|
+
{children}
|
|
160
|
+
</Pressable>
|
|
161
|
+
</Animated.View>
|
|
162
|
+
</Pressable>
|
|
163
|
+
</Modal>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
DrawerContent.displayName = "DrawerContent";
|
|
167
|
+
|
|
168
|
+
interface DrawerHeaderNativeProps extends DrawerHeaderProps {}
|
|
169
|
+
|
|
170
|
+
function DrawerHeader({ children, className }: DrawerHeaderNativeProps) {
|
|
171
|
+
return (
|
|
172
|
+
<View className={cn("p-4 items-center", className)}>
|
|
173
|
+
{children}
|
|
174
|
+
</View>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
DrawerHeader.displayName = "DrawerHeader";
|
|
178
|
+
|
|
179
|
+
interface DrawerFooterNativeProps extends DrawerFooterProps {}
|
|
180
|
+
|
|
181
|
+
function DrawerFooter({ children, className }: DrawerFooterNativeProps) {
|
|
182
|
+
return (
|
|
183
|
+
<View className={cn("p-4 gap-2", className)}>
|
|
184
|
+
{children}
|
|
185
|
+
</View>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
DrawerFooter.displayName = "DrawerFooter";
|
|
189
|
+
|
|
190
|
+
interface DrawerTitleNativeProps extends DrawerTitleProps {}
|
|
191
|
+
|
|
192
|
+
function DrawerTitle({ children, className }: DrawerTitleNativeProps) {
|
|
193
|
+
return (
|
|
194
|
+
<Text className={cn("text-lg font-semibold text-foreground", className)}>
|
|
195
|
+
{children}
|
|
196
|
+
</Text>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
DrawerTitle.displayName = "DrawerTitle";
|
|
200
|
+
|
|
201
|
+
interface DrawerDescriptionNativeProps extends DrawerDescriptionProps {}
|
|
202
|
+
|
|
203
|
+
function DrawerDescription({ children, className }: DrawerDescriptionNativeProps) {
|
|
204
|
+
return (
|
|
205
|
+
<Text className={cn("text-sm text-muted-foreground mt-1", className)}>
|
|
206
|
+
{children}
|
|
207
|
+
</Text>
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
DrawerDescription.displayName = "DrawerDescription";
|
|
211
|
+
|
|
212
|
+
interface DrawerCloseNativeProps extends DrawerCloseProps {
|
|
213
|
+
onPress?: () => void;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function DrawerClose({ children, onPress }: DrawerCloseNativeProps) {
|
|
217
|
+
const { onOpenChange } = useContext(DrawerContext);
|
|
218
|
+
return (
|
|
219
|
+
<Pressable
|
|
220
|
+
onPress={() => {
|
|
221
|
+
onOpenChange(false);
|
|
222
|
+
onPress?.();
|
|
223
|
+
}}
|
|
224
|
+
>
|
|
225
|
+
{children || (
|
|
226
|
+
<Text className="text-sm text-muted-foreground text-center">
|
|
227
|
+
Close
|
|
228
|
+
</Text>
|
|
229
|
+
)}
|
|
230
|
+
</Pressable>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
DrawerClose.displayName = "DrawerClose";
|
|
234
|
+
|
|
235
|
+
export {
|
|
236
|
+
Drawer,
|
|
237
|
+
DrawerTrigger,
|
|
238
|
+
DrawerContent,
|
|
239
|
+
DrawerHeader,
|
|
240
|
+
DrawerFooter,
|
|
241
|
+
DrawerTitle,
|
|
242
|
+
DrawerDescription,
|
|
243
|
+
DrawerClose,
|
|
244
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import {
|
|
3
|
+
Drawer,
|
|
4
|
+
DrawerTrigger,
|
|
5
|
+
DrawerContent,
|
|
6
|
+
DrawerHeader,
|
|
7
|
+
DrawerFooter,
|
|
8
|
+
DrawerTitle,
|
|
9
|
+
DrawerDescription,
|
|
10
|
+
} from "./Drawer.web";
|
|
11
|
+
|
|
12
|
+
const meta: Meta<typeof Drawer> = {
|
|
13
|
+
title: "Components/Drawer",
|
|
14
|
+
component: Drawer,
|
|
15
|
+
tags: ["autodocs"],
|
|
16
|
+
parameters: { layout: "centered" },
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default meta;
|
|
20
|
+
type Story = StoryObj<typeof Drawer>;
|
|
21
|
+
|
|
22
|
+
export const Default: Story = {
|
|
23
|
+
render: () => (
|
|
24
|
+
<Drawer>
|
|
25
|
+
<DrawerTrigger>Open Drawer</DrawerTrigger>
|
|
26
|
+
<DrawerContent>
|
|
27
|
+
<DrawerHeader>
|
|
28
|
+
<DrawerTitle>Edit Profile</DrawerTitle>
|
|
29
|
+
<DrawerDescription>
|
|
30
|
+
Make changes to your profile here. Click save when you're done.
|
|
31
|
+
</DrawerDescription>
|
|
32
|
+
</DrawerHeader>
|
|
33
|
+
<DrawerFooter>
|
|
34
|
+
<button>Save changes</button>
|
|
35
|
+
</DrawerFooter>
|
|
36
|
+
</DrawerContent>
|
|
37
|
+
</Drawer>
|
|
38
|
+
),
|
|
39
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
export interface DrawerProps {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
open?: boolean;
|
|
6
|
+
onOpenChange?: (open: boolean) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface DrawerTriggerProps {
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
className?: string;
|
|
12
|
+
asChild?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface DrawerContentProps {
|
|
16
|
+
children?: ReactNode;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface DrawerHeaderProps {
|
|
21
|
+
children?: ReactNode;
|
|
22
|
+
className?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface DrawerFooterProps {
|
|
26
|
+
children?: ReactNode;
|
|
27
|
+
className?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface DrawerTitleProps {
|
|
31
|
+
children?: ReactNode;
|
|
32
|
+
className?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface DrawerDescriptionProps {
|
|
36
|
+
children?: ReactNode;
|
|
37
|
+
className?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface DrawerCloseProps {
|
|
41
|
+
children?: ReactNode;
|
|
42
|
+
className?: string;
|
|
43
|
+
asChild?: boolean;
|
|
44
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Drawer as DrawerPrimitive } from "vaul";
|
|
2
|
+
import { cn } from "../../utils/cn";
|
|
3
|
+
|
|
4
|
+
function Drawer({
|
|
5
|
+
...props
|
|
6
|
+
}: React.ComponentProps<typeof DrawerPrimitive.Root>) {
|
|
7
|
+
return <DrawerPrimitive.Root {...props} />;
|
|
8
|
+
}
|
|
9
|
+
Drawer.displayName = "Drawer";
|
|
10
|
+
|
|
11
|
+
function DrawerTrigger({
|
|
12
|
+
...props
|
|
13
|
+
}: React.ComponentProps<typeof DrawerPrimitive.Trigger>) {
|
|
14
|
+
return <DrawerPrimitive.Trigger {...props} />;
|
|
15
|
+
}
|
|
16
|
+
DrawerTrigger.displayName = "DrawerTrigger";
|
|
17
|
+
|
|
18
|
+
function DrawerPortal({
|
|
19
|
+
...props
|
|
20
|
+
}: React.ComponentProps<typeof DrawerPrimitive.Portal>) {
|
|
21
|
+
return <DrawerPrimitive.Portal {...props} />;
|
|
22
|
+
}
|
|
23
|
+
DrawerPortal.displayName = "DrawerPortal";
|
|
24
|
+
|
|
25
|
+
function DrawerClose({
|
|
26
|
+
...props
|
|
27
|
+
}: React.ComponentProps<typeof DrawerPrimitive.Close>) {
|
|
28
|
+
return <DrawerPrimitive.Close {...props} />;
|
|
29
|
+
}
|
|
30
|
+
DrawerClose.displayName = "DrawerClose";
|
|
31
|
+
|
|
32
|
+
function DrawerOverlay({
|
|
33
|
+
className,
|
|
34
|
+
...props
|
|
35
|
+
}: React.ComponentProps<typeof DrawerPrimitive.Overlay>) {
|
|
36
|
+
return (
|
|
37
|
+
<DrawerPrimitive.Overlay
|
|
38
|
+
className={cn(
|
|
39
|
+
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
|
40
|
+
className,
|
|
41
|
+
)}
|
|
42
|
+
{...props}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
DrawerOverlay.displayName = "DrawerOverlay";
|
|
47
|
+
|
|
48
|
+
function DrawerContent({
|
|
49
|
+
className,
|
|
50
|
+
children,
|
|
51
|
+
...props
|
|
52
|
+
}: React.ComponentProps<typeof DrawerPrimitive.Content>) {
|
|
53
|
+
return (
|
|
54
|
+
<DrawerPortal>
|
|
55
|
+
<DrawerOverlay />
|
|
56
|
+
<DrawerPrimitive.Content
|
|
57
|
+
className={cn(
|
|
58
|
+
"fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background text-foreground",
|
|
59
|
+
className,
|
|
60
|
+
)}
|
|
61
|
+
{...props}
|
|
62
|
+
>
|
|
63
|
+
<div className="mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" />
|
|
64
|
+
{children}
|
|
65
|
+
</DrawerPrimitive.Content>
|
|
66
|
+
</DrawerPortal>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
DrawerContent.displayName = "DrawerContent";
|
|
70
|
+
|
|
71
|
+
const DrawerHeader = ({
|
|
72
|
+
className,
|
|
73
|
+
...props
|
|
74
|
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
75
|
+
<div
|
|
76
|
+
className={cn("grid gap-1.5 p-4 text-center sm:text-left", className)}
|
|
77
|
+
{...props}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
DrawerHeader.displayName = "DrawerHeader";
|
|
81
|
+
|
|
82
|
+
const DrawerFooter = ({
|
|
83
|
+
className,
|
|
84
|
+
...props
|
|
85
|
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
86
|
+
<div
|
|
87
|
+
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
|
|
88
|
+
{...props}
|
|
89
|
+
/>
|
|
90
|
+
);
|
|
91
|
+
DrawerFooter.displayName = "DrawerFooter";
|
|
92
|
+
|
|
93
|
+
function DrawerTitle({
|
|
94
|
+
className,
|
|
95
|
+
...props
|
|
96
|
+
}: React.ComponentProps<typeof DrawerPrimitive.Title>) {
|
|
97
|
+
return (
|
|
98
|
+
<DrawerPrimitive.Title
|
|
99
|
+
className={cn(
|
|
100
|
+
"text-lg font-semibold leading-none tracking-tight",
|
|
101
|
+
className,
|
|
102
|
+
)}
|
|
103
|
+
{...props}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
DrawerTitle.displayName = "DrawerTitle";
|
|
108
|
+
|
|
109
|
+
function DrawerDescription({
|
|
110
|
+
className,
|
|
111
|
+
...props
|
|
112
|
+
}: React.ComponentProps<typeof DrawerPrimitive.Description>) {
|
|
113
|
+
return (
|
|
114
|
+
<DrawerPrimitive.Description
|
|
115
|
+
className={cn("text-sm text-muted-foreground", className)}
|
|
116
|
+
{...props}
|
|
117
|
+
/>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
DrawerDescription.displayName = "DrawerDescription";
|
|
121
|
+
|
|
122
|
+
export {
|
|
123
|
+
Drawer,
|
|
124
|
+
DrawerPortal,
|
|
125
|
+
DrawerOverlay,
|
|
126
|
+
DrawerTrigger,
|
|
127
|
+
DrawerClose,
|
|
128
|
+
DrawerContent,
|
|
129
|
+
DrawerHeader,
|
|
130
|
+
DrawerFooter,
|
|
131
|
+
DrawerTitle,
|
|
132
|
+
DrawerDescription,
|
|
133
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { renderHook, act } from "@testing-library/react";
|
|
3
|
+
import { useDrawer } from "./useDrawer";
|
|
4
|
+
|
|
5
|
+
describe("useDrawer", () => {
|
|
6
|
+
it("defaults to closed", () => {
|
|
7
|
+
const { result } = renderHook(() => useDrawer());
|
|
8
|
+
expect(result.current.open).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("opens via onOpenChange", () => {
|
|
12
|
+
const { result } = renderHook(() => useDrawer());
|
|
13
|
+
act(() => result.current.onOpenChange(true));
|
|
14
|
+
expect(result.current.open).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("calls external onOpenChange", () => {
|
|
18
|
+
const onChange = vi.fn();
|
|
19
|
+
const { result } = renderHook(() => useDrawer({ onOpenChange: onChange }));
|
|
20
|
+
act(() => result.current.onOpenChange(true));
|
|
21
|
+
expect(onChange).toHaveBeenCalledWith(true);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("works in controlled mode", () => {
|
|
25
|
+
const onChange = vi.fn();
|
|
26
|
+
const { result } = renderHook(() =>
|
|
27
|
+
useDrawer({ open: false, onOpenChange: onChange }),
|
|
28
|
+
);
|
|
29
|
+
act(() => result.current.onOpenChange(true));
|
|
30
|
+
expect(result.current.open).toBe(false);
|
|
31
|
+
expect(onChange).toHaveBeenCalledWith(true);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useControllableState } from "../../hooks/useControllableState";
|
|
2
|
+
|
|
3
|
+
interface UseDrawerProps {
|
|
4
|
+
open?: boolean;
|
|
5
|
+
onOpenChange?: (open: boolean) => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function useDrawer({ open: controlledOpen, onOpenChange }: UseDrawerProps = {}) {
|
|
9
|
+
const [open, setOpen] = useControllableState<boolean>({
|
|
10
|
+
value: controlledOpen,
|
|
11
|
+
defaultValue: false,
|
|
12
|
+
onChange: onOpenChange,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
open,
|
|
17
|
+
onOpenChange: setOpen,
|
|
18
|
+
};
|
|
19
|
+
}
|