tharaday 0.8.2 → 0.8.4
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/.gitignore +3 -0
- package/.storybook/preview.ts +2 -2
- package/dist/{src/components → components}/Accordion/Accordion.d.ts +0 -1
- package/dist/{src/components → components}/Avatar/Avatar.d.ts +0 -1
- package/dist/{src/components → components}/Badge/Badge.d.ts +0 -1
- package/dist/{src/components → components}/Box/Box.d.ts +0 -1
- package/dist/{src/components → components}/Box/Box.types.d.ts +11 -11
- package/dist/{src/components → components}/Box/helpers/getSpacingStyles.d.ts +2 -2
- package/dist/{src/components → components}/Breadcrumbs/Breadcrumbs.d.ts +0 -1
- package/dist/{src/components → components}/Button/Button.d.ts +0 -1
- package/dist/{src/components → components}/Card/Card.d.ts +0 -1
- package/dist/{src/components → components}/Checkbox/Checkbox.d.ts +0 -1
- package/dist/components/DatePicker/DatePicker.d.ts +1 -0
- package/dist/{src/components → components}/Divider/Divider.d.ts +0 -1
- package/dist/components/Drawer/Drawer.d.ts +1 -0
- package/dist/{src/components → components}/Dropdown/Dropdown.d.ts +0 -1
- package/dist/components/EmptyState/EmptyState.d.ts +1 -0
- package/dist/{src/components → components}/Header/Header.d.ts +0 -1
- package/dist/{src/components → components}/Input/Input.d.ts +0 -1
- package/dist/{src/components → components}/List/List.d.ts +2 -2
- package/dist/{src/components → components}/List/List.types.d.ts +3 -3
- package/dist/{src/components → components}/List/ListItem.d.ts +1 -1
- package/dist/{src/components → components}/List/ListItem.types.d.ts +1 -1
- package/dist/{src/components → components}/Loader/Loader.d.ts +0 -1
- package/dist/{src/components → components}/Modal/Modal.d.ts +1 -2
- package/dist/{src/components → components}/NavBar/NavBar.d.ts +0 -1
- package/dist/{src/components → components}/Notification/Notification.d.ts +0 -1
- package/dist/{src/components → components}/Pagination/Pagination.d.ts +0 -1
- package/dist/components/Popover/Popover.d.ts +1 -0
- package/dist/{src/components → components}/ProgressBar/ProgressBar.d.ts +0 -1
- package/dist/{src/components → components}/RadioButton/RadioButton.d.ts +0 -1
- package/dist/{src/components → components}/Select/Select.d.ts +0 -1
- package/dist/{src/components → components}/Skeleton/Skeleton.d.ts +0 -1
- package/dist/{src/components → components}/Slider/Slider.d.ts +0 -1
- package/dist/{src/components → components}/Stepper/Step.d.ts +0 -1
- package/dist/{src/components → components}/Stepper/Stepper.d.ts +0 -1
- package/dist/{src/components → components}/Stepper/stepper.utils.d.ts +2 -2
- package/dist/{src/components → components}/Switch/Switch.d.ts +0 -1
- package/dist/{src/components → components}/Table/Table.d.ts +0 -1
- package/dist/{src/components → components}/Tabs/Tabs.d.ts +0 -1
- package/dist/components/Tag/Tag.d.ts +1 -0
- package/dist/{src/components → components}/Text/Text.d.ts +0 -1
- package/dist/{src/components → components}/Textarea/Textarea.d.ts +0 -1
- package/dist/{src/components → components}/Tooltip/Tooltip.d.ts +0 -1
- package/dist/{src/components → components}/Tree/Tree.d.ts +2 -2
- package/dist/{src/components → components}/Tree/Tree.types.d.ts +1 -1
- package/dist/{src/components → components}/Tree/TreeItem.d.ts +1 -1
- package/dist/{src/components → components}/Tree/TreeItem.types.d.ts +1 -1
- package/dist/ds.css +1 -1
- package/dist/ds.js +1351 -1206
- package/dist/ds.umd.cjs +1 -1
- package/dist/hooks/useClickOutside.d.ts +6 -0
- package/dist/{src/hooks → hooks}/useComponentId.d.ts +1 -1
- package/dist/hooks/useFocusTrap.d.ts +17 -0
- package/dist/{src/index.d.ts → index.d.ts} +38 -28
- package/dist/{src/layouts → layouts}/AppLayout/AppLayout.d.ts +0 -1
- package/dist/{src/layouts → layouts}/AuthLayout/AuthLayout.d.ts +0 -1
- package/dist/{src/layouts → layouts}/DashboardLayout/DashboardLayout.d.ts +0 -1
- package/dist/{src/layouts → layouts}/SettingsLayout/SettingsLayout.d.ts +0 -1
- package/eslint.config.js +15 -0
- package/package.json +13 -11
- package/src/components/Accordion/Accordion.stories.tsx +1 -1
- package/src/components/Accordion/Accordion.tsx +1 -1
- package/src/components/Avatar/Avatar.stories.tsx +1 -1
- package/src/components/Avatar/Avatar.test.tsx +1 -1
- package/src/components/Badge/Badge.stories.tsx +1 -1
- package/src/components/Box/Box.module.css +0 -557
- package/src/components/Box/Box.test.tsx +4 -4
- package/src/components/Box/Box.tsx +8 -16
- package/src/components/Box/Box.types.ts +1 -1
- package/src/components/Box/helpers/getSpacingStyles.ts +24 -17
- package/src/components/Breadcrumbs/Breadcrumbs.stories.tsx +1 -1
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +1 -1
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +1 -1
- package/src/components/Breadcrumbs/Breadcrumbs.types.ts +1 -1
- package/src/components/Button/Button.stories.tsx +1 -1
- package/src/components/Card/Card.stories.tsx +1 -1
- package/src/components/Card/Card.test.tsx +1 -1
- package/src/components/Card/Card.tsx +2 -2
- package/src/components/Checkbox/Checkbox.stories.tsx +1 -1
- package/src/components/Checkbox/Checkbox.tsx +1 -1
- package/src/components/DatePicker/DatePicker.module.css +212 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +56 -0
- package/src/components/DatePicker/DatePicker.test.tsx +61 -0
- package/src/components/DatePicker/DatePicker.tsx +271 -0
- package/src/components/DatePicker/DatePicker.types.ts +11 -0
- package/src/components/Divider/Divider.stories.tsx +1 -1
- package/src/components/Drawer/Drawer.module.css +126 -0
- package/src/components/Drawer/Drawer.stories.tsx +71 -0
- package/src/components/Drawer/Drawer.test.tsx +49 -0
- package/src/components/Drawer/Drawer.tsx +77 -0
- package/src/components/Drawer/Drawer.types.ts +17 -0
- package/src/components/Dropdown/Dropdown.tsx +7 -3
- package/src/components/EmptyState/EmptyState.module.css +73 -0
- package/src/components/EmptyState/EmptyState.stories.tsx +65 -0
- package/src/components/EmptyState/EmptyState.test.tsx +30 -0
- package/src/components/EmptyState/EmptyState.tsx +29 -0
- package/src/components/EmptyState/EmptyState.types.ts +12 -0
- package/src/components/Header/Header.test.tsx +5 -5
- package/src/components/Header/Header.tsx +2 -2
- package/src/components/Input/Input.stories.tsx +1 -1
- package/src/components/Input/Input.tsx +1 -1
- package/src/components/List/List.stories.tsx +1 -0
- package/src/components/List/List.tsx +1 -1
- package/src/components/List/List.types.ts +3 -2
- package/src/components/List/ListItem.tsx +2 -1
- package/src/components/List/ListItem.types.ts +1 -1
- package/src/components/Loader/Loader.stories.tsx +1 -1
- package/src/components/Modal/Modal.stories.tsx +1 -1
- package/src/components/Modal/Modal.tsx +4 -65
- package/src/components/NavBar/NavBar.stories.tsx +1 -1
- package/src/components/Notification/Notification.stories.tsx +1 -1
- package/src/components/Notification/Notification.tsx +1 -1
- package/src/components/Pagination/Pagination.tsx +2 -2
- package/src/components/Popover/Popover.module.css +52 -0
- package/src/components/Popover/Popover.stories.tsx +67 -0
- package/src/components/Popover/Popover.test.tsx +40 -0
- package/src/components/Popover/Popover.tsx +78 -0
- package/src/components/Popover/Popover.types.ts +13 -0
- package/src/components/ProgressBar/ProgressBar.stories.tsx +1 -1
- package/src/components/ProgressBar/ProgressBar.tsx +1 -1
- package/src/components/RadioButton/RadioButton.stories.tsx +1 -1
- package/src/components/RadioButton/RadioButton.tsx +1 -1
- package/src/components/Select/Select.stories.tsx +1 -1
- package/src/components/Select/Select.tsx +1 -1
- package/src/components/Select/Select.types.ts +1 -1
- package/src/components/Skeleton/Skeleton.stories.tsx +1 -1
- package/src/components/Skeleton/Skeleton.tsx +1 -1
- package/src/components/Slider/Slider.tsx +4 -1
- package/src/components/Stepper/Stepper.stories.tsx +1 -1
- package/src/components/Stepper/Stepper.tsx +1 -1
- package/src/components/Stepper/stepper.utils.ts +4 -1
- package/src/components/Switch/Switch.stories.tsx +1 -1
- package/src/components/Switch/Switch.tsx +1 -1
- package/src/components/Table/Table.stories.tsx +1 -1
- package/src/components/Table/Table.test.tsx +3 -3
- package/src/components/Table/Table.tsx +4 -4
- package/src/components/Tabs/Tabs.tsx +2 -2
- package/src/components/Tag/Tag.module.css +115 -0
- package/src/components/Tag/Tag.stories.tsx +61 -0
- package/src/components/Tag/Tag.test.tsx +42 -0
- package/src/components/Tag/Tag.tsx +74 -0
- package/src/components/Tag/Tag.types.ts +15 -0
- package/src/components/Text/Text.module.css +0 -521
- package/src/components/Text/Text.stories.tsx +1 -1
- package/src/components/Text/Text.test.tsx +4 -4
- package/src/components/Text/Text.tsx +0 -14
- package/src/components/Text/Text.types.ts +3 -3
- package/src/components/Textarea/Textarea.stories.tsx +1 -1
- package/src/components/Textarea/Textarea.tsx +1 -1
- package/src/components/Tooltip/Tooltip.module.css +1 -1
- package/src/components/Tooltip/Tooltip.stories.tsx +1 -1
- package/src/components/Tooltip/Tooltip.test.tsx +5 -5
- package/src/components/Tooltip/Tooltip.tsx +6 -9
- package/src/components/Tree/Tree.stories.tsx +1 -0
- package/src/components/Tree/Tree.tsx +3 -2
- package/src/components/Tree/TreeItem.tsx +5 -2
- package/src/hooks/useClickOutside.test.tsx +69 -0
- package/src/hooks/useClickOutside.ts +36 -0
- package/src/hooks/useComponentId.ts +1 -0
- package/src/hooks/useFocusTrap.test.tsx +97 -0
- package/src/hooks/useFocusTrap.ts +89 -0
- package/src/index.ts +43 -33
- package/src/layouts/AppLayout/AppLayout.stories.tsx +2 -2
- package/src/layouts/AppLayout/AppLayout.tsx +1 -1
- package/src/layouts/AuthLayout/AuthLayout.stories.tsx +1 -1
- package/src/layouts/AuthLayout/AuthLayout.tsx +2 -2
- package/src/layouts/AuthLayout/AuthLayout.types.tsx +2 -2
- package/src/layouts/DashboardLayout/DashboardLayout.stories.tsx +3 -3
- package/src/layouts/SettingsLayout/SettingsLayout.stories.tsx +3 -3
- package/src/styles/themes.browser.test.ts +76 -0
- package/vite.config.ts +2 -3
- package/dist/src/components/Accordion/Accordion.stories.d.ts +0 -14
- package/dist/src/components/Accordion/Accordion.types.d.ts +0 -18
- package/dist/src/components/Avatar/Avatar.stories.d.ts +0 -14
- package/dist/src/components/Avatar/Avatar.types.d.ts +0 -10
- package/dist/src/components/Badge/Badge.stories.d.ts +0 -33
- package/dist/src/components/Badge/Badge.types.d.ts +0 -10
- package/dist/src/components/Box/Box.stories.d.ts +0 -38
- package/dist/src/components/Breadcrumbs/Breadcrumbs.stories.d.ts +0 -13
- package/dist/src/components/Breadcrumbs/Breadcrumbs.types.d.ts +0 -11
- package/dist/src/components/Button/Button.stories.d.ts +0 -22
- package/dist/src/components/Button/Button.types.d.ts +0 -12
- package/dist/src/components/Card/Card.stories.d.ts +0 -27
- package/dist/src/components/Card/Card.types.d.ts +0 -16
- package/dist/src/components/Checkbox/Checkbox.stories.d.ts +0 -17
- package/dist/src/components/Checkbox/Checkbox.types.d.ts +0 -7
- package/dist/src/components/Divider/Divider.stories.d.ts +0 -15
- package/dist/src/components/Divider/Divider.types.d.ts +0 -10
- package/dist/src/components/Dropdown/Dropdown.stories.d.ts +0 -12
- package/dist/src/components/Dropdown/Dropdown.types.d.ts +0 -24
- package/dist/src/components/Header/Header.stories.d.ts +0 -20
- package/dist/src/components/Header/Header.types.d.ts +0 -16
- package/dist/src/components/Input/Input.stories.d.ts +0 -32
- package/dist/src/components/Input/Input.types.d.ts +0 -10
- package/dist/src/components/List/List.stories.d.ts +0 -25
- package/dist/src/components/Loader/Loader.stories.d.ts +0 -25
- package/dist/src/components/Loader/Loader.types.d.ts +0 -8
- package/dist/src/components/Modal/Modal.stories.d.ts +0 -28
- package/dist/src/components/Modal/Modal.types.d.ts +0 -12
- package/dist/src/components/NavBar/NavBar.stories.d.ts +0 -8
- package/dist/src/components/NavBar/NavBar.types.d.ts +0 -38
- package/dist/src/components/Notification/Notification.stories.d.ts +0 -26
- package/dist/src/components/Notification/Notification.types.d.ts +0 -9
- package/dist/src/components/Pagination/Pagination.stories.d.ts +0 -21
- package/dist/src/components/Pagination/Pagination.types.d.ts +0 -34
- package/dist/src/components/ProgressBar/ProgressBar.stories.d.ts +0 -32
- package/dist/src/components/ProgressBar/ProgressBar.types.d.ts +0 -12
- package/dist/src/components/RadioButton/RadioButton.stories.d.ts +0 -30
- package/dist/src/components/RadioButton/RadioButton.types.d.ts +0 -9
- package/dist/src/components/Select/Select.stories.d.ts +0 -32
- package/dist/src/components/Select/Select.types.d.ts +0 -23
- package/dist/src/components/Skeleton/Skeleton.stories.d.ts +0 -15
- package/dist/src/components/Skeleton/Skeleton.types.d.ts +0 -9
- package/dist/src/components/Slider/Slider.stories.d.ts +0 -23
- package/dist/src/components/Slider/Slider.types.d.ts +0 -15
- package/dist/src/components/Stepper/Step.types.d.ts +0 -18
- package/dist/src/components/Stepper/Stepper.stories.d.ts +0 -15
- package/dist/src/components/Stepper/Stepper.types.d.ts +0 -14
- package/dist/src/components/Switch/Switch.stories.d.ts +0 -16
- package/dist/src/components/Switch/Switch.types.d.ts +0 -6
- package/dist/src/components/Table/Table.stories.d.ts +0 -27
- package/dist/src/components/Table/Table.types.d.ts +0 -19
- package/dist/src/components/Tabs/Tabs.stories.d.ts +0 -19
- package/dist/src/components/Tabs/Tabs.types.d.ts +0 -16
- package/dist/src/components/Text/Text.stories.d.ts +0 -78
- package/dist/src/components/Text/Text.types.d.ts +0 -52
- package/dist/src/components/Textarea/Textarea.stories.d.ts +0 -32
- package/dist/src/components/Textarea/Textarea.types.d.ts +0 -11
- package/dist/src/components/Tooltip/Tooltip.stories.d.ts +0 -10
- package/dist/src/components/Tooltip/Tooltip.types.d.ts +0 -12
- package/dist/src/components/Tree/Tree.stories.d.ts +0 -27
- package/dist/src/layouts/AppLayout/AppLayout.stories.d.ts +0 -13
- package/dist/src/layouts/AppLayout/AppLayout.types.d.ts +0 -13
- package/dist/src/layouts/AuthLayout/AuthLayout.stories.d.ts +0 -12
- package/dist/src/layouts/AuthLayout/AuthLayout.types.d.ts +0 -8
- package/dist/src/layouts/DashboardLayout/DashboardLayout.stories.d.ts +0 -11
- package/dist/src/layouts/DashboardLayout/DashboardLayout.types.d.ts +0 -10
- package/dist/src/layouts/SettingsLayout/SettingsLayout.stories.d.ts +0 -11
- package/dist/src/layouts/SettingsLayout/SettingsLayout.types.d.ts +0 -9
|
@@ -2,12 +2,12 @@ import { render, screen } from '@testing-library/react';
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
Table,
|
|
5
|
-
TableHeader,
|
|
6
5
|
TableBody,
|
|
6
|
+
TableCell,
|
|
7
7
|
TableFooter,
|
|
8
|
-
TableRow,
|
|
9
8
|
TableHead,
|
|
10
|
-
|
|
9
|
+
TableHeader,
|
|
10
|
+
TableRow,
|
|
11
11
|
} from './Table.tsx';
|
|
12
12
|
|
|
13
13
|
const BasicTable = () => (
|
|
@@ -2,13 +2,13 @@ import classnames from 'classnames';
|
|
|
2
2
|
|
|
3
3
|
import styles from './Table.module.css';
|
|
4
4
|
import type {
|
|
5
|
-
TableProps,
|
|
6
|
-
TableHeaderProps,
|
|
7
5
|
TableBodyProps,
|
|
6
|
+
TableCellProps,
|
|
8
7
|
TableFooterProps,
|
|
9
|
-
|
|
8
|
+
TableHeaderProps,
|
|
10
9
|
TableHeadProps,
|
|
11
|
-
|
|
10
|
+
TableProps,
|
|
11
|
+
TableRowProps,
|
|
12
12
|
} from './Table.types.ts';
|
|
13
13
|
|
|
14
14
|
export const Table = ({
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import classnames from 'classnames';
|
|
2
|
-
import {
|
|
2
|
+
import { type KeyboardEvent, useRef, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
5
|
-
|
|
6
5
|
import styles from './Tabs.module.css';
|
|
7
6
|
import type { TabsProps } from './Tabs.types.ts';
|
|
8
7
|
|
|
@@ -76,6 +75,7 @@ export const Tabs = ({
|
|
|
76
75
|
const isSelected = item.id === activeId;
|
|
77
76
|
const isDisabled = Boolean(item.disabled);
|
|
78
77
|
const tabIndex = isDisabled ? -1 : isSelected ? 0 : -1;
|
|
78
|
+
|
|
79
79
|
return (
|
|
80
80
|
<button
|
|
81
81
|
key={item.id}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
gap: var(--ds-space-1);
|
|
5
|
+
font-family: var(--ds-font-family-base);
|
|
6
|
+
font-weight: var(--ds-font-weight-medium);
|
|
7
|
+
border-radius: var(--ds-radius-full);
|
|
8
|
+
border: 1px solid transparent;
|
|
9
|
+
white-space: nowrap;
|
|
10
|
+
transition:
|
|
11
|
+
background-color 0.15s,
|
|
12
|
+
border-color 0.15s;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* Sizes */
|
|
16
|
+
.sm {
|
|
17
|
+
height: var(--ds-space-5);
|
|
18
|
+
padding: 0 var(--ds-space-2);
|
|
19
|
+
font-size: var(--ds-font-size-xs);
|
|
20
|
+
}
|
|
21
|
+
.md {
|
|
22
|
+
height: var(--ds-space-6);
|
|
23
|
+
padding: 0 var(--ds-space-3);
|
|
24
|
+
font-size: var(--ds-font-size-xs);
|
|
25
|
+
}
|
|
26
|
+
.lg {
|
|
27
|
+
height: var(--ds-space-8);
|
|
28
|
+
padding: 0 var(--ds-space-4);
|
|
29
|
+
font-size: var(--ds-font-size-sm);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Intents */
|
|
33
|
+
.neutral {
|
|
34
|
+
background-color: var(--ds-surface-1);
|
|
35
|
+
color: var(--ds-text-1);
|
|
36
|
+
border-color: var(--ds-border-1);
|
|
37
|
+
}
|
|
38
|
+
.success {
|
|
39
|
+
background-color: var(--ds-success-subtle);
|
|
40
|
+
color: var(--ds-success-active);
|
|
41
|
+
border-color: var(--ds-success);
|
|
42
|
+
}
|
|
43
|
+
.warning {
|
|
44
|
+
background-color: var(--ds-warning-subtle);
|
|
45
|
+
color: var(--ds-warning-active);
|
|
46
|
+
border-color: var(--ds-warning);
|
|
47
|
+
}
|
|
48
|
+
.danger {
|
|
49
|
+
background-color: var(--ds-danger-subtle);
|
|
50
|
+
color: var(--ds-danger-active);
|
|
51
|
+
border-color: var(--ds-danger);
|
|
52
|
+
}
|
|
53
|
+
.info {
|
|
54
|
+
background-color: var(--ds-info-subtle);
|
|
55
|
+
color: var(--ds-info-active);
|
|
56
|
+
border-color: var(--ds-info);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* Clickable */
|
|
60
|
+
.clickable {
|
|
61
|
+
cursor: pointer;
|
|
62
|
+
}
|
|
63
|
+
.clickable:hover {
|
|
64
|
+
filter: brightness(0.95);
|
|
65
|
+
}
|
|
66
|
+
.clickable:focus-visible {
|
|
67
|
+
outline: none;
|
|
68
|
+
box-shadow:
|
|
69
|
+
0 0 0 2px var(--ds-ring-offset),
|
|
70
|
+
0 0 0 4px var(--ds-ring);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.disabled {
|
|
74
|
+
opacity: 0.5;
|
|
75
|
+
cursor: not-allowed;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.icon {
|
|
79
|
+
display: inline-flex;
|
|
80
|
+
align-items: center;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.label {
|
|
84
|
+
line-height: 1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.removeButton {
|
|
88
|
+
all: unset;
|
|
89
|
+
display: inline-flex;
|
|
90
|
+
align-items: center;
|
|
91
|
+
justify-content: center;
|
|
92
|
+
cursor: pointer;
|
|
93
|
+
border-radius: var(--ds-radius-full);
|
|
94
|
+
padding: 0.125rem;
|
|
95
|
+
margin-left: var(--ds-space-1);
|
|
96
|
+
margin-right: calc(-1 * var(--ds-space-1));
|
|
97
|
+
opacity: 0.6;
|
|
98
|
+
transition:
|
|
99
|
+
opacity 0.15s,
|
|
100
|
+
background-color 0.15s;
|
|
101
|
+
}
|
|
102
|
+
.removeButton:hover {
|
|
103
|
+
opacity: 1;
|
|
104
|
+
background-color: color-mix(in srgb, currentColor 15%, transparent);
|
|
105
|
+
}
|
|
106
|
+
.removeButton:focus-visible {
|
|
107
|
+
outline: none;
|
|
108
|
+
box-shadow:
|
|
109
|
+
0 0 0 2px var(--ds-ring-offset),
|
|
110
|
+
0 0 0 4px var(--ds-ring);
|
|
111
|
+
}
|
|
112
|
+
.removeButton:disabled {
|
|
113
|
+
cursor: not-allowed;
|
|
114
|
+
pointer-events: none;
|
|
115
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
|
|
3
|
+
import { Box } from '../Box/Box.tsx';
|
|
4
|
+
import { Tag } from './Tag.tsx';
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Components/Tag',
|
|
8
|
+
component: Tag,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
parameters: { layout: 'centered' },
|
|
11
|
+
argTypes: {
|
|
12
|
+
intent: { control: 'select', options: ['neutral', 'success', 'warning', 'danger', 'info'] },
|
|
13
|
+
size: { control: 'select', options: ['sm', 'md', 'lg'] },
|
|
14
|
+
},
|
|
15
|
+
} satisfies Meta<typeof Tag>;
|
|
16
|
+
|
|
17
|
+
export default meta;
|
|
18
|
+
type Story = StoryObj<typeof meta>;
|
|
19
|
+
|
|
20
|
+
export const Default: Story = {
|
|
21
|
+
args: { label: 'Design' },
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const Dismissible: Story = {
|
|
25
|
+
args: { label: 'React', onRemove: () => {} },
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const Clickable: Story = {
|
|
29
|
+
args: { label: 'Clickable', onClick: () => {} },
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const WithIcon: Story = {
|
|
33
|
+
args: {
|
|
34
|
+
label: 'With icon',
|
|
35
|
+
icon: (
|
|
36
|
+
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" aria-hidden="true">
|
|
37
|
+
<circle cx="5" cy="5" r="4" stroke="currentColor" strokeWidth="1.5" />
|
|
38
|
+
</svg>
|
|
39
|
+
),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const Disabled: Story = {
|
|
44
|
+
args: { label: 'Disabled', onRemove: () => {}, disabled: true },
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const Gallery: Story = {
|
|
48
|
+
name: 'Gallery',
|
|
49
|
+
args: { label: '' },
|
|
50
|
+
render: () => (
|
|
51
|
+
<Box display="flex" flexDirection="column" gap={6}>
|
|
52
|
+
{(['neutral', 'success', 'warning', 'danger', 'info'] as const).map((intent) => (
|
|
53
|
+
<Box key={intent} display="flex" gap={3} alignItems="center">
|
|
54
|
+
{(['sm', 'md', 'lg'] as const).map((size) => (
|
|
55
|
+
<Tag key={size} label={intent} intent={intent} size={size} onRemove={() => {}} />
|
|
56
|
+
))}
|
|
57
|
+
</Box>
|
|
58
|
+
))}
|
|
59
|
+
</Box>
|
|
60
|
+
),
|
|
61
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
|
|
4
|
+
import { Tag } from './Tag.tsx';
|
|
5
|
+
|
|
6
|
+
describe('Tag', () => {
|
|
7
|
+
it('renders label', () => {
|
|
8
|
+
render(<Tag label="React" />);
|
|
9
|
+
expect(screen.getByText('React')).toBeInTheDocument();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('renders remove button when onRemove is provided', () => {
|
|
13
|
+
render(<Tag label="React" onRemove={vi.fn()} />);
|
|
14
|
+
expect(screen.getByRole('button', { name: 'Remove React' })).toBeInTheDocument();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('calls onRemove when remove button is clicked', async () => {
|
|
18
|
+
const onRemove = vi.fn();
|
|
19
|
+
render(<Tag label="React" onRemove={onRemove} />);
|
|
20
|
+
await userEvent.click(screen.getByRole('button', { name: 'Remove React' }));
|
|
21
|
+
expect(onRemove).toHaveBeenCalledOnce();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('calls onClick when clickable tag is clicked', async () => {
|
|
25
|
+
const onClick = vi.fn();
|
|
26
|
+
render(<Tag label="React" onClick={onClick} />);
|
|
27
|
+
await userEvent.click(screen.getByRole('button'));
|
|
28
|
+
expect(onClick).toHaveBeenCalledOnce();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('does not call onClick when disabled', async () => {
|
|
32
|
+
const onClick = vi.fn();
|
|
33
|
+
render(<Tag label="React" onClick={onClick} disabled />);
|
|
34
|
+
const tag = screen.queryByRole('button');
|
|
35
|
+
expect(tag).toBeNull();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('forwards extra props', () => {
|
|
39
|
+
render(<Tag label="React" data-testid="tag" />);
|
|
40
|
+
expect(screen.getByTestId('tag')).toBeInTheDocument();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import classnames from 'classnames';
|
|
2
|
+
import type { KeyboardEvent } from 'react';
|
|
3
|
+
|
|
4
|
+
import styles from './Tag.module.css';
|
|
5
|
+
import type { TagProps } from './Tag.types.ts';
|
|
6
|
+
|
|
7
|
+
export const Tag = ({
|
|
8
|
+
label,
|
|
9
|
+
intent = 'neutral',
|
|
10
|
+
size = 'md',
|
|
11
|
+
onRemove,
|
|
12
|
+
onClick,
|
|
13
|
+
icon,
|
|
14
|
+
disabled = false,
|
|
15
|
+
className,
|
|
16
|
+
...props
|
|
17
|
+
}: TagProps) => {
|
|
18
|
+
const isClickable = !!onClick && !disabled;
|
|
19
|
+
|
|
20
|
+
const handleKeyDown = (e: KeyboardEvent<HTMLSpanElement>) => {
|
|
21
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
22
|
+
e.preventDefault();
|
|
23
|
+
onClick?.();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<span
|
|
29
|
+
className={classnames(
|
|
30
|
+
styles.root,
|
|
31
|
+
styles[intent],
|
|
32
|
+
styles[size],
|
|
33
|
+
isClickable && styles.clickable,
|
|
34
|
+
disabled && styles.disabled,
|
|
35
|
+
className
|
|
36
|
+
)}
|
|
37
|
+
onClick={isClickable ? onClick : undefined}
|
|
38
|
+
role={isClickable ? 'button' : undefined}
|
|
39
|
+
tabIndex={isClickable ? 0 : undefined}
|
|
40
|
+
aria-disabled={disabled || undefined}
|
|
41
|
+
onKeyDown={isClickable ? handleKeyDown : undefined}
|
|
42
|
+
{...props}
|
|
43
|
+
>
|
|
44
|
+
{icon && (
|
|
45
|
+
<span className={styles.icon} aria-hidden="true">
|
|
46
|
+
{icon}
|
|
47
|
+
</span>
|
|
48
|
+
)}
|
|
49
|
+
<span className={styles.label}>{label}</span>
|
|
50
|
+
{onRemove && (
|
|
51
|
+
<button
|
|
52
|
+
type="button"
|
|
53
|
+
className={styles.removeButton}
|
|
54
|
+
onClick={(e) => {
|
|
55
|
+
e.stopPropagation();
|
|
56
|
+
onRemove();
|
|
57
|
+
}}
|
|
58
|
+
aria-label={`Remove ${label}`}
|
|
59
|
+
disabled={disabled}
|
|
60
|
+
tabIndex={disabled ? -1 : 0}
|
|
61
|
+
>
|
|
62
|
+
<svg width="8" height="8" viewBox="0 0 8 8" fill="none" aria-hidden="true">
|
|
63
|
+
<path
|
|
64
|
+
d="M1 1L7 7M7 1L1 7"
|
|
65
|
+
stroke="currentColor"
|
|
66
|
+
strokeWidth="1.5"
|
|
67
|
+
strokeLinecap="round"
|
|
68
|
+
/>
|
|
69
|
+
</svg>
|
|
70
|
+
</button>
|
|
71
|
+
)}
|
|
72
|
+
</span>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export type TagIntent = 'neutral' | 'success' | 'warning' | 'danger' | 'info';
|
|
4
|
+
export type TagSize = 'sm' | 'md' | 'lg';
|
|
5
|
+
|
|
6
|
+
export interface TagProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'onClick'> {
|
|
7
|
+
label: string;
|
|
8
|
+
intent?: TagIntent;
|
|
9
|
+
size?: TagSize;
|
|
10
|
+
onRemove?: () => void;
|
|
11
|
+
onClick?: () => void;
|
|
12
|
+
icon?: ReactNode;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|