@umituz/react-native-design-system 1.14.0 → 2.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 +26 -19
- package/src/atoms/AtomicAvatar.tsx +161 -0
- package/src/atoms/AtomicButton.tsx +241 -0
- package/src/atoms/AtomicChip.tsx +226 -0
- package/src/atoms/AtomicDatePicker.tsx +255 -0
- package/src/atoms/AtomicFab.tsx +99 -0
- package/src/atoms/AtomicIcon.tsx +149 -0
- package/src/atoms/AtomicInput.tsx +308 -0
- package/src/atoms/AtomicPicker.tsx +310 -0
- package/src/atoms/AtomicProgress.tsx +149 -0
- package/src/atoms/AtomicText.tsx +55 -0
- package/src/atoms/__tests__/AtomicButton.test.tsx +107 -0
- package/src/atoms/__tests__/AtomicIcon.test.tsx +110 -0
- package/src/atoms/__tests__/AtomicInput.test.tsx +195 -0
- package/src/atoms/datepicker/components/DatePickerButton.tsx +112 -0
- package/src/atoms/datepicker/components/DatePickerModal.tsx +143 -0
- package/src/atoms/fab/styles/fabStyles.ts +98 -0
- package/src/atoms/fab/types/index.ts +88 -0
- package/src/atoms/index.ts +70 -0
- package/src/atoms/input/hooks/useInputState.ts +63 -0
- package/src/atoms/input/styles/inputStylesHelper.ts +120 -0
- package/src/atoms/picker/components/PickerChips.tsx +57 -0
- package/src/atoms/picker/components/PickerModal.tsx +214 -0
- package/src/atoms/picker/styles/pickerStyles.ts +223 -0
- package/src/atoms/picker/types/index.ts +42 -0
- package/src/index.ts +148 -79
- package/src/molecules/ConfirmationModal.tsx +42 -0
- package/src/molecules/ConfirmationModalContent.tsx +87 -0
- package/src/molecules/ConfirmationModalMain.tsx +91 -0
- package/src/molecules/FormField.tsx +155 -0
- package/src/molecules/IconContainer.tsx +79 -0
- package/src/molecules/ListItem.tsx +35 -0
- package/src/molecules/ScreenHeader.tsx +171 -0
- package/src/molecules/SearchBar.tsx +198 -0
- package/src/molecules/confirmation-modal/components.tsx +94 -0
- package/src/molecules/confirmation-modal/index.ts +7 -0
- package/src/molecules/confirmation-modal/styles/confirmationModalStyles.ts +133 -0
- package/src/molecules/confirmation-modal/types/index.ts +41 -0
- package/src/molecules/confirmation-modal/useConfirmationModal.ts +50 -0
- package/src/molecules/index.ts +19 -0
- package/src/molecules/listitem/index.ts +6 -0
- package/src/molecules/listitem/styles/listItemStyles.ts +37 -0
- package/src/molecules/listitem/types/index.ts +21 -0
- package/src/organisms/AppHeader.tsx +136 -0
- package/src/organisms/FormContainer.tsx +169 -0
- package/src/organisms/ScreenLayout.tsx +183 -0
- package/src/organisms/index.ts +31 -0
- package/src/responsive/config.ts +139 -0
- package/src/responsive/deviceDetection.ts +155 -0
- package/src/responsive/gridUtils.ts +79 -0
- package/src/responsive/index.ts +52 -0
- package/src/responsive/platformConstants.ts +98 -0
- package/src/responsive/responsive.ts +61 -0
- package/src/responsive/responsiveLayout.ts +137 -0
- package/src/responsive/responsiveSizing.ts +134 -0
- package/src/responsive/useResponsive.ts +140 -0
- package/src/responsive/validation.ts +158 -0
- package/src/theme/core/BaseTokens.ts +42 -0
- package/src/theme/core/ColorPalette.ts +29 -0
- package/src/theme/core/CustomColors.ts +122 -0
- package/src/theme/core/NavigationTheme.ts +72 -0
- package/src/theme/core/TokenFactory.ts +103 -0
- package/src/theme/core/colors/ColorUtils.ts +53 -0
- package/src/theme/core/colors/DarkColors.ts +146 -0
- package/src/theme/core/colors/LightColors.ts +146 -0
- package/src/theme/core/constants/DesignConstants.ts +31 -0
- package/src/theme/core/themes.ts +118 -0
- package/src/theme/core/tokens/BaseTokens.ts +144 -0
- package/src/theme/core/tokens/Borders.ts +43 -0
- package/src/theme/core/tokens/Sizes.ts +51 -0
- package/src/theme/core/tokens/Spacing.ts +38 -0
- package/src/theme/core/tokens/Typography.ts +143 -0
- package/src/theme/hooks/useAppDesignTokens.ts +45 -0
- package/src/theme/hooks/useCommonStyles.ts +248 -0
- package/src/theme/hooks/useThemedStyles.ts +68 -0
- package/src/theme/index.ts +94 -0
- package/src/theme/infrastructure/globalThemeStore.ts +69 -0
- package/src/theme/infrastructure/storage/ThemeStorage.ts +93 -0
- package/src/theme/infrastructure/stores/themeStore.ts +109 -0
- package/src/typography/__tests__/colorValidationUtils.test.ts +180 -0
- package/src/typography/__tests__/textColorUtils.test.ts +185 -0
- package/src/typography/__tests__/textStyleUtils.test.ts +168 -0
- package/src/typography/domain/entities/TypographyTypes.ts +88 -0
- package/src/typography/index.ts +53 -0
- package/src/typography/presentation/utils/colorValidationUtils.ts +133 -0
- package/src/typography/presentation/utils/textColorUtils.ts +205 -0
- package/src/typography/presentation/utils/textStyleUtils.ts +159 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text Color Utilities
|
|
3
|
+
*
|
|
4
|
+
* Helper functions for resolving text colors from design tokens.
|
|
5
|
+
* These utilities are used by components like AtomicText to map color variants
|
|
6
|
+
* to actual color values from theme.
|
|
7
|
+
*
|
|
8
|
+
* @fileoverview Provides color resolution utilities for Material Design 3
|
|
9
|
+
* @author Ümit UZ <umit@umituz.com>
|
|
10
|
+
* @since 1.0.0
|
|
11
|
+
* @version 1.2.0
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { getTextColor } from '@umituz/react-native-design-system-typography';
|
|
16
|
+
* import { useAppDesignTokens } from '@umituz/react-native-design-system-theme';
|
|
17
|
+
*
|
|
18
|
+
* const MyComponent = () => {
|
|
19
|
+
* const tokens = useAppDesignTokens();
|
|
20
|
+
* const textColor = getTextColor('textPrimary', tokens);
|
|
21
|
+
* return <Text style={{ color: textColor }}>Hello</Text>;
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import type { ColorVariant } from '../../domain/entities/TypographyTypes';
|
|
27
|
+
import type { DesignTokens } from '../../../theme';
|
|
28
|
+
|
|
29
|
+
// Cache for color variant validation to improve performance
|
|
30
|
+
const COLOR_VARIANT_SET = new Set<string>([
|
|
31
|
+
'textPrimary',
|
|
32
|
+
'textSecondary',
|
|
33
|
+
'textTertiary',
|
|
34
|
+
'textDisabled',
|
|
35
|
+
'textInverse',
|
|
36
|
+
'onSurface',
|
|
37
|
+
'onBackground',
|
|
38
|
+
'onPrimary',
|
|
39
|
+
'onSecondary',
|
|
40
|
+
'onSuccess',
|
|
41
|
+
'onError',
|
|
42
|
+
'onWarning',
|
|
43
|
+
'onInfo',
|
|
44
|
+
'success',
|
|
45
|
+
'error',
|
|
46
|
+
'warning',
|
|
47
|
+
'info',
|
|
48
|
+
'primary',
|
|
49
|
+
'secondary',
|
|
50
|
+
'tertiary',
|
|
51
|
+
'disabled',
|
|
52
|
+
'inverse',
|
|
53
|
+
'surfaceVariant',
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Color mapper interface for dependency injection
|
|
58
|
+
*/
|
|
59
|
+
interface ColorMapper {
|
|
60
|
+
getColor(color: ColorVariant, tokens: DesignTokens): string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Material Design 3 color mapper implementation
|
|
65
|
+
*/
|
|
66
|
+
class MaterialColorMapper implements ColorMapper {
|
|
67
|
+
getColor(color: ColorVariant, tokens: DesignTokens): string {
|
|
68
|
+
switch (color) {
|
|
69
|
+
// General text colors (Material Design 3)
|
|
70
|
+
case 'textPrimary':
|
|
71
|
+
return tokens.colors.textPrimary;
|
|
72
|
+
case 'textSecondary':
|
|
73
|
+
return tokens.colors.textSecondary;
|
|
74
|
+
case 'textTertiary':
|
|
75
|
+
return tokens.colors.textTertiary;
|
|
76
|
+
case 'textDisabled':
|
|
77
|
+
return tokens.colors.textDisabled;
|
|
78
|
+
case 'textInverse':
|
|
79
|
+
return tokens.colors.textInverse;
|
|
80
|
+
|
|
81
|
+
// Text on surfaces (Material Design 3)
|
|
82
|
+
case 'onSurface':
|
|
83
|
+
return tokens.colors.onSurface;
|
|
84
|
+
case 'onBackground':
|
|
85
|
+
return tokens.colors.onBackground;
|
|
86
|
+
|
|
87
|
+
// Text on colored backgrounds (Material Design 3)
|
|
88
|
+
case 'onPrimary':
|
|
89
|
+
return tokens.colors.onPrimary;
|
|
90
|
+
case 'onSecondary':
|
|
91
|
+
return tokens.colors.onSecondary;
|
|
92
|
+
case 'onSuccess':
|
|
93
|
+
return tokens.colors.onSuccess;
|
|
94
|
+
case 'onError':
|
|
95
|
+
return tokens.colors.onError;
|
|
96
|
+
case 'onWarning':
|
|
97
|
+
return tokens.colors.onWarning;
|
|
98
|
+
case 'onInfo':
|
|
99
|
+
return tokens.colors.onInfo;
|
|
100
|
+
|
|
101
|
+
// Semantic colors (can be used as text)
|
|
102
|
+
case 'success':
|
|
103
|
+
return tokens.colors.success;
|
|
104
|
+
case 'error':
|
|
105
|
+
return tokens.colors.error;
|
|
106
|
+
case 'warning':
|
|
107
|
+
return tokens.colors.warning;
|
|
108
|
+
case 'info':
|
|
109
|
+
return tokens.colors.info;
|
|
110
|
+
|
|
111
|
+
// Legacy support (deprecated - maps to new names)
|
|
112
|
+
case 'primary':
|
|
113
|
+
return tokens.colors.textPrimary;
|
|
114
|
+
case 'secondary':
|
|
115
|
+
return tokens.colors.textSecondary;
|
|
116
|
+
case 'tertiary':
|
|
117
|
+
return tokens.colors.textTertiary;
|
|
118
|
+
case 'disabled':
|
|
119
|
+
return tokens.colors.textDisabled;
|
|
120
|
+
case 'inverse':
|
|
121
|
+
return tokens.colors.textInverse;
|
|
122
|
+
case 'surfaceVariant':
|
|
123
|
+
return tokens.colors.textSecondary;
|
|
124
|
+
|
|
125
|
+
default:
|
|
126
|
+
if (__DEV__) {
|
|
127
|
+
// eslint-disable-next-line no-console
|
|
128
|
+
console.warn(`Unknown color variant: ${color}`);
|
|
129
|
+
}
|
|
130
|
+
return tokens.colors.textPrimary;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Singleton instance for performance
|
|
136
|
+
const colorMapper = new MaterialColorMapper();
|
|
137
|
+
|
|
138
|
+
// Cache for resolved colors to improve performance
|
|
139
|
+
const colorCache = new Map<string, string>();
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Clear the color cache
|
|
143
|
+
* Useful for testing or theme changes
|
|
144
|
+
*/
|
|
145
|
+
export function clearColorCache(): void {
|
|
146
|
+
colorCache.clear();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Get text color from design tokens based on color variant
|
|
151
|
+
*
|
|
152
|
+
* @param color - Color variant or custom color string
|
|
153
|
+
* @param tokens - Design tokens containing color values
|
|
154
|
+
* @returns Resolved color string
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```tsx
|
|
158
|
+
* const tokens = useAppDesignTokens();
|
|
159
|
+
* const textColor = getTextColor('textPrimary', tokens);
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
export function getTextColor(
|
|
163
|
+
color: ColorVariant | string | undefined,
|
|
164
|
+
tokens: DesignTokens,
|
|
165
|
+
): string {
|
|
166
|
+
// Validate tokens parameter
|
|
167
|
+
if (!tokens || !tokens.colors) {
|
|
168
|
+
throw new Error('Invalid design tokens: tokens and tokens.colors are required');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (!color) {
|
|
172
|
+
return tokens.colors.textPrimary;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// If it's a custom color string (not a variant), return as-is
|
|
176
|
+
if (typeof color === 'string' && !isColorVariant(color)) {
|
|
177
|
+
return color;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Create cache key - use hash instead of JSON.stringify to prevent memory leaks
|
|
181
|
+
const cacheKey = `${color}_${Object.keys(tokens.colors).length}_${tokens.colors.textPrimary}`;
|
|
182
|
+
|
|
183
|
+
// Check cache first
|
|
184
|
+
if (colorCache.has(cacheKey)) {
|
|
185
|
+
return colorCache.get(cacheKey)!;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Resolve color and cache it
|
|
189
|
+
const resolvedColor = colorMapper.getColor(color as ColorVariant, tokens);
|
|
190
|
+
colorCache.set(cacheKey, resolvedColor);
|
|
191
|
+
|
|
192
|
+
return resolvedColor;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Check if a string is a valid ColorVariant
|
|
197
|
+
* Uses Set for O(1) lookup performance
|
|
198
|
+
*
|
|
199
|
+
* @param value - String to check
|
|
200
|
+
* @returns True if value is a ColorVariant
|
|
201
|
+
*/
|
|
202
|
+
function isColorVariant(value: string): value is ColorVariant {
|
|
203
|
+
return COLOR_VARIANT_SET.has(value);
|
|
204
|
+
}
|
|
205
|
+
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typography Style Utilities
|
|
3
|
+
*
|
|
4
|
+
* Helper functions for resolving typography styles from design tokens.
|
|
5
|
+
* These utilities are used by components to map text style variants
|
|
6
|
+
* to actual style objects from theme.
|
|
7
|
+
*
|
|
8
|
+
* @fileoverview Provides typography style resolution utilities for Material Design 3
|
|
9
|
+
* @author Ümit UZ <umit@umituz.com>
|
|
10
|
+
* @since 1.2.0
|
|
11
|
+
* @version 1.2.0
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { getTextStyle } from '@umituz/react-native-design-system-typography';
|
|
16
|
+
* import { useAppDesignTokens } from '@umituz/react-native-design-system-theme';
|
|
17
|
+
*
|
|
18
|
+
* const MyComponent = () => {
|
|
19
|
+
* const tokens = useAppDesignTokens();
|
|
20
|
+
* const textStyle = getTextStyle('headlineLarge', tokens);
|
|
21
|
+
* return <Text style={textStyle}>Hello</Text>;
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import type { TextStyle as RNTextStyle } from 'react-native';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Basic text style interface
|
|
30
|
+
* Compatible with React Native TextStyle
|
|
31
|
+
*/
|
|
32
|
+
type TextStyle = RNTextStyle;
|
|
33
|
+
|
|
34
|
+
import type { TextStyleVariant } from '../../domain/entities/TypographyTypes';
|
|
35
|
+
import type { DesignTokens } from '../../../theme';
|
|
36
|
+
|
|
37
|
+
// Cache for text style variant validation to improve performance
|
|
38
|
+
const TEXT_STYLE_VARIANT_SET = new Set<string>([
|
|
39
|
+
'displayLarge',
|
|
40
|
+
'displayMedium',
|
|
41
|
+
'displaySmall',
|
|
42
|
+
'headlineLarge',
|
|
43
|
+
'headlineMedium',
|
|
44
|
+
'headlineSmall',
|
|
45
|
+
'titleLarge',
|
|
46
|
+
'titleMedium',
|
|
47
|
+
'titleSmall',
|
|
48
|
+
'bodyLarge',
|
|
49
|
+
'bodyMedium',
|
|
50
|
+
'bodySmall',
|
|
51
|
+
'labelLarge',
|
|
52
|
+
'labelMedium',
|
|
53
|
+
'labelSmall',
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Typography style mapper interface for dependency injection
|
|
58
|
+
*/
|
|
59
|
+
interface TypographyStyleMapper {
|
|
60
|
+
getStyle(variant: TextStyleVariant, tokens: DesignTokens): TextStyle;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Material Design 3 typography style mapper implementation
|
|
65
|
+
*/
|
|
66
|
+
class MaterialTypographyMapper implements TypographyStyleMapper {
|
|
67
|
+
getStyle(variant: TextStyleVariant, tokens: DesignTokens): TextStyle {
|
|
68
|
+
const style = tokens.typography[variant] || tokens.typography.bodyLarge;
|
|
69
|
+
return style as TextStyle;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Singleton instance for performance
|
|
74
|
+
const typographyMapper = new MaterialTypographyMapper();
|
|
75
|
+
|
|
76
|
+
// Cache for resolved typography styles to improve performance
|
|
77
|
+
const typographyCache = new Map<string, TextStyle>();
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Clear typography cache
|
|
81
|
+
* Useful for testing or theme changes
|
|
82
|
+
*/
|
|
83
|
+
export function clearTypographyCache(): void {
|
|
84
|
+
typographyCache.clear();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Get typography style from design tokens based on text style variant
|
|
89
|
+
*
|
|
90
|
+
* @param variant - Text style variant
|
|
91
|
+
* @param tokens - Design tokens containing typography values
|
|
92
|
+
* @returns Resolved typography style object
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```tsx
|
|
96
|
+
* const tokens = useAppDesignTokens();
|
|
97
|
+
* const textStyle = getTextStyle('headlineLarge', tokens);
|
|
98
|
+
* // Returns: { fontSize: 32, fontWeight: '400' }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export function getTextStyle(
|
|
102
|
+
variant: TextStyleVariant,
|
|
103
|
+
tokens: DesignTokens,
|
|
104
|
+
): TextStyle {
|
|
105
|
+
// Validate tokens parameter
|
|
106
|
+
if (!tokens || !tokens.typography) {
|
|
107
|
+
throw new Error('Invalid design tokens: tokens and tokens.typography are required');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Create cache key - use hash instead of JSON.stringify to prevent memory leaks
|
|
111
|
+
const cacheKey = `${variant}_${Object.keys(tokens.typography).length}_${tokens.typography.bodyLarge?.fontSize || 16}`;
|
|
112
|
+
|
|
113
|
+
// Check cache first
|
|
114
|
+
if (typographyCache.has(cacheKey)) {
|
|
115
|
+
return typographyCache.get(cacheKey)!;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Resolve style and cache it
|
|
119
|
+
const resolvedStyle = typographyMapper.getStyle(variant, tokens);
|
|
120
|
+
typographyCache.set(cacheKey, resolvedStyle);
|
|
121
|
+
|
|
122
|
+
return resolvedStyle;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Check if a string is a valid TextStyleVariant
|
|
127
|
+
* Uses Set for O(1) lookup performance
|
|
128
|
+
*
|
|
129
|
+
* @param value - String to check
|
|
130
|
+
* @returns True if value is a TextStyleVariant
|
|
131
|
+
*/
|
|
132
|
+
export function isTextStyleVariant(value: string): value is TextStyleVariant {
|
|
133
|
+
return TEXT_STYLE_VARIANT_SET.has(value);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Get all available text style variants
|
|
138
|
+
*
|
|
139
|
+
* @returns Array of all TextStyleVariant values
|
|
140
|
+
*/
|
|
141
|
+
export function getAllTextStyleVariants(): TextStyleVariant[] {
|
|
142
|
+
return [
|
|
143
|
+
'displayLarge',
|
|
144
|
+
'displayMedium',
|
|
145
|
+
'displaySmall',
|
|
146
|
+
'headlineLarge',
|
|
147
|
+
'headlineMedium',
|
|
148
|
+
'headlineSmall',
|
|
149
|
+
'titleLarge',
|
|
150
|
+
'titleMedium',
|
|
151
|
+
'titleSmall',
|
|
152
|
+
'bodyLarge',
|
|
153
|
+
'bodyMedium',
|
|
154
|
+
'bodySmall',
|
|
155
|
+
'labelLarge',
|
|
156
|
+
'labelMedium',
|
|
157
|
+
'labelSmall',
|
|
158
|
+
];
|
|
159
|
+
}
|