@draftbit/core 44.1.15 → 44.1.16
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/lib/commonjs/components/Picker/Picker.js +289 -26
- package/lib/commonjs/components/Picker/Picker.js.map +1 -1
- package/lib/module/components/Picker/Picker.js +281 -28
- package/lib/module/components/Picker/Picker.js.map +1 -1
- package/lib/typescript/src/components/Picker/Picker.d.ts +28 -4
- package/package.json +3 -4
- package/src/components/Picker/Picker.tsx +416 -34
- package/lib/commonjs/components/Picker/PickerComponent.android.js +0 -135
- package/lib/commonjs/components/Picker/PickerComponent.android.js.map +0 -1
- package/lib/commonjs/components/Picker/PickerComponent.ios.js +0 -161
- package/lib/commonjs/components/Picker/PickerComponent.ios.js.map +0 -1
- package/lib/commonjs/components/Picker/PickerComponent.web.js +0 -136
- package/lib/commonjs/components/Picker/PickerComponent.web.js.map +0 -1
- package/lib/commonjs/components/Picker/PickerTypes.js +0 -6
- package/lib/commonjs/components/Picker/PickerTypes.js.map +0 -1
- package/lib/module/components/Picker/PickerComponent.android.js +0 -112
- package/lib/module/components/Picker/PickerComponent.android.js.map +0 -1
- package/lib/module/components/Picker/PickerComponent.ios.js +0 -135
- package/lib/module/components/Picker/PickerComponent.ios.js.map +0 -1
- package/lib/module/components/Picker/PickerComponent.web.js +0 -113
- package/lib/module/components/Picker/PickerComponent.web.js.map +0 -1
- package/lib/module/components/Picker/PickerTypes.js +0 -2
- package/lib/module/components/Picker/PickerTypes.js.map +0 -1
- package/lib/typescript/src/components/Picker/PickerComponent.android.d.ts +0 -6
- package/lib/typescript/src/components/Picker/PickerComponent.ios.d.ts +0 -7
- package/lib/typescript/src/components/Picker/PickerComponent.web.d.ts +0 -6
- package/lib/typescript/src/components/Picker/PickerTypes.d.ts +0 -18
- package/src/components/Picker/PickerComponent.android.tsx +0 -116
- package/src/components/Picker/PickerComponent.ios.tsx +0 -142
- package/src/components/Picker/PickerComponent.web.tsx +0 -117
- package/src/components/Picker/PickerTypes.ts +0 -18
|
@@ -1,31 +1,77 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
Text,
|
|
6
|
+
Platform,
|
|
7
|
+
ViewStyle,
|
|
8
|
+
StyleProp,
|
|
9
|
+
Dimensions,
|
|
10
|
+
} from "react-native";
|
|
11
|
+
import { omit, pickBy, identity, isObject } from "lodash";
|
|
12
|
+
import { SafeAreaView } from "react-native-safe-area-context";
|
|
13
|
+
import { Picker as NativePicker } from "@react-native-picker/picker";
|
|
14
|
+
|
|
2
15
|
import { withTheme } from "../../theming";
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
16
|
+
import Portal from "../Portal/Portal";
|
|
17
|
+
import Button from "../DeprecatedButton";
|
|
18
|
+
import Touchable from "../Touchable";
|
|
19
|
+
import type { Theme } from "../../styles/DefaultTheme";
|
|
20
|
+
import type { IconSlot } from "../../interfaces/Icon";
|
|
21
|
+
import {
|
|
22
|
+
extractStyles,
|
|
23
|
+
extractBorderAndMarginStyles,
|
|
24
|
+
borderStyleNames,
|
|
25
|
+
marginStyleNames,
|
|
26
|
+
} from "../../utilities";
|
|
27
|
+
|
|
28
|
+
export interface PickerOption {
|
|
29
|
+
value: string;
|
|
30
|
+
label: string;
|
|
31
|
+
}
|
|
6
32
|
|
|
7
|
-
type
|
|
33
|
+
export type PickerProps = {
|
|
34
|
+
error?: any;
|
|
8
35
|
placeholder?: string;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
style?: StyleProp<ViewStyle> & { height?: number };
|
|
9
38
|
value?: string;
|
|
10
39
|
options: PickerOption[] | string[];
|
|
40
|
+
onValueChange: (value: string, index: number) => void;
|
|
41
|
+
defaultValue?: string;
|
|
42
|
+
assistiveText?: string;
|
|
43
|
+
label?: string;
|
|
44
|
+
iconColor?: string;
|
|
45
|
+
iconSize?: number;
|
|
46
|
+
leftIconMode?: "inset" | "outset";
|
|
47
|
+
leftIconName?: string;
|
|
48
|
+
placeholderTextColor?: string;
|
|
49
|
+
rightIconName?: string;
|
|
50
|
+
type?: "solid" | "underline";
|
|
51
|
+
theme: Theme;
|
|
52
|
+
Icon: IconSlot["Icon"];
|
|
11
53
|
};
|
|
12
54
|
|
|
13
|
-
function normalizeOptions(options:
|
|
55
|
+
function normalizeOptions(options: PickerProps["options"]): PickerOption[] {
|
|
14
56
|
if (options.length === 0) {
|
|
15
57
|
return [];
|
|
16
58
|
}
|
|
17
59
|
|
|
18
|
-
if (typeof options[0] === "string") {
|
|
60
|
+
if (typeof options[0] === ("string" || "number")) {
|
|
19
61
|
return (options as string[]).map((option) => ({
|
|
20
|
-
label: option,
|
|
62
|
+
label: String(option),
|
|
21
63
|
value: String(option),
|
|
22
64
|
}));
|
|
23
65
|
}
|
|
24
66
|
|
|
25
|
-
if (
|
|
26
|
-
|
|
67
|
+
if (
|
|
68
|
+
isObject(options[0]) &&
|
|
69
|
+
options[0].value !== null &&
|
|
70
|
+
options[0].label !== null
|
|
71
|
+
) {
|
|
72
|
+
return (options as PickerOption[]).map((option) => {
|
|
27
73
|
return {
|
|
28
|
-
label: option.label,
|
|
74
|
+
label: String(option.label),
|
|
29
75
|
value: String(option.value),
|
|
30
76
|
};
|
|
31
77
|
});
|
|
@@ -36,18 +82,45 @@ function normalizeOptions(options: Props["options"]): PickerOption[] {
|
|
|
36
82
|
);
|
|
37
83
|
}
|
|
38
84
|
|
|
39
|
-
const
|
|
85
|
+
const { width: deviceWidth, height: deviceHeight } = Dimensions.get("screen");
|
|
86
|
+
const isIos = Platform.OS === "ios";
|
|
87
|
+
const unstyledColor = "rgba(165, 173, 183, 1)";
|
|
88
|
+
const disabledColor = "rgb(240, 240, 240)";
|
|
89
|
+
const errorColor = "rgba(255, 69, 100, 1)";
|
|
90
|
+
|
|
91
|
+
const Picker: React.FC<PickerProps> = ({
|
|
92
|
+
error,
|
|
40
93
|
options = [],
|
|
94
|
+
onValueChange,
|
|
95
|
+
defaultValue,
|
|
96
|
+
Icon,
|
|
97
|
+
style,
|
|
41
98
|
placeholder,
|
|
42
|
-
onValueChange: onValueChangeOverride,
|
|
43
99
|
value,
|
|
44
|
-
|
|
45
|
-
|
|
100
|
+
disabled = false,
|
|
101
|
+
theme,
|
|
102
|
+
assistiveText,
|
|
103
|
+
label,
|
|
104
|
+
iconColor = unstyledColor,
|
|
105
|
+
iconSize = 24,
|
|
106
|
+
leftIconMode = "inset",
|
|
107
|
+
leftIconName,
|
|
108
|
+
placeholderTextColor = unstyledColor,
|
|
109
|
+
rightIconName,
|
|
110
|
+
type = "solid",
|
|
46
111
|
}) => {
|
|
112
|
+
const androidPickerRef = React.useRef<any | undefined>(undefined);
|
|
113
|
+
|
|
47
114
|
const [internalValue, setInternalValue] = React.useState<string | undefined>(
|
|
48
115
|
value || defaultValue
|
|
49
116
|
);
|
|
50
117
|
|
|
118
|
+
const [pickerVisible, setPickerVisible] = React.useState(false);
|
|
119
|
+
|
|
120
|
+
const togglePickerVisible = () => {
|
|
121
|
+
setPickerVisible(!pickerVisible);
|
|
122
|
+
};
|
|
123
|
+
|
|
51
124
|
React.useEffect(() => {
|
|
52
125
|
if (value != null) {
|
|
53
126
|
setInternalValue(value);
|
|
@@ -60,16 +133,11 @@ const Picker: React.FC<Props> = ({
|
|
|
60
133
|
}
|
|
61
134
|
}, [defaultValue]);
|
|
62
135
|
|
|
63
|
-
|
|
64
|
-
(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
onValueChangeOverride &&
|
|
69
|
-
onValueChangeOverride(String(itemValue), itemIndex);
|
|
70
|
-
},
|
|
71
|
-
[placeholder, onValueChangeOverride]
|
|
72
|
-
);
|
|
136
|
+
React.useEffect(() => {
|
|
137
|
+
if (pickerVisible && androidPickerRef.current) {
|
|
138
|
+
androidPickerRef?.current?.focus();
|
|
139
|
+
}
|
|
140
|
+
}, [pickerVisible, androidPickerRef]);
|
|
73
141
|
|
|
74
142
|
const normalizedOptions = normalizeOptions(options);
|
|
75
143
|
|
|
@@ -77,22 +145,336 @@ const Picker: React.FC<Props> = ({
|
|
|
77
145
|
? [{ value: placeholder, label: placeholder }, ...normalizedOptions]
|
|
78
146
|
: normalizedOptions;
|
|
79
147
|
|
|
148
|
+
const { colors } = theme;
|
|
149
|
+
|
|
150
|
+
const { viewStyles, textStyles } = extractStyles(style);
|
|
151
|
+
|
|
152
|
+
const additionalBorderStyles = ["backgroundColor"];
|
|
153
|
+
|
|
154
|
+
const additionalMarginStyles = [
|
|
155
|
+
"bottom",
|
|
156
|
+
"height",
|
|
157
|
+
"left",
|
|
158
|
+
"maxHeight",
|
|
159
|
+
"maxWidth",
|
|
160
|
+
"minHeight",
|
|
161
|
+
"minWidth",
|
|
162
|
+
"overflow",
|
|
163
|
+
"position",
|
|
164
|
+
"right",
|
|
165
|
+
"top",
|
|
166
|
+
"width",
|
|
167
|
+
"zIndex",
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
const {
|
|
171
|
+
borderStyles: extractedBorderStyles,
|
|
172
|
+
marginStyles: extractedMarginStyles,
|
|
173
|
+
} = extractBorderAndMarginStyles(
|
|
174
|
+
viewStyles,
|
|
175
|
+
additionalBorderStyles,
|
|
176
|
+
additionalMarginStyles
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const borderStyles = {
|
|
180
|
+
...{
|
|
181
|
+
...(type === "solid"
|
|
182
|
+
? {
|
|
183
|
+
borderTopLeftRadius: 5,
|
|
184
|
+
borderTopRightRadius: 5,
|
|
185
|
+
borderBottomRightRadius: 5,
|
|
186
|
+
borderBottomLeftRadius: 5,
|
|
187
|
+
borderTopWidth: 1,
|
|
188
|
+
borderRightWidth: 1,
|
|
189
|
+
borderLeftWidth: 1,
|
|
190
|
+
}
|
|
191
|
+
: {}),
|
|
192
|
+
borderBottomWidth: 1,
|
|
193
|
+
borderColor: unstyledColor,
|
|
194
|
+
borderStyle: "solid",
|
|
195
|
+
},
|
|
196
|
+
...extractedBorderStyles,
|
|
197
|
+
...(error ? { borderColor: errorColor } : {}),
|
|
198
|
+
...(disabled
|
|
199
|
+
? { borderColor: "transparent", backgroundColor: disabledColor }
|
|
200
|
+
: {}),
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const marginStyles = {
|
|
204
|
+
height: 60,
|
|
205
|
+
...extractedMarginStyles,
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const stylesWithoutBordersAndMargins = omit(viewStyles, [
|
|
209
|
+
...borderStyleNames,
|
|
210
|
+
...marginStyleNames,
|
|
211
|
+
...additionalBorderStyles,
|
|
212
|
+
...additionalMarginStyles,
|
|
213
|
+
]);
|
|
214
|
+
|
|
215
|
+
const selectedLabel =
|
|
216
|
+
internalValue &&
|
|
217
|
+
((pickerOptions as unknown as PickerOption[]).find(
|
|
218
|
+
(option) => option.value === internalValue
|
|
219
|
+
)?.label ??
|
|
220
|
+
internalValue);
|
|
221
|
+
|
|
222
|
+
const labelText = label ? (
|
|
223
|
+
<Text
|
|
224
|
+
style={{
|
|
225
|
+
textAlign: textStyles.textAlign,
|
|
226
|
+
color: unstyledColor,
|
|
227
|
+
fontSize: 12,
|
|
228
|
+
paddingBottom: 4,
|
|
229
|
+
}}
|
|
230
|
+
>
|
|
231
|
+
{label}
|
|
232
|
+
</Text>
|
|
233
|
+
) : null;
|
|
234
|
+
|
|
235
|
+
const leftIconOutset = leftIconMode === "outset";
|
|
236
|
+
|
|
237
|
+
const leftIcon = leftIconName ? (
|
|
238
|
+
<Icon
|
|
239
|
+
name={leftIconName}
|
|
240
|
+
color={disabled ? unstyledColor : iconColor}
|
|
241
|
+
size={iconSize}
|
|
242
|
+
style={{
|
|
243
|
+
marginRight: 4,
|
|
244
|
+
marginLeft: 4,
|
|
245
|
+
}}
|
|
246
|
+
/>
|
|
247
|
+
) : null;
|
|
248
|
+
|
|
249
|
+
const rightIcon = rightIconName ? (
|
|
250
|
+
<Icon
|
|
251
|
+
name={rightIconName}
|
|
252
|
+
color={disabled ? unstyledColor : iconColor}
|
|
253
|
+
size={iconSize}
|
|
254
|
+
style={{
|
|
255
|
+
marginRight: -10,
|
|
256
|
+
marginLeft: 8,
|
|
257
|
+
}}
|
|
258
|
+
/>
|
|
259
|
+
) : null;
|
|
260
|
+
|
|
261
|
+
const textAlign = textStyles?.textAlign;
|
|
262
|
+
|
|
263
|
+
const calculateLeftPadding = () => {
|
|
264
|
+
if (leftIconOutset) {
|
|
265
|
+
if (textAlign === "center") {
|
|
266
|
+
return iconSize - Math.abs(8 - iconSize);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return iconSize + 8;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return 0;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const assistiveTextLabel = assistiveText ? (
|
|
276
|
+
<Text
|
|
277
|
+
style={{
|
|
278
|
+
textAlign,
|
|
279
|
+
width: "100%",
|
|
280
|
+
paddingLeft: calculateLeftPadding(),
|
|
281
|
+
color: unstyledColor,
|
|
282
|
+
fontSize: 12,
|
|
283
|
+
paddingTop: 4,
|
|
284
|
+
}}
|
|
285
|
+
>
|
|
286
|
+
{assistiveText}
|
|
287
|
+
</Text>
|
|
288
|
+
) : null;
|
|
289
|
+
|
|
290
|
+
const primaryTextStyle = {
|
|
291
|
+
color: unstyledColor,
|
|
292
|
+
fontSize: 14,
|
|
293
|
+
...pickBy(textStyles, identity),
|
|
294
|
+
...(placeholder === internalValue ? { color: placeholderTextColor } : {}),
|
|
295
|
+
...(disabled ? { color: unstyledColor } : {}),
|
|
296
|
+
};
|
|
297
|
+
|
|
80
298
|
const handleValueChange = (newValue: string, itemIndex: number) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
onValueChange(newValue, itemIndex);
|
|
299
|
+
if (!placeholder || itemIndex > 0) {
|
|
300
|
+
onValueChange?.(newValue, itemIndex);
|
|
84
301
|
}
|
|
302
|
+
setInternalValue(newValue);
|
|
85
303
|
};
|
|
86
304
|
|
|
87
305
|
return (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
306
|
+
/* marginsContainer */
|
|
307
|
+
<View style={[styles.marginsContainer, marginStyles]}>
|
|
308
|
+
{/* touchableContainer */}
|
|
309
|
+
<Touchable
|
|
310
|
+
disabled={disabled}
|
|
311
|
+
onPress={togglePickerVisible}
|
|
312
|
+
style={styles.touchableContainer}
|
|
313
|
+
>
|
|
314
|
+
{/* outsetContainer */}
|
|
315
|
+
<View
|
|
316
|
+
pointerEvents="none"
|
|
317
|
+
style={[
|
|
318
|
+
styles.outsetContainer,
|
|
319
|
+
stylesWithoutBordersAndMargins,
|
|
320
|
+
!leftIconOutset ? (borderStyles as PickerProps["style"]) : {},
|
|
321
|
+
]}
|
|
322
|
+
>
|
|
323
|
+
{leftIcon}
|
|
324
|
+
|
|
325
|
+
{/* insetContainer */}
|
|
326
|
+
<View
|
|
327
|
+
style={[
|
|
328
|
+
styles.insetContainer,
|
|
329
|
+
leftIconOutset ? (borderStyles as PickerProps["style"]) : {},
|
|
330
|
+
]}
|
|
331
|
+
>
|
|
332
|
+
{/* primaryTextContainer */}
|
|
333
|
+
<View style={styles.primaryTextContainer}>
|
|
334
|
+
{labelText}
|
|
335
|
+
|
|
336
|
+
<Text style={primaryTextStyle}>
|
|
337
|
+
{String(selectedLabel ?? placeholder)}
|
|
338
|
+
</Text>
|
|
339
|
+
</View>
|
|
340
|
+
|
|
341
|
+
{rightIcon}
|
|
342
|
+
</View>
|
|
343
|
+
</View>
|
|
344
|
+
{assistiveTextLabel}
|
|
345
|
+
</Touchable>
|
|
346
|
+
|
|
347
|
+
{/* iosPicker */}
|
|
348
|
+
{isIos && pickerVisible ? (
|
|
349
|
+
<Portal>
|
|
350
|
+
<View
|
|
351
|
+
style={[
|
|
352
|
+
styles.iosPicker,
|
|
353
|
+
{
|
|
354
|
+
backgroundColor: colors.divider,
|
|
355
|
+
},
|
|
356
|
+
]}
|
|
357
|
+
>
|
|
358
|
+
<SafeAreaView style={styles.iosSafeArea}>
|
|
359
|
+
<Button
|
|
360
|
+
Icon={Icon}
|
|
361
|
+
type="text"
|
|
362
|
+
onPress={togglePickerVisible}
|
|
363
|
+
style={styles.iosButton}
|
|
364
|
+
>
|
|
365
|
+
{"Close"}
|
|
366
|
+
</Button>
|
|
367
|
+
|
|
368
|
+
<NativePicker
|
|
369
|
+
style={styles.iosNativePicker}
|
|
370
|
+
selectedValue={internalValue}
|
|
371
|
+
onValueChange={handleValueChange}
|
|
372
|
+
>
|
|
373
|
+
{(pickerOptions as unknown as PickerOption[]).map((option) => (
|
|
374
|
+
<NativePicker.Item
|
|
375
|
+
label={option.label}
|
|
376
|
+
value={option.value}
|
|
377
|
+
key={option.value}
|
|
378
|
+
/>
|
|
379
|
+
))}
|
|
380
|
+
</NativePicker>
|
|
381
|
+
</SafeAreaView>
|
|
382
|
+
</View>
|
|
383
|
+
</Portal>
|
|
384
|
+
) : null}
|
|
385
|
+
|
|
386
|
+
{/* nonIosPicker */}
|
|
387
|
+
{!isIos && pickerVisible ? (
|
|
388
|
+
<NativePicker
|
|
389
|
+
enabled={pickerVisible}
|
|
390
|
+
selectedValue={internalValue}
|
|
391
|
+
onValueChange={handleValueChange}
|
|
392
|
+
style={styles.nonIosPicker}
|
|
393
|
+
ref={androidPickerRef}
|
|
394
|
+
onBlur={() => setPickerVisible(false)}
|
|
395
|
+
>
|
|
396
|
+
{(pickerOptions as unknown as PickerOption[]).map((option) => (
|
|
397
|
+
<NativePicker.Item
|
|
398
|
+
label={option.label}
|
|
399
|
+
value={option.value}
|
|
400
|
+
key={option.value}
|
|
401
|
+
/>
|
|
402
|
+
))}
|
|
403
|
+
</NativePicker>
|
|
404
|
+
) : null}
|
|
405
|
+
</View>
|
|
95
406
|
);
|
|
96
407
|
};
|
|
97
408
|
|
|
98
409
|
export default withTheme(Picker);
|
|
410
|
+
|
|
411
|
+
const styles = StyleSheet.create({
|
|
412
|
+
marginsContainer: {
|
|
413
|
+
alignSelf: "stretch",
|
|
414
|
+
alignItems: "center",
|
|
415
|
+
width: "100%",
|
|
416
|
+
maxWidth: deviceWidth,
|
|
417
|
+
},
|
|
418
|
+
touchableContainer: {
|
|
419
|
+
flex: 1,
|
|
420
|
+
height: "100%",
|
|
421
|
+
width: "100%",
|
|
422
|
+
alignSelf: "stretch",
|
|
423
|
+
alignItems: "center",
|
|
424
|
+
},
|
|
425
|
+
outsetContainer: {
|
|
426
|
+
flex: 1,
|
|
427
|
+
height: "100%",
|
|
428
|
+
width: "100%",
|
|
429
|
+
flexDirection: "row",
|
|
430
|
+
alignItems: "center",
|
|
431
|
+
justifyContent: "space-between",
|
|
432
|
+
},
|
|
433
|
+
insetContainer: {
|
|
434
|
+
flex: 1,
|
|
435
|
+
height: "100%",
|
|
436
|
+
width: "100%",
|
|
437
|
+
flexDirection: "row",
|
|
438
|
+
alignItems: "center",
|
|
439
|
+
justifyContent: "space-between",
|
|
440
|
+
paddingLeft: 12,
|
|
441
|
+
paddingRight: 12,
|
|
442
|
+
},
|
|
443
|
+
primaryTextContainer: {
|
|
444
|
+
flex: 1,
|
|
445
|
+
},
|
|
446
|
+
iosPicker: {
|
|
447
|
+
position: "absolute",
|
|
448
|
+
bottom: 0,
|
|
449
|
+
left: 0,
|
|
450
|
+
right: 0,
|
|
451
|
+
flexDirection: "row",
|
|
452
|
+
justifyContent: "center",
|
|
453
|
+
width: "100%",
|
|
454
|
+
maxWidth: deviceWidth,
|
|
455
|
+
maxHeight: deviceHeight,
|
|
456
|
+
},
|
|
457
|
+
iosSafeArea: {
|
|
458
|
+
backgroundColor: "white",
|
|
459
|
+
flexDirection: "column",
|
|
460
|
+
width: "100%",
|
|
461
|
+
maxWidth: deviceWidth,
|
|
462
|
+
},
|
|
463
|
+
iosButton: {
|
|
464
|
+
alignSelf: "flex-end",
|
|
465
|
+
},
|
|
466
|
+
iosNativePicker: {
|
|
467
|
+
backgroundColor: "white",
|
|
468
|
+
},
|
|
469
|
+
nonIosPicker: {
|
|
470
|
+
opacity: 0,
|
|
471
|
+
position: "absolute",
|
|
472
|
+
top: 0,
|
|
473
|
+
left: 0,
|
|
474
|
+
right: 0,
|
|
475
|
+
bottom: 0,
|
|
476
|
+
width: "100%",
|
|
477
|
+
maxWidth: deviceWidth,
|
|
478
|
+
maxHeight: deviceHeight,
|
|
479
|
+
},
|
|
480
|
+
});
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var React = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
|
-
var _reactNative = require("react-native");
|
|
11
|
-
|
|
12
|
-
var _lodash = _interopRequireDefault(require("lodash.omit"));
|
|
13
|
-
|
|
14
|
-
var _theming = require("../../theming");
|
|
15
|
-
|
|
16
|
-
var _picker = require("@react-native-picker/picker");
|
|
17
|
-
|
|
18
|
-
var _utilities = require("../../utilities");
|
|
19
|
-
|
|
20
|
-
var _TextField = _interopRequireDefault(require("../TextField"));
|
|
21
|
-
|
|
22
|
-
var _Touchable = _interopRequireDefault(require("../Touchable"));
|
|
23
|
-
|
|
24
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
27
|
-
|
|
28
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
29
|
-
|
|
30
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
31
|
-
|
|
32
|
-
const Picker = _ref => {
|
|
33
|
-
var _options$find$label, _options$find;
|
|
34
|
-
|
|
35
|
-
let {
|
|
36
|
-
style,
|
|
37
|
-
options,
|
|
38
|
-
placeholder,
|
|
39
|
-
selectedValue,
|
|
40
|
-
disabled = false,
|
|
41
|
-
onValueChange: onValueChangeOverride = () => {},
|
|
42
|
-
...props
|
|
43
|
-
} = _ref;
|
|
44
|
-
const {
|
|
45
|
-
viewStyles: {
|
|
46
|
-
borderRadius,
|
|
47
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
48
|
-
borderWidth,
|
|
49
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
50
|
-
borderTopWidth,
|
|
51
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
52
|
-
borderRightWidth,
|
|
53
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
54
|
-
borderBottomWidth,
|
|
55
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
56
|
-
borderLeftWidth,
|
|
57
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
58
|
-
borderColor,
|
|
59
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
60
|
-
backgroundColor,
|
|
61
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
62
|
-
padding,
|
|
63
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
64
|
-
paddingTop,
|
|
65
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
66
|
-
paddingRight,
|
|
67
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
68
|
-
paddingBottom,
|
|
69
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
70
|
-
paddingLeft,
|
|
71
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
72
|
-
...viewStyles
|
|
73
|
-
}
|
|
74
|
-
} = (0, _utilities.extractStyles)(style);
|
|
75
|
-
const textField = React.useRef(undefined);
|
|
76
|
-
|
|
77
|
-
const onValueChange = (itemValue, itemIndex) => {
|
|
78
|
-
toggleFocus();
|
|
79
|
-
onValueChangeOverride(itemValue, itemIndex);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const toggleFocus = () => {
|
|
83
|
-
if (!disabled) {
|
|
84
|
-
// @ts-ignore
|
|
85
|
-
textField.current.toggleFocus(); // cannot determine if method exists due to component being wrapped in a withTheme()
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const stylesWithoutMargin = style && (0, _lodash.default)(_reactNative.StyleSheet.flatten(style), ["margin", "marginTop", "marginRight", "marginBottom", "marginLeft"]);
|
|
90
|
-
const selectedLabel = selectedValue && ((_options$find$label = (_options$find = options.find(o => o.value === selectedValue)) === null || _options$find === void 0 ? void 0 : _options$find.label) !== null && _options$find$label !== void 0 ? _options$find$label : selectedValue);
|
|
91
|
-
return /*#__PURE__*/React.createElement(_Touchable.default, {
|
|
92
|
-
disabled: disabled,
|
|
93
|
-
onPress: toggleFocus,
|
|
94
|
-
style: [styles.container, viewStyles]
|
|
95
|
-
}, /*#__PURE__*/React.createElement(_reactNative.View, null, /*#__PURE__*/React.createElement(_picker.Picker, {
|
|
96
|
-
enabled: !disabled,
|
|
97
|
-
selectedValue: selectedValue,
|
|
98
|
-
onValueChange: onValueChange,
|
|
99
|
-
style: {
|
|
100
|
-
opacity: 0,
|
|
101
|
-
position: "absolute",
|
|
102
|
-
top: 0,
|
|
103
|
-
left: 0,
|
|
104
|
-
right: 0,
|
|
105
|
-
bottom: 0,
|
|
106
|
-
width: "100%"
|
|
107
|
-
}
|
|
108
|
-
}, options.map(o => /*#__PURE__*/React.createElement(_picker.Picker.Item, {
|
|
109
|
-
label: o.label,
|
|
110
|
-
value: o.value,
|
|
111
|
-
key: o.value
|
|
112
|
-
}))), /*#__PURE__*/React.createElement(_reactNative.View, {
|
|
113
|
-
pointerEvents: "none"
|
|
114
|
-
}, /*#__PURE__*/React.createElement(_TextField.default, _extends({}, props, {
|
|
115
|
-
value: selectedLabel,
|
|
116
|
-
placeholder: placeholder // @ts-ignore
|
|
117
|
-
,
|
|
118
|
-
ref: textField // cannot determine if ref is of correct type due to component being wrapped in a withTheme()
|
|
119
|
-
,
|
|
120
|
-
disabled: disabled // @ts-expect-error
|
|
121
|
-
,
|
|
122
|
-
style: stylesWithoutMargin
|
|
123
|
-
})))));
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const styles = _reactNative.StyleSheet.create({
|
|
127
|
-
container: {
|
|
128
|
-
alignSelf: "stretch"
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
var _default = (0, _theming.withTheme)(Picker);
|
|
133
|
-
|
|
134
|
-
exports.default = _default;
|
|
135
|
-
//# sourceMappingURL=PickerComponent.android.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["PickerComponent.android.tsx"],"names":["Picker","style","options","placeholder","selectedValue","disabled","onValueChange","onValueChangeOverride","props","viewStyles","borderRadius","borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderColor","backgroundColor","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","textField","React","useRef","undefined","itemValue","itemIndex","toggleFocus","current","stylesWithoutMargin","StyleSheet","flatten","selectedLabel","find","o","value","label","styles","container","opacity","position","top","left","right","bottom","width","map","create","alignSelf"],"mappings":"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","sourcesContent":["import * as React from \"react\";\nimport { View, StyleSheet } from \"react-native\";\nimport omit from \"lodash.omit\";\nimport { withTheme } from \"../../theming\";\nimport { Picker as NativePicker } from \"@react-native-picker/picker\";\nimport { extractStyles } from \"../../utilities\";\n\nimport TextField from \"../TextField\";\nimport Touchable from \"../Touchable\";\nimport { PickerComponentProps } from \"./PickerTypes\";\n\nconst Picker: React.FC<PickerComponentProps> = ({\n style,\n options,\n placeholder,\n selectedValue,\n disabled = false,\n onValueChange: onValueChangeOverride = () => {},\n ...props\n}) => {\n const {\n viewStyles: {\n borderRadius, // eslint-disable-line @typescript-eslint/no-unused-vars\n borderWidth, // eslint-disable-line @typescript-eslint/no-unused-vars\n borderTopWidth, // eslint-disable-line @typescript-eslint/no-unused-vars\n borderRightWidth, // eslint-disable-line @typescript-eslint/no-unused-vars\n borderBottomWidth, // eslint-disable-line @typescript-eslint/no-unused-vars\n borderLeftWidth, // eslint-disable-line @typescript-eslint/no-unused-vars\n borderColor, // eslint-disable-line @typescript-eslint/no-unused-vars\n backgroundColor, // eslint-disable-line @typescript-eslint/no-unused-vars\n padding, // eslint-disable-line @typescript-eslint/no-unused-vars\n paddingTop, // eslint-disable-line @typescript-eslint/no-unused-vars\n paddingRight, // eslint-disable-line @typescript-eslint/no-unused-vars\n paddingBottom, // eslint-disable-line @typescript-eslint/no-unused-vars\n paddingLeft, // eslint-disable-line @typescript-eslint/no-unused-vars\n ...viewStyles\n },\n } = extractStyles(style);\n\n const textField = React.useRef<typeof TextField | undefined>(undefined);\n\n const onValueChange = (itemValue: string, itemIndex: number) => {\n toggleFocus();\n onValueChangeOverride(itemValue, itemIndex);\n };\n\n const toggleFocus = () => {\n if (!disabled) {\n // @ts-ignore\n textField.current.toggleFocus(); // cannot determine if method exists due to component being wrapped in a withTheme()\n }\n };\n\n const stylesWithoutMargin =\n style &&\n omit(StyleSheet.flatten(style), [\n \"margin\",\n \"marginTop\",\n \"marginRight\",\n \"marginBottom\",\n \"marginLeft\",\n ]);\n\n const selectedLabel =\n selectedValue &&\n (options.find((o) => o.value === selectedValue)?.label ?? selectedValue);\n\n return (\n <Touchable\n disabled={disabled}\n onPress={toggleFocus}\n style={[styles.container, viewStyles]}\n >\n <View>\n <NativePicker\n enabled={!disabled}\n selectedValue={selectedValue}\n onValueChange={onValueChange}\n style={{\n opacity: 0,\n position: \"absolute\",\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n width: \"100%\",\n }}\n >\n {options.map((o) => (\n <NativePicker.Item label={o.label} value={o.value} key={o.value} />\n ))}\n </NativePicker>\n <View pointerEvents=\"none\">\n <TextField\n {...props}\n value={selectedLabel}\n placeholder={placeholder}\n // @ts-ignore\n ref={textField} // cannot determine if ref is of correct type due to component being wrapped in a withTheme()\n disabled={disabled}\n // @ts-expect-error\n style={stylesWithoutMargin}\n />\n </View>\n </View>\n </Touchable>\n );\n};\n\nconst styles = StyleSheet.create({\n container: {\n alignSelf: \"stretch\",\n },\n});\n\nexport default withTheme(Picker);\n"]}
|