@boostdev/design-system-components 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +72 -0
- package/README.md +396 -0
- package/dist/index.cjs +2273 -0
- package/dist/index.css +2543 -0
- package/dist/index.d.cts +453 -0
- package/dist/index.d.ts +453 -0
- package/dist/index.js +2221 -0
- package/package.json +143 -0
- package/src/components/interaction/Button/Button.module.css +136 -0
- package/src/components/interaction/Button/Button.spec.tsx +50 -0
- package/src/components/interaction/Button/Button.stories.tsx +43 -0
- package/src/components/interaction/Button/Button.tsx +68 -0
- package/src/components/interaction/Button/index.ts +1 -0
- package/src/components/interaction/Command/Command.module.css +128 -0
- package/src/components/interaction/Command/Command.spec.tsx +60 -0
- package/src/components/interaction/Command/Command.stories.tsx +35 -0
- package/src/components/interaction/Command/Command.tsx +161 -0
- package/src/components/interaction/Command/index.ts +2 -0
- package/src/components/interaction/Dialog/Dialog.module.css +39 -0
- package/src/components/interaction/Dialog/Dialog.spec.tsx +43 -0
- package/src/components/interaction/Dialog/Dialog.stories.tsx +36 -0
- package/src/components/interaction/Dialog/Dialog.tsx +42 -0
- package/src/components/interaction/Dialog/index.ts +1 -0
- package/src/components/interaction/Drawer/Drawer.module.css +98 -0
- package/src/components/interaction/Drawer/Drawer.spec.tsx +43 -0
- package/src/components/interaction/Drawer/Drawer.stories.tsx +46 -0
- package/src/components/interaction/Drawer/Drawer.tsx +71 -0
- package/src/components/interaction/Drawer/index.ts +1 -0
- package/src/components/interaction/DropdownMenu/DropdownMenu.module.css +68 -0
- package/src/components/interaction/DropdownMenu/DropdownMenu.spec.tsx +74 -0
- package/src/components/interaction/DropdownMenu/DropdownMenu.stories.tsx +68 -0
- package/src/components/interaction/DropdownMenu/DropdownMenu.tsx +137 -0
- package/src/components/interaction/DropdownMenu/index.ts +1 -0
- package/src/components/interaction/Popover/Popover.module.css +39 -0
- package/src/components/interaction/Popover/Popover.spec.tsx +72 -0
- package/src/components/interaction/Popover/Popover.stories.tsx +47 -0
- package/src/components/interaction/Popover/Popover.tsx +78 -0
- package/src/components/interaction/Popover/index.ts +1 -0
- package/src/components/interaction/Rating/Rating.module.css +16 -0
- package/src/components/interaction/Rating/Rating.spec.tsx +30 -0
- package/src/components/interaction/Rating/Rating.stories.tsx +29 -0
- package/src/components/interaction/Rating/Rating.tsx +30 -0
- package/src/components/interaction/Rating/index.ts +1 -0
- package/src/components/interaction/Toast/Toast.module.css +48 -0
- package/src/components/interaction/Toast/Toast.spec.tsx +41 -0
- package/src/components/interaction/Toast/Toast.stories.tsx +57 -0
- package/src/components/interaction/Toast/Toast.tsx +64 -0
- package/src/components/interaction/Toast/index.ts +1 -0
- package/src/components/interaction/form/Checkbox/Checkbox.module.css +61 -0
- package/src/components/interaction/form/Checkbox/Checkbox.spec.tsx +39 -0
- package/src/components/interaction/form/Checkbox/Checkbox.stories.tsx +17 -0
- package/src/components/interaction/form/Checkbox/Checkbox.tsx +39 -0
- package/src/components/interaction/form/Checkbox/index.ts +1 -0
- package/src/components/interaction/form/Combobox/Combobox.module.css +104 -0
- package/src/components/interaction/form/Combobox/Combobox.spec.tsx +81 -0
- package/src/components/interaction/form/Combobox/Combobox.stories.tsx +25 -0
- package/src/components/interaction/form/Combobox/Combobox.tsx +182 -0
- package/src/components/interaction/form/Combobox/index.ts +1 -0
- package/src/components/interaction/form/FileInput/FileInput.module.css +79 -0
- package/src/components/interaction/form/FileInput/FileInput.spec.tsx +53 -0
- package/src/components/interaction/form/FileInput/FileInput.stories.tsx +17 -0
- package/src/components/interaction/form/FileInput/FileInput.tsx +99 -0
- package/src/components/interaction/form/FileInput/index.ts +1 -0
- package/src/components/interaction/form/FormInput/FormInput.module.css +37 -0
- package/src/components/interaction/form/FormInput/FormInput.spec.tsx +43 -0
- package/src/components/interaction/form/FormInput/FormInput.stories.tsx +17 -0
- package/src/components/interaction/form/FormInput/FormInput.tsx +47 -0
- package/src/components/interaction/form/FormInput/index.ts +1 -0
- package/src/components/interaction/form/NumberInput/NumberInput.module.css +78 -0
- package/src/components/interaction/form/NumberInput/NumberInput.spec.tsx +49 -0
- package/src/components/interaction/form/NumberInput/NumberInput.stories.tsx +17 -0
- package/src/components/interaction/form/NumberInput/NumberInput.tsx +106 -0
- package/src/components/interaction/form/NumberInput/index.ts +1 -0
- package/src/components/interaction/form/Radio/Radio.module.css +62 -0
- package/src/components/interaction/form/Radio/Radio.spec.tsx +38 -0
- package/src/components/interaction/form/Radio/Radio.stories.tsx +26 -0
- package/src/components/interaction/form/Radio/Radio.tsx +39 -0
- package/src/components/interaction/form/Radio/index.ts +1 -0
- package/src/components/interaction/form/Select/Select.module.css +64 -0
- package/src/components/interaction/form/Select/Select.spec.tsx +61 -0
- package/src/components/interaction/form/Select/Select.stories.tsx +24 -0
- package/src/components/interaction/form/Select/Select.tsx +72 -0
- package/src/components/interaction/form/Select/index.ts +1 -0
- package/src/components/interaction/form/Slider/Slider.module.css +99 -0
- package/src/components/interaction/form/Slider/Slider.spec.tsx +53 -0
- package/src/components/interaction/form/Slider/Slider.stories.tsx +18 -0
- package/src/components/interaction/form/Slider/Slider.tsx +71 -0
- package/src/components/interaction/form/Slider/index.ts +1 -0
- package/src/components/interaction/form/Switch/Switch.module.css +114 -0
- package/src/components/interaction/form/Switch/Switch.spec.tsx +48 -0
- package/src/components/interaction/form/Switch/Switch.stories.tsx +31 -0
- package/src/components/interaction/form/Switch/Switch.tsx +54 -0
- package/src/components/interaction/form/Switch/index.ts +1 -0
- package/src/components/interaction/form/Textarea/Textarea.module.css +44 -0
- package/src/components/interaction/form/Textarea/Textarea.spec.tsx +53 -0
- package/src/components/interaction/form/Textarea/Textarea.stories.tsx +18 -0
- package/src/components/interaction/form/Textarea/Textarea.tsx +44 -0
- package/src/components/interaction/form/Textarea/index.ts +1 -0
- package/src/components/interaction/form/atoms/InputContainer.module.css +9 -0
- package/src/components/interaction/form/atoms/InputContainer.tsx +9 -0
- package/src/components/interaction/form/atoms/Label.module.css +10 -0
- package/src/components/interaction/form/atoms/Label.tsx +15 -0
- package/src/components/interaction/form/atoms/Message.module.css +11 -0
- package/src/components/interaction/form/atoms/Message.tsx +17 -0
- package/src/components/layout/ButtonGroup/ButtonGroup.module.css +59 -0
- package/src/components/layout/ButtonGroup/ButtonGroup.spec.tsx +20 -0
- package/src/components/layout/ButtonGroup/ButtonGroup.stories.tsx +28 -0
- package/src/components/layout/ButtonGroup/ButtonGroup.tsx +17 -0
- package/src/components/layout/ButtonGroup/index.ts +1 -0
- package/src/components/layout/Card/Card.module.css +72 -0
- package/src/components/layout/Card/Card.spec.tsx +33 -0
- package/src/components/layout/Card/Card.stories.tsx +32 -0
- package/src/components/layout/Card/Card.tsx +45 -0
- package/src/components/layout/Card/index.ts +1 -0
- package/src/components/layout/IconWrapper/IconWrapper.module.css +24 -0
- package/src/components/layout/IconWrapper/IconWrapper.spec.tsx +19 -0
- package/src/components/layout/IconWrapper/IconWrapper.stories.tsx +22 -0
- package/src/components/layout/IconWrapper/IconWrapper.tsx +14 -0
- package/src/components/layout/IconWrapper/index.ts +1 -0
- package/src/components/layout/SectionHeader/SectionHeader.module.css +75 -0
- package/src/components/layout/SectionHeader/SectionHeader.spec.tsx +31 -0
- package/src/components/layout/SectionHeader/SectionHeader.stories.tsx +21 -0
- package/src/components/layout/SectionHeader/SectionHeader.tsx +32 -0
- package/src/components/layout/SectionHeader/index.ts +1 -0
- package/src/components/ui/Accordion/Accordion.module.css +87 -0
- package/src/components/ui/Accordion/Accordion.spec.tsx +78 -0
- package/src/components/ui/Accordion/Accordion.stories.tsx +34 -0
- package/src/components/ui/Accordion/Accordion.tsx +82 -0
- package/src/components/ui/Accordion/index.ts +1 -0
- package/src/components/ui/Alert/Alert.module.css +91 -0
- package/src/components/ui/Alert/Alert.spec.tsx +63 -0
- package/src/components/ui/Alert/Alert.stories.tsx +53 -0
- package/src/components/ui/Alert/Alert.tsx +54 -0
- package/src/components/ui/Alert/index.ts +1 -0
- package/src/components/ui/Avatar/Avatar.module.css +42 -0
- package/src/components/ui/Avatar/Avatar.spec.tsx +49 -0
- package/src/components/ui/Avatar/Avatar.stories.tsx +44 -0
- package/src/components/ui/Avatar/Avatar.tsx +45 -0
- package/src/components/ui/Avatar/index.ts +1 -0
- package/src/components/ui/Badge/Badge.module.css +46 -0
- package/src/components/ui/Badge/Badge.spec.tsx +19 -0
- package/src/components/ui/Badge/Badge.stories.tsx +29 -0
- package/src/components/ui/Badge/Badge.tsx +13 -0
- package/src/components/ui/Badge/index.ts +1 -0
- package/src/components/ui/Breadcrumb/Breadcrumb.module.css +50 -0
- package/src/components/ui/Breadcrumb/Breadcrumb.spec.tsx +44 -0
- package/src/components/ui/Breadcrumb/Breadcrumb.stories.tsx +48 -0
- package/src/components/ui/Breadcrumb/Breadcrumb.tsx +41 -0
- package/src/components/ui/Breadcrumb/index.ts +1 -0
- package/src/components/ui/Calendar/Calendar.module.css +120 -0
- package/src/components/ui/Calendar/Calendar.spec.tsx +64 -0
- package/src/components/ui/Calendar/Calendar.stories.tsx +59 -0
- package/src/components/ui/Calendar/Calendar.tsx +184 -0
- package/src/components/ui/Calendar/index.ts +1 -0
- package/src/components/ui/Carousel/Carousel.module.css +66 -0
- package/src/components/ui/Carousel/Carousel.spec.tsx +29 -0
- package/src/components/ui/Carousel/Carousel.stories.tsx +30 -0
- package/src/components/ui/Carousel/Carousel.tsx +64 -0
- package/src/components/ui/Carousel/index.ts +1 -0
- package/src/components/ui/DescriptionList/DescriptionList.module.css +43 -0
- package/src/components/ui/DescriptionList/DescriptionList.spec.tsx +31 -0
- package/src/components/ui/DescriptionList/DescriptionList.stories.tsx +21 -0
- package/src/components/ui/DescriptionList/DescriptionList.tsx +30 -0
- package/src/components/ui/DescriptionList/index.ts +1 -0
- package/src/components/ui/Link/Link.module.css +64 -0
- package/src/components/ui/Link/Link.spec.tsx +43 -0
- package/src/components/ui/Link/Link.stories.tsx +55 -0
- package/src/components/ui/Link/Link.tsx +42 -0
- package/src/components/ui/Link/index.ts +1 -0
- package/src/components/ui/Loading/Loading.module.css +33 -0
- package/src/components/ui/Loading/Loading.spec.tsx +19 -0
- package/src/components/ui/Loading/Loading.stories.tsx +27 -0
- package/src/components/ui/Loading/Loading.tsx +15 -0
- package/src/components/ui/Loading/index.ts +1 -0
- package/src/components/ui/NotificationBanner/NotificationBanner.module.css +79 -0
- package/src/components/ui/NotificationBanner/NotificationBanner.spec.tsx +42 -0
- package/src/components/ui/NotificationBanner/NotificationBanner.stories.tsx +30 -0
- package/src/components/ui/NotificationBanner/NotificationBanner.tsx +45 -0
- package/src/components/ui/NotificationBanner/index.ts +1 -0
- package/src/components/ui/Pagination/Pagination.module.css +78 -0
- package/src/components/ui/Pagination/Pagination.spec.tsx +67 -0
- package/src/components/ui/Pagination/Pagination.stories.tsx +40 -0
- package/src/components/ui/Pagination/Pagination.tsx +87 -0
- package/src/components/ui/Pagination/index.ts +1 -0
- package/src/components/ui/Progress/Progress.module.css +51 -0
- package/src/components/ui/Progress/Progress.spec.tsx +55 -0
- package/src/components/ui/Progress/Progress.stories.tsx +30 -0
- package/src/components/ui/Progress/Progress.tsx +43 -0
- package/src/components/ui/Progress/index.ts +1 -0
- package/src/components/ui/ProgressCircle/ProgressCircle.module.css +40 -0
- package/src/components/ui/ProgressCircle/ProgressCircle.spec.tsx +34 -0
- package/src/components/ui/ProgressCircle/ProgressCircle.stories.tsx +18 -0
- package/src/components/ui/ProgressCircle/ProgressCircle.tsx +75 -0
- package/src/components/ui/ProgressCircle/index.ts +1 -0
- package/src/components/ui/Separator/Separator.module.css +23 -0
- package/src/components/ui/Separator/Separator.spec.tsx +30 -0
- package/src/components/ui/Separator/Separator.stories.tsx +40 -0
- package/src/components/ui/Separator/Separator.tsx +21 -0
- package/src/components/ui/Separator/index.ts +1 -0
- package/src/components/ui/Skeleton/Skeleton.module.css +24 -0
- package/src/components/ui/Skeleton/Skeleton.spec.tsx +19 -0
- package/src/components/ui/Skeleton/Skeleton.stories.tsx +25 -0
- package/src/components/ui/Skeleton/Skeleton.tsx +12 -0
- package/src/components/ui/Skeleton/index.ts +1 -0
- package/src/components/ui/SkipLink/SkipLink.module.css +30 -0
- package/src/components/ui/SkipLink/SkipLink.spec.tsx +24 -0
- package/src/components/ui/SkipLink/SkipLink.stories.tsx +24 -0
- package/src/components/ui/SkipLink/SkipLink.tsx +14 -0
- package/src/components/ui/SkipLink/index.ts +1 -0
- package/src/components/ui/Table/Table.module.css +111 -0
- package/src/components/ui/Table/Table.spec.tsx +69 -0
- package/src/components/ui/Table/Table.stories.tsx +53 -0
- package/src/components/ui/Table/Table.tsx +98 -0
- package/src/components/ui/Table/index.ts +1 -0
- package/src/components/ui/Tabs/Tabs.module.css +61 -0
- package/src/components/ui/Tabs/Tabs.spec.tsx +91 -0
- package/src/components/ui/Tabs/Tabs.stories.tsx +59 -0
- package/src/components/ui/Tabs/Tabs.tsx +100 -0
- package/src/components/ui/Tabs/index.ts +1 -0
- package/src/components/ui/Tooltip/Tooltip.module.css +69 -0
- package/src/components/ui/Tooltip/Tooltip.spec.tsx +46 -0
- package/src/components/ui/Tooltip/Tooltip.stories.tsx +69 -0
- package/src/components/ui/Tooltip/Tooltip.tsx +38 -0
- package/src/components/ui/Tooltip/index.ts +1 -0
- package/src/components/ui/Typography/Typography.module.css +41 -0
- package/src/components/ui/Typography/Typography.spec.tsx +39 -0
- package/src/components/ui/Typography/Typography.stories.tsx +31 -0
- package/src/components/ui/Typography/Typography.tsx +28 -0
- package/src/components/ui/Typography/index.ts +1 -0
- package/src/css/index.css +55 -0
- package/src/index.ts +54 -0
- package/src/test/setup.ts +1 -0
- package/src/typings.d.ts +4 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
@layer component {
|
|
2
|
+
.wrapper {
|
|
3
|
+
width: 100%;
|
|
4
|
+
overflow-x: auto;
|
|
5
|
+
border-radius: var(--border_radius--s);
|
|
6
|
+
border: 1px solid var(--color_bg--subtle);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.table {
|
|
10
|
+
width: 100%;
|
|
11
|
+
border-collapse: collapse;
|
|
12
|
+
font-size: var(--font_size--body);
|
|
13
|
+
font-family: var(--font_family--body);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.caption {
|
|
17
|
+
caption-side: top;
|
|
18
|
+
text-align: start;
|
|
19
|
+
padding: var(--space_s) var(--space_m);
|
|
20
|
+
font-weight: var(--font_weight--semibold);
|
|
21
|
+
color: var(--color_on-bg);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.thead {
|
|
25
|
+
background-color: var(--color_bg--subtle);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.th {
|
|
29
|
+
padding: var(--space_s) var(--space_m);
|
|
30
|
+
text-align: start;
|
|
31
|
+
font-weight: var(--font_weight--semibold);
|
|
32
|
+
font-size: var(--font_size--body--s);
|
|
33
|
+
color: var(--color_on-bg--subtle);
|
|
34
|
+
white-space: nowrap;
|
|
35
|
+
border-bottom: 1px solid var(--color_bg--subtle);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.th.--sortable {
|
|
39
|
+
padding: 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.sortButton {
|
|
43
|
+
all: unset;
|
|
44
|
+
display: flex;
|
|
45
|
+
align-items: center;
|
|
46
|
+
gap: var(--space_xxs);
|
|
47
|
+
padding: var(--space_s) var(--space_m);
|
|
48
|
+
width: 100%;
|
|
49
|
+
cursor: pointer;
|
|
50
|
+
color: var(--color_on-bg--subtle);
|
|
51
|
+
font-weight: var(--font_weight--semibold);
|
|
52
|
+
font-size: var(--font_size--body--s);
|
|
53
|
+
transition: var(--animation_transition);
|
|
54
|
+
box-sizing: border-box;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.sortButton:focus-visible {
|
|
58
|
+
outline: var(--outline_default);
|
|
59
|
+
outline-offset: calc(var(--outline_offset) * -1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@media (hover: hover) and (pointer: fine) {
|
|
63
|
+
.sortButton:hover {
|
|
64
|
+
color: var(--color_on-bg);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.sortIcon {
|
|
69
|
+
width: 1rem;
|
|
70
|
+
height: 1rem;
|
|
71
|
+
opacity: 0.4;
|
|
72
|
+
transition: transform var(--animation_transition-duration) var(--animation_easing),
|
|
73
|
+
opacity var(--animation_transition-duration) var(--animation_easing);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.sortIcon.--sort-active {
|
|
77
|
+
opacity: 1;
|
|
78
|
+
color: var(--color_interactive);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.sortIcon.--sort-desc {
|
|
82
|
+
transform: rotate(180deg);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.tbody .tr {
|
|
86
|
+
border-bottom: 1px solid var(--color_bg--subtle);
|
|
87
|
+
transition: var(--animation_transition);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.tbody .tr:last-child {
|
|
91
|
+
border-bottom: none;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@media (hover: hover) and (pointer: fine) {
|
|
95
|
+
.tbody .tr:hover {
|
|
96
|
+
background-color: var(--color_bg--subtle);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.td {
|
|
101
|
+
padding: var(--space_s) var(--space_m);
|
|
102
|
+
color: var(--color_on-bg);
|
|
103
|
+
vertical-align: middle;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@media (prefers-reduced-motion: reduce) {
|
|
107
|
+
.sortIcon {
|
|
108
|
+
transition: none;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { Table } from './Table';
|
|
4
|
+
|
|
5
|
+
const columns = [
|
|
6
|
+
{ key: 'name', header: 'Name' },
|
|
7
|
+
{ key: 'role', header: 'Role', sortable: true },
|
|
8
|
+
{ key: 'status', header: 'Status', render: (row: Record<string, unknown>) => <span>{String(row.status)}</span> },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const rows = [
|
|
12
|
+
{ name: 'Alice', role: 'Admin', status: 'Active' },
|
|
13
|
+
{ name: 'Bob', role: 'User', status: 'Inactive' },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
describe('Table', () => {
|
|
17
|
+
it('renders a table element', () => {
|
|
18
|
+
render(<Table columns={columns} rows={rows} />);
|
|
19
|
+
expect(screen.getByRole('table')).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('renders column headers', () => {
|
|
23
|
+
render(<Table columns={columns} rows={rows} />);
|
|
24
|
+
expect(screen.getByRole('columnheader', { name: 'Name' })).toBeInTheDocument();
|
|
25
|
+
expect(screen.getByRole('columnheader', { name: /Role/i })).toBeInTheDocument();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('renders row data', () => {
|
|
29
|
+
render(<Table columns={columns} rows={rows} />);
|
|
30
|
+
expect(screen.getByText('Alice')).toBeInTheDocument();
|
|
31
|
+
expect(screen.getByText('Bob')).toBeInTheDocument();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('uses custom render function', () => {
|
|
35
|
+
render(<Table columns={columns} rows={rows} />);
|
|
36
|
+
expect(screen.getByText('Active')).toBeInTheDocument();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('renders a caption when provided', () => {
|
|
40
|
+
render(<Table columns={columns} rows={rows} caption="Team members" />);
|
|
41
|
+
expect(screen.getByText('Team members')).toBeInTheDocument();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('renders a sort button for sortable columns', () => {
|
|
45
|
+
render(<Table columns={columns} rows={rows} onSort={() => {}} />);
|
|
46
|
+
expect(screen.getByRole('button', { name: /Role/i })).toBeInTheDocument();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('calls onSort when a sortable column header is clicked', async () => {
|
|
50
|
+
const user = userEvent.setup();
|
|
51
|
+
const onSort = vi.fn();
|
|
52
|
+
render(<Table columns={columns} rows={rows} onSort={onSort} />);
|
|
53
|
+
await user.click(screen.getByRole('button', { name: /Role/i }));
|
|
54
|
+
expect(onSort).toHaveBeenCalledWith('role', 'asc');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('toggles sort direction on second click', async () => {
|
|
58
|
+
const user = userEvent.setup();
|
|
59
|
+
const onSort = vi.fn();
|
|
60
|
+
render(<Table columns={columns} rows={rows} sortKey="role" sortDirection="asc" onSort={onSort} />);
|
|
61
|
+
await user.click(screen.getByRole('button', { name: /Role/i }));
|
|
62
|
+
expect(onSort).toHaveBeenCalledWith('role', 'desc');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('sets aria-sort on the active sorted column', () => {
|
|
66
|
+
render(<Table columns={columns} rows={rows} sortKey="role" sortDirection="asc" onSort={() => {}} />);
|
|
67
|
+
expect(screen.getByRole('columnheader', { name: /Role/i })).toHaveAttribute('aria-sort', 'ascending');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Table } from './Table';
|
|
4
|
+
|
|
5
|
+
type User = { name: string; role: string; status: string; joined: string };
|
|
6
|
+
|
|
7
|
+
const meta = {
|
|
8
|
+
title: 'UI/Table',
|
|
9
|
+
component: Table,
|
|
10
|
+
tags: ['autodocs'],
|
|
11
|
+
} satisfies Meta<typeof Table<User>>;
|
|
12
|
+
|
|
13
|
+
export default meta;
|
|
14
|
+
type Story = StoryObj<typeof meta>;
|
|
15
|
+
|
|
16
|
+
const rows: User[] = [
|
|
17
|
+
{ name: 'Alice Johnson', role: 'Admin', status: 'Active', joined: '2023-01-15' },
|
|
18
|
+
{ name: 'Bob Smith', role: 'User', status: 'Inactive', joined: '2023-04-22' },
|
|
19
|
+
{ name: 'Carol White', role: 'Editor', status: 'Active', joined: '2024-02-10' },
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const columns = [
|
|
23
|
+
{ key: 'name', header: 'Name', sortable: true },
|
|
24
|
+
{ key: 'role', header: 'Role', sortable: true },
|
|
25
|
+
{ key: 'status', header: 'Status', render: (row: User) => (
|
|
26
|
+
<span style={{ color: row.status === 'Active' ? 'green' : 'grey' }}>{row.status}</span>
|
|
27
|
+
)},
|
|
28
|
+
{ key: 'joined', header: 'Joined' },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
export const Default: Story = { args: { columns, rows } };
|
|
32
|
+
export const WithCaption: Story = { args: { columns, rows, caption: 'Team members' } };
|
|
33
|
+
|
|
34
|
+
export const Sortable: Story = {
|
|
35
|
+
render: () => {
|
|
36
|
+
const [sortKey, setSortKey] = useState<string | undefined>();
|
|
37
|
+
const [sortDir, setSortDir] = useState<'asc' | 'desc'>('asc');
|
|
38
|
+
const sorted = [...rows].sort((a, b) => {
|
|
39
|
+
if (!sortKey) return 0;
|
|
40
|
+
const v = String(a[sortKey as keyof User]).localeCompare(String(b[sortKey as keyof User]));
|
|
41
|
+
return sortDir === 'asc' ? v : -v;
|
|
42
|
+
});
|
|
43
|
+
return (
|
|
44
|
+
<Table
|
|
45
|
+
columns={columns}
|
|
46
|
+
rows={sorted}
|
|
47
|
+
sortKey={sortKey}
|
|
48
|
+
sortDirection={sortDir}
|
|
49
|
+
onSort={(key, dir) => { setSortKey(key); setSortDir(dir); }}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import css from './Table.module.css';
|
|
3
|
+
import { cn } from '@boostdev/design-system-foundation';
|
|
4
|
+
|
|
5
|
+
interface TableColumn<Row> {
|
|
6
|
+
key: string;
|
|
7
|
+
header: ReactNode;
|
|
8
|
+
sortable?: boolean;
|
|
9
|
+
render?: (row: Row) => ReactNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface TableProps<Row extends Record<string, unknown>> {
|
|
13
|
+
columns: TableColumn<Row>[];
|
|
14
|
+
rows: Row[];
|
|
15
|
+
caption?: string;
|
|
16
|
+
sortKey?: string;
|
|
17
|
+
sortDirection?: 'asc' | 'desc';
|
|
18
|
+
onSort?: (key: string, direction: 'asc' | 'desc') => void;
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function Table<Row extends Record<string, unknown>>({
|
|
23
|
+
columns,
|
|
24
|
+
rows,
|
|
25
|
+
caption,
|
|
26
|
+
sortKey,
|
|
27
|
+
sortDirection,
|
|
28
|
+
onSort,
|
|
29
|
+
className,
|
|
30
|
+
}: Readonly<TableProps<Row>>) {
|
|
31
|
+
const handleSort = (key: string) => {
|
|
32
|
+
if (!onSort) return;
|
|
33
|
+
const nextDirection = sortKey === key && sortDirection === 'asc' ? 'desc' : 'asc';
|
|
34
|
+
onSort(key, nextDirection);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const getAriaSort = (key: string): 'ascending' | 'descending' | 'none' => {
|
|
38
|
+
if (sortKey !== key) return 'none';
|
|
39
|
+
return sortDirection === 'asc' ? 'ascending' : 'descending';
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div className={cn(css.wrapper, className)}>
|
|
44
|
+
<table className={css.table}>
|
|
45
|
+
{caption && <caption className={css.caption}>{caption}</caption>}
|
|
46
|
+
<thead className={css.thead}>
|
|
47
|
+
<tr>
|
|
48
|
+
{columns.map(col => (
|
|
49
|
+
<th
|
|
50
|
+
key={col.key}
|
|
51
|
+
scope="col"
|
|
52
|
+
aria-sort={col.sortable ? getAriaSort(col.key) : undefined}
|
|
53
|
+
className={cn(css.th, col.sortable ? css['--sortable'] : undefined)}
|
|
54
|
+
>
|
|
55
|
+
{col.sortable ? (
|
|
56
|
+
<button
|
|
57
|
+
type="button"
|
|
58
|
+
className={css.sortButton}
|
|
59
|
+
onClick={() => handleSort(col.key)}
|
|
60
|
+
>
|
|
61
|
+
{col.header}
|
|
62
|
+
<svg
|
|
63
|
+
aria-hidden="true"
|
|
64
|
+
className={cn(
|
|
65
|
+
css.sortIcon,
|
|
66
|
+
sortKey === col.key ? css['--sort-active'] : undefined,
|
|
67
|
+
sortKey === col.key && sortDirection === 'desc' ? css['--sort-desc'] : undefined,
|
|
68
|
+
)}
|
|
69
|
+
viewBox="0 0 24 24"
|
|
70
|
+
fill="none"
|
|
71
|
+
stroke="currentColor"
|
|
72
|
+
strokeWidth="2"
|
|
73
|
+
>
|
|
74
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="M6 9l6 6 6-6" />
|
|
75
|
+
</svg>
|
|
76
|
+
</button>
|
|
77
|
+
) : (
|
|
78
|
+
col.header
|
|
79
|
+
)}
|
|
80
|
+
</th>
|
|
81
|
+
))}
|
|
82
|
+
</tr>
|
|
83
|
+
</thead>
|
|
84
|
+
<tbody className={css.tbody}>
|
|
85
|
+
{rows.map((row, rowIndex) => (
|
|
86
|
+
<tr key={rowIndex} className={css.tr}>
|
|
87
|
+
{columns.map(col => (
|
|
88
|
+
<td key={col.key} className={css.td}>
|
|
89
|
+
{col.render ? col.render(row) : String(row[col.key] ?? '')}
|
|
90
|
+
</td>
|
|
91
|
+
))}
|
|
92
|
+
</tr>
|
|
93
|
+
))}
|
|
94
|
+
</tbody>
|
|
95
|
+
</table>
|
|
96
|
+
</div>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Table } from './Table';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
@layer component {
|
|
2
|
+
.tabs {
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.tabList {
|
|
8
|
+
display: flex;
|
|
9
|
+
border-bottom: 1px solid var(--color_bg--subtle);
|
|
10
|
+
gap: var(--space_xxs);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.tab {
|
|
14
|
+
--tab_color: var(--color_on-bg);
|
|
15
|
+
--tab_border-color: transparent;
|
|
16
|
+
|
|
17
|
+
all: unset;
|
|
18
|
+
display: inline-flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
padding: var(--space_s) var(--space_m);
|
|
21
|
+
font-family: var(--font_family--body);
|
|
22
|
+
font-size: var(--font_size--body);
|
|
23
|
+
font-weight: var(--font_weight--semibold);
|
|
24
|
+
color: var(--tab_color);
|
|
25
|
+
border-bottom: 2px solid var(--tab_border-color);
|
|
26
|
+
margin-bottom: -1px;
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
transition: var(--animation_transition);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.tab.--active {
|
|
32
|
+
--tab_color: var(--color_interactive);
|
|
33
|
+
--tab_border-color: var(--color_interactive);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.tab:disabled {
|
|
37
|
+
opacity: 0.4;
|
|
38
|
+
cursor: not-allowed;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.tab:focus-visible {
|
|
42
|
+
outline: var(--outline_default);
|
|
43
|
+
outline-offset: var(--outline_offset);
|
|
44
|
+
border-radius: var(--border_radius--xs);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@media (hover: hover) and (pointer: fine) {
|
|
48
|
+
.tab:not(:disabled, .--active):hover {
|
|
49
|
+
--tab_color: var(--color_interactive);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.panel {
|
|
54
|
+
padding-block-start: var(--space_m);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.panel:focus-visible {
|
|
58
|
+
outline: var(--outline_default);
|
|
59
|
+
outline-offset: var(--outline_offset);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { Tabs } from './Tabs';
|
|
4
|
+
|
|
5
|
+
const tabs = [
|
|
6
|
+
{ id: 'tab1', label: 'First', content: <p>First panel</p> },
|
|
7
|
+
{ id: 'tab2', label: 'Second', content: <p>Second panel</p> },
|
|
8
|
+
{ id: 'tab3', label: 'Third', content: <p>Third panel</p>, disabled: true },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
describe('Tabs', () => {
|
|
12
|
+
it('renders a tablist', () => {
|
|
13
|
+
render(<Tabs tabs={tabs} />);
|
|
14
|
+
expect(screen.getByRole('tablist')).toBeInTheDocument();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('renders all tab buttons', () => {
|
|
18
|
+
render(<Tabs tabs={tabs} />);
|
|
19
|
+
expect(screen.getAllByRole('tab')).toHaveLength(3);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('renders all tab panels', () => {
|
|
23
|
+
render(<Tabs tabs={tabs} />);
|
|
24
|
+
expect(screen.getAllByRole('tabpanel', { hidden: true })).toHaveLength(3);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('shows the first tab as active by default', () => {
|
|
28
|
+
render(<Tabs tabs={tabs} />);
|
|
29
|
+
expect(screen.getByRole('tab', { name: 'First' })).toHaveAttribute('aria-selected', 'true');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('shows the defaultTab as active when provided', () => {
|
|
33
|
+
render(<Tabs tabs={tabs} defaultTab="tab2" />);
|
|
34
|
+
expect(screen.getByRole('tab', { name: 'Second' })).toHaveAttribute('aria-selected', 'true');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('shows the first panel content by default', () => {
|
|
38
|
+
render(<Tabs tabs={tabs} />);
|
|
39
|
+
expect(screen.getByText('First panel')).toBeVisible();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('hides inactive panels', () => {
|
|
43
|
+
render(<Tabs tabs={tabs} />);
|
|
44
|
+
const allPanels = screen.getAllByRole('tabpanel', { hidden: true });
|
|
45
|
+
expect(allPanels[1]).not.toBeVisible();
|
|
46
|
+
expect(allPanels[2]).not.toBeVisible();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('switches panel on tab click', async () => {
|
|
50
|
+
const user = userEvent.setup();
|
|
51
|
+
render(<Tabs tabs={tabs} />);
|
|
52
|
+
await user.click(screen.getByRole('tab', { name: 'Second' }));
|
|
53
|
+
expect(screen.getByText('Second panel')).toBeVisible();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('marks the clicked tab as active', async () => {
|
|
57
|
+
const user = userEvent.setup();
|
|
58
|
+
render(<Tabs tabs={tabs} />);
|
|
59
|
+
await user.click(screen.getByRole('tab', { name: 'Second' }));
|
|
60
|
+
expect(screen.getByRole('tab', { name: 'Second' })).toHaveAttribute('aria-selected', 'true');
|
|
61
|
+
expect(screen.getByRole('tab', { name: 'First' })).toHaveAttribute('aria-selected', 'false');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('disables a tab when disabled is set', () => {
|
|
65
|
+
render(<Tabs tabs={tabs} />);
|
|
66
|
+
expect(screen.getByRole('tab', { name: 'Third' })).toBeDisabled();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('navigates with ArrowRight key', async () => {
|
|
70
|
+
const user = userEvent.setup();
|
|
71
|
+
render(<Tabs tabs={tabs} />);
|
|
72
|
+
screen.getByRole('tab', { name: 'First' }).focus();
|
|
73
|
+
await user.keyboard('{ArrowRight}');
|
|
74
|
+
expect(screen.getByRole('tab', { name: 'Second' })).toHaveFocus();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('navigates with ArrowLeft key', async () => {
|
|
78
|
+
const user = userEvent.setup();
|
|
79
|
+
render(<Tabs tabs={tabs} defaultTab="tab2" />);
|
|
80
|
+
screen.getByRole('tab', { name: 'Second' }).focus();
|
|
81
|
+
await user.keyboard('{ArrowLeft}');
|
|
82
|
+
expect(screen.getByRole('tab', { name: 'First' })).toHaveFocus();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('links each tab to its panel via aria-controls', () => {
|
|
86
|
+
render(<Tabs tabs={tabs} />);
|
|
87
|
+
const firstTab = screen.getByRole('tab', { name: 'First' });
|
|
88
|
+
const panelId = firstTab.getAttribute('aria-controls');
|
|
89
|
+
expect(document.getElementById(panelId!)).toBeInTheDocument();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Tabs } from './Tabs';
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'UI/Tabs',
|
|
6
|
+
component: Tabs,
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
} satisfies Meta<typeof Tabs>;
|
|
9
|
+
|
|
10
|
+
export default meta;
|
|
11
|
+
type Story = StoryObj<typeof meta>;
|
|
12
|
+
|
|
13
|
+
const defaultTabs = [
|
|
14
|
+
{ id: 'overview', label: 'Overview', content: <p>Overview content goes here.</p> },
|
|
15
|
+
{ id: 'details', label: 'Details', content: <p>Detailed information goes here.</p> },
|
|
16
|
+
{ id: 'history', label: 'History', content: <p>Historical records go here.</p> },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
export const Default: Story = { args: { tabs: defaultTabs } };
|
|
20
|
+
|
|
21
|
+
export const WithDefaultTab: Story = { args: { tabs: defaultTabs, defaultTab: 'details' } };
|
|
22
|
+
|
|
23
|
+
export const WithDisabledTab: Story = {
|
|
24
|
+
args: {
|
|
25
|
+
tabs: [
|
|
26
|
+
{ id: 'active', label: 'Active', content: <p>This tab is active.</p> },
|
|
27
|
+
{ id: 'disabled', label: 'Disabled', content: <p>This tab is disabled.</p>, disabled: true },
|
|
28
|
+
{ id: 'another', label: 'Another', content: <p>Another tab.</p> },
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const RichContent: Story = {
|
|
34
|
+
args: {
|
|
35
|
+
tabs: [
|
|
36
|
+
{
|
|
37
|
+
id: 'profile',
|
|
38
|
+
label: 'Profile',
|
|
39
|
+
content: (
|
|
40
|
+
<div>
|
|
41
|
+
<h3>User Profile</h3>
|
|
42
|
+
<p>Name: Jane Doe</p>
|
|
43
|
+
<p>Email: jane@example.com</p>
|
|
44
|
+
</div>
|
|
45
|
+
),
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 'settings',
|
|
49
|
+
label: 'Settings',
|
|
50
|
+
content: (
|
|
51
|
+
<div>
|
|
52
|
+
<h3>Account Settings</h3>
|
|
53
|
+
<p>Manage your preferences here.</p>
|
|
54
|
+
</div>
|
|
55
|
+
),
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { KeyboardEvent, ReactNode, useId, useRef, useState } from 'react';
|
|
2
|
+
import css from './Tabs.module.css';
|
|
3
|
+
import { cn } from '@boostdev/design-system-foundation';
|
|
4
|
+
|
|
5
|
+
interface TabItem {
|
|
6
|
+
id: string;
|
|
7
|
+
label: ReactNode;
|
|
8
|
+
content: ReactNode;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface TabsProps {
|
|
13
|
+
tabs: TabItem[];
|
|
14
|
+
defaultTab?: string;
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function Tabs({ tabs, defaultTab, className }: Readonly<TabsProps>) {
|
|
19
|
+
const baseId = useId();
|
|
20
|
+
const [activeTab, setActiveTab] = useState(defaultTab ?? tabs[0]?.id);
|
|
21
|
+
const tabRefs = useRef<(HTMLButtonElement | null)[]>([]);
|
|
22
|
+
|
|
23
|
+
const enabledIndexes = tabs
|
|
24
|
+
.map((tab, i) => ({ tab, i }))
|
|
25
|
+
.filter(({ tab }) => !tab.disabled)
|
|
26
|
+
.map(({ i }) => i);
|
|
27
|
+
|
|
28
|
+
const handleKeyDown = (e: KeyboardEvent<HTMLButtonElement>, index: number) => {
|
|
29
|
+
const pos = enabledIndexes.indexOf(index);
|
|
30
|
+
|
|
31
|
+
const focusAt = (i: number) => {
|
|
32
|
+
tabRefs.current[i]?.focus();
|
|
33
|
+
setActiveTab(tabs[i].id);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
if (e.key === 'ArrowRight') {
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
focusAt(enabledIndexes[(pos + 1) % enabledIndexes.length]);
|
|
39
|
+
} else if (e.key === 'ArrowLeft') {
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
focusAt(enabledIndexes[(pos - 1 + enabledIndexes.length) % enabledIndexes.length]);
|
|
42
|
+
} else if (e.key === 'Home') {
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
focusAt(enabledIndexes[0]);
|
|
45
|
+
} else if (e.key === 'End') {
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
focusAt(enabledIndexes[enabledIndexes.length - 1]);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div className={cn(css.tabs, className)}>
|
|
53
|
+
<div role="tablist" className={css.tabList}>
|
|
54
|
+
{tabs.map((tab, i) => {
|
|
55
|
+
const tabId = `${baseId}-tab-${tab.id}`;
|
|
56
|
+
const panelId = `${baseId}-panel-${tab.id}`;
|
|
57
|
+
const isActive = activeTab === tab.id;
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<button
|
|
61
|
+
key={tab.id}
|
|
62
|
+
ref={el => { tabRefs.current[i] = el; }}
|
|
63
|
+
id={tabId}
|
|
64
|
+
type="button"
|
|
65
|
+
role="tab"
|
|
66
|
+
aria-selected={isActive}
|
|
67
|
+
aria-controls={panelId}
|
|
68
|
+
tabIndex={isActive ? 0 : -1}
|
|
69
|
+
disabled={tab.disabled}
|
|
70
|
+
className={cn(css.tab, isActive ? css['--active'] : undefined)}
|
|
71
|
+
onClick={() => setActiveTab(tab.id)}
|
|
72
|
+
onKeyDown={e => handleKeyDown(e, i)}
|
|
73
|
+
>
|
|
74
|
+
{tab.label}
|
|
75
|
+
</button>
|
|
76
|
+
);
|
|
77
|
+
})}
|
|
78
|
+
</div>
|
|
79
|
+
{tabs.map(tab => {
|
|
80
|
+
const tabId = `${baseId}-tab-${tab.id}`;
|
|
81
|
+
const panelId = `${baseId}-panel-${tab.id}`;
|
|
82
|
+
const isActive = activeTab === tab.id;
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<div
|
|
86
|
+
key={tab.id}
|
|
87
|
+
id={panelId}
|
|
88
|
+
role="tabpanel"
|
|
89
|
+
aria-labelledby={tabId}
|
|
90
|
+
tabIndex={0}
|
|
91
|
+
hidden={!isActive}
|
|
92
|
+
className={css.panel}
|
|
93
|
+
>
|
|
94
|
+
{tab.content}
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
})}
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Tabs } from './Tabs';
|