@draftbit/core 48.4.9-a58004.2 → 48.4.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/lib/commonjs/components/Checkbox/Checkbox.js +1 -1
- package/lib/commonjs/components/IconButton.js +1 -1
- package/lib/commonjs/components/Picker/Picker.js +1 -0
- package/lib/commonjs/components/Picker/PickerComponent.android.js +1 -0
- package/lib/commonjs/components/Picker/PickerComponent.ios.js +1 -0
- package/lib/commonjs/components/Picker/PickerComponent.web.js +1 -0
- package/lib/commonjs/components/Picker/PickerTypes.js +1 -0
- package/lib/commonjs/components/TextField.js +1 -1
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/utilities.js +1 -1
- package/lib/typescript/src/components/Checkbox/Checkbox.js +1 -1
- package/lib/typescript/src/components/Checkbox/Checkbox.js.map +1 -1
- package/lib/typescript/src/components/IconButton.js +0 -2
- package/lib/typescript/src/components/IconButton.js.map +1 -1
- package/lib/typescript/src/components/Picker/Picker.d.ts +36 -0
- package/lib/typescript/src/components/Picker/Picker.js +288 -0
- package/lib/typescript/src/components/Picker/Picker.js.map +1 -0
- package/lib/typescript/src/components/Picker/PickerComponent.android.d.ts +6 -0
- package/lib/typescript/src/components/Picker/PickerComponent.android.js +70 -0
- package/lib/typescript/src/components/Picker/PickerComponent.android.js.map +1 -0
- package/lib/typescript/src/components/Picker/PickerComponent.ios.d.ts +7 -0
- package/lib/typescript/src/components/Picker/PickerComponent.ios.js +80 -0
- package/lib/typescript/src/components/Picker/PickerComponent.ios.js.map +1 -0
- package/lib/typescript/src/components/Picker/PickerComponent.web.d.ts +6 -0
- package/lib/typescript/src/components/Picker/PickerComponent.web.js +71 -0
- package/lib/typescript/src/components/Picker/PickerComponent.web.js.map +1 -0
- package/lib/typescript/src/components/Picker/PickerTypes.d.ts +18 -0
- package/lib/typescript/src/components/Picker/PickerTypes.js +2 -0
- package/lib/typescript/src/components/Picker/PickerTypes.js.map +1 -0
- package/lib/typescript/src/components/TextField.d.ts +3 -3
- package/lib/typescript/src/components/TextField.js +6 -9
- package/lib/typescript/src/components/TextField.js.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.js +1 -1
- package/lib/typescript/src/index.js.map +1 -1
- package/lib/typescript/src/utilities.d.ts +0 -8
- package/lib/typescript/src/utilities.js +1 -22
- package/lib/typescript/src/utilities.js.map +1 -1
- package/lib/typescript/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -5
- package/src/components/Checkbox/Checkbox.js +1 -1
- package/src/components/Checkbox/Checkbox.js.map +1 -1
- package/src/components/Checkbox/Checkbox.tsx +1 -1
- package/src/components/IconButton.js +0 -2
- package/src/components/IconButton.js.map +1 -1
- package/src/components/IconButton.tsx +0 -2
- package/src/components/Picker/Picker.js +288 -0
- package/src/components/Picker/Picker.js.map +1 -0
- package/src/components/Picker/Picker.tsx +509 -0
- package/src/components/Picker/PickerComponent.android.js +70 -0
- package/src/components/Picker/PickerComponent.android.js.map +1 -0
- package/src/components/Picker/PickerComponent.android.tsx +116 -0
- package/src/components/Picker/PickerComponent.ios.js +80 -0
- package/src/components/Picker/PickerComponent.ios.js.map +1 -0
- package/src/components/Picker/PickerComponent.ios.tsx +142 -0
- package/src/components/Picker/PickerComponent.web.js +71 -0
- package/src/components/Picker/PickerComponent.web.js.map +1 -0
- package/src/components/Picker/PickerComponent.web.tsx +117 -0
- package/src/components/Picker/PickerTypes.js +2 -0
- package/src/components/Picker/PickerTypes.js.map +1 -0
- package/src/components/Picker/PickerTypes.ts +18 -0
- package/src/components/TextField.js +6 -9
- package/src/components/TextField.js.map +1 -1
- package/src/components/TextField.tsx +8 -14
- package/src/index.js +1 -1
- package/src/index.js.map +1 -1
- package/src/index.tsx +1 -1
- package/src/utilities.js +1 -22
- package/src/utilities.js.map +1 -1
- package/src/utilities.ts +1 -33
- package/lib/commonjs/components/Picker/NativePicker.js +0 -1
- package/lib/commonjs/components/Picker/PickerCommon.js +0 -1
- package/lib/commonjs/components/Picker/PickerInputContainer.js +0 -1
- package/lib/commonjs/components/Picker/dropdown/DropDownPicker.js +0 -1
- package/lib/commonjs/components/Picker/dropdown/MultiSelectPicker.js +0 -1
- package/lib/commonjs/components/Picker/index.js +0 -1
- package/lib/typescript/src/components/Picker/NativePicker.d.ts +0 -4
- package/lib/typescript/src/components/Picker/NativePicker.js +0 -92
- package/lib/typescript/src/components/Picker/NativePicker.js.map +0 -1
- package/lib/typescript/src/components/Picker/PickerCommon.d.ts +0 -51
- package/lib/typescript/src/components/Picker/PickerCommon.js +0 -23
- package/lib/typescript/src/components/Picker/PickerCommon.js.map +0 -1
- package/lib/typescript/src/components/Picker/PickerInputContainer.d.ts +0 -10
- package/lib/typescript/src/components/Picker/PickerInputContainer.js +0 -37
- package/lib/typescript/src/components/Picker/PickerInputContainer.js.map +0 -1
- package/lib/typescript/src/components/Picker/dropdown/DropDownPicker.d.ts +0 -6
- package/lib/typescript/src/components/Picker/dropdown/DropDownPicker.js +0 -44
- package/lib/typescript/src/components/Picker/dropdown/DropDownPicker.js.map +0 -1
- package/lib/typescript/src/components/Picker/dropdown/MultiSelectPicker.d.ts +0 -6
- package/lib/typescript/src/components/Picker/dropdown/MultiSelectPicker.js +0 -9
- package/lib/typescript/src/components/Picker/dropdown/MultiSelectPicker.js.map +0 -1
- package/lib/typescript/src/components/Picker/index.d.ts +0 -9
- package/lib/typescript/src/components/Picker/index.js +0 -16
- package/lib/typescript/src/components/Picker/index.js.map +0 -1
- package/src/components/Picker/NativePicker.js +0 -92
- package/src/components/Picker/NativePicker.js.map +0 -1
- package/src/components/Picker/NativePicker.tsx +0 -152
- package/src/components/Picker/PickerCommon.js +0 -23
- package/src/components/Picker/PickerCommon.js.map +0 -1
- package/src/components/Picker/PickerCommon.ts +0 -87
- package/src/components/Picker/PickerInputContainer.js +0 -37
- package/src/components/Picker/PickerInputContainer.js.map +0 -1
- package/src/components/Picker/PickerInputContainer.tsx +0 -85
- package/src/components/Picker/dropdown/DropDownPicker.js +0 -44
- package/src/components/Picker/dropdown/DropDownPicker.js.map +0 -1
- package/src/components/Picker/dropdown/DropDownPicker.tsx +0 -122
- package/src/components/Picker/dropdown/MultiSelectPicker.js +0 -9
- package/src/components/Picker/dropdown/MultiSelectPicker.js.map +0 -1
- package/src/components/Picker/dropdown/MultiSelectPicker.tsx +0 -16
- package/src/components/Picker/index.js +0 -16
- package/src/components/Picker/index.js.map +0 -1
- package/src/components/Picker/index.tsx +0 -22
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { View, StyleSheet, Platform, Keyboard } from "react-native";
|
|
3
|
-
import { SafeAreaView } from "react-native-safe-area-context";
|
|
4
|
-
import { Picker as NativePickerComponent } from "@react-native-picker/picker";
|
|
5
|
-
import Portal from "../Portal/Portal";
|
|
6
|
-
import { Button } from "../Button";
|
|
7
|
-
import { useDeepCompareMemo } from "../../utilities";
|
|
8
|
-
import { normalizeToPickerOptions, } from "./PickerCommon";
|
|
9
|
-
import PickerInputContainer from "./PickerInputContainer";
|
|
10
|
-
const isIos = Platform.OS === "ios";
|
|
11
|
-
const isWeb = Platform.OS === "web";
|
|
12
|
-
const NativePicker = ({ options: optionsProp = [], onValueChange, Icon, placeholder, value, autoDismissKeyboard = true, ...rest }) => {
|
|
13
|
-
const pickerRef = React.useRef(null);
|
|
14
|
-
const [pickerVisible, setPickerVisible] = React.useState(false);
|
|
15
|
-
const options = useDeepCompareMemo(() => {
|
|
16
|
-
const normalizedOptions = normalizeToPickerOptions(optionsProp);
|
|
17
|
-
// Underlying Picker component defaults selection to first element when value is not provided (or undefined)
|
|
18
|
-
// Placholder must be the 1st option in order to allow selection of the 'actual' 1st option
|
|
19
|
-
if (placeholder) {
|
|
20
|
-
return [{ label: placeholder, value: placeholder }, ...normalizedOptions];
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
return normalizedOptions;
|
|
24
|
-
}
|
|
25
|
-
}, [placeholder, optionsProp]);
|
|
26
|
-
// When no placeholder is provided then first item should be marked selected to reflect underlying Picker internal state
|
|
27
|
-
if (!placeholder && options.length && !value && value !== options[0].value) {
|
|
28
|
-
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(options[0].value);
|
|
29
|
-
}
|
|
30
|
-
const renderNativePicker = () => (React.createElement(NativePickerComponent, { ref: pickerRef, selectedValue: value, onValueChange: (newValue) => {
|
|
31
|
-
if (newValue !== placeholder) {
|
|
32
|
-
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(newValue);
|
|
33
|
-
}
|
|
34
|
-
else if (newValue === placeholder) {
|
|
35
|
-
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange("");
|
|
36
|
-
}
|
|
37
|
-
}, style: [
|
|
38
|
-
styles.nativePicker,
|
|
39
|
-
isIos ? styles.iosNativePicker : styles.nonIosPicker,
|
|
40
|
-
], onBlur: () => setPickerVisible(false) }, options.map((option) => (React.createElement(NativePickerComponent.Item, { label: option.label.toString(), value: option.value, key: option.value })))));
|
|
41
|
-
const renderPicker = () => {
|
|
42
|
-
if (isIos) {
|
|
43
|
-
return (React.createElement(Portal, null,
|
|
44
|
-
React.createElement(SafeAreaView, { style: styles.nativePicker },
|
|
45
|
-
React.createElement(View, { style: styles.iosPickerContent },
|
|
46
|
-
React.createElement(Button, { Icon: Icon, type: "text", onPress: () => setPickerVisible(!pickerVisible), style: styles.iosButton }, "Close"),
|
|
47
|
-
renderNativePicker()))));
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
return renderNativePicker();
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
React.useEffect(() => {
|
|
54
|
-
var _a;
|
|
55
|
-
if (pickerVisible && pickerRef.current) {
|
|
56
|
-
(_a = pickerRef === null || pickerRef === void 0 ? void 0 : pickerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
57
|
-
}
|
|
58
|
-
}, [pickerVisible, pickerRef]);
|
|
59
|
-
React.useEffect(() => {
|
|
60
|
-
if (pickerVisible && autoDismissKeyboard) {
|
|
61
|
-
Keyboard.dismiss();
|
|
62
|
-
}
|
|
63
|
-
}, [pickerVisible, autoDismissKeyboard]);
|
|
64
|
-
return (React.createElement(PickerInputContainer, { Icon: Icon, placeholder: placeholder, selectedValue: value, options: options, onPress: () => setPickerVisible(!pickerVisible), ...rest }, (pickerVisible || isWeb) && renderPicker()));
|
|
65
|
-
};
|
|
66
|
-
const styles = StyleSheet.create({
|
|
67
|
-
nativePicker: {
|
|
68
|
-
position: "absolute",
|
|
69
|
-
bottom: 0,
|
|
70
|
-
left: 0,
|
|
71
|
-
right: 0,
|
|
72
|
-
flexDirection: "row",
|
|
73
|
-
justifyContent: "center",
|
|
74
|
-
width: "100%",
|
|
75
|
-
backgroundColor: "white",
|
|
76
|
-
},
|
|
77
|
-
iosPickerContent: {
|
|
78
|
-
flexDirection: "column",
|
|
79
|
-
width: "100%",
|
|
80
|
-
},
|
|
81
|
-
iosButton: {
|
|
82
|
-
alignSelf: "flex-end",
|
|
83
|
-
},
|
|
84
|
-
iosNativePicker: {
|
|
85
|
-
backgroundColor: "white",
|
|
86
|
-
},
|
|
87
|
-
nonIosPicker: {
|
|
88
|
-
opacity: 0,
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
export default NativePicker;
|
|
92
|
-
//# sourceMappingURL=NativePicker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NativePicker.js","sourceRoot":"","sources":["NativePicker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,MAAM,IAAI,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OA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AE,UAAU;KACtB;IACD,eAAe,EAAE;QACf,eAAe,EAAE,OAAO;KACzB;IACD,YAAY,EAAE;QACZ,OAAO,EAAE,CAAC;KACX;CACF,CAAC,CAAC;AAEH,eAAe,YAAY,CAAC"}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { View, StyleSheet, Platform, Keyboard } from "react-native";
|
|
3
|
-
import { SafeAreaView } from "react-native-safe-area-context";
|
|
4
|
-
import { Picker as NativePickerComponent } from "@react-native-picker/picker";
|
|
5
|
-
import Portal from "../Portal/Portal";
|
|
6
|
-
import { Button } from "../Button";
|
|
7
|
-
import { useDeepCompareMemo } from "../../utilities";
|
|
8
|
-
import {
|
|
9
|
-
CommonPickerProps,
|
|
10
|
-
SinglePickerProps,
|
|
11
|
-
normalizeToPickerOptions,
|
|
12
|
-
} from "./PickerCommon";
|
|
13
|
-
import PickerInputContainer from "./PickerInputContainer";
|
|
14
|
-
|
|
15
|
-
const isIos = Platform.OS === "ios";
|
|
16
|
-
const isWeb = Platform.OS === "web";
|
|
17
|
-
|
|
18
|
-
const NativePicker: React.FC<CommonPickerProps & SinglePickerProps> = ({
|
|
19
|
-
options: optionsProp = [],
|
|
20
|
-
onValueChange,
|
|
21
|
-
Icon,
|
|
22
|
-
placeholder,
|
|
23
|
-
value,
|
|
24
|
-
autoDismissKeyboard = true,
|
|
25
|
-
...rest
|
|
26
|
-
}) => {
|
|
27
|
-
const pickerRef = React.useRef<NativePickerComponent<string | number>>(null);
|
|
28
|
-
|
|
29
|
-
const [pickerVisible, setPickerVisible] = React.useState(false);
|
|
30
|
-
|
|
31
|
-
const options = useDeepCompareMemo(() => {
|
|
32
|
-
const normalizedOptions = normalizeToPickerOptions(optionsProp);
|
|
33
|
-
|
|
34
|
-
// Underlying Picker component defaults selection to first element when value is not provided (or undefined)
|
|
35
|
-
// Placholder must be the 1st option in order to allow selection of the 'actual' 1st option
|
|
36
|
-
if (placeholder) {
|
|
37
|
-
return [{ label: placeholder, value: placeholder }, ...normalizedOptions];
|
|
38
|
-
} else {
|
|
39
|
-
return normalizedOptions;
|
|
40
|
-
}
|
|
41
|
-
}, [placeholder, optionsProp]);
|
|
42
|
-
|
|
43
|
-
// When no placeholder is provided then first item should be marked selected to reflect underlying Picker internal state
|
|
44
|
-
if (!placeholder && options.length && !value && value !== options[0].value) {
|
|
45
|
-
onValueChange?.(options[0].value);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const renderNativePicker = () => (
|
|
49
|
-
<NativePickerComponent
|
|
50
|
-
ref={pickerRef}
|
|
51
|
-
selectedValue={value}
|
|
52
|
-
onValueChange={(newValue) => {
|
|
53
|
-
if (newValue !== placeholder) {
|
|
54
|
-
onValueChange?.(newValue);
|
|
55
|
-
} else if (newValue === placeholder) {
|
|
56
|
-
onValueChange?.("");
|
|
57
|
-
}
|
|
58
|
-
}}
|
|
59
|
-
style={[
|
|
60
|
-
styles.nativePicker,
|
|
61
|
-
isIos ? styles.iosNativePicker : styles.nonIosPicker,
|
|
62
|
-
]}
|
|
63
|
-
onBlur={() => setPickerVisible(false)}
|
|
64
|
-
>
|
|
65
|
-
{options.map((option) => (
|
|
66
|
-
<NativePickerComponent.Item
|
|
67
|
-
label={option.label.toString()}
|
|
68
|
-
value={option.value}
|
|
69
|
-
key={option.value}
|
|
70
|
-
/>
|
|
71
|
-
))}
|
|
72
|
-
</NativePickerComponent>
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const renderPicker = () => {
|
|
76
|
-
if (isIos) {
|
|
77
|
-
return (
|
|
78
|
-
<Portal>
|
|
79
|
-
<SafeAreaView style={styles.nativePicker}>
|
|
80
|
-
<View style={styles.iosPickerContent}>
|
|
81
|
-
<Button
|
|
82
|
-
Icon={Icon}
|
|
83
|
-
type="text"
|
|
84
|
-
onPress={() => setPickerVisible(!pickerVisible)}
|
|
85
|
-
style={styles.iosButton}
|
|
86
|
-
>
|
|
87
|
-
{"Close"}
|
|
88
|
-
</Button>
|
|
89
|
-
{renderNativePicker()}
|
|
90
|
-
</View>
|
|
91
|
-
</SafeAreaView>
|
|
92
|
-
</Portal>
|
|
93
|
-
);
|
|
94
|
-
} else {
|
|
95
|
-
return renderNativePicker();
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
React.useEffect(() => {
|
|
100
|
-
if (pickerVisible && pickerRef.current) {
|
|
101
|
-
pickerRef?.current?.focus();
|
|
102
|
-
}
|
|
103
|
-
}, [pickerVisible, pickerRef]);
|
|
104
|
-
|
|
105
|
-
React.useEffect(() => {
|
|
106
|
-
if (pickerVisible && autoDismissKeyboard) {
|
|
107
|
-
Keyboard.dismiss();
|
|
108
|
-
}
|
|
109
|
-
}, [pickerVisible, autoDismissKeyboard]);
|
|
110
|
-
|
|
111
|
-
return (
|
|
112
|
-
<PickerInputContainer
|
|
113
|
-
Icon={Icon}
|
|
114
|
-
placeholder={placeholder}
|
|
115
|
-
selectedValue={value}
|
|
116
|
-
options={options}
|
|
117
|
-
onPress={() => setPickerVisible(!pickerVisible)}
|
|
118
|
-
{...rest}
|
|
119
|
-
>
|
|
120
|
-
{/* Web version is collapsed by default, always show to allow direct expand */}
|
|
121
|
-
{(pickerVisible || isWeb) && renderPicker()}
|
|
122
|
-
</PickerInputContainer>
|
|
123
|
-
);
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const styles = StyleSheet.create({
|
|
127
|
-
nativePicker: {
|
|
128
|
-
position: "absolute",
|
|
129
|
-
bottom: 0,
|
|
130
|
-
left: 0,
|
|
131
|
-
right: 0,
|
|
132
|
-
flexDirection: "row",
|
|
133
|
-
justifyContent: "center",
|
|
134
|
-
width: "100%",
|
|
135
|
-
backgroundColor: "white",
|
|
136
|
-
},
|
|
137
|
-
iosPickerContent: {
|
|
138
|
-
flexDirection: "column",
|
|
139
|
-
width: "100%",
|
|
140
|
-
},
|
|
141
|
-
iosButton: {
|
|
142
|
-
alignSelf: "flex-end",
|
|
143
|
-
},
|
|
144
|
-
iosNativePicker: {
|
|
145
|
-
backgroundColor: "white",
|
|
146
|
-
},
|
|
147
|
-
nonIosPicker: {
|
|
148
|
-
opacity: 0,
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
export default NativePicker;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { isObject } from "lodash";
|
|
2
|
-
export function normalizeToPickerOptions(options) {
|
|
3
|
-
if (options.length === 0) {
|
|
4
|
-
return [];
|
|
5
|
-
}
|
|
6
|
-
const firstOption = options[0];
|
|
7
|
-
if (typeof firstOption === ("string" || "number")) {
|
|
8
|
-
return options.map((option) => ({
|
|
9
|
-
label: option,
|
|
10
|
-
value: option,
|
|
11
|
-
}));
|
|
12
|
-
}
|
|
13
|
-
if (isObject(firstOption) && firstOption.value && firstOption.label) {
|
|
14
|
-
return options.map((option) => {
|
|
15
|
-
return {
|
|
16
|
-
label: option.label,
|
|
17
|
-
value: option.value,
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
throw new Error('Picker options must be either an array of strings, numbers, or an array of { "label": string | number; "value": string | number; } objects.');
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=PickerCommon.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PickerCommon.js","sourceRoot":"","sources":["PickerCommon.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAwDlC,MAAM,UAAU,wBAAwB,CACtC,OAA6C;IAE7C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,OAAO,EAAE,CAAC;KACX;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAE/B,IAAI,OAAO,WAAW,KAAK,CAAC,QAAQ,IAAI,QAAQ,CAAC,EAAE;QACjD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YAC9B,KAAK,EAAE,MAAyB;YAChC,KAAK,EAAE,MAAyB;SACjC,CAAC,CAAC,CAAC;KACL;IAED,IAAI,QAAQ,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC,KAAK,IAAI,WAAW,CAAC,KAAK,EAAE;QACnE,OAAQ,OAA0B,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YAChD,OAAO;gBACL,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,KAAK,EAAE,MAAM,CAAC,KAAK;aACpB,CAAC;QACJ,CAAC,CAAC,CAAC;KACJ;IAED,MAAM,IAAI,KAAK,CACb,6IAA6I,CAC9I,CAAC;AACJ,CAAC"}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { StyleProp, ViewStyle, TextStyle } from "react-native";
|
|
2
|
-
import { IconSlot } from "../../interfaces/Icon";
|
|
3
|
-
import { isObject } from "lodash";
|
|
4
|
-
import { Theme } from "../../styles/DefaultTheme";
|
|
5
|
-
|
|
6
|
-
export interface PickerOption {
|
|
7
|
-
value: string | number;
|
|
8
|
-
label: string | number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface PickerInputContainerProps extends IconSlot {
|
|
12
|
-
error?: any;
|
|
13
|
-
placeholder?: string;
|
|
14
|
-
disabled?: boolean;
|
|
15
|
-
style?: StyleProp<ViewStyle> | TextStyle;
|
|
16
|
-
label?: string;
|
|
17
|
-
assistiveText?: string;
|
|
18
|
-
iconColor?: string;
|
|
19
|
-
iconSize?: number;
|
|
20
|
-
leftIconMode?: "inset" | "outset";
|
|
21
|
-
leftIconName?: string;
|
|
22
|
-
placeholderTextColor?: string;
|
|
23
|
-
rightIconName?: string;
|
|
24
|
-
type?: "solid" | "underline";
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface CommonPickerProps extends PickerInputContainerProps {
|
|
28
|
-
options: PickerOption[] | string[] | number[];
|
|
29
|
-
autoDismissKeyboard?: boolean;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface SinglePickerProps {
|
|
33
|
-
value?: string | number;
|
|
34
|
-
onValueChange: (value: string | number) => void;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface MultiSelectPickerProps {
|
|
38
|
-
value?: (string | number)[];
|
|
39
|
-
onValueChange: (value: (string | number)[]) => void;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface CommonDropDownPickerProps extends CommonPickerProps {
|
|
43
|
-
selectedIconName?: string;
|
|
44
|
-
selectedIconColor?: string;
|
|
45
|
-
selectedIconSize?: number;
|
|
46
|
-
itemTextSize?: number;
|
|
47
|
-
itemTextColor?: string;
|
|
48
|
-
itemBackgroundColor?: string;
|
|
49
|
-
selectedItemTextSize?: number;
|
|
50
|
-
selectedItemTextColor?: string;
|
|
51
|
-
selectedItemBackgroundColor?: string;
|
|
52
|
-
dropDownBackgroundColor?: string;
|
|
53
|
-
dropDownBorderColor?: string;
|
|
54
|
-
dropDownBorderWidth?: number;
|
|
55
|
-
dropDownBorderRadius?: number;
|
|
56
|
-
theme: Theme;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function normalizeToPickerOptions(
|
|
60
|
-
options: PickerOption[] | string[] | number[]
|
|
61
|
-
): PickerOption[] {
|
|
62
|
-
if (options.length === 0) {
|
|
63
|
-
return [];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const firstOption = options[0];
|
|
67
|
-
|
|
68
|
-
if (typeof firstOption === ("string" || "number")) {
|
|
69
|
-
return options.map((option) => ({
|
|
70
|
-
label: option as string | number,
|
|
71
|
-
value: option as string | number,
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (isObject(firstOption) && firstOption.value && firstOption.label) {
|
|
76
|
-
return (options as PickerOption[]).map((option) => {
|
|
77
|
-
return {
|
|
78
|
-
label: option.label,
|
|
79
|
-
value: option.value,
|
|
80
|
-
};
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
throw new Error(
|
|
85
|
-
'Picker options must be either an array of strings, numbers, or an array of { "label": string | number; "value": string | number; } objects.'
|
|
86
|
-
);
|
|
87
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { View, StyleSheet } from "react-native";
|
|
3
|
-
import omit from "lodash.omit";
|
|
4
|
-
import { extractSizeStyles, extractPositionStyles, extractFlexItemStyles, extractBorderAndMarginStyles, } from "../../utilities";
|
|
5
|
-
import TextField from "../TextField";
|
|
6
|
-
import Touchable from "../Touchable";
|
|
7
|
-
const PickerInputContainer = ({ options = [], onPress, Icon, style, placeholder, selectedValue, disabled = false, zIndex, children, ...rest }) => {
|
|
8
|
-
var _a;
|
|
9
|
-
const containerStyle = StyleSheet.flatten([
|
|
10
|
-
extractSizeStyles(style),
|
|
11
|
-
extractPositionStyles(style),
|
|
12
|
-
extractFlexItemStyles(style),
|
|
13
|
-
extractBorderAndMarginStyles(style).marginStyles,
|
|
14
|
-
]);
|
|
15
|
-
const textFieldStyle = omit(StyleSheet.flatten(style), Object.keys(containerStyle));
|
|
16
|
-
let selectedLabel = "";
|
|
17
|
-
if (Array.isArray(selectedValue)) {
|
|
18
|
-
selectedLabel = selectedValue
|
|
19
|
-
.map((value) => {
|
|
20
|
-
var _a;
|
|
21
|
-
return ((_a = options.find((option) => option.value === value)) === null || _a === void 0 ? void 0 : _a.label.toString()) ||
|
|
22
|
-
value;
|
|
23
|
-
})
|
|
24
|
-
.join(", ");
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
selectedLabel =
|
|
28
|
-
((_a = options
|
|
29
|
-
.find((option) => option.value === selectedValue)) === null || _a === void 0 ? void 0 : _a.label.toString()) || selectedValue;
|
|
30
|
-
}
|
|
31
|
-
return (React.createElement(View, { style: [containerStyle, { zIndex }] },
|
|
32
|
-
React.createElement(Touchable, { disabled: disabled, onPress: onPress },
|
|
33
|
-
React.createElement(TextField, { Icon: Icon, numberOfLines: 1, onChangeText: () => { }, value: (selectedLabel === null || selectedLabel === void 0 ? void 0 : selectedLabel.toString()) || placeholder, editable: false, disabled: disabled, style: textFieldStyle, ...rest })),
|
|
34
|
-
children));
|
|
35
|
-
};
|
|
36
|
-
export default PickerInputContainer;
|
|
37
|
-
//# sourceMappingURL=PickerInputContainer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PickerInputContainer.js","sourceRoot":"","sources":["PickerInputContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,iBAAiB,CAAC;AACzB,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,SAAS,MAAM,cAAc,CAAC;AAarC,MAAM,oBAAoB,GAEtB,CAAC,EACH,OAAO,GAAG,EAAE,EACZ,OAAO,EACP,IAAI,EACJ,KAAK,EACL,WAAW,EACX,aAAa,EACb,QAAQ,GAAG,KAAK,EAChB,MAAM,EACN,QAAQ,EACR,GAAG,IAAI,EACR,EAAE,EAAE;;IACH,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,CAAC;QACxC,iBAAiB,CAAC,KAAK,CAAC;QACxB,qBAAqB,CAAC,KAAK,CAAC;QAC5B,qBAAqB,CAAC,KAAK,CAAC;QAC5B,4BAA4B,CAAC,KAAK,CAAC,CAAC,YAAY;KACjD,CAAC,CAAC;IAEH,MAAM,cAAc,GAAG,IAAI,CACzB,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,EACzB,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAC5B,CAAC;IAEF,IAAI,aAAa,GAAgC,EAAE,CAAC;IACpD,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;QAChC,aAAa,GAAG,aAAa;aAC1B,GAAG,CACF,CAAC,KAAK,EAAE,EAAE;;YACR,OAAA,CAAA,MAAA,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,KAAK,KAAK,CAAC,0CAAE,KAAK,CAAC,QAAQ,EAAE;gBAClE,KAAK,CAAA;SAAA,CACR;aACA,IAAI,CAAC,IAAI,CAAC,CAAC;KACf;SAAM;QACL,aAAa;YACX,CAAA,MAAA,OAAO;iBACJ,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,KAAK,aAAa,CAAC,0CAC/C,KAAK,CAAC,QAAQ,EAAE,KAAI,aAAa,CAAC;KACzC;IAED,OAAO,CACL,oBAAC,IAAI,IAAC,KAAK,EAAE,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,CAAC;QACvC,oBAAC,SAAS,IAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO;YAC7C,oBAAC,SAAS,IACR,IAAI,EAAE,IAAI,EACV,aAAa,EAAE,CAAC,EAChB,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC,EACtB,KAAK,EAAE,CAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,QAAQ,EAAE,KAAI,WAAW,EAC/C,QAAQ,EAAE,KAAK,EACf,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,cAAc,KACjB,IAAI,GACR,CACQ;QACX,QAAQ,CACJ,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { View, StyleSheet } from "react-native";
|
|
3
|
-
import omit from "lodash.omit";
|
|
4
|
-
import {
|
|
5
|
-
extractSizeStyles,
|
|
6
|
-
extractPositionStyles,
|
|
7
|
-
extractFlexItemStyles,
|
|
8
|
-
extractBorderAndMarginStyles,
|
|
9
|
-
} from "../../utilities";
|
|
10
|
-
import TextField from "../TextField";
|
|
11
|
-
import Touchable from "../Touchable";
|
|
12
|
-
import {
|
|
13
|
-
PickerInputContainerProps as ExposedPickerInputContainerProps,
|
|
14
|
-
PickerOption,
|
|
15
|
-
} from "./PickerCommon";
|
|
16
|
-
|
|
17
|
-
interface PickerInputContainerProps extends ExposedPickerInputContainerProps {
|
|
18
|
-
selectedValue?: string | number | (string | number)[];
|
|
19
|
-
options: PickerOption[];
|
|
20
|
-
zIndex?: number;
|
|
21
|
-
onPress?: () => void;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const PickerInputContainer: React.FC<
|
|
25
|
-
React.PropsWithChildren<PickerInputContainerProps>
|
|
26
|
-
> = ({
|
|
27
|
-
options = [],
|
|
28
|
-
onPress,
|
|
29
|
-
Icon,
|
|
30
|
-
style,
|
|
31
|
-
placeholder,
|
|
32
|
-
selectedValue,
|
|
33
|
-
disabled = false,
|
|
34
|
-
zIndex,
|
|
35
|
-
children,
|
|
36
|
-
...rest
|
|
37
|
-
}) => {
|
|
38
|
-
const containerStyle = StyleSheet.flatten([
|
|
39
|
-
extractSizeStyles(style),
|
|
40
|
-
extractPositionStyles(style),
|
|
41
|
-
extractFlexItemStyles(style),
|
|
42
|
-
extractBorderAndMarginStyles(style).marginStyles,
|
|
43
|
-
]);
|
|
44
|
-
|
|
45
|
-
const textFieldStyle = omit(
|
|
46
|
-
StyleSheet.flatten(style),
|
|
47
|
-
Object.keys(containerStyle)
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
let selectedLabel: string | number | undefined = "";
|
|
51
|
-
if (Array.isArray(selectedValue)) {
|
|
52
|
-
selectedLabel = selectedValue
|
|
53
|
-
.map(
|
|
54
|
-
(value) =>
|
|
55
|
-
options.find((option) => option.value === value)?.label.toString() ||
|
|
56
|
-
value
|
|
57
|
-
)
|
|
58
|
-
.join(", ");
|
|
59
|
-
} else {
|
|
60
|
-
selectedLabel =
|
|
61
|
-
options
|
|
62
|
-
.find((option) => option.value === selectedValue)
|
|
63
|
-
?.label.toString() || selectedValue;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<View style={[containerStyle, { zIndex }]}>
|
|
68
|
-
<Touchable disabled={disabled} onPress={onPress}>
|
|
69
|
-
<TextField
|
|
70
|
-
Icon={Icon}
|
|
71
|
-
numberOfLines={1}
|
|
72
|
-
onChangeText={() => {}}
|
|
73
|
-
value={selectedLabel?.toString() || placeholder}
|
|
74
|
-
editable={false}
|
|
75
|
-
disabled={disabled}
|
|
76
|
-
style={textFieldStyle}
|
|
77
|
-
{...rest}
|
|
78
|
-
/>
|
|
79
|
-
</Touchable>
|
|
80
|
-
{children}
|
|
81
|
-
</View>
|
|
82
|
-
);
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export default PickerInputContainer;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { Keyboard } from "react-native";
|
|
3
|
-
import { extractStyles, useDeepCompareMemo } from "../../../utilities";
|
|
4
|
-
import { normalizeToPickerOptions, } from "../PickerCommon";
|
|
5
|
-
import PickerInputContainer from "../PickerInputContainer";
|
|
6
|
-
import DropDownPickerComponent from "react-native-dropdown-picker";
|
|
7
|
-
import { withTheme } from "../../../theming";
|
|
8
|
-
const DropDownPicker = ({ theme, options: optionsProp = [], onValueChange, Icon, placeholder, value, autoDismissKeyboard = true, style, selectedIconName = "Feather/check", selectedIconColor = theme.colors.strong, selectedIconSize = 20, itemTextSize = 14, itemTextColor = theme.colors.strong, itemBackgroundColor, selectedItemTextSize = itemTextSize, selectedItemTextColor = itemTextColor, selectedItemBackgroundColor = itemBackgroundColor, dropDownBackgroundColor = theme.colors.background, dropDownBorderColor = theme.colors.divider, dropDownBorderWidth = 1, dropDownBorderRadius = 8, ...rest }) => {
|
|
9
|
-
const [pickerVisible, setPickerVisible] = React.useState(false);
|
|
10
|
-
const [internalValue, setInternalValue] = React.useState();
|
|
11
|
-
const isMultiSelect = Array.isArray(value);
|
|
12
|
-
const options = useDeepCompareMemo(() => normalizeToPickerOptions(optionsProp).map((option) => ({
|
|
13
|
-
label: option.label.toString(),
|
|
14
|
-
value: option.value,
|
|
15
|
-
})), [optionsProp]);
|
|
16
|
-
const { textStyles } = extractStyles(style);
|
|
17
|
-
React.useEffect(() => {
|
|
18
|
-
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange((isMultiSelect ? internalValue !== null && internalValue !== void 0 ? internalValue : [] : internalValue !== null && internalValue !== void 0 ? internalValue : "") // cannot determine if multiselect or not on compile time
|
|
19
|
-
);
|
|
20
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
21
|
-
}, [internalValue]);
|
|
22
|
-
React.useEffect(() => {
|
|
23
|
-
if (pickerVisible && autoDismissKeyboard) {
|
|
24
|
-
Keyboard.dismiss();
|
|
25
|
-
}
|
|
26
|
-
}, [pickerVisible, autoDismissKeyboard]);
|
|
27
|
-
return (React.createElement(PickerInputContainer, { style: style, Icon: Icon, placeholder: placeholder, selectedValue: value, options: options, onPress: () => setPickerVisible(!pickerVisible), zIndex: pickerVisible ? 100 : undefined, ...rest },
|
|
28
|
-
React.createElement(DropDownPickerComponent, { open: pickerVisible, setOpen: setPickerVisible, value: (value || null), setValue: setInternalValue, items: options, placeholder: placeholder, listMode: "SCROLLVIEW", multiple: isMultiSelect, style: { display: "none" }, listItemLabelStyle: [
|
|
29
|
-
textStyles,
|
|
30
|
-
{ color: itemTextColor, fontSize: itemTextSize },
|
|
31
|
-
], selectedItemLabelStyle: {
|
|
32
|
-
color: selectedItemTextColor,
|
|
33
|
-
fontSize: selectedItemTextSize,
|
|
34
|
-
}, listItemContainerStyle: { backgroundColor: itemBackgroundColor }, selectedItemContainerStyle: {
|
|
35
|
-
backgroundColor: selectedItemBackgroundColor,
|
|
36
|
-
}, dropDownContainerStyle: {
|
|
37
|
-
borderColor: dropDownBorderColor,
|
|
38
|
-
borderWidth: dropDownBorderWidth,
|
|
39
|
-
borderRadius: dropDownBorderRadius,
|
|
40
|
-
backgroundColor: dropDownBackgroundColor,
|
|
41
|
-
}, TickIconComponent: () => (React.createElement(Icon, { name: selectedIconName, size: selectedIconSize, color: selectedIconColor })) })));
|
|
42
|
-
};
|
|
43
|
-
export default withTheme(DropDownPicker);
|
|
44
|
-
//# sourceMappingURL=DropDownPicker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DropDownPicker.js","sourceRoot":"","sources":["DropDownPicker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAIL,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,MAAM,cAAc,GAEhB,CAAC,EACH,KAAK,EACL,OAAO,EAAE,WAAW,GAAG,EAAE,EACzB,aAAa,EACb,IAAI,EACJ,WAAW,EACX,KAAK,EACL,mBAAmB,GAAG,IAAI,EAC1B,KAAK,EACL,gBAAgB,GAAG,eAAe,EAClC,iBAAiB,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EACvC,gBAAgB,GAAG,EAAE,EACrB,YAAY,GAAG,EAAE,EACjB,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EACnC,mBAAmB,EACnB,oBAAoB,GAAG,YAAY,EACnC,qBAAqB,GAAG,aAAa,EACrC,2BAA2B,GAAG,mBAAmB,EACjD,uBAAuB,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU,EACjD,mBAAmB,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,EAC1C,m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|
1
|
-
import * as React from "react";
|
|
2
|
-
import { Keyboard } from "react-native";
|
|
3
|
-
import { extractStyles, useDeepCompareMemo } from "../../../utilities";
|
|
4
|
-
import {
|
|
5
|
-
CommonDropDownPickerProps,
|
|
6
|
-
MultiSelectPickerProps,
|
|
7
|
-
SinglePickerProps,
|
|
8
|
-
normalizeToPickerOptions,
|
|
9
|
-
} from "../PickerCommon";
|
|
10
|
-
import PickerInputContainer from "../PickerInputContainer";
|
|
11
|
-
import DropDownPickerComponent from "react-native-dropdown-picker";
|
|
12
|
-
import { withTheme } from "../../../theming";
|
|
13
|
-
|
|
14
|
-
const DropDownPicker: React.FC<
|
|
15
|
-
CommonDropDownPickerProps & (SinglePickerProps | MultiSelectPickerProps)
|
|
16
|
-
> = ({
|
|
17
|
-
theme,
|
|
18
|
-
options: optionsProp = [],
|
|
19
|
-
onValueChange,
|
|
20
|
-
Icon,
|
|
21
|
-
placeholder,
|
|
22
|
-
value,
|
|
23
|
-
autoDismissKeyboard = true,
|
|
24
|
-
style,
|
|
25
|
-
selectedIconName = "Feather/check",
|
|
26
|
-
selectedIconColor = theme.colors.strong,
|
|
27
|
-
selectedIconSize = 20,
|
|
28
|
-
itemTextSize = 14,
|
|
29
|
-
itemTextColor = theme.colors.strong,
|
|
30
|
-
itemBackgroundColor,
|
|
31
|
-
selectedItemTextSize = itemTextSize,
|
|
32
|
-
selectedItemTextColor = itemTextColor,
|
|
33
|
-
selectedItemBackgroundColor = itemBackgroundColor,
|
|
34
|
-
dropDownBackgroundColor = theme.colors.background,
|
|
35
|
-
dropDownBorderColor = theme.colors.divider,
|
|
36
|
-
dropDownBorderWidth = 1,
|
|
37
|
-
dropDownBorderRadius = 8,
|
|
38
|
-
...rest
|
|
39
|
-
}) => {
|
|
40
|
-
const [pickerVisible, setPickerVisible] = React.useState(false);
|
|
41
|
-
const [internalValue, setInternalValue] = React.useState<
|
|
42
|
-
string | number | (string | number)[]
|
|
43
|
-
>();
|
|
44
|
-
|
|
45
|
-
const isMultiSelect = Array.isArray(value);
|
|
46
|
-
|
|
47
|
-
const options = useDeepCompareMemo(
|
|
48
|
-
() =>
|
|
49
|
-
normalizeToPickerOptions(optionsProp).map((option) => ({
|
|
50
|
-
label: option.label.toString(),
|
|
51
|
-
value: option.value,
|
|
52
|
-
})),
|
|
53
|
-
[optionsProp]
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
const { textStyles } = extractStyles(style);
|
|
57
|
-
|
|
58
|
-
React.useEffect(() => {
|
|
59
|
-
onValueChange?.(
|
|
60
|
-
(isMultiSelect ? internalValue ?? [] : internalValue ?? "") as any // cannot determine if multiselect or not on compile time
|
|
61
|
-
);
|
|
62
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
63
|
-
}, [internalValue]);
|
|
64
|
-
|
|
65
|
-
React.useEffect(() => {
|
|
66
|
-
if (pickerVisible && autoDismissKeyboard) {
|
|
67
|
-
Keyboard.dismiss();
|
|
68
|
-
}
|
|
69
|
-
}, [pickerVisible, autoDismissKeyboard]);
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<PickerInputContainer
|
|
73
|
-
style={style}
|
|
74
|
-
Icon={Icon}
|
|
75
|
-
placeholder={placeholder}
|
|
76
|
-
selectedValue={value}
|
|
77
|
-
options={options}
|
|
78
|
-
onPress={() => setPickerVisible(!pickerVisible)}
|
|
79
|
-
zIndex={pickerVisible ? 100 : undefined} // Guarantees drop down is rendered above all sibling components
|
|
80
|
-
{...rest}
|
|
81
|
-
>
|
|
82
|
-
<DropDownPickerComponent
|
|
83
|
-
open={pickerVisible}
|
|
84
|
-
setOpen={setPickerVisible}
|
|
85
|
-
value={(value || null) as any}
|
|
86
|
-
setValue={setInternalValue}
|
|
87
|
-
items={options}
|
|
88
|
-
placeholder={placeholder}
|
|
89
|
-
listMode="SCROLLVIEW"
|
|
90
|
-
multiple={isMultiSelect}
|
|
91
|
-
style={{ display: "none" }} // To not render the default input container
|
|
92
|
-
listItemLabelStyle={[
|
|
93
|
-
textStyles,
|
|
94
|
-
{ color: itemTextColor, fontSize: itemTextSize },
|
|
95
|
-
]}
|
|
96
|
-
selectedItemLabelStyle={{
|
|
97
|
-
color: selectedItemTextColor,
|
|
98
|
-
fontSize: selectedItemTextSize,
|
|
99
|
-
}}
|
|
100
|
-
listItemContainerStyle={{ backgroundColor: itemBackgroundColor }}
|
|
101
|
-
selectedItemContainerStyle={{
|
|
102
|
-
backgroundColor: selectedItemBackgroundColor,
|
|
103
|
-
}}
|
|
104
|
-
dropDownContainerStyle={{
|
|
105
|
-
borderColor: dropDownBorderColor,
|
|
106
|
-
borderWidth: dropDownBorderWidth,
|
|
107
|
-
borderRadius: dropDownBorderRadius,
|
|
108
|
-
backgroundColor: dropDownBackgroundColor,
|
|
109
|
-
}}
|
|
110
|
-
TickIconComponent={() => (
|
|
111
|
-
<Icon
|
|
112
|
-
name={selectedIconName}
|
|
113
|
-
size={selectedIconSize}
|
|
114
|
-
color={selectedIconColor}
|
|
115
|
-
/>
|
|
116
|
-
)}
|
|
117
|
-
/>
|
|
118
|
-
</PickerInputContainer>
|
|
119
|
-
);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
export default withTheme(DropDownPicker);
|