@ds-mo/ui 0.1.0
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/LICENSE +21 -0
- package/README.md +81 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +969 -0
- package/dist/index.js +2623 -0
- package/dist/index.js.map +1 -0
- package/dist/r/accordion.json +79 -0
- package/dist/r/badge.json +69 -0
- package/dist/r/banner.json +90 -0
- package/dist/r/breadcrumb.json +70 -0
- package/dist/r/button-group.json +65 -0
- package/dist/r/button.json +137 -0
- package/dist/r/card.json +82 -0
- package/dist/r/checkbox.json +91 -0
- package/dist/r/divider.json +57 -0
- package/dist/r/empty-state.json +69 -0
- package/dist/r/error-boundary.json +66 -0
- package/dist/r/fade.json +65 -0
- package/dist/r/field.json +71 -0
- package/dist/r/header.json +67 -0
- package/dist/r/input.json +77 -0
- package/dist/r/loader.json +54 -0
- package/dist/r/menu.json +130 -0
- package/dist/r/modal.json +93 -0
- package/dist/r/pagination.json +80 -0
- package/dist/r/radio.json +85 -0
- package/dist/r/registry.json +1600 -0
- package/dist/r/scrollbar.json +68 -0
- package/dist/r/select.json +93 -0
- package/dist/r/sidebar.json +105 -0
- package/dist/r/skeleton.json +72 -0
- package/dist/r/slider.json +87 -0
- package/dist/r/surface.json +97 -0
- package/dist/r/tab-group.json +72 -0
- package/dist/r/tab.json +71 -0
- package/dist/r/table.json +110 -0
- package/dist/r/tag.json +110 -0
- package/dist/r/text.json +94 -0
- package/dist/r/toast.json +77 -0
- package/dist/r/toggle-button-group.json +65 -0
- package/dist/r/toggle-button.json +94 -0
- package/dist/r/toggle.json +65 -0
- package/dist/r/tooltip.json +86 -0
- package/package.json +80 -0
- package/src/components/Accordion/Accordion.module.css +66 -0
- package/src/components/Accordion/Accordion.stories.tsx +95 -0
- package/src/components/Accordion/Accordion.tsx +122 -0
- package/src/components/Accordion/index.ts +2 -0
- package/src/components/Badge/Badge.module.css +6 -0
- package/src/components/Badge/Badge.stories.tsx +99 -0
- package/src/components/Badge/Badge.tsx +23 -0
- package/src/components/Badge/index.ts +2 -0
- package/src/components/Banner/Banner.module.css +67 -0
- package/src/components/Banner/Banner.stories.tsx +81 -0
- package/src/components/Banner/Banner.tsx +109 -0
- package/src/components/Banner/index.ts +2 -0
- package/src/components/Breadcrumb/Breadcrumb.module.css +46 -0
- package/src/components/Breadcrumb/Breadcrumb.stories.tsx +72 -0
- package/src/components/Breadcrumb/Breadcrumb.tsx +68 -0
- package/src/components/Breadcrumb/index.ts +2 -0
- package/src/components/Button/Button.module.css +343 -0
- package/src/components/Button/Button.stories.tsx +575 -0
- package/src/components/Button/Button.tsx +201 -0
- package/src/components/Button/index.ts +10 -0
- package/src/components/ButtonGroup/ButtonGroup.module.css +157 -0
- package/src/components/ButtonGroup/ButtonGroup.stories.tsx +384 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +122 -0
- package/src/components/ButtonGroup/index.ts +2 -0
- package/src/components/Card/Card.module.css +36 -0
- package/src/components/Card/Card.stories.tsx +78 -0
- package/src/components/Card/Card.tsx +53 -0
- package/src/components/Card/index.ts +2 -0
- package/src/components/Checkbox/Checkbox.module.css +47 -0
- package/src/components/Checkbox/Checkbox.stories.tsx +129 -0
- package/src/components/Checkbox/Checkbox.tsx +68 -0
- package/src/components/Checkbox/index.ts +2 -0
- package/src/components/Divider/Divider.module.css +19 -0
- package/src/components/Divider/Divider.stories.tsx +55 -0
- package/src/components/Divider/Divider.tsx +28 -0
- package/src/components/Divider/index.ts +2 -0
- package/src/components/EmptyState/EmptyState.module.css +8 -0
- package/src/components/EmptyState/EmptyState.stories.tsx +53 -0
- package/src/components/EmptyState/EmptyState.tsx +31 -0
- package/src/components/EmptyState/index.ts +2 -0
- package/src/components/ErrorBoundary/ErrorBoundary.module.css +18 -0
- package/src/components/ErrorBoundary/ErrorBoundary.stories.tsx +38 -0
- package/src/components/ErrorBoundary/ErrorBoundary.tsx +50 -0
- package/src/components/ErrorBoundary/index.ts +2 -0
- package/src/components/Fade/Fade.module.css +31 -0
- package/src/components/Fade/Fade.stories.tsx +35 -0
- package/src/components/Fade/Fade.tsx +33 -0
- package/src/components/Fade/index.ts +2 -0
- package/src/components/Field/Field.module.css +5 -0
- package/src/components/Field/Field.stories.tsx +111 -0
- package/src/components/Field/Field.tsx +22 -0
- package/src/components/Field/index.ts +2 -0
- package/src/components/Header/Header.module.css +33 -0
- package/src/components/Header/Header.stories.tsx +52 -0
- package/src/components/Header/Header.tsx +42 -0
- package/src/components/Header/index.ts +2 -0
- package/src/components/Input/Input.module.css +71 -0
- package/src/components/Input/Input.stories.tsx +135 -0
- package/src/components/Input/Input.tsx +76 -0
- package/src/components/Input/index.ts +2 -0
- package/src/components/LabelWrap/LabelWrap.module.css +34 -0
- package/src/components/LabelWrap/LabelWrap.tsx +32 -0
- package/src/components/LabelWrap/index.ts +1 -0
- package/src/components/Loader/Loader.module.css +9 -0
- package/src/components/Loader/Loader.stories.tsx +44 -0
- package/src/components/Loader/Loader.tsx +43 -0
- package/src/components/Loader/index.ts +2 -0
- package/src/components/Menu/DestructiveMenuItem.module.css +57 -0
- package/src/components/Menu/DestructiveMenuItem.tsx +64 -0
- package/src/components/Menu/Menu.module.css +49 -0
- package/src/components/Menu/Menu.stories.tsx +129 -0
- package/src/components/Menu/Menu.tsx +269 -0
- package/src/components/Menu/MenuItem.module.css +84 -0
- package/src/components/Menu/MenuItem.tsx +101 -0
- package/src/components/Menu/index.ts +6 -0
- package/src/components/Modal/Modal.module.css +67 -0
- package/src/components/Modal/Modal.stories.tsx +71 -0
- package/src/components/Modal/Modal.tsx +122 -0
- package/src/components/Modal/index.ts +2 -0
- package/src/components/Pagination/Pagination.module.css +64 -0
- package/src/components/Pagination/Pagination.stories.tsx +51 -0
- package/src/components/Pagination/Pagination.tsx +103 -0
- package/src/components/Pagination/index.ts +2 -0
- package/src/components/Radio/Radio.module.css +61 -0
- package/src/components/Radio/Radio.stories.tsx +101 -0
- package/src/components/Radio/Radio.tsx +108 -0
- package/src/components/Radio/index.ts +2 -0
- package/src/components/Scrollbar/Scrollbar.module.css +81 -0
- package/src/components/Scrollbar/Scrollbar.stories.tsx +46 -0
- package/src/components/Scrollbar/Scrollbar.tsx +187 -0
- package/src/components/Scrollbar/index.ts +2 -0
- package/src/components/Select/Select.module.css +31 -0
- package/src/components/Select/Select.stories.tsx +59 -0
- package/src/components/Select/Select.tsx +92 -0
- package/src/components/Select/index.ts +2 -0
- package/src/components/Sidebar/Sidebar.module.css +161 -0
- package/src/components/Sidebar/Sidebar.stories.tsx +125 -0
- package/src/components/Sidebar/Sidebar.tsx +129 -0
- package/src/components/Sidebar/SidebarItem.tsx +57 -0
- package/src/components/Sidebar/SidebarSection.tsx +42 -0
- package/src/components/Sidebar/index.ts +6 -0
- package/src/components/Skeleton/Skeleton.module.css +53 -0
- package/src/components/Skeleton/Skeleton.stories.tsx +89 -0
- package/src/components/Skeleton/Skeleton.tsx +66 -0
- package/src/components/Skeleton/index.ts +2 -0
- package/src/components/Slider/Slider.module.css +62 -0
- package/src/components/Slider/Slider.stories.tsx +120 -0
- package/src/components/Slider/Slider.tsx +74 -0
- package/src/components/Slider/index.ts +2 -0
- package/src/components/Surface/Surface.module.css +222 -0
- package/src/components/Surface/Surface.stories.tsx +213 -0
- package/src/components/Surface/Surface.tsx +219 -0
- package/src/components/Surface/index.ts +12 -0
- package/src/components/Tab/Tab.module.css +66 -0
- package/src/components/Tab/Tab.stories.tsx +103 -0
- package/src/components/Tab/Tab.tsx +41 -0
- package/src/components/Tab/index.ts +2 -0
- package/src/components/TabGroup/TabGroup.module.css +26 -0
- package/src/components/TabGroup/TabGroup.stories.tsx +60 -0
- package/src/components/TabGroup/TabGroup.tsx +83 -0
- package/src/components/TabGroup/index.ts +2 -0
- package/src/components/Table/Table.module.css +130 -0
- package/src/components/Table/Table.stories.tsx +111 -0
- package/src/components/Table/Table.tsx +226 -0
- package/src/components/Table/index.ts +11 -0
- package/src/components/Tag/Tag.module.css +270 -0
- package/src/components/Tag/Tag.stories.tsx +399 -0
- package/src/components/Tag/Tag.tsx +162 -0
- package/src/components/Tag/index.ts +2 -0
- package/src/components/Text/Text.module.css +166 -0
- package/src/components/Text/Text.stories.tsx +212 -0
- package/src/components/Text/Text.tsx +181 -0
- package/src/components/Text/index.ts +13 -0
- package/src/components/Toast/Toast.module.css +91 -0
- package/src/components/Toast/Toast.stories.tsx +66 -0
- package/src/components/Toast/Toast.tsx +182 -0
- package/src/components/Toast/index.ts +8 -0
- package/src/components/Toggle/Toggle.module.css +87 -0
- package/src/components/Toggle/Toggle.stories.tsx +85 -0
- package/src/components/Toggle/Toggle.tsx +52 -0
- package/src/components/Toggle/index.ts +2 -0
- package/src/components/ToggleButton/ToggleButton.module.css +172 -0
- package/src/components/ToggleButton/ToggleButton.stories.tsx +299 -0
- package/src/components/ToggleButton/ToggleButton.tsx +118 -0
- package/src/components/ToggleButton/index.ts +2 -0
- package/src/components/ToggleButtonGroup/ToggleButtonGroup.module.css +163 -0
- package/src/components/ToggleButtonGroup/ToggleButtonGroup.stories.tsx +341 -0
- package/src/components/ToggleButtonGroup/ToggleButtonGroup.tsx +111 -0
- package/src/components/ToggleButtonGroup/index.ts +2 -0
- package/src/components/Tooltip/Tooltip.module.css +45 -0
- package/src/components/Tooltip/Tooltip.stories.tsx +46 -0
- package/src/components/Tooltip/Tooltip.tsx +224 -0
- package/src/components/Tooltip/index.ts +2 -0
- package/src/css-modules.d.ts +4 -0
- package/src/docs/ColorUsage.mdx +195 -0
- package/src/docs/ElevationUsage.mdx +95 -0
- package/src/docs/Introduction.mdx +97 -0
- package/src/docs/OpticalSizing.mdx +178 -0
- package/src/docs/TypographyUsage.mdx +121 -0
- package/src/index.ts +154 -0
- package/src/stories/Colors.stories.tsx +528 -0
- package/src/stories/Dimensions.stories.tsx +200 -0
- package/src/stories/Effects.stories.tsx +231 -0
- package/src/stories/Icons.stories.tsx +159 -0
- package/src/stories/Typography.stories.tsx +157 -0
- package/src/types/icons.ts +15 -0
- package/src/types/index.ts +1 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/css-tokens.ts +22 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
.menuItem {
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
gap: var(--dimension-space-050);
|
|
5
|
+
padding: var(--dimension-space-075);
|
|
6
|
+
border: none;
|
|
7
|
+
cursor: pointer;
|
|
8
|
+
-webkit-user-select: none;
|
|
9
|
+
user-select: none;
|
|
10
|
+
text-align: left;
|
|
11
|
+
width: 100%;
|
|
12
|
+
min-height: var(--dimension-size-400);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.menuItem:has(.subtext) { align-items: flex-start; }
|
|
16
|
+
|
|
17
|
+
.iconPrefix {
|
|
18
|
+
flex-shrink: 0;
|
|
19
|
+
display: flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
color: var(--color-foreground-secondary);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.menuItemSelected .iconPrefix { color: var(--color-foreground-primary); }
|
|
25
|
+
|
|
26
|
+
.content {
|
|
27
|
+
flex: 1;
|
|
28
|
+
display: flex;
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
gap: var(--dimension-space-025);
|
|
31
|
+
min-width: 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.label { color: var(--color-foreground-secondary); }
|
|
35
|
+
.menuItem:has(.subtext) .label { color: var(--color-foreground-primary); }
|
|
36
|
+
.menuItemSelected .label { color: var(--color-foreground-primary) !important; }
|
|
37
|
+
.menuItemLabelTertiary .label, .menuItemLabelTertiary .iconPrefix { color: var(--color-foreground-tertiary); }
|
|
38
|
+
.menuItemNegative .label { color: var(--color-foreground-bold-negative) !important; }
|
|
39
|
+
|
|
40
|
+
.subtext { color: var(--color-foreground-secondary); line-height: 1.4; }
|
|
41
|
+
|
|
42
|
+
.menuItemInactive { opacity: 0.5; cursor: default; pointer-events: none; }
|
|
43
|
+
|
|
44
|
+
.toggleSuffix { flex-shrink: 0; display: flex; align-items: center; }
|
|
45
|
+
|
|
46
|
+
.toggle {
|
|
47
|
+
width: calc(var(--dimension-size-400) + var(--dimension-size-050));
|
|
48
|
+
height: var(--dimension-size-250);
|
|
49
|
+
background-color: var(--color-background-translucent);
|
|
50
|
+
border-radius: var(--dimension-radius-125);
|
|
51
|
+
position: relative;
|
|
52
|
+
transition: var(--effect-transition-interaction-background-short-2);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.toggleOn { background-color: var(--color-background-medium-brand); }
|
|
56
|
+
|
|
57
|
+
.toggleThumb {
|
|
58
|
+
width: var(--dimension-size-200);
|
|
59
|
+
height: var(--dimension-size-200);
|
|
60
|
+
background-color: var(--color-foreground-on-bold-background-primary);
|
|
61
|
+
border-radius: 50%;
|
|
62
|
+
position: absolute;
|
|
63
|
+
top: var(--dimension-space-025);
|
|
64
|
+
left: var(--dimension-space-025);
|
|
65
|
+
transition: transform var(--effect-motion-short-2);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.toggleOn .toggleThumb { transform: translateX(var(--dimension-offset-200)); }
|
|
69
|
+
|
|
70
|
+
.checkSuffix {
|
|
71
|
+
flex-shrink: 0;
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
color: var(--color-foreground-primary);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.chevronSuffix {
|
|
78
|
+
flex-shrink: 0;
|
|
79
|
+
display: flex;
|
|
80
|
+
align-items: center;
|
|
81
|
+
color: var(--color-foreground-secondary);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.menuItemSelected .chevronSuffix { color: var(--color-foreground-primary); }
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { Text } from '@/components/Text';
|
|
3
|
+
import { Surface } from '@/components/Surface';
|
|
4
|
+
import type { IconComponent } from '@/types';
|
|
5
|
+
import styles from './MenuItem.module.css';
|
|
6
|
+
|
|
7
|
+
export type MenuItemSelectionStyle = 'highlight' | 'radio' | 'noOverlay';
|
|
8
|
+
|
|
9
|
+
export interface MenuItemProps {
|
|
10
|
+
label: string;
|
|
11
|
+
onClick: () => void;
|
|
12
|
+
isSelected?: boolean;
|
|
13
|
+
isInactive?: boolean;
|
|
14
|
+
icon?: IconComponent;
|
|
15
|
+
labelColor?: 'primary' | 'secondary' | 'tertiary';
|
|
16
|
+
subtext?: string;
|
|
17
|
+
showToggle?: boolean;
|
|
18
|
+
toggleValue?: boolean;
|
|
19
|
+
intent?: 'negative';
|
|
20
|
+
selectionStyle?: MenuItemSelectionStyle;
|
|
21
|
+
showTrailingChevron?: boolean;
|
|
22
|
+
checkIcon?: IconComponent;
|
|
23
|
+
chevronIcon?: IconComponent;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const MenuItem = forwardRef<HTMLButtonElement, MenuItemProps>(
|
|
27
|
+
({
|
|
28
|
+
label,
|
|
29
|
+
onClick,
|
|
30
|
+
isSelected = false,
|
|
31
|
+
isInactive = false,
|
|
32
|
+
icon: Icon,
|
|
33
|
+
labelColor,
|
|
34
|
+
subtext,
|
|
35
|
+
showToggle = false,
|
|
36
|
+
toggleValue = false,
|
|
37
|
+
intent,
|
|
38
|
+
selectionStyle = 'highlight',
|
|
39
|
+
showTrailingChevron = false,
|
|
40
|
+
checkIcon: CheckIcon,
|
|
41
|
+
chevronIcon: ChevronIcon,
|
|
42
|
+
}, ref) => {
|
|
43
|
+
const useRadioStyle = selectionStyle === 'radio';
|
|
44
|
+
const noOverlay = selectionStyle === 'noOverlay' || useRadioStyle;
|
|
45
|
+
const showSelectedOverlay = isSelected && !noOverlay;
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Surface
|
|
49
|
+
ref={ref as React.Ref<HTMLElement>}
|
|
50
|
+
as="button"
|
|
51
|
+
interactive={!isInactive}
|
|
52
|
+
selected={showSelectedOverlay}
|
|
53
|
+
radius="sm"
|
|
54
|
+
className={`${styles.menuItem} ${isSelected ? styles.menuItemSelected : ''} ${isInactive ? styles.menuItemInactive : ''} ${intent === 'negative' ? styles.menuItemNegative : ''} ${labelColor === 'tertiary' ? styles.menuItemLabelTertiary : ''}`}
|
|
55
|
+
onClick={onClick}
|
|
56
|
+
type="button"
|
|
57
|
+
inactive={isInactive}
|
|
58
|
+
>
|
|
59
|
+
{Icon && (
|
|
60
|
+
<div className={styles.iconPrefix}>
|
|
61
|
+
<Icon size={20} />
|
|
62
|
+
</div>
|
|
63
|
+
)}
|
|
64
|
+
<div className={styles.content}>
|
|
65
|
+
<Text
|
|
66
|
+
variant={isSelected ? 'text-body-medium-emphasis' : 'text-body-medium'}
|
|
67
|
+
color={labelColor}
|
|
68
|
+
as="span"
|
|
69
|
+
className={styles.label}
|
|
70
|
+
>
|
|
71
|
+
{label}
|
|
72
|
+
</Text>
|
|
73
|
+
{subtext && (
|
|
74
|
+
<Text variant="text-body-small" as="span" className={styles.subtext}>
|
|
75
|
+
{subtext}
|
|
76
|
+
</Text>
|
|
77
|
+
)}
|
|
78
|
+
</div>
|
|
79
|
+
{showToggle && (
|
|
80
|
+
<div className={styles.toggleSuffix}>
|
|
81
|
+
<div className={`${styles.toggle} ${toggleValue ? styles.toggleOn : ''}`}>
|
|
82
|
+
<div className={styles.toggleThumb} />
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
)}
|
|
86
|
+
{useRadioStyle && isSelected && CheckIcon && (
|
|
87
|
+
<div className={styles.checkSuffix}>
|
|
88
|
+
<CheckIcon size={20} />
|
|
89
|
+
</div>
|
|
90
|
+
)}
|
|
91
|
+
{showTrailingChevron && ChevronIcon && (
|
|
92
|
+
<div className={styles.chevronSuffix}>
|
|
93
|
+
<ChevronIcon size={20} />
|
|
94
|
+
</div>
|
|
95
|
+
)}
|
|
96
|
+
</Surface>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
MenuItem.displayName = 'MenuItem';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Menu } from './Menu';
|
|
2
|
+
export type { MenuProps, MenuSection, MenuItemData, MenuSide, MenuAlign } from './Menu';
|
|
3
|
+
export { MenuItem } from './MenuItem';
|
|
4
|
+
export type { MenuItemProps, MenuItemSelectionStyle } from './MenuItem';
|
|
5
|
+
export { DestructiveMenuItem } from './DestructiveMenuItem';
|
|
6
|
+
export type { DestructiveMenuItemProps } from './DestructiveMenuItem';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
.backdrop {
|
|
2
|
+
position: fixed;
|
|
3
|
+
inset: 0;
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
justify-content: center;
|
|
7
|
+
padding: var(--dimension-space-200);
|
|
8
|
+
background-color: var(--color-background-shade);
|
|
9
|
+
backdrop-filter: blur(var(--effect-blur-sm));
|
|
10
|
+
-webkit-backdrop-filter: blur(var(--effect-blur-sm));
|
|
11
|
+
animation: modalBackdropFadeIn var(--effect-motion-short-2) forwards;
|
|
12
|
+
z-index: 9999;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.backdrop.closing {
|
|
16
|
+
animation: modalBackdropFadeOut var(--effect-motion-short-3) forwards;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@keyframes modalBackdropFadeIn {
|
|
20
|
+
from { opacity: 0; }
|
|
21
|
+
to { opacity: 1; }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@keyframes modalBackdropFadeOut {
|
|
25
|
+
from { opacity: 1; }
|
|
26
|
+
to { opacity: 0; }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.dialog {
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-direction: column;
|
|
32
|
+
max-height: calc(100vh - 32px);
|
|
33
|
+
overflow: hidden;
|
|
34
|
+
animation: modalDialogFadeIn var(--effect-motion-short-2) forwards;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.backdrop.closing .dialog {
|
|
38
|
+
animation: modalDialogFadeOut var(--effect-motion-short-3) forwards;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@keyframes modalDialogFadeIn {
|
|
42
|
+
from { opacity: 0; }
|
|
43
|
+
to { opacity: 1; }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@keyframes modalDialogFadeOut {
|
|
47
|
+
from { opacity: 1; }
|
|
48
|
+
to { opacity: 0; }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.header {
|
|
52
|
+
padding: var(--dimension-space-200) var(--dimension-space-200) var(--dimension-space-100) var(--dimension-space-200);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.subtitle {
|
|
56
|
+
margin-top: var(--dimension-space-100);
|
|
57
|
+
text-wrap: balance;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.body {
|
|
61
|
+
padding: var(--dimension-space-100) var(--dimension-space-200);
|
|
62
|
+
overflow-y: auto;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.footer {
|
|
66
|
+
padding: var(--dimension-space-100) var(--dimension-space-200) var(--dimension-space-200) var(--dimension-space-200);
|
|
67
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
3
|
+
import { Modal } from './Modal';
|
|
4
|
+
import { Button } from '../Button';
|
|
5
|
+
|
|
6
|
+
const meta: Meta<typeof Modal> = {
|
|
7
|
+
title: 'Components/Modal',
|
|
8
|
+
component: Modal,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default meta;
|
|
12
|
+
type Story = StoryObj<typeof Modal>;
|
|
13
|
+
|
|
14
|
+
export const Default: Story = {
|
|
15
|
+
render: () => {
|
|
16
|
+
const [open, setOpen] = useState(false);
|
|
17
|
+
return (
|
|
18
|
+
<>
|
|
19
|
+
<Button variant="primary" label="Open Modal" onClick={() => setOpen(true)} />
|
|
20
|
+
<Modal isOpen={open} onClose={() => setOpen(false)} title="Confirm Action">
|
|
21
|
+
<p>Are you sure you want to proceed? This action cannot be undone.</p>
|
|
22
|
+
</Modal>
|
|
23
|
+
</>
|
|
24
|
+
);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const WithSubtitleAndFooter: Story = {
|
|
29
|
+
render: () => {
|
|
30
|
+
const [open, setOpen] = useState(false);
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
<Button variant="primary" label="Open Modal" onClick={() => setOpen(true)} />
|
|
34
|
+
<Modal
|
|
35
|
+
isOpen={open}
|
|
36
|
+
onClose={() => setOpen(false)}
|
|
37
|
+
title="Edit Profile"
|
|
38
|
+
subtitle="Update your personal information"
|
|
39
|
+
footer={
|
|
40
|
+
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 8 }}>
|
|
41
|
+
<Button variant="secondary" label="Cancel" onClick={() => setOpen(false)} />
|
|
42
|
+
<Button variant="primary" label="Save Changes" onClick={() => setOpen(false)} />
|
|
43
|
+
</div>
|
|
44
|
+
}
|
|
45
|
+
>
|
|
46
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
|
|
47
|
+
<p>Form content would go here.</p>
|
|
48
|
+
</div>
|
|
49
|
+
</Modal>
|
|
50
|
+
</>
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const Sizes: Story = {
|
|
56
|
+
render: () => {
|
|
57
|
+
const [size, setSize] = useState<'sm' | 'md' | 'lg' | null>(null);
|
|
58
|
+
return (
|
|
59
|
+
<>
|
|
60
|
+
<div style={{ display: 'flex', gap: 8 }}>
|
|
61
|
+
<Button variant="secondary" label="Small" onClick={() => setSize('sm')} />
|
|
62
|
+
<Button variant="secondary" label="Medium" onClick={() => setSize('md')} />
|
|
63
|
+
<Button variant="secondary" label="Large" onClick={() => setSize('lg')} />
|
|
64
|
+
</div>
|
|
65
|
+
<Modal isOpen={!!size} onClose={() => setSize(null)} title={`${size} modal`} width={size || 'md'}>
|
|
66
|
+
<p>This is a {size} width modal.</p>
|
|
67
|
+
</Modal>
|
|
68
|
+
</>
|
|
69
|
+
);
|
|
70
|
+
},
|
|
71
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import React, { useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import { Surface } from '@/components/Surface';
|
|
4
|
+
import { Text } from '@/components/Text';
|
|
5
|
+
import styles from './Modal.module.css';
|
|
6
|
+
|
|
7
|
+
export type ModalWidth = 'sm' | 'md' | 'lg';
|
|
8
|
+
|
|
9
|
+
const WIDTH_MAP: Record<ModalWidth, string> = {
|
|
10
|
+
sm: 'var(--dimension-modal-width-sm, 400px)',
|
|
11
|
+
md: 'var(--dimension-modal-width-md, 560px)',
|
|
12
|
+
lg: 'var(--dimension-modal-width-lg, 720px)',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const CLOSE_ANIMATION_MS = 220;
|
|
16
|
+
|
|
17
|
+
export interface ModalProps {
|
|
18
|
+
isOpen: boolean;
|
|
19
|
+
onClose: () => void;
|
|
20
|
+
title: string;
|
|
21
|
+
subtitle?: React.ReactNode;
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
footer?: React.ReactNode;
|
|
24
|
+
width?: ModalWidth | string;
|
|
25
|
+
bodyClassName?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const Modal: React.FC<ModalProps> = ({
|
|
29
|
+
isOpen,
|
|
30
|
+
onClose,
|
|
31
|
+
title,
|
|
32
|
+
subtitle,
|
|
33
|
+
children,
|
|
34
|
+
footer,
|
|
35
|
+
width = 'md',
|
|
36
|
+
bodyClassName,
|
|
37
|
+
}) => {
|
|
38
|
+
const dialogRef = useRef<HTMLDivElement>(null);
|
|
39
|
+
const titleId = useId();
|
|
40
|
+
const [isClosing, setIsClosing] = useState(false);
|
|
41
|
+
const [shouldRender, setShouldRender] = useState(isOpen);
|
|
42
|
+
|
|
43
|
+
const resolvedWidth = useMemo(() => {
|
|
44
|
+
if (width === 'sm' || width === 'md' || width === 'lg') {
|
|
45
|
+
return WIDTH_MAP[width];
|
|
46
|
+
}
|
|
47
|
+
return width;
|
|
48
|
+
}, [width]);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (isOpen) {
|
|
52
|
+
setShouldRender(true);
|
|
53
|
+
setIsClosing(false);
|
|
54
|
+
} else if (shouldRender) {
|
|
55
|
+
setIsClosing(true);
|
|
56
|
+
const timer = setTimeout(() => {
|
|
57
|
+
setShouldRender(false);
|
|
58
|
+
setIsClosing(false);
|
|
59
|
+
}, CLOSE_ANIMATION_MS);
|
|
60
|
+
return () => clearTimeout(timer);
|
|
61
|
+
}
|
|
62
|
+
}, [isOpen, shouldRender]);
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (!isOpen) return;
|
|
66
|
+
const handleEscape = (e: KeyboardEvent) => {
|
|
67
|
+
if (e.key === 'Escape') onClose();
|
|
68
|
+
};
|
|
69
|
+
document.addEventListener('keydown', handleEscape);
|
|
70
|
+
return () => document.removeEventListener('keydown', handleEscape);
|
|
71
|
+
}, [isOpen, onClose]);
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (!isOpen || !shouldRender) return;
|
|
75
|
+
const id = requestAnimationFrame(() => {
|
|
76
|
+
dialogRef.current?.focus();
|
|
77
|
+
});
|
|
78
|
+
return () => cancelAnimationFrame(id);
|
|
79
|
+
}, [isOpen, shouldRender]);
|
|
80
|
+
|
|
81
|
+
if (!shouldRender) return null;
|
|
82
|
+
|
|
83
|
+
return createPortal(
|
|
84
|
+
<div
|
|
85
|
+
className={`${styles.backdrop} ${isClosing ? styles.closing : ''}`}
|
|
86
|
+
onMouseDown={(e) => {
|
|
87
|
+
if (e.target === e.currentTarget) onClose();
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
<Surface
|
|
91
|
+
ref={dialogRef}
|
|
92
|
+
background="primary"
|
|
93
|
+
elevation="floating"
|
|
94
|
+
radius="var(--dimension-radius-275, 22px)"
|
|
95
|
+
className={styles.dialog}
|
|
96
|
+
style={{ width: `min(${resolvedWidth}, calc(100vw - 32px))` }}
|
|
97
|
+
role="dialog"
|
|
98
|
+
aria-modal="true"
|
|
99
|
+
aria-labelledby={titleId}
|
|
100
|
+
tabIndex={-1}
|
|
101
|
+
>
|
|
102
|
+
<div className={styles.header}>
|
|
103
|
+
<Text id={titleId} as="h2" variant="text-title-small">
|
|
104
|
+
{title}
|
|
105
|
+
</Text>
|
|
106
|
+
{subtitle != null && (
|
|
107
|
+
<div className={styles.subtitle}>{subtitle}</div>
|
|
108
|
+
)}
|
|
109
|
+
</div>
|
|
110
|
+
<div className={`${styles.body} ${bodyClassName ?? ''}`.trim()}>
|
|
111
|
+
{children}
|
|
112
|
+
</div>
|
|
113
|
+
{footer != null && (
|
|
114
|
+
<div className={styles.footer}>{footer}</div>
|
|
115
|
+
)}
|
|
116
|
+
</Surface>
|
|
117
|
+
</div>,
|
|
118
|
+
document.body
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
Modal.displayName = 'Modal';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
.pagination {
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
gap: var(--dimension-space-025);
|
|
5
|
+
-webkit-user-select: none;
|
|
6
|
+
user-select: none;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.inactive {
|
|
10
|
+
opacity: 0.5;
|
|
11
|
+
pointer-events: none;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/* ─── Button ────────────────────────────────────────────────────────────────── */
|
|
15
|
+
|
|
16
|
+
.button {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
min-width: var(--dimension-size-300);
|
|
21
|
+
height: var(--dimension-size-300);
|
|
22
|
+
padding: 0 var(--dimension-space-050);
|
|
23
|
+
background: none;
|
|
24
|
+
border: none;
|
|
25
|
+
border-radius: var(--dimension-radius-075);
|
|
26
|
+
cursor: pointer;
|
|
27
|
+
color: var(--color-foreground-secondary);
|
|
28
|
+
transition: background-color var(--effect-motion-short-2), color var(--effect-motion-short-2);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.button:hover:not(:disabled) {
|
|
32
|
+
background-color: var(--color-interaction-hover);
|
|
33
|
+
color: var(--color-foreground-primary);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.button:active:not(:disabled) {
|
|
37
|
+
background-color: var(--color-interaction-pressed);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.button:disabled {
|
|
41
|
+
cursor: not-allowed;
|
|
42
|
+
opacity: 0.35;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.active {
|
|
46
|
+
background-color: var(--color-interaction-hover);
|
|
47
|
+
color: var(--color-foreground-primary);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* ─── Nav arrows ────────────────────────────────────────────────────────────── */
|
|
51
|
+
|
|
52
|
+
.nav {
|
|
53
|
+
font-size: 18px;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* ─── Ellipsis ──────────────────────────────────────────────────────────────── */
|
|
57
|
+
|
|
58
|
+
.ellipsis {
|
|
59
|
+
display: flex;
|
|
60
|
+
align-items: center;
|
|
61
|
+
justify-content: center;
|
|
62
|
+
min-width: var(--dimension-size-300);
|
|
63
|
+
height: var(--dimension-size-300);
|
|
64
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
3
|
+
import { Pagination } from './Pagination';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof Pagination> = {
|
|
6
|
+
title: 'Classic/Pagination',
|
|
7
|
+
component: Pagination,
|
|
8
|
+
args: {
|
|
9
|
+
inactive: false,
|
|
10
|
+
siblingCount: 1,
|
|
11
|
+
},
|
|
12
|
+
argTypes: {
|
|
13
|
+
inactive: { control: 'boolean' },
|
|
14
|
+
siblingCount: { control: { type: 'number', min: 0, max: 3 } },
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default meta;
|
|
19
|
+
type Story = StoryObj<typeof Pagination>;
|
|
20
|
+
|
|
21
|
+
const Controlled = (props: Partial<React.ComponentProps<typeof Pagination>> & { totalPages?: number }) => {
|
|
22
|
+
const total = props.totalPages ?? 10;
|
|
23
|
+
const [page, setPage] = useState(1);
|
|
24
|
+
return <Pagination page={page} totalPages={total} onPageChange={setPage} {...props} />;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const Playground: Story = {
|
|
28
|
+
render: args => <Controlled totalPages={20} {...args} />,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const Default: Story = {
|
|
32
|
+
render: () => <Controlled totalPages={10} />,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const ManyPages: Story = {
|
|
36
|
+
render: () => <Controlled totalPages={100} />,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const FewPages: Story = {
|
|
40
|
+
render: () => <Controlled totalPages={3} />,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const SinglePage: Story = {
|
|
44
|
+
render: () => <Controlled totalPages={1} />,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const Inactive: Story = {
|
|
48
|
+
render: () => (
|
|
49
|
+
<Pagination page={5} totalPages={20} onPageChange={() => {}} inactive />
|
|
50
|
+
),
|
|
51
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import React, { forwardRef, useMemo } from 'react';
|
|
2
|
+
import { cn } from '@/utils/cn';
|
|
3
|
+
import { Text } from '@/components/Text';
|
|
4
|
+
import styles from './Pagination.module.css';
|
|
5
|
+
|
|
6
|
+
export interface PaginationProps {
|
|
7
|
+
/** Current page (1-based). */
|
|
8
|
+
page: number;
|
|
9
|
+
/** Total number of pages. */
|
|
10
|
+
totalPages: number;
|
|
11
|
+
/** Called when page changes. */
|
|
12
|
+
onPageChange: (page: number) => void;
|
|
13
|
+
/** Max page buttons visible (excluding prev/next). */
|
|
14
|
+
siblingCount?: number;
|
|
15
|
+
/** Disables all interaction. */
|
|
16
|
+
inactive?: boolean;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function buildRange(start: number, end: number): (number | 'ellipsis')[] {
|
|
21
|
+
const items: (number | 'ellipsis')[] = [];
|
|
22
|
+
for (let i = start; i <= end; i++) items.push(i);
|
|
23
|
+
return items;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function buildPages(page: number, totalPages: number, siblings: number): (number | 'ellipsis')[] {
|
|
27
|
+
const totalSlots = siblings * 2 + 5; // siblings + boundaries + ellipses + current
|
|
28
|
+
|
|
29
|
+
if (totalPages <= totalSlots) return buildRange(1, totalPages);
|
|
30
|
+
|
|
31
|
+
const leftSibling = Math.max(page - siblings, 2);
|
|
32
|
+
const rightSibling = Math.min(page + siblings, totalPages - 1);
|
|
33
|
+
|
|
34
|
+
const showLeftEllipsis = leftSibling > 2;
|
|
35
|
+
const showRightEllipsis = rightSibling < totalPages - 1;
|
|
36
|
+
|
|
37
|
+
if (!showLeftEllipsis && showRightEllipsis) {
|
|
38
|
+
const left = buildRange(1, siblings * 2 + 3);
|
|
39
|
+
return [...left, 'ellipsis', totalPages];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (showLeftEllipsis && !showRightEllipsis) {
|
|
43
|
+
const right = buildRange(totalPages - (siblings * 2 + 2), totalPages);
|
|
44
|
+
return [1, 'ellipsis', ...right];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return [1, 'ellipsis', ...buildRange(leftSibling, rightSibling), 'ellipsis', totalPages];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const Pagination = forwardRef<HTMLElement, PaginationProps>(
|
|
51
|
+
({ page, totalPages, onPageChange, siblingCount = 1, inactive = false, className }, ref) => {
|
|
52
|
+
const pages = useMemo(() => buildPages(page, totalPages, siblingCount), [page, totalPages, siblingCount]);
|
|
53
|
+
|
|
54
|
+
if (totalPages <= 1) return null;
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<nav ref={ref} aria-label="Pagination" className={cn(styles.pagination, inactive && styles.inactive, className)}>
|
|
58
|
+
<button
|
|
59
|
+
type="button"
|
|
60
|
+
className={cn(styles.button, styles.nav)}
|
|
61
|
+
disabled={page <= 1 || inactive}
|
|
62
|
+
onClick={() => onPageChange(page - 1)}
|
|
63
|
+
aria-label="Previous page"
|
|
64
|
+
>
|
|
65
|
+
<Text variant="text-body-small" as="span" color="inherit">‹</Text>
|
|
66
|
+
</button>
|
|
67
|
+
|
|
68
|
+
{pages.map((item, i) =>
|
|
69
|
+
item === 'ellipsis' ? (
|
|
70
|
+
<span key={`e${i}`} className={styles.ellipsis}>
|
|
71
|
+
<Text variant="text-body-small" as="span" color="tertiary">…</Text>
|
|
72
|
+
</span>
|
|
73
|
+
) : (
|
|
74
|
+
<button
|
|
75
|
+
key={item}
|
|
76
|
+
type="button"
|
|
77
|
+
className={cn(styles.button, item === page && styles.active)}
|
|
78
|
+
onClick={() => onPageChange(item)}
|
|
79
|
+
aria-current={item === page ? 'page' : undefined}
|
|
80
|
+
disabled={inactive}
|
|
81
|
+
>
|
|
82
|
+
<Text variant={item === page ? 'text-body-small-emphasis' : 'text-body-small'} as="span" color="inherit">
|
|
83
|
+
{item}
|
|
84
|
+
</Text>
|
|
85
|
+
</button>
|
|
86
|
+
)
|
|
87
|
+
)}
|
|
88
|
+
|
|
89
|
+
<button
|
|
90
|
+
type="button"
|
|
91
|
+
className={cn(styles.button, styles.nav)}
|
|
92
|
+
disabled={page >= totalPages || inactive}
|
|
93
|
+
onClick={() => onPageChange(page + 1)}
|
|
94
|
+
aria-label="Next page"
|
|
95
|
+
>
|
|
96
|
+
<Text variant="text-body-small" as="span" color="inherit">›</Text>
|
|
97
|
+
</button>
|
|
98
|
+
</nav>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
Pagination.displayName = 'Pagination';
|