@fabio.caffarello/react-design-system 1.7.0 → 1.8.0
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 +48 -3
- package/dist/docs/components/ComponentStatusTable.d.ts +11 -0
- package/dist/ui/atoms/Accordion/Accordion.d.ts +34 -0
- package/dist/ui/atoms/Accordion/Accordion.stories.d.ts +11 -0
- package/dist/ui/atoms/Accordion/Accordion.test.d.ts +1 -0
- package/dist/ui/atoms/Accordion/index.d.ts +2 -0
- package/dist/ui/atoms/Avatar/Avatar.d.ts +30 -0
- package/dist/ui/atoms/Avatar/Avatar.stories.d.ts +13 -0
- package/dist/ui/atoms/Avatar/Avatar.test.d.ts +1 -0
- package/dist/ui/atoms/Avatar/AvatarGroup.d.ts +26 -0
- package/dist/ui/atoms/Avatar/index.d.ts +9 -0
- package/dist/ui/atoms/Badge/Badge.d.ts +14 -6
- package/dist/ui/atoms/Badge/Badge.stories.d.ts +8 -9
- package/dist/ui/atoms/BoxWrapper/BoxWrapper.d.ts +3 -3
- package/dist/ui/atoms/BoxWrapper/BoxWrapper.test.d.ts +1 -0
- package/dist/ui/atoms/Button/Button.d.ts +32 -10
- package/dist/ui/atoms/Button/Button.stories.d.ts +7 -0
- package/dist/ui/atoms/Button/Button.test.d.ts +1 -0
- package/dist/ui/atoms/Checkbox/Checkbox.d.ts +2 -1
- package/dist/ui/atoms/Collapsible/Collapsible.stories.d.ts +2 -0
- package/dist/ui/atoms/Info/Info.d.ts +2 -3
- package/dist/ui/atoms/Info/Info.test.d.ts +1 -0
- package/dist/ui/atoms/Input/Input.d.ts +14 -4
- package/dist/ui/atoms/Input/Input.stories.d.ts +6 -0
- package/dist/ui/atoms/Popover/Popover.d.ts +35 -0
- package/dist/ui/atoms/Popover/Popover.stories.d.ts +11 -0
- package/dist/ui/atoms/Popover/Popover.test.d.ts +1 -0
- package/dist/ui/atoms/Popover/index.d.ts +2 -0
- package/dist/ui/atoms/Progress/Progress.d.ts +33 -0
- package/dist/ui/atoms/Progress/Progress.stories.d.ts +12 -0
- package/dist/ui/atoms/Progress/Progress.test.d.ts +1 -0
- package/dist/ui/atoms/Select/Select.d.ts +18 -6
- package/dist/ui/atoms/Select/Select.stories.d.ts +11 -8
- package/dist/ui/atoms/Separator/Separator.d.ts +23 -0
- package/dist/ui/atoms/Separator/Separator.stories.d.ts +10 -0
- package/dist/ui/atoms/Separator/Separator.test.d.ts +1 -0
- package/dist/ui/atoms/Separator/index.d.ts +2 -0
- package/dist/ui/atoms/Skeleton/Skeleton.d.ts +1 -1
- package/dist/ui/atoms/Skeleton/Skeleton.stories.d.ts +24 -0
- package/dist/ui/atoms/Slider/Slider.d.ts +45 -0
- package/dist/ui/atoms/Slider/Slider.stories.d.ts +13 -0
- package/dist/ui/atoms/Slider/Slider.test.d.ts +1 -0
- package/dist/ui/atoms/Slider/index.d.ts +2 -0
- package/dist/ui/atoms/Spinner/Spinner.d.ts +22 -0
- package/dist/ui/atoms/Spinner/Spinner.stories.d.ts +9 -0
- package/dist/ui/atoms/Spinner/Spinner.test.d.ts +1 -0
- package/dist/ui/atoms/Switch/Switch.d.ts +28 -0
- package/dist/ui/atoms/Switch/Switch.stories.d.ts +11 -0
- package/dist/ui/atoms/Switch/Switch.test.d.ts +1 -0
- package/dist/ui/atoms/Switch/index.d.ts +2 -0
- package/dist/ui/atoms/Tooltip/Tooltip.d.ts +2 -1
- package/dist/ui/atoms/Tooltip/Tooltip.stories.d.ts +17 -0
- package/dist/ui/atoms/index.d.ts +20 -3
- package/dist/ui/index.d.ts +6 -1
- package/dist/ui/molecules/Card/Card.d.ts +6 -2
- package/dist/ui/molecules/Card/Card.stories.d.ts +2 -0
- package/dist/ui/molecules/ColorPicker/ColorPicker.d.ts +28 -0
- package/dist/ui/molecules/ColorPicker/ColorPicker.stories.d.ts +12 -0
- package/dist/ui/molecules/ColorPicker/ColorPicker.test.d.ts +1 -0
- package/dist/ui/molecules/ColorPicker/index.d.ts +2 -0
- package/dist/ui/molecules/DatePicker/DatePicker.d.ts +74 -0
- package/dist/ui/molecules/DatePicker/DatePicker.stories.d.ts +12 -0
- package/dist/ui/molecules/DatePicker/DatePicker.test.d.ts +1 -0
- package/dist/ui/molecules/DatePicker/DatePickerCalendar.d.ts +6 -0
- package/dist/ui/molecules/DatePicker/DatePickerContext.d.ts +28 -0
- package/dist/ui/molecules/DatePicker/DatePickerInput.d.ts +9 -0
- package/dist/ui/molecules/DatePicker/DatePickerProvider.d.ts +23 -0
- package/dist/ui/molecules/DatePicker/index.d.ts +14 -0
- package/dist/ui/molecules/Dropdown/Dropdown.d.ts +2 -1
- package/dist/ui/molecules/Dropdown/Dropdown.stories.d.ts +13 -0
- package/dist/ui/molecules/EmptyState/EmptyState.stories.d.ts +22 -0
- package/dist/ui/molecules/FileUpload/FileUpload.d.ts +37 -0
- package/dist/ui/molecules/FileUpload/FileUpload.stories.d.ts +12 -0
- package/dist/ui/molecules/FileUpload/FileUpload.test.d.ts +1 -0
- package/dist/ui/molecules/FileUpload/index.d.ts +2 -0
- package/dist/ui/molecules/Form/Form.d.ts +29 -4
- package/dist/ui/molecules/Form/Form.stories.d.ts +2 -0
- package/dist/ui/molecules/Form/FormContext.d.ts +17 -0
- package/dist/ui/molecules/Form/FormField.d.ts +36 -0
- package/dist/ui/molecules/Form/FormProvider.d.ts +14 -0
- package/dist/ui/molecules/Form/index.d.ts +13 -0
- package/dist/ui/molecules/Form/useFormFieldArray.d.ts +28 -0
- package/dist/ui/molecules/InputWithLabel/InputWithLabel.test.d.ts +1 -0
- package/dist/ui/molecules/Rating/Rating.d.ts +33 -0
- package/dist/ui/molecules/Rating/Rating.stories.d.ts +13 -0
- package/dist/ui/molecules/Rating/Rating.test.d.ts +1 -0
- package/dist/ui/molecules/Rating/index.d.ts +2 -0
- package/dist/ui/molecules/SearchInput/SearchInput.d.ts +24 -0
- package/dist/ui/molecules/SearchInput/SearchInput.stories.d.ts +10 -0
- package/dist/ui/molecules/SearchInput/SearchInput.test.d.ts +1 -0
- package/dist/ui/molecules/SearchInput/index.d.ts +2 -0
- package/dist/ui/molecules/SidebarHeader/SidebarHeader.test.d.ts +1 -0
- package/dist/ui/molecules/TableActions/TableActions.d.ts +31 -0
- package/dist/ui/molecules/TableActions/TableActions.stories.d.ts +7 -0
- package/dist/ui/molecules/TableActions/TableActions.test.d.ts +1 -0
- package/dist/ui/molecules/TableFilters/TableFilters.d.ts +37 -0
- package/dist/ui/molecules/TableFilters/TableFilters.stories.d.ts +7 -0
- package/dist/ui/molecules/TableFilters/TableFilters.test.d.ts +1 -0
- package/dist/ui/molecules/TablePagination/TablePagination.d.ts +29 -0
- package/dist/ui/molecules/TablePagination/TablePagination.stories.d.ts +8 -0
- package/dist/ui/molecules/TablePagination/TablePagination.test.d.ts +1 -0
- package/dist/ui/molecules/Tabs/Tabs.d.ts +15 -0
- package/dist/ui/molecules/Tabs/Tabs.stories.d.ts +10 -0
- package/dist/ui/molecules/Tabs/Tabs.test.d.ts +1 -0
- package/dist/ui/molecules/Tabs/TabsContent.d.ts +14 -0
- package/dist/ui/molecules/Tabs/TabsContext.d.ts +18 -0
- package/dist/ui/molecules/Tabs/TabsList.d.ts +12 -0
- package/dist/ui/molecules/Tabs/TabsProvider.d.ts +16 -0
- package/dist/ui/molecules/Tabs/TabsTrigger.d.ts +13 -0
- package/dist/ui/molecules/Tabs/index.d.ts +17 -0
- package/dist/ui/molecules/TimePicker/TimePicker.d.ts +29 -0
- package/dist/ui/molecules/TimePicker/TimePicker.stories.d.ts +12 -0
- package/dist/ui/molecules/TimePicker/TimePicker.test.d.ts +1 -0
- package/dist/ui/molecules/TimePicker/index.d.ts +2 -0
- package/dist/ui/molecules/index.d.ts +13 -5
- package/dist/ui/organisms/CommandPalette/CommandPalette.d.ts +37 -0
- package/dist/ui/organisms/CommandPalette/CommandPalette.stories.d.ts +11 -0
- package/dist/ui/organisms/CommandPalette/CommandPalette.test.d.ts +1 -0
- package/dist/ui/organisms/CommandPalette/index.d.ts +2 -0
- package/dist/ui/organisms/DataGrid/DataGrid.d.ts +84 -0
- package/dist/ui/organisms/DataGrid/DataGrid.stories.d.ts +14 -0
- package/dist/ui/organisms/DataGrid/DataGrid.test.d.ts +1 -0
- package/dist/ui/organisms/DataGrid/index.d.ts +2 -0
- package/dist/ui/organisms/Dialog/AlertDialog.d.ts +34 -0
- package/dist/ui/organisms/Dialog/Dialog.d.ts +58 -0
- package/dist/ui/organisms/Dialog/Dialog.stories.d.ts +13 -0
- package/dist/ui/organisms/Dialog/Dialog.test.d.ts +1 -0
- package/dist/ui/organisms/Dialog/DialogClose.d.ts +8 -0
- package/dist/ui/organisms/Dialog/DialogContent.d.ts +8 -0
- package/dist/ui/organisms/Dialog/DialogContext.d.ts +10 -0
- package/dist/ui/organisms/Dialog/DialogDescription.d.ts +4 -0
- package/dist/ui/organisms/Dialog/DialogFooter.d.ts +5 -0
- package/dist/ui/organisms/Dialog/DialogHeader.d.ts +5 -0
- package/dist/ui/organisms/Dialog/DialogProvider.d.ts +10 -0
- package/dist/ui/organisms/Dialog/DialogTitle.d.ts +5 -0
- package/dist/ui/organisms/Dialog/DialogTrigger.d.ts +6 -0
- package/dist/ui/organisms/Dialog/index.d.ts +22 -0
- package/dist/ui/organisms/Sidebar/Sidebar.d.ts +7 -4
- package/dist/ui/organisms/Sidebar/SidebarGroup/SidebarGroup.d.ts +27 -0
- package/dist/ui/organisms/Sidebar/SidebarGroup/SidebarGroup.stories.d.ts +11 -0
- package/dist/ui/organisms/Sidebar/SidebarGroup/SidebarGroup.test.d.ts +1 -0
- package/dist/ui/organisms/Sidebar/SidebarHeader/SidebarHeader.d.ts +19 -0
- package/dist/ui/organisms/Sidebar/SidebarHeader/SidebarHeader.test.d.ts +1 -0
- package/dist/ui/organisms/Sidebar/SidebarItem/SidebarItem.d.ts +23 -0
- package/dist/ui/organisms/Sidebar/SidebarItem/SidebarItem.stories.d.ts +10 -0
- package/dist/ui/organisms/Sidebar/SidebarItem/SidebarItem.test.d.ts +1 -0
- package/dist/ui/organisms/Sidebar/index.d.ts +8 -0
- package/dist/ui/organisms/Stepper/Stepper.d.ts +40 -0
- package/dist/ui/organisms/Stepper/Stepper.stories.d.ts +12 -0
- package/dist/ui/organisms/Stepper/Stepper.test.d.ts +1 -0
- package/dist/ui/organisms/Stepper/index.d.ts +2 -0
- package/dist/ui/organisms/Table/Table.d.ts +84 -16
- package/dist/ui/organisms/Table/Table.stories.d.ts +15 -0
- package/dist/ui/organisms/Table/TableActions/TableActions.d.ts +31 -0
- package/dist/ui/organisms/Table/TableActions/TableActions.stories.d.ts +7 -0
- package/dist/ui/organisms/Table/TableActions/TableActions.test.d.ts +1 -0
- package/dist/ui/organisms/Table/TableActions.d.ts +13 -0
- package/dist/ui/organisms/Table/TableBody.d.ts +12 -0
- package/dist/ui/organisms/Table/TableCell.d.ts +14 -0
- package/dist/ui/organisms/Table/TableContext.d.ts +75 -0
- package/dist/ui/organisms/Table/TableEmptyState.d.ts +11 -0
- package/dist/ui/organisms/Table/TableFilters/TableFilters.d.ts +37 -0
- package/dist/ui/organisms/Table/TableFilters/TableFilters.stories.d.ts +7 -0
- package/dist/ui/organisms/Table/TableFilters/TableFilters.test.d.ts +1 -0
- package/dist/ui/organisms/Table/TableFilters.d.ts +12 -0
- package/dist/ui/organisms/Table/TableHeader.d.ts +10 -0
- package/dist/ui/organisms/Table/TableHeaderCell.d.ts +18 -0
- package/dist/ui/organisms/Table/TableHeaderRow.d.ts +10 -0
- package/dist/ui/organisms/Table/TablePagination/TablePagination.d.ts +29 -0
- package/dist/ui/organisms/Table/TablePagination/TablePagination.stories.d.ts +8 -0
- package/dist/ui/organisms/Table/TablePagination/TablePagination.test.d.ts +1 -0
- package/dist/ui/organisms/Table/TablePagination.d.ts +14 -0
- package/dist/ui/organisms/Table/TableProvider.d.ts +55 -0
- package/dist/ui/organisms/Table/TableRow.d.ts +14 -0
- package/dist/ui/organisms/Table/TableTypes.d.ts +8 -0
- package/dist/ui/organisms/Table/index.d.ts +30 -0
- package/dist/ui/organisms/Table/useColumnResizing.d.ts +39 -0
- package/dist/ui/organisms/Table/useVirtualScrolling.d.ts +35 -0
- package/dist/ui/organisms/Timeline/Timeline.d.ts +34 -0
- package/dist/ui/organisms/Timeline/Timeline.stories.d.ts +12 -0
- package/dist/ui/organisms/Timeline/Timeline.test.d.ts +1 -0
- package/dist/ui/organisms/Timeline/index.d.ts +2 -0
- package/dist/ui/organisms/Toast/Toast.d.ts +8 -0
- package/dist/ui/organisms/Toast/Toast.stories.d.ts +14 -0
- package/dist/ui/organisms/Toast/Toast.test.d.ts +1 -0
- package/dist/ui/organisms/Toast/ToastContainer.d.ts +5 -0
- package/dist/ui/organisms/Toast/ToastContext.d.ts +21 -0
- package/dist/ui/organisms/Toast/ToastProvider.d.ts +7 -0
- package/dist/ui/organisms/Toast/index.d.ts +15 -0
- package/dist/ui/organisms/Toast/useToast.d.ts +35 -0
- package/dist/ui/organisms/index.d.ts +12 -2
- package/dist/ui/providers/AdvancedThemeProvider.d.ts +52 -0
- package/dist/ui/providers/index.d.ts +9 -0
- package/dist/ui/themes/ThemeBuilder.d.ts +28 -0
- package/dist/ui/themes/ThemeRegistry.d.ts +55 -0
- package/dist/ui/themes/index.d.ts +9 -0
- package/dist/ui/themes/types.d.ts +48 -0
- package/dist/ui/themes/utils.d.ts +21 -0
- package/dist/ui/tokens/TokenVisualizations.d.ts +41 -0
- package/dist/ui/tokens/animations.d.ts +65 -0
- package/dist/ui/tokens/borders.d.ts +61 -0
- package/dist/ui/tokens/gradients.d.ts +55 -0
- package/dist/ui/tokens/index.d.ts +31 -0
- package/dist/ui/tokens/opacity.d.ts +51 -0
- package/dist/ui/tokens/radius.d.ts +45 -0
- package/dist/ui/tokens/shadows.d.ts +42 -0
- package/dist/ui/tokens/themes/dark.d.ts +26 -26
- package/dist/ui/tokens/themes/light.d.ts +26 -26
- package/dist/ui/tokens/tokens.factory.d.ts +42 -0
- package/dist/ui/tokens/z-index.d.ts +44 -0
- package/dist/ui/utils/index.d.ts +6 -0
- package/package.json +50 -6
- package/src/docs/Accessibility.mdx +402 -0
- package/src/docs/BestPractices.mdx +315 -0
- package/src/docs/ComponentComposition.mdx +381 -0
- package/src/docs/ComponentStatus.mdx +177 -0
- package/src/docs/DesignSystem.mdx +121 -0
- package/src/docs/GettingStarted.mdx +284 -0
- package/src/docs/MigrationGuide.mdx +297 -0
- package/src/docs/Performance.mdx +206 -0
- package/src/docs/components/ComponentStatusTable.tsx +184 -0
- package/src/setupTests.ts +32 -0
- package/src/ui/atoms/Accordion/Accordion.stories.tsx +147 -0
- package/src/ui/atoms/Accordion/Accordion.test.tsx +86 -0
- package/src/ui/atoms/Accordion/Accordion.tsx +147 -0
- package/src/ui/atoms/Accordion/index.ts +2 -0
- package/src/ui/atoms/Avatar/Avatar.stories.tsx +226 -0
- package/src/ui/atoms/Avatar/Avatar.test.tsx +233 -0
- package/src/ui/atoms/Avatar/Avatar.tsx +128 -0
- package/src/ui/atoms/Avatar/AvatarGroup.tsx +96 -0
- package/src/ui/atoms/Avatar/index.ts +11 -0
- package/src/ui/atoms/Badge/Badge.stories.tsx +65 -56
- package/src/ui/atoms/Badge/Badge.test.tsx +27 -50
- package/src/ui/atoms/Badge/Badge.tsx +70 -27
- package/src/ui/atoms/BoxWrapper/BoxWrapper.stories.tsx +1 -1
- package/src/ui/atoms/BoxWrapper/BoxWrapper.test.tsx +27 -0
- package/src/ui/atoms/BoxWrapper/BoxWrapper.tsx +5 -2
- package/src/ui/atoms/Button/Button.stories.tsx +130 -1
- package/src/ui/atoms/Button/Button.test.tsx +233 -0
- package/src/ui/atoms/Button/Button.tsx +160 -53
- package/src/ui/atoms/Checkbox/Checkbox.tsx +14 -1
- package/src/ui/atoms/Collapsible/Collapsible.stories.tsx +47 -1
- package/src/ui/atoms/Collapsible/Collapsible.test.tsx +36 -24
- package/src/ui/atoms/Collapsible/Collapsible.tsx +9 -1
- package/src/ui/atoms/ErrorMessage/ErrorMessage.stories.tsx +1 -1
- package/src/ui/atoms/Info/Info.stories.tsx +1 -1
- package/src/ui/atoms/Info/Info.test.tsx +45 -0
- package/src/ui/atoms/Info/Info.tsx +2 -2
- package/src/ui/atoms/Input/Input.stories.tsx +80 -0
- package/src/ui/atoms/Input/Input.test.tsx +190 -36
- package/src/ui/atoms/Input/Input.tsx +144 -25
- package/src/ui/atoms/Label/Label.stories.tsx +1 -1
- package/src/ui/atoms/NavLink/NavLink.stories.tsx +1 -1
- package/src/ui/atoms/Popover/Popover.stories.tsx +157 -0
- package/src/ui/atoms/Popover/Popover.test.tsx +80 -0
- package/src/ui/atoms/Popover/Popover.tsx +256 -0
- package/src/ui/atoms/Popover/index.ts +2 -0
- package/src/ui/atoms/Progress/Progress.css +17 -0
- package/src/ui/atoms/Progress/Progress.stories.tsx +170 -0
- package/src/ui/atoms/Progress/Progress.test.tsx +134 -0
- package/src/ui/atoms/Progress/Progress.tsx +138 -0
- package/src/ui/atoms/Radio/Radio.tsx +1 -1
- package/src/ui/atoms/Select/Select.stories.tsx +93 -58
- package/src/ui/atoms/Select/Select.test.tsx +162 -46
- package/src/ui/atoms/Select/Select.tsx +142 -44
- package/src/ui/atoms/Separator/Separator.stories.tsx +88 -0
- package/src/ui/atoms/Separator/Separator.test.tsx +34 -0
- package/src/ui/atoms/Separator/Separator.tsx +81 -0
- package/src/ui/atoms/Separator/index.ts +2 -0
- package/src/ui/atoms/Skeleton/Skeleton.stories.tsx +62 -0
- package/src/ui/atoms/Skeleton/Skeleton.tsx +19 -2
- package/src/ui/atoms/Slider/Slider.stories.tsx +205 -0
- package/src/ui/atoms/Slider/Slider.test.tsx +53 -0
- package/src/ui/atoms/Slider/Slider.tsx +307 -0
- package/src/ui/atoms/Slider/index.ts +2 -0
- package/src/ui/atoms/Spinner/Spinner.stories.tsx +56 -0
- package/src/ui/atoms/Spinner/Spinner.test.tsx +35 -0
- package/src/ui/atoms/Spinner/Spinner.tsx +88 -0
- package/src/ui/atoms/Switch/Switch.stories.tsx +182 -0
- package/src/ui/atoms/Switch/Switch.test.tsx +90 -0
- package/src/ui/atoms/Switch/Switch.tsx +181 -0
- package/src/ui/atoms/Switch/index.ts +2 -0
- package/src/ui/atoms/Text/Text.stories.tsx +1 -1
- package/src/ui/atoms/Text/Text.test.tsx +48 -32
- package/src/ui/atoms/Textarea/Textarea.stories.tsx +1 -1
- package/src/ui/atoms/Tooltip/Tooltip.stories.tsx +44 -0
- package/src/ui/atoms/Tooltip/Tooltip.tsx +94 -6
- package/src/ui/atoms/index.ts +27 -4
- package/src/ui/index.ts +6 -1
- package/src/ui/molecules/Breadcrumb/Breadcrumb.stories.tsx +1 -1
- package/src/ui/molecules/Breadcrumb/Breadcrumb.tsx +1 -1
- package/src/ui/molecules/Card/Card.stories.tsx +49 -1
- package/src/ui/molecules/Card/Card.tsx +40 -5
- package/src/ui/molecules/ColorPicker/ColorPicker.stories.tsx +156 -0
- package/src/ui/molecules/ColorPicker/ColorPicker.test.tsx +47 -0
- package/src/ui/molecules/ColorPicker/ColorPicker.tsx +271 -0
- package/src/ui/molecules/ColorPicker/index.ts +2 -0
- package/src/ui/molecules/DatePicker/DatePicker.mdx +150 -0
- package/src/ui/molecules/DatePicker/DatePicker.stories.tsx +188 -0
- package/src/ui/molecules/DatePicker/DatePicker.test.tsx +381 -0
- package/src/ui/molecules/DatePicker/DatePicker.tsx +231 -0
- package/src/ui/molecules/DatePicker/DatePickerCalendar.tsx +277 -0
- package/src/ui/molecules/DatePicker/DatePickerContext.tsx +39 -0
- package/src/ui/molecules/DatePicker/DatePickerInput.tsx +147 -0
- package/src/ui/molecules/DatePicker/DatePickerProvider.tsx +100 -0
- package/src/ui/molecules/DatePicker/index.ts +16 -0
- package/src/ui/molecules/Dropdown/Dropdown.stories.tsx +50 -8
- package/src/ui/molecules/Dropdown/Dropdown.test.tsx +272 -12
- package/src/ui/molecules/Dropdown/Dropdown.tsx +176 -10
- package/src/ui/molecules/EmptyState/EmptyState.stories.tsx +24 -2
- package/src/ui/molecules/EmptyState/EmptyState.tsx +9 -3
- package/src/ui/molecules/FileUpload/FileUpload.stories.tsx +177 -0
- package/src/ui/molecules/FileUpload/FileUpload.test.tsx +114 -0
- package/src/ui/molecules/FileUpload/FileUpload.tsx +312 -0
- package/src/ui/molecules/FileUpload/index.ts +2 -0
- package/src/ui/molecules/Form/Form.mdx +145 -0
- package/src/ui/molecules/Form/Form.stories.tsx +121 -1
- package/src/ui/molecules/Form/Form.test.tsx +1 -3
- package/src/ui/molecules/Form/Form.tsx +95 -15
- package/src/ui/molecules/Form/FormContext.tsx +35 -0
- package/src/ui/molecules/Form/FormField.tsx +83 -0
- package/src/ui/molecules/Form/FormProvider.tsx +34 -0
- package/src/ui/molecules/Form/index.ts +21 -0
- package/src/ui/molecules/Form/useFormFieldArray.ts +46 -0
- package/src/ui/molecules/InputWithLabel/InputWithLabel.stories.tsx +1 -1
- package/src/ui/molecules/InputWithLabel/InputWithLabel.test.tsx +44 -0
- package/src/ui/molecules/InputWithLabel/InputWithLabel.tsx +3 -1
- package/src/ui/molecules/NavbarGroup/NavbarGroup.stories.tsx +1 -1
- package/src/ui/molecules/Pagination/Pagination.stories.tsx +1 -1
- package/src/ui/molecules/Rating/Rating.stories.tsx +206 -0
- package/src/ui/molecules/Rating/Rating.test.tsx +60 -0
- package/src/ui/molecules/Rating/Rating.tsx +173 -0
- package/src/ui/molecules/Rating/index.ts +2 -0
- package/src/ui/molecules/SearchInput/SearchInput.stories.tsx +146 -0
- package/src/ui/molecules/SearchInput/SearchInput.test.tsx +82 -0
- package/src/ui/molecules/SearchInput/SearchInput.tsx +133 -0
- package/src/ui/molecules/SearchInput/index.ts +2 -0
- package/src/ui/molecules/Tabs/Tabs.stories.tsx +229 -0
- package/src/ui/molecules/Tabs/Tabs.test.tsx +497 -0
- package/src/ui/molecules/Tabs/Tabs.tsx +58 -0
- package/src/ui/molecules/Tabs/TabsContent.tsx +50 -0
- package/src/ui/molecules/Tabs/TabsContext.tsx +36 -0
- package/src/ui/molecules/Tabs/TabsList.tsx +98 -0
- package/src/ui/molecules/Tabs/TabsProvider.tsx +53 -0
- package/src/ui/molecules/Tabs/TabsTrigger.tsx +111 -0
- package/src/ui/molecules/Tabs/index.ts +23 -0
- package/src/ui/molecules/TimePicker/TimePicker.stories.tsx +145 -0
- package/src/ui/molecules/TimePicker/TimePicker.test.tsx +41 -0
- package/src/ui/molecules/TimePicker/TimePicker.tsx +264 -0
- package/src/ui/molecules/TimePicker/index.ts +2 -0
- package/src/ui/molecules/index.ts +20 -7
- package/src/ui/organisms/CommandPalette/CommandPalette.stories.tsx +218 -0
- package/src/ui/organisms/CommandPalette/CommandPalette.test.tsx +85 -0
- package/src/ui/organisms/CommandPalette/CommandPalette.tsx +333 -0
- package/src/ui/organisms/CommandPalette/index.ts +2 -0
- package/src/ui/organisms/DataGrid/DataGrid.stories.tsx +196 -0
- package/src/ui/organisms/DataGrid/DataGrid.test.tsx +53 -0
- package/src/ui/organisms/DataGrid/DataGrid.tsx +294 -0
- package/src/ui/organisms/DataGrid/index.ts +2 -0
- package/src/ui/organisms/Dialog/AlertDialog.tsx +92 -0
- package/src/ui/organisms/Dialog/Dialog.mdx +200 -0
- package/src/ui/organisms/Dialog/Dialog.stories.tsx +226 -0
- package/src/ui/organisms/Dialog/Dialog.test.tsx +435 -0
- package/src/ui/organisms/Dialog/Dialog.tsx +79 -0
- package/src/ui/organisms/Dialog/DialogClose.tsx +45 -0
- package/src/ui/organisms/Dialog/DialogContent.tsx +149 -0
- package/src/ui/organisms/Dialog/DialogContext.tsx +25 -0
- package/src/ui/organisms/Dialog/DialogDescription.tsx +28 -0
- package/src/ui/organisms/Dialog/DialogFooter.tsx +18 -0
- package/src/ui/organisms/Dialog/DialogHeader.tsx +18 -0
- package/src/ui/organisms/Dialog/DialogProvider.tsx +73 -0
- package/src/ui/organisms/Dialog/DialogTitle.tsx +31 -0
- package/src/ui/organisms/Dialog/DialogTrigger.tsx +34 -0
- package/src/ui/organisms/Dialog/index.ts +24 -0
- package/src/ui/organisms/LoginBox/LoginBox.stories.tsx +1 -1
- package/src/ui/organisms/Modal/Modal.stories.tsx +2 -2
- package/src/ui/organisms/Modal/Modal.test.tsx +1 -1
- package/src/ui/organisms/Sidebar/Sidebar.stories.tsx +1 -1
- package/src/ui/organisms/Sidebar/Sidebar.test.tsx +5 -3
- package/src/ui/organisms/Sidebar/Sidebar.tsx +21 -6
- package/src/ui/{molecules → organisms/Sidebar}/SidebarGroup/SidebarGroup.stories.tsx +2 -2
- package/src/ui/{molecules → organisms/Sidebar}/SidebarGroup/SidebarGroup.test.tsx +32 -9
- package/src/ui/{molecules → organisms/Sidebar}/SidebarGroup/SidebarGroup.tsx +7 -7
- package/src/ui/organisms/Sidebar/SidebarHeader/SidebarHeader.test.tsx +66 -0
- package/src/ui/{molecules → organisms/Sidebar}/SidebarHeader/SidebarHeader.tsx +1 -2
- package/src/ui/{atoms → organisms/Sidebar}/SidebarItem/SidebarItem.stories.tsx +1 -1
- package/src/ui/{atoms → organisms/Sidebar}/SidebarItem/SidebarItem.test.tsx +9 -8
- package/src/ui/{atoms → organisms/Sidebar}/SidebarItem/SidebarItem.tsx +9 -3
- package/src/ui/organisms/Sidebar/index.ts +13 -0
- package/src/ui/organisms/Stepper/Stepper.stories.tsx +253 -0
- package/src/ui/organisms/Stepper/Stepper.test.tsx +76 -0
- package/src/ui/organisms/Stepper/Stepper.tsx +323 -0
- package/src/ui/organisms/Stepper/index.ts +2 -0
- package/src/ui/organisms/Table/Table.mdx +154 -0
- package/src/ui/organisms/Table/Table.stories.tsx +614 -4
- package/src/ui/organisms/Table/Table.test.tsx +86 -4
- package/src/ui/organisms/Table/Table.tsx +215 -99
- package/src/ui/organisms/Table/TableActions/TableActions.stories.tsx +88 -0
- package/src/ui/organisms/Table/TableActions/TableActions.test.tsx +64 -0
- package/src/ui/organisms/Table/TableActions/TableActions.tsx +71 -0
- package/src/ui/organisms/Table/TableActions.tsx +46 -0
- package/src/ui/organisms/Table/TableBody.tsx +137 -0
- package/src/ui/organisms/Table/TableCell.tsx +36 -0
- package/src/ui/organisms/Table/TableContext.tsx +111 -0
- package/src/ui/organisms/Table/TableEmptyState.tsx +51 -0
- package/src/ui/organisms/Table/TableFilters/TableFilters.stories.tsx +111 -0
- package/src/ui/organisms/Table/TableFilters/TableFilters.test.tsx +104 -0
- package/src/ui/organisms/Table/TableFilters/TableFilters.tsx +191 -0
- package/src/ui/organisms/Table/TableFilters.tsx +39 -0
- package/src/ui/organisms/Table/TableHeader.tsx +29 -0
- package/src/ui/organisms/Table/TableHeaderCell.tsx +142 -0
- package/src/ui/organisms/Table/TableHeaderRow.tsx +72 -0
- package/src/ui/organisms/Table/TablePagination/TablePagination.stories.tsx +87 -0
- package/src/ui/organisms/Table/TablePagination/TablePagination.test.tsx +90 -0
- package/src/ui/organisms/Table/TablePagination/TablePagination.tsx +207 -0
- package/src/ui/organisms/Table/TablePagination.tsx +48 -0
- package/src/ui/organisms/Table/TableProvider.tsx +429 -0
- package/src/ui/organisms/Table/TableRow.tsx +85 -0
- package/src/ui/organisms/Table/TableTypes.ts +11 -0
- package/src/ui/organisms/Table/index.ts +55 -0
- package/src/ui/organisms/Table/useColumnResizing.ts +134 -0
- package/src/ui/organisms/Table/useVirtualScrolling.ts +116 -0
- package/src/ui/organisms/Timeline/Timeline.stories.tsx +230 -0
- package/src/ui/organisms/Timeline/Timeline.test.tsx +47 -0
- package/src/ui/organisms/Timeline/Timeline.tsx +179 -0
- package/src/ui/organisms/Timeline/index.ts +2 -0
- package/src/ui/organisms/Toast/Toast.stories.tsx +169 -0
- package/src/ui/organisms/Toast/Toast.test.tsx +537 -0
- package/src/ui/organisms/Toast/Toast.tsx +144 -0
- package/src/ui/organisms/Toast/ToastContainer.tsx +54 -0
- package/src/ui/organisms/Toast/ToastContext.tsx +38 -0
- package/src/ui/organisms/Toast/ToastProvider.tsx +56 -0
- package/src/ui/organisms/Toast/index.ts +17 -0
- package/src/ui/organisms/Toast/useToast.ts +70 -0
- package/src/ui/organisms/index.ts +17 -2
- package/src/ui/providers/AdvancedThemeProvider.tsx +229 -0
- package/src/ui/providers/index.ts +14 -0
- package/src/ui/themes/README.md +281 -0
- package/src/ui/themes/ThemeBuilder.ts +149 -0
- package/src/ui/themes/ThemeRegistry.ts +187 -0
- package/src/ui/themes/index.ts +20 -0
- package/src/ui/themes/types.ts +53 -0
- package/src/ui/themes/utils.ts +70 -0
- package/src/ui/tokens/README.md +212 -0
- package/src/ui/tokens/TokenVisualizations.tsx +273 -0
- package/src/ui/tokens/Tokens.mdx +348 -0
- package/src/ui/tokens/animations.ts +157 -0
- package/src/ui/tokens/borders.ts +121 -0
- package/src/ui/tokens/gradients.ts +154 -0
- package/src/ui/tokens/index.ts +57 -0
- package/src/ui/tokens/opacity.ts +107 -0
- package/src/ui/tokens/radius.ts +107 -0
- package/src/ui/tokens/shadows.ts +92 -0
- package/src/ui/tokens/tokens.factory.ts +124 -0
- package/src/ui/tokens/z-index.ts +113 -0
- package/src/ui/utils/index.ts +10 -0
- package/src/App.css +0 -42
- package/src/App.tsx +0 -35
- package/src/index.css +0 -68
- package/src/main.tsx +0 -15
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import Rating from './Rating';
|
|
4
|
+
|
|
5
|
+
describe('Rating', () => {
|
|
6
|
+
it('renders correctly', () => {
|
|
7
|
+
render(<Rating value={3} max={5} />);
|
|
8
|
+
const stars = screen.getAllByRole('button');
|
|
9
|
+
expect(stars.length).toBeGreaterThan(0);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('displays correct number of stars', () => {
|
|
13
|
+
render(<Rating value={0} max={5} />);
|
|
14
|
+
const stars = screen.getAllByRole('button');
|
|
15
|
+
expect(stars).toHaveLength(5);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('calls onChange when star is clicked', () => {
|
|
19
|
+
const handleChange = vi.fn();
|
|
20
|
+
render(<Rating value={0} onChange={handleChange} />);
|
|
21
|
+
const stars = screen.getAllByRole('button');
|
|
22
|
+
fireEvent.click(stars[2]);
|
|
23
|
+
expect(handleChange).toHaveBeenCalledWith(3);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('handles read-only mode', () => {
|
|
27
|
+
render(<Rating value={4} readOnly />);
|
|
28
|
+
const container = screen.getByRole('img');
|
|
29
|
+
expect(container).toBeInTheDocument();
|
|
30
|
+
const stars = screen.queryAllByRole('button');
|
|
31
|
+
expect(stars).toHaveLength(0);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('displays value when showValue is true', () => {
|
|
35
|
+
render(<Rating value={3.5} max={5} showValue allowHalf />);
|
|
36
|
+
expect(screen.getByText('3.5/5')).toBeInTheDocument();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('handles different sizes', () => {
|
|
40
|
+
const { rerender, container } = render(<Rating value={3} size="sm" />);
|
|
41
|
+
const ratingContainer = container.querySelector('div[role="img"]') || container.querySelector('div');
|
|
42
|
+
expect(ratingContainer).toBeInTheDocument();
|
|
43
|
+
|
|
44
|
+
rerender(<Rating value={3} size="md" />);
|
|
45
|
+
const ratingContainer2 = container.querySelector('div[role="img"]') || container.querySelector('div');
|
|
46
|
+
expect(ratingContainer2).toBeInTheDocument();
|
|
47
|
+
|
|
48
|
+
rerender(<Rating value={3} size="lg" />);
|
|
49
|
+
const ratingContainer3 = container.querySelector('div[role="img"]') || container.querySelector('div');
|
|
50
|
+
expect(ratingContainer3).toBeInTheDocument();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('handles keyboard navigation', () => {
|
|
54
|
+
const handleChange = vi.fn();
|
|
55
|
+
render(<Rating value={0} onChange={handleChange} />);
|
|
56
|
+
const stars = screen.getAllByRole('button');
|
|
57
|
+
fireEvent.keyDown(stars[2], { key: 'Enter' });
|
|
58
|
+
expect(handleChange).toHaveBeenCalledWith(3);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState, type ReactNode } from 'react';
|
|
4
|
+
import { Star } from 'lucide-react';
|
|
5
|
+
import { getColorClass } from '../../tokens/colors';
|
|
6
|
+
import { getSpacingClass } from '../../tokens/spacing';
|
|
7
|
+
import { getAnimationClass } from '../../tokens/animations';
|
|
8
|
+
|
|
9
|
+
export type RatingSize = 'sm' | 'md' | 'lg';
|
|
10
|
+
export type RatingVariant = 'filled' | 'outlined';
|
|
11
|
+
|
|
12
|
+
export interface RatingProps {
|
|
13
|
+
value?: number;
|
|
14
|
+
defaultValue?: number;
|
|
15
|
+
max?: number;
|
|
16
|
+
size?: RatingSize;
|
|
17
|
+
variant?: RatingVariant;
|
|
18
|
+
readOnly?: boolean;
|
|
19
|
+
allowHalf?: boolean;
|
|
20
|
+
showValue?: boolean;
|
|
21
|
+
onChange?: (value: number) => void;
|
|
22
|
+
onHover?: (value: number) => void;
|
|
23
|
+
className?: string;
|
|
24
|
+
icon?: ReactNode;
|
|
25
|
+
emptyIcon?: ReactNode;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Rating Component
|
|
30
|
+
*
|
|
31
|
+
* A rating component for displaying and selecting ratings.
|
|
32
|
+
* Supports filled and outlined variants, half ratings, and read-only mode.
|
|
33
|
+
* Follows Atomic Design principles as a Molecule component.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* <Rating value={4} max={5} onChange={(value) => console.log(value)} />
|
|
38
|
+
*
|
|
39
|
+
* <Rating value={3.5} readOnly showValue />
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export default function Rating({
|
|
43
|
+
value: controlledValue,
|
|
44
|
+
defaultValue = 0,
|
|
45
|
+
max = 5,
|
|
46
|
+
size = 'md',
|
|
47
|
+
variant = 'filled',
|
|
48
|
+
readOnly = false,
|
|
49
|
+
allowHalf = false,
|
|
50
|
+
showValue = false,
|
|
51
|
+
onChange,
|
|
52
|
+
onHover,
|
|
53
|
+
className = '',
|
|
54
|
+
icon,
|
|
55
|
+
emptyIcon,
|
|
56
|
+
}: RatingProps) {
|
|
57
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
58
|
+
const [hoverValue, setHoverValue] = useState<number | null>(null);
|
|
59
|
+
|
|
60
|
+
const isControlled = controlledValue !== undefined;
|
|
61
|
+
const displayValue = hoverValue ?? (isControlled ? controlledValue : internalValue);
|
|
62
|
+
|
|
63
|
+
const sizeConfig = {
|
|
64
|
+
sm: 'h-4 w-4',
|
|
65
|
+
md: 'h-5 w-5',
|
|
66
|
+
lg: 'h-6 w-6',
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const handleClick = (newValue: number) => {
|
|
70
|
+
if (readOnly) return;
|
|
71
|
+
|
|
72
|
+
if (!isControlled) {
|
|
73
|
+
setInternalValue(newValue);
|
|
74
|
+
}
|
|
75
|
+
onChange?.(newValue);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const handleMouseEnter = (newValue: number) => {
|
|
79
|
+
if (readOnly) return;
|
|
80
|
+
setHoverValue(newValue);
|
|
81
|
+
onHover?.(newValue);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const handleMouseLeave = () => {
|
|
85
|
+
if (readOnly) return;
|
|
86
|
+
setHoverValue(null);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const renderStar = (index: number) => {
|
|
90
|
+
const starValue = index + 1;
|
|
91
|
+
const isHalf = allowHalf && displayValue >= starValue - 0.5 && displayValue < starValue;
|
|
92
|
+
const isFilled = displayValue >= starValue;
|
|
93
|
+
|
|
94
|
+
const starClasses = [
|
|
95
|
+
sizeConfig[size],
|
|
96
|
+
getAnimationClass('base'),
|
|
97
|
+
!readOnly && 'cursor-pointer',
|
|
98
|
+
isFilled || isHalf
|
|
99
|
+
? variant === 'filled'
|
|
100
|
+
? getColorClass('warning', 'DEFAULT', 'text')
|
|
101
|
+
: getColorClass('warning', 'DEFAULT', 'text')
|
|
102
|
+
: 'text-gray-300',
|
|
103
|
+
].filter(Boolean).join(' ');
|
|
104
|
+
|
|
105
|
+
const CustomIcon = icon || <Star className={starClasses} fill={isFilled ? 'currentColor' : 'none'} />;
|
|
106
|
+
const CustomEmptyIcon = emptyIcon || <Star className={starClasses} fill="none" />;
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<span
|
|
110
|
+
key={index}
|
|
111
|
+
className="relative inline-block"
|
|
112
|
+
onClick={() => handleClick(starValue)}
|
|
113
|
+
onMouseEnter={() => handleMouseEnter(starValue)}
|
|
114
|
+
onMouseLeave={handleMouseLeave}
|
|
115
|
+
role={readOnly ? undefined : 'button'}
|
|
116
|
+
tabIndex={readOnly ? undefined : 0}
|
|
117
|
+
aria-label={`Rate ${starValue} out of ${max}`}
|
|
118
|
+
onKeyDown={(e) => {
|
|
119
|
+
if (!readOnly && (e.key === 'Enter' || e.key === ' ')) {
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
handleClick(starValue);
|
|
122
|
+
}
|
|
123
|
+
}}
|
|
124
|
+
>
|
|
125
|
+
{isHalf ? (
|
|
126
|
+
<span className="relative inline-block">
|
|
127
|
+
<span className="absolute inset-0 overflow-hidden" style={{ width: '50%' }}>
|
|
128
|
+
{variant === 'filled' ? (
|
|
129
|
+
<Star className={starClasses} fill="currentColor" />
|
|
130
|
+
) : (
|
|
131
|
+
CustomIcon
|
|
132
|
+
)}
|
|
133
|
+
</span>
|
|
134
|
+
{variant === 'filled' ? (
|
|
135
|
+
<Star className={starClasses} fill="none" />
|
|
136
|
+
) : (
|
|
137
|
+
CustomEmptyIcon
|
|
138
|
+
)}
|
|
139
|
+
</span>
|
|
140
|
+
) : isFilled ? (
|
|
141
|
+
variant === 'filled' ? (
|
|
142
|
+
<Star className={starClasses} fill="currentColor" />
|
|
143
|
+
) : (
|
|
144
|
+
CustomIcon
|
|
145
|
+
)
|
|
146
|
+
) : (
|
|
147
|
+
variant === 'filled' ? (
|
|
148
|
+
<Star className={starClasses} fill="none" />
|
|
149
|
+
) : (
|
|
150
|
+
CustomEmptyIcon
|
|
151
|
+
)
|
|
152
|
+
)}
|
|
153
|
+
</span>
|
|
154
|
+
);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<div className={`inline-flex items-center gap-1 ${className}`}>
|
|
159
|
+
<div
|
|
160
|
+
className="flex items-center"
|
|
161
|
+
role={readOnly ? 'img' : undefined}
|
|
162
|
+
aria-label={readOnly ? `Rating: ${displayValue} out of ${max}` : undefined}
|
|
163
|
+
>
|
|
164
|
+
{Array.from({ length: max }, (_, i) => renderStar(i))}
|
|
165
|
+
</div>
|
|
166
|
+
{showValue && (
|
|
167
|
+
<span className={`${getSpacingClass('sm', 'ml')} text-sm text-gray-600`}>
|
|
168
|
+
{displayValue.toFixed(allowHalf ? 1 : 0)}/{max}
|
|
169
|
+
</span>
|
|
170
|
+
)}
|
|
171
|
+
</div>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import SearchInput from './SearchInput';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof SearchInput> = {
|
|
6
|
+
title: 'Molecules/SearchInput',
|
|
7
|
+
component: SearchInput,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: 'centered',
|
|
11
|
+
},
|
|
12
|
+
argTypes: {
|
|
13
|
+
loading: {
|
|
14
|
+
control: 'boolean',
|
|
15
|
+
},
|
|
16
|
+
showClearButton: {
|
|
17
|
+
control: 'boolean',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default meta;
|
|
23
|
+
type Story = StoryObj<typeof SearchInput>;
|
|
24
|
+
|
|
25
|
+
export const Default: Story = {
|
|
26
|
+
render: (args) => {
|
|
27
|
+
const [value, setValue] = useState('');
|
|
28
|
+
return (
|
|
29
|
+
<div className="w-64">
|
|
30
|
+
<SearchInput
|
|
31
|
+
{...args}
|
|
32
|
+
value={value}
|
|
33
|
+
onChange={(e) => setValue(e.target.value)}
|
|
34
|
+
onSearch={(val) => console.log('Search:', val)}
|
|
35
|
+
/>
|
|
36
|
+
<p className="mt-2 text-sm text-gray-600">Value: {value}</p>
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
args: {
|
|
41
|
+
placeholder: 'Search...',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const WithLoading: Story = {
|
|
46
|
+
render: (args) => {
|
|
47
|
+
const [loading, setLoading] = useState(false);
|
|
48
|
+
const [value, setValue] = useState('');
|
|
49
|
+
|
|
50
|
+
const handleSearch = (_val: string) => {
|
|
51
|
+
setLoading(true);
|
|
52
|
+
setTimeout(() => setLoading(false), 2000);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<div className="w-64">
|
|
57
|
+
<SearchInput
|
|
58
|
+
{...args}
|
|
59
|
+
value={value}
|
|
60
|
+
onChange={(e) => setValue(e.target.value)}
|
|
61
|
+
onSearch={handleSearch}
|
|
62
|
+
loading={loading}
|
|
63
|
+
/>
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
},
|
|
67
|
+
args: {
|
|
68
|
+
placeholder: 'Search with loading...',
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const WithoutClearButton: Story = {
|
|
73
|
+
render: (args) => {
|
|
74
|
+
const [value, setValue] = useState('test');
|
|
75
|
+
return (
|
|
76
|
+
<div className="w-64">
|
|
77
|
+
<SearchInput
|
|
78
|
+
{...args}
|
|
79
|
+
value={value}
|
|
80
|
+
onChange={(e) => setValue(e.target.value)}
|
|
81
|
+
showClearButton={false}
|
|
82
|
+
/>
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
},
|
|
86
|
+
args: {
|
|
87
|
+
placeholder: 'Search without clear...',
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const WithDebounce: Story = {
|
|
92
|
+
render: (args) => {
|
|
93
|
+
const [value, setValue] = useState('');
|
|
94
|
+
const [searchResults, setSearchResults] = useState<string[]>([]);
|
|
95
|
+
|
|
96
|
+
const handleSearch = (val: string) => {
|
|
97
|
+
setSearchResults([`Result 1 for "${val}"`, `Result 2 for "${val}"`]);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<div className="w-64 space-y-4">
|
|
102
|
+
<SearchInput
|
|
103
|
+
{...args}
|
|
104
|
+
value={value}
|
|
105
|
+
onChange={(e) => setValue(e.target.value)}
|
|
106
|
+
onSearch={handleSearch}
|
|
107
|
+
debounceMs={500}
|
|
108
|
+
/>
|
|
109
|
+
{searchResults.length > 0 && (
|
|
110
|
+
<div className="border border-gray-200 rounded-md p-2">
|
|
111
|
+
<p className="text-sm font-medium mb-2">Results:</p>
|
|
112
|
+
<ul className="text-sm space-y-1">
|
|
113
|
+
{searchResults.map((result, i) => (
|
|
114
|
+
<li key={i}>{result}</li>
|
|
115
|
+
))}
|
|
116
|
+
</ul>
|
|
117
|
+
</div>
|
|
118
|
+
)}
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
},
|
|
122
|
+
args: {
|
|
123
|
+
placeholder: 'Search with 500ms debounce...',
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const InForm: Story = {
|
|
128
|
+
render: () => {
|
|
129
|
+
const [searchValue, setSearchValue] = useState('');
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<div className="w-96 space-y-4 p-4 border border-gray-200 rounded-lg">
|
|
133
|
+
<h3 className="text-lg font-semibold">Search Form</h3>
|
|
134
|
+
<SearchInput
|
|
135
|
+
placeholder="Search products..."
|
|
136
|
+
value={searchValue}
|
|
137
|
+
onChange={(e) => setSearchValue(e.target.value)}
|
|
138
|
+
onSearch={(val) => console.log('Searching for:', val)}
|
|
139
|
+
/>
|
|
140
|
+
<p className="text-sm text-gray-600">
|
|
141
|
+
Press Enter or wait for debounce to trigger search
|
|
142
|
+
</p>
|
|
143
|
+
</div>
|
|
144
|
+
);
|
|
145
|
+
},
|
|
146
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent, act } from '@testing-library/react';
|
|
3
|
+
import SearchInput from './SearchInput';
|
|
4
|
+
|
|
5
|
+
describe('SearchInput', () => {
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
vi.useFakeTimers();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
vi.runOnlyPendingTimers();
|
|
12
|
+
vi.useRealTimers();
|
|
13
|
+
vi.clearAllMocks();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('renders correctly', () => {
|
|
17
|
+
render(<SearchInput />);
|
|
18
|
+
const input = screen.getByRole('searchbox') || screen.getByRole('textbox') || document.querySelector('input[type="search"]');
|
|
19
|
+
expect(input).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('calls onSearch with debounce', async () => {
|
|
23
|
+
const handleSearch = vi.fn();
|
|
24
|
+
render(<SearchInput onSearch={handleSearch} debounceMs={300} />);
|
|
25
|
+
|
|
26
|
+
const input = screen.getByRole('searchbox') || screen.getByRole('textbox') || document.querySelector('input[type="search"]') as HTMLInputElement;
|
|
27
|
+
expect(input).toBeInTheDocument();
|
|
28
|
+
|
|
29
|
+
act(() => {
|
|
30
|
+
fireEvent.change(input, { target: { value: 'test' } });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
expect(handleSearch).not.toHaveBeenCalled();
|
|
34
|
+
|
|
35
|
+
// Advance timers for debounce - need to advance more than debounceMs
|
|
36
|
+
act(() => {
|
|
37
|
+
vi.advanceTimersByTime(350);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Run all pending timers to ensure debounce completes
|
|
41
|
+
act(() => {
|
|
42
|
+
vi.runOnlyPendingTimers();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Check if callback was called
|
|
46
|
+
expect(handleSearch).toHaveBeenCalledWith('test');
|
|
47
|
+
}, 10000);
|
|
48
|
+
|
|
49
|
+
it('calls onSearch on Enter key', () => {
|
|
50
|
+
const handleSearch = vi.fn();
|
|
51
|
+
render(<SearchInput onSearch={handleSearch} defaultValue="test" />);
|
|
52
|
+
|
|
53
|
+
const input = screen.getByRole('searchbox') || screen.getByRole('textbox') || document.querySelector('input[type="search"]') as HTMLInputElement;
|
|
54
|
+
fireEvent.keyDown(input, { key: 'Enter' });
|
|
55
|
+
|
|
56
|
+
expect(handleSearch).toHaveBeenCalledWith('test');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('shows clear button when value exists', () => {
|
|
60
|
+
render(<SearchInput defaultValue="test" showClearButton />);
|
|
61
|
+
expect(screen.getByLabelText('Clear search')).toBeInTheDocument();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('calls onClear when clear button is clicked', () => {
|
|
65
|
+
const handleClear = vi.fn();
|
|
66
|
+
render(<SearchInput defaultValue="test" onClear={handleClear} />);
|
|
67
|
+
|
|
68
|
+
const clearButton = screen.getByLabelText('Clear search');
|
|
69
|
+
fireEvent.click(clearButton);
|
|
70
|
+
|
|
71
|
+
expect(handleClear).toHaveBeenCalled();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('shows loading state', () => {
|
|
75
|
+
render(<SearchInput loading />);
|
|
76
|
+
const input = screen.getByRole('searchbox') || screen.getByRole('textbox') || document.querySelector('input[type="search"]');
|
|
77
|
+
expect(input).toBeInTheDocument();
|
|
78
|
+
// Check for loading indicator (spinner)
|
|
79
|
+
const spinner = document.querySelector('.animate-spin');
|
|
80
|
+
expect(spinner).toBeInTheDocument();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState, forwardRef } from 'react';
|
|
4
|
+
import type { InputHTMLAttributes } from 'react';
|
|
5
|
+
import { Search, X } from 'lucide-react';
|
|
6
|
+
import Input from '../../atoms/Input/Input';
|
|
7
|
+
import Button from '../../atoms/Button/Button';
|
|
8
|
+
|
|
9
|
+
export interface SearchInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size' | 'onChange'> {
|
|
10
|
+
onSearch?: (value: string) => void;
|
|
11
|
+
onClear?: () => void;
|
|
12
|
+
loading?: boolean;
|
|
13
|
+
showClearButton?: boolean;
|
|
14
|
+
debounceMs?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* SearchInput Component
|
|
19
|
+
*
|
|
20
|
+
* A search input component with icon, clear button, and loading state.
|
|
21
|
+
* Follows Atomic Design principles as a Molecule component.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <SearchInput
|
|
26
|
+
* placeholder="Search..."
|
|
27
|
+
* onSearch={(value) => console.log(value)}
|
|
28
|
+
* />
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
const SearchInput = forwardRef<HTMLInputElement, SearchInputProps>(function SearchInput({
|
|
32
|
+
onSearch,
|
|
33
|
+
onClear,
|
|
34
|
+
loading = false,
|
|
35
|
+
showClearButton = true,
|
|
36
|
+
debounceMs = 300,
|
|
37
|
+
value: controlledValue,
|
|
38
|
+
defaultValue,
|
|
39
|
+
onChange,
|
|
40
|
+
className = '',
|
|
41
|
+
...props
|
|
42
|
+
}, ref) {
|
|
43
|
+
const [internalValue, setInternalValue] = useState<string>(
|
|
44
|
+
typeof defaultValue === 'string' ? defaultValue : ''
|
|
45
|
+
);
|
|
46
|
+
const [debounceTimer, setDebounceTimer] = useState<NodeJS.Timeout | null>(null);
|
|
47
|
+
|
|
48
|
+
const isControlled = controlledValue !== undefined;
|
|
49
|
+
const currentValue = isControlled ? controlledValue : internalValue;
|
|
50
|
+
const hasValue = currentValue !== undefined && currentValue !== null && String(currentValue).length > 0;
|
|
51
|
+
|
|
52
|
+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
53
|
+
const newValue = e.target.value;
|
|
54
|
+
|
|
55
|
+
if (!isControlled) {
|
|
56
|
+
setInternalValue(newValue);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
onChange?.(e);
|
|
60
|
+
|
|
61
|
+
// Debounce search
|
|
62
|
+
if (debounceTimer) {
|
|
63
|
+
clearTimeout(debounceTimer);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const timer = setTimeout(() => {
|
|
67
|
+
onSearch?.(newValue);
|
|
68
|
+
}, debounceMs);
|
|
69
|
+
|
|
70
|
+
setDebounceTimer(timer);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const handleClear = () => {
|
|
74
|
+
if (!isControlled) {
|
|
75
|
+
setInternalValue('');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Create synthetic event for onChange
|
|
79
|
+
const syntheticEvent = {
|
|
80
|
+
target: { value: '' },
|
|
81
|
+
currentTarget: { value: '' },
|
|
82
|
+
} as React.ChangeEvent<HTMLInputElement>;
|
|
83
|
+
onChange?.(syntheticEvent);
|
|
84
|
+
|
|
85
|
+
onClear?.();
|
|
86
|
+
onSearch?.('');
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
90
|
+
if (e.key === 'Enter' && onSearch) {
|
|
91
|
+
onSearch(String(currentValue || ''));
|
|
92
|
+
}
|
|
93
|
+
props.onKeyDown?.(e);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<div className={`relative ${className}`}>
|
|
98
|
+
<Input
|
|
99
|
+
ref={ref}
|
|
100
|
+
{...props}
|
|
101
|
+
type="search"
|
|
102
|
+
value={currentValue}
|
|
103
|
+
onChange={handleChange}
|
|
104
|
+
onKeyDown={handleKeyDown}
|
|
105
|
+
leftIcon={loading ? (
|
|
106
|
+
<div className="animate-spin">
|
|
107
|
+
<Search className="h-4 w-4" />
|
|
108
|
+
</div>
|
|
109
|
+
) : (
|
|
110
|
+
<Search className="h-4 w-4" />
|
|
111
|
+
)}
|
|
112
|
+
rightIcon={
|
|
113
|
+
showClearButton && hasValue && !loading ? (
|
|
114
|
+
<Button
|
|
115
|
+
variant="ghost"
|
|
116
|
+
size="sm"
|
|
117
|
+
onClick={handleClear}
|
|
118
|
+
className="h-auto p-1"
|
|
119
|
+
aria-label="Clear search"
|
|
120
|
+
>
|
|
121
|
+
<X className="h-4 w-4" />
|
|
122
|
+
</Button>
|
|
123
|
+
) : undefined
|
|
124
|
+
}
|
|
125
|
+
className="pr-10"
|
|
126
|
+
/>
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
SearchInput.displayName = 'SearchInput';
|
|
132
|
+
|
|
133
|
+
export default SearchInput;
|