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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import classnames from 'classnames';
|
|
2
2
|
import type { CSSProperties } from 'react';
|
|
3
3
|
|
|
4
|
+
import { getSpacingStyles } from '../Box/helpers/getSpacingStyles';
|
|
4
5
|
import styles from './List.module.css';
|
|
5
6
|
import type { ListProps } from './List.types';
|
|
6
|
-
import { getSpacingStyles } from '../Box/helpers/getSpacingStyles';
|
|
7
7
|
import { ListItem } from './ListItem';
|
|
8
8
|
|
|
9
9
|
export const List = ({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { BoxMargin, BoxPadding } from '../Box/Box.types';
|
|
3
4
|
|
|
4
5
|
export type ListVariant = 'unordered' | 'ordered' | 'none';
|
|
5
6
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import classnames from 'classnames';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import styles from './ListItem.module.css';
|
|
4
|
+
import type { ListItemProps } from './ListItem.types';
|
|
4
5
|
|
|
5
6
|
export const ListItem = ({ children, icon, className, ...props }: ListItemProps) => {
|
|
6
7
|
return (
|
|
@@ -2,12 +2,12 @@ import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
import { fn } from 'storybook/test';
|
|
4
4
|
|
|
5
|
-
import { Modal } from './Modal.tsx';
|
|
6
5
|
import { Box } from '../Box/Box.tsx';
|
|
7
6
|
import { Button } from '../Button/Button.tsx';
|
|
8
7
|
import { Input } from '../Input/Input.tsx';
|
|
9
8
|
import { Text } from '../Text/Text.tsx';
|
|
10
9
|
import { Textarea } from '../Textarea/Textarea.tsx';
|
|
10
|
+
import { Modal } from './Modal.tsx';
|
|
11
11
|
|
|
12
12
|
const meta = {
|
|
13
13
|
title: 'Components/Modal',
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import classnames from 'classnames';
|
|
2
|
-
import { useEffect, useRef } from 'react';
|
|
3
|
-
|
|
4
|
-
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
5
2
|
import { createPortal } from 'react-dom';
|
|
6
3
|
|
|
4
|
+
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
5
|
+
import { useFocusTrap } from '../../hooks/useFocusTrap.ts';
|
|
6
|
+
import { Button } from '../Button/Button.tsx';
|
|
7
7
|
import styles from './Modal.module.css';
|
|
8
8
|
import type { ModalProps } from './Modal.types.ts';
|
|
9
|
-
import { Button } from '../Button/Button.tsx';
|
|
10
9
|
|
|
11
10
|
export const Modal = ({
|
|
12
11
|
isOpen,
|
|
@@ -19,70 +18,10 @@ export const Modal = ({
|
|
|
19
18
|
className,
|
|
20
19
|
id,
|
|
21
20
|
}: ModalProps) => {
|
|
22
|
-
const modalRef =
|
|
23
|
-
const previousFocus = useRef<HTMLElement | null>(null);
|
|
24
|
-
const onCloseRef = useRef(onClose);
|
|
21
|
+
const modalRef = useFocusTrap<HTMLDivElement>({ isOpen, onClose, isLoading });
|
|
25
22
|
const componentId = useComponentId('modal', id);
|
|
26
23
|
const titleId = `${componentId}-title`;
|
|
27
24
|
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
onCloseRef.current = onClose;
|
|
30
|
-
}, [onClose]);
|
|
31
|
-
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
const handleKeyDown = (event: KeyboardEvent) => {
|
|
34
|
-
if (event.key === 'Escape' && !isLoading) {
|
|
35
|
-
onCloseRef.current();
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (event.key === 'Tab' && modalRef.current) {
|
|
40
|
-
const focusableElements = modalRef.current.querySelectorAll<HTMLElement>(
|
|
41
|
-
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
|
|
42
|
-
);
|
|
43
|
-
const firstElement = focusableElements[0];
|
|
44
|
-
const lastElement = focusableElements[focusableElements.length - 1];
|
|
45
|
-
|
|
46
|
-
if (!firstElement || !lastElement) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (event.shiftKey) {
|
|
51
|
-
if (document.activeElement === firstElement) {
|
|
52
|
-
lastElement.focus();
|
|
53
|
-
event.preventDefault();
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
if (document.activeElement === lastElement) {
|
|
57
|
-
firstElement.focus();
|
|
58
|
-
event.preventDefault();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
if (isOpen) {
|
|
65
|
-
previousFocus.current = document.activeElement as HTMLElement;
|
|
66
|
-
document.body.style.overflow = 'hidden';
|
|
67
|
-
window.addEventListener('keydown', handleKeyDown);
|
|
68
|
-
|
|
69
|
-
requestAnimationFrame(() => {
|
|
70
|
-
const focusableElements = modalRef.current?.querySelectorAll<HTMLElement>(
|
|
71
|
-
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
|
|
72
|
-
);
|
|
73
|
-
if (focusableElements && focusableElements.length > 0) {
|
|
74
|
-
focusableElements[0].focus();
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return () => {
|
|
80
|
-
document.body.style.overflow = 'unset';
|
|
81
|
-
window.removeEventListener('keydown', handleKeyDown);
|
|
82
|
-
previousFocus.current?.focus();
|
|
83
|
-
};
|
|
84
|
-
}, [isOpen, isLoading]);
|
|
85
|
-
|
|
86
25
|
if (!isOpen) {
|
|
87
26
|
return null;
|
|
88
27
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
2
|
import { fn } from 'storybook/test';
|
|
3
3
|
|
|
4
|
-
import { Notification } from './Notification.tsx';
|
|
5
4
|
import { Box } from '../Box/Box.tsx';
|
|
5
|
+
import { Notification } from './Notification.tsx';
|
|
6
6
|
|
|
7
7
|
const meta = {
|
|
8
8
|
title: 'Components/Notification',
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import classnames from 'classnames';
|
|
2
2
|
|
|
3
|
+
import { Button } from '../Button/Button.tsx';
|
|
3
4
|
import styles from './Notification.module.css';
|
|
4
5
|
import type { NotificationProps } from './Notification.types.ts';
|
|
5
|
-
import { Button } from '../Button/Button.tsx';
|
|
6
6
|
|
|
7
7
|
export const Notification = ({
|
|
8
8
|
intent = 'neutral',
|
|
@@ -2,10 +2,9 @@ import classnames from 'classnames';
|
|
|
2
2
|
import { useMemo, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
5
|
-
|
|
5
|
+
import { Button } from '../Button/Button.tsx';
|
|
6
6
|
import styles from './Pagination.module.css';
|
|
7
7
|
import type { PaginationProps } from './Pagination.types.ts';
|
|
8
|
-
import { Button } from '../Button/Button.tsx';
|
|
9
8
|
|
|
10
9
|
type PageItem = number | 'ellipsis';
|
|
11
10
|
|
|
@@ -16,6 +15,7 @@ const range = (start: number, end: number) => {
|
|
|
16
15
|
for (let i = start; i <= end; i += 1) {
|
|
17
16
|
items.push(i);
|
|
18
17
|
}
|
|
18
|
+
|
|
19
19
|
return items;
|
|
20
20
|
};
|
|
21
21
|
|
|
@@ -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
|
+
type ReactElement,
|
|
6
|
+
useCallback,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
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
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import classnames from 'classnames';
|
|
2
|
-
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
3
2
|
|
|
3
|
+
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
4
4
|
import styles from './ProgressBar.module.css';
|
|
5
5
|
import type { ProgressBarProps } from './ProgressBar.types.ts';
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import classnames from 'classnames';
|
|
2
|
-
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
3
2
|
|
|
3
|
+
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
4
4
|
import styles from './RadioButton.module.css';
|
|
5
5
|
import type { RadioButtonProps } from './RadioButton.types.ts';
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import classnames from 'classnames';
|
|
2
|
-
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
3
2
|
|
|
3
|
+
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
4
4
|
import styles from './Select.module.css';
|
|
5
5
|
import type { SelectProps } from './Select.types.ts';
|
|
6
6
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import classnames from 'classnames';
|
|
2
2
|
|
|
3
|
+
import { Box } from '../Box/Box.tsx';
|
|
3
4
|
import styles from './Skeleton.module.css';
|
|
4
5
|
import type { SkeletonProps } from './Skeleton.types.ts';
|
|
5
|
-
import { Box } from '../Box/Box.tsx';
|
|
6
6
|
|
|
7
7
|
export const Skeleton = ({
|
|
8
8
|
variant = 'rectangular',
|
|
@@ -2,7 +2,6 @@ import classnames from 'classnames';
|
|
|
2
2
|
import { useEffect, useMemo, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
5
|
-
|
|
6
5
|
import { Input } from '../Input/Input.tsx';
|
|
7
6
|
import styles from './Slider.module.css';
|
|
8
7
|
import type { SliderProps, SliderValue } from './Slider.types.ts';
|
|
@@ -12,6 +11,7 @@ const toNumber = (value: number | string | undefined, fallback: number): number
|
|
|
12
11
|
return fallback;
|
|
13
12
|
}
|
|
14
13
|
const parsed = typeof value === 'number' ? value : Number(value);
|
|
14
|
+
|
|
15
15
|
return Number.isNaN(parsed) ? fallback : parsed;
|
|
16
16
|
};
|
|
17
17
|
|
|
@@ -29,6 +29,7 @@ const alignToStep = (
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const steps = Math.round((value - min) / step);
|
|
32
|
+
|
|
32
33
|
return clamp(min + steps * step, min, max);
|
|
33
34
|
};
|
|
34
35
|
|
|
@@ -40,10 +41,12 @@ const normalizeToPair = (
|
|
|
40
41
|
if (Array.isArray(value)) {
|
|
41
42
|
const left = clamp(toNumber(value[0], min), min, max);
|
|
42
43
|
const right = clamp(toNumber(value[1], max), min, max);
|
|
44
|
+
|
|
43
45
|
return left <= right ? [left, right] : [right, left];
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
const resolved = clamp(toNumber(value, min), min, max);
|
|
49
|
+
|
|
47
50
|
return [resolved, resolved];
|
|
48
51
|
};
|
|
49
52
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
2
|
|
|
3
|
+
import { Box } from '../Box/Box.tsx';
|
|
3
4
|
import type { StepOptions } from './Step.types.ts';
|
|
4
5
|
import { Stepper } from './Stepper.tsx';
|
|
5
|
-
import { Box } from '../Box/Box.tsx';
|
|
6
6
|
|
|
7
7
|
const meta = {
|
|
8
8
|
title: 'Components/Stepper',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import classnames from 'classnames';
|
|
2
|
-
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
3
2
|
|
|
3
|
+
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
4
4
|
import { Step } from './Step.tsx';
|
|
5
5
|
import styles from './Stepper.module.css';
|
|
6
6
|
import type { StepperProps } from './Stepper.types.ts';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { StepOptions, StepperStatus } from './Step.types.ts';
|
|
2
2
|
|
|
3
3
|
const clampIndex = (index: number, length: number) => {
|
|
4
4
|
if (Number.isNaN(index) || length <= 0) {
|
|
5
5
|
return -1;
|
|
6
6
|
}
|
|
7
|
+
|
|
7
8
|
return Math.min(Math.max(index, 0), length - 1);
|
|
8
9
|
};
|
|
9
10
|
|
|
@@ -17,6 +18,7 @@ export const resolveCurrentIndex = (
|
|
|
17
18
|
if (typeof currentStep === 'string') {
|
|
18
19
|
return steps.findIndex((step) => step.id === currentStep);
|
|
19
20
|
}
|
|
21
|
+
|
|
20
22
|
return steps.findIndex((step) => step.status === 'current');
|
|
21
23
|
};
|
|
22
24
|
|
|
@@ -37,5 +39,6 @@ export const getStepStatus = (
|
|
|
37
39
|
if (index === currentIndex) {
|
|
38
40
|
return 'current';
|
|
39
41
|
}
|
|
42
|
+
|
|
40
43
|
return 'upcoming';
|
|
41
44
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import classnames from 'classnames';
|
|
2
|
-
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
3
2
|
|
|
3
|
+
import { useComponentId } from '../../hooks/useComponentId.ts';
|
|
4
4
|
import styles from './Switch.module.css';
|
|
5
5
|
import type { SwitchProps } from './Switch.types.ts';
|
|
6
6
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
2
|
|
|
3
|
-
import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from './Table.tsx';
|
|
4
3
|
import { Badge } from '../Badge/Badge.tsx';
|
|
5
4
|
import { Button } from '../Button/Button.tsx';
|
|
5
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from './Table.tsx';
|
|
6
6
|
|
|
7
7
|
const meta = {
|
|
8
8
|
title: 'Components/Table',
|