@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,89 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
3
|
+
import { Skeleton } from './Skeleton';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof Skeleton> = {
|
|
6
|
+
title: 'Classic/Skeleton',
|
|
7
|
+
component: Skeleton,
|
|
8
|
+
args: {
|
|
9
|
+
variant: 'text',
|
|
10
|
+
animate: true,
|
|
11
|
+
},
|
|
12
|
+
argTypes: {
|
|
13
|
+
variant: { control: 'select', options: ['text', 'circular', 'rectangular'] },
|
|
14
|
+
animate: { control: 'boolean' },
|
|
15
|
+
width: { control: 'text' },
|
|
16
|
+
height: { control: 'text' },
|
|
17
|
+
lines: { control: { type: 'number', min: 1, max: 10 } },
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default meta;
|
|
22
|
+
type Story = StoryObj<typeof Skeleton>;
|
|
23
|
+
|
|
24
|
+
export const Playground: Story = {};
|
|
25
|
+
|
|
26
|
+
// ─── Variants ─────────────────────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
const col: React.CSSProperties = { display: 'flex', flexDirection: 'column', gap: 24 };
|
|
29
|
+
const row: React.CSSProperties = { display: 'flex', gap: 16, alignItems: 'center' };
|
|
30
|
+
const section = (text: string) => (
|
|
31
|
+
<div style={{ fontSize: 11, fontWeight: 600, letterSpacing: '0.05em', textTransform: 'uppercase', color: '#555' }}>
|
|
32
|
+
{text}
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export const Variants: Story = {
|
|
37
|
+
parameters: { layout: 'padded' },
|
|
38
|
+
render: () => (
|
|
39
|
+
<div style={col}>
|
|
40
|
+
{section('Text (single line)')}
|
|
41
|
+
<Skeleton variant="text" width={240} />
|
|
42
|
+
{section('Text (multiple lines)')}
|
|
43
|
+
<Skeleton variant="text" lines={4} width={320} />
|
|
44
|
+
{section('Circular')}
|
|
45
|
+
<div style={row}>
|
|
46
|
+
<Skeleton variant="circular" width={32} height={32} />
|
|
47
|
+
<Skeleton variant="circular" width={40} height={40} />
|
|
48
|
+
<Skeleton variant="circular" width={56} height={56} />
|
|
49
|
+
</div>
|
|
50
|
+
{section('Rectangular')}
|
|
51
|
+
<Skeleton variant="rectangular" width={320} height={120} />
|
|
52
|
+
</div>
|
|
53
|
+
),
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const CardSkeleton: Story = {
|
|
57
|
+
render: () => (
|
|
58
|
+
<div style={{ display: 'flex', gap: 12, padding: 16, border: '1px solid var(--color-border-secondary)', borderRadius: 12, width: 320 }}>
|
|
59
|
+
<Skeleton variant="circular" width={48} height={48} />
|
|
60
|
+
<div style={{ flex: 1, display: 'flex', flexDirection: 'column', gap: 8 }}>
|
|
61
|
+
<Skeleton variant="text" width="60%" />
|
|
62
|
+
<Skeleton variant="text" lines={2} />
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const TableSkeleton: Story = {
|
|
69
|
+
render: () => (
|
|
70
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 12, width: 400 }}>
|
|
71
|
+
{Array.from({ length: 5 }, (_, i) => (
|
|
72
|
+
<div key={i} style={{ display: 'flex', gap: 16, alignItems: 'center' }}>
|
|
73
|
+
<Skeleton variant="text" width={120} />
|
|
74
|
+
<Skeleton variant="text" width={80} />
|
|
75
|
+
<Skeleton variant="text" width={160} />
|
|
76
|
+
</div>
|
|
77
|
+
))}
|
|
78
|
+
</div>
|
|
79
|
+
),
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const NoAnimation: Story = {
|
|
83
|
+
render: () => (
|
|
84
|
+
<div style={col}>
|
|
85
|
+
<Skeleton variant="text" width={200} animate={false} />
|
|
86
|
+
<Skeleton variant="rectangular" width={200} height={60} animate={false} />
|
|
87
|
+
</div>
|
|
88
|
+
),
|
|
89
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { cn } from '@/utils/cn';
|
|
3
|
+
import styles from './Skeleton.module.css';
|
|
4
|
+
|
|
5
|
+
export type SkeletonVariant = 'text' | 'circular' | 'rectangular';
|
|
6
|
+
|
|
7
|
+
export interface SkeletonProps {
|
|
8
|
+
/** Shape of the skeleton. */
|
|
9
|
+
variant?: SkeletonVariant;
|
|
10
|
+
/** Width (CSS value). */
|
|
11
|
+
width?: string | number;
|
|
12
|
+
/** Height (CSS value). */
|
|
13
|
+
height?: string | number;
|
|
14
|
+
/** Number of text lines to render. Only applies to 'text' variant. */
|
|
15
|
+
lines?: number;
|
|
16
|
+
/** Whether to animate the shimmer. */
|
|
17
|
+
animate?: boolean;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const Skeleton = forwardRef<HTMLDivElement, SkeletonProps>(
|
|
22
|
+
(
|
|
23
|
+
{
|
|
24
|
+
variant = 'text',
|
|
25
|
+
width,
|
|
26
|
+
height,
|
|
27
|
+
lines = 1,
|
|
28
|
+
animate = true,
|
|
29
|
+
className,
|
|
30
|
+
},
|
|
31
|
+
ref
|
|
32
|
+
) => {
|
|
33
|
+
if (variant === 'text' && lines > 1) {
|
|
34
|
+
return (
|
|
35
|
+
<div ref={ref} className={cn(styles.textGroup, className)} style={{ width }}>
|
|
36
|
+
{Array.from({ length: lines }, (_, i) => (
|
|
37
|
+
<div
|
|
38
|
+
key={i}
|
|
39
|
+
className={cn(styles.skeleton, styles.text, animate && styles.animate)}
|
|
40
|
+
style={{
|
|
41
|
+
width: i === lines - 1 ? '60%' : '100%',
|
|
42
|
+
height,
|
|
43
|
+
}}
|
|
44
|
+
/>
|
|
45
|
+
))}
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div
|
|
52
|
+
ref={ref}
|
|
53
|
+
className={cn(
|
|
54
|
+
styles.skeleton,
|
|
55
|
+
styles[variant],
|
|
56
|
+
animate && styles.animate,
|
|
57
|
+
className
|
|
58
|
+
)}
|
|
59
|
+
style={{ width, height }}
|
|
60
|
+
aria-hidden="true"
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
Skeleton.displayName = 'Skeleton';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
.field { display: flex; flex-direction: column; gap: var(--dimension-space-050); width: 100%; }
|
|
2
|
+
.labelRow { display: flex; align-items: baseline; justify-content: space-between; gap: var(--dimension-space-050); }
|
|
3
|
+
|
|
4
|
+
.track {
|
|
5
|
+
position: relative; width: 100%; height: var(--dimension-size-400);
|
|
6
|
+
padding: 0 var(--dimension-space-025); border-radius: var(--dimension-radius-075); cursor: pointer; -webkit-user-select: none;
|
|
7
|
+
user-select: none;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.trackInner {
|
|
11
|
+
position: absolute; inset: 0; border-radius: inherit;
|
|
12
|
+
background-color: var(--color-background-primary);
|
|
13
|
+
box-shadow: var(--effect-elevation-depressed-sm); pointer-events: none; z-index: 1;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.fillTrack { position: absolute; top: var(--dimension-space-025); right: 0; bottom: var(--dimension-space-025); left: 0; z-index: 1; }
|
|
17
|
+
|
|
18
|
+
.fill {
|
|
19
|
+
position: absolute; left: var(--dimension-space-025); top: 0; bottom: 0;
|
|
20
|
+
width: max(0px, calc((var(--slider-pct, 0) / 100) * (100% - var(--dimension-size-150)) - var(--dimension-space-025)));
|
|
21
|
+
background-color: var(--color-background-bold-brand);
|
|
22
|
+
box-shadow: var(--effect-elevation-elevated-sm);
|
|
23
|
+
border-radius: var(--dimension-radius-050);
|
|
24
|
+
transition: opacity var(--effect-motion-short-2);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.trackAtMin .fill { opacity: 0; }
|
|
28
|
+
|
|
29
|
+
.thumb {
|
|
30
|
+
position: absolute; top: 0; bottom: 0;
|
|
31
|
+
left: calc((var(--slider-pct, 0) / 100) * (100% - var(--dimension-size-150)));
|
|
32
|
+
width: var(--dimension-size-150); padding: var(--dimension-space-025);
|
|
33
|
+
box-sizing: border-box; pointer-events: none; z-index: 2;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.thumb::before {
|
|
37
|
+
content: ''; position: absolute; inset: var(--dimension-space-025);
|
|
38
|
+
background-color: var(--color-background-primary);
|
|
39
|
+
box-shadow: var(--effect-elevation-elevated-sm);
|
|
40
|
+
border-radius: var(--dimension-radius-050);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.thumb::after {
|
|
44
|
+
content: ''; position: absolute; inset: var(--dimension-space-025);
|
|
45
|
+
background-color: transparent; border-radius: var(--dimension-radius-050);
|
|
46
|
+
transition: var(--effect-transition-interaction-background-instant);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.track:hover:not(.trackInactive) .thumb::after { background-color: var(--color-interaction-hover); }
|
|
50
|
+
.track:active:not(.trackInactive) .thumb::after { background-color: var(--color-interaction-pressed); }
|
|
51
|
+
|
|
52
|
+
.trackInactive { cursor: not-allowed; opacity: 0.5; }
|
|
53
|
+
|
|
54
|
+
.input {
|
|
55
|
+
position: absolute; inset: 0; width: 100%; height: 100%;
|
|
56
|
+
margin: 0; padding: 0; opacity: 0; cursor: pointer;
|
|
57
|
+
-webkit-appearance: none; appearance: none; outline: none; z-index: 3;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.input:disabled { cursor: not-allowed; }
|
|
61
|
+
.input:hover { cursor: grab; }
|
|
62
|
+
.input:active { cursor: grabbing; }
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
3
|
+
import { Slider } from './Slider';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof Slider> = {
|
|
6
|
+
title: 'Primitives/Slider',
|
|
7
|
+
component: Slider,
|
|
8
|
+
args: {
|
|
9
|
+
label: 'Value',
|
|
10
|
+
min: 0,
|
|
11
|
+
max: 100,
|
|
12
|
+
step: 1,
|
|
13
|
+
inactive: false,
|
|
14
|
+
},
|
|
15
|
+
argTypes: {
|
|
16
|
+
label: { control: 'text' },
|
|
17
|
+
min: { control: 'number' },
|
|
18
|
+
max: { control: 'number' },
|
|
19
|
+
step: { control: 'number' },
|
|
20
|
+
inactive: { control: 'boolean' },
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default meta;
|
|
25
|
+
type Story = StoryObj<typeof Slider>;
|
|
26
|
+
|
|
27
|
+
const Controlled = (props: Omit<React.ComponentProps<typeof Slider>, 'value' | 'onChange'> & { initialValue?: number }) => {
|
|
28
|
+
const [value, setValue] = useState(props.initialValue ?? 50);
|
|
29
|
+
return <Slider {...props} value={value} onChange={setValue} />;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const Playground: Story = {
|
|
33
|
+
render: (args) => <Controlled {...args} />,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// ─── Matrix ───────────────────────────────────────────────────────────────────
|
|
37
|
+
|
|
38
|
+
const SNAPSHOTS = [0, 25, 50, 75, 100];
|
|
39
|
+
|
|
40
|
+
const col: React.CSSProperties = { display: 'flex', flexDirection: 'column', gap: 12 };
|
|
41
|
+
const row: React.CSSProperties = { display: 'flex', gap: 16, alignItems: 'center' };
|
|
42
|
+
const labelStyle: React.CSSProperties = { fontSize: 10, fontFamily: 'monospace', color: '#888', minWidth: 72, flexShrink: 0 };
|
|
43
|
+
const sliderCell: React.CSSProperties = { width: 200, flexShrink: 0 };
|
|
44
|
+
const section = (text: string) => (
|
|
45
|
+
<div style={{ fontSize: 11, fontWeight: 600, letterSpacing: '0.05em', textTransform: 'uppercase', color: '#555', marginTop: 8 }}>
|
|
46
|
+
{text}
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
const divider = <hr style={{ border: 'none', borderTop: '1px solid #e0e0e0', margin: '16px 0' }} />;
|
|
50
|
+
|
|
51
|
+
export const Matrix: Story = {
|
|
52
|
+
parameters: { layout: 'padded' },
|
|
53
|
+
render: () => (
|
|
54
|
+
<div style={{ ...col, fontFamily: 'sans-serif', gap: 0 }}>
|
|
55
|
+
|
|
56
|
+
{section('Values (0–100)')}
|
|
57
|
+
<div style={{ ...col, marginTop: 12 }}>
|
|
58
|
+
{SNAPSHOTS.map(v => (
|
|
59
|
+
<div key={v} style={row}>
|
|
60
|
+
<span style={labelStyle}>{v}%</span>
|
|
61
|
+
<div style={sliderCell}>
|
|
62
|
+
<Slider label="Volume" value={v} onChange={() => {}} />
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
))}
|
|
66
|
+
</div>
|
|
67
|
+
|
|
68
|
+
{divider}
|
|
69
|
+
|
|
70
|
+
{section('States')}
|
|
71
|
+
<div style={{ ...col, marginTop: 12 }}>
|
|
72
|
+
<div style={row}>
|
|
73
|
+
<span style={labelStyle}>enabled</span>
|
|
74
|
+
<div style={sliderCell}><Controlled label="Brightness" initialValue={60} /></div>
|
|
75
|
+
</div>
|
|
76
|
+
<div style={row}>
|
|
77
|
+
<span style={labelStyle}>Inactive</span>
|
|
78
|
+
<div style={sliderCell}><Slider label="Brightness" value={60} inactive onChange={() => {}} /></div>
|
|
79
|
+
</div>
|
|
80
|
+
<div style={row}>
|
|
81
|
+
<span style={labelStyle}>at min</span>
|
|
82
|
+
<div style={sliderCell}><Slider label="Brightness" value={0} onChange={() => {}} /></div>
|
|
83
|
+
</div>
|
|
84
|
+
<div style={row}>
|
|
85
|
+
<span style={labelStyle}>at max</span>
|
|
86
|
+
<div style={sliderCell}><Slider label="Brightness" value={100} onChange={() => {}} /></div>
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
|
|
90
|
+
</div>
|
|
91
|
+
),
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// ─── Individual stories ───────────────────────────────────────────────────────
|
|
95
|
+
|
|
96
|
+
export const Default: Story = {
|
|
97
|
+
render: () => (
|
|
98
|
+
<div style={{ width: 280 }}>
|
|
99
|
+
<Controlled label="Volume" initialValue={50} />
|
|
100
|
+
</div>
|
|
101
|
+
),
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const CustomRange: Story = {
|
|
105
|
+
render: () => (
|
|
106
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 16, width: 280 }}>
|
|
107
|
+
<Controlled label="Rating (0–10)" min={0} max={10} step={1} initialValue={7} />
|
|
108
|
+
<Controlled label="Opacity (0–1)" min={0} max={1} step={0.1} initialValue={0.8} />
|
|
109
|
+
</div>
|
|
110
|
+
),
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const Inactive: Story = {
|
|
114
|
+
render: () => (
|
|
115
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 16, width: 280 }}>
|
|
116
|
+
<Slider label="Brightness" value={30} inactive onChange={() => {}} />
|
|
117
|
+
<Slider label="Contrast" value={70} inactive onChange={() => {}} />
|
|
118
|
+
</div>
|
|
119
|
+
),
|
|
120
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React, { forwardRef, useCallback, useEffect, useId, useRef, useState } from 'react';
|
|
2
|
+
import { cn } from '@/utils/cn';
|
|
3
|
+
import { Text } from '@/components/Text';
|
|
4
|
+
import styles from './Slider.module.css';
|
|
5
|
+
|
|
6
|
+
export interface SliderProps {
|
|
7
|
+
value: number;
|
|
8
|
+
onChange: (value: number) => void;
|
|
9
|
+
min?: number;
|
|
10
|
+
max?: number;
|
|
11
|
+
step?: number;
|
|
12
|
+
label: string;
|
|
13
|
+
id?: string;
|
|
14
|
+
inactive?: boolean;
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const Slider = forwardRef<HTMLDivElement, SliderProps>(
|
|
19
|
+
({ value, onChange, min = 0, max = 100, step = 1, label, id: idProp, inactive = false, className }, ref) => {
|
|
20
|
+
const generatedId = useId();
|
|
21
|
+
const id = idProp ?? generatedId;
|
|
22
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
23
|
+
const [pct, setPct] = useState(() => {
|
|
24
|
+
const range = max - min;
|
|
25
|
+
return range === 0 ? 0 : Math.round(((value - min) / range) * 100);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const sync = useCallback(() => {
|
|
29
|
+
const range = max - min;
|
|
30
|
+
setPct(range === 0 ? 0 : Math.round(((value - min) / range) * 100));
|
|
31
|
+
}, [value, min, max]);
|
|
32
|
+
|
|
33
|
+
useEffect(() => { sync(); }, [sync]);
|
|
34
|
+
|
|
35
|
+
const handleInput = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
36
|
+
onChange(Number(e.target.value));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<div ref={ref} className={cn(styles.field, className)}>
|
|
41
|
+
<div className={styles.labelRow}>
|
|
42
|
+
<Text variant="text-body-small-emphasis" as="label" htmlFor={id}>{label}</Text>
|
|
43
|
+
<Text variant="text-body-small-emphasis" as="span">{value}</Text>
|
|
44
|
+
</div>
|
|
45
|
+
<div
|
|
46
|
+
ref={containerRef}
|
|
47
|
+
className={cn(styles.track, inactive && styles.trackInactive, pct === 0 && styles.trackAtMin)}
|
|
48
|
+
style={{ '--slider-pct': pct } as React.CSSProperties}
|
|
49
|
+
>
|
|
50
|
+
<div className={styles.trackInner}>
|
|
51
|
+
<div className={styles.fillTrack}><div className={styles.fill} /></div>
|
|
52
|
+
<div className={styles.thumb} />
|
|
53
|
+
</div>
|
|
54
|
+
<input
|
|
55
|
+
type="range"
|
|
56
|
+
id={id}
|
|
57
|
+
min={min}
|
|
58
|
+
max={max}
|
|
59
|
+
step={step}
|
|
60
|
+
value={value}
|
|
61
|
+
onChange={handleInput}
|
|
62
|
+
disabled={inactive}
|
|
63
|
+
className={styles.input}
|
|
64
|
+
aria-valuemin={min}
|
|
65
|
+
aria-valuemax={max}
|
|
66
|
+
aria-valuenow={value}
|
|
67
|
+
/>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
Slider.displayName = 'Slider';
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Surface — lean container primitive.
|
|
3
|
+
* Backgrounds, elevation, edges, radius, and interactive states.
|
|
4
|
+
* Hover/pressed via direct background-color + color-mix(). No pseudo-element overlays.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
.surface {
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
position: relative;
|
|
10
|
+
/* Reset native button/anchor chrome when rendered as those elements */
|
|
11
|
+
border: none;
|
|
12
|
+
padding: 0;
|
|
13
|
+
margin: 0;
|
|
14
|
+
font: inherit;
|
|
15
|
+
color: inherit;
|
|
16
|
+
background: none;
|
|
17
|
+
text-decoration: none;
|
|
18
|
+
text-align: left;
|
|
19
|
+
cursor: default;
|
|
20
|
+
appearance: none;
|
|
21
|
+
-webkit-appearance: none;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* ==========================================================================
|
|
25
|
+
Backgrounds
|
|
26
|
+
========================================================================== */
|
|
27
|
+
|
|
28
|
+
.bgPrimary {
|
|
29
|
+
background-color: var(--color-background-primary);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.bgSecondary {
|
|
33
|
+
background-color: var(--color-background-secondary);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.bgTransparent {
|
|
37
|
+
background-color: transparent;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.bgTranslucent {
|
|
41
|
+
background-color: var(--color-background-translucent);
|
|
42
|
+
backdrop-filter: blur(var(--effect-blur-md));
|
|
43
|
+
-webkit-backdrop-filter: blur(var(--effect-blur-md));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* ==========================================================================
|
|
47
|
+
Semantic Intent Backgrounds — intent{Intent}{Contrast}
|
|
48
|
+
========================================================================== */
|
|
49
|
+
|
|
50
|
+
/* Brand */
|
|
51
|
+
.intentBrandFaint { background-color: var(--color-background-faint-brand); }
|
|
52
|
+
.intentBrandMedium { background-color: var(--color-background-medium-brand); }
|
|
53
|
+
.intentBrandBold { background-color: var(--color-background-bold-brand); }
|
|
54
|
+
.intentBrandStrong { background-color: var(--color-background-strong-brand); }
|
|
55
|
+
|
|
56
|
+
/* Positive */
|
|
57
|
+
.intentPositiveFaint { background-color: var(--color-background-faint-positive); }
|
|
58
|
+
.intentPositiveMedium { background-color: var(--color-background-medium-positive); }
|
|
59
|
+
.intentPositiveBold { background-color: var(--color-background-bold-positive); }
|
|
60
|
+
.intentPositiveStrong { background-color: var(--color-background-strong-positive); }
|
|
61
|
+
|
|
62
|
+
/* Negative */
|
|
63
|
+
.intentNegativeFaint { background-color: var(--color-background-faint-negative); }
|
|
64
|
+
.intentNegativeMedium { background-color: var(--color-background-medium-negative); }
|
|
65
|
+
.intentNegativeBold { background-color: var(--color-background-bold-negative); }
|
|
66
|
+
.intentNegativeStrong { background-color: var(--color-background-strong-negative); }
|
|
67
|
+
|
|
68
|
+
/* Warning */
|
|
69
|
+
.intentWarningFaint { background-color: var(--color-background-faint-warning); }
|
|
70
|
+
.intentWarningMedium { background-color: var(--color-background-medium-warning); }
|
|
71
|
+
.intentWarningBold { background-color: var(--color-background-bold-warning); }
|
|
72
|
+
.intentWarningStrong { background-color: var(--color-background-strong-warning); }
|
|
73
|
+
|
|
74
|
+
/* Caution */
|
|
75
|
+
.intentCautionFaint { background-color: var(--color-background-faint-caution); }
|
|
76
|
+
.intentCautionMedium { background-color: var(--color-background-medium-caution); }
|
|
77
|
+
.intentCautionBold { background-color: var(--color-background-bold-caution); }
|
|
78
|
+
.intentCautionStrong { background-color: var(--color-background-strong-caution); }
|
|
79
|
+
|
|
80
|
+
/* AI */
|
|
81
|
+
.intentAiFaint { background-color: var(--color-background-faint-ai); }
|
|
82
|
+
.intentAiMedium { background-color: var(--color-background-medium-ai); }
|
|
83
|
+
.intentAiBold { background-color: var(--color-background-bold-ai); }
|
|
84
|
+
.intentAiStrong { background-color: var(--color-background-strong-ai); }
|
|
85
|
+
|
|
86
|
+
/* Neutral */
|
|
87
|
+
.intentNeutralFaint { background-color: var(--color-background-faint-neutral); }
|
|
88
|
+
.intentNeutralMedium { background-color: var(--color-background-medium-neutral); }
|
|
89
|
+
.intentNeutralBold { background-color: var(--color-background-bold-neutral); }
|
|
90
|
+
.intentNeutralStrong { background-color: var(--color-background-strong-neutral); }
|
|
91
|
+
|
|
92
|
+
/* Walkthrough */
|
|
93
|
+
.intentWalkthroughFaint { background-color: var(--color-background-faint-walkthrough); }
|
|
94
|
+
.intentWalkthroughMedium { background-color: var(--color-background-medium-walkthrough); }
|
|
95
|
+
.intentWalkthroughBold { background-color: var(--color-background-bold-walkthrough); }
|
|
96
|
+
.intentWalkthroughStrong { background-color: var(--color-background-strong-walkthrough); }
|
|
97
|
+
|
|
98
|
+
/* Guide */
|
|
99
|
+
.intentGuideFaint { background-color: var(--color-background-faint-guide); }
|
|
100
|
+
.intentGuideMedium { background-color: var(--color-background-medium-guide); }
|
|
101
|
+
.intentGuideBold { background-color: var(--color-background-bold-guide); }
|
|
102
|
+
.intentGuideStrong { background-color: var(--color-background-strong-guide); }
|
|
103
|
+
|
|
104
|
+
/* ==========================================================================
|
|
105
|
+
Elevation — progressive: none → flat → elevated → floating
|
|
106
|
+
========================================================================== */
|
|
107
|
+
|
|
108
|
+
.elevationNone {}
|
|
109
|
+
|
|
110
|
+
.elevationDepressed {
|
|
111
|
+
box-shadow: var(--effect-elevation-depressed-sm);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.elevationDepressedMd {
|
|
115
|
+
box-shadow: var(--effect-elevation-depressed-md);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.elevationFlat {
|
|
119
|
+
box-shadow: var(--effect-elevation-elevated-sm);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.elevationElevated {
|
|
123
|
+
box-shadow: var(--effect-elevation-elevated-md);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.elevationFloating {
|
|
127
|
+
box-shadow: var(--effect-elevation-elevated-floating);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.elevationOverlayTop {
|
|
131
|
+
box-shadow: var(--effect-elevation-elevated-panel-top);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.elevationOverlayRight {
|
|
135
|
+
box-shadow: var(--effect-elevation-elevated-panel-right);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.elevationOverlayBottom {
|
|
139
|
+
box-shadow: var(--effect-elevation-elevated-panel-bottom);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.elevationOverlayLeft {
|
|
143
|
+
box-shadow: var(--effect-elevation-elevated-panel-left);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/* ==========================================================================
|
|
147
|
+
Edge Borders (only when elevation='none')
|
|
148
|
+
========================================================================== */
|
|
149
|
+
|
|
150
|
+
.edgeTop { border-top: var(--dimension-stroke-width-015) solid var(--color-border-tertiary); }
|
|
151
|
+
.edgeRight { border-right: var(--dimension-stroke-width-015) solid var(--color-border-tertiary); }
|
|
152
|
+
.edgeBottom { border-bottom: var(--dimension-stroke-width-015) solid var(--color-border-tertiary); }
|
|
153
|
+
.edgeLeft { border-left: var(--dimension-stroke-width-015) solid var(--color-border-tertiary); }
|
|
154
|
+
|
|
155
|
+
/* ==========================================================================
|
|
156
|
+
Corner Radius
|
|
157
|
+
========================================================================== */
|
|
158
|
+
|
|
159
|
+
.radiusNone { border-radius: var(--dimension-radius-000); }
|
|
160
|
+
.radiusXs { border-radius: var(--dimension-radius-050); }
|
|
161
|
+
.radiusSm { border-radius: var(--dimension-radius-075); }
|
|
162
|
+
.radiusMd { border-radius: var(--dimension-radius-100); }
|
|
163
|
+
.radiusLg { border-radius: var(--dimension-radius-125); }
|
|
164
|
+
.radiusXl { border-radius: var(--dimension-radius-175); }
|
|
165
|
+
.radius2xl { border-radius: var(--dimension-radius-200); }
|
|
166
|
+
.radiusFull { border-radius: var(--dimension-radius-half); }
|
|
167
|
+
|
|
168
|
+
/* ==========================================================================
|
|
169
|
+
Interactive States — direct background-color, no pseudo-elements
|
|
170
|
+
========================================================================== */
|
|
171
|
+
|
|
172
|
+
.interactive {
|
|
173
|
+
cursor: pointer;
|
|
174
|
+
transition: transform var(--effect-motion-short-2);
|
|
175
|
+
|
|
176
|
+
/* Interaction — ghost defaults */
|
|
177
|
+
--_hover-bg: var(--color-interaction-hover);
|
|
178
|
+
--_pressed-bg: var(--color-interaction-pressed);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.interactive:hover {
|
|
182
|
+
background-color: var(--_hover-bg);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.interactive:active {
|
|
186
|
+
background-color: var(--_pressed-bg);
|
|
187
|
+
transform: scale(var(--dimension-scale-subtle));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.interactive:focus-visible {
|
|
191
|
+
outline: var(--dimension-stroke-width-025) solid var(--color-interaction-focus);
|
|
192
|
+
outline-offset: var(--dimension-space-025);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/* ==========================================================================
|
|
196
|
+
Selected State — persistent overlay on any background via ::before
|
|
197
|
+
========================================================================== */
|
|
198
|
+
|
|
199
|
+
.selected::before {
|
|
200
|
+
content: '';
|
|
201
|
+
position: absolute;
|
|
202
|
+
inset: 0;
|
|
203
|
+
border-radius: inherit;
|
|
204
|
+
pointer-events: none;
|
|
205
|
+
z-index: 0;
|
|
206
|
+
background-color: var(--color-interaction-hover);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.selected > * {
|
|
210
|
+
position: relative;
|
|
211
|
+
z-index: 1;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/* ==========================================================================
|
|
215
|
+
Inactive State
|
|
216
|
+
========================================================================== */
|
|
217
|
+
|
|
218
|
+
.inactive {
|
|
219
|
+
opacity: 0.5;
|
|
220
|
+
cursor: not-allowed;
|
|
221
|
+
pointer-events: none;
|
|
222
|
+
}
|