@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,61 @@
|
|
|
1
|
+
.group {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: var(--dimension-space-025);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.horizontal {
|
|
8
|
+
flex-direction: row;
|
|
9
|
+
gap: var(--dimension-space-100);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/* ─── Radio item ────────────────────────────────────────────────────────────── */
|
|
13
|
+
|
|
14
|
+
.radio {
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
gap: var(--dimension-space-050);
|
|
18
|
+
padding: var(--dimension-space-075);
|
|
19
|
+
height: var(--dimension-size-400);
|
|
20
|
+
box-sizing: border-box;
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
-webkit-user-select: none;
|
|
23
|
+
user-select: none;
|
|
24
|
+
border-radius: var(--dimension-radius-075);
|
|
25
|
+
transition: background-color var(--effect-motion-short-2);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.radio:hover { background-color: var(--color-interaction-hover); }
|
|
29
|
+
.radio:active { background-color: var(--color-interaction-pressed); }
|
|
30
|
+
|
|
31
|
+
.inactive {
|
|
32
|
+
cursor: not-allowed;
|
|
33
|
+
opacity: 0.5;
|
|
34
|
+
pointer-events: none;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* ─── Circle indicator ──────────────────────────────────────────────────────── */
|
|
38
|
+
|
|
39
|
+
.circle {
|
|
40
|
+
width: 20px;
|
|
41
|
+
height: 20px;
|
|
42
|
+
border: 1.5px solid var(--color-foreground-secondary);
|
|
43
|
+
border-radius: var(--dimension-radius-half);
|
|
44
|
+
display: flex;
|
|
45
|
+
align-items: center;
|
|
46
|
+
justify-content: center;
|
|
47
|
+
flex-shrink: 0;
|
|
48
|
+
transition: all var(--effect-motion-short-2);
|
|
49
|
+
box-sizing: border-box;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.circleChecked {
|
|
53
|
+
border-color: var(--color-foreground-primary);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.dot {
|
|
57
|
+
width: 10px;
|
|
58
|
+
height: 10px;
|
|
59
|
+
border-radius: var(--dimension-radius-half);
|
|
60
|
+
background-color: var(--color-foreground-primary);
|
|
61
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
3
|
+
import { RadioGroup } from './Radio';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof RadioGroup> = {
|
|
6
|
+
title: 'Classic/RadioGroup',
|
|
7
|
+
component: RadioGroup,
|
|
8
|
+
args: {
|
|
9
|
+
direction: 'vertical',
|
|
10
|
+
inactive: false,
|
|
11
|
+
},
|
|
12
|
+
argTypes: {
|
|
13
|
+
direction: { control: 'select', options: ['vertical', 'horizontal'] },
|
|
14
|
+
inactive: { control: 'boolean' },
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default meta;
|
|
19
|
+
type Story = StoryObj<typeof RadioGroup>;
|
|
20
|
+
|
|
21
|
+
const OPTIONS = [
|
|
22
|
+
{ label: 'Option A', value: 'a' },
|
|
23
|
+
{ label: 'Option B', value: 'b' },
|
|
24
|
+
{ label: 'Option C', value: 'c' },
|
|
25
|
+
{ label: 'Option D', value: 'd' },
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const Controlled = (props: Partial<React.ComponentProps<typeof RadioGroup>>) => {
|
|
29
|
+
const [value, setValue] = useState('b');
|
|
30
|
+
return (
|
|
31
|
+
<RadioGroup
|
|
32
|
+
value={value}
|
|
33
|
+
onChange={setValue}
|
|
34
|
+
options={OPTIONS}
|
|
35
|
+
aria-label="Demo radio group"
|
|
36
|
+
{...props}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const Playground: Story = {
|
|
42
|
+
render: args => <Controlled {...args} />,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// ─── Matrix ───────────────────────────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
const col: React.CSSProperties = { display: 'flex', flexDirection: 'column', gap: 24 };
|
|
48
|
+
const section = (text: string) => (
|
|
49
|
+
<div style={{ fontSize: 11, fontWeight: 600, letterSpacing: '0.05em', textTransform: 'uppercase', color: '#555', marginTop: 8 }}>
|
|
50
|
+
{text}
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export const Matrix: Story = {
|
|
55
|
+
parameters: { layout: 'padded' },
|
|
56
|
+
render: () => (
|
|
57
|
+
<div style={col}>
|
|
58
|
+
{section('Vertical (default)')}
|
|
59
|
+
<Controlled />
|
|
60
|
+
{section('Horizontal')}
|
|
61
|
+
<Controlled direction="horizontal" />
|
|
62
|
+
{section('Inactive')}
|
|
63
|
+
<RadioGroup
|
|
64
|
+
value="b"
|
|
65
|
+
onChange={() => {}}
|
|
66
|
+
options={OPTIONS}
|
|
67
|
+
inactive
|
|
68
|
+
aria-label="Disabled group"
|
|
69
|
+
/>
|
|
70
|
+
{section('With inactive individual option')}
|
|
71
|
+
<Controlled
|
|
72
|
+
options={[
|
|
73
|
+
{ label: 'Available', value: 'a' },
|
|
74
|
+
{ label: 'Available', value: 'b' },
|
|
75
|
+
{ label: 'Unavailable', value: 'c', inactive: true },
|
|
76
|
+
{ label: 'Available', value: 'd' },
|
|
77
|
+
]}
|
|
78
|
+
/>
|
|
79
|
+
</div>
|
|
80
|
+
),
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const Default: Story = {
|
|
84
|
+
render: () => <Controlled />,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const Horizontal: Story = {
|
|
88
|
+
render: () => <Controlled direction="horizontal" />,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const Inactive: Story = {
|
|
92
|
+
render: () => (
|
|
93
|
+
<RadioGroup
|
|
94
|
+
value="a"
|
|
95
|
+
onChange={() => {}}
|
|
96
|
+
options={OPTIONS}
|
|
97
|
+
inactive
|
|
98
|
+
aria-label="Disabled group"
|
|
99
|
+
/>
|
|
100
|
+
),
|
|
101
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { cn } from '@/utils/cn';
|
|
3
|
+
import { Text } from '@/components/Text';
|
|
4
|
+
import styles from './Radio.module.css';
|
|
5
|
+
|
|
6
|
+
export interface RadioOption {
|
|
7
|
+
label: string;
|
|
8
|
+
value: string;
|
|
9
|
+
inactive?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface RadioGroupProps {
|
|
13
|
+
/** Currently selected value. */
|
|
14
|
+
value: string;
|
|
15
|
+
/** Called when selection changes. */
|
|
16
|
+
onChange: (value: string) => void;
|
|
17
|
+
/** Radio options to render. */
|
|
18
|
+
options: RadioOption[];
|
|
19
|
+
/** Group label for accessibility. */
|
|
20
|
+
'aria-label'?: string;
|
|
21
|
+
/** Layout direction. */
|
|
22
|
+
direction?: 'vertical' | 'horizontal';
|
|
23
|
+
/** Disables the entire group. */
|
|
24
|
+
inactive?: boolean;
|
|
25
|
+
className?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const RadioGroup = forwardRef<HTMLDivElement, RadioGroupProps>(
|
|
29
|
+
(
|
|
30
|
+
{
|
|
31
|
+
value,
|
|
32
|
+
onChange,
|
|
33
|
+
options,
|
|
34
|
+
'aria-label': ariaLabel,
|
|
35
|
+
direction = 'vertical',
|
|
36
|
+
inactive = false,
|
|
37
|
+
className,
|
|
38
|
+
},
|
|
39
|
+
ref
|
|
40
|
+
) => (
|
|
41
|
+
<div
|
|
42
|
+
ref={ref}
|
|
43
|
+
role="radiogroup"
|
|
44
|
+
aria-label={ariaLabel}
|
|
45
|
+
className={cn(
|
|
46
|
+
styles.group,
|
|
47
|
+
direction === 'horizontal' && styles.horizontal,
|
|
48
|
+
className
|
|
49
|
+
)}
|
|
50
|
+
>
|
|
51
|
+
{options.map(opt => (
|
|
52
|
+
<RadioItem
|
|
53
|
+
key={opt.value}
|
|
54
|
+
label={opt.label}
|
|
55
|
+
checked={value === opt.value}
|
|
56
|
+
inactive={inactive || opt.inactive}
|
|
57
|
+
onChange={() => onChange(opt.value)}
|
|
58
|
+
/>
|
|
59
|
+
))}
|
|
60
|
+
</div>
|
|
61
|
+
)
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
RadioGroup.displayName = 'RadioGroup';
|
|
65
|
+
|
|
66
|
+
/* ─── Individual Radio Item ─────────────────────────────────────────────────── */
|
|
67
|
+
|
|
68
|
+
export interface RadioItemProps {
|
|
69
|
+
label: string;
|
|
70
|
+
checked?: boolean;
|
|
71
|
+
onChange?: () => void;
|
|
72
|
+
inactive?: boolean;
|
|
73
|
+
className?: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const RadioItem = forwardRef<HTMLDivElement, RadioItemProps>(
|
|
77
|
+
({ label, checked = false, onChange, inactive = false, className }, ref) => {
|
|
78
|
+
const handleClick = () => {
|
|
79
|
+
if (!inactive && !checked) onChange?.();
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div
|
|
84
|
+
ref={ref}
|
|
85
|
+
role="radio"
|
|
86
|
+
aria-checked={checked}
|
|
87
|
+
tabIndex={inactive ? -1 : 0}
|
|
88
|
+
className={cn(styles.radio, inactive && styles.inactive, className)}
|
|
89
|
+
onClick={handleClick}
|
|
90
|
+
onKeyDown={e => {
|
|
91
|
+
if (e.key === ' ' || e.key === 'Enter') {
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
handleClick();
|
|
94
|
+
}
|
|
95
|
+
}}
|
|
96
|
+
>
|
|
97
|
+
<span className={cn(styles.circle, checked && styles.circleChecked)}>
|
|
98
|
+
{checked && <span className={styles.dot} />}
|
|
99
|
+
</span>
|
|
100
|
+
<Text variant="text-body-medium" as="span" color="inherit">
|
|
101
|
+
{label}
|
|
102
|
+
</Text>
|
|
103
|
+
</div>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
RadioItem.displayName = 'RadioItem';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
.container {
|
|
2
|
+
position: relative;
|
|
3
|
+
width: 100%;
|
|
4
|
+
height: 100%;
|
|
5
|
+
overflow: hidden;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.content {
|
|
9
|
+
width: 100%;
|
|
10
|
+
height: 100%;
|
|
11
|
+
min-height: 0;
|
|
12
|
+
overflow-y: auto;
|
|
13
|
+
overflow-x: auto;
|
|
14
|
+
scrollbar-width: none;
|
|
15
|
+
-ms-overflow-style: none;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.content::-webkit-scrollbar { display: none; }
|
|
19
|
+
|
|
20
|
+
.track {
|
|
21
|
+
position: absolute;
|
|
22
|
+
top: 0; right: 0; bottom: 0;
|
|
23
|
+
width: var(--dimension-size-050, 4px);
|
|
24
|
+
pointer-events: none;
|
|
25
|
+
z-index: 10;
|
|
26
|
+
opacity: 0;
|
|
27
|
+
transition: opacity var(--effect-motion-short-2);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.container[data-show-track='true'] .track {
|
|
31
|
+
opacity: 1;
|
|
32
|
+
pointer-events: auto;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.thumb {
|
|
36
|
+
position: absolute;
|
|
37
|
+
right: 0;
|
|
38
|
+
width: var(--dimension-size-050, 4px);
|
|
39
|
+
cursor: grab;
|
|
40
|
+
border-radius: 0;
|
|
41
|
+
background-color: var(--color-foreground-quaternary);
|
|
42
|
+
transition: background-color var(--effect-motion-short-2);
|
|
43
|
+
-webkit-user-select: none;
|
|
44
|
+
user-select: none;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.thumb:active { cursor: grabbing; }
|
|
48
|
+
|
|
49
|
+
.trackHorizontal {
|
|
50
|
+
position: absolute;
|
|
51
|
+
left: 0; right: 0; bottom: 0;
|
|
52
|
+
height: var(--dimension-size-050, 4px);
|
|
53
|
+
pointer-events: none;
|
|
54
|
+
z-index: 10;
|
|
55
|
+
opacity: 0;
|
|
56
|
+
transition: opacity var(--effect-motion-short-2);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.container[data-show-track='true'] .trackHorizontal {
|
|
60
|
+
opacity: 1;
|
|
61
|
+
pointer-events: auto;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.thumbHorizontal {
|
|
65
|
+
position: absolute;
|
|
66
|
+
bottom: 0;
|
|
67
|
+
height: var(--dimension-size-050, 4px);
|
|
68
|
+
cursor: grab;
|
|
69
|
+
border-radius: 0;
|
|
70
|
+
background-color: var(--color-foreground-quaternary);
|
|
71
|
+
transition: background-color var(--effect-motion-short-2);
|
|
72
|
+
-webkit-user-select: none;
|
|
73
|
+
user-select: none;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.thumbHorizontal:active { cursor: grabbing; }
|
|
77
|
+
|
|
78
|
+
.thick .track { width: var(--dimension-size-100, 8px); }
|
|
79
|
+
.thick .thumb { width: var(--dimension-size-100, 8px); }
|
|
80
|
+
.thick .trackHorizontal { height: var(--dimension-size-100, 8px); }
|
|
81
|
+
.thick .thumbHorizontal { height: var(--dimension-size-100, 8px); }
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { Scrollbar } from './Scrollbar';
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof Scrollbar> = {
|
|
5
|
+
title: 'Layout/Scrollbar',
|
|
6
|
+
component: Scrollbar,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default meta;
|
|
10
|
+
type Story = StoryObj<typeof Scrollbar>;
|
|
11
|
+
|
|
12
|
+
const longContent = Array.from({ length: 30 }, (_, i) => (
|
|
13
|
+
<div key={i} style={{ padding: '8px 12px', borderBottom: '1px solid var(--color-border-tertiary)' }}>
|
|
14
|
+
Item {i + 1}
|
|
15
|
+
</div>
|
|
16
|
+
));
|
|
17
|
+
|
|
18
|
+
export const Default: Story = {
|
|
19
|
+
render: () => (
|
|
20
|
+
<div style={{ height: 300, width: 260, padding: 24 }}>
|
|
21
|
+
<Scrollbar>
|
|
22
|
+
{longContent}
|
|
23
|
+
</Scrollbar>
|
|
24
|
+
</div>
|
|
25
|
+
),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const Thick: Story = {
|
|
29
|
+
render: () => (
|
|
30
|
+
<div style={{ height: 300, width: 260, padding: 24 }}>
|
|
31
|
+
<Scrollbar variant="thick">
|
|
32
|
+
{longContent}
|
|
33
|
+
</Scrollbar>
|
|
34
|
+
</div>
|
|
35
|
+
),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const ShowTrackOnHover: Story = {
|
|
39
|
+
render: () => (
|
|
40
|
+
<div style={{ height: 300, width: 260, padding: 24 }}>
|
|
41
|
+
<Scrollbar showTrackOnHover>
|
|
42
|
+
{longContent}
|
|
43
|
+
</Scrollbar>
|
|
44
|
+
</div>
|
|
45
|
+
),
|
|
46
|
+
};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import React, { useRef, useEffect, useState, useCallback } from 'react';
|
|
2
|
+
import { cn } from '@/utils/cn';
|
|
3
|
+
import styles from './Scrollbar.module.css';
|
|
4
|
+
|
|
5
|
+
export type ScrollbarVariant = 'default' | 'thick';
|
|
6
|
+
|
|
7
|
+
export interface ScrollbarProps {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
className?: string;
|
|
10
|
+
variant?: ScrollbarVariant;
|
|
11
|
+
showTrackOnHover?: boolean;
|
|
12
|
+
onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;
|
|
13
|
+
fadeOverlay?: React.ReactNode;
|
|
14
|
+
contentRef?: React.RefObject<HTMLDivElement>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const Scrollbar: React.FC<ScrollbarProps> = ({
|
|
18
|
+
children,
|
|
19
|
+
className,
|
|
20
|
+
variant = 'default',
|
|
21
|
+
showTrackOnHover = true,
|
|
22
|
+
onScroll,
|
|
23
|
+
fadeOverlay,
|
|
24
|
+
contentRef: externalContentRef,
|
|
25
|
+
}) => {
|
|
26
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
27
|
+
const internalContentRef = useRef<HTMLDivElement>(null);
|
|
28
|
+
const contentRef = externalContentRef || internalContentRef;
|
|
29
|
+
const thumbRef = useRef<HTMLDivElement>(null);
|
|
30
|
+
const thumbHRef = useRef<HTMLDivElement>(null);
|
|
31
|
+
const [thumbHeight, setThumbHeight] = useState(0);
|
|
32
|
+
const [thumbTop, setThumbTop] = useState(0);
|
|
33
|
+
const [thumbWidth, setThumbWidth] = useState(0);
|
|
34
|
+
const [thumbLeft, setThumbLeft] = useState(0);
|
|
35
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
36
|
+
const [isDraggingH, setIsDraggingH] = useState(false);
|
|
37
|
+
const [isPointerInside, setIsPointerInside] = useState(false);
|
|
38
|
+
const dragStartY = useRef(0);
|
|
39
|
+
const dragStartScrollTop = useRef(0);
|
|
40
|
+
const dragStartX = useRef(0);
|
|
41
|
+
const dragStartScrollLeft = useRef(0);
|
|
42
|
+
|
|
43
|
+
const handleMouseEnter = useCallback(() => {
|
|
44
|
+
if (showTrackOnHover) setIsPointerInside(true);
|
|
45
|
+
}, [showTrackOnHover]);
|
|
46
|
+
|
|
47
|
+
const handleMouseLeave = useCallback(() => {
|
|
48
|
+
setIsPointerInside(false);
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
const updateThumb = useCallback(() => {
|
|
52
|
+
const container = containerRef.current;
|
|
53
|
+
const content = contentRef.current;
|
|
54
|
+
if (!container || !content) return;
|
|
55
|
+
|
|
56
|
+
const containerHeight = container.clientHeight;
|
|
57
|
+
const containerWidth = container.clientWidth;
|
|
58
|
+
const contentHeight = content.scrollHeight;
|
|
59
|
+
const contentWidth = content.scrollWidth;
|
|
60
|
+
const scrollTop = content.scrollTop;
|
|
61
|
+
const scrollLeft = content.scrollLeft;
|
|
62
|
+
|
|
63
|
+
if (contentHeight <= containerHeight) {
|
|
64
|
+
setThumbHeight(0);
|
|
65
|
+
} else {
|
|
66
|
+
const ratio = containerHeight / contentHeight;
|
|
67
|
+
const h = Math.max(20, containerHeight * ratio);
|
|
68
|
+
setThumbHeight(h);
|
|
69
|
+
setThumbTop((scrollTop / (contentHeight - containerHeight)) * (containerHeight - h));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (contentWidth <= containerWidth) {
|
|
73
|
+
setThumbWidth(0);
|
|
74
|
+
} else {
|
|
75
|
+
const ratio = containerWidth / contentWidth;
|
|
76
|
+
const w = Math.max(20, containerWidth * ratio);
|
|
77
|
+
setThumbWidth(w);
|
|
78
|
+
setThumbLeft((scrollLeft / (contentWidth - containerWidth)) * (containerWidth - w));
|
|
79
|
+
}
|
|
80
|
+
}, [contentRef]);
|
|
81
|
+
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
const content = contentRef.current;
|
|
84
|
+
if (!content) return;
|
|
85
|
+
const handleScroll = (e: Event) => {
|
|
86
|
+
updateThumb();
|
|
87
|
+
if (onScroll) onScroll(e as unknown as React.UIEvent<HTMLDivElement>);
|
|
88
|
+
};
|
|
89
|
+
content.addEventListener('scroll', handleScroll);
|
|
90
|
+
return () => content.removeEventListener('scroll', handleScroll);
|
|
91
|
+
}, [updateThumb, onScroll, contentRef]);
|
|
92
|
+
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
const content = contentRef.current;
|
|
95
|
+
if (!content) return;
|
|
96
|
+
const handleResize = () => updateThumb();
|
|
97
|
+
window.addEventListener('resize', handleResize);
|
|
98
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
99
|
+
const observer = new ResizeObserver(handleResize);
|
|
100
|
+
observer.observe(content);
|
|
101
|
+
return () => { window.removeEventListener('resize', handleResize); observer.disconnect(); };
|
|
102
|
+
}
|
|
103
|
+
return () => window.removeEventListener('resize', handleResize);
|
|
104
|
+
}, [updateThumb, contentRef]);
|
|
105
|
+
|
|
106
|
+
useEffect(() => { updateThumb(); }, [updateThumb, children]);
|
|
107
|
+
|
|
108
|
+
const handleThumbMouseDown = useCallback((e: React.MouseEvent) => {
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
e.stopPropagation();
|
|
111
|
+
const content = contentRef.current;
|
|
112
|
+
if (!content) return;
|
|
113
|
+
setIsDragging(true);
|
|
114
|
+
dragStartY.current = e.clientY;
|
|
115
|
+
dragStartScrollTop.current = content.scrollTop;
|
|
116
|
+
const handleMouseMove = (e: MouseEvent) => {
|
|
117
|
+
const container = containerRef.current;
|
|
118
|
+
if (!container || !content) return;
|
|
119
|
+
const deltaY = e.clientY - dragStartY.current;
|
|
120
|
+
const scrollableHeight = content.scrollHeight - container.clientHeight;
|
|
121
|
+
const scrollRatio = scrollableHeight / (container.clientHeight - thumbHeight);
|
|
122
|
+
content.scrollTop = Math.max(0, Math.min(scrollableHeight, dragStartScrollTop.current + deltaY * scrollRatio));
|
|
123
|
+
};
|
|
124
|
+
const handleMouseUp = () => {
|
|
125
|
+
setIsDragging(false);
|
|
126
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
127
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
128
|
+
};
|
|
129
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
130
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
131
|
+
}, [thumbHeight, contentRef]);
|
|
132
|
+
|
|
133
|
+
const handleThumbHMouseDown = useCallback((e: React.MouseEvent) => {
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
e.stopPropagation();
|
|
136
|
+
const content = contentRef.current;
|
|
137
|
+
if (!content) return;
|
|
138
|
+
setIsDraggingH(true);
|
|
139
|
+
dragStartX.current = e.clientX;
|
|
140
|
+
dragStartScrollLeft.current = content.scrollLeft;
|
|
141
|
+
const handleMouseMove = (e: MouseEvent) => {
|
|
142
|
+
const container = containerRef.current;
|
|
143
|
+
if (!container || !content) return;
|
|
144
|
+
const deltaX = e.clientX - dragStartX.current;
|
|
145
|
+
const scrollableWidth = content.scrollWidth - container.clientWidth;
|
|
146
|
+
const scrollRatio = scrollableWidth / (container.clientWidth - thumbWidth);
|
|
147
|
+
content.scrollLeft = Math.max(0, Math.min(scrollableWidth, dragStartScrollLeft.current + deltaX * scrollRatio));
|
|
148
|
+
};
|
|
149
|
+
const handleMouseUp = () => {
|
|
150
|
+
setIsDraggingH(false);
|
|
151
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
152
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
153
|
+
};
|
|
154
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
155
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
156
|
+
}, [thumbWidth, contentRef]);
|
|
157
|
+
|
|
158
|
+
const showThumb = thumbHeight > 0;
|
|
159
|
+
const showThumbH = thumbWidth > 0;
|
|
160
|
+
const showTrack = showTrackOnHover && (isPointerInside || isDragging || isDraggingH);
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<div
|
|
164
|
+
ref={containerRef}
|
|
165
|
+
className={cn(styles.container, variant === 'thick' && styles.thick, className)}
|
|
166
|
+
onMouseEnter={handleMouseEnter}
|
|
167
|
+
onMouseLeave={handleMouseLeave}
|
|
168
|
+
data-dragging={isDragging || isDraggingH}
|
|
169
|
+
data-show-track={showTrack ? 'true' : 'false'}
|
|
170
|
+
>
|
|
171
|
+
<div ref={contentRef} className={styles.content}>{children}</div>
|
|
172
|
+
{fadeOverlay}
|
|
173
|
+
{showThumb && (
|
|
174
|
+
<div className={styles.track}>
|
|
175
|
+
<div ref={thumbRef} className={styles.thumb} style={{ height: `${thumbHeight}px`, top: `${thumbTop}px` }} onMouseDown={handleThumbMouseDown} />
|
|
176
|
+
</div>
|
|
177
|
+
)}
|
|
178
|
+
{showThumbH && (
|
|
179
|
+
<div className={styles.trackHorizontal}>
|
|
180
|
+
<div ref={thumbHRef} className={styles.thumbHorizontal} style={{ width: `${thumbWidth}px`, left: `${thumbLeft}px` }} onMouseDown={handleThumbHMouseDown} />
|
|
181
|
+
</div>
|
|
182
|
+
)}
|
|
183
|
+
</div>
|
|
184
|
+
);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
Scrollbar.displayName = 'Scrollbar';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
.selectWrapper {
|
|
2
|
+
width: 100%;
|
|
3
|
+
position: relative;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.selectButton {
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
justify-content: space-between;
|
|
10
|
+
width: 100%;
|
|
11
|
+
height: var(--dimension-size-400);
|
|
12
|
+
padding: 0 var(--dimension-space-075);
|
|
13
|
+
gap: var(--dimension-space-050);
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
-webkit-user-select: none;
|
|
16
|
+
user-select: none;
|
|
17
|
+
border: none;
|
|
18
|
+
outline: none;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.selectButton:disabled {
|
|
22
|
+
opacity: 0.5;
|
|
23
|
+
cursor: not-allowed;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.chevron {
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
color: var(--color-foreground-secondary);
|
|
30
|
+
flex-shrink: 0;
|
|
31
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
3
|
+
import { Select } from './Select';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof Select> = {
|
|
6
|
+
title: 'Components/Select',
|
|
7
|
+
component: Select,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default meta;
|
|
11
|
+
type Story = StoryObj<typeof Select>;
|
|
12
|
+
|
|
13
|
+
const fruitOptions = [
|
|
14
|
+
{ value: 'apple', label: 'Apple' },
|
|
15
|
+
{ value: 'banana', label: 'Banana' },
|
|
16
|
+
{ value: 'cherry', label: 'Cherry' },
|
|
17
|
+
{ value: 'date', label: 'Date' },
|
|
18
|
+
{ value: 'elderberry', label: 'Elderberry' },
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
export const Default: Story = {
|
|
22
|
+
render: () => {
|
|
23
|
+
const [value, setValue] = useState<string | number>('');
|
|
24
|
+
return (
|
|
25
|
+
<div style={{ width: 260, padding: 24 }}>
|
|
26
|
+
<Select
|
|
27
|
+
value={value}
|
|
28
|
+
onChange={setValue}
|
|
29
|
+
options={fruitOptions}
|
|
30
|
+
placeholder="Select a fruit"
|
|
31
|
+
/>
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const WithValue: Story = {
|
|
38
|
+
render: () => {
|
|
39
|
+
const [value, setValue] = useState<string | number>('cherry');
|
|
40
|
+
return (
|
|
41
|
+
<div style={{ width: 260, padding: 24 }}>
|
|
42
|
+
<Select value={value} onChange={setValue} options={fruitOptions} />
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const Inactive: Story = {
|
|
49
|
+
render: () => (
|
|
50
|
+
<div style={{ width: 260, padding: 24 }}>
|
|
51
|
+
<Select
|
|
52
|
+
value="banana"
|
|
53
|
+
onChange={() => {}}
|
|
54
|
+
options={fruitOptions}
|
|
55
|
+
inactive
|
|
56
|
+
/>
|
|
57
|
+
</div>
|
|
58
|
+
),
|
|
59
|
+
};
|