@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,111 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { renderHook, act } from "@testing-library/react";
|
|
3
|
+
import { useCarouselState } from "./useCarousel";
|
|
4
|
+
|
|
5
|
+
describe("useCarouselState", () => {
|
|
6
|
+
it("starts at index 0", () => {
|
|
7
|
+
const { result } = renderHook(() => useCarouselState());
|
|
8
|
+
expect(result.current.currentIndex).toBe(0);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("defaults to horizontal orientation", () => {
|
|
12
|
+
const { result } = renderHook(() => useCarouselState());
|
|
13
|
+
expect(result.current.orientation).toBe("horizontal");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("cannot scroll previous at index 0", () => {
|
|
17
|
+
const { result } = renderHook(() => useCarouselState());
|
|
18
|
+
expect(result.current.canScrollPrevious).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("cannot scroll next when totalItems is 0", () => {
|
|
22
|
+
const { result } = renderHook(() => useCarouselState());
|
|
23
|
+
expect(result.current.canScrollNext).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("scrolls next", () => {
|
|
27
|
+
const { result } = renderHook(() => useCarouselState());
|
|
28
|
+
|
|
29
|
+
act(() => result.current.setTotalItems(5));
|
|
30
|
+
act(() => {
|
|
31
|
+
const pos = result.current.scrollNext();
|
|
32
|
+
expect(pos.index).toBe(1);
|
|
33
|
+
});
|
|
34
|
+
expect(result.current.currentIndex).toBe(1);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("scrolls previous", () => {
|
|
38
|
+
const { result } = renderHook(() => useCarouselState());
|
|
39
|
+
|
|
40
|
+
act(() => result.current.setTotalItems(5));
|
|
41
|
+
act(() => result.current.scrollNext());
|
|
42
|
+
act(() => result.current.scrollNext());
|
|
43
|
+
act(() => {
|
|
44
|
+
const pos = result.current.scrollPrevious();
|
|
45
|
+
expect(pos.index).toBe(1);
|
|
46
|
+
});
|
|
47
|
+
expect(result.current.currentIndex).toBe(1);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("does not scroll past the last item", () => {
|
|
51
|
+
const { result } = renderHook(() => useCarouselState());
|
|
52
|
+
|
|
53
|
+
act(() => result.current.setTotalItems(2));
|
|
54
|
+
act(() => result.current.scrollNext());
|
|
55
|
+
act(() => result.current.scrollNext()); // Should stay at index 1
|
|
56
|
+
expect(result.current.currentIndex).toBe(1);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("does not scroll before index 0", () => {
|
|
60
|
+
const { result } = renderHook(() => useCarouselState());
|
|
61
|
+
act(() => result.current.scrollPrevious());
|
|
62
|
+
expect(result.current.currentIndex).toBe(0);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("computes scroll position for horizontal", () => {
|
|
66
|
+
const { result } = renderHook(() => useCarouselState());
|
|
67
|
+
|
|
68
|
+
act(() => {
|
|
69
|
+
result.current.setTotalItems(5);
|
|
70
|
+
result.current.setItemWidth(200);
|
|
71
|
+
});
|
|
72
|
+
act(() => {
|
|
73
|
+
const pos = result.current.scrollNext();
|
|
74
|
+
expect(pos.x).toBe(200);
|
|
75
|
+
expect(pos.y).toBe(0);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("computes scroll position for vertical", () => {
|
|
80
|
+
const { result } = renderHook(() =>
|
|
81
|
+
useCarouselState({ orientation: "vertical" }),
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
act(() => {
|
|
85
|
+
result.current.setTotalItems(5);
|
|
86
|
+
result.current.setItemWidth(200);
|
|
87
|
+
});
|
|
88
|
+
act(() => {
|
|
89
|
+
const pos = result.current.scrollNext();
|
|
90
|
+
expect(pos.x).toBe(0);
|
|
91
|
+
expect(pos.y).toBe(200);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("reports canScrollPrevious and canScrollNext correctly", () => {
|
|
96
|
+
const { result } = renderHook(() => useCarouselState());
|
|
97
|
+
|
|
98
|
+
act(() => result.current.setTotalItems(3));
|
|
99
|
+
|
|
100
|
+
expect(result.current.canScrollPrevious).toBe(false);
|
|
101
|
+
expect(result.current.canScrollNext).toBe(true);
|
|
102
|
+
|
|
103
|
+
act(() => result.current.scrollNext());
|
|
104
|
+
expect(result.current.canScrollPrevious).toBe(true);
|
|
105
|
+
expect(result.current.canScrollNext).toBe(true);
|
|
106
|
+
|
|
107
|
+
act(() => result.current.scrollNext());
|
|
108
|
+
expect(result.current.canScrollPrevious).toBe(true);
|
|
109
|
+
expect(result.current.canScrollNext).toBe(false);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
|
+
import type { CarouselOrientation } from "./Carousel.types";
|
|
3
|
+
|
|
4
|
+
interface UseCarouselProps {
|
|
5
|
+
orientation?: CarouselOrientation;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function useCarouselState({ orientation = "horizontal" }: UseCarouselProps = {}) {
|
|
9
|
+
const [currentIndex, setCurrentIndex] = useState(0);
|
|
10
|
+
const [totalItems, setTotalItems] = useState(0);
|
|
11
|
+
const [itemWidth, setItemWidth] = useState(0);
|
|
12
|
+
|
|
13
|
+
const canScrollPrevious = currentIndex > 0;
|
|
14
|
+
const canScrollNext = currentIndex < totalItems - 1;
|
|
15
|
+
|
|
16
|
+
const scrollPrevious = useCallback(() => {
|
|
17
|
+
const newIndex = Math.max(0, currentIndex - 1);
|
|
18
|
+
setCurrentIndex(newIndex);
|
|
19
|
+
return {
|
|
20
|
+
index: newIndex,
|
|
21
|
+
x: orientation === "horizontal" ? newIndex * itemWidth : 0,
|
|
22
|
+
y: orientation === "vertical" ? newIndex * itemWidth : 0,
|
|
23
|
+
};
|
|
24
|
+
}, [currentIndex, itemWidth, orientation]);
|
|
25
|
+
|
|
26
|
+
const scrollNext = useCallback(() => {
|
|
27
|
+
const newIndex = Math.min(totalItems - 1, currentIndex + 1);
|
|
28
|
+
setCurrentIndex(newIndex);
|
|
29
|
+
return {
|
|
30
|
+
index: newIndex,
|
|
31
|
+
x: orientation === "horizontal" ? newIndex * itemWidth : 0,
|
|
32
|
+
y: orientation === "vertical" ? newIndex * itemWidth : 0,
|
|
33
|
+
};
|
|
34
|
+
}, [currentIndex, totalItems, itemWidth, orientation]);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
orientation,
|
|
38
|
+
currentIndex,
|
|
39
|
+
totalItems,
|
|
40
|
+
setTotalItems,
|
|
41
|
+
itemWidth,
|
|
42
|
+
setItemWidth,
|
|
43
|
+
canScrollPrevious,
|
|
44
|
+
canScrollNext,
|
|
45
|
+
scrollPrevious,
|
|
46
|
+
scrollNext,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { Chart } from "./Chart.web";
|
|
3
|
+
import type { ChartConfig } from "./Chart.types";
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: "Components/Chart",
|
|
7
|
+
component: Chart,
|
|
8
|
+
parameters: {
|
|
9
|
+
layout: "centered",
|
|
10
|
+
},
|
|
11
|
+
tags: ["autodocs"],
|
|
12
|
+
} satisfies Meta<typeof Chart>;
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
type Story = StoryObj<typeof meta>;
|
|
16
|
+
|
|
17
|
+
const sampleConfig: ChartConfig = {
|
|
18
|
+
revenue: {
|
|
19
|
+
label: "Revenue",
|
|
20
|
+
color: "hsl(221.2 83.2% 53.3%)",
|
|
21
|
+
},
|
|
22
|
+
expenses: {
|
|
23
|
+
label: "Expenses",
|
|
24
|
+
color: "hsl(0 84.2% 60.2%)",
|
|
25
|
+
},
|
|
26
|
+
profit: {
|
|
27
|
+
label: "Profit",
|
|
28
|
+
color: "hsl(142.1 76.2% 36.3%)",
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const Default: Story = {
|
|
33
|
+
args: { config: sampleConfig },
|
|
34
|
+
render: () => (
|
|
35
|
+
<Chart config={sampleConfig} style={{ width: 400, height: 250 }}>
|
|
36
|
+
<div className="flex h-full flex-col items-center justify-center gap-4">
|
|
37
|
+
<p className="text-sm text-muted-foreground">
|
|
38
|
+
Chart container with CSS color variables applied.
|
|
39
|
+
</p>
|
|
40
|
+
<div className="flex gap-4">
|
|
41
|
+
{Object.entries(sampleConfig).map(([key, value]) => (
|
|
42
|
+
<div key={key} className="flex items-center gap-2">
|
|
43
|
+
<div
|
|
44
|
+
className="h-3 w-3 rounded-full"
|
|
45
|
+
style={{ backgroundColor: `var(--color-${key})` }}
|
|
46
|
+
/>
|
|
47
|
+
<span className="text-xs">{value.label}</span>
|
|
48
|
+
</div>
|
|
49
|
+
))}
|
|
50
|
+
</div>
|
|
51
|
+
<p className="text-xs text-muted-foreground">
|
|
52
|
+
Wrap Recharts components inside this container for themed charts.
|
|
53
|
+
</p>
|
|
54
|
+
</div>
|
|
55
|
+
</Chart>
|
|
56
|
+
),
|
|
57
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { forwardRef, useMemo } from "react";
|
|
2
|
+
import { cn } from "../../utils/cn";
|
|
3
|
+
import type { ChartConfig, ChartProps } from "./Chart.types";
|
|
4
|
+
|
|
5
|
+
const Chart = forwardRef<
|
|
6
|
+
HTMLDivElement,
|
|
7
|
+
ChartProps & React.HTMLAttributes<HTMLDivElement>
|
|
8
|
+
>(({ className, config, children, ...props }, ref) => {
|
|
9
|
+
const cssVars = useMemo(() => {
|
|
10
|
+
const vars: Record<string, string> = {};
|
|
11
|
+
Object.entries(config).forEach(([key, value]) => {
|
|
12
|
+
if (value.color) {
|
|
13
|
+
vars[`--color-${key}`] = value.color;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return vars;
|
|
17
|
+
}, [config]);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<div
|
|
21
|
+
ref={ref}
|
|
22
|
+
className={cn(
|
|
23
|
+
"flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none",
|
|
24
|
+
className,
|
|
25
|
+
)}
|
|
26
|
+
style={cssVars as React.CSSProperties}
|
|
27
|
+
{...props}
|
|
28
|
+
>
|
|
29
|
+
{children}
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
Chart.displayName = "Chart";
|
|
34
|
+
|
|
35
|
+
export { Chart };
|
|
36
|
+
export type { ChartConfig };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Pressable, type PressableProps } from "react-native";
|
|
2
|
+
import { Check } from "lucide-react-native";
|
|
3
|
+
import type { CheckboxProps } from "./Checkbox.types";
|
|
4
|
+
import { useCheckbox } from "./useCheckbox";
|
|
5
|
+
import { Icon } from "../Icon/Icon.native";
|
|
6
|
+
import { cn } from "../../utils/cn";
|
|
7
|
+
|
|
8
|
+
interface CheckboxNativeProps extends CheckboxProps, Omit<PressableProps, "onPress" | "children" | "disabled"> {}
|
|
9
|
+
|
|
10
|
+
function Checkbox({
|
|
11
|
+
checked: controlledChecked,
|
|
12
|
+
defaultChecked,
|
|
13
|
+
onCheckedChange,
|
|
14
|
+
disabled: disabledProp,
|
|
15
|
+
...props
|
|
16
|
+
}: CheckboxNativeProps) {
|
|
17
|
+
const { checked, disabled, toggle } = useCheckbox({
|
|
18
|
+
checked: controlledChecked,
|
|
19
|
+
defaultChecked,
|
|
20
|
+
onCheckedChange,
|
|
21
|
+
disabled: disabledProp,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Pressable
|
|
26
|
+
onPress={toggle}
|
|
27
|
+
disabled={disabled}
|
|
28
|
+
className={cn(
|
|
29
|
+
"w-4 h-4 rounded-sm border items-center justify-center shadow-sm elevation-1",
|
|
30
|
+
checked ? "border-primary bg-primary" : "border-primary bg-transparent",
|
|
31
|
+
disabled && "opacity-50",
|
|
32
|
+
)}
|
|
33
|
+
accessibilityRole="checkbox"
|
|
34
|
+
accessibilityState={{ checked, disabled }}
|
|
35
|
+
{...props}
|
|
36
|
+
>
|
|
37
|
+
{checked && (
|
|
38
|
+
<Icon icon={Check} size={12} strokeWidth={3} className="text-primary-foreground" />
|
|
39
|
+
)}
|
|
40
|
+
</Pressable>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
Checkbox.displayName = "Checkbox";
|
|
45
|
+
|
|
46
|
+
export { Checkbox };
|
|
47
|
+
export type { CheckboxNativeProps };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { Checkbox } from "./Checkbox.web";
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: "Components/Checkbox",
|
|
6
|
+
component: Checkbox,
|
|
7
|
+
parameters: {
|
|
8
|
+
layout: "centered",
|
|
9
|
+
},
|
|
10
|
+
tags: ["autodocs"],
|
|
11
|
+
} satisfies Meta<typeof Checkbox>;
|
|
12
|
+
|
|
13
|
+
export default meta;
|
|
14
|
+
type Story = StoryObj<typeof meta>;
|
|
15
|
+
|
|
16
|
+
export const Default: Story = {
|
|
17
|
+
args: {},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const Checked: Story = {
|
|
21
|
+
args: {
|
|
22
|
+
defaultChecked: true,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const Disabled: Story = {
|
|
27
|
+
args: {
|
|
28
|
+
disabled: true,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface CheckboxProps {
|
|
2
|
+
checked?: boolean;
|
|
3
|
+
defaultChecked?: boolean;
|
|
4
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
required?: boolean;
|
|
7
|
+
name?: string;
|
|
8
|
+
value?: string;
|
|
9
|
+
id?: string;
|
|
10
|
+
className?: string;
|
|
11
|
+
children?: React.ReactNode;
|
|
12
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
|
3
|
+
import { cn } from "../../utils/cn";
|
|
4
|
+
|
|
5
|
+
const Checkbox = forwardRef<
|
|
6
|
+
React.ComponentRef<typeof CheckboxPrimitive.Root>,
|
|
7
|
+
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
|
|
8
|
+
>(({ className, ...props }, ref) => (
|
|
9
|
+
<CheckboxPrimitive.Root
|
|
10
|
+
ref={ref}
|
|
11
|
+
className={cn(
|
|
12
|
+
"peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
|
|
13
|
+
className,
|
|
14
|
+
)}
|
|
15
|
+
{...props}
|
|
16
|
+
>
|
|
17
|
+
<CheckboxPrimitive.Indicator
|
|
18
|
+
className={cn("flex items-center justify-center text-current")}
|
|
19
|
+
>
|
|
20
|
+
<svg
|
|
21
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
22
|
+
viewBox="0 0 24 24"
|
|
23
|
+
fill="none"
|
|
24
|
+
stroke="currentColor"
|
|
25
|
+
strokeWidth="3"
|
|
26
|
+
strokeLinecap="round"
|
|
27
|
+
strokeLinejoin="round"
|
|
28
|
+
className="h-3.5 w-3.5"
|
|
29
|
+
>
|
|
30
|
+
<polyline points="20 6 9 17 4 12" />
|
|
31
|
+
</svg>
|
|
32
|
+
</CheckboxPrimitive.Indicator>
|
|
33
|
+
</CheckboxPrimitive.Root>
|
|
34
|
+
));
|
|
35
|
+
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
|
|
36
|
+
|
|
37
|
+
export { Checkbox };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { renderHook, act } from "@testing-library/react";
|
|
3
|
+
import { useCheckbox } from "./useCheckbox";
|
|
4
|
+
|
|
5
|
+
describe("useCheckbox", () => {
|
|
6
|
+
it("defaults to unchecked", () => {
|
|
7
|
+
const { result } = renderHook(() => useCheckbox({}));
|
|
8
|
+
expect(result.current.checked).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("uses defaultChecked", () => {
|
|
12
|
+
const { result } = renderHook(() =>
|
|
13
|
+
useCheckbox({ defaultChecked: true }),
|
|
14
|
+
);
|
|
15
|
+
expect(result.current.checked).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("toggles from unchecked to checked", () => {
|
|
19
|
+
const { result } = renderHook(() => useCheckbox({}));
|
|
20
|
+
act(() => result.current.toggle());
|
|
21
|
+
expect(result.current.checked).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("toggles from checked to unchecked", () => {
|
|
25
|
+
const { result } = renderHook(() =>
|
|
26
|
+
useCheckbox({ defaultChecked: true }),
|
|
27
|
+
);
|
|
28
|
+
act(() => result.current.toggle());
|
|
29
|
+
expect(result.current.checked).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("calls onCheckedChange on toggle", () => {
|
|
33
|
+
const onChange = vi.fn();
|
|
34
|
+
const { result } = renderHook(() =>
|
|
35
|
+
useCheckbox({ onCheckedChange: onChange }),
|
|
36
|
+
);
|
|
37
|
+
act(() => result.current.toggle());
|
|
38
|
+
expect(onChange).toHaveBeenCalledWith(true);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("does not toggle when disabled", () => {
|
|
42
|
+
const { result } = renderHook(() =>
|
|
43
|
+
useCheckbox({ disabled: true }),
|
|
44
|
+
);
|
|
45
|
+
act(() => result.current.toggle());
|
|
46
|
+
expect(result.current.checked).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("works in controlled mode", () => {
|
|
50
|
+
const onChange = vi.fn();
|
|
51
|
+
const { result } = renderHook(() =>
|
|
52
|
+
useCheckbox({ checked: false, onCheckedChange: onChange }),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
act(() => result.current.toggle());
|
|
56
|
+
expect(result.current.checked).toBe(false);
|
|
57
|
+
expect(onChange).toHaveBeenCalledWith(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("exposes disabled state", () => {
|
|
61
|
+
const { result } = renderHook(() =>
|
|
62
|
+
useCheckbox({ disabled: true }),
|
|
63
|
+
);
|
|
64
|
+
expect(result.current.disabled).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { useControllableState } from "../../hooks/useControllableState";
|
|
3
|
+
|
|
4
|
+
interface UseCheckboxProps {
|
|
5
|
+
checked?: boolean;
|
|
6
|
+
defaultChecked?: boolean;
|
|
7
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface UseCheckboxReturn {
|
|
12
|
+
checked: boolean;
|
|
13
|
+
disabled: boolean;
|
|
14
|
+
toggle: () => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function useCheckbox({
|
|
18
|
+
checked: controlledChecked,
|
|
19
|
+
defaultChecked = false,
|
|
20
|
+
onCheckedChange,
|
|
21
|
+
disabled = false,
|
|
22
|
+
}: UseCheckboxProps): UseCheckboxReturn {
|
|
23
|
+
const [checked, setChecked] = useControllableState({
|
|
24
|
+
value: controlledChecked,
|
|
25
|
+
defaultValue: defaultChecked,
|
|
26
|
+
onChange: onCheckedChange,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const toggle = useCallback(() => {
|
|
30
|
+
if (disabled) return;
|
|
31
|
+
setChecked((prev) => !prev);
|
|
32
|
+
}, [disabled, setChecked]);
|
|
33
|
+
|
|
34
|
+
return { checked, disabled, toggle };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type { UseCheckboxProps, UseCheckboxReturn };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
Pressable,
|
|
5
|
+
LayoutAnimation,
|
|
6
|
+
Platform,
|
|
7
|
+
UIManager,
|
|
8
|
+
type ViewProps,
|
|
9
|
+
type PressableProps,
|
|
10
|
+
} from "react-native";
|
|
11
|
+
import type {
|
|
12
|
+
CollapsibleProps,
|
|
13
|
+
CollapsibleTriggerProps,
|
|
14
|
+
CollapsibleContentProps,
|
|
15
|
+
} from "./Collapsible.types";
|
|
16
|
+
import { useCollapsible } from "./useCollapsible";
|
|
17
|
+
|
|
18
|
+
if (
|
|
19
|
+
Platform.OS === "android" &&
|
|
20
|
+
UIManager.setLayoutAnimationEnabledExperimental
|
|
21
|
+
) {
|
|
22
|
+
UIManager.setLayoutAnimationEnabledExperimental(true);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface CollapsibleContextValue {
|
|
26
|
+
open: boolean;
|
|
27
|
+
onOpenChange: (open: boolean) => void;
|
|
28
|
+
disabled: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const CollapsibleContext = createContext<CollapsibleContextValue>({
|
|
32
|
+
open: false,
|
|
33
|
+
onOpenChange: () => {},
|
|
34
|
+
disabled: false,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
interface CollapsibleNativeProps extends CollapsibleProps, ViewProps {}
|
|
38
|
+
|
|
39
|
+
function Collapsible({
|
|
40
|
+
open: controlledOpen,
|
|
41
|
+
defaultOpen,
|
|
42
|
+
onOpenChange: onOpenChangeProp,
|
|
43
|
+
disabled: disabledProp,
|
|
44
|
+
children,
|
|
45
|
+
...props
|
|
46
|
+
}: CollapsibleNativeProps) {
|
|
47
|
+
const { open, disabled, setOpen } = useCollapsible({
|
|
48
|
+
open: controlledOpen,
|
|
49
|
+
defaultOpen,
|
|
50
|
+
onOpenChange: onOpenChangeProp,
|
|
51
|
+
disabled: disabledProp,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const handleOpenChange = (next: boolean) => {
|
|
55
|
+
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
|
|
56
|
+
setOpen(next);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<CollapsibleContext.Provider
|
|
61
|
+
value={{ open, onOpenChange: handleOpenChange, disabled }}
|
|
62
|
+
>
|
|
63
|
+
<View {...props}>{children}</View>
|
|
64
|
+
</CollapsibleContext.Provider>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface CollapsibleTriggerNativeProps extends Omit<CollapsibleTriggerProps, "asChild" | "children">, PressableProps {}
|
|
69
|
+
|
|
70
|
+
function CollapsibleTrigger({
|
|
71
|
+
children,
|
|
72
|
+
...props
|
|
73
|
+
}: CollapsibleTriggerNativeProps) {
|
|
74
|
+
const { open, onOpenChange, disabled } = useContext(CollapsibleContext);
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<Pressable
|
|
78
|
+
onPress={() => onOpenChange(!open)}
|
|
79
|
+
disabled={disabled}
|
|
80
|
+
accessibilityRole="button"
|
|
81
|
+
accessibilityState={{ expanded: open }}
|
|
82
|
+
{...props}
|
|
83
|
+
>
|
|
84
|
+
{children}
|
|
85
|
+
</Pressable>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface CollapsibleContentNativeProps extends CollapsibleContentProps, ViewProps {}
|
|
90
|
+
|
|
91
|
+
function CollapsibleContent({
|
|
92
|
+
children,
|
|
93
|
+
...props
|
|
94
|
+
}: CollapsibleContentNativeProps) {
|
|
95
|
+
const { open } = useContext(CollapsibleContext);
|
|
96
|
+
|
|
97
|
+
if (!open) return null;
|
|
98
|
+
|
|
99
|
+
return <View {...props}>{children}</View>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
Collapsible.displayName = "Collapsible";
|
|
103
|
+
CollapsibleTrigger.displayName = "CollapsibleTrigger";
|
|
104
|
+
CollapsibleContent.displayName = "CollapsibleContent";
|
|
105
|
+
|
|
106
|
+
export { Collapsible, CollapsibleTrigger, CollapsibleContent };
|
|
107
|
+
export type {
|
|
108
|
+
CollapsibleNativeProps,
|
|
109
|
+
CollapsibleTriggerNativeProps,
|
|
110
|
+
CollapsibleContentNativeProps,
|
|
111
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import {
|
|
3
|
+
Collapsible,
|
|
4
|
+
CollapsibleTrigger,
|
|
5
|
+
CollapsibleContent,
|
|
6
|
+
} from "./Collapsible.web";
|
|
7
|
+
|
|
8
|
+
const meta = {
|
|
9
|
+
title: "Components/Collapsible",
|
|
10
|
+
component: Collapsible,
|
|
11
|
+
parameters: {
|
|
12
|
+
layout: "centered",
|
|
13
|
+
},
|
|
14
|
+
tags: ["autodocs"],
|
|
15
|
+
} satisfies Meta<typeof Collapsible>;
|
|
16
|
+
|
|
17
|
+
export default meta;
|
|
18
|
+
type Story = StoryObj<typeof meta>;
|
|
19
|
+
|
|
20
|
+
export const Default: Story = {
|
|
21
|
+
args: {
|
|
22
|
+
style: { width: 360 },
|
|
23
|
+
children: (
|
|
24
|
+
<>
|
|
25
|
+
<CollapsibleTrigger asChild>
|
|
26
|
+
<button>Toggle content</button>
|
|
27
|
+
</CollapsibleTrigger>
|
|
28
|
+
<CollapsibleContent>
|
|
29
|
+
This is the collapsible content. It can contain any elements you want
|
|
30
|
+
to show or hide.
|
|
31
|
+
</CollapsibleContent>
|
|
32
|
+
</>
|
|
33
|
+
),
|
|
34
|
+
},
|
|
35
|
+
};
|