@fabio.caffarello/react-design-system 1.6.0 → 1.7.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/dist/index.cjs +29 -4
- package/dist/index.js +1866 -716
- package/dist/ui/atoms/Button/Button.d.ts +28 -5
- package/dist/ui/atoms/Button/Button.stories.d.ts +11 -3
- package/dist/ui/atoms/Checkbox/Checkbox.d.ts +24 -0
- package/dist/ui/atoms/Checkbox/Checkbox.stories.d.ts +10 -0
- package/dist/ui/atoms/Checkbox/Checkbox.test.d.ts +1 -0
- package/dist/ui/atoms/Collapsible/Collapsible.d.ts +29 -0
- package/dist/ui/atoms/Collapsible/Collapsible.stories.d.ts +9 -0
- package/dist/ui/atoms/Collapsible/Collapsible.test.d.ts +1 -0
- package/dist/ui/atoms/Input/Input.d.ts +28 -4
- package/dist/ui/atoms/Input/Input.stories.d.ts +8 -3
- package/dist/ui/atoms/Radio/Radio.d.ts +26 -0
- package/dist/ui/atoms/Radio/Radio.stories.d.ts +10 -0
- package/dist/ui/atoms/Radio/Radio.test.d.ts +1 -0
- package/dist/ui/atoms/SidebarItem/SidebarItem.d.ts +3 -1
- package/dist/ui/atoms/SidebarItem/SidebarItem.stories.d.ts +3 -0
- package/dist/ui/atoms/index.d.ts +7 -0
- package/dist/ui/hooks/useCollapsible.d.ts +27 -0
- package/dist/ui/index.d.ts +13 -0
- package/dist/ui/molecules/InputWithLabel/InputWithLabel.d.ts +4 -2
- package/dist/ui/molecules/SidebarGroup/SidebarGroup.d.ts +8 -1
- package/dist/ui/molecules/SidebarGroup/SidebarGroup.stories.d.ts +11 -0
- package/dist/ui/molecules/SidebarGroup/SidebarGroup.test.d.ts +1 -0
- package/dist/ui/providers/ThemeProvider.d.ts +34 -0
- package/dist/ui/tokens/breakpoints.d.ts +36 -0
- package/dist/ui/tokens/colors.d.ts +89 -0
- package/dist/ui/tokens/sidebar.d.ts +48 -0
- package/dist/ui/tokens/spacing.d.ts +53 -0
- package/dist/ui/tokens/themes/dark.d.ts +38 -0
- package/dist/ui/tokens/themes/light.d.ts +38 -0
- package/dist/ui/tokens/tokens.factory.d.ts +57 -0
- package/dist/ui/tokens/typography.d.ts +90 -0
- package/package.json +3 -2
- package/src/ui/atoms/Button/Button.stories.tsx +77 -7
- package/src/ui/atoms/Button/Button.tsx +176 -28
- package/src/ui/atoms/Checkbox/Checkbox.stories.tsx +61 -0
- package/src/ui/atoms/Checkbox/Checkbox.test.tsx +32 -0
- package/src/ui/atoms/Checkbox/Checkbox.tsx +103 -0
- package/src/ui/atoms/Collapsible/Collapsible.tsx +2 -2
- package/src/ui/atoms/Input/Input.stories.tsx +67 -6
- package/src/ui/atoms/Input/Input.tsx +117 -14
- package/src/ui/atoms/Radio/Radio.stories.tsx +72 -0
- package/src/ui/atoms/Radio/Radio.test.tsx +32 -0
- package/src/ui/atoms/Radio/Radio.tsx +104 -0
- package/src/ui/atoms/index.ts +7 -0
- package/src/ui/index.ts +14 -0
- package/src/ui/molecules/InputWithLabel/InputWithLabel.tsx +5 -4
- package/src/ui/molecules/SidebarGroup/SidebarGroup.tsx +30 -38
- package/src/ui/providers/ThemeProvider.tsx +105 -0
- package/src/ui/tokens/breakpoints.ts +71 -0
- package/src/ui/tokens/colors.ts +250 -0
- package/src/ui/tokens/sidebar.ts +9 -3
- package/src/ui/tokens/spacing.ts +127 -0
- package/src/ui/tokens/themes/dark.ts +18 -0
- package/src/ui/tokens/themes/light.ts +18 -0
- package/src/ui/tokens/tokens.factory.ts +117 -0
- package/src/ui/tokens/typography.ts +191 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dark Theme Tokens
|
|
3
|
+
*
|
|
4
|
+
* Dark theme color palette and tokens.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { COLOR_TOKENS_DARK } from '../colors';
|
|
8
|
+
import { SPACING_TOKENS } from '../spacing';
|
|
9
|
+
import { TYPOGRAPHY_TOKENS } from '../typography';
|
|
10
|
+
import { BREAKPOINT_TOKENS } from '../breakpoints';
|
|
11
|
+
|
|
12
|
+
export const DARK_THEME = {
|
|
13
|
+
colors: COLOR_TOKENS_DARK,
|
|
14
|
+
spacing: SPACING_TOKENS,
|
|
15
|
+
typography: TYPOGRAPHY_TOKENS,
|
|
16
|
+
breakpoints: BREAKPOINT_TOKENS,
|
|
17
|
+
mode: 'dark' as const,
|
|
18
|
+
} as const;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Light Theme Tokens
|
|
3
|
+
*
|
|
4
|
+
* Light theme color palette and tokens.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { COLOR_TOKENS_LIGHT } from '../colors';
|
|
8
|
+
import { SPACING_TOKENS } from '../spacing';
|
|
9
|
+
import { TYPOGRAPHY_TOKENS } from '../typography';
|
|
10
|
+
import { BREAKPOINT_TOKENS } from '../breakpoints';
|
|
11
|
+
|
|
12
|
+
export const LIGHT_THEME = {
|
|
13
|
+
colors: COLOR_TOKENS_LIGHT,
|
|
14
|
+
spacing: SPACING_TOKENS,
|
|
15
|
+
typography: TYPOGRAPHY_TOKENS,
|
|
16
|
+
breakpoints: BREAKPOINT_TOKENS,
|
|
17
|
+
mode: 'light' as const,
|
|
18
|
+
} as const;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tokens Factory
|
|
3
|
+
*
|
|
4
|
+
* Main factory for creating all types of tokens.
|
|
5
|
+
* Implements Factory Pattern for unified token creation.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { SpacingTokenFactory, type SpacingScale, type SpacingToken } from './spacing';
|
|
9
|
+
import { TypographyTokenFactory, type TypographyToken, type FontSize, type LineHeight, type FontWeight } from './typography';
|
|
10
|
+
import { ColorTokenFactory, type ColorRole, type SemanticColor, LightColorStrategy, DarkColorStrategy } from './colors';
|
|
11
|
+
import { BreakpointTokenFactory, type BreakpointName, type BreakpointToken } from './breakpoints';
|
|
12
|
+
|
|
13
|
+
export type ThemeMode = 'light' | 'dark';
|
|
14
|
+
|
|
15
|
+
export interface TokenSet {
|
|
16
|
+
spacing: Record<string, SpacingToken>;
|
|
17
|
+
typography: Record<string, TypographyToken>;
|
|
18
|
+
colors: Record<ColorRole, SemanticColor>;
|
|
19
|
+
breakpoints: Record<BreakpointName, BreakpointToken>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Tokens Factory
|
|
24
|
+
* Main factory for creating complete token sets
|
|
25
|
+
*/
|
|
26
|
+
export class TokensFactory {
|
|
27
|
+
private colorFactory: ColorTokenFactory;
|
|
28
|
+
|
|
29
|
+
constructor(theme: ThemeMode = 'light') {
|
|
30
|
+
const strategy = theme === 'light' ? new LightColorStrategy() : new DarkColorStrategy();
|
|
31
|
+
this.colorFactory = new ColorTokenFactory(strategy);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Create spacing token
|
|
36
|
+
*/
|
|
37
|
+
createSpacing(scale: SpacingScale): SpacingToken {
|
|
38
|
+
return SpacingTokenFactory.create(scale);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Create typography token
|
|
43
|
+
*/
|
|
44
|
+
createTypography(size: FontSize, lineHeight?: LineHeight, weight?: FontWeight): TypographyToken {
|
|
45
|
+
return TypographyTokenFactory.create(size, lineHeight, weight);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Create color palette
|
|
50
|
+
*/
|
|
51
|
+
createColorPalette(): Record<ColorRole, SemanticColor> {
|
|
52
|
+
return this.colorFactory.generatePalette();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Create breakpoint token
|
|
57
|
+
*/
|
|
58
|
+
createBreakpoint(name: BreakpointName): BreakpointToken {
|
|
59
|
+
return BreakpointTokenFactory.create(name);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Create complete token set for a theme
|
|
64
|
+
*/
|
|
65
|
+
createTokenSet(): TokenSet {
|
|
66
|
+
return {
|
|
67
|
+
spacing: {
|
|
68
|
+
xs: this.createSpacing(1),
|
|
69
|
+
sm: this.createSpacing(2),
|
|
70
|
+
md: this.createSpacing(3),
|
|
71
|
+
base: this.createSpacing(4),
|
|
72
|
+
lg: this.createSpacing(6),
|
|
73
|
+
xl: this.createSpacing(8),
|
|
74
|
+
'2xl': this.createSpacing(10),
|
|
75
|
+
'3xl': this.createSpacing(12),
|
|
76
|
+
'4xl': this.createSpacing(16),
|
|
77
|
+
},
|
|
78
|
+
typography: {
|
|
79
|
+
h1: this.createTypography('4xl', 'tight', 'bold'),
|
|
80
|
+
h2: this.createTypography('3xl', 'tight', 'bold'),
|
|
81
|
+
h3: this.createTypography('2xl', 'snug', 'semibold'),
|
|
82
|
+
body: this.createTypography('base', 'relaxed', 'normal'),
|
|
83
|
+
label: this.createTypography('sm', 'normal', 'medium'),
|
|
84
|
+
caption: this.createTypography('xs', 'normal', 'normal'),
|
|
85
|
+
},
|
|
86
|
+
colors: this.createColorPalette(),
|
|
87
|
+
breakpoints: {
|
|
88
|
+
sm: this.createBreakpoint('sm'),
|
|
89
|
+
md: this.createBreakpoint('md'),
|
|
90
|
+
lg: this.createBreakpoint('lg'),
|
|
91
|
+
xl: this.createBreakpoint('xl'),
|
|
92
|
+
'2xl': this.createBreakpoint('2xl'),
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Switch theme
|
|
99
|
+
*/
|
|
100
|
+
setTheme(theme: ThemeMode): void {
|
|
101
|
+
const strategy = theme === 'light' ? new LightColorStrategy() : new DarkColorStrategy();
|
|
102
|
+
this.colorFactory.setStrategy(strategy);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Default factory instance (light theme)
|
|
108
|
+
*/
|
|
109
|
+
export const defaultTokensFactory = new TokensFactory('light');
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Helper function to create token set
|
|
113
|
+
*/
|
|
114
|
+
export function createTokenSet(theme: ThemeMode = 'light'): TokenSet {
|
|
115
|
+
const factory = new TokensFactory(theme);
|
|
116
|
+
return factory.createTokenSet();
|
|
117
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typography Tokens
|
|
3
|
+
*
|
|
4
|
+
* Centralized typography system with font families, sizes, weights, and line heights.
|
|
5
|
+
* Uses Factory Pattern for type-safe token creation.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type FontFamily = 'sans' | 'serif' | 'mono';
|
|
9
|
+
export type FontWeight = 'light' | 'normal' | 'medium' | 'semibold' | 'bold';
|
|
10
|
+
export type FontSize = 'xs' | 'sm' | 'base' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | '6xl';
|
|
11
|
+
export type LineHeight = 'none' | 'tight' | 'snug' | 'normal' | 'relaxed' | 'loose';
|
|
12
|
+
|
|
13
|
+
export interface TypographyToken {
|
|
14
|
+
fontSize: {
|
|
15
|
+
value: number;
|
|
16
|
+
rem: string;
|
|
17
|
+
px: string;
|
|
18
|
+
tailwind: string;
|
|
19
|
+
};
|
|
20
|
+
lineHeight: {
|
|
21
|
+
value: number;
|
|
22
|
+
tailwind: string;
|
|
23
|
+
};
|
|
24
|
+
fontWeight: {
|
|
25
|
+
value: number;
|
|
26
|
+
tailwind: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface FontFamilyToken {
|
|
31
|
+
name: string;
|
|
32
|
+
stack: string;
|
|
33
|
+
tailwind: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface FontWeightToken {
|
|
37
|
+
value: number;
|
|
38
|
+
tailwind: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Typography Token Factory
|
|
43
|
+
* Creates typography tokens with consistent values
|
|
44
|
+
*/
|
|
45
|
+
export class TypographyTokenFactory {
|
|
46
|
+
/**
|
|
47
|
+
* Create font size token
|
|
48
|
+
*/
|
|
49
|
+
static createFontSize(size: FontSize): TypographyToken['fontSize'] {
|
|
50
|
+
const sizeMap: Record<FontSize, { px: number; tailwind: string }> = {
|
|
51
|
+
xs: { px: 12, tailwind: 'text-xs' },
|
|
52
|
+
sm: { px: 14, tailwind: 'text-sm' },
|
|
53
|
+
base: { px: 16, tailwind: 'text-base' },
|
|
54
|
+
lg: { px: 18, tailwind: 'text-lg' },
|
|
55
|
+
xl: { px: 20, tailwind: 'text-xl' },
|
|
56
|
+
'2xl': { px: 24, tailwind: 'text-2xl' },
|
|
57
|
+
'3xl': { px: 30, tailwind: 'text-3xl' },
|
|
58
|
+
'4xl': { px: 36, tailwind: 'text-4xl' },
|
|
59
|
+
'5xl': { px: 48, tailwind: 'text-5xl' },
|
|
60
|
+
'6xl': { px: 60, tailwind: 'text-6xl' },
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const config = sizeMap[size];
|
|
64
|
+
return {
|
|
65
|
+
value: config.px,
|
|
66
|
+
rem: `${config.px / 16}rem`,
|
|
67
|
+
px: `${config.px}px`,
|
|
68
|
+
tailwind: config.tailwind,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Create line height token
|
|
74
|
+
*/
|
|
75
|
+
static createLineHeight(height: LineHeight): TypographyToken['lineHeight'] {
|
|
76
|
+
const heightMap: Record<LineHeight, { value: number; tailwind: string }> = {
|
|
77
|
+
none: { value: 1, tailwind: 'leading-none' },
|
|
78
|
+
tight: { value: 1.25, tailwind: 'leading-tight' },
|
|
79
|
+
snug: { value: 1.375, tailwind: 'leading-snug' },
|
|
80
|
+
normal: { value: 1.5, tailwind: 'leading-normal' },
|
|
81
|
+
relaxed: { value: 1.625, tailwind: 'leading-relaxed' },
|
|
82
|
+
loose: { value: 2, tailwind: 'leading-loose' },
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const config = heightMap[height];
|
|
86
|
+
return {
|
|
87
|
+
value: config.value,
|
|
88
|
+
tailwind: config.tailwind,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Create font weight token
|
|
94
|
+
*/
|
|
95
|
+
static createFontWeight(weight: FontWeight): FontWeightToken {
|
|
96
|
+
const weightMap: Record<FontWeight, { value: number; tailwind: string }> = {
|
|
97
|
+
light: { value: 300, tailwind: 'font-light' },
|
|
98
|
+
normal: { value: 400, tailwind: 'font-normal' },
|
|
99
|
+
medium: { value: 500, tailwind: 'font-medium' },
|
|
100
|
+
semibold: { value: 600, tailwind: 'font-semibold' },
|
|
101
|
+
bold: { value: 700, tailwind: 'font-bold' },
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const config = weightMap[weight];
|
|
105
|
+
return {
|
|
106
|
+
value: config.value,
|
|
107
|
+
tailwind: config.tailwind,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Create complete typography token
|
|
113
|
+
*/
|
|
114
|
+
static create(size: FontSize, lineHeight: LineHeight = 'normal', weight: FontWeight = 'normal'): TypographyToken {
|
|
115
|
+
return {
|
|
116
|
+
fontSize: this.createFontSize(size),
|
|
117
|
+
lineHeight: this.createLineHeight(lineHeight),
|
|
118
|
+
fontWeight: this.createFontWeight(weight),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Font family tokens
|
|
125
|
+
*/
|
|
126
|
+
export const FONT_FAMILY_TOKENS: Record<FontFamily, FontFamilyToken> = {
|
|
127
|
+
sans: {
|
|
128
|
+
name: 'sans',
|
|
129
|
+
stack: 'ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif',
|
|
130
|
+
tailwind: 'font-sans',
|
|
131
|
+
},
|
|
132
|
+
serif: {
|
|
133
|
+
name: 'serif',
|
|
134
|
+
stack: 'ui-serif, Georgia, Cambria, "Times New Roman", Times, serif',
|
|
135
|
+
tailwind: 'font-serif',
|
|
136
|
+
},
|
|
137
|
+
mono: {
|
|
138
|
+
name: 'mono',
|
|
139
|
+
stack: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
|
|
140
|
+
tailwind: 'font-mono',
|
|
141
|
+
},
|
|
142
|
+
} as const;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Font weight tokens
|
|
146
|
+
*/
|
|
147
|
+
export const FONT_WEIGHT_TOKENS: Record<FontWeight, FontWeightToken> = {
|
|
148
|
+
light: TypographyTokenFactory.createFontWeight('light'),
|
|
149
|
+
normal: TypographyTokenFactory.createFontWeight('normal'),
|
|
150
|
+
medium: TypographyTokenFactory.createFontWeight('medium'),
|
|
151
|
+
semibold: TypographyTokenFactory.createFontWeight('semibold'),
|
|
152
|
+
bold: TypographyTokenFactory.createFontWeight('bold'),
|
|
153
|
+
} as const;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Pre-defined typography tokens for common use cases
|
|
157
|
+
*/
|
|
158
|
+
export const TYPOGRAPHY_TOKENS = {
|
|
159
|
+
// Headings
|
|
160
|
+
h1: TypographyTokenFactory.create('4xl', 'tight', 'bold'),
|
|
161
|
+
h2: TypographyTokenFactory.create('3xl', 'tight', 'bold'),
|
|
162
|
+
h3: TypographyTokenFactory.create('2xl', 'snug', 'semibold'),
|
|
163
|
+
h4: TypographyTokenFactory.create('xl', 'snug', 'semibold'),
|
|
164
|
+
h5: TypographyTokenFactory.create('lg', 'normal', 'medium'),
|
|
165
|
+
h6: TypographyTokenFactory.create('base', 'normal', 'medium'),
|
|
166
|
+
|
|
167
|
+
// Body text
|
|
168
|
+
body: TypographyTokenFactory.create('base', 'relaxed', 'normal'),
|
|
169
|
+
bodySmall: TypographyTokenFactory.create('sm', 'relaxed', 'normal'),
|
|
170
|
+
bodyLarge: TypographyTokenFactory.create('lg', 'relaxed', 'normal'),
|
|
171
|
+
|
|
172
|
+
// UI elements
|
|
173
|
+
label: TypographyTokenFactory.create('sm', 'normal', 'medium'),
|
|
174
|
+
caption: TypographyTokenFactory.create('xs', 'normal', 'normal'),
|
|
175
|
+
button: TypographyTokenFactory.create('base', 'normal', 'medium'),
|
|
176
|
+
} as const;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Helper function to get typography token
|
|
180
|
+
*/
|
|
181
|
+
export function getTypography(variant: keyof typeof TYPOGRAPHY_TOKENS): TypographyToken {
|
|
182
|
+
return TYPOGRAPHY_TOKENS[variant];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Helper function to get typography classes as string
|
|
187
|
+
*/
|
|
188
|
+
export function getTypographyClasses(variant: keyof typeof TYPOGRAPHY_TOKENS): string {
|
|
189
|
+
const token = TYPOGRAPHY_TOKENS[variant];
|
|
190
|
+
return `${token.fontSize.tailwind} ${token.lineHeight.tailwind} ${token.fontWeight.tailwind}`;
|
|
191
|
+
}
|