@umituz/web-design-system 2.9.0 → 3.0.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/package.json
CHANGED
|
@@ -1,245 +1,224 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Responsive Design Tokens
|
|
3
|
-
* @description Centralized
|
|
2
|
+
* Responsive Design Tokens (Formula-Based)
|
|
3
|
+
* @description Centralized responsive scale generation using formulas
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* All responsive values are generated dynamically from base values and formulas.
|
|
6
|
+
* This provides ZERO code duplication and single source of truth.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* To modify responsive behavior:
|
|
9
|
+
* 1. Change base values (BASE_* constants)
|
|
10
|
+
* 2. Modify formula functions (*Formula)
|
|
11
|
+
* 3. Entire system updates automatically
|
|
10
12
|
*/
|
|
11
13
|
|
|
12
14
|
import type { SizeVariant, Breakpoint } from '../types';
|
|
13
15
|
import { SPACING_SCALE } from '../../infrastructure/constants/spacing.constants';
|
|
14
|
-
import { TEXT_SIZES } from '../../infrastructure/constants/typography.constants';
|
|
16
|
+
import { TEXT_SIZES, type TextSizeKey } from '../../infrastructure/constants/typography.constants';
|
|
17
|
+
import { BREAKPOINT_ORDER } from '../../infrastructure/constants/breakpoint.constants';
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
20
|
+
* Type for scale generation formula
|
|
21
|
+
* Input: base value for size variant, current breakpoint
|
|
22
|
+
* Output: spacing scale index (as number, will be converted to string)
|
|
19
23
|
*/
|
|
20
|
-
|
|
24
|
+
type ScaleFormula = (base: number, breakpoint: Breakpoint) => number;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Type for generator result
|
|
28
|
+
*/
|
|
29
|
+
type ResponsiveScale = Record<SizeVariant, Partial<Record<Breakpoint, string>>>;
|
|
30
|
+
|
|
31
|
+
// ============================================================================
|
|
32
|
+
// BASE VALUES - Single source of truth for size variants
|
|
33
|
+
// ============================================================================
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Base spacing values for each size variant
|
|
37
|
+
* Defines the starting point for responsive spacing calculation
|
|
38
|
+
*/
|
|
39
|
+
const SPACING_BASES: Record<SizeVariant, number> = {
|
|
40
|
+
xs: 1, // SPACING_SCALE['1'] = 4px
|
|
41
|
+
sm: 2, // SPACING_SCALE['2'] = 8px
|
|
42
|
+
md: 3, // SPACING_SCALE['3'] = 12px
|
|
43
|
+
lg: 4, // SPACING_SCALE['4'] = 16px
|
|
44
|
+
xl: 5, // SPACING_SCALE['5'] = 20px
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Base icon size values for each size variant
|
|
49
|
+
*/
|
|
50
|
+
const ICON_BASES: Record<SizeVariant, number> = {
|
|
51
|
+
xs: 4,
|
|
52
|
+
sm: 5,
|
|
53
|
+
md: 6,
|
|
54
|
+
lg: 8,
|
|
55
|
+
xl: 10,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Base container size values (for icon wrappers)
|
|
60
|
+
*/
|
|
61
|
+
const CONTAINER_BASES: Record<SizeVariant, number> = {
|
|
62
|
+
xs: 6,
|
|
63
|
+
sm: 8,
|
|
64
|
+
md: 10,
|
|
65
|
+
lg: 12,
|
|
66
|
+
xl: 14,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Base gap/spacing values for layout
|
|
71
|
+
*/
|
|
72
|
+
const GAP_BASES: Record<SizeVariant, number> = {
|
|
73
|
+
xs: 1,
|
|
74
|
+
sm: 2,
|
|
75
|
+
md: 3,
|
|
76
|
+
lg: 4,
|
|
77
|
+
xl: 5,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// ============================================================================
|
|
81
|
+
// FORMULAS - Define responsive behavior for each token type
|
|
82
|
+
// ============================================================================
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Spacing formula for padding, margin, gap
|
|
86
|
+
* Progression: xs/sm→base, md/lg→base+1, xl→base+2, 2xl→base+3
|
|
87
|
+
*/
|
|
88
|
+
const spacingFormula: ScaleFormula = (base, bp) => {
|
|
89
|
+
const bpIndex = BREAKPOINT_ORDER.indexOf(bp);
|
|
90
|
+
if (bpIndex <= 1) return base; // xs, sm
|
|
91
|
+
if (bpIndex <= 3) return base + 1; // md, lg
|
|
92
|
+
if (bpIndex === 4) return base + 2; // xl
|
|
93
|
+
return base + 3; // 2xl
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Icon size formula
|
|
98
|
+
* Progression: More gradual increase across breakpoints
|
|
99
|
+
*/
|
|
100
|
+
const iconFormula: ScaleFormula = (base, bp) => {
|
|
101
|
+
const bpIndex = BREAKPOINT_ORDER.indexOf(bp);
|
|
102
|
+
if (bp === 'xs') return base - 1;
|
|
103
|
+
if (bp === 'sm') return base;
|
|
104
|
+
if (bp === 'md') return base + 1;
|
|
105
|
+
if (bp === 'lg') return base + 2;
|
|
106
|
+
if (bp === 'xl') return base + 3;
|
|
107
|
+
return base + 3; // 2xl
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Container size formula (for icon wrappers)
|
|
112
|
+
* Consistent size increase
|
|
113
|
+
*/
|
|
114
|
+
const containerFormula: ScaleFormula = (base, bp) => {
|
|
115
|
+
const bpIndex = BREAKPOINT_ORDER.indexOf(bp);
|
|
116
|
+
if (bpIndex <= 3) return base + 2; // xs, sm, md, lg
|
|
117
|
+
if (bpIndex === 4) return base + 2; // xl
|
|
118
|
+
return base + 2; // 2xl
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Gap formula for layout spacing
|
|
123
|
+
*/
|
|
124
|
+
const gapFormula: ScaleFormula = (base, bp) => {
|
|
125
|
+
const bpIndex = BREAKPOINT_ORDER.indexOf(bp);
|
|
126
|
+
if (bpIndex <= 1) return base; // xs, sm
|
|
127
|
+
if (bpIndex <= 3) return base + 1; // md, lg
|
|
128
|
+
if (bpIndex === 4) return base + 1; // xl
|
|
129
|
+
return base + 2; // 2xl
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// ============================================================================
|
|
133
|
+
// GENERATORS - Create responsive scales dynamically
|
|
134
|
+
// ============================================================================
|
|
21
135
|
|
|
22
136
|
/**
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
'
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
SizeVariant,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
xs: SPACING_SCALE['8'],
|
|
112
|
-
sm: SPACING_SCALE['9'],
|
|
113
|
-
md: SPACING_SCALE['10'],
|
|
114
|
-
lg: SPACING_SCALE['12'],
|
|
115
|
-
xl: SPACING_SCALE['14'],
|
|
116
|
-
'2xl': SPACING_SCALE['16'],
|
|
117
|
-
},
|
|
118
|
-
} as const;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Container/icon wrapper size (for rounded containers that hold icons)
|
|
122
|
-
*/
|
|
123
|
-
export const RESPONSIVE_CONTAINER_SIZE: Record<
|
|
124
|
-
SizeVariant,
|
|
125
|
-
Partial<Record<Breakpoint, SpacingScale>>
|
|
126
|
-
> = {
|
|
127
|
-
xs: {
|
|
128
|
-
xs: SPACING_SCALE['6'],
|
|
129
|
-
sm: SPACING_SCALE['8'],
|
|
130
|
-
md: SPACING_SCALE['8'],
|
|
131
|
-
lg: SPACING_SCALE['10'],
|
|
132
|
-
xl: SPACING_SCALE['10'],
|
|
133
|
-
'2xl': SPACING_SCALE['12'],
|
|
134
|
-
},
|
|
135
|
-
sm: {
|
|
136
|
-
xs: SPACING_SCALE['8'],
|
|
137
|
-
sm: SPACING_SCALE['10'],
|
|
138
|
-
md: SPACING_SCALE['10'],
|
|
139
|
-
lg: SPACING_SCALE['12'],
|
|
140
|
-
xl: SPACING_SCALE['12'],
|
|
141
|
-
'2xl': SPACING_SCALE['14'],
|
|
142
|
-
},
|
|
143
|
-
md: {
|
|
144
|
-
xs: SPACING_SCALE['10'],
|
|
145
|
-
sm: SPACING_SCALE['12'],
|
|
146
|
-
md: SPACING_SCALE['12'],
|
|
147
|
-
lg: SPACING_SCALE['14'],
|
|
148
|
-
xl: SPACING_SCALE['14'],
|
|
149
|
-
'2xl': SPACING_SCALE['16'],
|
|
150
|
-
},
|
|
151
|
-
lg: {
|
|
152
|
-
xs: SPACING_SCALE['12'],
|
|
153
|
-
sm: SPACING_SCALE['14'],
|
|
154
|
-
md: SPACING_SCALE['14'],
|
|
155
|
-
lg: SPACING_SCALE['16'],
|
|
156
|
-
xl: SPACING_SCALE['16'],
|
|
157
|
-
'2xl': SPACING_SCALE['20'],
|
|
158
|
-
},
|
|
159
|
-
xl: {
|
|
160
|
-
xs: SPACING_SCALE['14'],
|
|
161
|
-
sm: SPACING_SCALE['16'],
|
|
162
|
-
md: SPACING_SCALE['16'],
|
|
163
|
-
lg: SPACING_SCALE['20'],
|
|
164
|
-
xl: SPACING_SCALE['20'],
|
|
165
|
-
'2xl': SPACING_SCALE['24'],
|
|
166
|
-
},
|
|
167
|
-
} as const;
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Text size scale (Tailwind text utilities)
|
|
171
|
-
*/
|
|
172
|
-
export const RESPONSIVE_TEXT_SIZE: Record<
|
|
173
|
-
SizeVariant,
|
|
174
|
-
Partial<Record<'mobile' | 'tablet', string>>
|
|
175
|
-
> = {
|
|
176
|
-
xs: {
|
|
177
|
-
mobile: TEXT_SIZES.xs,
|
|
178
|
-
tablet: `sm:${TEXT_SIZES.xs}`,
|
|
179
|
-
},
|
|
180
|
-
sm: {
|
|
181
|
-
mobile: TEXT_SIZES.xs,
|
|
182
|
-
tablet: `sm:${TEXT_SIZES.sm}`,
|
|
183
|
-
},
|
|
184
|
-
md: {
|
|
185
|
-
mobile: TEXT_SIZES.sm,
|
|
186
|
-
tablet: `sm:${TEXT_SIZES.base}`,
|
|
187
|
-
},
|
|
188
|
-
lg: {
|
|
189
|
-
mobile: TEXT_SIZES.base,
|
|
190
|
-
tablet: `sm:${TEXT_SIZES.lg}`,
|
|
191
|
-
},
|
|
192
|
-
xl: {
|
|
193
|
-
mobile: TEXT_SIZES.lg,
|
|
194
|
-
tablet: `sm:${TEXT_SIZES.xl}`,
|
|
195
|
-
},
|
|
196
|
-
} as const;
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Gap/Spacing between elements (space-y-*, space-x-*, gap-*)
|
|
200
|
-
*/
|
|
201
|
-
export const RESPONSIVE_GAP: Record<
|
|
202
|
-
SizeVariant,
|
|
203
|
-
Partial<Record<Breakpoint, SpacingScale>>
|
|
204
|
-
> = {
|
|
205
|
-
xs: {
|
|
206
|
-
xs: SPACING_SCALE['1'],
|
|
207
|
-
sm: SPACING_SCALE['2'],
|
|
208
|
-
md: SPACING_SCALE['2'],
|
|
209
|
-
lg: SPACING_SCALE['3'],
|
|
210
|
-
xl: SPACING_SCALE['3'],
|
|
211
|
-
'2xl': SPACING_SCALE['4'],
|
|
212
|
-
},
|
|
213
|
-
sm: {
|
|
214
|
-
xs: SPACING_SCALE['2'],
|
|
215
|
-
sm: SPACING_SCALE['3'],
|
|
216
|
-
md: SPACING_SCALE['3'],
|
|
217
|
-
lg: SPACING_SCALE['4'],
|
|
218
|
-
xl: SPACING_SCALE['4'],
|
|
219
|
-
'2xl': SPACING_SCALE['5'],
|
|
220
|
-
},
|
|
221
|
-
md: {
|
|
222
|
-
xs: SPACING_SCALE['3'],
|
|
223
|
-
sm: SPACING_SCALE['4'],
|
|
224
|
-
md: SPACING_SCALE['4'],
|
|
225
|
-
lg: SPACING_SCALE['5'],
|
|
226
|
-
xl: SPACING_SCALE['5'],
|
|
227
|
-
'2xl': SPACING_SCALE['6'],
|
|
228
|
-
},
|
|
229
|
-
lg: {
|
|
230
|
-
xs: SPACING_SCALE['4'],
|
|
231
|
-
sm: SPACING_SCALE['5'],
|
|
232
|
-
md: SPACING_SCALE['5'],
|
|
233
|
-
lg: SPACING_SCALE['6'],
|
|
234
|
-
xl: SPACING_SCALE['6'],
|
|
235
|
-
'2xl': SPACING_SCALE['8'],
|
|
236
|
-
},
|
|
237
|
-
xl: {
|
|
238
|
-
xs: SPACING_SCALE['5'],
|
|
239
|
-
sm: SPACING_SCALE['6'],
|
|
240
|
-
md: SPACING_SCALE['6'],
|
|
241
|
-
lg: SPACING_SCALE['8'],
|
|
242
|
-
xl: SPACING_SCALE['8'],
|
|
243
|
-
'2xl': SPACING_SCALE['10'],
|
|
244
|
-
},
|
|
245
|
-
} as const;
|
|
137
|
+
* Generate responsive scale for any token type
|
|
138
|
+
* @param bases - Base values for each size variant
|
|
139
|
+
* @param formula - Formula to calculate value at each breakpoint
|
|
140
|
+
* @returns Complete responsive scale object
|
|
141
|
+
*/
|
|
142
|
+
function generateResponsiveScale(
|
|
143
|
+
bases: Record<SizeVariant, number>,
|
|
144
|
+
formula: ScaleFormula
|
|
145
|
+
): ResponsiveScale {
|
|
146
|
+
const result: Partial<ResponsiveScale> = {};
|
|
147
|
+
|
|
148
|
+
for (const size of Object.keys(bases) as SizeVariant[]) {
|
|
149
|
+
const base = bases[size];
|
|
150
|
+
result[size] = {};
|
|
151
|
+
|
|
152
|
+
for (const bp of BREAKPOINT_ORDER) {
|
|
153
|
+
const scaleIndex = formula(base, bp);
|
|
154
|
+
const scaleKey = scaleIndex.toString() as keyof typeof SPACING_SCALE;
|
|
155
|
+
|
|
156
|
+
// Validate and get spacing scale value
|
|
157
|
+
if (scaleKey in SPACING_SCALE) {
|
|
158
|
+
result[size]![bp] = SPACING_SCALE[scaleKey];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return result as ResponsiveScale;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Generate responsive text sizes
|
|
168
|
+
* Text sizes use string literals, not spacing scale
|
|
169
|
+
*/
|
|
170
|
+
function generateResponsiveTextSizes() {
|
|
171
|
+
const textSizeKeys: Record<SizeVariant, { mobile: TextSizeKey; tablet: TextSizeKey }> = {
|
|
172
|
+
xs: { mobile: 'xs', tablet: 'xs' },
|
|
173
|
+
sm: { mobile: 'xs', tablet: 'sm' },
|
|
174
|
+
md: { mobile: 'sm', tablet: 'base' },
|
|
175
|
+
lg: { mobile: 'base', tablet: 'lg' },
|
|
176
|
+
xl: { mobile: 'lg', tablet: 'xl' },
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const result: Partial<Record<SizeVariant, Partial<Record<'mobile' | 'tablet', string>>>> = {};
|
|
180
|
+
|
|
181
|
+
for (const size of Object.keys(textSizeKeys) as SizeVariant[]) {
|
|
182
|
+
const keys = textSizeKeys[size];
|
|
183
|
+
result[size] = {
|
|
184
|
+
mobile: TEXT_SIZES[keys.mobile],
|
|
185
|
+
tablet: `sm:${TEXT_SIZES[keys.tablet]}`,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return result as Record<SizeVariant, Partial<Record<'mobile' | 'tablet', string>>>;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// ============================================================================
|
|
193
|
+
// EXPORTS - All responsive tokens (one line each!)
|
|
194
|
+
// ============================================================================
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Responsive spacing scale for padding, margin, space-*, gap-*
|
|
198
|
+
*/
|
|
199
|
+
export const RESPONSIVE_SPACING = generateResponsiveScale(SPACING_BASES, spacingFormula);
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Responsive icon sizes (height/width)
|
|
203
|
+
*/
|
|
204
|
+
export const RESPONSIVE_ICON_SIZE = generateResponsiveScale(ICON_BASES, iconFormula);
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Responsive container sizes for icon wrappers
|
|
208
|
+
*/
|
|
209
|
+
export const RESPONSIVE_CONTAINER_SIZE = generateResponsiveScale(CONTAINER_BASES, containerFormula);
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Responsive gap/spacing for layouts
|
|
213
|
+
*/
|
|
214
|
+
export const RESPONSIVE_GAP = generateResponsiveScale(GAP_BASES, gapFormula);
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Responsive text sizes (mobile + tablet)
|
|
218
|
+
*/
|
|
219
|
+
export const RESPONSIVE_TEXT_SIZE = generateResponsiveTextSizes();
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Type exports
|
|
223
|
+
*/
|
|
224
|
+
export type SpacingScale = keyof typeof SPACING_SCALE;
|