@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,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-design-system",
3
- "version": "2.9.0",
3
+ "version": "3.0.0",
4
4
  "private": false,
5
5
  "description": "Web Design System - Atomic Design components (Atoms, Molecules, Organisms, Templates) for React applications",
6
6
  "main": "./src/index.ts",
@@ -1,245 +1,224 @@
1
1
  /**
2
- * Responsive Design Tokens
3
- * @description Centralized mapping of size variants to Tailwind spacing scale values
2
+ * Responsive Design Tokens (Formula-Based)
3
+ * @description Centralized responsive scale generation using formulas
4
4
  *
5
- * Scale values align with Tailwind's default spacing scale:
6
- * 3=12px, 4=16px, 5=20px, 6=24px, 8=32px, 10=40px, 12=48px, 16=64px, 20=80px
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
- * All responsive calculations are centralized here - components should NOT
9
- * define their own size styles or do any spacing calculations.
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
- * Spacing scale values for padding, margin, and gap
18
- * Format: Tailwind spacing unit numbers (as strings for easier concatenation)
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
- export type SpacingScale = keyof typeof SPACING_SCALE;
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
- * Responsive spacing mapping by size variant and breakpoint
24
- */
25
- export const RESPONSIVE_SPACING: Record<
26
- SizeVariant,
27
- Partial<Record<Breakpoint, SpacingScale>>
28
- > = {
29
- xs: {
30
- xs: SPACING_SCALE['2'],
31
- sm: SPACING_SCALE['3'],
32
- md: SPACING_SCALE['3'],
33
- lg: SPACING_SCALE['4'],
34
- xl: SPACING_SCALE['4'],
35
- '2xl': SPACING_SCALE['5'],
36
- },
37
- sm: {
38
- xs: SPACING_SCALE['3'],
39
- sm: SPACING_SCALE['4'],
40
- md: SPACING_SCALE['4'],
41
- lg: SPACING_SCALE['5'],
42
- xl: SPACING_SCALE['6'],
43
- '2xl': SPACING_SCALE['8'],
44
- },
45
- md: {
46
- xs: SPACING_SCALE['4'],
47
- sm: SPACING_SCALE['5'],
48
- md: SPACING_SCALE['5'],
49
- lg: SPACING_SCALE['6'],
50
- xl: SPACING_SCALE['8'],
51
- '2xl': SPACING_SCALE['10'],
52
- },
53
- lg: {
54
- xs: SPACING_SCALE['5'],
55
- sm: SPACING_SCALE['6'],
56
- md: SPACING_SCALE['6'],
57
- lg: SPACING_SCALE['8'],
58
- xl: SPACING_SCALE['10'],
59
- '2xl': SPACING_SCALE['12'],
60
- },
61
- xl: {
62
- xs: SPACING_SCALE['6'],
63
- sm: SPACING_SCALE['8'],
64
- md: SPACING_SCALE['8'],
65
- lg: SPACING_SCALE['10'],
66
- xl: SPACING_SCALE['12'],
67
- '2xl': SPACING_SCALE['16'],
68
- },
69
- } as const;
70
-
71
- /**
72
- * Icon size scale values (height/width)
73
- */
74
- export const RESPONSIVE_ICON_SIZE: Record<
75
- SizeVariant,
76
- Partial<Record<Breakpoint, SpacingScale>>
77
- > = {
78
- xs: {
79
- xs: SPACING_SCALE['3'],
80
- sm: SPACING_SCALE['4'],
81
- md: SPACING_SCALE['5'],
82
- lg: SPACING_SCALE['5'],
83
- xl: SPACING_SCALE['6'],
84
- '2xl': SPACING_SCALE['7'],
85
- },
86
- sm: {
87
- xs: SPACING_SCALE['4'],
88
- sm: SPACING_SCALE['5'],
89
- md: SPACING_SCALE['6'],
90
- lg: SPACING_SCALE['6'],
91
- xl: SPACING_SCALE['8'],
92
- '2xl': SPACING_SCALE['8'],
93
- },
94
- md: {
95
- xs: SPACING_SCALE['5'],
96
- sm: SPACING_SCALE['6'],
97
- md: SPACING_SCALE['7'],
98
- lg: SPACING_SCALE['8'],
99
- xl: SPACING_SCALE['9'],
100
- '2xl': SPACING_SCALE['10'],
101
- },
102
- lg: {
103
- xs: SPACING_SCALE['6'],
104
- sm: SPACING_SCALE['7'],
105
- md: SPACING_SCALE['8'],
106
- lg: SPACING_SCALE['9'],
107
- xl: SPACING_SCALE['10'],
108
- '2xl': SPACING_SCALE['12'],
109
- },
110
- xl: {
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;