sapo-components-ui-rn 1.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/README.md +69 -0
- package/dist/assets/error.png +0 -0
- package/dist/assets/icon-checkbox-active.svg +4 -0
- package/dist/assets/icon-checkbox.svg +3 -0
- package/dist/assets/image_default.png +0 -0
- package/dist/assets/images/error.png +0 -0
- package/dist/assets/images/image_default.png +0 -0
- package/dist/assets/images/info.png +0 -0
- package/dist/assets/images/success.png +0 -0
- package/dist/assets/images/warning.png +0 -0
- package/dist/assets/info.png +0 -0
- package/dist/assets/success.png +0 -0
- package/dist/assets/svg/icon-checkbox-active.svg +4 -0
- package/dist/assets/svg/icon-checkbox.svg +3 -0
- package/dist/assets/warning.png +0 -0
- package/dist/components/ActivityIndicator.d.ts +28 -0
- package/dist/components/Avatar/index.d.ts +17 -0
- package/dist/components/Badge/index.d.ts +13 -0
- package/dist/components/Button/index.d.ts +23 -0
- package/dist/components/ButtonIcon/index.d.ts +18 -0
- package/dist/components/Checkbox/index.d.ts +14 -0
- package/dist/components/ChipBar/index.d.ts +16 -0
- package/dist/components/CountingDot/index.d.ts +13 -0
- package/dist/components/FloatingButton/index.d.ts +17 -0
- package/dist/components/Icon/index.d.ts +17 -0
- package/dist/components/IconSvg/index.d.ts +12 -0
- package/dist/components/Image/index.d.ts +14 -0
- package/dist/components/ProgressBar.d.ts +42 -0
- package/dist/components/RadioButton/index.d.ts +13 -0
- package/dist/components/ScaleButton/index.d.ts +4 -0
- package/dist/components/SelectionField/index.d.ts +24 -0
- package/dist/components/Spacer/index.d.ts +9 -0
- package/dist/components/Switch/Switch.d.ts +47 -0
- package/dist/components/Switch/utils.d.ts +14 -0
- package/dist/components/Text/index.d.ts +14 -0
- package/dist/components/TextInput/Addons/Outline.d.ts +15 -0
- package/dist/components/TextInput/Addons/Underline.d.ts +19 -0
- package/dist/components/TextInput/Adornment/TextInputAdornment.d.ts +43 -0
- package/dist/components/TextInput/Adornment/TextInputAffix.d.ts +72 -0
- package/dist/components/TextInput/Adornment/enums.d.ts +12 -0
- package/dist/components/TextInput/Adornment/types.d.ts +11 -0
- package/dist/components/TextInput/Adornment/utils.d.ts +11 -0
- package/dist/components/TextInput/Label/InputLabel.d.ts +4 -0
- package/dist/components/TextInput/Label/LabelBackground.d.ts +4 -0
- package/dist/components/TextInput/TextInput.d.ts +171 -0
- package/dist/components/TextInput/TextInputDefault.d.ts +4 -0
- package/dist/components/TextInput/TextInputFlat.d.ts +4 -0
- package/dist/components/TextInput/constants.d.ts +31 -0
- package/dist/components/TextInput/helpers.d.ts +95 -0
- package/dist/components/TextInput/types.d.ts +154 -0
- package/dist/components/Toast/ToastProvider.d.ts +21 -0
- package/dist/components/Toast/index.d.ts +3 -0
- package/dist/components/Typography/AnimatedText.d.ts +34 -0
- package/dist/components/Typography/StyledText.d.ts +12 -0
- package/dist/components/Typography/Text.d.ts +35 -0
- package/dist/components/Typography/types.d.ts +2 -0
- package/dist/components/View/index.d.ts +38 -0
- package/dist/components/ViewVisibleAnimated/index.d.ts +25 -0
- package/dist/constants.d.ts +1 -0
- package/dist/core/theming.d.ts +43 -0
- package/dist/icons/IconArrowDown.d.ts +4 -0
- package/dist/icons/IconCheckbox.d.ts +4 -0
- package/dist/icons/IconCheckboxActive.d.ts +4 -0
- package/dist/icons/IconClearText.d.ts +4 -0
- package/dist/icons/IconRadio.d.ts +4 -0
- package/dist/icons/IconRadioActive.d.ts +4 -0
- package/dist/icons/IconRadioDisable.d.ts +4 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.esm.js +6758 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +6823 -0
- package/dist/index.js.map +1 -0
- package/dist/styles/fonts.d.ts +78 -0
- package/dist/styles/overlay.d.ts +3 -0
- package/dist/styles/shadow.d.ts +18 -0
- package/dist/styles/themes/DarkTheme.d.ts +2 -0
- package/dist/styles/themes/LightTheme.d.ts +2 -0
- package/dist/styles/themes/index.d.ts +2 -0
- package/dist/styles/themes/tokens.d.ts +830 -0
- package/dist/theme/blue.d.ts +14 -0
- package/dist/theme/colors.d.ts +99 -0
- package/dist/theme/container-styles.d.ts +124 -0
- package/dist/theme/dimensions.d.ts +36 -0
- package/dist/theme/green.d.ts +15 -0
- package/dist/theme/icon.d.ts +5 -0
- package/dist/theme/ink.d.ts +11 -0
- package/dist/theme/orange.d.ts +14 -0
- package/dist/theme/purple.d.ts +6 -0
- package/dist/theme/red.d.ts +15 -0
- package/dist/theme/themes.d.ts +277 -0
- package/dist/theme/white.d.ts +10 -0
- package/dist/theme/yellow.d.ts +15 -0
- package/dist/types/index.d.ts +65 -0
- package/dist/types.d.ts +220 -0
- package/dist/utils/BackHandler/BackHandler.d.ts +9 -0
- package/dist/utils/BackHandler/BackHandler.native.d.ts +2 -0
- package/dist/utils/addEventListener.d.ts +12 -0
- package/dist/utils/forwardRef.d.ts +11 -0
- package/dist/utils/function-utils.d.ts +12 -0
- package/dist/utils/getContrastingColor.d.ts +2 -0
- package/dist/utils/hasTouchHandler.d.ts +5 -0
- package/dist/utils/roundLayoutSize.d.ts +1 -0
- package/dist/utils/splitStyles.d.ts +19 -0
- package/dist/utils/toast-manager.d.ts +21 -0
- package/dist/utils/useAnimatedValue.d.ts +2 -0
- package/dist/utils/useAnimatedValueArray.d.ts +2 -0
- package/dist/utils/useIsKeyboardShown.d.ts +6 -0
- package/dist/utils/useLayout.d.ts +6 -0
- package/dist/utils/useLazyRef.d.ts +2 -0
- package/package.json +104 -0
- package/src/.DS_Store +0 -0
- package/src/assets/images/error.png +0 -0
- package/src/assets/images/image_default.png +0 -0
- package/src/assets/images/info.png +0 -0
- package/src/assets/images/success.png +0 -0
- package/src/assets/images/warning.png +0 -0
- package/src/assets/svg/icon-checkbox-active.svg +4 -0
- package/src/assets/svg/icon-checkbox.svg +3 -0
- package/src/babel/.eslintrc +7 -0
- package/src/babel/index.js +63 -0
- package/src/components/.DS_Store +0 -0
- package/src/components/ActivityIndicator.tsx +238 -0
- package/src/components/Avatar/index.tsx +102 -0
- package/src/components/Badge/index.tsx +55 -0
- package/src/components/Button/index.tsx +162 -0
- package/src/components/ButtonIcon/index.tsx +98 -0
- package/src/components/Checkbox/index.tsx +107 -0
- package/src/components/ChipBar/index.tsx +112 -0
- package/src/components/CountingDot/index.tsx +63 -0
- package/src/components/FloatingButton/index.tsx +99 -0
- package/src/components/Icon/index.tsx +135 -0
- package/src/components/IconSvg/index.tsx +42 -0
- package/src/components/Image/index.tsx +127 -0
- package/src/components/ProgressBar.tsx +272 -0
- package/src/components/RadioButton/index.tsx +105 -0
- package/src/components/ScaleButton/index.tsx +17 -0
- package/src/components/SelectionField/index.tsx +166 -0
- package/src/components/Spacer/index.tsx +19 -0
- package/src/components/Switch/Switch.tsx +110 -0
- package/src/components/Switch/utils.ts +96 -0
- package/src/components/Text/index.tsx +69 -0
- package/src/components/TextInput/.DS_Store +0 -0
- package/src/components/TextInput/Addons/Outline.tsx +62 -0
- package/src/components/TextInput/Addons/Underline.tsx +71 -0
- package/src/components/TextInput/Adornment/TextInputAdornment.tsx +191 -0
- package/src/components/TextInput/Adornment/TextInputAffix.tsx +212 -0
- package/src/components/TextInput/Adornment/enums.tsx +12 -0
- package/src/components/TextInput/Adornment/types.tsx +11 -0
- package/src/components/TextInput/Adornment/utils.ts +39 -0
- package/src/components/TextInput/Label/InputLabel.tsx +216 -0
- package/src/components/TextInput/Label/LabelBackground.tsx +100 -0
- package/src/components/TextInput/TextInput.tsx +564 -0
- package/src/components/TextInput/TextInputDefault.tsx +187 -0
- package/src/components/TextInput/TextInputFlat.tsx +452 -0
- package/src/components/TextInput/constants.tsx +48 -0
- package/src/components/TextInput/helpers.tsx +546 -0
- package/src/components/TextInput/types.tsx +155 -0
- package/src/components/Toast/ToastProvider.tsx +69 -0
- package/src/components/Toast/index.tsx +239 -0
- package/src/components/Typography/AnimatedText.tsx +84 -0
- package/src/components/Typography/StyledText.tsx +53 -0
- package/src/components/Typography/Text.tsx +189 -0
- package/src/components/Typography/types.tsx +5 -0
- package/src/components/View/index.tsx +175 -0
- package/src/components/ViewVisibleAnimated/index.tsx +199 -0
- package/src/constants.tsx +16 -0
- package/src/core/theming.tsx +144 -0
- package/src/icons/IconArrowDown.tsx +14 -0
- package/src/icons/IconCheckbox.tsx +20 -0
- package/src/icons/IconCheckboxActive.tsx +18 -0
- package/src/icons/IconClearText.tsx +14 -0
- package/src/icons/IconRadio.tsx +11 -0
- package/src/icons/IconRadioActive.tsx +12 -0
- package/src/icons/IconRadioDisable.tsx +12 -0
- package/src/index.ts +51 -0
- package/src/index.tsx +50 -0
- package/src/styles/fonts.tsx +89 -0
- package/src/styles/overlay.tsx +69 -0
- package/src/styles/shadow.tsx +47 -0
- package/src/styles/themes/DarkTheme.tsx +157 -0
- package/src/styles/themes/LightTheme.tsx +160 -0
- package/src/styles/themes/index.ts +3 -0
- package/src/styles/themes/tokens.tsx +481 -0
- package/src/theme/blue.ts +25 -0
- package/src/theme/colors.ts +21 -0
- package/src/theme/container-styles.tsx +126 -0
- package/src/theme/dimensions.ts +44 -0
- package/src/theme/green.ts +27 -0
- package/src/theme/icon.ts +7 -0
- package/src/theme/ink.ts +18 -0
- package/src/theme/orange.ts +24 -0
- package/src/theme/purple.ts +8 -0
- package/src/theme/red.ts +26 -0
- package/src/theme/themes.tsx +287 -0
- package/src/theme/white.ts +16 -0
- package/src/theme/yellow.ts +26 -0
- package/src/types/index.ts +71 -0
- package/src/types/svg.d.ts +5 -0
- package/src/types.ts +259 -0
- package/src/types.tsx +284 -0
- package/src/utils/BackHandler/BackHandler.native.tsx +3 -0
- package/src/utils/BackHandler/BackHandler.tsx +11 -0
- package/src/utils/addEventListener.tsx +56 -0
- package/src/utils/forwardRef.tsx +23 -0
- package/src/utils/function-utils.tsx +108 -0
- package/src/utils/getContrastingColor.tsx +15 -0
- package/src/utils/hasTouchHandler.tsx +23 -0
- package/src/utils/roundLayoutSize.ts +2 -0
- package/src/utils/splitStyles.ts +60 -0
- package/src/utils/toast-manager.tsx +46 -0
- package/src/utils/useAnimatedValue.tsx +9 -0
- package/src/utils/useAnimatedValueArray.tsx +13 -0
- package/src/utils/useIsKeyboardShown.tsx +55 -0
- package/src/utils/useLayout.tsx +29 -0
- package/src/utils/useLazyRef.tsx +11 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
Animated,
|
|
4
|
+
Easing,
|
|
5
|
+
Platform,
|
|
6
|
+
StyleProp,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
View,
|
|
9
|
+
ViewStyle,
|
|
10
|
+
} from "react-native";
|
|
11
|
+
|
|
12
|
+
import { useInternalTheme } from "../core/theming";
|
|
13
|
+
import type { ThemeProp } from "../types";
|
|
14
|
+
|
|
15
|
+
export type Props = React.ComponentPropsWithRef<typeof View> & {
|
|
16
|
+
/**
|
|
17
|
+
* Whether to show the indicator or hide it.
|
|
18
|
+
*/
|
|
19
|
+
animating?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The color of the spinner.
|
|
22
|
+
*/
|
|
23
|
+
color?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Size of the indicator.
|
|
26
|
+
*/
|
|
27
|
+
size?: "small" | "large" | number;
|
|
28
|
+
/**
|
|
29
|
+
* Whether the indicator should hide when not animating.
|
|
30
|
+
*/
|
|
31
|
+
hidesWhenStopped?: boolean;
|
|
32
|
+
style?: StyleProp<ViewStyle>;
|
|
33
|
+
/**
|
|
34
|
+
* @optional
|
|
35
|
+
*/
|
|
36
|
+
theme?: ThemeProp;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const DURATION = 2400;
|
|
40
|
+
|
|
41
|
+
const ActivityIndicator = ({
|
|
42
|
+
animating = true,
|
|
43
|
+
color: indicatorColor,
|
|
44
|
+
hidesWhenStopped = true,
|
|
45
|
+
size: indicatorSize = "small",
|
|
46
|
+
style,
|
|
47
|
+
theme: themeOverrides,
|
|
48
|
+
...rest
|
|
49
|
+
}: Props) => {
|
|
50
|
+
const theme = useInternalTheme();
|
|
51
|
+
const { current: timer } = React.useRef<Animated.Value>(
|
|
52
|
+
new Animated.Value(0)
|
|
53
|
+
);
|
|
54
|
+
const { current: fade } = React.useRef<Animated.Value>(
|
|
55
|
+
new Animated.Value(!animating && hidesWhenStopped ? 0 : 1)
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const rotation = React.useRef<Animated.CompositeAnimation | undefined>(
|
|
59
|
+
undefined
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const {
|
|
63
|
+
animation: { scale },
|
|
64
|
+
} = theme;
|
|
65
|
+
|
|
66
|
+
const startRotation = React.useCallback(() => {
|
|
67
|
+
// Show indicator
|
|
68
|
+
Animated.timing(fade, {
|
|
69
|
+
duration: 200 * scale,
|
|
70
|
+
toValue: 1,
|
|
71
|
+
isInteraction: false,
|
|
72
|
+
useNativeDriver: true,
|
|
73
|
+
}).start();
|
|
74
|
+
|
|
75
|
+
// Circular animation in loop
|
|
76
|
+
if (rotation.current) {
|
|
77
|
+
timer.setValue(0);
|
|
78
|
+
// $FlowFixMe
|
|
79
|
+
Animated.loop(rotation.current).start();
|
|
80
|
+
}
|
|
81
|
+
}, [scale, fade, timer]);
|
|
82
|
+
|
|
83
|
+
const stopRotation = () => {
|
|
84
|
+
if (rotation.current) {
|
|
85
|
+
rotation.current.stop();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
React.useEffect(() => {
|
|
90
|
+
if (rotation.current === undefined) {
|
|
91
|
+
// Circular animation in loop
|
|
92
|
+
rotation.current = Animated.timing(timer, {
|
|
93
|
+
duration: DURATION,
|
|
94
|
+
easing: Easing.linear,
|
|
95
|
+
// Animated.loop does not work if useNativeDriver is true on web
|
|
96
|
+
useNativeDriver: Platform.OS !== "web",
|
|
97
|
+
toValue: 1,
|
|
98
|
+
isInteraction: false,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (animating) {
|
|
103
|
+
startRotation();
|
|
104
|
+
} else if (hidesWhenStopped) {
|
|
105
|
+
// Hide indicator first and then stop rotation
|
|
106
|
+
Animated.timing(fade, {
|
|
107
|
+
duration: 200 * scale,
|
|
108
|
+
toValue: 0,
|
|
109
|
+
useNativeDriver: true,
|
|
110
|
+
isInteraction: false,
|
|
111
|
+
}).start(stopRotation);
|
|
112
|
+
} else {
|
|
113
|
+
stopRotation();
|
|
114
|
+
}
|
|
115
|
+
}, [animating, fade, hidesWhenStopped, startRotation, scale, timer]);
|
|
116
|
+
|
|
117
|
+
const color = indicatorColor || theme.colors?.surfaceBrandDefault;
|
|
118
|
+
const size =
|
|
119
|
+
typeof indicatorSize === "string"
|
|
120
|
+
? indicatorSize === "small"
|
|
121
|
+
? 24
|
|
122
|
+
: 48
|
|
123
|
+
: indicatorSize
|
|
124
|
+
? indicatorSize
|
|
125
|
+
: 24;
|
|
126
|
+
|
|
127
|
+
const frames = (60 * DURATION) / 1000;
|
|
128
|
+
const easing = Easing.bezier(0.4, 0.0, 0.7, 1.0);
|
|
129
|
+
const containerStyle = {
|
|
130
|
+
width: size,
|
|
131
|
+
height: size / 2,
|
|
132
|
+
overflow: "hidden" as const,
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<View
|
|
137
|
+
style={[styles.container, style]}
|
|
138
|
+
{...rest}
|
|
139
|
+
accessible
|
|
140
|
+
accessibilityRole="progressbar"
|
|
141
|
+
accessibilityState={{ busy: animating }}
|
|
142
|
+
>
|
|
143
|
+
<Animated.View
|
|
144
|
+
style={[{ width: size, height: size, opacity: fade }]}
|
|
145
|
+
collapsable={false}
|
|
146
|
+
>
|
|
147
|
+
{[0, 1].map((index) => {
|
|
148
|
+
// Thanks to https://github.com/n4kz/react-native-indicators for the great work
|
|
149
|
+
const inputRange = Array.from(
|
|
150
|
+
new Array(frames),
|
|
151
|
+
(_, frameIndex) => frameIndex / (frames - 1)
|
|
152
|
+
);
|
|
153
|
+
const outputRange = Array.from(new Array(frames), (_, frameIndex) => {
|
|
154
|
+
let progress = (2 * frameIndex) / (frames - 1);
|
|
155
|
+
const rotation = index ? +(360 - 15) : -(180 - 15);
|
|
156
|
+
|
|
157
|
+
if (progress > 1.0) {
|
|
158
|
+
progress = 2.0 - progress;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const direction = index ? -1 : +1;
|
|
162
|
+
|
|
163
|
+
return `${direction * (180 - 30) * easing(progress) + rotation}deg`;
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const layerStyle = {
|
|
167
|
+
width: size,
|
|
168
|
+
height: size,
|
|
169
|
+
transform: [
|
|
170
|
+
{
|
|
171
|
+
rotate: timer.interpolate({
|
|
172
|
+
inputRange: [0, 1],
|
|
173
|
+
outputRange: [`${0 + 30 + 15}deg`, `${2 * 360 + 30 + 15}deg`],
|
|
174
|
+
}),
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const viewportStyle = {
|
|
180
|
+
width: size,
|
|
181
|
+
height: size,
|
|
182
|
+
transform: [
|
|
183
|
+
{
|
|
184
|
+
translateY: index ? -size / 2 : 0,
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
rotate: timer.interpolate({ inputRange, outputRange }),
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const offsetStyle = index ? { top: size / 2 } : null;
|
|
193
|
+
|
|
194
|
+
const lineStyle = {
|
|
195
|
+
width: size,
|
|
196
|
+
height: size,
|
|
197
|
+
borderColor: color,
|
|
198
|
+
borderWidth: size / 10,
|
|
199
|
+
borderRadius: size / 2,
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
return (
|
|
203
|
+
<Animated.View key={index} style={[styles.layer]}>
|
|
204
|
+
<Animated.View style={layerStyle}>
|
|
205
|
+
<Animated.View
|
|
206
|
+
style={[containerStyle, offsetStyle]}
|
|
207
|
+
collapsable={false}
|
|
208
|
+
>
|
|
209
|
+
<Animated.View style={viewportStyle}>
|
|
210
|
+
<Animated.View style={containerStyle} collapsable={false}>
|
|
211
|
+
<Animated.View style={lineStyle} />
|
|
212
|
+
</Animated.View>
|
|
213
|
+
</Animated.View>
|
|
214
|
+
</Animated.View>
|
|
215
|
+
</Animated.View>
|
|
216
|
+
</Animated.View>
|
|
217
|
+
);
|
|
218
|
+
})}
|
|
219
|
+
</Animated.View>
|
|
220
|
+
</View>
|
|
221
|
+
);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const styles = StyleSheet.create({
|
|
225
|
+
container: {
|
|
226
|
+
justifyContent: "center",
|
|
227
|
+
alignItems: "center",
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
layer: {
|
|
231
|
+
...StyleSheet.absoluteFillObject,
|
|
232
|
+
|
|
233
|
+
justifyContent: "center",
|
|
234
|
+
alignItems: "center",
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
export default ActivityIndicator;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import View from "../View";
|
|
3
|
+
import Text from "../Text";
|
|
4
|
+
import { useInternalTheme } from "../../core/theming";
|
|
5
|
+
import {
|
|
6
|
+
StyleProp,
|
|
7
|
+
ViewStyle,
|
|
8
|
+
StyleSheet,
|
|
9
|
+
TextStyle,
|
|
10
|
+
ImageStyle,
|
|
11
|
+
} from "react-native";
|
|
12
|
+
import Image from "../Image";
|
|
13
|
+
interface AvatarProps {
|
|
14
|
+
children?: React.ReactNode;
|
|
15
|
+
name?: string;
|
|
16
|
+
borderColor?: string;
|
|
17
|
+
backgroundColor?: string;
|
|
18
|
+
style?: StyleProp<ViewStyle>;
|
|
19
|
+
textColor?: string;
|
|
20
|
+
size: 64 | 48 | 24;
|
|
21
|
+
source?: string;
|
|
22
|
+
onPress?: () => void;
|
|
23
|
+
textStyle?: StyleProp<TextStyle>;
|
|
24
|
+
imageStyle?: StyleProp<ImageStyle>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const Avatar = ({
|
|
28
|
+
children,
|
|
29
|
+
name = "Sapo",
|
|
30
|
+
backgroundColor,
|
|
31
|
+
style,
|
|
32
|
+
textColor,
|
|
33
|
+
size = 64,
|
|
34
|
+
source,
|
|
35
|
+
onPress,
|
|
36
|
+
textStyle,
|
|
37
|
+
imageStyle,
|
|
38
|
+
}: AvatarProps) => {
|
|
39
|
+
const theme = useInternalTheme();
|
|
40
|
+
const { colors } = theme;
|
|
41
|
+
|
|
42
|
+
const getInitials = (name: string) => {
|
|
43
|
+
const words = name.trim().split(" ");
|
|
44
|
+
if (words.length === 1) {
|
|
45
|
+
return words[0][0];
|
|
46
|
+
}
|
|
47
|
+
return words[0][0] + words[words.length - 1][0];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
if (children) {
|
|
51
|
+
return <View style={style}>{children}</View>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const getSize = (size: number) => {
|
|
55
|
+
switch (size) {
|
|
56
|
+
case 64:
|
|
57
|
+
return 28;
|
|
58
|
+
case 48:
|
|
59
|
+
return 20;
|
|
60
|
+
case 24:
|
|
61
|
+
return 16;
|
|
62
|
+
default:
|
|
63
|
+
return 16;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<View
|
|
69
|
+
onPress={onPress}
|
|
70
|
+
width={size}
|
|
71
|
+
height={size}
|
|
72
|
+
borderRadius={size / 2}
|
|
73
|
+
center
|
|
74
|
+
backgroundColor={backgroundColor || colors.surfaceSecondaryDefault}
|
|
75
|
+
style={[styles.container, style]}
|
|
76
|
+
>
|
|
77
|
+
{source ? (
|
|
78
|
+
<Image
|
|
79
|
+
useFastImage
|
|
80
|
+
resizeMode="cover"
|
|
81
|
+
source={source}
|
|
82
|
+
style={[{ width: size, height: size }, imageStyle]}
|
|
83
|
+
/>
|
|
84
|
+
) : (
|
|
85
|
+
<Text
|
|
86
|
+
size={getSize(size)}
|
|
87
|
+
color={textColor || colors.textSecondary}
|
|
88
|
+
style={textStyle || { fontWeight: "500" }}
|
|
89
|
+
>
|
|
90
|
+
{getInitials(name)}
|
|
91
|
+
</Text>
|
|
92
|
+
)}
|
|
93
|
+
</View>
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const styles = StyleSheet.create({
|
|
98
|
+
container: {
|
|
99
|
+
overflow: "hidden",
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
export default Avatar;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import View from "../View";
|
|
3
|
+
import Text from "../Text";
|
|
4
|
+
import { CONSTANTS } from "../../styles/themes/tokens";
|
|
5
|
+
import { useInternalTheme } from "../../core/theming";
|
|
6
|
+
import { StyleProp, ViewStyle, TextStyle } from "react-native";
|
|
7
|
+
interface BadgeProps {
|
|
8
|
+
children?: React.ReactNode;
|
|
9
|
+
value: string;
|
|
10
|
+
borderColor?: string;
|
|
11
|
+
backgroundColor?: string;
|
|
12
|
+
style?: StyleProp<ViewStyle>;
|
|
13
|
+
textColor?: string;
|
|
14
|
+
textStyle?: StyleProp<TextStyle>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const Badge = ({
|
|
18
|
+
children,
|
|
19
|
+
value = "1",
|
|
20
|
+
borderColor,
|
|
21
|
+
backgroundColor,
|
|
22
|
+
style,
|
|
23
|
+
textColor,
|
|
24
|
+
textStyle,
|
|
25
|
+
}: BadgeProps) => {
|
|
26
|
+
const theme = useInternalTheme();
|
|
27
|
+
const { colors } = theme;
|
|
28
|
+
|
|
29
|
+
if (children) {
|
|
30
|
+
return <View style={style}>{children}</View>;
|
|
31
|
+
}
|
|
32
|
+
return (
|
|
33
|
+
<View row>
|
|
34
|
+
<View
|
|
35
|
+
borderRadius={CONSTANTS.BORDER_RADIUS_12}
|
|
36
|
+
borderWidth={CONSTANTS.BORDER_WIDTH_1}
|
|
37
|
+
borderColor={borderColor || colors.borderPrimaryDefault}
|
|
38
|
+
backgroundColor={backgroundColor || colors.surfaceSecondaryDefault}
|
|
39
|
+
paddingHorizontal={CONSTANTS.SPACE_8}
|
|
40
|
+
paddingVertical={CONSTANTS.SPACE_4}
|
|
41
|
+
style={style}
|
|
42
|
+
>
|
|
43
|
+
<Text
|
|
44
|
+
size={12}
|
|
45
|
+
color={textColor || colors.textSecondary}
|
|
46
|
+
style={textStyle}
|
|
47
|
+
>
|
|
48
|
+
{value}
|
|
49
|
+
</Text>
|
|
50
|
+
</View>
|
|
51
|
+
</View>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default Badge;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Created by Dung Nguyen on 08/01/25.
|
|
3
|
+
//
|
|
4
|
+
import React from "react";
|
|
5
|
+
import {
|
|
6
|
+
StyleSheet,
|
|
7
|
+
StyleProp,
|
|
8
|
+
ViewStyle,
|
|
9
|
+
TouchableOpacityProps,
|
|
10
|
+
ActivityIndicator,
|
|
11
|
+
TextStyle,
|
|
12
|
+
} from "react-native";
|
|
13
|
+
|
|
14
|
+
import { CONSTANTS } from "../../styles/themes/tokens";
|
|
15
|
+
import ScaleButton from "../ScaleButton";
|
|
16
|
+
import Text from "../Text";
|
|
17
|
+
import View from "../View";
|
|
18
|
+
import { useInternalTheme } from "../../core/theming";
|
|
19
|
+
import { ThemeProp } from "../../types";
|
|
20
|
+
import Spacer from "../Spacer";
|
|
21
|
+
|
|
22
|
+
export interface ButtonProps extends TouchableOpacityProps {
|
|
23
|
+
style?: StyleProp<ViewStyle>;
|
|
24
|
+
borderColor?: string;
|
|
25
|
+
title?: string;
|
|
26
|
+
backgroundColor?: string;
|
|
27
|
+
isLoading?: boolean;
|
|
28
|
+
left?: React.ReactNode;
|
|
29
|
+
right?: React.ReactNode;
|
|
30
|
+
small?: boolean;
|
|
31
|
+
textColor?: string;
|
|
32
|
+
bold?: boolean;
|
|
33
|
+
size?: number;
|
|
34
|
+
textStyle?: TextStyle;
|
|
35
|
+
medium?: boolean;
|
|
36
|
+
mode?: "outlined" | "contained" | "transparent";
|
|
37
|
+
onPress?: (res?: any) => void;
|
|
38
|
+
theme?: ThemeProp;
|
|
39
|
+
}
|
|
40
|
+
const Button = ({
|
|
41
|
+
style,
|
|
42
|
+
title,
|
|
43
|
+
borderColor,
|
|
44
|
+
isLoading,
|
|
45
|
+
left,
|
|
46
|
+
right,
|
|
47
|
+
small,
|
|
48
|
+
textStyle,
|
|
49
|
+
onPress,
|
|
50
|
+
disabled,
|
|
51
|
+
backgroundColor,
|
|
52
|
+
textColor,
|
|
53
|
+
bold = true,
|
|
54
|
+
size = 16,
|
|
55
|
+
medium = false,
|
|
56
|
+
mode = "contained",
|
|
57
|
+
theme: themeOverrides,
|
|
58
|
+
...props
|
|
59
|
+
}: ButtonProps) => {
|
|
60
|
+
const theme = useInternalTheme();
|
|
61
|
+
const { colors } = theme;
|
|
62
|
+
|
|
63
|
+
const disabledTextStyle = {
|
|
64
|
+
color: colors.textBrandDisabled,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const renderButtonStyle = () => {
|
|
68
|
+
switch (mode) {
|
|
69
|
+
case "outlined":
|
|
70
|
+
return [styles.border, { borderColor: colors.borderBrandDefault }];
|
|
71
|
+
case "contained":
|
|
72
|
+
return [{ backgroundColor: colors.surfaceBrandDefault }];
|
|
73
|
+
case "transparent":
|
|
74
|
+
return [
|
|
75
|
+
{ borderColor: colors.borderBrandDefault },
|
|
76
|
+
{ backgroundColor: "transparent" },
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<View style={styles.container}>
|
|
83
|
+
<ScaleButton
|
|
84
|
+
activeOpacity={0.8}
|
|
85
|
+
onPress={onPress}
|
|
86
|
+
{...props}
|
|
87
|
+
disabled={disabled || false}
|
|
88
|
+
>
|
|
89
|
+
<View
|
|
90
|
+
style={[
|
|
91
|
+
styles.button,
|
|
92
|
+
{
|
|
93
|
+
borderRadius: CONSTANTS.BORDER_RADIUS_6,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
backgroundColor: colors.surfaceBrandDefault,
|
|
97
|
+
},
|
|
98
|
+
borderColor && { borderColor: borderColor },
|
|
99
|
+
backgroundColor && { backgroundColor: backgroundColor },
|
|
100
|
+
renderButtonStyle(),
|
|
101
|
+
small && styles.small,
|
|
102
|
+
disabled && [
|
|
103
|
+
styles.disabled,
|
|
104
|
+
{
|
|
105
|
+
borderColor: colors.borderPrimaryDisabled,
|
|
106
|
+
backgroundColor: colors.surfacePrimaryDisabled,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
isLoading && { justifyContent: "center" },
|
|
110
|
+
style,
|
|
111
|
+
]}
|
|
112
|
+
disabled={isLoading}
|
|
113
|
+
>
|
|
114
|
+
<Spacer width={left ? CONSTANTS.SPACE_12 : CONSTANTS.SPACE_16} />
|
|
115
|
+
{!isLoading && left}
|
|
116
|
+
{left && <Spacer width={CONSTANTS.SPACE_8} />}
|
|
117
|
+
{isLoading ? (
|
|
118
|
+
<ActivityIndicator
|
|
119
|
+
color={textStyle?.color || colors.borderBrandDefault}
|
|
120
|
+
/>
|
|
121
|
+
) : (
|
|
122
|
+
<Text
|
|
123
|
+
numberOfLines={1}
|
|
124
|
+
color={textColor || colors.textOnFillDefault}
|
|
125
|
+
size={size}
|
|
126
|
+
bold={bold}
|
|
127
|
+
medium={medium}
|
|
128
|
+
style={[disabled && disabledTextStyle, textStyle]}
|
|
129
|
+
>
|
|
130
|
+
{title}
|
|
131
|
+
</Text>
|
|
132
|
+
)}
|
|
133
|
+
{right && <Spacer width={CONSTANTS.SPACE_8} />}
|
|
134
|
+
{!isLoading && right}
|
|
135
|
+
<Spacer width={right ? CONSTANTS.SPACE_12 : CONSTANTS.SPACE_16} />
|
|
136
|
+
</View>
|
|
137
|
+
</ScaleButton>
|
|
138
|
+
</View>
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const styles = StyleSheet.create({
|
|
143
|
+
container: {
|
|
144
|
+
flexDirection: "row",
|
|
145
|
+
},
|
|
146
|
+
disabled: { opacity: 0.6 },
|
|
147
|
+
button: {
|
|
148
|
+
height: CONSTANTS.BUTTON_HEIGHT,
|
|
149
|
+
flexDirection: "row",
|
|
150
|
+
alignItems: "center",
|
|
151
|
+
justifyContent: "space-between",
|
|
152
|
+
},
|
|
153
|
+
border: {
|
|
154
|
+
borderWidth: CONSTANTS.BORDER_WIDTH_1,
|
|
155
|
+
backgroundColor: "transparent",
|
|
156
|
+
},
|
|
157
|
+
small: {
|
|
158
|
+
height: CONSTANTS.BUTTON_HEIGHT_SMALL,
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
export default React.memo(Button);
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Created by Dung Nguyen on 25/04/25.
|
|
3
|
+
//
|
|
4
|
+
import React from "react";
|
|
5
|
+
import {
|
|
6
|
+
ActivityIndicator,
|
|
7
|
+
StyleProp,
|
|
8
|
+
ViewStyle,
|
|
9
|
+
StyleSheet,
|
|
10
|
+
} from "react-native";
|
|
11
|
+
import View from "../View";
|
|
12
|
+
import { memoDeepEqual } from "../../utils/function-utils";
|
|
13
|
+
import ScaleButton from "../ScaleButton";
|
|
14
|
+
import { CONSTANTS } from "../../styles/themes/tokens";
|
|
15
|
+
import { useInternalTheme } from "../../core/theming";
|
|
16
|
+
|
|
17
|
+
export interface ButtonIconProps {
|
|
18
|
+
isLoading?: boolean;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
onPress?: (val?: any) => void;
|
|
21
|
+
style?: StyleProp<ViewStyle>;
|
|
22
|
+
children?: React.ReactNode;
|
|
23
|
+
size?: number;
|
|
24
|
+
hiddenBackground?: boolean;
|
|
25
|
+
props?: object;
|
|
26
|
+
border?: boolean;
|
|
27
|
+
circle?: boolean;
|
|
28
|
+
backgroundColor?: string;
|
|
29
|
+
borderColor?: string;
|
|
30
|
+
}
|
|
31
|
+
const ButtonIcon = ({
|
|
32
|
+
isLoading,
|
|
33
|
+
disabled,
|
|
34
|
+
onPress,
|
|
35
|
+
style,
|
|
36
|
+
hiddenBackground = false,
|
|
37
|
+
size = CONSTANTS.BUTTON_HEIGHT,
|
|
38
|
+
border,
|
|
39
|
+
children,
|
|
40
|
+
circle,
|
|
41
|
+
backgroundColor,
|
|
42
|
+
borderColor,
|
|
43
|
+
props,
|
|
44
|
+
}: ButtonIconProps) => {
|
|
45
|
+
const { colors } = useInternalTheme();
|
|
46
|
+
return (
|
|
47
|
+
<ScaleButton
|
|
48
|
+
activeOpacity={0.8}
|
|
49
|
+
onPress={onPress}
|
|
50
|
+
{...props}
|
|
51
|
+
disabled={disabled || false}
|
|
52
|
+
>
|
|
53
|
+
<View
|
|
54
|
+
style={[
|
|
55
|
+
styles.btn,
|
|
56
|
+
!hiddenBackground
|
|
57
|
+
? {
|
|
58
|
+
backgroundColor: backgroundColor || colors.surfaceBrandDefault,
|
|
59
|
+
}
|
|
60
|
+
: {
|
|
61
|
+
backgroundColor: "transparent",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
width: size,
|
|
65
|
+
height: size,
|
|
66
|
+
},
|
|
67
|
+
border && {
|
|
68
|
+
borderWidth: CONSTANTS.BORDER_WIDTH_1,
|
|
69
|
+
borderColor: borderColor || colors.borderBrandDefault,
|
|
70
|
+
backgroundColor: backgroundColor || colors.surfacePrimaryDefault,
|
|
71
|
+
},
|
|
72
|
+
circle && {
|
|
73
|
+
borderRadius: size / 2,
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
disabled && {
|
|
77
|
+
borderWidth: 0,
|
|
78
|
+
backgroundColor: colors.surfaceBrandDisabled,
|
|
79
|
+
},
|
|
80
|
+
style,
|
|
81
|
+
]}
|
|
82
|
+
{...props}
|
|
83
|
+
>
|
|
84
|
+
{isLoading ? <ActivityIndicator size={"small"} /> : children}
|
|
85
|
+
</View>
|
|
86
|
+
</ScaleButton>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const styles = StyleSheet.create({
|
|
91
|
+
btn: {
|
|
92
|
+
justifyContent: "center",
|
|
93
|
+
alignItems: "center",
|
|
94
|
+
borderRadius: CONSTANTS.BORDER_RADIUS_6,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export default memoDeepEqual(ButtonIcon);
|