rnnovaui 0.8.8 → 0.8.9
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
|
@@ -12,10 +12,6 @@ import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
|
12
12
|
|
|
13
13
|
import { useUITheme } from "../../theme";
|
|
14
14
|
|
|
15
|
-
/* =========================================================
|
|
16
|
-
CONSTANTS
|
|
17
|
-
========================================================= */
|
|
18
|
-
|
|
19
15
|
const RADIO_GROUP_ORIENTATIONS = {
|
|
20
16
|
vertical: "vertical",
|
|
21
17
|
horizontal: "horizontal",
|
|
@@ -27,10 +23,6 @@ const RADIO_GROUP_SIZES = {
|
|
|
27
23
|
lg: "lg",
|
|
28
24
|
};
|
|
29
25
|
|
|
30
|
-
/* =========================================================
|
|
31
|
-
CONTEXT
|
|
32
|
-
========================================================= */
|
|
33
|
-
|
|
34
26
|
const RadioGroupContext = createContext(null);
|
|
35
27
|
|
|
36
28
|
/* =========================================================
|
|
@@ -158,18 +150,20 @@ const UIRadioGroupComponent = forwardRef(function UIRadioGroup(
|
|
|
158
150
|
</Text>
|
|
159
151
|
) : null}
|
|
160
152
|
|
|
161
|
-
{/* OPTIONS */}
|
|
153
|
+
{/* RADIO OPTIONS */}
|
|
162
154
|
|
|
163
155
|
<View
|
|
164
156
|
style={[
|
|
165
157
|
styles.options,
|
|
166
158
|
|
|
167
159
|
resolvedOrientation === "horizontal"
|
|
168
|
-
? styles.
|
|
169
|
-
: styles.
|
|
160
|
+
? styles.horizontal
|
|
161
|
+
: styles.vertical,
|
|
170
162
|
|
|
171
163
|
{
|
|
172
|
-
gap,
|
|
164
|
+
columnGap: gap,
|
|
165
|
+
|
|
166
|
+
rowGap: gap,
|
|
173
167
|
},
|
|
174
168
|
]}
|
|
175
169
|
>
|
|
@@ -182,7 +176,7 @@ const UIRadioGroupComponent = forwardRef(function UIRadioGroup(
|
|
|
182
176
|
})}
|
|
183
177
|
</View>
|
|
184
178
|
|
|
185
|
-
{/* ERROR */}
|
|
179
|
+
{/* ERROR / HELPER */}
|
|
186
180
|
|
|
187
181
|
{hasError ? (
|
|
188
182
|
<Text
|
|
@@ -294,7 +288,7 @@ const UIRadioOptionComponent = function UIRadioOptionComponent({
|
|
|
294
288
|
style,
|
|
295
289
|
]}
|
|
296
290
|
>
|
|
297
|
-
{/* RADIO */}
|
|
291
|
+
{/* RADIO CIRCLE */}
|
|
298
292
|
|
|
299
293
|
<View
|
|
300
294
|
style={[
|
|
@@ -338,10 +332,10 @@ const UIRadioOptionComponent = function UIRadioOptionComponent({
|
|
|
338
332
|
) : null}
|
|
339
333
|
</View>
|
|
340
334
|
|
|
341
|
-
{/* LABEL
|
|
335
|
+
{/* LABEL */}
|
|
342
336
|
|
|
343
337
|
<View style={styles.content}>
|
|
344
|
-
{label !==
|
|
338
|
+
{label !== "" ? (
|
|
345
339
|
<Text
|
|
346
340
|
style={[
|
|
347
341
|
styles.optionLabel,
|
|
@@ -363,9 +357,9 @@ const UIRadioOptionComponent = function UIRadioOptionComponent({
|
|
|
363
357
|
</Text>
|
|
364
358
|
) : null}
|
|
365
359
|
|
|
366
|
-
{description !==
|
|
367
|
-
description !==
|
|
368
|
-
|
|
360
|
+
{description !== "" &&
|
|
361
|
+
description !== null &&
|
|
362
|
+
description !== undefined ? (
|
|
369
363
|
<Text
|
|
370
364
|
style={[
|
|
371
365
|
styles.description,
|
|
@@ -412,7 +406,7 @@ function getRadioSize(size) {
|
|
|
412
406
|
case "md":
|
|
413
407
|
default:
|
|
414
408
|
return {
|
|
415
|
-
outer:
|
|
409
|
+
outer: 20,
|
|
416
410
|
inner: 9,
|
|
417
411
|
fontSize: 14,
|
|
418
412
|
lineHeight: 20,
|
|
@@ -430,7 +424,7 @@ const styles = StyleSheet.create({
|
|
|
430
424
|
},
|
|
431
425
|
|
|
432
426
|
groupLabel: {
|
|
433
|
-
marginBottom:
|
|
427
|
+
marginBottom: 12,
|
|
434
428
|
|
|
435
429
|
fontSize: 14,
|
|
436
430
|
|
|
@@ -443,40 +437,48 @@ const styles = StyleSheet.create({
|
|
|
443
437
|
|
|
444
438
|
options: {
|
|
445
439
|
width: "100%",
|
|
440
|
+
|
|
441
|
+
flexDirection: "row",
|
|
442
|
+
|
|
443
|
+
flexWrap: "wrap",
|
|
444
|
+
|
|
445
|
+
alignItems: "flex-start",
|
|
446
446
|
},
|
|
447
447
|
|
|
448
|
-
|
|
448
|
+
vertical: {
|
|
449
449
|
flexDirection: "column",
|
|
450
450
|
|
|
451
451
|
alignItems: "stretch",
|
|
452
452
|
},
|
|
453
453
|
|
|
454
|
-
|
|
454
|
+
horizontal: {
|
|
455
455
|
flexDirection: "row",
|
|
456
456
|
|
|
457
457
|
flexWrap: "wrap",
|
|
458
458
|
|
|
459
|
-
alignItems: "
|
|
460
|
-
|
|
461
|
-
justifyContent: "flex-start",
|
|
459
|
+
alignItems: "center",
|
|
462
460
|
},
|
|
463
461
|
|
|
462
|
+
/*
|
|
463
|
+
* IMPORTANT:
|
|
464
|
+
*
|
|
465
|
+
* The option does NOT have
|
|
466
|
+
* width: "100%".
|
|
467
|
+
*
|
|
468
|
+
* Therefore horizontal options
|
|
469
|
+
* use only the width they need.
|
|
470
|
+
*/
|
|
471
|
+
|
|
464
472
|
option: {
|
|
465
473
|
flexDirection: "row",
|
|
466
474
|
|
|
467
|
-
alignItems: "
|
|
475
|
+
alignItems: "center",
|
|
468
476
|
|
|
469
|
-
/*
|
|
470
|
-
* IMPORTANT:
|
|
471
|
-
*
|
|
472
|
-
* No width: "100%" here.
|
|
473
|
-
*
|
|
474
|
-
* That was the reason horizontal
|
|
475
|
-
* layout was not working.
|
|
476
|
-
*/
|
|
477
477
|
flexShrink: 0,
|
|
478
478
|
|
|
479
|
-
|
|
479
|
+
flexGrow: 0,
|
|
480
|
+
|
|
481
|
+
minHeight: 32,
|
|
480
482
|
},
|
|
481
483
|
|
|
482
484
|
radio: {
|
|
@@ -485,26 +487,24 @@ const styles = StyleSheet.create({
|
|
|
485
487
|
alignItems: "center",
|
|
486
488
|
|
|
487
489
|
justifyContent: "center",
|
|
488
|
-
|
|
489
|
-
marginTop: 1,
|
|
490
490
|
},
|
|
491
491
|
|
|
492
492
|
radioDot: {},
|
|
493
493
|
|
|
494
494
|
content: {
|
|
495
|
-
flexShrink:
|
|
496
|
-
|
|
497
|
-
minWidth: 0,
|
|
495
|
+
flexShrink: 0,
|
|
498
496
|
|
|
499
|
-
|
|
497
|
+
flexGrow: 0,
|
|
500
498
|
|
|
501
|
-
|
|
499
|
+
marginLeft: 8,
|
|
502
500
|
},
|
|
503
501
|
|
|
504
502
|
optionLabel: {
|
|
505
503
|
fontWeight: "500",
|
|
506
504
|
|
|
507
505
|
includeFontPadding: false,
|
|
506
|
+
|
|
507
|
+
flexShrink: 0,
|
|
508
508
|
},
|
|
509
509
|
|
|
510
510
|
description: {
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
forwardRef,
|
|
3
|
+
memo,
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
} from "react";
|
|
2
9
|
|
|
3
10
|
import {
|
|
11
|
+
ActivityIndicator,
|
|
4
12
|
Animated,
|
|
5
|
-
Easing,
|
|
6
13
|
Pressable,
|
|
7
14
|
StyleSheet,
|
|
8
15
|
Text,
|
|
@@ -11,283 +18,480 @@ import {
|
|
|
11
18
|
|
|
12
19
|
import { useUITheme } from "../../theme";
|
|
13
20
|
|
|
14
|
-
const
|
|
21
|
+
const UI_SWITCH_SIZES = {
|
|
15
22
|
sm: "sm",
|
|
16
23
|
md: "md",
|
|
17
24
|
lg: "lg",
|
|
18
25
|
};
|
|
19
26
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
const SIZE_CONFIG = {
|
|
28
|
+
sm: {
|
|
29
|
+
width: 38,
|
|
30
|
+
height: 22,
|
|
31
|
+
thumb: 16,
|
|
32
|
+
padding: 3,
|
|
33
|
+
labelSize: 13,
|
|
34
|
+
descriptionSize: 11,
|
|
35
|
+
},
|
|
26
36
|
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
md: {
|
|
38
|
+
width: 48,
|
|
39
|
+
height: 28,
|
|
40
|
+
thumb: 22,
|
|
41
|
+
padding: 3,
|
|
42
|
+
labelSize: 14,
|
|
43
|
+
descriptionSize: 12,
|
|
44
|
+
},
|
|
29
45
|
|
|
30
|
-
|
|
46
|
+
lg: {
|
|
47
|
+
width: 58,
|
|
48
|
+
height: 34,
|
|
49
|
+
thumb: 28,
|
|
50
|
+
padding: 3,
|
|
51
|
+
labelSize: 16,
|
|
52
|
+
descriptionSize: 13,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
31
55
|
|
|
32
|
-
|
|
56
|
+
const UISwitchComponent = forwardRef(function UISwitch(
|
|
57
|
+
{
|
|
58
|
+
value,
|
|
59
|
+
defaultValue = false,
|
|
33
60
|
|
|
34
|
-
|
|
61
|
+
onChange,
|
|
35
62
|
|
|
36
|
-
|
|
63
|
+
label,
|
|
64
|
+
description,
|
|
37
65
|
|
|
38
|
-
|
|
66
|
+
size = "md",
|
|
39
67
|
|
|
40
|
-
|
|
68
|
+
disabled = false,
|
|
69
|
+
loading = false,
|
|
41
70
|
|
|
42
|
-
|
|
71
|
+
error = false,
|
|
72
|
+
errorText,
|
|
43
73
|
|
|
44
|
-
|
|
74
|
+
helperText,
|
|
45
75
|
|
|
46
|
-
|
|
76
|
+
activeColor,
|
|
77
|
+
inactiveColor,
|
|
78
|
+
thumbColor,
|
|
47
79
|
|
|
48
|
-
|
|
80
|
+
animated = true,
|
|
81
|
+
animationDuration = 180,
|
|
49
82
|
|
|
50
|
-
|
|
83
|
+
animatePress = true,
|
|
84
|
+
pressScale = 0.92,
|
|
51
85
|
|
|
52
|
-
|
|
86
|
+
labelPosition = "right",
|
|
53
87
|
|
|
54
|
-
|
|
88
|
+
containerStyle,
|
|
89
|
+
switchStyle,
|
|
90
|
+
labelStyle,
|
|
91
|
+
descriptionStyle,
|
|
92
|
+
helperStyle,
|
|
93
|
+
errorStyle,
|
|
55
94
|
|
|
56
|
-
|
|
95
|
+
testID,
|
|
96
|
+
accessibilityLabel,
|
|
57
97
|
|
|
58
|
-
|
|
59
|
-
}
|
|
98
|
+
...props
|
|
99
|
+
},
|
|
100
|
+
ref,
|
|
101
|
+
) {
|
|
60
102
|
const { theme } = useUITheme();
|
|
61
103
|
|
|
62
104
|
const colors = theme?.colors || {};
|
|
63
105
|
|
|
64
|
-
const
|
|
106
|
+
const config = SIZE_CONFIG[UI_SWITCH_SIZES[size] ? size : UI_SWITCH_SIZES.md];
|
|
107
|
+
|
|
108
|
+
/*
|
|
109
|
+
* --------------------------------------------------
|
|
110
|
+
* CONTROLLED / UNCONTROLLED
|
|
111
|
+
* --------------------------------------------------
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
const isControlled = value !== undefined;
|
|
115
|
+
|
|
116
|
+
const [internalValue, setInternalValue] = useState(Boolean(defaultValue));
|
|
117
|
+
|
|
118
|
+
const checked = isControlled ? Boolean(value) : internalValue;
|
|
65
119
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
120
|
+
/*
|
|
121
|
+
* --------------------------------------------------
|
|
122
|
+
* ANIMATION
|
|
123
|
+
* --------------------------------------------------
|
|
124
|
+
*/
|
|
69
125
|
|
|
70
|
-
const
|
|
126
|
+
const progress = useRef(new Animated.Value(checked ? 1 : 0)).current;
|
|
71
127
|
|
|
72
|
-
const
|
|
128
|
+
const pressScaleValue = useRef(new Animated.Value(1)).current;
|
|
73
129
|
|
|
74
|
-
|
|
130
|
+
/*
|
|
131
|
+
* --------------------------------------------------
|
|
132
|
+
* VALUE ANIMATION
|
|
133
|
+
* --------------------------------------------------
|
|
134
|
+
*/
|
|
75
135
|
|
|
76
136
|
useEffect(() => {
|
|
77
|
-
|
|
78
|
-
toValue: value ? 1 : 0,
|
|
137
|
+
const target = checked ? 1 : 0;
|
|
79
138
|
|
|
80
|
-
|
|
139
|
+
if (!animated) {
|
|
140
|
+
progress.setValue(target);
|
|
81
141
|
|
|
82
|
-
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
Animated.timing(progress, {
|
|
146
|
+
toValue: target,
|
|
147
|
+
|
|
148
|
+
duration: Math.max(0, animationDuration),
|
|
83
149
|
|
|
84
150
|
useNativeDriver: true,
|
|
85
151
|
}).start();
|
|
86
|
-
}, [
|
|
152
|
+
}, [checked, animated, animationDuration, progress]);
|
|
153
|
+
|
|
154
|
+
/*
|
|
155
|
+
* --------------------------------------------------
|
|
156
|
+
* PRESS ANIMATION
|
|
157
|
+
* --------------------------------------------------
|
|
158
|
+
*/
|
|
87
159
|
|
|
88
|
-
const
|
|
89
|
-
if (disabled) {
|
|
160
|
+
const animatePressIn = useCallback(() => {
|
|
161
|
+
if (!animated || !animatePress || disabled || loading) {
|
|
90
162
|
return;
|
|
91
163
|
}
|
|
92
164
|
|
|
93
|
-
|
|
94
|
-
|
|
165
|
+
Animated.spring(pressScaleValue, {
|
|
166
|
+
toValue: pressScale,
|
|
95
167
|
|
|
96
|
-
|
|
97
|
-
inputRange: [0, 1],
|
|
168
|
+
friction: 7,
|
|
98
169
|
|
|
99
|
-
|
|
100
|
-
|
|
170
|
+
tension: 120,
|
|
171
|
+
|
|
172
|
+
useNativeDriver: true,
|
|
173
|
+
}).start();
|
|
174
|
+
}, [animated, animatePress, disabled, loading, pressScale, pressScaleValue]);
|
|
175
|
+
|
|
176
|
+
const animatePressOut = useCallback(() => {
|
|
177
|
+
if (!animated || !animatePress) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
Animated.spring(pressScaleValue, {
|
|
182
|
+
toValue: 1,
|
|
183
|
+
|
|
184
|
+
friction: 7,
|
|
185
|
+
|
|
186
|
+
tension: 120,
|
|
187
|
+
|
|
188
|
+
useNativeDriver: true,
|
|
189
|
+
}).start();
|
|
190
|
+
}, [animated, animatePress, pressScaleValue]);
|
|
191
|
+
|
|
192
|
+
/*
|
|
193
|
+
* --------------------------------------------------
|
|
194
|
+
* CHANGE
|
|
195
|
+
* --------------------------------------------------
|
|
196
|
+
*/
|
|
197
|
+
|
|
198
|
+
const handleChange = useCallback(() => {
|
|
199
|
+
if (disabled || loading) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const nextValue = !checked;
|
|
204
|
+
|
|
205
|
+
if (!isControlled) {
|
|
206
|
+
setInternalValue(nextValue);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
onChange?.(nextValue);
|
|
210
|
+
}, [disabled, loading, checked, isControlled, onChange]);
|
|
211
|
+
|
|
212
|
+
/*
|
|
213
|
+
* --------------------------------------------------
|
|
214
|
+
* COLORS
|
|
215
|
+
* --------------------------------------------------
|
|
216
|
+
*/
|
|
101
217
|
|
|
102
|
-
const
|
|
218
|
+
const resolvedActiveColor = activeColor || colors.primary || "#FF5A1F";
|
|
219
|
+
|
|
220
|
+
const resolvedInactiveColor =
|
|
221
|
+
inactiveColor || colors.borderStrong || "#D4D4D4";
|
|
222
|
+
|
|
223
|
+
const resolvedThumbColor = thumbColor || colors.background || "#FFFFFF";
|
|
224
|
+
|
|
225
|
+
const disabledOpacity = disabled ? 0.5 : 1;
|
|
226
|
+
|
|
227
|
+
/*
|
|
228
|
+
* --------------------------------------------------
|
|
229
|
+
* THUMB MOVEMENT
|
|
230
|
+
* --------------------------------------------------
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
const travel = config.width - config.thumb - config.padding * 2;
|
|
234
|
+
|
|
235
|
+
const translateX = progress.interpolate({
|
|
103
236
|
inputRange: [0, 1],
|
|
104
237
|
|
|
105
|
-
outputRange: [
|
|
238
|
+
outputRange: [0, travel],
|
|
239
|
+
|
|
240
|
+
extrapolate: "clamp",
|
|
106
241
|
});
|
|
107
242
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
accessibilityRole="switch"
|
|
114
|
-
accessibilityLabel={accessibilityLabel || label}
|
|
115
|
-
accessibilityHint={accessibilityHint}
|
|
116
|
-
accessibilityState={{
|
|
117
|
-
checked: value,
|
|
243
|
+
/*
|
|
244
|
+
* --------------------------------------------------
|
|
245
|
+
* SWITCH
|
|
246
|
+
* --------------------------------------------------
|
|
247
|
+
*/
|
|
118
248
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
249
|
+
const switchElement = (
|
|
250
|
+
<Animated.View
|
|
251
|
+
style={[
|
|
252
|
+
{
|
|
253
|
+
width: config.width,
|
|
254
|
+
|
|
255
|
+
height: config.height,
|
|
256
|
+
|
|
257
|
+
borderRadius: config.height / 2,
|
|
258
|
+
|
|
259
|
+
backgroundColor: checked
|
|
260
|
+
? resolvedActiveColor
|
|
261
|
+
: resolvedInactiveColor,
|
|
262
|
+
|
|
263
|
+
opacity: disabledOpacity,
|
|
126
264
|
|
|
265
|
+
transform: [
|
|
127
266
|
{
|
|
128
|
-
|
|
267
|
+
scale: pressScaleValue,
|
|
129
268
|
},
|
|
130
|
-
]
|
|
131
|
-
|
|
132
|
-
|
|
269
|
+
],
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
switchStyle,
|
|
273
|
+
]}
|
|
274
|
+
>
|
|
275
|
+
<Animated.View
|
|
276
|
+
style={[
|
|
277
|
+
styles.thumb,
|
|
278
|
+
|
|
279
|
+
{
|
|
280
|
+
width: config.thumb,
|
|
281
|
+
|
|
282
|
+
height: config.thumb,
|
|
283
|
+
|
|
284
|
+
borderRadius: config.thumb / 2,
|
|
285
|
+
|
|
286
|
+
backgroundColor: resolvedThumbColor,
|
|
287
|
+
|
|
288
|
+
top: config.padding,
|
|
289
|
+
|
|
290
|
+
left: config.padding,
|
|
291
|
+
|
|
292
|
+
transform: [
|
|
293
|
+
{
|
|
294
|
+
translateX,
|
|
295
|
+
},
|
|
296
|
+
],
|
|
297
|
+
},
|
|
298
|
+
]}
|
|
299
|
+
>
|
|
300
|
+
{loading ? (
|
|
301
|
+
<ActivityIndicator size="small" color={resolvedActiveColor} />
|
|
302
|
+
) : null}
|
|
303
|
+
</Animated.View>
|
|
304
|
+
</Animated.View>
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
/*
|
|
308
|
+
* --------------------------------------------------
|
|
309
|
+
* LABEL CONTENT
|
|
310
|
+
* --------------------------------------------------
|
|
311
|
+
*/
|
|
312
|
+
|
|
313
|
+
const textContent =
|
|
314
|
+
label || description ? (
|
|
315
|
+
<View
|
|
316
|
+
style={[
|
|
317
|
+
styles.textContainer,
|
|
318
|
+
|
|
319
|
+
labelPosition === "left" ? styles.textLeft : styles.textRight,
|
|
320
|
+
]}
|
|
321
|
+
>
|
|
322
|
+
{label ? (
|
|
323
|
+
<Text
|
|
133
324
|
style={[
|
|
134
|
-
styles.
|
|
325
|
+
styles.label,
|
|
135
326
|
|
|
136
327
|
{
|
|
137
|
-
|
|
328
|
+
fontSize: config.labelSize,
|
|
138
329
|
|
|
139
|
-
|
|
330
|
+
color: disabled
|
|
331
|
+
? colors.textDisabled || "#A3A3A3"
|
|
332
|
+
: colors.text || "#111111",
|
|
333
|
+
},
|
|
140
334
|
|
|
141
|
-
|
|
335
|
+
labelStyle,
|
|
336
|
+
]}
|
|
337
|
+
>
|
|
338
|
+
{label}
|
|
339
|
+
</Text>
|
|
340
|
+
) : null}
|
|
341
|
+
|
|
342
|
+
{description ? (
|
|
343
|
+
<Text
|
|
344
|
+
style={[
|
|
345
|
+
styles.description,
|
|
346
|
+
|
|
347
|
+
{
|
|
348
|
+
fontSize: config.descriptionSize,
|
|
142
349
|
|
|
143
|
-
|
|
350
|
+
color: disabled
|
|
351
|
+
? colors.textDisabled || "#A3A3A3"
|
|
352
|
+
: colors.textSecondary || "#525252",
|
|
144
353
|
},
|
|
145
354
|
|
|
146
|
-
|
|
355
|
+
descriptionStyle,
|
|
147
356
|
]}
|
|
148
357
|
>
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
color: colors.textSecondary || "#525252",
|
|
197
|
-
},
|
|
198
|
-
|
|
199
|
-
descriptionStyle,
|
|
200
|
-
]}
|
|
201
|
-
>
|
|
202
|
-
{description}
|
|
203
|
-
</Text>
|
|
204
|
-
) : null}
|
|
205
|
-
</View>
|
|
206
|
-
) : null}
|
|
207
|
-
</View>
|
|
358
|
+
{description}
|
|
359
|
+
</Text>
|
|
360
|
+
) : null}
|
|
361
|
+
</View>
|
|
362
|
+
) : null;
|
|
363
|
+
|
|
364
|
+
/*
|
|
365
|
+
* --------------------------------------------------
|
|
366
|
+
* MAIN
|
|
367
|
+
* --------------------------------------------------
|
|
368
|
+
*/
|
|
369
|
+
|
|
370
|
+
return (
|
|
371
|
+
<View
|
|
372
|
+
ref={ref}
|
|
373
|
+
testID={testID}
|
|
374
|
+
style={[styles.container, containerStyle]}
|
|
375
|
+
{...props}
|
|
376
|
+
>
|
|
377
|
+
<Pressable
|
|
378
|
+
disabled={disabled || loading}
|
|
379
|
+
onPress={handleChange}
|
|
380
|
+
onPressIn={animatePressIn}
|
|
381
|
+
onPressOut={animatePressOut}
|
|
382
|
+
accessibilityRole="switch"
|
|
383
|
+
accessibilityLabel={accessibilityLabel || label}
|
|
384
|
+
accessibilityState={{
|
|
385
|
+
checked,
|
|
386
|
+
disabled: disabled || loading,
|
|
387
|
+
}}
|
|
388
|
+
style={[
|
|
389
|
+
styles.pressable,
|
|
390
|
+
|
|
391
|
+
labelPosition === "left" ? styles.rowReverse : styles.row,
|
|
392
|
+
]}
|
|
393
|
+
>
|
|
394
|
+
{labelPosition === "left" ? (
|
|
395
|
+
<>
|
|
396
|
+
{textContent}
|
|
397
|
+
{switchElement}
|
|
398
|
+
</>
|
|
399
|
+
) : (
|
|
400
|
+
<>
|
|
401
|
+
{switchElement}
|
|
402
|
+
{textContent}
|
|
403
|
+
</>
|
|
404
|
+
)}
|
|
208
405
|
</Pressable>
|
|
406
|
+
|
|
407
|
+
{error || errorText ? (
|
|
408
|
+
<Text
|
|
409
|
+
style={[
|
|
410
|
+
styles.message,
|
|
411
|
+
|
|
412
|
+
{
|
|
413
|
+
color: colors.danger || "#DC2626",
|
|
414
|
+
},
|
|
415
|
+
|
|
416
|
+
errorStyle,
|
|
417
|
+
]}
|
|
418
|
+
>
|
|
419
|
+
{errorText}
|
|
420
|
+
</Text>
|
|
421
|
+
) : helperText ? (
|
|
422
|
+
<Text
|
|
423
|
+
style={[
|
|
424
|
+
styles.message,
|
|
425
|
+
|
|
426
|
+
{
|
|
427
|
+
color: colors.textSecondary || "#525252",
|
|
428
|
+
},
|
|
429
|
+
|
|
430
|
+
helperStyle,
|
|
431
|
+
]}
|
|
432
|
+
>
|
|
433
|
+
{helperText}
|
|
434
|
+
</Text>
|
|
435
|
+
) : null}
|
|
209
436
|
</View>
|
|
210
437
|
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function getActiveColor(variant, colors) {
|
|
214
|
-
switch (variant) {
|
|
215
|
-
case SWITCH_VARIANTS.secondary:
|
|
216
|
-
return colors.secondary || "#7CFF32";
|
|
217
|
-
|
|
218
|
-
case SWITCH_VARIANTS.success:
|
|
219
|
-
return colors.success || "#16A34A";
|
|
220
|
-
|
|
221
|
-
case SWITCH_VARIANTS.danger:
|
|
222
|
-
return colors.danger || "#DC2626";
|
|
223
|
-
|
|
224
|
-
case SWITCH_VARIANTS.primary:
|
|
225
|
-
default:
|
|
226
|
-
return colors.primary || "#FF5A1F";
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function getDimensions(size) {
|
|
231
|
-
switch (size) {
|
|
232
|
-
case SWITCH_SIZES.sm:
|
|
233
|
-
return {
|
|
234
|
-
trackWidth: 40,
|
|
235
|
-
trackHeight: 22,
|
|
236
|
-
thumbSize: 18,
|
|
237
|
-
thumbTravel: 18,
|
|
238
|
-
fontSize: 13,
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
case SWITCH_SIZES.lg:
|
|
242
|
-
return {
|
|
243
|
-
trackWidth: 58,
|
|
244
|
-
trackHeight: 32,
|
|
245
|
-
thumbSize: 28,
|
|
246
|
-
thumbTravel: 26,
|
|
247
|
-
fontSize: 16,
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
case SWITCH_SIZES.md:
|
|
251
|
-
default:
|
|
252
|
-
return {
|
|
253
|
-
trackWidth: 48,
|
|
254
|
-
trackHeight: 28,
|
|
255
|
-
thumbSize: 24,
|
|
256
|
-
thumbTravel: 20,
|
|
257
|
-
fontSize: 14,
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
}
|
|
438
|
+
});
|
|
261
439
|
|
|
262
440
|
const styles = StyleSheet.create({
|
|
263
|
-
|
|
264
|
-
|
|
441
|
+
container: {
|
|
442
|
+
width: "100%",
|
|
265
443
|
},
|
|
266
444
|
|
|
267
445
|
pressable: {
|
|
268
|
-
|
|
446
|
+
alignItems: "center",
|
|
269
447
|
|
|
270
|
-
|
|
448
|
+
minHeight: 36,
|
|
271
449
|
},
|
|
272
450
|
|
|
273
451
|
row: {
|
|
274
452
|
flexDirection: "row",
|
|
453
|
+
},
|
|
275
454
|
|
|
276
|
-
|
|
455
|
+
rowReverse: {
|
|
456
|
+
flexDirection: "row-reverse",
|
|
277
457
|
},
|
|
278
458
|
|
|
279
|
-
|
|
280
|
-
|
|
459
|
+
textContainer: {
|
|
460
|
+
flex: 1,
|
|
281
461
|
|
|
282
|
-
|
|
462
|
+
minWidth: 0,
|
|
463
|
+
},
|
|
464
|
+
|
|
465
|
+
textRight: {
|
|
466
|
+
marginLeft: 10,
|
|
467
|
+
},
|
|
468
|
+
|
|
469
|
+
textLeft: {
|
|
470
|
+
marginRight: 10,
|
|
471
|
+
},
|
|
283
472
|
|
|
284
|
-
|
|
473
|
+
label: {
|
|
474
|
+
fontWeight: "600",
|
|
285
475
|
|
|
286
|
-
|
|
476
|
+
lineHeight: 20,
|
|
477
|
+
|
|
478
|
+
includeFontPadding: false,
|
|
479
|
+
},
|
|
480
|
+
|
|
481
|
+
description: {
|
|
482
|
+
marginTop: 3,
|
|
483
|
+
|
|
484
|
+
lineHeight: 17,
|
|
485
|
+
|
|
486
|
+
includeFontPadding: false,
|
|
287
487
|
},
|
|
288
488
|
|
|
289
489
|
thumb: {
|
|
290
|
-
|
|
490
|
+
position: "absolute",
|
|
491
|
+
|
|
492
|
+
alignItems: "center",
|
|
493
|
+
|
|
494
|
+
justifyContent: "center",
|
|
291
495
|
|
|
292
496
|
elevation: 2,
|
|
293
497
|
|
|
@@ -295,34 +499,21 @@ const styles = StyleSheet.create({
|
|
|
295
499
|
|
|
296
500
|
shadowOffset: {
|
|
297
501
|
width: 0,
|
|
502
|
+
|
|
298
503
|
height: 1,
|
|
299
504
|
},
|
|
300
505
|
|
|
301
|
-
shadowOpacity: 0.
|
|
506
|
+
shadowOpacity: 0.2,
|
|
302
507
|
|
|
303
508
|
shadowRadius: 2,
|
|
304
509
|
},
|
|
305
510
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
marginLeft: 12,
|
|
310
|
-
},
|
|
311
|
-
|
|
312
|
-
label: {
|
|
313
|
-
fontWeight: "600",
|
|
314
|
-
|
|
315
|
-
lineHeight: 20,
|
|
316
|
-
|
|
317
|
-
includeFontPadding: false,
|
|
318
|
-
},
|
|
319
|
-
|
|
320
|
-
description: {
|
|
321
|
-
marginTop: 2,
|
|
511
|
+
message: {
|
|
512
|
+
marginTop: 6,
|
|
322
513
|
|
|
323
514
|
fontSize: 12,
|
|
324
515
|
|
|
325
|
-
lineHeight:
|
|
516
|
+
lineHeight: 16,
|
|
326
517
|
|
|
327
518
|
includeFontPadding: false,
|
|
328
519
|
},
|
|
@@ -332,6 +523,6 @@ export const UISwitch = memo(UISwitchComponent);
|
|
|
332
523
|
|
|
333
524
|
UISwitch.displayName = "UISwitch";
|
|
334
525
|
|
|
335
|
-
export {
|
|
526
|
+
export { UI_SWITCH_SIZES as UISwitchSizes };
|
|
336
527
|
|
|
337
528
|
export default UISwitch;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { UISwitch, UISwitchSizes
|
|
1
|
+
export { UISwitch, UISwitchSizes } from "./UISwitch";
|
package/src/components/index.js
CHANGED
|
@@ -22,7 +22,7 @@ export {
|
|
|
22
22
|
export { UIInput, UIInputVariants, UIInputSizes, UIInputStates } from "./Input";
|
|
23
23
|
export { UICheckbox, UICheckboxSizes, UICheckboxVariants } from "./Checkbox";
|
|
24
24
|
export { UIRadio, UIRadioSizes, UIRadioVariants } from "./Radio";
|
|
25
|
-
export { UISwitch, UISwitchSizes
|
|
25
|
+
export { UISwitch, UISwitchSizes } from "./Switch";
|
|
26
26
|
export {
|
|
27
27
|
UIAvatar,
|
|
28
28
|
UIAvatarSizes,
|