@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,220 @@
|
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
import * as ContextMenuPrimitive from "@radix-ui/react-context-menu";
|
|
3
|
+
import { cn } from "../../utils/cn";
|
|
4
|
+
|
|
5
|
+
function CheckIcon(props: React.SVGProps<SVGSVGElement>) {
|
|
6
|
+
return (
|
|
7
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...props}>
|
|
8
|
+
<path d="M20 6 9 17l-5-5"/>
|
|
9
|
+
</svg>
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function ChevronRightIcon(props: React.SVGProps<SVGSVGElement>) {
|
|
14
|
+
return (
|
|
15
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...props}>
|
|
16
|
+
<path d="m9 18 6-6-6-6"/>
|
|
17
|
+
</svg>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function CircleIcon(props: React.SVGProps<SVGSVGElement>) {
|
|
22
|
+
return (
|
|
23
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...props}>
|
|
24
|
+
<circle cx="12" cy="12" r="10"/>
|
|
25
|
+
</svg>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const ContextMenu = ContextMenuPrimitive.Root;
|
|
30
|
+
|
|
31
|
+
const ContextMenuTrigger = ContextMenuPrimitive.Trigger;
|
|
32
|
+
|
|
33
|
+
const ContextMenuGroup = ContextMenuPrimitive.Group;
|
|
34
|
+
|
|
35
|
+
const ContextMenuPortal = ContextMenuPrimitive.Portal;
|
|
36
|
+
|
|
37
|
+
const ContextMenuSub = ContextMenuPrimitive.Sub;
|
|
38
|
+
|
|
39
|
+
const ContextMenuRadioGroup = ContextMenuPrimitive.RadioGroup;
|
|
40
|
+
|
|
41
|
+
const ContextMenuSubTrigger = forwardRef<
|
|
42
|
+
React.ComponentRef<typeof ContextMenuPrimitive.SubTrigger>,
|
|
43
|
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubTrigger> & {
|
|
44
|
+
inset?: boolean;
|
|
45
|
+
}
|
|
46
|
+
>(({ className, inset, children, ...props }, ref) => (
|
|
47
|
+
<ContextMenuPrimitive.SubTrigger
|
|
48
|
+
ref={ref}
|
|
49
|
+
className={cn(
|
|
50
|
+
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground",
|
|
51
|
+
inset && "pl-8",
|
|
52
|
+
className,
|
|
53
|
+
)}
|
|
54
|
+
{...props}
|
|
55
|
+
>
|
|
56
|
+
{children}
|
|
57
|
+
<ChevronRightIcon className="ml-auto h-4 w-4" />
|
|
58
|
+
</ContextMenuPrimitive.SubTrigger>
|
|
59
|
+
));
|
|
60
|
+
ContextMenuSubTrigger.displayName = ContextMenuPrimitive.SubTrigger.displayName;
|
|
61
|
+
|
|
62
|
+
const ContextMenuSubContent = forwardRef<
|
|
63
|
+
React.ComponentRef<typeof ContextMenuPrimitive.SubContent>,
|
|
64
|
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubContent>
|
|
65
|
+
>(({ className, ...props }, ref) => (
|
|
66
|
+
<ContextMenuPrimitive.SubContent
|
|
67
|
+
ref={ref}
|
|
68
|
+
className={cn(
|
|
69
|
+
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-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",
|
|
70
|
+
className,
|
|
71
|
+
)}
|
|
72
|
+
{...props}
|
|
73
|
+
/>
|
|
74
|
+
));
|
|
75
|
+
ContextMenuSubContent.displayName = ContextMenuPrimitive.SubContent.displayName;
|
|
76
|
+
|
|
77
|
+
const ContextMenuContent = forwardRef<
|
|
78
|
+
React.ComponentRef<typeof ContextMenuPrimitive.Content>,
|
|
79
|
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Content>
|
|
80
|
+
>(({ className, ...props }, ref) => (
|
|
81
|
+
<ContextMenuPrimitive.Portal>
|
|
82
|
+
<ContextMenuPrimitive.Content
|
|
83
|
+
ref={ref}
|
|
84
|
+
className={cn(
|
|
85
|
+
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-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",
|
|
86
|
+
className,
|
|
87
|
+
)}
|
|
88
|
+
{...props}
|
|
89
|
+
/>
|
|
90
|
+
</ContextMenuPrimitive.Portal>
|
|
91
|
+
));
|
|
92
|
+
ContextMenuContent.displayName = ContextMenuPrimitive.Content.displayName;
|
|
93
|
+
|
|
94
|
+
const ContextMenuItem = forwardRef<
|
|
95
|
+
React.ComponentRef<typeof ContextMenuPrimitive.Item>,
|
|
96
|
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Item> & {
|
|
97
|
+
inset?: boolean;
|
|
98
|
+
}
|
|
99
|
+
>(({ className, inset, ...props }, ref) => (
|
|
100
|
+
<ContextMenuPrimitive.Item
|
|
101
|
+
ref={ref}
|
|
102
|
+
className={cn(
|
|
103
|
+
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
104
|
+
inset && "pl-8",
|
|
105
|
+
className,
|
|
106
|
+
)}
|
|
107
|
+
{...props}
|
|
108
|
+
/>
|
|
109
|
+
));
|
|
110
|
+
ContextMenuItem.displayName = ContextMenuPrimitive.Item.displayName;
|
|
111
|
+
|
|
112
|
+
const ContextMenuCheckboxItem = forwardRef<
|
|
113
|
+
React.ComponentRef<typeof ContextMenuPrimitive.CheckboxItem>,
|
|
114
|
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.CheckboxItem>
|
|
115
|
+
>(({ className, children, checked, ...props }, ref) => (
|
|
116
|
+
<ContextMenuPrimitive.CheckboxItem
|
|
117
|
+
ref={ref}
|
|
118
|
+
className={cn(
|
|
119
|
+
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
120
|
+
className,
|
|
121
|
+
)}
|
|
122
|
+
checked={checked}
|
|
123
|
+
{...props}
|
|
124
|
+
>
|
|
125
|
+
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
|
126
|
+
<ContextMenuPrimitive.ItemIndicator>
|
|
127
|
+
<CheckIcon className="h-4 w-4" />
|
|
128
|
+
</ContextMenuPrimitive.ItemIndicator>
|
|
129
|
+
</span>
|
|
130
|
+
{children}
|
|
131
|
+
</ContextMenuPrimitive.CheckboxItem>
|
|
132
|
+
));
|
|
133
|
+
ContextMenuCheckboxItem.displayName =
|
|
134
|
+
ContextMenuPrimitive.CheckboxItem.displayName;
|
|
135
|
+
|
|
136
|
+
const ContextMenuRadioItem = forwardRef<
|
|
137
|
+
React.ComponentRef<typeof ContextMenuPrimitive.RadioItem>,
|
|
138
|
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.RadioItem>
|
|
139
|
+
>(({ className, children, ...props }, ref) => (
|
|
140
|
+
<ContextMenuPrimitive.RadioItem
|
|
141
|
+
ref={ref}
|
|
142
|
+
className={cn(
|
|
143
|
+
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
144
|
+
className,
|
|
145
|
+
)}
|
|
146
|
+
{...props}
|
|
147
|
+
>
|
|
148
|
+
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
|
149
|
+
<ContextMenuPrimitive.ItemIndicator>
|
|
150
|
+
<CircleIcon className="h-2 w-2 fill-current" />
|
|
151
|
+
</ContextMenuPrimitive.ItemIndicator>
|
|
152
|
+
</span>
|
|
153
|
+
{children}
|
|
154
|
+
</ContextMenuPrimitive.RadioItem>
|
|
155
|
+
));
|
|
156
|
+
ContextMenuRadioItem.displayName = ContextMenuPrimitive.RadioItem.displayName;
|
|
157
|
+
|
|
158
|
+
const ContextMenuLabel = forwardRef<
|
|
159
|
+
React.ComponentRef<typeof ContextMenuPrimitive.Label>,
|
|
160
|
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Label> & {
|
|
161
|
+
inset?: boolean;
|
|
162
|
+
}
|
|
163
|
+
>(({ className, inset, ...props }, ref) => (
|
|
164
|
+
<ContextMenuPrimitive.Label
|
|
165
|
+
ref={ref}
|
|
166
|
+
className={cn(
|
|
167
|
+
"px-2 py-1.5 text-sm font-semibold text-foreground",
|
|
168
|
+
inset && "pl-8",
|
|
169
|
+
className,
|
|
170
|
+
)}
|
|
171
|
+
{...props}
|
|
172
|
+
/>
|
|
173
|
+
));
|
|
174
|
+
ContextMenuLabel.displayName = ContextMenuPrimitive.Label.displayName;
|
|
175
|
+
|
|
176
|
+
const ContextMenuSeparator = forwardRef<
|
|
177
|
+
React.ComponentRef<typeof ContextMenuPrimitive.Separator>,
|
|
178
|
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Separator>
|
|
179
|
+
>(({ className, ...props }, ref) => (
|
|
180
|
+
<ContextMenuPrimitive.Separator
|
|
181
|
+
ref={ref}
|
|
182
|
+
className={cn("-mx-1 my-1 h-px bg-border", className)}
|
|
183
|
+
{...props}
|
|
184
|
+
/>
|
|
185
|
+
));
|
|
186
|
+
ContextMenuSeparator.displayName = ContextMenuPrimitive.Separator.displayName;
|
|
187
|
+
|
|
188
|
+
const ContextMenuShortcut = ({
|
|
189
|
+
className,
|
|
190
|
+
...props
|
|
191
|
+
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
|
192
|
+
return (
|
|
193
|
+
<span
|
|
194
|
+
className={cn(
|
|
195
|
+
"ml-auto text-xs tracking-widest text-muted-foreground",
|
|
196
|
+
className,
|
|
197
|
+
)}
|
|
198
|
+
{...props}
|
|
199
|
+
/>
|
|
200
|
+
);
|
|
201
|
+
};
|
|
202
|
+
ContextMenuShortcut.displayName = "ContextMenuShortcut";
|
|
203
|
+
|
|
204
|
+
export {
|
|
205
|
+
ContextMenu,
|
|
206
|
+
ContextMenuTrigger,
|
|
207
|
+
ContextMenuContent,
|
|
208
|
+
ContextMenuItem,
|
|
209
|
+
ContextMenuCheckboxItem,
|
|
210
|
+
ContextMenuRadioItem,
|
|
211
|
+
ContextMenuLabel,
|
|
212
|
+
ContextMenuSeparator,
|
|
213
|
+
ContextMenuShortcut,
|
|
214
|
+
ContextMenuSub,
|
|
215
|
+
ContextMenuSubContent,
|
|
216
|
+
ContextMenuSubTrigger,
|
|
217
|
+
ContextMenuRadioGroup,
|
|
218
|
+
ContextMenuPortal,
|
|
219
|
+
ContextMenuGroup,
|
|
220
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export {
|
|
2
|
+
ContextMenu,
|
|
3
|
+
ContextMenuTrigger,
|
|
4
|
+
ContextMenuContent,
|
|
5
|
+
ContextMenuItem,
|
|
6
|
+
ContextMenuSeparator,
|
|
7
|
+
ContextMenuLabel,
|
|
8
|
+
ContextMenuCheckboxItem,
|
|
9
|
+
ContextMenuRadioGroup,
|
|
10
|
+
ContextMenuRadioItem,
|
|
11
|
+
ContextMenuSub,
|
|
12
|
+
ContextMenuSubTrigger,
|
|
13
|
+
ContextMenuSubContent,
|
|
14
|
+
} from "./ContextMenu.native";
|
|
15
|
+
export type {
|
|
16
|
+
ContextMenuProps,
|
|
17
|
+
ContextMenuTriggerProps,
|
|
18
|
+
ContextMenuContentProps,
|
|
19
|
+
ContextMenuItemProps,
|
|
20
|
+
ContextMenuSeparatorProps,
|
|
21
|
+
ContextMenuLabelProps,
|
|
22
|
+
ContextMenuCheckboxItemProps,
|
|
23
|
+
ContextMenuRadioGroupProps,
|
|
24
|
+
ContextMenuRadioItemProps,
|
|
25
|
+
ContextMenuSubProps,
|
|
26
|
+
ContextMenuSubTriggerProps,
|
|
27
|
+
ContextMenuSubContentProps,
|
|
28
|
+
} from "./ContextMenu.types";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { renderHook, act } from "@testing-library/react";
|
|
3
|
+
import { useContextMenu } from "./useContextMenu";
|
|
4
|
+
|
|
5
|
+
describe("useContextMenu", () => {
|
|
6
|
+
it("defaults to closed", () => {
|
|
7
|
+
const { result } = renderHook(() => useContextMenu());
|
|
8
|
+
expect(result.current.open).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("uses defaultOpen", () => {
|
|
12
|
+
const { result } = renderHook(() =>
|
|
13
|
+
useContextMenu({ defaultOpen: true }),
|
|
14
|
+
);
|
|
15
|
+
expect(result.current.open).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("opens and closes", () => {
|
|
19
|
+
const { result } = renderHook(() => useContextMenu());
|
|
20
|
+
act(() => result.current.onOpenChange(true));
|
|
21
|
+
expect(result.current.open).toBe(true);
|
|
22
|
+
act(() => result.current.onOpenChange(false));
|
|
23
|
+
expect(result.current.open).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("calls external onOpenChange", () => {
|
|
27
|
+
const onChange = vi.fn();
|
|
28
|
+
const { result } = renderHook(() =>
|
|
29
|
+
useContextMenu({ onOpenChange: onChange }),
|
|
30
|
+
);
|
|
31
|
+
act(() => result.current.onOpenChange(true));
|
|
32
|
+
expect(onChange).toHaveBeenCalledWith(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("works in controlled mode", () => {
|
|
36
|
+
const onChange = vi.fn();
|
|
37
|
+
const { result } = renderHook(() =>
|
|
38
|
+
useContextMenu({ open: false, onOpenChange: onChange }),
|
|
39
|
+
);
|
|
40
|
+
act(() => result.current.onOpenChange(true));
|
|
41
|
+
expect(result.current.open).toBe(false);
|
|
42
|
+
expect(onChange).toHaveBeenCalledWith(true);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { useControllableState } from "../../hooks/useControllableState";
|
|
3
|
+
|
|
4
|
+
interface UseContextMenuProps {
|
|
5
|
+
open?: boolean;
|
|
6
|
+
defaultOpen?: boolean;
|
|
7
|
+
onOpenChange?: (open: boolean) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface UseContextMenuReturn {
|
|
11
|
+
open: boolean;
|
|
12
|
+
onOpenChange: (open: boolean) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function useContextMenu({
|
|
16
|
+
open: controlledOpen,
|
|
17
|
+
defaultOpen = false,
|
|
18
|
+
onOpenChange,
|
|
19
|
+
}: UseContextMenuProps = {}): UseContextMenuReturn {
|
|
20
|
+
const [open, setOpen] = useControllableState({
|
|
21
|
+
value: controlledOpen,
|
|
22
|
+
defaultValue: defaultOpen,
|
|
23
|
+
onChange: onOpenChange,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const handleOpenChange = useCallback(
|
|
27
|
+
(nextOpen: boolean) => {
|
|
28
|
+
setOpen(nextOpen);
|
|
29
|
+
},
|
|
30
|
+
[setOpen],
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return { open, onOpenChange: handleOpenChange };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type { UseContextMenuProps, UseContextMenuReturn };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { View, Text, Pressable, FlatList, type ViewProps } from "react-native";
|
|
2
|
+
import type { DataTableProps } from "./DataTable.types";
|
|
3
|
+
import { useDataTable, getCellValue } from "./useDataTable";
|
|
4
|
+
import { cn } from "../../utils/cn";
|
|
5
|
+
|
|
6
|
+
interface DataTableNativeProps<TData> extends DataTableProps<TData>, ViewProps {}
|
|
7
|
+
|
|
8
|
+
function DataTable<TData>({
|
|
9
|
+
columns,
|
|
10
|
+
data,
|
|
11
|
+
...props
|
|
12
|
+
}: DataTableNativeProps<TData>) {
|
|
13
|
+
const { sortColumn, sortDirection, sortedData, handleSort } = useDataTable({
|
|
14
|
+
columns,
|
|
15
|
+
data,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const renderHeader = () => (
|
|
19
|
+
<View className="flex-row border-b border-border bg-background">
|
|
20
|
+
{columns.map((column) => (
|
|
21
|
+
<Pressable
|
|
22
|
+
key={column.id}
|
|
23
|
+
onPress={column.sortable ? () => handleSort(column.id) : undefined}
|
|
24
|
+
className="flex-1 px-2 py-2.5 flex-row items-center"
|
|
25
|
+
>
|
|
26
|
+
<Text className="font-medium text-xs text-muted-foreground">
|
|
27
|
+
{column.header}
|
|
28
|
+
{column.sortable && sortColumn === column.id
|
|
29
|
+
? sortDirection === "asc"
|
|
30
|
+
? " \u2191"
|
|
31
|
+
: " \u2193"
|
|
32
|
+
: ""}
|
|
33
|
+
</Text>
|
|
34
|
+
</Pressable>
|
|
35
|
+
))}
|
|
36
|
+
</View>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const renderRow = ({ item, index }: { item: TData; index: number }) => (
|
|
40
|
+
<View
|
|
41
|
+
className={cn(
|
|
42
|
+
"flex-row border-b border-border",
|
|
43
|
+
index % 2 === 0 ? "bg-background" : "bg-muted",
|
|
44
|
+
)}
|
|
45
|
+
>
|
|
46
|
+
{columns.map((column) => {
|
|
47
|
+
const value = getCellValue(column, item);
|
|
48
|
+
return (
|
|
49
|
+
<View
|
|
50
|
+
key={column.id}
|
|
51
|
+
className="flex-1 px-2 py-2.5 justify-center"
|
|
52
|
+
>
|
|
53
|
+
{column.cell ? (
|
|
54
|
+
column.cell(value, item)
|
|
55
|
+
) : (
|
|
56
|
+
<Text className="text-sm text-foreground">
|
|
57
|
+
{String(value ?? "")}
|
|
58
|
+
</Text>
|
|
59
|
+
)}
|
|
60
|
+
</View>
|
|
61
|
+
);
|
|
62
|
+
})}
|
|
63
|
+
</View>
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<View className="overflow-hidden" {...props}>
|
|
68
|
+
{renderHeader()}
|
|
69
|
+
<FlatList
|
|
70
|
+
data={sortedData}
|
|
71
|
+
renderItem={renderRow}
|
|
72
|
+
keyExtractor={(_: TData, index: number) => String(index)}
|
|
73
|
+
ListEmptyComponent={
|
|
74
|
+
<View className="p-6 items-center">
|
|
75
|
+
<Text className="text-muted-foreground text-sm">No results.</Text>
|
|
76
|
+
</View>
|
|
77
|
+
}
|
|
78
|
+
/>
|
|
79
|
+
</View>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
DataTable.displayName = "DataTable";
|
|
83
|
+
|
|
84
|
+
export { DataTable };
|
|
85
|
+
export type { DataTableNativeProps };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { DataTable } from "./DataTable.web";
|
|
3
|
+
import type { ColumnDef } from "./DataTable.types";
|
|
4
|
+
|
|
5
|
+
interface Payment {
|
|
6
|
+
id: string;
|
|
7
|
+
amount: number;
|
|
8
|
+
status: "pending" | "processing" | "success" | "failed";
|
|
9
|
+
email: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const columns: ColumnDef<Payment>[] = [
|
|
13
|
+
{
|
|
14
|
+
id: "status",
|
|
15
|
+
header: "Status",
|
|
16
|
+
accessorKey: "status",
|
|
17
|
+
sortable: true,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: "email",
|
|
21
|
+
header: "Email",
|
|
22
|
+
accessorKey: "email",
|
|
23
|
+
sortable: true,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "amount",
|
|
27
|
+
header: "Amount",
|
|
28
|
+
accessorKey: "amount",
|
|
29
|
+
sortable: true,
|
|
30
|
+
cell: (value) => {
|
|
31
|
+
const formatted = new Intl.NumberFormat("en-US", {
|
|
32
|
+
style: "currency",
|
|
33
|
+
currency: "USD",
|
|
34
|
+
}).format(value as number);
|
|
35
|
+
return formatted;
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const data: Payment[] = [
|
|
41
|
+
{ id: "1", amount: 316, status: "success", email: "alice@example.com" },
|
|
42
|
+
{ id: "2", amount: 242, status: "success", email: "bob@example.com" },
|
|
43
|
+
{ id: "3", amount: 837, status: "processing", email: "carol@example.com" },
|
|
44
|
+
{ id: "4", amount: 874, status: "failed", email: "dave@example.com" },
|
|
45
|
+
{ id: "5", amount: 721, status: "pending", email: "eve@example.com" },
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
const meta = {
|
|
49
|
+
title: "Components/DataTable",
|
|
50
|
+
component: DataTable,
|
|
51
|
+
parameters: {
|
|
52
|
+
layout: "centered",
|
|
53
|
+
},
|
|
54
|
+
tags: ["autodocs"],
|
|
55
|
+
} satisfies Meta<typeof DataTable>;
|
|
56
|
+
|
|
57
|
+
export default meta;
|
|
58
|
+
type Story = StoryObj<typeof meta>;
|
|
59
|
+
|
|
60
|
+
export const Default: Story = {
|
|
61
|
+
args: {
|
|
62
|
+
columns: columns as ColumnDef<unknown>[],
|
|
63
|
+
data,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const Empty: Story = {
|
|
68
|
+
args: {
|
|
69
|
+
columns: columns as ColumnDef<unknown>[],
|
|
70
|
+
data: [],
|
|
71
|
+
},
|
|
72
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type SortDirection = "asc" | "desc" | null;
|
|
2
|
+
|
|
3
|
+
export interface ColumnDef<TData> {
|
|
4
|
+
id: string;
|
|
5
|
+
header: string;
|
|
6
|
+
accessorKey?: keyof TData;
|
|
7
|
+
accessorFn?: (row: TData) => unknown;
|
|
8
|
+
cell?: (value: unknown, row: TData) => React.ReactNode;
|
|
9
|
+
sortable?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface DataTableProps<TData> {
|
|
13
|
+
columns: ColumnDef<TData>[];
|
|
14
|
+
data: TData[];
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { forwardRef, useState, useMemo, useCallback } from "react";
|
|
2
|
+
import { cn } from "../../utils/cn";
|
|
3
|
+
import type { ColumnDef, SortDirection, DataTableProps } from "./DataTable.types";
|
|
4
|
+
|
|
5
|
+
function getCellValue<TData>(column: ColumnDef<TData>, row: TData): unknown {
|
|
6
|
+
if (column.accessorFn) return column.accessorFn(row);
|
|
7
|
+
if (column.accessorKey) return row[column.accessorKey];
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function DataTableInner<TData>(
|
|
12
|
+
{
|
|
13
|
+
columns,
|
|
14
|
+
data,
|
|
15
|
+
className,
|
|
16
|
+
...props
|
|
17
|
+
}: DataTableProps<TData> & React.HTMLAttributes<HTMLDivElement>,
|
|
18
|
+
ref: React.ForwardedRef<HTMLDivElement>,
|
|
19
|
+
) {
|
|
20
|
+
const [sortColumn, setSortColumn] = useState<string | null>(null);
|
|
21
|
+
const [sortDirection, setSortDirection] = useState<SortDirection>(null);
|
|
22
|
+
|
|
23
|
+
const handleSort = useCallback(
|
|
24
|
+
(columnId: string) => {
|
|
25
|
+
if (sortColumn === columnId) {
|
|
26
|
+
if (sortDirection === "asc") {
|
|
27
|
+
setSortDirection("desc");
|
|
28
|
+
} else if (sortDirection === "desc") {
|
|
29
|
+
setSortColumn(null);
|
|
30
|
+
setSortDirection(null);
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
setSortColumn(columnId);
|
|
34
|
+
setSortDirection("asc");
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
[sortColumn, sortDirection],
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const sortedData = useMemo(() => {
|
|
41
|
+
if (!sortColumn || !sortDirection) return data;
|
|
42
|
+
|
|
43
|
+
const column = columns.find((c) => c.id === sortColumn);
|
|
44
|
+
if (!column) return data;
|
|
45
|
+
|
|
46
|
+
return [...data].sort((a, b) => {
|
|
47
|
+
const aVal = getCellValue(column, a);
|
|
48
|
+
const bVal = getCellValue(column, b);
|
|
49
|
+
|
|
50
|
+
if (aVal == null && bVal == null) return 0;
|
|
51
|
+
if (aVal == null) return 1;
|
|
52
|
+
if (bVal == null) return -1;
|
|
53
|
+
|
|
54
|
+
const comparison =
|
|
55
|
+
typeof aVal === "string" && typeof bVal === "string"
|
|
56
|
+
? aVal.localeCompare(bVal)
|
|
57
|
+
: Number(aVal) - Number(bVal);
|
|
58
|
+
|
|
59
|
+
return sortDirection === "asc" ? comparison : -comparison;
|
|
60
|
+
});
|
|
61
|
+
}, [data, columns, sortColumn, sortDirection]);
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<div ref={ref} className={cn("relative w-full overflow-auto", className)} {...props}>
|
|
65
|
+
<table className="w-full caption-bottom text-sm">
|
|
66
|
+
<thead className="[&_tr]:border-b">
|
|
67
|
+
<tr className="border-b transition-colors hover:bg-muted/50">
|
|
68
|
+
{columns.map((column) => (
|
|
69
|
+
<th
|
|
70
|
+
key={column.id}
|
|
71
|
+
className={cn(
|
|
72
|
+
"h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
|
73
|
+
column.sortable && "cursor-pointer select-none",
|
|
74
|
+
)}
|
|
75
|
+
onClick={
|
|
76
|
+
column.sortable ? () => handleSort(column.id) : undefined
|
|
77
|
+
}
|
|
78
|
+
>
|
|
79
|
+
<div className="flex items-center gap-1">
|
|
80
|
+
{column.header}
|
|
81
|
+
{column.sortable && sortColumn === column.id && (
|
|
82
|
+
<span className="ml-1 text-xs">
|
|
83
|
+
{sortDirection === "asc" ? "\u2191" : "\u2193"}
|
|
84
|
+
</span>
|
|
85
|
+
)}
|
|
86
|
+
</div>
|
|
87
|
+
</th>
|
|
88
|
+
))}
|
|
89
|
+
</tr>
|
|
90
|
+
</thead>
|
|
91
|
+
<tbody className="[&_tr:last-child]:border-0">
|
|
92
|
+
{sortedData.length === 0 ? (
|
|
93
|
+
<tr>
|
|
94
|
+
<td
|
|
95
|
+
colSpan={columns.length}
|
|
96
|
+
className="h-24 text-center text-muted-foreground"
|
|
97
|
+
>
|
|
98
|
+
No results.
|
|
99
|
+
</td>
|
|
100
|
+
</tr>
|
|
101
|
+
) : (
|
|
102
|
+
sortedData.map((row, rowIndex) => (
|
|
103
|
+
<tr
|
|
104
|
+
key={rowIndex}
|
|
105
|
+
className="border-b transition-colors hover:bg-muted/50"
|
|
106
|
+
>
|
|
107
|
+
{columns.map((column) => {
|
|
108
|
+
const value = getCellValue(column, row);
|
|
109
|
+
return (
|
|
110
|
+
<td
|
|
111
|
+
key={column.id}
|
|
112
|
+
className="p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]"
|
|
113
|
+
>
|
|
114
|
+
{column.cell ? column.cell(value, row) : String(value ?? "")}
|
|
115
|
+
</td>
|
|
116
|
+
);
|
|
117
|
+
})}
|
|
118
|
+
</tr>
|
|
119
|
+
))
|
|
120
|
+
)}
|
|
121
|
+
</tbody>
|
|
122
|
+
</table>
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const DataTable = forwardRef(DataTableInner) as <TData>(
|
|
128
|
+
props: DataTableProps<TData> &
|
|
129
|
+
React.HTMLAttributes<HTMLDivElement> & {
|
|
130
|
+
ref?: React.ForwardedRef<HTMLDivElement>;
|
|
131
|
+
},
|
|
132
|
+
) => React.ReactElement;
|
|
133
|
+
|
|
134
|
+
export { DataTable };
|
|
135
|
+
export type { ColumnDef };
|