@umituz/react-native-design-system 2.4.5 → 2.4.7
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/react-native-design-system",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.7",
|
|
4
4
|
"description": "Universal design system for React Native apps - Consolidated package with atoms, molecules, organisms, theme, typography, responsive and safe area utilities",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AtomicSpinner - Universal Loading Spinner Component
|
|
3
|
+
*
|
|
4
|
+
* Displays loading indicators with flexible configuration
|
|
5
|
+
*
|
|
6
|
+
* Atomic Design Level: ATOM
|
|
7
|
+
* Purpose: Loading state indication across all apps
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* - Page loading states
|
|
11
|
+
* - Button loading states
|
|
12
|
+
* - Data fetching indicators
|
|
13
|
+
* - Async operation feedback
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import React from 'react';
|
|
17
|
+
import { View, ActivityIndicator, StyleSheet, ViewStyle } from 'react-native';
|
|
18
|
+
import { useAppDesignTokens } from '../theme';
|
|
19
|
+
import { AtomicText } from './AtomicText';
|
|
20
|
+
|
|
21
|
+
// =============================================================================
|
|
22
|
+
// TYPE DEFINITIONS
|
|
23
|
+
// =============================================================================
|
|
24
|
+
|
|
25
|
+
export type SpinnerSize = 'sm' | 'md' | 'lg' | 'xl';
|
|
26
|
+
export type SpinnerColor = 'primary' | 'secondary' | 'success' | 'error' | 'warning' | 'white';
|
|
27
|
+
|
|
28
|
+
export interface AtomicSpinnerProps {
|
|
29
|
+
/** Spinner size preset or custom number */
|
|
30
|
+
size?: SpinnerSize | number;
|
|
31
|
+
/** Spinner color preset or custom hex */
|
|
32
|
+
color?: SpinnerColor | string;
|
|
33
|
+
/** Optional loading text */
|
|
34
|
+
text?: string;
|
|
35
|
+
/** Text position relative to spinner */
|
|
36
|
+
textPosition?: 'bottom' | 'right';
|
|
37
|
+
/** Fill entire parent container */
|
|
38
|
+
fullContainer?: boolean;
|
|
39
|
+
/** Show semi-transparent overlay behind spinner */
|
|
40
|
+
overlay?: boolean;
|
|
41
|
+
/** Overlay background color */
|
|
42
|
+
overlayColor?: string;
|
|
43
|
+
/** Style overrides for container */
|
|
44
|
+
style?: ViewStyle | ViewStyle[];
|
|
45
|
+
/** Test ID for testing */
|
|
46
|
+
testID?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// =============================================================================
|
|
50
|
+
// SIZE MAPPINGS
|
|
51
|
+
// =============================================================================
|
|
52
|
+
|
|
53
|
+
const SIZE_MAP: Record<SpinnerSize, number> = {
|
|
54
|
+
sm: 16,
|
|
55
|
+
md: 24,
|
|
56
|
+
lg: 36,
|
|
57
|
+
xl: 48,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const ACTIVITY_SIZE_MAP: Record<SpinnerSize, 'small' | 'large'> = {
|
|
61
|
+
sm: 'small',
|
|
62
|
+
md: 'small',
|
|
63
|
+
lg: 'large',
|
|
64
|
+
xl: 'large',
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// =============================================================================
|
|
68
|
+
// COMPONENT IMPLEMENTATION
|
|
69
|
+
// =============================================================================
|
|
70
|
+
|
|
71
|
+
export const AtomicSpinner: React.FC<AtomicSpinnerProps> = ({
|
|
72
|
+
size = 'md',
|
|
73
|
+
color = 'primary',
|
|
74
|
+
text,
|
|
75
|
+
textPosition = 'bottom',
|
|
76
|
+
fullContainer = false,
|
|
77
|
+
overlay = false,
|
|
78
|
+
overlayColor,
|
|
79
|
+
style,
|
|
80
|
+
testID,
|
|
81
|
+
}) => {
|
|
82
|
+
const tokens = useAppDesignTokens();
|
|
83
|
+
|
|
84
|
+
// Resolve size
|
|
85
|
+
const resolvedSize = typeof size === 'number' ? size : SIZE_MAP[size];
|
|
86
|
+
const activitySize = typeof size === 'number'
|
|
87
|
+
? (size >= 30 ? 'large' : 'small')
|
|
88
|
+
: ACTIVITY_SIZE_MAP[size];
|
|
89
|
+
|
|
90
|
+
// Resolve color
|
|
91
|
+
const resolveColor = (): string => {
|
|
92
|
+
if (color.startsWith('#') || color.startsWith('rgb')) {
|
|
93
|
+
return color;
|
|
94
|
+
}
|
|
95
|
+
const colorMap: Record<SpinnerColor, string> = {
|
|
96
|
+
primary: tokens.colors.primary,
|
|
97
|
+
secondary: tokens.colors.secondary,
|
|
98
|
+
success: tokens.colors.success,
|
|
99
|
+
error: tokens.colors.error,
|
|
100
|
+
warning: tokens.colors.warning,
|
|
101
|
+
white: '#FFFFFF',
|
|
102
|
+
};
|
|
103
|
+
return colorMap[color as SpinnerColor] || tokens.colors.primary;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const spinnerColor = resolveColor();
|
|
107
|
+
const resolvedOverlayColor = overlayColor || 'rgba(0, 0, 0, 0.5)';
|
|
108
|
+
|
|
109
|
+
// Container styles
|
|
110
|
+
const containerStyles: ViewStyle[] = [
|
|
111
|
+
styles.container,
|
|
112
|
+
textPosition === 'right' && styles.containerRow,
|
|
113
|
+
fullContainer && styles.fullContainer,
|
|
114
|
+
overlay && [styles.overlay, { backgroundColor: resolvedOverlayColor }],
|
|
115
|
+
].filter(Boolean) as ViewStyle[];
|
|
116
|
+
|
|
117
|
+
// Spinner wrapper styles
|
|
118
|
+
const spinnerWrapperStyles: ViewStyle = {
|
|
119
|
+
width: resolvedSize,
|
|
120
|
+
height: resolvedSize,
|
|
121
|
+
justifyContent: 'center',
|
|
122
|
+
alignItems: 'center',
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<View
|
|
127
|
+
style={[containerStyles, style]}
|
|
128
|
+
testID={testID}
|
|
129
|
+
accessibilityRole="progressbar"
|
|
130
|
+
accessibilityLabel={text || 'Loading'}
|
|
131
|
+
accessibilityLiveRegion="polite"
|
|
132
|
+
>
|
|
133
|
+
<View style={spinnerWrapperStyles}>
|
|
134
|
+
<ActivityIndicator
|
|
135
|
+
size={activitySize}
|
|
136
|
+
color={spinnerColor}
|
|
137
|
+
testID={testID ? `${testID}-indicator` : undefined}
|
|
138
|
+
/>
|
|
139
|
+
</View>
|
|
140
|
+
{text && (
|
|
141
|
+
<AtomicText
|
|
142
|
+
type="bodyMedium"
|
|
143
|
+
style={[
|
|
144
|
+
styles.text,
|
|
145
|
+
textPosition === 'right' ? styles.textRight : styles.textBottom,
|
|
146
|
+
{ color: overlay ? '#FFFFFF' : tokens.colors.textSecondary },
|
|
147
|
+
]}
|
|
148
|
+
>
|
|
149
|
+
{text}
|
|
150
|
+
</AtomicText>
|
|
151
|
+
)}
|
|
152
|
+
</View>
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// =============================================================================
|
|
157
|
+
// STYLES
|
|
158
|
+
// =============================================================================
|
|
159
|
+
|
|
160
|
+
const styles = StyleSheet.create({
|
|
161
|
+
container: {
|
|
162
|
+
justifyContent: 'center',
|
|
163
|
+
alignItems: 'center',
|
|
164
|
+
},
|
|
165
|
+
containerRow: {
|
|
166
|
+
flexDirection: 'row',
|
|
167
|
+
},
|
|
168
|
+
fullContainer: {
|
|
169
|
+
flex: 1,
|
|
170
|
+
},
|
|
171
|
+
overlay: {
|
|
172
|
+
...StyleSheet.absoluteFillObject,
|
|
173
|
+
zIndex: 999,
|
|
174
|
+
},
|
|
175
|
+
text: {
|
|
176
|
+
textAlign: 'center',
|
|
177
|
+
},
|
|
178
|
+
textBottom: {
|
|
179
|
+
marginTop: 12,
|
|
180
|
+
},
|
|
181
|
+
textRight: {
|
|
182
|
+
marginLeft: 12,
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// =============================================================================
|
|
187
|
+
// EXPORTS
|
|
188
|
+
// =============================================================================
|
|
189
|
+
|
|
190
|
+
export default AtomicSpinner;
|
package/src/atoms/index.ts
CHANGED
|
@@ -22,8 +22,17 @@
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import React, { useEffect
|
|
26
|
-
import { View, StyleSheet,
|
|
25
|
+
import React, { useEffect } from 'react';
|
|
26
|
+
import { View, StyleSheet, type StyleProp, type ViewStyle } from 'react-native';
|
|
27
|
+
import {
|
|
28
|
+
useSharedValue,
|
|
29
|
+
useAnimatedStyle,
|
|
30
|
+
withRepeat,
|
|
31
|
+
withSequence,
|
|
32
|
+
withTiming,
|
|
33
|
+
Easing,
|
|
34
|
+
} from 'react-native-reanimated';
|
|
35
|
+
import Animated from 'react-native-reanimated';
|
|
27
36
|
import { useAppDesignTokens } from '../../theme';
|
|
28
37
|
import type { SkeletonPattern, SkeletonConfig } from './AtomicSkeleton.types';
|
|
29
38
|
import { SKELETON_PATTERNS } from './AtomicSkeleton.types';
|
|
@@ -50,6 +59,53 @@ export interface AtomicSkeletonProps {
|
|
|
50
59
|
*
|
|
51
60
|
* Provides visual feedback during content loading with customizable patterns
|
|
52
61
|
*/
|
|
62
|
+
const SkeletonItem: React.FC<{
|
|
63
|
+
config: SkeletonConfig;
|
|
64
|
+
baseColor: string;
|
|
65
|
+
highlightColor: string;
|
|
66
|
+
disableAnimation: boolean;
|
|
67
|
+
}> = ({ config, baseColor, highlightColor, disableAnimation }) => {
|
|
68
|
+
const opacity = useSharedValue(0);
|
|
69
|
+
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (disableAnimation) return;
|
|
72
|
+
|
|
73
|
+
opacity.value = withRepeat(
|
|
74
|
+
withSequence(
|
|
75
|
+
withTiming(1, { duration: SHIMMER_DURATION / 2, easing: Easing.ease }),
|
|
76
|
+
withTiming(0, { duration: SHIMMER_DURATION / 2, easing: Easing.ease })
|
|
77
|
+
),
|
|
78
|
+
-1,
|
|
79
|
+
false
|
|
80
|
+
);
|
|
81
|
+
}, [opacity, disableAnimation]);
|
|
82
|
+
|
|
83
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
84
|
+
backgroundColor: disableAnimation
|
|
85
|
+
? baseColor
|
|
86
|
+
: opacity.value === 0
|
|
87
|
+
? baseColor
|
|
88
|
+
: highlightColor,
|
|
89
|
+
opacity: disableAnimation ? 1 : 0.5 + opacity.value * 0.5,
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<Animated.View
|
|
94
|
+
style={[
|
|
95
|
+
styles.skeleton,
|
|
96
|
+
{
|
|
97
|
+
width: config.width as number | `${number}%` | undefined,
|
|
98
|
+
height: config.height,
|
|
99
|
+
borderRadius: config.borderRadius,
|
|
100
|
+
marginBottom: config.marginBottom,
|
|
101
|
+
backgroundColor: baseColor,
|
|
102
|
+
},
|
|
103
|
+
animatedStyle,
|
|
104
|
+
]}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
53
109
|
export const AtomicSkeleton: React.FC<AtomicSkeletonProps> = ({
|
|
54
110
|
pattern = 'list',
|
|
55
111
|
custom,
|
|
@@ -63,59 +119,15 @@ export const AtomicSkeleton: React.FC<AtomicSkeletonProps> = ({
|
|
|
63
119
|
? custom
|
|
64
120
|
: SKELETON_PATTERNS[pattern];
|
|
65
121
|
|
|
66
|
-
const shimmerAnim = useRef(new Animated.Value(0)).current;
|
|
67
|
-
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
if (disableAnimation) return;
|
|
70
|
-
|
|
71
|
-
const shimmerAnimation = Animated.loop(
|
|
72
|
-
Animated.sequence([
|
|
73
|
-
Animated.timing(shimmerAnim, {
|
|
74
|
-
toValue: 1,
|
|
75
|
-
duration: SHIMMER_DURATION,
|
|
76
|
-
useNativeDriver: false,
|
|
77
|
-
}),
|
|
78
|
-
Animated.timing(shimmerAnim, {
|
|
79
|
-
toValue: 0,
|
|
80
|
-
duration: 0,
|
|
81
|
-
useNativeDriver: false,
|
|
82
|
-
}),
|
|
83
|
-
])
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
shimmerAnimation.start();
|
|
87
|
-
|
|
88
|
-
return () => {
|
|
89
|
-
shimmerAnimation.stop();
|
|
90
|
-
};
|
|
91
|
-
}, [shimmerAnim, disableAnimation]);
|
|
92
|
-
|
|
93
|
-
const backgroundColor = shimmerAnim.interpolate({
|
|
94
|
-
inputRange: [0, 0.5, 1],
|
|
95
|
-
outputRange: [
|
|
96
|
-
tokens.colors.surfaceSecondary,
|
|
97
|
-
tokens.colors.border,
|
|
98
|
-
tokens.colors.surfaceSecondary,
|
|
99
|
-
],
|
|
100
|
-
});
|
|
101
|
-
|
|
102
122
|
const renderSkeletonItem = (index: number) => (
|
|
103
123
|
<View key={`skeleton-group-${index}`} style={styles.skeletonGroup}>
|
|
104
124
|
{skeletonConfigs.map((config, configIndex) => (
|
|
105
|
-
<
|
|
125
|
+
<SkeletonItem
|
|
106
126
|
key={`skeleton-${index}-${configIndex}`}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
height: config.height,
|
|
112
|
-
borderRadius: config.borderRadius,
|
|
113
|
-
marginBottom: config.marginBottom,
|
|
114
|
-
backgroundColor: disableAnimation
|
|
115
|
-
? tokens.colors.surfaceSecondary
|
|
116
|
-
: backgroundColor,
|
|
117
|
-
} as any,
|
|
118
|
-
]}
|
|
127
|
+
config={config}
|
|
128
|
+
baseColor={tokens.colors.surfaceSecondary}
|
|
129
|
+
highlightColor={tokens.colors.border}
|
|
130
|
+
disableAnimation={disableAnimation}
|
|
119
131
|
/>
|
|
120
132
|
))}
|
|
121
133
|
</View>
|