@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,79 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { renderHook, act } from "@testing-library/react";
|
|
3
|
+
import { useToggleGroup } from "./useToggleGroup";
|
|
4
|
+
|
|
5
|
+
describe("useToggleGroup", () => {
|
|
6
|
+
describe("single type", () => {
|
|
7
|
+
it("starts with empty value", () => {
|
|
8
|
+
const { result } = renderHook(() => useToggleGroup({}));
|
|
9
|
+
expect(result.current.value).toEqual([]);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("selects an item", () => {
|
|
13
|
+
const { result } = renderHook(() => useToggleGroup({}));
|
|
14
|
+
act(() => result.current.onItemPress("a"));
|
|
15
|
+
expect(result.current.value).toEqual(["a"]);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("deselects an already-selected item", () => {
|
|
19
|
+
const { result } = renderHook(() =>
|
|
20
|
+
useToggleGroup({ defaultValue: "a" }),
|
|
21
|
+
);
|
|
22
|
+
act(() => result.current.onItemPress("a"));
|
|
23
|
+
expect(result.current.value).toEqual([]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("replaces selection when pressing a different item", () => {
|
|
27
|
+
const { result } = renderHook(() =>
|
|
28
|
+
useToggleGroup({ defaultValue: "a" }),
|
|
29
|
+
);
|
|
30
|
+
act(() => result.current.onItemPress("b"));
|
|
31
|
+
expect(result.current.value).toEqual(["b"]);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("calls onValueChange with string for single type", () => {
|
|
35
|
+
const onChange = vi.fn();
|
|
36
|
+
const { result } = renderHook(() =>
|
|
37
|
+
useToggleGroup({ onValueChange: onChange }),
|
|
38
|
+
);
|
|
39
|
+
act(() => result.current.onItemPress("a"));
|
|
40
|
+
expect(onChange).toHaveBeenCalledWith("a");
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("multiple type", () => {
|
|
45
|
+
it("adds items to selection", () => {
|
|
46
|
+
const { result } = renderHook(() =>
|
|
47
|
+
useToggleGroup({ type: "multiple" }),
|
|
48
|
+
);
|
|
49
|
+
act(() => result.current.onItemPress("a"));
|
|
50
|
+
act(() => result.current.onItemPress("b"));
|
|
51
|
+
expect(result.current.value).toEqual(["a", "b"]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("removes an item from selection", () => {
|
|
55
|
+
const { result } = renderHook(() =>
|
|
56
|
+
useToggleGroup({ type: "multiple", defaultValue: ["a", "b"] }),
|
|
57
|
+
);
|
|
58
|
+
act(() => result.current.onItemPress("a"));
|
|
59
|
+
expect(result.current.value).toEqual(["b"]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("calls onValueChange with array for multiple type", () => {
|
|
63
|
+
const onChange = vi.fn();
|
|
64
|
+
const { result } = renderHook(() =>
|
|
65
|
+
useToggleGroup({ type: "multiple", onValueChange: onChange }),
|
|
66
|
+
);
|
|
67
|
+
act(() => result.current.onItemPress("a"));
|
|
68
|
+
expect(onChange).toHaveBeenCalledWith(["a"]);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("does not change value when disabled", () => {
|
|
73
|
+
const { result } = renderHook(() =>
|
|
74
|
+
useToggleGroup({ disabled: true }),
|
|
75
|
+
);
|
|
76
|
+
act(() => result.current.onItemPress("a"));
|
|
77
|
+
expect(result.current.value).toEqual([]);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useCallback, useMemo } from "react";
|
|
2
|
+
import { useControllableState } from "../../hooks/useControllableState";
|
|
3
|
+
|
|
4
|
+
interface UseToggleGroupProps {
|
|
5
|
+
type?: "single" | "multiple";
|
|
6
|
+
value?: string | string[];
|
|
7
|
+
defaultValue?: string | string[];
|
|
8
|
+
onValueChange?: (value: string | string[]) => void;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface UseToggleGroupReturn {
|
|
13
|
+
type: "single" | "multiple";
|
|
14
|
+
value: string[];
|
|
15
|
+
disabled: boolean;
|
|
16
|
+
onItemPress: (itemValue: string) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function normalizeValue(v: string | string[] | undefined): string[] {
|
|
20
|
+
if (v === undefined) return [];
|
|
21
|
+
return Array.isArray(v) ? v : [v];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function useToggleGroup({
|
|
25
|
+
type = "single",
|
|
26
|
+
value: controlledValue,
|
|
27
|
+
defaultValue,
|
|
28
|
+
onValueChange,
|
|
29
|
+
disabled = false,
|
|
30
|
+
}: UseToggleGroupProps): UseToggleGroupReturn {
|
|
31
|
+
const controlledNormalized = useMemo(
|
|
32
|
+
() => (controlledValue !== undefined ? normalizeValue(controlledValue) : undefined),
|
|
33
|
+
[controlledValue],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const [value, setValue] = useControllableState<string[]>({
|
|
37
|
+
value: controlledNormalized,
|
|
38
|
+
defaultValue: normalizeValue(defaultValue),
|
|
39
|
+
onChange: (next) => {
|
|
40
|
+
onValueChange?.(type === "single" ? (next[0] || "") : next);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const onItemPress = useCallback(
|
|
45
|
+
(itemValue: string) => {
|
|
46
|
+
if (disabled) return;
|
|
47
|
+
if (type === "single") {
|
|
48
|
+
setValue(value.includes(itemValue) ? [] : [itemValue]);
|
|
49
|
+
} else {
|
|
50
|
+
setValue(
|
|
51
|
+
value.includes(itemValue)
|
|
52
|
+
? value.filter((v) => v !== itemValue)
|
|
53
|
+
: [...value, itemValue],
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
[disabled, type, value, setValue],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return { type, value, disabled, onItemPress };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type { UseToggleGroupProps, UseToggleGroupReturn };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import {
|
|
3
|
+
Tooltip,
|
|
4
|
+
TooltipTrigger,
|
|
5
|
+
TooltipContent,
|
|
6
|
+
TooltipProvider,
|
|
7
|
+
} from "./Tooltip.web";
|
|
8
|
+
|
|
9
|
+
const meta: Meta<typeof Tooltip> = {
|
|
10
|
+
title: "Components/Tooltip",
|
|
11
|
+
component: Tooltip,
|
|
12
|
+
tags: ["autodocs"],
|
|
13
|
+
parameters: {
|
|
14
|
+
layout: "centered",
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default meta;
|
|
19
|
+
type Story = StoryObj<typeof Tooltip>;
|
|
20
|
+
|
|
21
|
+
export const Default: Story = {
|
|
22
|
+
render: () => (
|
|
23
|
+
<TooltipProvider>
|
|
24
|
+
<Tooltip>
|
|
25
|
+
<TooltipTrigger asChild>
|
|
26
|
+
<button type="button">Hover me</button>
|
|
27
|
+
</TooltipTrigger>
|
|
28
|
+
<TooltipContent>Tooltip text</TooltipContent>
|
|
29
|
+
</Tooltip>
|
|
30
|
+
</TooltipProvider>
|
|
31
|
+
),
|
|
32
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
export interface TooltipProps {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
open?: boolean;
|
|
6
|
+
onOpenChange?: (open: boolean) => void;
|
|
7
|
+
delayDuration?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface TooltipTriggerProps {
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
className?: string;
|
|
13
|
+
asChild?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TooltipContentProps {
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
className?: string;
|
|
19
|
+
sideOffset?: number;
|
|
20
|
+
side?: "top" | "right" | "bottom" | "left";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface TooltipProviderProps {
|
|
24
|
+
children?: ReactNode;
|
|
25
|
+
delayDuration?: number;
|
|
26
|
+
skipDelayDuration?: number;
|
|
27
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from "./Tooltip.web";
|
|
4
|
+
|
|
5
|
+
describe("Tooltip", () => {
|
|
6
|
+
it("renders trigger", () => {
|
|
7
|
+
render(
|
|
8
|
+
<TooltipProvider>
|
|
9
|
+
<Tooltip>
|
|
10
|
+
<TooltipTrigger>Hover me</TooltipTrigger>
|
|
11
|
+
<TooltipContent>Tip</TooltipContent>
|
|
12
|
+
</Tooltip>
|
|
13
|
+
</TooltipProvider>,
|
|
14
|
+
);
|
|
15
|
+
expect(screen.getByText("Hover me")).toBeDefined();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("content is hidden by default", () => {
|
|
19
|
+
render(
|
|
20
|
+
<TooltipProvider>
|
|
21
|
+
<Tooltip>
|
|
22
|
+
<TooltipTrigger>Hover me</TooltipTrigger>
|
|
23
|
+
<TooltipContent>Tip</TooltipContent>
|
|
24
|
+
</Tooltip>
|
|
25
|
+
</TooltipProvider>,
|
|
26
|
+
);
|
|
27
|
+
expect(screen.queryByText("Tip")).toBeNull();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("shows content when open", () => {
|
|
31
|
+
render(
|
|
32
|
+
<TooltipProvider>
|
|
33
|
+
<Tooltip open>
|
|
34
|
+
<TooltipTrigger>Hover me</TooltipTrigger>
|
|
35
|
+
<TooltipContent>Tip</TooltipContent>
|
|
36
|
+
</Tooltip>
|
|
37
|
+
</TooltipProvider>,
|
|
38
|
+
);
|
|
39
|
+
// Radix renders tooltip text twice (visible + sr-only), so use getAllByText
|
|
40
|
+
expect(screen.getAllByText("Tip").length).toBeGreaterThan(0);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
3
|
+
import { cn } from "../../utils/cn";
|
|
4
|
+
|
|
5
|
+
const TooltipProvider = TooltipPrimitive.Provider;
|
|
6
|
+
|
|
7
|
+
const Tooltip = TooltipPrimitive.Root;
|
|
8
|
+
|
|
9
|
+
const TooltipTrigger = TooltipPrimitive.Trigger;
|
|
10
|
+
|
|
11
|
+
const TooltipContent = forwardRef<
|
|
12
|
+
React.ComponentRef<typeof TooltipPrimitive.Content>,
|
|
13
|
+
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
|
|
14
|
+
>(({ className, sideOffset = 4, ...props }, ref) => (
|
|
15
|
+
<TooltipPrimitive.Portal>
|
|
16
|
+
<TooltipPrimitive.Content
|
|
17
|
+
ref={ref}
|
|
18
|
+
sideOffset={sideOffset}
|
|
19
|
+
className={cn(
|
|
20
|
+
"z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
21
|
+
className,
|
|
22
|
+
)}
|
|
23
|
+
{...props}
|
|
24
|
+
/>
|
|
25
|
+
</TooltipPrimitive.Portal>
|
|
26
|
+
));
|
|
27
|
+
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
|
|
28
|
+
|
|
29
|
+
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export * from "./Accordion/index.native";
|
|
2
|
+
export * from "./Alert/index.native";
|
|
3
|
+
export * from "./AlertDialog/index.native";
|
|
4
|
+
export * from "./AspectRatio/index.native";
|
|
5
|
+
export * from "./Avatar/index.native";
|
|
6
|
+
export * from "./Badge/index.native";
|
|
7
|
+
export * from "./Breadcrumb/index.native";
|
|
8
|
+
export * from "./Button/index.native";
|
|
9
|
+
export * from "./Calendar/index.native";
|
|
10
|
+
export * from "./Card/index.native";
|
|
11
|
+
export * from "./Carousel/index.native";
|
|
12
|
+
export * from "./Chart/index.native";
|
|
13
|
+
export * from "./Checkbox/index.native";
|
|
14
|
+
export * from "./Collapsible/index.native";
|
|
15
|
+
export * from "./Combobox/index.native";
|
|
16
|
+
export * from "./Command/index.native";
|
|
17
|
+
export * from "./ContextMenu/index.native";
|
|
18
|
+
export * from "./DataTable/index.native";
|
|
19
|
+
export * from "./DatePicker/index.native";
|
|
20
|
+
export * from "./Dialog/index.native";
|
|
21
|
+
export * from "./Drawer/index.native";
|
|
22
|
+
export * from "./DropdownMenu/index.native";
|
|
23
|
+
export * from "./Form/index.native";
|
|
24
|
+
export * from "./HoverCard/index.native";
|
|
25
|
+
export * from "./Icon/index.native";
|
|
26
|
+
export * from "./Input/index.native";
|
|
27
|
+
export * from "./InputOTP/index.native";
|
|
28
|
+
export * from "./Label/index.native";
|
|
29
|
+
export * from "./Menubar/index.native";
|
|
30
|
+
export * from "./NavigationMenu/index.native";
|
|
31
|
+
export * from "./Pagination/index.native";
|
|
32
|
+
export * from "./Popover/index.native";
|
|
33
|
+
export * from "./Progress/index.native";
|
|
34
|
+
export * from "./RadioGroup/index.native";
|
|
35
|
+
export * from "./ResizablePanel/index.native";
|
|
36
|
+
export * from "./ScrollArea/index.native";
|
|
37
|
+
export * from "./Select/index.native";
|
|
38
|
+
export * from "./Separator/index.native";
|
|
39
|
+
export * from "./Sheet/index.native";
|
|
40
|
+
export * from "./Sidebar/index.native";
|
|
41
|
+
export * from "./Skeleton/index.native";
|
|
42
|
+
export * from "./Slider/index.native";
|
|
43
|
+
export * from "./Switch/index.native";
|
|
44
|
+
export * from "./Table/index.native";
|
|
45
|
+
export * from "./Tabs/index.native";
|
|
46
|
+
export * from "./Textarea/index.native";
|
|
47
|
+
export * from "./Toast/index.native";
|
|
48
|
+
export * from "./Toggle/index.native";
|
|
49
|
+
export * from "./ToggleGroup/index.native";
|
|
50
|
+
export * from "./Tooltip/index.native";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export * from "./Accordion";
|
|
2
|
+
export * from "./Alert";
|
|
3
|
+
export * from "./AlertDialog";
|
|
4
|
+
export * from "./AspectRatio";
|
|
5
|
+
export * from "./Avatar";
|
|
6
|
+
export * from "./Badge";
|
|
7
|
+
export * from "./Breadcrumb";
|
|
8
|
+
export * from "./Button";
|
|
9
|
+
export * from "./Calendar";
|
|
10
|
+
export * from "./Card";
|
|
11
|
+
export * from "./Carousel";
|
|
12
|
+
export * from "./Chart";
|
|
13
|
+
export * from "./Checkbox";
|
|
14
|
+
export * from "./Collapsible";
|
|
15
|
+
export * from "./Combobox";
|
|
16
|
+
export * from "./Command";
|
|
17
|
+
export * from "./ContextMenu";
|
|
18
|
+
export * from "./DataTable";
|
|
19
|
+
export * from "./DatePicker";
|
|
20
|
+
export * from "./Dialog";
|
|
21
|
+
export * from "./Drawer";
|
|
22
|
+
export * from "./DropdownMenu";
|
|
23
|
+
export * from "./Form";
|
|
24
|
+
export * from "./HoverCard";
|
|
25
|
+
export * from "./Input";
|
|
26
|
+
export * from "./InputOTP";
|
|
27
|
+
export * from "./Label";
|
|
28
|
+
export * from "./Menubar";
|
|
29
|
+
export * from "./NavigationMenu";
|
|
30
|
+
export * from "./Pagination";
|
|
31
|
+
export * from "./Popover";
|
|
32
|
+
export * from "./Progress";
|
|
33
|
+
export * from "./RadioGroup";
|
|
34
|
+
export * from "./ResizablePanel";
|
|
35
|
+
export * from "./ScrollArea";
|
|
36
|
+
export * from "./Select";
|
|
37
|
+
export * from "./Separator";
|
|
38
|
+
export * from "./Sheet";
|
|
39
|
+
export * from "./Sidebar";
|
|
40
|
+
export * from "./Skeleton";
|
|
41
|
+
export * from "./Slider";
|
|
42
|
+
export * from "./Switch";
|
|
43
|
+
export * from "./Table";
|
|
44
|
+
export * from "./Tabs";
|
|
45
|
+
export * from "./Textarea";
|
|
46
|
+
export * from "./Toast";
|
|
47
|
+
export * from "./Toggle";
|
|
48
|
+
export * from "./ToggleGroup";
|
|
49
|
+
export * from "./Tooltip";
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { renderHook, act } from "@testing-library/react";
|
|
3
|
+
import { useControllableState } from "./useControllableState";
|
|
4
|
+
|
|
5
|
+
describe("useControllableState", () => {
|
|
6
|
+
it("uses defaultValue when uncontrolled", () => {
|
|
7
|
+
const { result } = renderHook(() =>
|
|
8
|
+
useControllableState({ defaultValue: "hello" }),
|
|
9
|
+
);
|
|
10
|
+
expect(result.current[0]).toBe("hello");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("updates internal state when uncontrolled", () => {
|
|
14
|
+
const { result } = renderHook(() =>
|
|
15
|
+
useControllableState({ defaultValue: 0 }),
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
act(() => result.current[1](5));
|
|
19
|
+
expect(result.current[0]).toBe(5);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("accepts a function updater when uncontrolled", () => {
|
|
23
|
+
const { result } = renderHook(() =>
|
|
24
|
+
useControllableState({ defaultValue: 10 }),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
act(() => result.current[1]((prev) => prev + 1));
|
|
28
|
+
expect(result.current[0]).toBe(11);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("uses controlled value when provided", () => {
|
|
32
|
+
const { result } = renderHook(() =>
|
|
33
|
+
useControllableState({ value: "controlled", defaultValue: "default" }),
|
|
34
|
+
);
|
|
35
|
+
expect(result.current[0]).toBe("controlled");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("does not update internal state when controlled", () => {
|
|
39
|
+
const onChange = vi.fn();
|
|
40
|
+
const { result } = renderHook(() =>
|
|
41
|
+
useControllableState({
|
|
42
|
+
value: "controlled",
|
|
43
|
+
defaultValue: "default",
|
|
44
|
+
onChange,
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
act(() => result.current[1]("new-value"));
|
|
49
|
+
// Value stays controlled
|
|
50
|
+
expect(result.current[0]).toBe("controlled");
|
|
51
|
+
// But onChange is called
|
|
52
|
+
expect(onChange).toHaveBeenCalledWith("new-value");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("calls onChange for both controlled and uncontrolled", () => {
|
|
56
|
+
const onChange = vi.fn();
|
|
57
|
+
const { result } = renderHook(() =>
|
|
58
|
+
useControllableState({ defaultValue: "start", onChange }),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
act(() => result.current[1]("next"));
|
|
62
|
+
expect(onChange).toHaveBeenCalledWith("next");
|
|
63
|
+
expect(result.current[0]).toBe("next");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("reflects updated controlled value on re-render", () => {
|
|
67
|
+
const { result, rerender } = renderHook(
|
|
68
|
+
({ value }) =>
|
|
69
|
+
useControllableState({ value, defaultValue: "default" }),
|
|
70
|
+
{ initialProps: { value: "a" as string | undefined } },
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
expect(result.current[0]).toBe("a");
|
|
74
|
+
rerender({ value: "b" });
|
|
75
|
+
expect(result.current[0]).toBe("b");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("transitions from uncontrolled to controlled", () => {
|
|
79
|
+
const { result, rerender } = renderHook(
|
|
80
|
+
({ value }) =>
|
|
81
|
+
useControllableState({ value, defaultValue: "default" }),
|
|
82
|
+
{ initialProps: { value: undefined as string | undefined } },
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
expect(result.current[0]).toBe("default");
|
|
86
|
+
rerender({ value: "now-controlled" });
|
|
87
|
+
expect(result.current[0]).toBe("now-controlled");
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useState, useCallback, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
interface UseControllableStateProps<T> {
|
|
4
|
+
value?: T;
|
|
5
|
+
defaultValue: T;
|
|
6
|
+
onChange?: (value: T) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function useControllableState<T>({
|
|
10
|
+
value: controlledValue,
|
|
11
|
+
defaultValue,
|
|
12
|
+
onChange,
|
|
13
|
+
}: UseControllableStateProps<T>): [T, (value: T | ((prev: T) => T)) => void] {
|
|
14
|
+
const [uncontrolledValue, setUncontrolledValue] = useState<T>(defaultValue);
|
|
15
|
+
const isControlled = controlledValue !== undefined;
|
|
16
|
+
const value = isControlled ? controlledValue : uncontrolledValue;
|
|
17
|
+
|
|
18
|
+
const onChangeRef = useRef(onChange);
|
|
19
|
+
onChangeRef.current = onChange;
|
|
20
|
+
|
|
21
|
+
const setValue = useCallback(
|
|
22
|
+
(next: T | ((prev: T) => T)) => {
|
|
23
|
+
const nextValue =
|
|
24
|
+
typeof next === "function"
|
|
25
|
+
? (next as (prev: T) => T)(value)
|
|
26
|
+
: next;
|
|
27
|
+
|
|
28
|
+
if (!isControlled) {
|
|
29
|
+
setUncontrolledValue(nextValue);
|
|
30
|
+
}
|
|
31
|
+
onChangeRef.current?.(nextValue);
|
|
32
|
+
},
|
|
33
|
+
[isControlled, value],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return [value, setValue];
|
|
37
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Components
|
|
2
|
+
export * from "./components/index.native";
|
|
3
|
+
|
|
4
|
+
// Theme
|
|
5
|
+
export { ThemeProvider, useTheme, useGlass, themes, createNativeTheme, defaultPreset, darkPreset, auroraPreset } from "./theme/native";
|
|
6
|
+
export type {
|
|
7
|
+
ThemePreset,
|
|
8
|
+
ThemeTokens,
|
|
9
|
+
} from "./theme/theme.types";
|
|
10
|
+
export type {
|
|
11
|
+
NativeTheme,
|
|
12
|
+
NativeThemeRadius,
|
|
13
|
+
NativeThemeSpacing,
|
|
14
|
+
} from "./theme/native";
|
|
15
|
+
|
|
16
|
+
// Glass utilities
|
|
17
|
+
export { GlassWrapper, useGlassActive } from "./utils/withGlass.native";
|
|
18
|
+
export { isGlassSupported } from "./utils/glass.native";
|
|
19
|
+
export type { GlassProps } from "./utils/glass.native";
|
|
20
|
+
export type { GlassWrapperProps } from "./utils/withGlass.native";
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Components
|
|
2
|
+
export * from "./components";
|
|
3
|
+
|
|
4
|
+
// Theme
|
|
5
|
+
export { ThemeProvider, useTheme, defaultPreset, darkPreset, auroraPreset } from "./theme/web";
|
|
6
|
+
export type {
|
|
7
|
+
ThemePreset,
|
|
8
|
+
ThemeTokens,
|
|
9
|
+
ThemeColors,
|
|
10
|
+
ThemeRadius,
|
|
11
|
+
ThemeSpacing,
|
|
12
|
+
} from "./theme/theme.types";
|