@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,162 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { cn } from '@/utils/cn';
|
|
3
|
+
import { Text } from '@/components/Text';
|
|
4
|
+
import { LabelWrap } from '@/components/LabelWrap';
|
|
5
|
+
import { Cross } from '@ds-mo/icons';
|
|
6
|
+
import type { IconComponent } from '@/types/icons';
|
|
7
|
+
import styles from './Tag.module.css';
|
|
8
|
+
|
|
9
|
+
export type TagIntent = 'neutral' | 'brand' | 'ai' | 'negative' | 'warning' | 'caution' | 'positive';
|
|
10
|
+
export type TagContrast = 'strong' | 'bold' | 'medium' | 'faint';
|
|
11
|
+
export type TagElevation = 'none' | 'flat' | 'elevated';
|
|
12
|
+
export type TagSize = 'md' | 'sm' | 'xs';
|
|
13
|
+
export type TagBackground = 'faint' | 'medium' | 'bold' | 'strong' | 'always-dark';
|
|
14
|
+
|
|
15
|
+
export interface TagProps {
|
|
16
|
+
label: string;
|
|
17
|
+
intent?: TagIntent;
|
|
18
|
+
contrast?: TagContrast;
|
|
19
|
+
/**
|
|
20
|
+
* Visual chrome level.
|
|
21
|
+
* none — filled with intent bg, no border, no shadow [default]
|
|
22
|
+
* flat — transparent bg + intent-coloured border ring
|
|
23
|
+
* elevated — filled with intent bg + elevated shadow
|
|
24
|
+
*/
|
|
25
|
+
elevation?: TagElevation;
|
|
26
|
+
size?: TagSize;
|
|
27
|
+
rounded?: boolean;
|
|
28
|
+
/** Leading icon component. */
|
|
29
|
+
icon?: IconComponent;
|
|
30
|
+
removable?: boolean;
|
|
31
|
+
onRemove?: () => void;
|
|
32
|
+
/** Override the default Cross remove icon. */
|
|
33
|
+
removeIcon?: IconComponent;
|
|
34
|
+
maxWidth?: string | number;
|
|
35
|
+
inactive?: boolean;
|
|
36
|
+
/** Parent surface context. Adjusts hover tokens for tags on colored backgrounds. */
|
|
37
|
+
background?: TagBackground;
|
|
38
|
+
/** Makes the tag clickable. Pair with pressed/onPressedChange for filter-chip behaviour. */
|
|
39
|
+
onClick?: () => void;
|
|
40
|
+
pressed?: boolean;
|
|
41
|
+
onPressedChange?: (pressed: boolean) => void;
|
|
42
|
+
className?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const ICON_SIZE: Record<TagSize, number> = { md: 20, sm: 16, xs: 12 };
|
|
46
|
+
|
|
47
|
+
const TEXT_STYLE_MAP: Record<TagSize, string> = {
|
|
48
|
+
md: 'text-body-medium',
|
|
49
|
+
sm: 'text-body-small',
|
|
50
|
+
xs: 'text-caption',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const Tag = forwardRef<HTMLDivElement, TagProps>(
|
|
54
|
+
(
|
|
55
|
+
{
|
|
56
|
+
label,
|
|
57
|
+
intent = 'neutral',
|
|
58
|
+
contrast = 'faint',
|
|
59
|
+
elevation = 'none',
|
|
60
|
+
size = 'md',
|
|
61
|
+
rounded = false,
|
|
62
|
+
icon: Icon,
|
|
63
|
+
removable = false,
|
|
64
|
+
onRemove,
|
|
65
|
+
removeIcon: RemoveIcon,
|
|
66
|
+
maxWidth,
|
|
67
|
+
inactive = false,
|
|
68
|
+
background,
|
|
69
|
+
onClick,
|
|
70
|
+
pressed,
|
|
71
|
+
onPressedChange,
|
|
72
|
+
className,
|
|
73
|
+
},
|
|
74
|
+
ref
|
|
75
|
+
) => {
|
|
76
|
+
const isInteractive = !!onClick || !!onPressedChange;
|
|
77
|
+
const hasRemove = removable && !!onRemove;
|
|
78
|
+
const iconSize = ICON_SIZE[size];
|
|
79
|
+
const textStyle = TEXT_STYLE_MAP[size];
|
|
80
|
+
const elevKey = elevation.charAt(0).toUpperCase() + elevation.slice(1);
|
|
81
|
+
const sizeKey = size.toUpperCase() as 'MD' | 'SM' | 'XS';
|
|
82
|
+
|
|
83
|
+
const classes = cn(
|
|
84
|
+
styles.tag,
|
|
85
|
+
styles[`intent${intent.charAt(0).toUpperCase() + intent.slice(1)}`],
|
|
86
|
+
styles[`contrast${contrast.charAt(0).toUpperCase() + contrast.slice(1)}`],
|
|
87
|
+
styles[`elevation${elevKey}`],
|
|
88
|
+
styles[`size${size.charAt(0).toUpperCase() + size.slice(1)}`],
|
|
89
|
+
rounded && styles.rounded,
|
|
90
|
+
// Pill padding correction — extra space-050 on bare sides (no content anchor)
|
|
91
|
+
rounded && !Icon && (styles as Record<string, string>)[`roundedLeft${sizeKey}`],
|
|
92
|
+
rounded && !hasRemove && (styles as Record<string, string>)[`roundedRight${sizeKey}`],
|
|
93
|
+
// Icon-edge correction — reduce padding to (height − icon) / 2 on icon sides
|
|
94
|
+
!!Icon && (styles as Record<string, string>)[`iconLeft${sizeKey}`],
|
|
95
|
+
hasRemove && (styles as Record<string, string>)[`iconRight${sizeKey}`],
|
|
96
|
+
removable && styles.removable,
|
|
97
|
+
isInteractive && styles.interactive,
|
|
98
|
+
background && background !== 'faint' && styles[
|
|
99
|
+
background === 'always-dark' ? 'onAlwaysDark'
|
|
100
|
+
: `on${background.charAt(0).toUpperCase() + background.slice(1)}`
|
|
101
|
+
],
|
|
102
|
+
inactive && styles.inactive,
|
|
103
|
+
pressed && styles.pressed,
|
|
104
|
+
className,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const style = maxWidth != null
|
|
108
|
+
? { maxWidth: typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth }
|
|
109
|
+
: undefined;
|
|
110
|
+
|
|
111
|
+
const handleInteract = isInteractive && !inactive
|
|
112
|
+
? () => {
|
|
113
|
+
onPressedChange?.(!pressed);
|
|
114
|
+
onClick?.();
|
|
115
|
+
}
|
|
116
|
+
: undefined;
|
|
117
|
+
|
|
118
|
+
const handleKeyDown = isInteractive && !inactive
|
|
119
|
+
? (e: React.KeyboardEvent<HTMLDivElement>) => {
|
|
120
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
onPressedChange?.(!pressed);
|
|
123
|
+
onClick?.();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
: undefined;
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<div
|
|
130
|
+
ref={ref}
|
|
131
|
+
className={classes}
|
|
132
|
+
style={style}
|
|
133
|
+
onClick={handleInteract}
|
|
134
|
+
onKeyDown={handleKeyDown}
|
|
135
|
+
role={isInteractive ? 'button' : undefined}
|
|
136
|
+
tabIndex={isInteractive && !inactive ? 0 : undefined}
|
|
137
|
+
aria-pressed={onPressedChange != null ? pressed : undefined}
|
|
138
|
+
aria-disabled={inactive || undefined}
|
|
139
|
+
>
|
|
140
|
+
{Icon && <Icon size={iconSize} />}
|
|
141
|
+
<LabelWrap size={size}>
|
|
142
|
+
<Text variant={textStyle as never} as="span" color="inherit">
|
|
143
|
+
{label}
|
|
144
|
+
</Text>
|
|
145
|
+
</LabelWrap>
|
|
146
|
+
{removable && onRemove && (
|
|
147
|
+
<button
|
|
148
|
+
type="button"
|
|
149
|
+
className={styles.removeButton}
|
|
150
|
+
onClick={(e) => { e.stopPropagation(); onRemove(); }}
|
|
151
|
+
aria-label={`Remove ${label}`}
|
|
152
|
+
tabIndex={-1}
|
|
153
|
+
>
|
|
154
|
+
{RemoveIcon ? <RemoveIcon size={iconSize} /> : <Cross size={iconSize} />}
|
|
155
|
+
</button>
|
|
156
|
+
)}
|
|
157
|
+
</div>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
Tag.displayName = 'Tag';
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
.text {
|
|
2
|
+
margin: 0;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/* ============================================
|
|
6
|
+
LINE TRUNCATION
|
|
7
|
+
============================================ */
|
|
8
|
+
|
|
9
|
+
.truncate1Line {
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
text-overflow: ellipsis;
|
|
12
|
+
white-space: nowrap;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.truncate2Lines {
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
display: -webkit-box;
|
|
18
|
+
-webkit-line-clamp: 2;
|
|
19
|
+
-webkit-box-orient: vertical;
|
|
20
|
+
text-overflow: ellipsis;
|
|
21
|
+
word-break: break-word;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.truncate3Lines {
|
|
25
|
+
overflow: hidden;
|
|
26
|
+
display: -webkit-box;
|
|
27
|
+
-webkit-line-clamp: 3;
|
|
28
|
+
-webkit-box-orient: vertical;
|
|
29
|
+
text-overflow: ellipsis;
|
|
30
|
+
word-break: break-word;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.truncate4Lines {
|
|
34
|
+
overflow: hidden;
|
|
35
|
+
display: -webkit-box;
|
|
36
|
+
-webkit-line-clamp: 4;
|
|
37
|
+
-webkit-box-orient: vertical;
|
|
38
|
+
text-overflow: ellipsis;
|
|
39
|
+
word-break: break-word;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.truncate5Lines {
|
|
43
|
+
overflow: hidden;
|
|
44
|
+
display: -webkit-box;
|
|
45
|
+
-webkit-line-clamp: 5;
|
|
46
|
+
-webkit-box-orient: vertical;
|
|
47
|
+
text-overflow: ellipsis;
|
|
48
|
+
word-break: break-word;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.noTruncation {
|
|
52
|
+
word-break: break-word;
|
|
53
|
+
white-space: normal;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.wrapNowrap {
|
|
57
|
+
white-space: nowrap;
|
|
58
|
+
word-break: normal;
|
|
59
|
+
overflow: hidden;
|
|
60
|
+
text-overflow: ellipsis;
|
|
61
|
+
min-width: 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.wrapBalance {
|
|
65
|
+
text-wrap: balance;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.wrapPretty {
|
|
69
|
+
text-wrap: pretty;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* ============================================
|
|
73
|
+
TEXT COLOR - Semantic Tokens
|
|
74
|
+
============================================ */
|
|
75
|
+
|
|
76
|
+
.colorPrimary {
|
|
77
|
+
color: var(--color-foreground-primary);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.colorSecondary {
|
|
81
|
+
color: var(--color-foreground-secondary);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.colorTertiary {
|
|
85
|
+
color: var(--color-foreground-tertiary);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.colorBrand {
|
|
89
|
+
color: var(--color-foreground-bold-brand);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.colorNegative {
|
|
93
|
+
color: var(--color-foreground-bold-negative);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.colorPositive {
|
|
97
|
+
color: var(--color-foreground-bold-positive);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.colorWarning {
|
|
101
|
+
color: var(--color-foreground-bold-warning);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.colorCaution {
|
|
105
|
+
color: var(--color-foreground-bold-caution);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.colorAi {
|
|
109
|
+
color: var(--color-foreground-bold-ai);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.colorOnStrong {
|
|
113
|
+
color: var(--color-foreground-on-strong-background-primary);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.colorOnBold {
|
|
117
|
+
color: var(--color-foreground-on-bold-background-primary);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.colorInherit {
|
|
121
|
+
color: inherit;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* ============================================
|
|
125
|
+
TEXT DECORATION
|
|
126
|
+
============================================ */
|
|
127
|
+
|
|
128
|
+
.decorationNone {
|
|
129
|
+
text-decoration: none;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.decorationUnderline {
|
|
133
|
+
text-decoration: underline;
|
|
134
|
+
text-underline-offset: 2px;
|
|
135
|
+
text-decoration-thickness: 1px;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.decorationDottedUnderline {
|
|
139
|
+
text-decoration: underline dotted;
|
|
140
|
+
text-underline-offset: 2px;
|
|
141
|
+
text-decoration-thickness: 1px;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/* ============================================
|
|
145
|
+
FONT STYLE
|
|
146
|
+
============================================ */
|
|
147
|
+
|
|
148
|
+
.italic {
|
|
149
|
+
font-style: italic;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* ============================================
|
|
153
|
+
TEXT ALIGNMENT
|
|
154
|
+
============================================ */
|
|
155
|
+
|
|
156
|
+
.alignLeft {
|
|
157
|
+
text-align: left;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.alignCenter {
|
|
161
|
+
text-align: center;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.alignRight {
|
|
165
|
+
text-align: right;
|
|
166
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Text } from './Text';
|
|
4
|
+
import type { TextVariant, TextColorToken } from './Text';
|
|
5
|
+
|
|
6
|
+
const VARIANTS: TextVariant[] = [
|
|
7
|
+
'text-display-medium',
|
|
8
|
+
'text-display-small',
|
|
9
|
+
'text-title-large',
|
|
10
|
+
'text-title-medium',
|
|
11
|
+
'text-title-small',
|
|
12
|
+
'text-body-large',
|
|
13
|
+
'text-body-large-emphasis',
|
|
14
|
+
'text-body-medium',
|
|
15
|
+
'text-body-medium-emphasis',
|
|
16
|
+
'text-body-small',
|
|
17
|
+
'text-body-small-emphasis',
|
|
18
|
+
'text-caption',
|
|
19
|
+
'text-caption-emphasis',
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const COLORS: TextColorToken[] = [
|
|
23
|
+
'primary', 'secondary', 'tertiary',
|
|
24
|
+
'brand', 'negative', 'positive', 'warning', 'caution', 'ai',
|
|
25
|
+
'on-strong', 'on-bold', 'inherit',
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const meta: Meta<typeof Text> = {
|
|
29
|
+
title: 'Primitives (Reviewed)/Text',
|
|
30
|
+
component: Text,
|
|
31
|
+
args: {
|
|
32
|
+
variant: 'text-body-medium',
|
|
33
|
+
children: 'The quick brown fox jumps over the lazy dog',
|
|
34
|
+
},
|
|
35
|
+
argTypes: {
|
|
36
|
+
variant: { control: 'select', options: VARIANTS },
|
|
37
|
+
color: { control: 'select', options: COLORS },
|
|
38
|
+
as: { control: 'select', options: ['p', 'span', 'div', 'label', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'] },
|
|
39
|
+
align: { control: 'select', options: ['left', 'center', 'right'] },
|
|
40
|
+
decoration: { control: 'select', options: ['none', 'underline', 'dotted-underline'] },
|
|
41
|
+
italic: { control: 'boolean' },
|
|
42
|
+
lineTruncation:{ control: 'select', options: [1, 2, 3, 4, 5, 'none'] },
|
|
43
|
+
wrap: { control: 'select', options: ['wrap', 'nowrap', 'balance', 'pretty'] },
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default meta;
|
|
48
|
+
type Story = StoryObj<typeof Text>;
|
|
49
|
+
|
|
50
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
51
|
+
|
|
52
|
+
const monoLabel = (text: string) => (
|
|
53
|
+
<span style={{ fontSize: 10, fontFamily: 'monospace', color: 'var(--color-foreground-tertiary)', minWidth: 210, flexShrink: 0, paddingTop: 2 }}>
|
|
54
|
+
{text}
|
|
55
|
+
</span>
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const sectionHeading = (title: string) => (
|
|
59
|
+
<div style={{ fontSize: 10, fontFamily: 'monospace', fontWeight: 700, textTransform: 'uppercase', letterSpacing: '0.08em', color: 'var(--color-foreground-tertiary)', marginTop: 12, marginBottom: 2 }}>
|
|
60
|
+
{title}
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const divider = <hr style={{ border: 'none', borderTop: '1px solid var(--color-border-tertiary)', margin: '12px 0' }} />;
|
|
65
|
+
|
|
66
|
+
const SAMPLE = 'The quick brown fox jumps over the lazy dog';
|
|
67
|
+
const SHORT_SAMPLE = 'Bright vixens jump dozy fowl quack';
|
|
68
|
+
const LONG_SAMPLE = 'This text is intentionally long to demonstrate how the component behaves when content exceeds the available width and must either wrap or truncate gracefully.';
|
|
69
|
+
|
|
70
|
+
// ─── Stories ──────────────────────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
export const Playground: Story = {};
|
|
73
|
+
|
|
74
|
+
export const TypeScale: Story = {
|
|
75
|
+
name: 'Type Scale',
|
|
76
|
+
parameters: { layout: 'padded' },
|
|
77
|
+
render: () => (
|
|
78
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
|
79
|
+
{sectionHeading('Display')}
|
|
80
|
+
{(['text-display-medium', 'text-display-small'] as TextVariant[]).map(v => (
|
|
81
|
+
<div key={v} style={{ display: 'flex', alignItems: 'baseline', gap: 16 }}>
|
|
82
|
+
{monoLabel(v)}
|
|
83
|
+
<Text variant={v}>{SHORT_SAMPLE}</Text>
|
|
84
|
+
</div>
|
|
85
|
+
))}
|
|
86
|
+
{divider}
|
|
87
|
+
{sectionHeading('Title')}
|
|
88
|
+
{(['text-title-large', 'text-title-medium', 'text-title-small'] as TextVariant[]).map(v => (
|
|
89
|
+
<div key={v} style={{ display: 'flex', alignItems: 'baseline', gap: 16 }}>
|
|
90
|
+
{monoLabel(v)}
|
|
91
|
+
<Text variant={v}>{SAMPLE}</Text>
|
|
92
|
+
</div>
|
|
93
|
+
))}
|
|
94
|
+
{divider}
|
|
95
|
+
{sectionHeading('Body')}
|
|
96
|
+
{([
|
|
97
|
+
'text-body-large', 'text-body-large-emphasis',
|
|
98
|
+
'text-body-medium', 'text-body-medium-emphasis',
|
|
99
|
+
'text-body-small', 'text-body-small-emphasis',
|
|
100
|
+
] as TextVariant[]).map(v => (
|
|
101
|
+
<div key={v} style={{ display: 'flex', alignItems: 'baseline', gap: 16 }}>
|
|
102
|
+
{monoLabel(v)}
|
|
103
|
+
<Text variant={v}>{SAMPLE}</Text>
|
|
104
|
+
</div>
|
|
105
|
+
))}
|
|
106
|
+
{divider}
|
|
107
|
+
{sectionHeading('Caption')}
|
|
108
|
+
{(['text-caption', 'text-caption-emphasis'] as TextVariant[]).map(v => (
|
|
109
|
+
<div key={v} style={{ display: 'flex', alignItems: 'baseline', gap: 16 }}>
|
|
110
|
+
{monoLabel(v)}
|
|
111
|
+
<Text variant={v}>{SAMPLE}</Text>
|
|
112
|
+
</div>
|
|
113
|
+
))}
|
|
114
|
+
</div>
|
|
115
|
+
),
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const Colors: Story = {
|
|
119
|
+
parameters: { layout: 'padded' },
|
|
120
|
+
render: () => (
|
|
121
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
|
122
|
+
{(['primary', 'secondary', 'tertiary'] as TextColorToken[]).map(color => (
|
|
123
|
+
<div key={color} style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
|
|
124
|
+
{monoLabel(color)}
|
|
125
|
+
<Text variant="text-body-medium" color={color}>{SAMPLE}</Text>
|
|
126
|
+
</div>
|
|
127
|
+
))}
|
|
128
|
+
{divider}
|
|
129
|
+
{(['brand', 'negative', 'positive', 'warning', 'caution', 'ai'] as TextColorToken[]).map(color => (
|
|
130
|
+
<div key={color} style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
|
|
131
|
+
{monoLabel(color)}
|
|
132
|
+
<Text variant="text-body-medium" color={color}>{SAMPLE}</Text>
|
|
133
|
+
</div>
|
|
134
|
+
))}
|
|
135
|
+
{divider}
|
|
136
|
+
{/* on-strong and on-bold require a colored background to be legible */}
|
|
137
|
+
<div style={{ display: 'flex', gap: 12 }}>
|
|
138
|
+
<div style={{ background: 'var(--color-background-strong-brand)', borderRadius: 8, padding: '12px 16px', flex: 1, display: 'flex', gap: 16, alignItems: 'center' }}>
|
|
139
|
+
{monoLabel('on-strong')}
|
|
140
|
+
<Text variant="text-body-medium" color="on-strong">{SAMPLE}</Text>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
<div style={{ display: 'flex', gap: 12 }}>
|
|
144
|
+
<div style={{ background: 'var(--color-background-bold-brand)', borderRadius: 8, padding: '12px 16px', flex: 1, display: 'flex', gap: 16, alignItems: 'center' }}>
|
|
145
|
+
{monoLabel('on-bold')}
|
|
146
|
+
<Text variant="text-body-medium" color="on-bold">{SAMPLE}</Text>
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
),
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export const Decorations: Story = {
|
|
154
|
+
parameters: { layout: 'padded' },
|
|
155
|
+
render: () => (
|
|
156
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
|
157
|
+
{([
|
|
158
|
+
{ label: 'underline', props: { decoration: 'underline' as const } },
|
|
159
|
+
{ label: 'dotted-underline', props: { decoration: 'dotted-underline' as const } },
|
|
160
|
+
{ label: 'italic', props: { italic: true } },
|
|
161
|
+
{ label: 'italic + underline', props: { italic: true, decoration: 'underline' as const } },
|
|
162
|
+
]).map(({ label, props }) => (
|
|
163
|
+
<div key={label} style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
|
|
164
|
+
{monoLabel(label)}
|
|
165
|
+
<Text variant="text-body-medium" {...props}>{SAMPLE}</Text>
|
|
166
|
+
</div>
|
|
167
|
+
))}
|
|
168
|
+
</div>
|
|
169
|
+
),
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export const Alignment: Story = {
|
|
173
|
+
parameters: { layout: 'padded' },
|
|
174
|
+
render: () => (
|
|
175
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, width: 480 }}>
|
|
176
|
+
{(['left', 'center', 'right'] as const).map(align => (
|
|
177
|
+
<div key={align} style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
|
|
178
|
+
{monoLabel(align)}
|
|
179
|
+
<Text
|
|
180
|
+
variant="text-body-medium"
|
|
181
|
+
align={align}
|
|
182
|
+
style={{ flex: 1, background: 'var(--color-background-secondary)', borderRadius: 6, padding: '8px 12px' }}
|
|
183
|
+
>
|
|
184
|
+
The quick brown fox
|
|
185
|
+
</Text>
|
|
186
|
+
</div>
|
|
187
|
+
))}
|
|
188
|
+
</div>
|
|
189
|
+
),
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export const Truncation: Story = {
|
|
193
|
+
parameters: { layout: 'padded' },
|
|
194
|
+
render: () => (
|
|
195
|
+
<div style={{ maxWidth: 400, display: 'flex', flexDirection: 'column', gap: 12 }}>
|
|
196
|
+
{([1, 2, 3] as const).map(lines => (
|
|
197
|
+
<div key={lines} style={{ display: 'flex', gap: 16, alignItems: 'flex-start' }}>
|
|
198
|
+
{monoLabel(`${lines} line${lines > 1 ? 's' : ''}`)}
|
|
199
|
+
<Text variant="text-body-medium" lineTruncation={lines} style={{ flex: 1 }}>
|
|
200
|
+
{LONG_SAMPLE}
|
|
201
|
+
</Text>
|
|
202
|
+
</div>
|
|
203
|
+
))}
|
|
204
|
+
<div style={{ display: 'flex', gap: 16, alignItems: 'flex-start' }}>
|
|
205
|
+
{monoLabel('no truncation')}
|
|
206
|
+
<Text variant="text-body-medium" style={{ flex: 1 }}>
|
|
207
|
+
{LONG_SAMPLE}
|
|
208
|
+
</Text>
|
|
209
|
+
</div>
|
|
210
|
+
</div>
|
|
211
|
+
),
|
|
212
|
+
};
|