@boxcustodia/library 2.0.0-alpha.11 → 2.0.0-alpha.13
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/dist/index.cjs.js +38 -38
- package/dist/index.css +1 -1
- package/dist/index.d.ts +28 -29
- package/dist/index.es.js +6804 -6792
- package/package.json +4 -3
- package/src/__doc__/Changelog.mdx +6 -0
- package/src/__doc__/Components.mdx +73 -0
- package/src/__doc__/Examples.tsx +69 -0
- package/src/__doc__/Icons.mdx +41 -0
- package/src/__doc__/Intro.mdx +138 -0
- package/src/__doc__/MCP.mdx +71 -0
- package/src/__doc__/Migration.mdx +451 -0
- package/src/__doc__/Theme.mdx +132 -0
- package/src/__doc__/Types.mdx +252 -0
- package/src/components/alert/alert.stories.tsx +142 -0
- package/src/components/alert/alert.tsx +109 -0
- package/src/components/alert/index.ts +7 -0
- package/src/components/alert-dialog/alert-dialog.stories.tsx +173 -0
- package/src/components/alert-dialog/alert-dialog.test.tsx +49 -0
- package/src/components/alert-dialog/alert-dialog.tsx +265 -0
- package/src/components/alert-dialog/index.ts +1 -0
- package/src/components/auto-complete/auto-complete-primitives.tsx +155 -0
- package/src/components/auto-complete/auto-complete.stories.tsx +241 -0
- package/src/components/auto-complete/auto-complete.tsx +82 -0
- package/src/components/auto-complete/index.ts +2 -0
- package/src/components/avatar/avatar.stories.tsx +84 -0
- package/src/components/avatar/avatar.test.tsx +61 -0
- package/src/components/avatar/avatar.tsx +104 -0
- package/src/components/avatar/index.ts +1 -0
- package/src/components/background-image/background-image.stories.tsx +21 -0
- package/src/components/background-image/background-image.test.tsx +29 -0
- package/src/components/background-image/background-image.tsx +23 -0
- package/src/components/background-image/index.ts +1 -0
- package/src/components/button/button.stories.tsx +396 -0
- package/src/components/button/button.test.tsx +58 -0
- package/src/components/button/button.tsx +31 -0
- package/src/components/button/button.variants.ts +44 -0
- package/src/components/button/components/base-button.tsx +86 -0
- package/src/components/button/components/loader-overlay.tsx +21 -0
- package/src/components/button/components/loading-icon.tsx +47 -0
- package/src/components/button/index.ts +3 -0
- package/src/components/calendar/calendar.model.ts +86 -0
- package/src/components/calendar/calendar.stories.tsx +155 -0
- package/src/components/calendar/calendar.test.tsx +12 -0
- package/src/components/calendar/calendar.tsx +185 -0
- package/src/components/calendar/components/calendar-navigation.tsx +141 -0
- package/src/components/calendar/components/day.tsx +61 -0
- package/src/components/calendar/components/decade-view.tsx +45 -0
- package/src/components/calendar/components/index.ts +6 -0
- package/src/components/calendar/components/month-view.tsx +58 -0
- package/src/components/calendar/components/week-days.tsx +27 -0
- package/src/components/calendar/components/year-view.tsx +29 -0
- package/src/components/calendar/hooks/index.ts +4 -0
- package/src/components/calendar/hooks/use-calendar-navigation.ts +79 -0
- package/src/components/calendar/hooks/use-calendar.ts +90 -0
- package/src/components/calendar/hooks/use-multiple-calendar.ts +34 -0
- package/src/components/calendar/hooks/use-range-calendar.ts +91 -0
- package/src/components/calendar/hooks/use-single-calendar.ts +18 -0
- package/src/components/calendar/index.ts +1 -0
- package/src/components/calendar/utils/typeguards.ts +7 -0
- package/src/components/card/card.stories.tsx +116 -0
- package/src/components/card/card.tsx +74 -0
- package/src/components/card/index.ts +1 -0
- package/src/components/center/center.stories.tsx +81 -0
- package/src/components/center/center.tsx +24 -0
- package/src/components/center/index.ts +1 -0
- package/src/components/checkbox/checkbox.stories.tsx +307 -0
- package/src/components/checkbox/checkbox.tsx +273 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/checkbox-group/checkbox-group.stories.tsx +104 -0
- package/src/components/checkbox-group/checkbox-group.tsx +16 -0
- package/src/components/checkbox-group/index.ts +1 -0
- package/src/components/combobox/combobox.stories.tsx +339 -0
- package/src/components/combobox/combobox.tsx +898 -0
- package/src/components/combobox/index.ts +1 -0
- package/src/components/date-picker/date-input.stories.tsx +158 -0
- package/src/components/date-picker/date-input.tsx +163 -0
- package/src/components/date-picker/date-picker.model.ts +90 -0
- package/src/components/date-picker/date-picker.stories.tsx +200 -0
- package/src/components/date-picker/date-picker.test.tsx +23 -0
- package/src/components/date-picker/date-picker.tsx +298 -0
- package/src/components/date-picker/date-picker.utils.ts +260 -0
- package/src/components/date-picker/index.ts +3 -0
- package/src/components/date-picker/use-date-input-popover.ts +48 -0
- package/src/components/date-picker/use-date-input.ts +125 -0
- package/src/components/dialog/dialog.stories.tsx +171 -0
- package/src/components/dialog/dialog.test.tsx +68 -0
- package/src/components/dialog/dialog.tsx +277 -0
- package/src/components/dialog/index.ts +1 -0
- package/src/components/divider/divider.stories.tsx +139 -0
- package/src/components/divider/divider.test.tsx +22 -0
- package/src/components/divider/divider.tsx +23 -0
- package/src/components/divider/index.ts +1 -0
- package/src/components/dropzone/dropzone.stories.tsx +210 -0
- package/src/components/dropzone/dropzone.tsx +154 -0
- package/src/components/dropzone/file-types.ts +64 -0
- package/src/components/dropzone/index.ts +3 -0
- package/src/components/dropzone/upload-primitives.tsx +310 -0
- package/src/components/dropzone/use-dropzone.ts +122 -0
- package/src/components/empty-state/empty-state.stories.tsx +56 -0
- package/src/components/empty-state/empty-state.tsx +39 -0
- package/src/components/empty-state/index.ts +1 -0
- package/src/components/field/field.stories.tsx +223 -0
- package/src/components/field/field.tsx +229 -0
- package/src/components/field/index.ts +1 -0
- package/src/components/form/form.stories.tsx +594 -0
- package/src/components/form/form.tsx +30 -0
- package/src/components/form/index.ts +1 -0
- package/src/components/heading/heading.stories.tsx +74 -0
- package/src/components/heading/heading.tsx +28 -0
- package/src/components/heading/heading.variants.ts +27 -0
- package/src/components/heading/index.ts +1 -0
- package/src/components/index.ts +46 -0
- package/src/components/input/index.ts +1 -0
- package/src/components/input/input.stories.tsx +104 -0
- package/src/components/input/input.tsx +75 -0
- package/src/components/kbd/index.ts +1 -0
- package/src/components/kbd/kbd.stories.tsx +40 -0
- package/src/components/kbd/kbd.tsx +31 -0
- package/src/components/kbd/kbd.variants.ts +26 -0
- package/src/components/label/index.ts +1 -0
- package/src/components/label/label.stories.tsx +68 -0
- package/src/components/label/label.test.tsx +61 -0
- package/src/components/label/label.tsx +62 -0
- package/src/components/loader/index.ts +1 -0
- package/src/components/loader/loader.stories.tsx +60 -0
- package/src/components/loader/loader.test.tsx +26 -0
- package/src/components/loader/loader.tsx +60 -0
- package/src/components/menu/index.ts +2 -0
- package/src/components/menu/menu-primitives.tsx +248 -0
- package/src/components/menu/menu.stories.tsx +203 -0
- package/src/components/menu/menu.tsx +100 -0
- package/src/components/menu/util/render-menu-item.tsx +54 -0
- package/src/components/multi-select/hooks/use-multi-select.ts +66 -0
- package/src/components/multi-select/index.ts +1 -0
- package/src/components/multi-select/multi-select.stories.tsx +294 -0
- package/src/components/multi-select/multi-select.tsx +300 -0
- package/src/components/multi-select/multi-select.variants.ts +22 -0
- package/src/components/number-input/index.ts +1 -0
- package/src/components/number-input/number-input.stories.tsx +209 -0
- package/src/components/number-input/number-input.test.tsx +87 -0
- package/src/components/number-input/number-input.tsx +232 -0
- package/src/components/pagination/components/pagination-option.tsx +27 -0
- package/src/components/pagination/index.ts +1 -0
- package/src/components/pagination/pagination.stories.tsx +80 -0
- package/src/components/pagination/pagination.test.tsx +76 -0
- package/src/components/pagination/pagination.tsx +102 -0
- package/src/components/password/index.ts +1 -0
- package/src/components/password/password.stories.tsx +104 -0
- package/src/components/password/password.tsx +75 -0
- package/src/components/popover/index.ts +1 -0
- package/src/components/popover/popover.stories.tsx +213 -0
- package/src/components/popover/popover.tsx +203 -0
- package/src/components/progress/index.ts +1 -0
- package/src/components/progress/progress.stories.tsx +124 -0
- package/src/components/progress/progress.test.tsx +25 -0
- package/src/components/progress/progress.tsx +124 -0
- package/src/components/scroll-area/index.ts +1 -0
- package/src/components/scroll-area/scroll-area.stories.tsx +166 -0
- package/src/components/scroll-area/scroll-area.tsx +64 -0
- package/src/components/select/index.ts +1 -0
- package/src/components/select/select.stories.tsx +253 -0
- package/src/components/select/select.tsx +430 -0
- package/src/components/show/index.ts +1 -0
- package/src/components/show/show.stories.tsx +197 -0
- package/src/components/show/show.test.tsx +41 -0
- package/src/components/show/show.tsx +16 -0
- package/src/components/skeleton/index.ts +1 -0
- package/src/components/skeleton/skeleton.stories.tsx +36 -0
- package/src/components/skeleton/skeleton.test.tsx +14 -0
- package/src/components/skeleton/skeleton.tsx +15 -0
- package/src/components/stack/index.ts +1 -0
- package/src/components/stack/stack.stories.tsx +194 -0
- package/src/components/stack/stack.tsx +52 -0
- package/src/components/stepper/Stepper.tsx +190 -0
- package/src/components/stepper/context/stepper-context.tsx +11 -0
- package/src/components/stepper/index.ts +1 -0
- package/src/components/stepper/stepper.stories.tsx +130 -0
- package/src/components/stepper/stepper.test.tsx +91 -0
- package/src/components/switch/index.ts +1 -0
- package/src/components/switch/switch.stories.tsx +122 -0
- package/src/components/switch/switch.test.tsx +30 -0
- package/src/components/switch/switch.tsx +86 -0
- package/src/components/table/index.ts +3 -0
- package/src/components/table/table-primitives.tsx +122 -0
- package/src/components/table/table.model.ts +20 -0
- package/src/components/table/table.stories.tsx +169 -0
- package/src/components/table/table.test.tsx +91 -0
- package/src/components/table/table.tsx +109 -0
- package/src/components/table-pagination/index.ts +2 -0
- package/src/components/table-pagination/table-pagination.model.ts +2 -0
- package/src/components/table-pagination/table-pagination.stories.tsx +23 -0
- package/src/components/table-pagination/table-pagination.test.tsx +32 -0
- package/src/components/table-pagination/table-pagination.tsx +108 -0
- package/src/components/tabs/context/tabs-context.tsx +14 -0
- package/src/components/tabs/index.ts +1 -0
- package/src/components/tabs/tabs.stories.tsx +182 -0
- package/src/components/tabs/tabs.test.tsx +61 -0
- package/src/components/tabs/tabs.tsx +175 -0
- package/src/components/tag/index.ts +2 -0
- package/src/components/tag/tag.stories.tsx +170 -0
- package/src/components/tag/tag.test.tsx +18 -0
- package/src/components/tag/tag.tsx +99 -0
- package/src/components/tag/tag.variants.ts +31 -0
- package/src/components/textarea/index.ts +1 -0
- package/src/components/textarea/textarea.stories.tsx +73 -0
- package/src/components/textarea/textarea.tsx +105 -0
- package/src/components/timeline/index.ts +1 -0
- package/src/components/timeline/timeline-status.ts +5 -0
- package/src/components/timeline/timeline.stories.tsx +84 -0
- package/src/components/timeline/timeline.tsx +147 -0
- package/src/components/toast/index.ts +1 -0
- package/src/components/toast/toast.stories.tsx +392 -0
- package/src/components/toast/toast.test.tsx +50 -0
- package/src/components/toast/toast.tsx +411 -0
- package/src/components/tooltip/index.ts +1 -0
- package/src/components/tooltip/tooltip.stories.tsx +226 -0
- package/src/components/tooltip/tooltip.test.tsx +46 -0
- package/src/components/tooltip/tooltip.tsx +171 -0
- package/src/components/tree/hooks/use-controllable-tree-state.ts +80 -0
- package/src/components/tree/index.ts +2 -0
- package/src/components/tree/tree-primitives.tsx +126 -0
- package/src/components/tree/tree.stories.tsx +468 -0
- package/src/components/tree/tree.tsx +42 -0
- package/src/hooks/index.ts +26 -0
- package/src/hooks/useArray/__doc__/useArray.stories.tsx +100 -0
- package/src/hooks/useArray/__test__/useArray.test.tsx +88 -0
- package/src/hooks/useArray/index.ts +1 -0
- package/src/hooks/useArray/useArray.ts +76 -0
- package/src/hooks/useAsync/__doc__/useAsync.stories.tsx +149 -0
- package/src/hooks/useAsync/__test__/useAsync.test.tsx +68 -0
- package/src/hooks/useAsync/index.ts +1 -0
- package/src/hooks/useAsync/useAsync.ts +58 -0
- package/src/hooks/useClickOutside/__doc__/useClickOutside.stories.tsx +40 -0
- package/src/hooks/useClickOutside/__test__/useClickOutside.test.tsx +33 -0
- package/src/hooks/useClickOutside/index.ts +1 -0
- package/src/hooks/useClickOutside/useClickOutside.ts +26 -0
- package/src/hooks/useClipboard/__doc__/useClipboard.stories.tsx +45 -0
- package/src/hooks/useClipboard/__test__/useClipboard.test.tsx +19 -0
- package/src/hooks/useClipboard/index.ts +1 -0
- package/src/hooks/useClipboard/useClipboard.tsx +28 -0
- package/src/hooks/useDebounceCallback/__doc__/useDebouncedCallback.stories.tsx +84 -0
- package/src/hooks/useDebounceCallback/index.ts +1 -0
- package/src/hooks/useDebounceCallback/useDebouncedCallback.ts +23 -0
- package/src/hooks/useDebounceValue/__doc__/useDebouncedValue.stories.tsx +75 -0
- package/src/hooks/useDebounceValue/index.ts +1 -0
- package/src/hooks/useDebounceValue/useDebouncedValue.ts +17 -0
- package/src/hooks/useDisclosure/__doc__/useDisclosure.stories.tsx +39 -0
- package/src/hooks/useDisclosure/__test__/useDisclosure.test.ts +43 -0
- package/src/hooks/useDisclosure/index.ts +1 -0
- package/src/hooks/useDisclosure/useDisclosure.ts +37 -0
- package/src/hooks/useDocumentTitle/__doc__/useDocumentTitle.stories.tsx +26 -0
- package/src/hooks/useDocumentTitle/index.ts +1 -0
- package/src/hooks/useDocumentTitle/useDocumentTitle.tsx +11 -0
- package/src/hooks/useEventListener/__doc__/useEventListener.stories.tsx +28 -0
- package/src/hooks/useEventListener/__test__/useEventListener.test.tsx +26 -0
- package/src/hooks/useEventListener/index.ts +1 -0
- package/src/hooks/useEventListener/useEventListener.ts +25 -0
- package/src/hooks/useFocusTrap/__doc__/useFocusTrap.stories.tsx +37 -0
- package/src/hooks/useFocusTrap/index.ts +1 -0
- package/src/hooks/useFocusTrap/scopeTab.ts +38 -0
- package/src/hooks/useFocusTrap/tabbable.ts +70 -0
- package/src/hooks/useFocusTrap/useFocusTrap.ts +78 -0
- package/src/hooks/useHotkey/__docs__/useHotkey.stories.tsx +116 -0
- package/src/hooks/useHotkey/__test__/useHotkey.test.tsx +105 -0
- package/src/hooks/useHotkey/__utils__/create-hotkey-listener.ts +25 -0
- package/src/hooks/useHotkey/__utils__/index.ts +3 -0
- package/src/hooks/useHotkey/__utils__/is-input-field.ts +14 -0
- package/src/hooks/useHotkey/__utils__/match-key-modifiers.ts +25 -0
- package/src/hooks/useHotkey/index.ts +1 -0
- package/src/hooks/useHotkey/useHotkey.ts +34 -0
- package/src/hooks/useHover/__doc__/useHover.stories.tsx +41 -0
- package/src/hooks/useHover/__test__/useHover.test.tsx +45 -0
- package/src/hooks/useHover/index.ts +1 -0
- package/src/hooks/useHover/useHover.tsx +40 -0
- package/src/hooks/useIsVisible/__doc__/useIsVisible.stories.tsx +60 -0
- package/src/hooks/useIsVisible/index.ts +1 -0
- package/src/hooks/useIsVisible/useIsVisible.tsx +50 -0
- package/src/hooks/useLocalStorage/__doc__/useLocalStorage.stories.tsx +86 -0
- package/src/hooks/useLocalStorage/__test__/useLocalStorage.test.ts +85 -0
- package/src/hooks/useLocalStorage/index.ts +1 -0
- package/src/hooks/useLocalStorage/useLocalStorage.ts +57 -0
- package/src/hooks/useMediaQuery/__doc__/useMediaQuery.stories.tsx +39 -0
- package/src/hooks/useMediaQuery/index.ts +1 -0
- package/src/hooks/useMediaQuery/useMediaQuery.ts +22 -0
- package/src/hooks/useMemoizedFn/index.ts +1 -0
- package/src/hooks/useMemoizedFn/useMemoizedFn.ts +32 -0
- package/src/hooks/useMutation/__doc__/useMutation.stories.tsx +111 -0
- package/src/hooks/useMutation/__test__/useMutation.test.tsx +83 -0
- package/src/hooks/useMutation/index.ts +1 -0
- package/src/hooks/useMutation/useMutation.tsx +60 -0
- package/src/hooks/useObject/__doc__/useObject.stories.tsx +119 -0
- package/src/hooks/useObject/__test__/useObject.test.tsx +87 -0
- package/src/hooks/useObject/index.ts +1 -0
- package/src/hooks/useObject/useObject.tsx +48 -0
- package/src/hooks/usePagination/__doc__/usePagination.stories.tsx +72 -0
- package/src/hooks/usePagination/__test__/usePagination.test.tsx +98 -0
- package/src/hooks/usePagination/index.ts +2 -0
- package/src/hooks/usePagination/usePagination.tsx +74 -0
- package/src/hooks/usePortal/__doc__/usePortal.stories.tsx +19 -0
- package/src/hooks/usePortal/__test__/usePortal.test.tsx +20 -0
- package/src/hooks/usePortal/index.ts +1 -0
- package/src/hooks/usePortal/usePortal.ts +40 -0
- package/src/hooks/usePreventCloseWindow/__doc__/usePreventCloseWindow.stories.tsx +32 -0
- package/src/hooks/usePreventCloseWindow/index.ts +1 -0
- package/src/hooks/usePreventCloseWindow/usePreventCloseWindow.ts +33 -0
- package/src/hooks/useRangePagination/__test__/useRangePagination.test.tsx +63 -0
- package/src/hooks/useRangePagination/index.ts +2 -0
- package/src/hooks/useRangePagination/useRangePagination.tsx +72 -0
- package/src/hooks/useSelection/__doc__/useSelection.stories.tsx +140 -0
- package/src/hooks/useSelection/__test__/useSelection.test.tsx +57 -0
- package/src/hooks/useSelection/index.ts +1 -0
- package/src/hooks/useSelection/useSelection.ts +121 -0
- package/src/hooks/useStep/__doc__/useStep.stories.tsx +98 -0
- package/src/hooks/useStep/__test__/useStep.test.ts +51 -0
- package/src/hooks/useStep/index.ts +1 -0
- package/src/hooks/useStep/useStep.ts +57 -0
- package/src/hooks/useToggle/__doc__/useToggle.stories.tsx +25 -0
- package/src/hooks/useToggle/__test__/useToggle.test.tsx +43 -0
- package/src/hooks/useToggle/index.ts +1 -0
- package/src/hooks/useToggle/useToggle.ts +16 -0
- package/src/index.ts +6 -0
- package/src/lib/cn.ts +8 -0
- package/src/lib/index.ts +1 -0
- package/src/models/Generic.model.ts +67 -0
- package/src/models/index.ts +1 -0
- package/src/providers/index.ts +2 -0
- package/src/providers/library-provider.tsx +44 -0
- package/src/providers/theme/ThemeProvider.tsx +25 -0
- package/src/providers/theme/index.ts +3 -0
- package/src/providers/theme/types.ts +11 -0
- package/src/providers/theme/useThemeProps.ts +25 -0
- package/src/stores/theme.store.ts +31 -0
- package/src/styles/components.css +4 -0
- package/src/styles/index.css +2 -0
- package/src/styles/library.css +2 -0
- package/src/styles/theme.css +232 -0
- package/src/utils/dates/parseDateRange.utility.ts +39 -0
- package/src/utils/form.tsx +91 -0
- package/src/utils/functions/createSafeContext.ts +17 -0
- package/src/utils/functions/ensureReactElement.tsx +30 -0
- package/src/utils/functions/getFormData.ts +19 -0
- package/src/utils/functions/index.ts +4 -0
- package/src/utils/functions/mergeRefs.ts +18 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/strings/extractInitials.utility.ts +10 -0
- package/src/utils/strings/index.ts +1 -0
- package/src/utils/tests/click.ts +3 -0
- package/src/utils/tests/index.ts +2 -0
- package/src/utils/tests/keyboard.ts +21 -0
- package/src/utils/tests/type.ts +6 -0
- package/dist/components.css +0 -2
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { render, screen, waitFor } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
Stepper,
|
|
5
|
+
StepperContainer,
|
|
6
|
+
StepperContent,
|
|
7
|
+
StepperList,
|
|
8
|
+
StepperTrigger,
|
|
9
|
+
} from "../../components";
|
|
10
|
+
import { click } from "../../utils";
|
|
11
|
+
|
|
12
|
+
describe("Stepper component", () => {
|
|
13
|
+
it("should render correctly", () => {
|
|
14
|
+
render(<StepperContainer data-testid="steps" />);
|
|
15
|
+
const component = screen.getByTestId("steps");
|
|
16
|
+
expect(component).toBeInTheDocument();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should show steps", () => {
|
|
20
|
+
render(
|
|
21
|
+
<StepperContainer>
|
|
22
|
+
<StepperList>
|
|
23
|
+
<StepperTrigger value={0} title="trigger"></StepperTrigger>
|
|
24
|
+
<StepperTrigger value={1} title="step"></StepperTrigger>
|
|
25
|
+
</StepperList>
|
|
26
|
+
</StepperContainer>,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
expect(screen.getByText(/trigger/i)).toBeInTheDocument();
|
|
30
|
+
expect(screen.getByText(/step/i)).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should show step content", () => {
|
|
34
|
+
render(
|
|
35
|
+
<StepperContainer current={0}>
|
|
36
|
+
<StepperList>
|
|
37
|
+
<StepperTrigger value={0} title="trigger"></StepperTrigger>
|
|
38
|
+
<StepperTrigger value={1} title="test"></StepperTrigger>
|
|
39
|
+
</StepperList>
|
|
40
|
+
<StepperContent value={0}>Contenido de trigger</StepperContent>
|
|
41
|
+
</StepperContainer>,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
expect(screen.getByText("Contenido de trigger")).toBeInTheDocument();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should be controlled", () => {
|
|
48
|
+
const mock = vi.fn();
|
|
49
|
+
render(
|
|
50
|
+
<StepperContainer value={0} onChange={mock}>
|
|
51
|
+
<StepperList>
|
|
52
|
+
<StepperTrigger value={0} title="trigger"></StepperTrigger>
|
|
53
|
+
<StepperTrigger value={1} title="test"></StepperTrigger>
|
|
54
|
+
</StepperList>
|
|
55
|
+
<StepperContent value={0}>Contenido de trigger</StepperContent>
|
|
56
|
+
<StepperContent value={1}>Contenido de test</StepperContent>
|
|
57
|
+
</StepperContainer>,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const testTrigger = screen.getByText("test");
|
|
61
|
+
click(testTrigger);
|
|
62
|
+
|
|
63
|
+
waitFor(() => {
|
|
64
|
+
expect(mock).toHaveBeenCalledWith(1);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should show step content", () => {
|
|
69
|
+
const mock = vi.fn();
|
|
70
|
+
render(
|
|
71
|
+
<Stepper
|
|
72
|
+
current={0}
|
|
73
|
+
onChange={mock}
|
|
74
|
+
items={[
|
|
75
|
+
{ title: "trigger", content: "Contenido de trigger" },
|
|
76
|
+
{ title: "step1", content: "Contenido de step1" },
|
|
77
|
+
]}
|
|
78
|
+
/>,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
expect(screen.getByText("Contenido de trigger")).toBeInTheDocument();
|
|
82
|
+
|
|
83
|
+
const testTrigger = screen.getByText("step1");
|
|
84
|
+
click(testTrigger);
|
|
85
|
+
|
|
86
|
+
waitFor(() => {
|
|
87
|
+
expect(mock).toHaveBeenCalledWith(1);
|
|
88
|
+
expect(screen.getByText("Contenido de step1")).toBeInTheDocument();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./switch";
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { useArgs } from "storybook/preview-api";
|
|
3
|
+
import { Button, Switch, SwitchRoot, SwitchThumb } from "../../components";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Toggle switch built on Base UI. Built on `@base-ui/react/switch`.
|
|
7
|
+
*
|
|
8
|
+
* The composite `Switch` accepts a label via `label` prop or `children` —
|
|
9
|
+
* both work, `label` takes priority when both are provided.
|
|
10
|
+
* `controlFirst` (default `true`) places the switch before the label.
|
|
11
|
+
*
|
|
12
|
+
* Supports controlled state via `checked` + `onCheckedChange`, and native
|
|
13
|
+
* form integration via `name` + `required`.
|
|
14
|
+
*
|
|
15
|
+
* Reference: [Switch – Base UI](https://base-ui.com/react/components/switch)
|
|
16
|
+
*/
|
|
17
|
+
const meta: Meta<typeof Switch> = {
|
|
18
|
+
title: "Components/Switch",
|
|
19
|
+
component: Switch,
|
|
20
|
+
parameters: { layout: "centered" },
|
|
21
|
+
args: {
|
|
22
|
+
label: "Enable notifications",
|
|
23
|
+
},
|
|
24
|
+
argTypes: {
|
|
25
|
+
children: { control: false },
|
|
26
|
+
onCheckedChange: { control: false },
|
|
27
|
+
thumbProps: { control: false },
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default meta;
|
|
32
|
+
type Story = StoryObj<typeof Switch>;
|
|
33
|
+
|
|
34
|
+
export const Default: Story = {};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Pass `label` or `children` — both render an accessible label next to the switch.
|
|
38
|
+
* `label` takes priority when both are provided.
|
|
39
|
+
*/
|
|
40
|
+
export const WithLabel: Story = {
|
|
41
|
+
args: {
|
|
42
|
+
label: "Dark mode",
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* `controlFirst={false}` places the label before the switch.
|
|
48
|
+
* Default is `true` (switch → label).
|
|
49
|
+
*/
|
|
50
|
+
export const ControlFirst: Story = {
|
|
51
|
+
args: {
|
|
52
|
+
controlFirst: false,
|
|
53
|
+
label: "Dark mode",
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const Disabled: Story = {
|
|
58
|
+
args: {
|
|
59
|
+
disabled: true,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Use `checked` + `onCheckedChange` for controlled mode.
|
|
65
|
+
*/
|
|
66
|
+
export const Controlled: Story = {
|
|
67
|
+
render: (args) => {
|
|
68
|
+
const [{ checked }, updateArgs] = useArgs();
|
|
69
|
+
return (
|
|
70
|
+
<Switch
|
|
71
|
+
{...args}
|
|
72
|
+
checked={checked}
|
|
73
|
+
onCheckedChange={(value) => updateArgs({ checked: value })}
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
},
|
|
77
|
+
args: {
|
|
78
|
+
defaultChecked: true,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Base UI injects a hidden `<input type="checkbox">` so `name` and `required`
|
|
84
|
+
* work with native `FormData` out of the box.
|
|
85
|
+
*/
|
|
86
|
+
export const Required: Story = {
|
|
87
|
+
args: {
|
|
88
|
+
name: "notifications",
|
|
89
|
+
required: true,
|
|
90
|
+
label: "I agree to receive marketing emails",
|
|
91
|
+
},
|
|
92
|
+
render: (args) => (
|
|
93
|
+
<form
|
|
94
|
+
className="space-y-2"
|
|
95
|
+
onSubmit={(event) => {
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
const data = new FormData(event.currentTarget);
|
|
98
|
+
alert(`Value: ${data.get("notifications")}`);
|
|
99
|
+
}}
|
|
100
|
+
>
|
|
101
|
+
<Switch {...args} />
|
|
102
|
+
<Button type="submit">Submit</Button>
|
|
103
|
+
</form>
|
|
104
|
+
),
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Direct composition with primitives for full structural control.
|
|
109
|
+
*
|
|
110
|
+
* ```tsx
|
|
111
|
+
* <SwitchRoot>
|
|
112
|
+
* <SwitchThumb />
|
|
113
|
+
* </SwitchRoot>
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export const Primitive: Story = {
|
|
117
|
+
render: () => (
|
|
118
|
+
<SwitchRoot>
|
|
119
|
+
<SwitchThumb />
|
|
120
|
+
</SwitchRoot>
|
|
121
|
+
),
|
|
122
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { act } from "react";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { Switch } from "../../components";
|
|
5
|
+
|
|
6
|
+
describe("Switch component", () => {
|
|
7
|
+
it("should be checked", () => {
|
|
8
|
+
render(<Switch name="Switch" data-testid="Switch" checked />);
|
|
9
|
+
const checkbox = screen.getByTestId("Switch");
|
|
10
|
+
expect(checkbox).toBeChecked();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should toggle on click", () => {
|
|
14
|
+
render(<Switch name="Switch" data-testid="Switch" />);
|
|
15
|
+
const checkbox = screen.getByTestId("Switch");
|
|
16
|
+
expect(checkbox).not.toBeChecked();
|
|
17
|
+
|
|
18
|
+
act(() => checkbox.click());
|
|
19
|
+
expect(checkbox).toBeChecked();
|
|
20
|
+
|
|
21
|
+
act(() => checkbox.click());
|
|
22
|
+
expect(checkbox).not.toBeChecked();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should be disabled", () => {
|
|
26
|
+
render(<Switch name="Switch" data-testid="Switch" disabled />);
|
|
27
|
+
const checkbox = screen.getByTestId("Switch");
|
|
28
|
+
expect(checkbox).toBeDisabled();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Switch as SwitchPrimitive } from "@base-ui/react/switch";
|
|
2
|
+
import type * as React from "react";
|
|
3
|
+
import { useId } from "react";
|
|
4
|
+
import { cn } from "../../lib";
|
|
5
|
+
import { Label } from "../label";
|
|
6
|
+
|
|
7
|
+
export function SwitchRoot({
|
|
8
|
+
className,
|
|
9
|
+
...props
|
|
10
|
+
}: SwitchPrimitive.Root.Props): React.ReactElement {
|
|
11
|
+
return (
|
|
12
|
+
<SwitchPrimitive.Root
|
|
13
|
+
className={cn(
|
|
14
|
+
"peer inline-flex h-[calc(var(--thumb-size)+2px)] w-[calc(var(--thumb-size)*2-2px)] shrink-0 items-center rounded-full p-px outline-none transition-[background-color,box-shadow] duration-200",
|
|
15
|
+
"[--thumb-size:--spacing(5)] sm:[--thumb-size:--spacing(4)]",
|
|
16
|
+
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
|
|
17
|
+
"data-checked:bg-primary data-unchecked:bg-input",
|
|
18
|
+
"data-disabled:cursor-not-allowed data-disabled:opacity-64",
|
|
19
|
+
className,
|
|
20
|
+
)}
|
|
21
|
+
data-slot="switch"
|
|
22
|
+
{...props}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function SwitchThumb({
|
|
28
|
+
className,
|
|
29
|
+
...props
|
|
30
|
+
}: SwitchPrimitive.Thumb.Props): React.ReactElement {
|
|
31
|
+
return (
|
|
32
|
+
<SwitchPrimitive.Thumb
|
|
33
|
+
className={cn(
|
|
34
|
+
"pointer-events-none block aspect-square h-full rounded-(--thumb-size) bg-background shadow-sm/5 will-change-transform",
|
|
35
|
+
"origin-left [transition:translate_.15s,border-radius_.15s,scale_.1s_.1s,transform-origin_.15s]",
|
|
36
|
+
"data-checked:origin-[var(--thumb-size)_50%] data-checked:translate-x-[calc(var(--thumb-size)-4px)]",
|
|
37
|
+
"in-[[role=switch]:active,[data-slot=label]:active,[data-slot=field-label]:active]:not-data-disabled:scale-x-110",
|
|
38
|
+
"in-[[role=switch]:active,[data-slot=label]:active,[data-slot=field-label]:active]:rounded-[var(--thumb-size)/calc(var(--thumb-size)*1.1)]",
|
|
39
|
+
className,
|
|
40
|
+
)}
|
|
41
|
+
data-slot="switch-thumb"
|
|
42
|
+
{...props}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface SwitchProps extends Omit<SwitchPrimitive.Root.Props, "children"> {
|
|
48
|
+
children?: React.ReactNode;
|
|
49
|
+
label?: React.ReactNode;
|
|
50
|
+
tooltip?: string;
|
|
51
|
+
thumbProps?: SwitchPrimitive.Thumb.Props;
|
|
52
|
+
controlFirst?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function Switch({
|
|
56
|
+
children,
|
|
57
|
+
label,
|
|
58
|
+
className,
|
|
59
|
+
id,
|
|
60
|
+
thumbProps,
|
|
61
|
+
controlFirst = true,
|
|
62
|
+
tooltip,
|
|
63
|
+
...props
|
|
64
|
+
}: SwitchProps): React.ReactElement {
|
|
65
|
+
const generatedId = useId();
|
|
66
|
+
const idToUse = id ?? generatedId;
|
|
67
|
+
const labelContent = label ?? children;
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div
|
|
71
|
+
className={cn(
|
|
72
|
+
"flex select-none items-center gap-x-2",
|
|
73
|
+
!controlFirst && "flex-row-reverse justify-end",
|
|
74
|
+
)}
|
|
75
|
+
>
|
|
76
|
+
<SwitchRoot id={idToUse} className={className} {...props}>
|
|
77
|
+
<SwitchThumb {...thumbProps} />
|
|
78
|
+
</SwitchRoot>
|
|
79
|
+
{labelContent && (
|
|
80
|
+
<Label htmlFor={idToUse} tooltip={tooltip}>
|
|
81
|
+
{labelContent}
|
|
82
|
+
</Label>
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cn } from "../../lib";
|
|
3
|
+
|
|
4
|
+
type ContainerProps = React.ComponentProps<"div">;
|
|
5
|
+
type TableProps = React.ComponentProps<"table">;
|
|
6
|
+
|
|
7
|
+
type TableRootProps = TableProps & {
|
|
8
|
+
containerClassName?: ContainerProps["className"];
|
|
9
|
+
containerProps?: ContainerProps;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const TableRoot = ({
|
|
13
|
+
className,
|
|
14
|
+
containerClassName,
|
|
15
|
+
containerProps,
|
|
16
|
+
...props
|
|
17
|
+
}: TableRootProps) => (
|
|
18
|
+
<div
|
|
19
|
+
data-slot="table-container"
|
|
20
|
+
className={cn(
|
|
21
|
+
"relative w-full overflow-auto rounded-md border",
|
|
22
|
+
containerClassName,
|
|
23
|
+
)}
|
|
24
|
+
{...containerProps}
|
|
25
|
+
>
|
|
26
|
+
<table
|
|
27
|
+
data-slot="table"
|
|
28
|
+
className={cn("w-full caption-bottom text-sm", className)}
|
|
29
|
+
{...props}
|
|
30
|
+
/>
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
type TableHeaderProps = React.ComponentProps<"thead">;
|
|
35
|
+
|
|
36
|
+
const TableHeader = ({ className, ...props }: TableHeaderProps) => (
|
|
37
|
+
<thead
|
|
38
|
+
data-slot="table-header"
|
|
39
|
+
className={cn("[&_tr]:border-b", className)}
|
|
40
|
+
{...props}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
type TableBodyProps = React.ComponentProps<"tbody">;
|
|
45
|
+
|
|
46
|
+
const TableBody = ({ className, ...props }: TableBodyProps) => (
|
|
47
|
+
<tbody
|
|
48
|
+
data-slot="table-body"
|
|
49
|
+
className={cn("[&_tr:last-child]:border-0", className)}
|
|
50
|
+
{...props}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
type TableFooterProps = React.ComponentProps<"tfoot">;
|
|
55
|
+
|
|
56
|
+
const TableFooter = ({ className, ...props }: TableFooterProps) => (
|
|
57
|
+
<tfoot
|
|
58
|
+
data-slot="table-footer"
|
|
59
|
+
className={cn(
|
|
60
|
+
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
|
|
61
|
+
className,
|
|
62
|
+
)}
|
|
63
|
+
{...props}
|
|
64
|
+
/>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
type TableRowProps = React.ComponentProps<"tr">;
|
|
68
|
+
|
|
69
|
+
const TableRow = ({ className, ...props }: TableRowProps) => (
|
|
70
|
+
<tr
|
|
71
|
+
data-slot="table-row"
|
|
72
|
+
className={cn(
|
|
73
|
+
"border-b transition-colors hover:bg-muted data-[selected=true]:bg-muted",
|
|
74
|
+
className,
|
|
75
|
+
)}
|
|
76
|
+
{...props}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
type TableHeadProps = React.ComponentProps<"th">;
|
|
81
|
+
|
|
82
|
+
const TableHead = ({ className, ...props }: TableHeadProps) => (
|
|
83
|
+
<th
|
|
84
|
+
data-slot="table-head"
|
|
85
|
+
className={cn(
|
|
86
|
+
"h-12 px-4 text-left align-middle font-medium text-muted-foreground sticky top-0 bg-background [&:has([role=checkbox])]:pr-0",
|
|
87
|
+
className,
|
|
88
|
+
)}
|
|
89
|
+
{...props}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
type TableCellProps = React.ComponentProps<"td">;
|
|
94
|
+
|
|
95
|
+
const TableCell = ({ className, ...props }: TableCellProps) => (
|
|
96
|
+
<td
|
|
97
|
+
data-slot="table-cell"
|
|
98
|
+
className={cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className)}
|
|
99
|
+
{...props}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
type TableCaptionProps = React.ComponentProps<"caption">;
|
|
104
|
+
|
|
105
|
+
const TableCaption = ({ className, ...props }: TableCaptionProps) => (
|
|
106
|
+
<caption
|
|
107
|
+
data-slot="table-caption"
|
|
108
|
+
className={cn("mt-4 text-sm text-muted-foreground", className)}
|
|
109
|
+
{...props}
|
|
110
|
+
/>
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
export {
|
|
114
|
+
TableBody,
|
|
115
|
+
TableCaption,
|
|
116
|
+
TableCell,
|
|
117
|
+
TableFooter,
|
|
118
|
+
TableHead,
|
|
119
|
+
TableHeader,
|
|
120
|
+
TableRoot,
|
|
121
|
+
TableRow,
|
|
122
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
export type ColumnDef<T> = {
|
|
4
|
+
/**
|
|
5
|
+
* Header de la columna
|
|
6
|
+
*/
|
|
7
|
+
header: string | (() => ReactNode);
|
|
8
|
+
/**
|
|
9
|
+
* Clave que identifica la columna
|
|
10
|
+
*/
|
|
11
|
+
key: keyof T;
|
|
12
|
+
/**
|
|
13
|
+
* Elemento que se renderiza en la celda
|
|
14
|
+
*/
|
|
15
|
+
cell?: (row: T, index: number) => ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* Ancho de la columna
|
|
18
|
+
*/
|
|
19
|
+
width?: string | number;
|
|
20
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { ImageIcon } from "lucide-react";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { Avatar, Checkbox, ColumnDef, Table, Tag } from "../../components";
|
|
5
|
+
import { useSelection } from "../../hooks";
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof Table> = {
|
|
8
|
+
title: "Data display/Table",
|
|
9
|
+
component: Table,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default meta;
|
|
13
|
+
type Story<T> = StoryObj<typeof Table<T>>;
|
|
14
|
+
|
|
15
|
+
interface User {
|
|
16
|
+
id: number;
|
|
17
|
+
name: string;
|
|
18
|
+
photo: string;
|
|
19
|
+
age: number;
|
|
20
|
+
gender: "male" | "female";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const data: User[] = [
|
|
24
|
+
{
|
|
25
|
+
id: 1,
|
|
26
|
+
name: "John",
|
|
27
|
+
photo: "https://i.pravatar.cc/300?un=123456787",
|
|
28
|
+
age: 25,
|
|
29
|
+
gender: "male",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: 2,
|
|
33
|
+
name: "Doe",
|
|
34
|
+
photo: "https://i.pravatar.cc/300?un=123456789",
|
|
35
|
+
age: 15,
|
|
36
|
+
gender: "female",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 3,
|
|
40
|
+
name: "Jane",
|
|
41
|
+
photo: "https://i.pravatar.cc/300?un=123612788",
|
|
42
|
+
age: 35,
|
|
43
|
+
gender: "female",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: 4,
|
|
47
|
+
name: "Doe",
|
|
48
|
+
photo: "https://i.pravatar.cc/300?un=1234589",
|
|
49
|
+
age: 15,
|
|
50
|
+
gender: "female",
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
const columns: ColumnDef<User>[] = [
|
|
55
|
+
{
|
|
56
|
+
header: () => (
|
|
57
|
+
<div className="flex items-center gap-x-2">
|
|
58
|
+
<ImageIcon />
|
|
59
|
+
<span>Photo</span>
|
|
60
|
+
</div>
|
|
61
|
+
),
|
|
62
|
+
key: "photo",
|
|
63
|
+
cell: (row) => <Avatar src={row.photo} alt={row.name} />,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
header: "Name",
|
|
67
|
+
key: "name",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
header: "Adult",
|
|
71
|
+
key: "age",
|
|
72
|
+
cell: (row) => {
|
|
73
|
+
const isAdult = row.age > 18;
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<Tag variant={isAdult ? "secondary" : "error"}>
|
|
77
|
+
{isAdult ? "Adult" : "Minor"}
|
|
78
|
+
</Tag>
|
|
79
|
+
);
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
header: "Gender",
|
|
84
|
+
key: "gender",
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
export const Default: Story<User> = {
|
|
89
|
+
args: {
|
|
90
|
+
columns: columns,
|
|
91
|
+
data: data,
|
|
92
|
+
className: "table-fixed",
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Al setear una altura en la propiedad `containerClassName` se puede hacer Scrollable
|
|
98
|
+
*
|
|
99
|
+
* ```tsx
|
|
100
|
+
* <Table
|
|
101
|
+
* ....
|
|
102
|
+
* containerClassName="max-h-[500px]"
|
|
103
|
+
* />
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export const Scrollable: Story<User> = {
|
|
107
|
+
args: {
|
|
108
|
+
columns: columns,
|
|
109
|
+
data: [...data, ...data, ...data],
|
|
110
|
+
className: "table-fixed",
|
|
111
|
+
containerClassName: "max-h-[500px]",
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export const Selection: Story<User> = {
|
|
116
|
+
render: () => {
|
|
117
|
+
const {
|
|
118
|
+
selected,
|
|
119
|
+
isSelected,
|
|
120
|
+
isAllSelected,
|
|
121
|
+
isSomeSelected,
|
|
122
|
+
toggle,
|
|
123
|
+
toggleAll,
|
|
124
|
+
} = useSelection(data);
|
|
125
|
+
|
|
126
|
+
const columnsAdapter = (): ColumnDef<User>[] => [
|
|
127
|
+
{
|
|
128
|
+
key: "id",
|
|
129
|
+
width: 30,
|
|
130
|
+
header: () => (
|
|
131
|
+
<Checkbox
|
|
132
|
+
name="selectAll"
|
|
133
|
+
checked={isAllSelected}
|
|
134
|
+
onCheckedChange={toggleAll}
|
|
135
|
+
indeterminate={isSomeSelected}
|
|
136
|
+
/>
|
|
137
|
+
),
|
|
138
|
+
cell: (row) => (
|
|
139
|
+
<Checkbox
|
|
140
|
+
name={row.id.toString()}
|
|
141
|
+
checked={isSelected(row)}
|
|
142
|
+
onCheckedChange={() => toggle(row)}
|
|
143
|
+
/>
|
|
144
|
+
),
|
|
145
|
+
},
|
|
146
|
+
...columns,
|
|
147
|
+
];
|
|
148
|
+
|
|
149
|
+
const columnsNew = useMemo(columnsAdapter, [selected]);
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<Table
|
|
153
|
+
data={data}
|
|
154
|
+
columns={columnsNew}
|
|
155
|
+
className="table-fixed"
|
|
156
|
+
onRowClick={toggle}
|
|
157
|
+
selected={isSelected}
|
|
158
|
+
/>
|
|
159
|
+
);
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export const DoubleClickAction: Story<User> = {
|
|
164
|
+
args: {
|
|
165
|
+
columns: columns,
|
|
166
|
+
data: data,
|
|
167
|
+
onDoubleClick: (row: User) => alert(`clicked ${row.name}`),
|
|
168
|
+
},
|
|
169
|
+
};
|