@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,32 @@
|
|
|
1
|
+
import { TextInput, type TextInputProps } from "react-native";
|
|
2
|
+
import type { InputProps } from "./Input.types";
|
|
3
|
+
import { cn } from "../../utils/cn";
|
|
4
|
+
|
|
5
|
+
interface InputNativeProps extends InputProps, TextInputProps {}
|
|
6
|
+
|
|
7
|
+
function Input({
|
|
8
|
+
disabled = false,
|
|
9
|
+
editable,
|
|
10
|
+
className,
|
|
11
|
+
placeholderTextColor,
|
|
12
|
+
...props
|
|
13
|
+
}: InputNativeProps) {
|
|
14
|
+
return (
|
|
15
|
+
<TextInput
|
|
16
|
+
editable={editable !== undefined ? editable : !disabled}
|
|
17
|
+
placeholderTextColor={placeholderTextColor}
|
|
18
|
+
className={cn(
|
|
19
|
+
"h-9 w-full rounded-md border border-input bg-transparent px-3 text-sm leading-tight text-foreground shadow-sm elevation-1",
|
|
20
|
+
disabled && "opacity-50",
|
|
21
|
+
className,
|
|
22
|
+
)}
|
|
23
|
+
style={{ textAlignVertical: "center" }}
|
|
24
|
+
{...props}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Input.displayName = "Input";
|
|
30
|
+
|
|
31
|
+
export { Input };
|
|
32
|
+
export type { InputNativeProps };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { Input } from "./Input.web";
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: "Components/Input",
|
|
6
|
+
component: Input,
|
|
7
|
+
parameters: {
|
|
8
|
+
layout: "centered",
|
|
9
|
+
},
|
|
10
|
+
tags: ["autodocs"],
|
|
11
|
+
} satisfies Meta<typeof Input>;
|
|
12
|
+
|
|
13
|
+
export default meta;
|
|
14
|
+
type Story = StoryObj<typeof meta>;
|
|
15
|
+
|
|
16
|
+
export const Default: Story = {
|
|
17
|
+
args: {
|
|
18
|
+
placeholder: "Type here...",
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const Disabled: Story = {
|
|
23
|
+
args: {
|
|
24
|
+
placeholder: "Disabled",
|
|
25
|
+
disabled: true,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const WithLabel: Story = {
|
|
30
|
+
decorators: [
|
|
31
|
+
(Story) => (
|
|
32
|
+
<label style={{ display: "flex", flexDirection: "column", gap: 4 }}>
|
|
33
|
+
<span style={{ fontSize: 14, fontWeight: 500 }}>Email</span>
|
|
34
|
+
<Story />
|
|
35
|
+
</label>
|
|
36
|
+
),
|
|
37
|
+
],
|
|
38
|
+
args: {
|
|
39
|
+
type: "email",
|
|
40
|
+
placeholder: "you@example.com",
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { render, screen, fireEvent } from "@testing-library/react";
|
|
3
|
+
import { Input } from "./Input.web";
|
|
4
|
+
|
|
5
|
+
describe("Input", () => {
|
|
6
|
+
it("renders an input element", () => {
|
|
7
|
+
render(<Input placeholder="Type here" />);
|
|
8
|
+
expect(screen.getByPlaceholderText("Type here")).toBeDefined();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("applies type prop", () => {
|
|
12
|
+
render(<Input type="email" placeholder="email" />);
|
|
13
|
+
expect(screen.getByPlaceholderText("email")).toHaveProperty("type", "email");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("merges custom className", () => {
|
|
17
|
+
render(<Input className="my-input" placeholder="test" />);
|
|
18
|
+
expect(screen.getByPlaceholderText("test").className).toContain("my-input");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("forwards disabled prop", () => {
|
|
22
|
+
render(<Input disabled placeholder="test" />);
|
|
23
|
+
expect(screen.getByPlaceholderText("test")).toHaveProperty("disabled", true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("forwards value and onChange", () => {
|
|
27
|
+
const onChange = vi.fn();
|
|
28
|
+
render(<Input value="hello" onChange={onChange} />);
|
|
29
|
+
const input = screen.getByDisplayValue("hello");
|
|
30
|
+
fireEvent.change(input, { target: { value: "world" } });
|
|
31
|
+
expect(onChange).toHaveBeenCalled();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("forwards ref", () => {
|
|
35
|
+
let ref: HTMLInputElement | null = null;
|
|
36
|
+
render(<Input ref={(el) => { ref = el; }} placeholder="test" />);
|
|
37
|
+
expect(ref).toBeInstanceOf(HTMLInputElement);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
import { cn } from "../../utils/cn";
|
|
3
|
+
|
|
4
|
+
const Input = forwardRef<HTMLInputElement, React.InputHTMLAttributes<HTMLInputElement>>(
|
|
5
|
+
({ className, type, ...props }, ref) => {
|
|
6
|
+
return (
|
|
7
|
+
<input
|
|
8
|
+
type={type}
|
|
9
|
+
className={cn(
|
|
10
|
+
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
|
11
|
+
className,
|
|
12
|
+
)}
|
|
13
|
+
ref={ref}
|
|
14
|
+
{...props}
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
17
|
+
},
|
|
18
|
+
);
|
|
19
|
+
Input.displayName = "Input";
|
|
20
|
+
|
|
21
|
+
export { Input };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
TextInput,
|
|
5
|
+
type ViewProps,
|
|
6
|
+
type NativeSyntheticEvent,
|
|
7
|
+
} from "react-native";
|
|
8
|
+
import { cn } from "../../utils/cn";
|
|
9
|
+
import { useInputOTP } from "./useInputOTP";
|
|
10
|
+
import type { InputOTPProps } from "./InputOTP.types";
|
|
11
|
+
|
|
12
|
+
interface InputOTPNativeProps extends InputOTPProps, ViewProps {}
|
|
13
|
+
|
|
14
|
+
function InputOTP({
|
|
15
|
+
length = 6,
|
|
16
|
+
value: controlledValue,
|
|
17
|
+
onValueChange,
|
|
18
|
+
disabled = false,
|
|
19
|
+
className,
|
|
20
|
+
...props
|
|
21
|
+
}: InputOTPNativeProps) {
|
|
22
|
+
const inputRefs = useRef<(TextInput | null)[]>([]);
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
currentValue,
|
|
26
|
+
activeIndex,
|
|
27
|
+
setActiveIndex,
|
|
28
|
+
handleCharInput,
|
|
29
|
+
handleBackspace,
|
|
30
|
+
} = useInputOTP({ length, value: controlledValue, onValueChange });
|
|
31
|
+
|
|
32
|
+
const handleChange = (index: number, text: string) => {
|
|
33
|
+
const char = text.slice(-1);
|
|
34
|
+
const nextIndex = handleCharInput(index, char);
|
|
35
|
+
if (nextIndex !== null) {
|
|
36
|
+
inputRefs.current[nextIndex]?.focus();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const handleKeyPress = (
|
|
41
|
+
index: number,
|
|
42
|
+
e: NativeSyntheticEvent<{ key: string }>,
|
|
43
|
+
) => {
|
|
44
|
+
if (e.nativeEvent.key === "Backspace") {
|
|
45
|
+
const focusIndex = handleBackspace(index);
|
|
46
|
+
if (focusIndex !== null) {
|
|
47
|
+
inputRefs.current[focusIndex]?.focus();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<View
|
|
54
|
+
className={cn(
|
|
55
|
+
"flex-row gap-2",
|
|
56
|
+
disabled && "opacity-50",
|
|
57
|
+
className,
|
|
58
|
+
)}
|
|
59
|
+
{...props}
|
|
60
|
+
>
|
|
61
|
+
{Array.from({ length }, (_, i) => (
|
|
62
|
+
<View
|
|
63
|
+
key={i}
|
|
64
|
+
className={cn(
|
|
65
|
+
"w-9 h-9 rounded-md border border-input items-center justify-center shadow-sm elevation-1",
|
|
66
|
+
activeIndex === i && "border-ring",
|
|
67
|
+
)}
|
|
68
|
+
>
|
|
69
|
+
<TextInput
|
|
70
|
+
ref={(el) => {
|
|
71
|
+
inputRefs.current[i] = el;
|
|
72
|
+
}}
|
|
73
|
+
value={currentValue[i] || ""}
|
|
74
|
+
onChangeText={(text) => handleChange(i, text)}
|
|
75
|
+
onKeyPress={(e) => handleKeyPress(i, e)}
|
|
76
|
+
onFocus={() => setActiveIndex(i)}
|
|
77
|
+
onBlur={() => setActiveIndex(-1)}
|
|
78
|
+
maxLength={1}
|
|
79
|
+
keyboardType="number-pad"
|
|
80
|
+
editable={!disabled}
|
|
81
|
+
className="w-full h-full text-center text-sm leading-tight text-foreground"
|
|
82
|
+
selectTextOnFocus
|
|
83
|
+
/>
|
|
84
|
+
</View>
|
|
85
|
+
))}
|
|
86
|
+
</View>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
InputOTP.displayName = "InputOTP";
|
|
91
|
+
|
|
92
|
+
export { InputOTP };
|
|
93
|
+
export type { InputOTPNativeProps };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { InputOTP } from "./InputOTP.web";
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: "Components/InputOTP",
|
|
7
|
+
component: InputOTP,
|
|
8
|
+
parameters: {
|
|
9
|
+
layout: "centered",
|
|
10
|
+
},
|
|
11
|
+
tags: ["autodocs"],
|
|
12
|
+
argTypes: {
|
|
13
|
+
length: {
|
|
14
|
+
control: "number",
|
|
15
|
+
},
|
|
16
|
+
disabled: {
|
|
17
|
+
control: "boolean",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
} satisfies Meta<typeof InputOTP>;
|
|
21
|
+
|
|
22
|
+
export default meta;
|
|
23
|
+
type Story = StoryObj<typeof meta>;
|
|
24
|
+
|
|
25
|
+
export const Default: Story = {
|
|
26
|
+
args: {
|
|
27
|
+
length: 6,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const FourDigits: Story = {
|
|
32
|
+
args: {
|
|
33
|
+
length: 4,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const Controlled: Story = {
|
|
38
|
+
render: (args) => {
|
|
39
|
+
const [value, setValue] = useState("");
|
|
40
|
+
return (
|
|
41
|
+
<div>
|
|
42
|
+
<InputOTP {...args} length={6} value={value} onValueChange={setValue} />
|
|
43
|
+
<p className="mt-4 text-sm text-muted-foreground">
|
|
44
|
+
Current value: {value || "(empty)"}
|
|
45
|
+
</p>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const Disabled: Story = {
|
|
52
|
+
args: {
|
|
53
|
+
length: 6,
|
|
54
|
+
disabled: true,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface InputOTPProps {
|
|
2
|
+
length?: number;
|
|
3
|
+
value?: string;
|
|
4
|
+
onValueChange?: (value: string) => void;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface InputOTPSlotProps {
|
|
10
|
+
index: number;
|
|
11
|
+
char?: string;
|
|
12
|
+
isActive?: boolean;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { forwardRef, useState, useRef, useCallback, createContext, useContext } from "react";
|
|
2
|
+
import { cn } from "../../utils/cn";
|
|
3
|
+
import type { InputOTPProps } from "./InputOTP.types";
|
|
4
|
+
|
|
5
|
+
interface InputOTPContextValue {
|
|
6
|
+
value: string;
|
|
7
|
+
activeIndex: number;
|
|
8
|
+
length: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const InputOTPContext = createContext<InputOTPContextValue>({
|
|
12
|
+
value: "",
|
|
13
|
+
activeIndex: -1,
|
|
14
|
+
length: 6,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const InputOTP = forwardRef<
|
|
18
|
+
HTMLDivElement,
|
|
19
|
+
InputOTPProps & Omit<React.HTMLAttributes<HTMLDivElement>, "onChange">
|
|
20
|
+
>(
|
|
21
|
+
(
|
|
22
|
+
{
|
|
23
|
+
length = 6,
|
|
24
|
+
value: controlledValue,
|
|
25
|
+
onValueChange,
|
|
26
|
+
disabled = false,
|
|
27
|
+
className,
|
|
28
|
+
children,
|
|
29
|
+
...props
|
|
30
|
+
},
|
|
31
|
+
ref,
|
|
32
|
+
) => {
|
|
33
|
+
const [internalValue, setInternalValue] = useState("");
|
|
34
|
+
const [activeIndex, setActiveIndex] = useState(-1);
|
|
35
|
+
const inputRefs = useRef<(HTMLInputElement | null)[]>([]);
|
|
36
|
+
|
|
37
|
+
const currentValue = controlledValue !== undefined ? controlledValue : internalValue;
|
|
38
|
+
|
|
39
|
+
const updateValue = useCallback(
|
|
40
|
+
(newValue: string) => {
|
|
41
|
+
const clamped = newValue.slice(0, length);
|
|
42
|
+
if (controlledValue === undefined) {
|
|
43
|
+
setInternalValue(clamped);
|
|
44
|
+
}
|
|
45
|
+
onValueChange?.(clamped);
|
|
46
|
+
},
|
|
47
|
+
[controlledValue, length, onValueChange],
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const handleKeyDown = (index: number, e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
51
|
+
if (e.key === "Backspace") {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
const chars = currentValue.split("");
|
|
54
|
+
if (chars[index]) {
|
|
55
|
+
chars[index] = "";
|
|
56
|
+
updateValue(chars.join(""));
|
|
57
|
+
} else if (index > 0) {
|
|
58
|
+
chars[index - 1] = "";
|
|
59
|
+
updateValue(chars.join(""));
|
|
60
|
+
inputRefs.current[index - 1]?.focus();
|
|
61
|
+
}
|
|
62
|
+
} else if (e.key === "ArrowLeft" && index > 0) {
|
|
63
|
+
inputRefs.current[index - 1]?.focus();
|
|
64
|
+
} else if (e.key === "ArrowRight" && index < length - 1) {
|
|
65
|
+
inputRefs.current[index + 1]?.focus();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const handleInput = (index: number, e: React.ChangeEvent<HTMLInputElement>) => {
|
|
70
|
+
const char = e.target.value.slice(-1);
|
|
71
|
+
if (!char) return;
|
|
72
|
+
|
|
73
|
+
const chars = currentValue.split("");
|
|
74
|
+
while (chars.length < length) chars.push("");
|
|
75
|
+
chars[index] = char;
|
|
76
|
+
updateValue(chars.join(""));
|
|
77
|
+
|
|
78
|
+
if (index < length - 1) {
|
|
79
|
+
inputRefs.current[index + 1]?.focus();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const handlePaste = (e: React.ClipboardEvent) => {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
const pasted = e.clipboardData.getData("text").slice(0, length);
|
|
86
|
+
updateValue(pasted);
|
|
87
|
+
const nextIndex = Math.min(pasted.length, length - 1);
|
|
88
|
+
inputRefs.current[nextIndex]?.focus();
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<InputOTPContext.Provider value={{ value: currentValue, activeIndex, length }}>
|
|
93
|
+
<div
|
|
94
|
+
ref={ref}
|
|
95
|
+
className={cn("flex items-center gap-2", disabled && "opacity-50", className)}
|
|
96
|
+
onPaste={handlePaste}
|
|
97
|
+
{...props}
|
|
98
|
+
>
|
|
99
|
+
{Array.from({ length }, (_, i) => (
|
|
100
|
+
<input
|
|
101
|
+
key={i}
|
|
102
|
+
ref={(el) => {
|
|
103
|
+
inputRefs.current[i] = el;
|
|
104
|
+
}}
|
|
105
|
+
type="text"
|
|
106
|
+
inputMode="numeric"
|
|
107
|
+
maxLength={1}
|
|
108
|
+
value={currentValue[i] || ""}
|
|
109
|
+
disabled={disabled}
|
|
110
|
+
onChange={(e) => handleInput(i, e)}
|
|
111
|
+
onKeyDown={(e) => handleKeyDown(i, e)}
|
|
112
|
+
onFocus={() => setActiveIndex(i)}
|
|
113
|
+
onBlur={() => setActiveIndex(-1)}
|
|
114
|
+
className={cn(
|
|
115
|
+
"flex h-9 w-9 items-center justify-center rounded-md border border-input bg-transparent text-center text-sm shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed",
|
|
116
|
+
activeIndex === i && "ring-1 ring-ring",
|
|
117
|
+
)}
|
|
118
|
+
autoComplete="one-time-code"
|
|
119
|
+
/>
|
|
120
|
+
))}
|
|
121
|
+
</div>
|
|
122
|
+
</InputOTPContext.Provider>
|
|
123
|
+
);
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
InputOTP.displayName = "InputOTP";
|
|
127
|
+
|
|
128
|
+
export { InputOTP };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { renderHook, act } from "@testing-library/react";
|
|
3
|
+
import { useInputOTP } from "./useInputOTP";
|
|
4
|
+
|
|
5
|
+
describe("useInputOTP", () => {
|
|
6
|
+
it("starts with empty value", () => {
|
|
7
|
+
const { result } = renderHook(() => useInputOTP({}));
|
|
8
|
+
expect(result.current.currentValue).toBe("");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("handles character input", () => {
|
|
12
|
+
const { result } = renderHook(() => useInputOTP({ length: 4 }));
|
|
13
|
+
|
|
14
|
+
act(() => {
|
|
15
|
+
result.current.handleCharInput(0, "1");
|
|
16
|
+
});
|
|
17
|
+
expect(result.current.currentValue).toBe("1");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("returns next index after input", () => {
|
|
21
|
+
const { result } = renderHook(() => useInputOTP({ length: 4 }));
|
|
22
|
+
|
|
23
|
+
let nextIndex: number | null = null;
|
|
24
|
+
act(() => {
|
|
25
|
+
nextIndex = result.current.handleCharInput(0, "1");
|
|
26
|
+
});
|
|
27
|
+
expect(nextIndex).toBe(1);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("returns null when inputting at last index", () => {
|
|
31
|
+
const { result } = renderHook(() => useInputOTP({ length: 4 }));
|
|
32
|
+
|
|
33
|
+
let nextIndex: number | null = null;
|
|
34
|
+
act(() => {
|
|
35
|
+
nextIndex = result.current.handleCharInput(3, "4");
|
|
36
|
+
});
|
|
37
|
+
expect(nextIndex).toBeNull();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("handles backspace - clears current character", () => {
|
|
41
|
+
const onChange = vi.fn();
|
|
42
|
+
const { result } = renderHook(() =>
|
|
43
|
+
useInputOTP({ length: 4, onValueChange: onChange }),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
act(() => result.current.handleCharInput(0, "1"));
|
|
47
|
+
act(() => result.current.handleCharInput(1, "2"));
|
|
48
|
+
act(() => result.current.handleBackspace(1));
|
|
49
|
+
|
|
50
|
+
expect(result.current.currentValue).toBe("1");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("handles backspace - moves to previous index when current is empty", () => {
|
|
54
|
+
const { result } = renderHook(() => useInputOTP({ length: 4 }));
|
|
55
|
+
|
|
56
|
+
act(() => result.current.handleCharInput(0, "1"));
|
|
57
|
+
|
|
58
|
+
let nextIndex: number | null = null;
|
|
59
|
+
act(() => {
|
|
60
|
+
// index 1 is empty, so backspace should clear index 0 and return 0
|
|
61
|
+
nextIndex = result.current.handleBackspace(1);
|
|
62
|
+
});
|
|
63
|
+
expect(nextIndex).toBe(0);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("clamps value to length", () => {
|
|
67
|
+
const { result } = renderHook(() => useInputOTP({ length: 4 }));
|
|
68
|
+
|
|
69
|
+
// Build up a full value
|
|
70
|
+
act(() => result.current.handleCharInput(0, "1"));
|
|
71
|
+
act(() => result.current.handleCharInput(1, "2"));
|
|
72
|
+
act(() => result.current.handleCharInput(2, "3"));
|
|
73
|
+
act(() => result.current.handleCharInput(3, "4"));
|
|
74
|
+
|
|
75
|
+
expect(result.current.currentValue).toBe("1234");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("calls onValueChange", () => {
|
|
79
|
+
const onChange = vi.fn();
|
|
80
|
+
const { result } = renderHook(() =>
|
|
81
|
+
useInputOTP({ length: 4, onValueChange: onChange }),
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
act(() => result.current.handleCharInput(0, "5"));
|
|
85
|
+
expect(onChange).toHaveBeenCalled();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("returns null for empty char input", () => {
|
|
89
|
+
const { result } = renderHook(() => useInputOTP({ length: 4 }));
|
|
90
|
+
|
|
91
|
+
let nextIndex: number | null = null;
|
|
92
|
+
act(() => {
|
|
93
|
+
nextIndex = result.current.handleCharInput(0, "");
|
|
94
|
+
});
|
|
95
|
+
expect(nextIndex).toBeNull();
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
|
+
import { useControllableState } from "../../hooks/useControllableState";
|
|
3
|
+
|
|
4
|
+
interface UseInputOTPProps {
|
|
5
|
+
length?: number;
|
|
6
|
+
value?: string;
|
|
7
|
+
onValueChange?: (value: string) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function useInputOTP({
|
|
11
|
+
length = 6,
|
|
12
|
+
value: controlledValue,
|
|
13
|
+
onValueChange,
|
|
14
|
+
}: UseInputOTPProps) {
|
|
15
|
+
const [currentValue, setCurrentValue] = useControllableState<string>({
|
|
16
|
+
value: controlledValue,
|
|
17
|
+
defaultValue: "",
|
|
18
|
+
onChange: onValueChange,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const [activeIndex, setActiveIndex] = useState(-1);
|
|
22
|
+
|
|
23
|
+
const updateValue = useCallback(
|
|
24
|
+
(newValue: string) => {
|
|
25
|
+
const clamped = newValue.slice(0, length);
|
|
26
|
+
setCurrentValue(clamped);
|
|
27
|
+
},
|
|
28
|
+
[length, setCurrentValue],
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const handleCharInput = useCallback(
|
|
32
|
+
(index: number, char: string): number | null => {
|
|
33
|
+
if (!char) return null;
|
|
34
|
+
|
|
35
|
+
const chars = currentValue.split("");
|
|
36
|
+
while (chars.length < length) chars.push("");
|
|
37
|
+
chars[index] = char;
|
|
38
|
+
updateValue(chars.join(""));
|
|
39
|
+
|
|
40
|
+
return index < length - 1 ? index + 1 : null;
|
|
41
|
+
},
|
|
42
|
+
[currentValue, length, updateValue],
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const handleBackspace = useCallback(
|
|
46
|
+
(index: number): number | null => {
|
|
47
|
+
const chars = currentValue.split("");
|
|
48
|
+
if (chars[index]) {
|
|
49
|
+
chars[index] = "";
|
|
50
|
+
updateValue(chars.join(""));
|
|
51
|
+
return null;
|
|
52
|
+
} else if (index > 0) {
|
|
53
|
+
chars[index - 1] = "";
|
|
54
|
+
updateValue(chars.join(""));
|
|
55
|
+
return index - 1;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
},
|
|
59
|
+
[currentValue, updateValue],
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
currentValue,
|
|
64
|
+
activeIndex,
|
|
65
|
+
setActiveIndex,
|
|
66
|
+
handleCharInput,
|
|
67
|
+
handleBackspace,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Text, type TextProps } from "react-native";
|
|
2
|
+
import type { LabelProps } from "./Label.types";
|
|
3
|
+
import { cn } from "../../utils/cn";
|
|
4
|
+
|
|
5
|
+
interface LabelNativeProps extends LabelProps, TextProps {}
|
|
6
|
+
|
|
7
|
+
function Label({ disabled = false, className, children, ...props }: LabelNativeProps) {
|
|
8
|
+
return (
|
|
9
|
+
<Text
|
|
10
|
+
className={cn(
|
|
11
|
+
"text-sm font-medium leading-none text-foreground",
|
|
12
|
+
disabled && "opacity-70",
|
|
13
|
+
className,
|
|
14
|
+
)}
|
|
15
|
+
{...props}
|
|
16
|
+
>
|
|
17
|
+
{children}
|
|
18
|
+
</Text>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Label.displayName = "Label";
|
|
23
|
+
|
|
24
|
+
export { Label };
|
|
25
|
+
export type { LabelNativeProps };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { Label } from "./Label.web";
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: "Components/Label",
|
|
6
|
+
component: Label,
|
|
7
|
+
parameters: {
|
|
8
|
+
layout: "centered",
|
|
9
|
+
},
|
|
10
|
+
tags: ["autodocs"],
|
|
11
|
+
} satisfies Meta<typeof Label>;
|
|
12
|
+
|
|
13
|
+
export default meta;
|
|
14
|
+
type Story = StoryObj<typeof meta>;
|
|
15
|
+
|
|
16
|
+
export const Default: Story = {
|
|
17
|
+
args: {
|
|
18
|
+
children: "Email address",
|
|
19
|
+
},
|
|
20
|
+
};
|