tharaday 0.8.2 → 0.8.3
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/{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 +1294 -1149
- 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} +10 -0
- 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/package.json +11 -10
- 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/helpers/getSpacingStyles.ts +23 -17
- package/src/components/DatePicker/DatePicker.module.css +212 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +53 -0
- package/src/components/DatePicker/DatePicker.test.tsx +61 -0
- package/src/components/DatePicker/DatePicker.tsx +269 -0
- package/src/components/DatePicker/DatePicker.types.ts +11 -0
- package/src/components/Drawer/Drawer.module.css +126 -0
- package/src/components/Drawer/Drawer.stories.tsx +70 -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/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/Modal/Modal.tsx +2 -62
- 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/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.test.tsx +4 -4
- package/src/components/Text/Text.tsx +0 -14
- package/src/components/Tooltip/Tooltip.module.css +1 -1
- package/src/components/Tooltip/Tooltip.test.tsx +5 -5
- package/src/components/Tooltip/Tooltip.tsx +2 -6
- package/src/hooks/useClickOutside.test.tsx +68 -0
- package/src/hooks/useClickOutside.ts +35 -0
- package/src/hooks/useFocusTrap.test.tsx +95 -0
- package/src/hooks/useFocusTrap.ts +88 -0
- package/src/index.ts +10 -0
- package/src/styles/themes.browser.test.ts +75 -0
- package/vite.config.ts +1 -1
- 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
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: inline-block;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.trigger {
|
|
7
|
+
display: inline-block;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.content {
|
|
11
|
+
position: absolute;
|
|
12
|
+
z-index: 500;
|
|
13
|
+
background-color: var(--ds-surface-0);
|
|
14
|
+
border: 1px solid var(--ds-border-1);
|
|
15
|
+
border-radius: var(--ds-radius-md);
|
|
16
|
+
box-shadow: var(--ds-shadow-md);
|
|
17
|
+
padding: var(--ds-space-4);
|
|
18
|
+
min-width: 12rem;
|
|
19
|
+
font-family: var(--ds-font-family-base);
|
|
20
|
+
font-size: var(--ds-font-size-sm);
|
|
21
|
+
color: var(--ds-text-1);
|
|
22
|
+
opacity: 0;
|
|
23
|
+
pointer-events: none;
|
|
24
|
+
visibility: hidden;
|
|
25
|
+
transition:
|
|
26
|
+
opacity 0.15s,
|
|
27
|
+
visibility 0.15s;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.visible {
|
|
31
|
+
opacity: 1;
|
|
32
|
+
pointer-events: auto;
|
|
33
|
+
visibility: visible;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/* Placements */
|
|
37
|
+
.bottom {
|
|
38
|
+
top: calc(100% + var(--ds-space-2));
|
|
39
|
+
left: 0;
|
|
40
|
+
}
|
|
41
|
+
.top {
|
|
42
|
+
bottom: calc(100% + var(--ds-space-2));
|
|
43
|
+
left: 0;
|
|
44
|
+
}
|
|
45
|
+
.right {
|
|
46
|
+
left: calc(100% + var(--ds-space-2));
|
|
47
|
+
top: 0;
|
|
48
|
+
}
|
|
49
|
+
.left {
|
|
50
|
+
right: calc(100% + var(--ds-space-2));
|
|
51
|
+
top: 0;
|
|
52
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
|
|
3
|
+
import { Box } from '../Box/Box.tsx';
|
|
4
|
+
import { Button } from '../Button/Button.tsx';
|
|
5
|
+
import { Text } from '../Text/Text.tsx';
|
|
6
|
+
import { Popover } from './Popover.tsx';
|
|
7
|
+
|
|
8
|
+
const meta = {
|
|
9
|
+
title: 'Components/Popover',
|
|
10
|
+
component: Popover,
|
|
11
|
+
tags: ['autodocs'],
|
|
12
|
+
parameters: { layout: 'centered' },
|
|
13
|
+
argTypes: {
|
|
14
|
+
placement: { control: 'select', options: ['top', 'bottom', 'left', 'right'] },
|
|
15
|
+
},
|
|
16
|
+
} satisfies Meta<typeof Popover>;
|
|
17
|
+
|
|
18
|
+
export default meta;
|
|
19
|
+
type Story = StoryObj<typeof meta>;
|
|
20
|
+
|
|
21
|
+
export const Default: Story = {
|
|
22
|
+
args: {
|
|
23
|
+
trigger: <Button size="sm">Open popover</Button>,
|
|
24
|
+
children: (
|
|
25
|
+
<Box display="flex" flexDirection="column" gap={2}>
|
|
26
|
+
<Text variant="body-sm" weight="medium">
|
|
27
|
+
Popover title
|
|
28
|
+
</Text>
|
|
29
|
+
<Text variant="body-sm" color="subtle">
|
|
30
|
+
This is some popover content.
|
|
31
|
+
</Text>
|
|
32
|
+
</Box>
|
|
33
|
+
),
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const Top: Story = {
|
|
38
|
+
args: {
|
|
39
|
+
trigger: <Button size="sm">Above</Button>,
|
|
40
|
+
placement: 'top',
|
|
41
|
+
children: <Text variant="body-sm">Placed above the trigger.</Text>,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const Right: Story = {
|
|
46
|
+
args: {
|
|
47
|
+
trigger: <Button size="sm">Right</Button>,
|
|
48
|
+
placement: 'right',
|
|
49
|
+
children: <Text variant="body-sm">Placed to the right.</Text>,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const WithActions: Story = {
|
|
54
|
+
args: {
|
|
55
|
+
trigger: <Button size="sm">Options</Button>,
|
|
56
|
+
children: (
|
|
57
|
+
<Box display="flex" flexDirection="column" gap={2}>
|
|
58
|
+
<Button variant="subtle" fullWidth>
|
|
59
|
+
Edit
|
|
60
|
+
</Button>
|
|
61
|
+
<Button variant="subtle" intent="danger" fullWidth>
|
|
62
|
+
Delete
|
|
63
|
+
</Button>
|
|
64
|
+
</Box>
|
|
65
|
+
),
|
|
66
|
+
},
|
|
67
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
|
|
4
|
+
import { Button } from '../Button/Button.tsx';
|
|
5
|
+
import { Popover } from './Popover.tsx';
|
|
6
|
+
|
|
7
|
+
const trigger = <Button>Open</Button>;
|
|
8
|
+
const content = <p>Popover content</p>;
|
|
9
|
+
|
|
10
|
+
describe('Popover', () => {
|
|
11
|
+
it('renders trigger', () => {
|
|
12
|
+
render(<Popover trigger={trigger}>{content}</Popover>);
|
|
13
|
+
expect(screen.getByRole('button', { name: 'Open' })).toBeInTheDocument();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('content is hidden by default', () => {
|
|
17
|
+
render(<Popover trigger={trigger}>{content}</Popover>);
|
|
18
|
+
expect(screen.getByRole('dialog', { hidden: true })).toHaveAttribute('aria-hidden', 'true');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('shows content when trigger is clicked', async () => {
|
|
22
|
+
render(<Popover trigger={trigger}>{content}</Popover>);
|
|
23
|
+
await userEvent.click(screen.getByRole('button', { name: 'Open' }));
|
|
24
|
+
expect(screen.getByRole('dialog')).toHaveAttribute('aria-hidden', 'false');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('hides content when trigger is clicked again', async () => {
|
|
28
|
+
render(<Popover trigger={trigger}>{content}</Popover>);
|
|
29
|
+
await userEvent.click(screen.getByRole('button', { name: 'Open' }));
|
|
30
|
+
await userEvent.click(screen.getByRole('button', { name: 'Open' }));
|
|
31
|
+
expect(screen.getByRole('dialog', { hidden: true })).toHaveAttribute('aria-hidden', 'true');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('closes on Escape', async () => {
|
|
35
|
+
render(<Popover trigger={trigger}>{content}</Popover>);
|
|
36
|
+
await userEvent.click(screen.getByRole('button', { name: 'Open' }));
|
|
37
|
+
await userEvent.keyboard('{Escape}');
|
|
38
|
+
expect(screen.getByRole('dialog', { hidden: true })).toHaveAttribute('aria-hidden', 'true');
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import classnames from 'classnames';
|
|
2
|
+
import {
|
|
3
|
+
cloneElement,
|
|
4
|
+
isValidElement,
|
|
5
|
+
useCallback,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
type ReactElement,
|
|
9
|
+
} from 'react';
|
|
10
|
+
|
|
11
|
+
import { useClickOutside } from '../../hooks/useClickOutside.ts';
|
|
12
|
+
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
13
|
+
import styles from './Popover.module.css';
|
|
14
|
+
import type { PopoverProps } from './Popover.types.ts';
|
|
15
|
+
|
|
16
|
+
export const Popover = ({
|
|
17
|
+
trigger,
|
|
18
|
+
children,
|
|
19
|
+
placement = 'bottom',
|
|
20
|
+
isOpen: controlledOpen,
|
|
21
|
+
onOpenChange,
|
|
22
|
+
className,
|
|
23
|
+
id,
|
|
24
|
+
}: PopoverProps) => {
|
|
25
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
|
26
|
+
const isControlled = controlledOpen !== undefined;
|
|
27
|
+
const isOpen = isControlled ? controlledOpen : uncontrolledOpen;
|
|
28
|
+
const componentId = useComponentId('popover', id);
|
|
29
|
+
const contentId = `${componentId}-content`;
|
|
30
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
31
|
+
|
|
32
|
+
const close = useCallback(() => {
|
|
33
|
+
if (!isControlled) {
|
|
34
|
+
setUncontrolledOpen(false);
|
|
35
|
+
}
|
|
36
|
+
onOpenChange?.(false);
|
|
37
|
+
}, [isControlled, onOpenChange]);
|
|
38
|
+
|
|
39
|
+
const toggle = () => {
|
|
40
|
+
const next = !isOpen;
|
|
41
|
+
if (!isControlled) {
|
|
42
|
+
setUncontrolledOpen(next);
|
|
43
|
+
}
|
|
44
|
+
onOpenChange?.(next);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
useClickOutside(rootRef, close, isOpen);
|
|
48
|
+
|
|
49
|
+
const triggerElement = isValidElement(trigger)
|
|
50
|
+
? cloneElement(trigger as ReactElement<Record<string, unknown>>, {
|
|
51
|
+
onClick: (e: React.MouseEvent) => {
|
|
52
|
+
const existing = (trigger as ReactElement<Record<string, unknown>>).props.onClick;
|
|
53
|
+
if (typeof existing === 'function') {
|
|
54
|
+
existing(e);
|
|
55
|
+
}
|
|
56
|
+
toggle();
|
|
57
|
+
},
|
|
58
|
+
'aria-expanded': isOpen,
|
|
59
|
+
'aria-controls': contentId,
|
|
60
|
+
'aria-haspopup': 'dialog',
|
|
61
|
+
})
|
|
62
|
+
: trigger;
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div ref={rootRef} className={classnames(styles.root, className)}>
|
|
66
|
+
<div className={styles.trigger}>{triggerElement}</div>
|
|
67
|
+
<div
|
|
68
|
+
id={contentId}
|
|
69
|
+
role="dialog"
|
|
70
|
+
aria-modal="false"
|
|
71
|
+
aria-hidden={!isOpen}
|
|
72
|
+
className={classnames(styles.content, styles[placement], isOpen && styles.visible)}
|
|
73
|
+
>
|
|
74
|
+
{children}
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export type PopoverPlacement = 'top' | 'bottom' | 'left' | 'right';
|
|
4
|
+
|
|
5
|
+
export interface PopoverProps {
|
|
6
|
+
trigger: ReactNode;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
placement?: PopoverPlacement;
|
|
9
|
+
isOpen?: boolean;
|
|
10
|
+
onOpenChange?: (open: boolean) => void;
|
|
11
|
+
className?: string;
|
|
12
|
+
id?: string;
|
|
13
|
+
}
|
|
@@ -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
|
+
}
|