@boxcustodia/library 2.0.0-alpha.11 → 2.0.0-alpha.12
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.css +1 -1
- 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 +475 -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 +892 -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 +70 -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 +230 -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 +71 -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 } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { ColumnDef, Table } from "../../components";
|
|
4
|
+
import { click } from "../../utils";
|
|
5
|
+
|
|
6
|
+
describe("Table", () => {
|
|
7
|
+
interface Person {
|
|
8
|
+
name: string;
|
|
9
|
+
age: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const data: Person[] = [
|
|
13
|
+
{
|
|
14
|
+
name: "John",
|
|
15
|
+
age: 30,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "Jane",
|
|
19
|
+
age: 25,
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const columns: ColumnDef<Person>[] = [
|
|
24
|
+
{
|
|
25
|
+
header: "Name",
|
|
26
|
+
key: "name",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
header: "Age",
|
|
30
|
+
key: "age",
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
it("should render items", () => {
|
|
35
|
+
render(<Table data={data} columns={columns} />);
|
|
36
|
+
|
|
37
|
+
data.forEach((person: Person) =>
|
|
38
|
+
expect(screen.getByText(person.name)).toBeInTheDocument(),
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should render custom header", () => {
|
|
43
|
+
const customColumns: ColumnDef<Person>[] = [
|
|
44
|
+
{
|
|
45
|
+
key: "name",
|
|
46
|
+
header: () => <div>Custom</div>,
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
render(<Table data={data} columns={customColumns} />);
|
|
50
|
+
|
|
51
|
+
expect(screen.getByText("Custom")).toBeInTheDocument();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should render custom cell", () => {
|
|
55
|
+
const customColumns: ColumnDef<Person>[] = [
|
|
56
|
+
{
|
|
57
|
+
key: "name",
|
|
58
|
+
header: "name",
|
|
59
|
+
cell: (row) => <div>{row.name + " custom"}</div>,
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
render(<Table data={data} columns={customColumns} />);
|
|
63
|
+
|
|
64
|
+
expect(screen.getByText("John custom")).toBeInTheDocument();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should select row", () => {
|
|
68
|
+
render(
|
|
69
|
+
<Table
|
|
70
|
+
data={data}
|
|
71
|
+
columns={columns}
|
|
72
|
+
selected={(row) => row.name === "John"}
|
|
73
|
+
/>,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const john = screen.getByText("John");
|
|
77
|
+
|
|
78
|
+
expect(john).toBeInTheDocument();
|
|
79
|
+
expect(john.parentElement).toHaveAttribute("data-selected", "true");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should handle onRowClick", () => {
|
|
83
|
+
const onRowClick = vi.fn();
|
|
84
|
+
render(<Table data={data} columns={columns} onRowClick={onRowClick} />);
|
|
85
|
+
|
|
86
|
+
const first = screen.getByText(data[0].name);
|
|
87
|
+
click(first);
|
|
88
|
+
|
|
89
|
+
expect(onRowClick).toHaveBeenCalledWith(data[0]);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { isFunction } from "lodash";
|
|
2
|
+
import { ComponentPropsWithoutRef, HTMLProps, JSX } from "react";
|
|
3
|
+
import { ClassName } from "@/models";
|
|
4
|
+
import { cn } from "../../lib";
|
|
5
|
+
import { ColumnDef } from "./table.model";
|
|
6
|
+
import {
|
|
7
|
+
TableBody,
|
|
8
|
+
TableCell,
|
|
9
|
+
TableHead,
|
|
10
|
+
TableHeader,
|
|
11
|
+
TableRoot,
|
|
12
|
+
TableRow,
|
|
13
|
+
} from "./table-primitives";
|
|
14
|
+
|
|
15
|
+
type Props<T> = {
|
|
16
|
+
data: T[];
|
|
17
|
+
columns: ColumnDef<T>[];
|
|
18
|
+
onRowClick?: (row: T) => void;
|
|
19
|
+
onDoubleClick?: (row: T) => void;
|
|
20
|
+
selected?: (row: T) => boolean;
|
|
21
|
+
} & ExtendedProps &
|
|
22
|
+
Omit<
|
|
23
|
+
ComponentPropsWithoutRef<typeof TableRoot>,
|
|
24
|
+
"data" | "selected" | "onDoubleClick"
|
|
25
|
+
>;
|
|
26
|
+
|
|
27
|
+
interface ExtendedProps {
|
|
28
|
+
theadClassName?: ClassName;
|
|
29
|
+
theadProps?: HTMLProps<HTMLTableSectionElement>;
|
|
30
|
+
tbodyClassName?: ClassName;
|
|
31
|
+
tbodyProps?: HTMLProps<HTMLTableSectionElement>;
|
|
32
|
+
trClassName?: ClassName;
|
|
33
|
+
trProps?: HTMLProps<HTMLTableRowElement>;
|
|
34
|
+
thClassName?: ClassName;
|
|
35
|
+
thProps?: HTMLProps<HTMLTableCellElement>;
|
|
36
|
+
tdClassName?: ClassName;
|
|
37
|
+
tdProps?: Omit<HTMLProps<HTMLTableCellElement>, "onDoubleClick">;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const Table = <T,>({
|
|
41
|
+
data = [],
|
|
42
|
+
columns = [],
|
|
43
|
+
onRowClick,
|
|
44
|
+
onDoubleClick,
|
|
45
|
+
selected,
|
|
46
|
+
theadClassName,
|
|
47
|
+
theadProps,
|
|
48
|
+
tbodyClassName,
|
|
49
|
+
tbodyProps,
|
|
50
|
+
trClassName,
|
|
51
|
+
trProps,
|
|
52
|
+
thClassName,
|
|
53
|
+
thProps,
|
|
54
|
+
tdClassName,
|
|
55
|
+
tdProps,
|
|
56
|
+
...tableProps
|
|
57
|
+
}: Props<T>) => {
|
|
58
|
+
return (
|
|
59
|
+
<TableRoot {...tableProps} className={cn(tableProps?.className)}>
|
|
60
|
+
<TableHeader
|
|
61
|
+
{...theadProps}
|
|
62
|
+
className={cn(theadProps?.className, theadClassName)}
|
|
63
|
+
>
|
|
64
|
+
<TableRow {...trProps} className={cn(trProps?.className, trClassName)}>
|
|
65
|
+
{columns.map((column, i) => (
|
|
66
|
+
<TableHead
|
|
67
|
+
key={i}
|
|
68
|
+
{...thProps}
|
|
69
|
+
className={cn(thProps?.className, thClassName)}
|
|
70
|
+
style={{
|
|
71
|
+
width: column.width,
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
{isFunction(column.header) ? column.header?.() : column.header}
|
|
75
|
+
</TableHead>
|
|
76
|
+
))}
|
|
77
|
+
</TableRow>
|
|
78
|
+
</TableHeader>
|
|
79
|
+
<TableBody
|
|
80
|
+
{...tbodyProps}
|
|
81
|
+
className={cn(tbodyProps?.className, tbodyClassName)}
|
|
82
|
+
>
|
|
83
|
+
{data.map((row, i) => (
|
|
84
|
+
<TableRow
|
|
85
|
+
key={i}
|
|
86
|
+
{...trProps}
|
|
87
|
+
data-selected={selected?.(row)}
|
|
88
|
+
className={cn(trProps?.className, trClassName)}
|
|
89
|
+
>
|
|
90
|
+
{columns.map((column, i) => (
|
|
91
|
+
<TableCell
|
|
92
|
+
key={i}
|
|
93
|
+
{...tdProps}
|
|
94
|
+
onClick={(e) => {
|
|
95
|
+
tdProps?.onClick?.(e);
|
|
96
|
+
onRowClick?.(row);
|
|
97
|
+
}}
|
|
98
|
+
onDoubleClick={() => onDoubleClick?.(row)}
|
|
99
|
+
className={cn(tdProps?.className, tdClassName)}
|
|
100
|
+
>
|
|
101
|
+
{(column.cell?.(row, i) as JSX.Element) || row[column.key]}
|
|
102
|
+
</TableCell>
|
|
103
|
+
))}
|
|
104
|
+
</TableRow>
|
|
105
|
+
))}
|
|
106
|
+
</TableBody>
|
|
107
|
+
</TableRoot>
|
|
108
|
+
);
|
|
109
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { TablePagination } from "../../components";
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof TablePagination> = {
|
|
5
|
+
title: "Data display/TablePagination",
|
|
6
|
+
component: TablePagination,
|
|
7
|
+
args: {
|
|
8
|
+
totalItems: 100,
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default meta;
|
|
13
|
+
type Story = StoryObj<typeof TablePagination>;
|
|
14
|
+
|
|
15
|
+
export const Default: Story = {};
|
|
16
|
+
|
|
17
|
+
export const NoSizes: Story = {
|
|
18
|
+
args: { sizes: false },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const OtherSizes: Story = {
|
|
22
|
+
args: { sizes: [1, 100, 1000] },
|
|
23
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { TablePagination } from "../../components";
|
|
4
|
+
import { click } from "../../utils";
|
|
5
|
+
|
|
6
|
+
describe("TablePagination component", () => {
|
|
7
|
+
it("should render correctly", () => {
|
|
8
|
+
render(<TablePagination pageSize={10} totalItems={30} />);
|
|
9
|
+
const pagination = screen.getByText(/1 - 10 de 30/g);
|
|
10
|
+
expect(pagination).toBeInTheDocument();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should go next page", () => {
|
|
14
|
+
render(<TablePagination pageSize={10} totalItems={30} />);
|
|
15
|
+
const goNext = screen.getAllByRole("button")[1];
|
|
16
|
+
click(goNext);
|
|
17
|
+
|
|
18
|
+
const pagination = screen.getByText(/11 - 20 de 30/g);
|
|
19
|
+
expect(pagination).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should go prev page", () => {
|
|
23
|
+
render(
|
|
24
|
+
<TablePagination initialCurrentPage={2} pageSize={10} totalItems={30} />,
|
|
25
|
+
);
|
|
26
|
+
const goNext = screen.getAllByRole("button")[0];
|
|
27
|
+
click(goNext);
|
|
28
|
+
|
|
29
|
+
const pagination = screen.getByText(/1 - 10 de 30/g);
|
|
30
|
+
expect(pagination).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
2
|
+
import { ChevronLeft, ChevronRight } from "lucide-react";
|
|
3
|
+
import { ChangeEvent, HTMLProps } from "react";
|
|
4
|
+
import { ClassName } from "@/models";
|
|
5
|
+
import { usePagination, usePaginationProps } from "../../hooks";
|
|
6
|
+
import { cn } from "../../lib";
|
|
7
|
+
import { Button } from "../button";
|
|
8
|
+
import { PageSize, TABLE_PAGE_SIZES } from "./table-pagination.model";
|
|
9
|
+
|
|
10
|
+
interface TablePaginationExtendedProps {
|
|
11
|
+
containerClassName?: ClassName;
|
|
12
|
+
containerProps?: HTMLProps<HTMLDivElement>;
|
|
13
|
+
selectClassName?: ClassName;
|
|
14
|
+
selectProps?: HTMLProps<HTMLSelectElement>;
|
|
15
|
+
sizes?: PageSize[] | false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type Props = {
|
|
19
|
+
setPageSize?: (value: PageSize) => void;
|
|
20
|
+
pageSize?: PageSize;
|
|
21
|
+
} & Omit<usePaginationProps, "pageSize"> &
|
|
22
|
+
TablePaginationExtendedProps;
|
|
23
|
+
|
|
24
|
+
export const TablePagination = ({
|
|
25
|
+
containerClassName,
|
|
26
|
+
containerProps,
|
|
27
|
+
selectClassName,
|
|
28
|
+
selectProps,
|
|
29
|
+
sizes = TABLE_PAGE_SIZES,
|
|
30
|
+
...props
|
|
31
|
+
}: Props) => {
|
|
32
|
+
const [pageSize = TABLE_PAGE_SIZES[0], setPageSize] =
|
|
33
|
+
useControllableState<PageSize>({
|
|
34
|
+
onChange: props?.setPageSize,
|
|
35
|
+
prop: props?.pageSize,
|
|
36
|
+
defaultProp: TABLE_PAGE_SIZES[0],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const { range, next, prev, isFirstPage, isLastPage, goTo } = usePagination({
|
|
40
|
+
...props,
|
|
41
|
+
pageSize,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const changePageSize = (event: ChangeEvent<HTMLSelectElement>) => {
|
|
45
|
+
const { value } = event.target;
|
|
46
|
+
const newPageSize = Number(value) as PageSize;
|
|
47
|
+
setPageSize(newPageSize);
|
|
48
|
+
goTo(1);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div
|
|
53
|
+
data-slot="table-pagination"
|
|
54
|
+
{...containerProps}
|
|
55
|
+
className={cn(
|
|
56
|
+
"flex justify-center items-center gap-x-4 bg-background border border-[#D9D9D9] rounded-2xl py-2",
|
|
57
|
+
containerClassName,
|
|
58
|
+
)}
|
|
59
|
+
>
|
|
60
|
+
{sizes && (
|
|
61
|
+
<select
|
|
62
|
+
data-slot="table-pagination-size-trigger"
|
|
63
|
+
{...selectProps}
|
|
64
|
+
value={pageSize}
|
|
65
|
+
onChange={changePageSize}
|
|
66
|
+
className={cn(
|
|
67
|
+
"border border-input rounded-md w-fit min-w-[3rem] bg-background p-2 ring-offset-background",
|
|
68
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
|
|
69
|
+
selectClassName,
|
|
70
|
+
)}
|
|
71
|
+
>
|
|
72
|
+
{sizes.map((option: number, index) => (
|
|
73
|
+
<option
|
|
74
|
+
key={index}
|
|
75
|
+
value={option}
|
|
76
|
+
data-slot="table-pagination-size-option"
|
|
77
|
+
>
|
|
78
|
+
{option}
|
|
79
|
+
</option>
|
|
80
|
+
))}
|
|
81
|
+
</select>
|
|
82
|
+
)}
|
|
83
|
+
<span data-slot="table-pagination-range">
|
|
84
|
+
{range.start} - {range.end} de {props.totalItems}
|
|
85
|
+
</span>
|
|
86
|
+
<div className="flex gap-2">
|
|
87
|
+
<Button
|
|
88
|
+
data-slot="table-pagination-prev"
|
|
89
|
+
size="icon"
|
|
90
|
+
variant="ghost"
|
|
91
|
+
disabled={isFirstPage}
|
|
92
|
+
onClick={prev}
|
|
93
|
+
>
|
|
94
|
+
<ChevronLeft data-slot="table-pagination-prev-icon" />
|
|
95
|
+
</Button>
|
|
96
|
+
<Button
|
|
97
|
+
data-slot="table-pagination-next"
|
|
98
|
+
size="icon"
|
|
99
|
+
variant="ghost"
|
|
100
|
+
disabled={isLastPage}
|
|
101
|
+
onClick={next}
|
|
102
|
+
>
|
|
103
|
+
<ChevronRight data-slot="table-pagination-next-icon" />
|
|
104
|
+
</Button>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createSafeContext } from "../../../utils";
|
|
2
|
+
|
|
3
|
+
interface TabsContextProps {
|
|
4
|
+
activeTab: string;
|
|
5
|
+
setActiveTab: (tab: string) => void;
|
|
6
|
+
targetRef: HTMLButtonElement | null;
|
|
7
|
+
setTargetRef: (element: HTMLButtonElement | null) => void;
|
|
8
|
+
variant: "default" | "background";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const [useTabsContext, TabsContextProvider] =
|
|
12
|
+
createSafeContext<TabsContextProps>();
|
|
13
|
+
|
|
14
|
+
export type { TabsContextProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./tabs";
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
Input,
|
|
6
|
+
TabContent,
|
|
7
|
+
TabList,
|
|
8
|
+
Tabs,
|
|
9
|
+
TabTrigger,
|
|
10
|
+
} from "../../components";
|
|
11
|
+
import { useStep } from "../../hooks";
|
|
12
|
+
|
|
13
|
+
const meta: Meta<typeof Tabs> = {
|
|
14
|
+
title: "Data display/Tabs",
|
|
15
|
+
component: Tabs,
|
|
16
|
+
args: {},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default meta;
|
|
20
|
+
type Story = StoryObj<typeof Tabs>;
|
|
21
|
+
|
|
22
|
+
const AccountStep = () => {
|
|
23
|
+
return (
|
|
24
|
+
<>
|
|
25
|
+
<Input name="name" />
|
|
26
|
+
<Input name="lastname" />
|
|
27
|
+
</>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const PasswordStep = () => {
|
|
32
|
+
return (
|
|
33
|
+
<>
|
|
34
|
+
<Input name="password" type="password" />
|
|
35
|
+
<Input name="confirmation" type="password" />
|
|
36
|
+
</>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const FileStep = () => {
|
|
41
|
+
return (
|
|
42
|
+
<>
|
|
43
|
+
<Input name="file" type="file" />
|
|
44
|
+
</>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const steps = [
|
|
49
|
+
{
|
|
50
|
+
value: "account",
|
|
51
|
+
content: <AccountStep />,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
value: "password",
|
|
55
|
+
content: <PasswordStep />,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
value: "config",
|
|
59
|
+
content: <FileStep />,
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
export const Default: Story = {
|
|
64
|
+
render: () => {
|
|
65
|
+
return (
|
|
66
|
+
<Tabs defaultValue="account" className="container">
|
|
67
|
+
<TabList className="max-w-[500px] mx-auto">
|
|
68
|
+
<TabTrigger value="account">Account</TabTrigger>
|
|
69
|
+
<TabTrigger value="password">Password</TabTrigger>
|
|
70
|
+
<TabTrigger value="config">File</TabTrigger>
|
|
71
|
+
</TabList>
|
|
72
|
+
|
|
73
|
+
<TabContent value="account" className="space-y-2 min-h-[150px]">
|
|
74
|
+
<AccountStep />
|
|
75
|
+
</TabContent>
|
|
76
|
+
|
|
77
|
+
<TabContent value="password" className="space-y-2 min-h-[150px]">
|
|
78
|
+
<PasswordStep />
|
|
79
|
+
</TabContent>
|
|
80
|
+
|
|
81
|
+
<TabContent value="config" className="space-y-2 min-h-[150px]">
|
|
82
|
+
<FileStep />
|
|
83
|
+
</TabContent>
|
|
84
|
+
</Tabs>
|
|
85
|
+
);
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Se puede utilizar el hook `useStep` para facilitar el manejo de estado y validaciones
|
|
91
|
+
*/
|
|
92
|
+
export const Steps: Story = {
|
|
93
|
+
render: () => {
|
|
94
|
+
const { step, isFirstStep, isLastStep, next, back, findAndGo } =
|
|
95
|
+
useStep(steps);
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<Tabs
|
|
99
|
+
value={step.value}
|
|
100
|
+
onChange={(step: string) => findAndGo({ value: step })}
|
|
101
|
+
className="container"
|
|
102
|
+
>
|
|
103
|
+
<TabList className="max-w-[500px] mx-auto">
|
|
104
|
+
{steps.map(({ value }) => (
|
|
105
|
+
<TabTrigger key={value} value={value} className="capitalize">
|
|
106
|
+
{value}
|
|
107
|
+
</TabTrigger>
|
|
108
|
+
))}
|
|
109
|
+
</TabList>
|
|
110
|
+
|
|
111
|
+
{steps.map(({ value, content }) => (
|
|
112
|
+
<TabContent
|
|
113
|
+
key={value}
|
|
114
|
+
value={value}
|
|
115
|
+
className="space-y-2 min-h-[150px]"
|
|
116
|
+
>
|
|
117
|
+
{content}
|
|
118
|
+
</TabContent>
|
|
119
|
+
))}
|
|
120
|
+
<div className="flex justify-end mt-2 gap-x-2">
|
|
121
|
+
<Button variant="ghost" disabled={isFirstStep} onClick={back}>
|
|
122
|
+
Prev
|
|
123
|
+
</Button>
|
|
124
|
+
<Button disabled={isLastStep} onClick={next}>
|
|
125
|
+
Next
|
|
126
|
+
</Button>
|
|
127
|
+
</div>
|
|
128
|
+
</Tabs>
|
|
129
|
+
);
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Se puede utilizar el prop `variant` para cambiar el estilo del indicador
|
|
135
|
+
* `default` (línea) y `background` (fondo)
|
|
136
|
+
*/
|
|
137
|
+
export const IndicatorVariant: Story = {
|
|
138
|
+
render: () => {
|
|
139
|
+
const [variant, setVariant] = useState<"default" | "background">("default");
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<div className="space-y-8">
|
|
143
|
+
<div className="flex items-center gap-4">
|
|
144
|
+
<label htmlFor="variant" className="text-sm font-medium">
|
|
145
|
+
Variant:
|
|
146
|
+
</label>
|
|
147
|
+
<select
|
|
148
|
+
id="variant"
|
|
149
|
+
value={variant}
|
|
150
|
+
onChange={(e) =>
|
|
151
|
+
setVariant(e.target.value as "default" | "background")
|
|
152
|
+
}
|
|
153
|
+
className="px-3 py-1 rounded border"
|
|
154
|
+
>
|
|
155
|
+
<option value="default">Default</option>
|
|
156
|
+
<option value="background">Background</option>
|
|
157
|
+
</select>
|
|
158
|
+
</div>
|
|
159
|
+
|
|
160
|
+
<Tabs defaultValue="account" variant={variant}>
|
|
161
|
+
<TabList>
|
|
162
|
+
<TabTrigger value="account">Account</TabTrigger>
|
|
163
|
+
<TabTrigger value="password">Password</TabTrigger>
|
|
164
|
+
<TabTrigger value="config">Config</TabTrigger>
|
|
165
|
+
</TabList>
|
|
166
|
+
|
|
167
|
+
<TabContent value="account" className="space-y-2 min-h-[150px]">
|
|
168
|
+
<div>Account</div>
|
|
169
|
+
</TabContent>
|
|
170
|
+
|
|
171
|
+
<TabContent value="password" className="space-y-2 min-h-[150px]">
|
|
172
|
+
<div>Password</div>
|
|
173
|
+
</TabContent>
|
|
174
|
+
|
|
175
|
+
<TabContent value="config" className="space-y-2 min-h-[150px]">
|
|
176
|
+
<div>Config</div>
|
|
177
|
+
</TabContent>
|
|
178
|
+
</Tabs>
|
|
179
|
+
</div>
|
|
180
|
+
);
|
|
181
|
+
},
|
|
182
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { render, screen, waitFor } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { TabContent, TabList, Tabs, TabTrigger } from "../../components";
|
|
4
|
+
import { click } from "../../utils";
|
|
5
|
+
|
|
6
|
+
describe("Tabs component", () => {
|
|
7
|
+
it("should render correctly", () => {
|
|
8
|
+
render(<Tabs data-testid="Tabs" />);
|
|
9
|
+
const component = screen.getByTestId("Tabs");
|
|
10
|
+
expect(component).toBeInTheDocument();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should show tabs", () => {
|
|
14
|
+
render(
|
|
15
|
+
<Tabs>
|
|
16
|
+
<TabList>
|
|
17
|
+
<TabTrigger value="trigger">Trigger</TabTrigger>
|
|
18
|
+
<TabTrigger value="test">Test</TabTrigger>
|
|
19
|
+
</TabList>
|
|
20
|
+
</Tabs>,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
expect(screen.getByText(/trigger/i)).toBeInTheDocument();
|
|
24
|
+
expect(screen.getByText(/test/i)).toBeInTheDocument();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should show tab content", () => {
|
|
28
|
+
render(
|
|
29
|
+
<Tabs defaultValue="trigger">
|
|
30
|
+
<TabList>
|
|
31
|
+
<TabTrigger value="trigger">Trigger</TabTrigger>
|
|
32
|
+
<TabTrigger value="test">Test</TabTrigger>
|
|
33
|
+
</TabList>
|
|
34
|
+
<TabContent value="trigger">Contenido de trigger</TabContent>
|
|
35
|
+
</Tabs>,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
expect(screen.getByText("Contenido de trigger")).toBeInTheDocument();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should be controlled", () => {
|
|
42
|
+
const mock = vi.fn();
|
|
43
|
+
render(
|
|
44
|
+
<Tabs value="trigger" onChange={mock}>
|
|
45
|
+
<TabList>
|
|
46
|
+
<TabTrigger value="trigger">Trigger</TabTrigger>
|
|
47
|
+
<TabTrigger value="test">Test</TabTrigger>
|
|
48
|
+
</TabList>
|
|
49
|
+
<TabContent value="trigger">Contenido de trigger</TabContent>
|
|
50
|
+
<TabContent value="test">Contenido de test</TabContent>
|
|
51
|
+
</Tabs>,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const testTrigger = screen.getByText("Test");
|
|
55
|
+
click(testTrigger);
|
|
56
|
+
|
|
57
|
+
waitFor(() => {
|
|
58
|
+
expect(mock).toHaveBeenCalledWith("test");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|