@draftbit/core 44.1.7 → 44.1.9-222859.1
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/ActionSheet/ActionSheetItem.js.map +1 -1
- package/lib/commonjs/components/DeprecatedFAB.js +4 -20
- package/lib/commonjs/components/Picker/Picker.js +254 -27
- package/lib/commonjs/components/Picker/Picker.js.map +1 -1
- package/lib/commonjs/components/StepIndicator.js.map +1 -1
- package/lib/commonjs/components/Stepper.js.map +1 -1
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/commonjs/mappings/MapCallout.js +1 -0
- package/lib/commonjs/mappings/MapCallout.js.map +1 -1
- package/lib/commonjs/mappings/Picker.js +3 -1
- package/lib/commonjs/mappings/Picker.js.map +1 -1
- package/lib/commonjs/mappings/ScrollView.js.map +1 -1
- package/lib/commonjs/mappings/WebView.js.map +1 -1
- package/lib/module/components/HeaderLarge.js.map +1 -1
- package/lib/module/components/Picker/Picker.js +241 -29
- package/lib/module/components/Picker/Picker.js.map +1 -1
- package/lib/module/mappings/AudioPlayer.js.map +1 -1
- package/lib/module/mappings/MapCallout.js +2 -1
- package/lib/module/mappings/MapCallout.js.map +1 -1
- package/lib/module/mappings/Picker.js +4 -2
- package/lib/module/mappings/Picker.js.map +1 -1
- package/lib/typescript/src/components/Picker/Picker.d.ts +28 -4
- package/lib/typescript/src/mappings/MapCallout.d.ts +1 -0
- package/lib/typescript/src/mappings/Picker.d.ts +21 -0
- package/package.json +2 -2
- package/src/components/Picker/Picker.js +188 -18
- package/src/components/Picker/Picker.tsx +364 -35
- package/src/mappings/MapCallout.js +2 -1
- package/src/mappings/MapCallout.ts +2 -0
- package/src/mappings/Picker.js +3 -1
- package/src/mappings/Picker.ts +4 -0
- 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.js +0 -68
- package/src/components/Picker/PickerComponent.android.tsx +0 -116
- package/src/components/Picker/PickerComponent.ios.js +0 -78
- package/src/components/Picker/PickerComponent.ios.tsx +0 -142
- package/src/components/Picker/PickerComponent.web.js +0 -69
- package/src/components/Picker/PickerComponent.web.tsx +0 -117
- package/src/components/Picker/PickerTypes.js +0 -1
- package/src/components/Picker/PickerTypes.ts +0 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Picker.ts"],"names":["COMPONENT_TYPES","Triggers","GROUPS","FORM_TYPES","PROP_TYPES","FIELD_NAME","SEED_DATA_PROPS","label","group","data","description","formType","string","propType","STRING","defaultValue","editable","required","placeholder","basic","placeholderTextColor","color","assistiveText","options","array","OBJECT","disabled","boolean","BOOLEAN","error","leftIconName","icon","ASSET","leftIconMode","flatArray","rightIconName","fieldName","handlerPropName","SEED_DATA_TRIGGERS","OnValueChange","SEED_DATA","name","tag","category","input","preview_image_url","supports_list_render","triggers","props","type","layout"],"mappings":"AAAA,SACEA,eADF,EAEEC,QAFF,EAGEC,MAHF,EAIEC,UAJF,EAKEC,UALF,EAMEC,UANF,
|
|
1
|
+
{"version":3,"sources":["Picker.ts"],"names":["COMPONENT_TYPES","Triggers","GROUPS","FORM_TYPES","PROP_TYPES","FIELD_NAME","createIconSizeProp","createColorProp","SEED_DATA_PROPS","label","group","data","description","formType","string","propType","STRING","defaultValue","editable","required","placeholder","basic","placeholderTextColor","color","assistiveText","options","array","OBJECT","disabled","boolean","BOOLEAN","error","leftIconName","icon","ASSET","leftIconMode","flatArray","rightIconName","fieldName","handlerPropName","SEED_DATA_TRIGGERS","OnValueChange","SEED_DATA","name","tag","category","input","preview_image_url","supports_list_render","triggers","props","type","iconSize","iconColor","layout"],"mappings":"AAAA,SACEA,eADF,EAEEC,QAFF,EAGEC,MAHF,EAIEC,UAJF,EAKEC,UALF,EAMEC,UANF,EAOEC,kBAPF,EAQEC,eARF,QASO,iBATP;AAWA,MAAMC,eAAe,GAAG;AACtBC,EAAAA,KAAK,EAAE;AACLC,IAAAA,KAAK,EAAER,MAAM,CAACS,IADT;AAELF,IAAAA,KAAK,EAAE,OAFF;AAGLG,IAAAA,WAAW,EAAE,yCAHR;AAILC,IAAAA,QAAQ,EAAEV,UAAU,CAACW,MAJhB;AAKLC,IAAAA,QAAQ,EAAEX,UAAU,CAACY,MALhB;AAMLC,IAAAA,YAAY,EAAE,IANT;AAOLC,IAAAA,QAAQ,EAAE,IAPL;AAQLC,IAAAA,QAAQ,EAAE;AARL,GADe;AAWtBC,EAAAA,WAAW,EAAE;AACXV,IAAAA,KAAK,EAAER,MAAM,CAACmB,KADH;AAEXZ,IAAAA,KAAK,EAAE,aAFI;AAGXG,IAAAA,WAAW,EAAE,oCAHF;AAIXC,IAAAA,QAAQ,EAAEV,UAAU,CAACW,MAJV;AAKXC,IAAAA,QAAQ,EAAE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,OALV;AAMJQ,MAAAA,OAAO,EAAE,CAAC,OAAD,EAAU,WAAV,CANL;AAOJP,MAAAA,QAAQ,EAAE,IAPN;AAQJC,MAAAA,QAAQ,EAAE,IARN;AASJT,MAAAA,KAAK,EAAER,MAAM,CAACmB;AATV,KAFD;AAaL+B,IAAAA,QAAQ,EAAE9C,kBAAkB,EAbvB;AAcL+C,IAAAA,SAAS,EAAE9C,eAAe;AAdrB,GART;AAwBE+C,EAAAA,MAAM,EAAE;AAxBV,CADuB,CAAlB","sourcesContent":["import {\n COMPONENT_TYPES,\n Triggers,\n GROUPS,\n FORM_TYPES,\n PROP_TYPES,\n FIELD_NAME,\n createIconSizeProp,\n createColorProp,\n} from \"@draftbit/types\";\n\nconst SEED_DATA_PROPS = {\n label: {\n group: GROUPS.data,\n label: \"Label\",\n description: \"The label to be displayed on the picker\",\n formType: FORM_TYPES.string,\n propType: PROP_TYPES.STRING,\n defaultValue: null,\n editable: true,\n required: true,\n },\n placeholder: {\n group: GROUPS.basic,\n label: \"Placeholder\",\n description: \"The placeholder text of the picker\",\n formType: FORM_TYPES.string,\n propType: PROP_TYPES.STRING,\n defaultValue: \"Select an option\",\n editable: true,\n required: false,\n },\n placeholderTextColor: {\n group: GROUPS.basic,\n label: \"Placeholder Text Color\",\n description: \"The color of the placeholder text.\",\n editable: true,\n required: false,\n defaultValue: null,\n formType: FORM_TYPES.color,\n propType: PROP_TYPES.STRING,\n },\n assistiveText: {\n group: GROUPS.basic,\n label: \"Assistive text\",\n description: \"Helper text to display below the picker\",\n formType: FORM_TYPES.string,\n propType: PROP_TYPES.STRING,\n defaultValue: null,\n editable: true,\n required: false,\n },\n options: {\n group: GROUPS.data,\n label: \"Options\",\n description:\n \"Array of picker options. An array of objects containing a label and value.\",\n editable: true,\n required: false,\n formType: FORM_TYPES.array,\n propType: PROP_TYPES.OBJECT,\n options: [],\n defaultValue: null,\n },\n disabled: {\n group: GROUPS.basic,\n label: \"Disabled\",\n description:\n \"Whether the picker should be disabled. Will prevent selection and show a greyed out state.\",\n formType: FORM_TYPES.boolean,\n propType: PROP_TYPES.BOOLEAN,\n defaultValue: false,\n editable: true,\n required: false,\n },\n error: {\n group: GROUPS.data,\n label: \"Error\",\n description: \"Whether the picker should display the error state\",\n formType: FORM_TYPES.boolean,\n propType: PROP_TYPES.BOOLEAN,\n defaultValue: false,\n editable: true,\n required: false,\n },\n leftIconName: {\n group: GROUPS.basic,\n label: \"Left icon name\",\n description: \"The icon to display on the left\",\n formType: FORM_TYPES.icon,\n propType: PROP_TYPES.ASSET,\n defaultValue: null,\n editable: true,\n required: false,\n },\n leftIconMode: {\n group: GROUPS.basic,\n label: \"Left icon mode\",\n description:\n \"The mode of the icon to display on the left. 'inset' or 'outset'.\",\n formType: FORM_TYPES.flatArray,\n propType: PROP_TYPES.STRING,\n defaultValue: \"inset\",\n options: [\"inset\", \"outset\"],\n editable: true,\n required: true,\n },\n rightIconName: {\n group: GROUPS.basic,\n label: \"Right icon name\",\n description: \"The icon to display on the right\",\n formType: FORM_TYPES.icon,\n propType: PROP_TYPES.ASSET,\n defaultValue: null,\n editable: true,\n required: false,\n },\n fieldName: {\n ...FIELD_NAME,\n defaultValue: \"pickerValue\",\n handlerPropName: \"onValueChange\",\n },\n};\n\nconst SEED_DATA_TRIGGERS = [Triggers.OnValueChange];\nexport const SEED_DATA = [\n {\n name: \"Picker\",\n tag: \"Picker\",\n description: \"A component used to pick a value from a set of options\",\n category: COMPONENT_TYPES.input,\n preview_image_url: \"{CLOUDINARY_URL}/Picker.png\",\n supports_list_render: false,\n triggers: SEED_DATA_TRIGGERS,\n props: {\n ...SEED_DATA_PROPS,\n type: {\n label: \"Appearance\",\n description: \"Type of Picker\",\n formType: FORM_TYPES.flatArray,\n propType: PROP_TYPES.STRING,\n defaultValue: \"solid\",\n options: [\"solid\", \"underline\"],\n editable: true,\n required: true,\n group: GROUPS.basic,\n },\n iconSize: createIconSizeProp(),\n iconColor: createColorProp(),\n },\n layout: {},\n },\n];\n"]}
|
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { ViewStyle, StyleProp } from "react-native";
|
|
3
|
+
import type { Theme } from "../../styles/DefaultTheme";
|
|
4
|
+
import type { IconSlot } from "../../interfaces/Icon";
|
|
5
|
+
export interface PickerOption {
|
|
6
|
+
value: string;
|
|
7
|
+
label: string;
|
|
8
|
+
}
|
|
9
|
+
export declare type PickerProps = {
|
|
10
|
+
error?: any;
|
|
4
11
|
placeholder?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
style?: StyleProp<ViewStyle> & {
|
|
14
|
+
height?: number;
|
|
15
|
+
};
|
|
5
16
|
value?: string;
|
|
6
17
|
options: PickerOption[] | string[];
|
|
18
|
+
onValueChange: (value: string, index: number) => void;
|
|
19
|
+
defaultValue?: string;
|
|
20
|
+
assistiveText?: string;
|
|
21
|
+
label?: string;
|
|
22
|
+
iconColor?: string;
|
|
23
|
+
iconSize?: number;
|
|
24
|
+
leftIconMode?: "inset" | "outset";
|
|
25
|
+
leftIconName?: string;
|
|
26
|
+
placeholderTextColor?: string;
|
|
27
|
+
rightIconName?: string;
|
|
28
|
+
type?: "solid" | "underline";
|
|
29
|
+
theme: Theme;
|
|
30
|
+
Icon: IconSlot["Icon"];
|
|
7
31
|
};
|
|
8
|
-
declare const _default: React.ComponentType<import("@draftbit/react-theme-provider").$Without<
|
|
32
|
+
declare const _default: React.ComponentType<import("@draftbit/react-theme-provider").$Without<PickerProps, "theme"> & {
|
|
9
33
|
theme?: import("@draftbit/react-theme-provider").$DeepPartial<any> | undefined;
|
|
10
|
-
}> & import("@draftbit/react-theme-provider/typings/hoist-non-react-statics").NonReactStatics<React.ComponentType<
|
|
34
|
+
}> & import("@draftbit/react-theme-provider/typings/hoist-non-react-statics").NonReactStatics<React.ComponentType<PickerProps> & React.FC<PickerProps>, {}>;
|
|
11
35
|
export default _default;
|
|
@@ -18,6 +18,27 @@ export declare const SEED_DATA: {
|
|
|
18
18
|
required: boolean;
|
|
19
19
|
group: string;
|
|
20
20
|
};
|
|
21
|
+
iconSize: {
|
|
22
|
+
group: string;
|
|
23
|
+
label: string;
|
|
24
|
+
description: string;
|
|
25
|
+
editable: boolean;
|
|
26
|
+
required: boolean;
|
|
27
|
+
formType: string;
|
|
28
|
+
propType: string;
|
|
29
|
+
defaultValue: number;
|
|
30
|
+
options: number[];
|
|
31
|
+
};
|
|
32
|
+
iconColor: {
|
|
33
|
+
group: string;
|
|
34
|
+
label: string;
|
|
35
|
+
description: string;
|
|
36
|
+
editable: boolean;
|
|
37
|
+
required: boolean;
|
|
38
|
+
defaultValue: null;
|
|
39
|
+
formType: string;
|
|
40
|
+
propType: string;
|
|
41
|
+
};
|
|
21
42
|
label: {
|
|
22
43
|
group: string;
|
|
23
44
|
label: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@draftbit/core",
|
|
3
|
-
"version": "44.1.
|
|
3
|
+
"version": "44.1.9-222859.1+22285965",
|
|
4
4
|
"description": "Core (non-native) Components",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
]
|
|
80
80
|
]
|
|
81
81
|
},
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "22285965c262975f9214a8aec02a06d2dc56d351"
|
|
83
83
|
}
|
|
@@ -1,29 +1,41 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet, Text, Platform, Dimensions, } from "react-native";
|
|
3
|
+
import { omit, pick, pickBy, identity } from "lodash";
|
|
4
|
+
import { SafeAreaView } from "react-native-safe-area-context";
|
|
5
|
+
import { Picker as NativePicker } from "@react-native-picker/picker";
|
|
2
6
|
import { withTheme } from "../../theming";
|
|
3
|
-
|
|
4
|
-
import
|
|
7
|
+
import Portal from "../Portal/Portal";
|
|
8
|
+
import Button from "../DeprecatedButton";
|
|
9
|
+
import Touchable from "../Touchable";
|
|
10
|
+
import { extractStyles } from "../../utilities";
|
|
5
11
|
function normalizeOptions(options) {
|
|
6
12
|
if (options.length === 0) {
|
|
7
13
|
return [];
|
|
8
14
|
}
|
|
9
|
-
if (typeof options[0] === "string") {
|
|
15
|
+
if (typeof options[0] === ("string" || "number")) {
|
|
10
16
|
return options.map((option) => ({
|
|
11
|
-
label: option,
|
|
17
|
+
label: String(option),
|
|
12
18
|
value: String(option),
|
|
13
19
|
}));
|
|
14
20
|
}
|
|
15
|
-
if (options[0]
|
|
21
|
+
if (typeof options[0] === "object" &&
|
|
22
|
+
options[0].value !== null &&
|
|
23
|
+
options[0].label !== null) {
|
|
16
24
|
return options.map((option) => {
|
|
17
25
|
return {
|
|
18
|
-
label: option.label,
|
|
26
|
+
label: String(option.label),
|
|
19
27
|
value: String(option.value),
|
|
20
28
|
};
|
|
21
29
|
});
|
|
22
30
|
}
|
|
23
31
|
throw new Error('Picker options must be either an array of strings or array of { "label": string; "value": string; } objects.');
|
|
24
32
|
}
|
|
25
|
-
const
|
|
33
|
+
const unstyledColor = "rgba(165, 173, 183, 1)";
|
|
34
|
+
const disabledColor = "rgb(240, 240, 240)";
|
|
35
|
+
const errorColor = "rgba(255, 69, 100, 1)";
|
|
36
|
+
const Picker = ({ error, options = [], onValueChange, defaultValue, Icon, style, placeholder, value, disabled = false, theme, assistiveText, label, iconColor = unstyledColor, iconSize = 24, leftIconMode = "inset", leftIconName, placeholderTextColor = unstyledColor, rightIconName, type = "solid", }) => {
|
|
26
37
|
const [internalValue, setInternalValue] = React.useState(value || defaultValue);
|
|
38
|
+
const [pickerVisible, togglePickerVisible] = React.useReducer((state) => !state, false);
|
|
27
39
|
React.useEffect(() => {
|
|
28
40
|
if (value != null) {
|
|
29
41
|
setInternalValue(value);
|
|
@@ -34,23 +46,181 @@ const Picker = ({ options = [], placeholder, onValueChange: onValueChangeOverrid
|
|
|
34
46
|
setInternalValue(defaultValue);
|
|
35
47
|
}
|
|
36
48
|
}, [defaultValue]);
|
|
37
|
-
const onValueChange = React.useCallback((itemValue, itemIndex) => {
|
|
38
|
-
if (placeholder && itemIndex === 0) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
onValueChangeOverride &&
|
|
42
|
-
onValueChangeOverride(String(itemValue), itemIndex);
|
|
43
|
-
}, [placeholder, onValueChangeOverride]);
|
|
44
49
|
const normalizedOptions = normalizeOptions(options);
|
|
45
50
|
const pickerOptions = placeholder
|
|
46
51
|
? [{ value: placeholder, label: placeholder }, ...normalizedOptions]
|
|
47
52
|
: normalizedOptions;
|
|
53
|
+
const { viewStyles, textStyles } = extractStyles(style);
|
|
54
|
+
const { colors } = theme;
|
|
55
|
+
const borders = [
|
|
56
|
+
"borderRadius",
|
|
57
|
+
"borderTopLeftRadius",
|
|
58
|
+
"borderTopRightRadius",
|
|
59
|
+
"borderBottomRightRadius",
|
|
60
|
+
"borderBottomLeftRadius",
|
|
61
|
+
"borderTopWidth",
|
|
62
|
+
"borderRightWidth",
|
|
63
|
+
"borderBottomWidth",
|
|
64
|
+
"borderLeftWidth",
|
|
65
|
+
"borderColor",
|
|
66
|
+
"borderStyle",
|
|
67
|
+
"backgroundColor",
|
|
68
|
+
];
|
|
69
|
+
const borderStyles = {
|
|
70
|
+
...{
|
|
71
|
+
...(type === "solid"
|
|
72
|
+
? {
|
|
73
|
+
borderTopLeftRadius: 5,
|
|
74
|
+
borderTopRightRadius: 5,
|
|
75
|
+
borderBottomRightRadius: 5,
|
|
76
|
+
borderBottomLeftRadius: 5,
|
|
77
|
+
borderTopWidth: 1,
|
|
78
|
+
borderRightWidth: 1,
|
|
79
|
+
borderLeftWidth: 1,
|
|
80
|
+
}
|
|
81
|
+
: {}),
|
|
82
|
+
borderBottomWidth: 1,
|
|
83
|
+
borderColor: unstyledColor,
|
|
84
|
+
borderStyle: "solid",
|
|
85
|
+
},
|
|
86
|
+
...pick(viewStyles, borders),
|
|
87
|
+
...(error ? { borderColor: errorColor } : {}),
|
|
88
|
+
...(disabled
|
|
89
|
+
? { borderColor: "transparent", backgroundColor: disabledColor }
|
|
90
|
+
: {}),
|
|
91
|
+
};
|
|
92
|
+
const margins = ["marginLeft", "marginRight", "marginTop", "marginBottom"];
|
|
93
|
+
const marginStyles = pick(viewStyles, margins);
|
|
94
|
+
const maxHeight = viewStyles?.maxHeight && viewStyles.maxHeight !== "100%"
|
|
95
|
+
? viewStyles.maxHeight
|
|
96
|
+
: Dimensions.get("window").height;
|
|
97
|
+
const stylesWithoutBordersAndMargins = {
|
|
98
|
+
...{
|
|
99
|
+
height: 60,
|
|
100
|
+
width: "100%",
|
|
101
|
+
},
|
|
102
|
+
...omit(viewStyles, [...borders, ...margins]),
|
|
103
|
+
...{ maxHeight },
|
|
104
|
+
};
|
|
105
|
+
const selectedLabel = internalValue &&
|
|
106
|
+
(pickerOptions.find((option) => option.value === internalValue)?.label ??
|
|
107
|
+
internalValue);
|
|
108
|
+
const labelText = label ? (React.createElement(Text, { style: {
|
|
109
|
+
textAlign: textStyles.textAlign,
|
|
110
|
+
color: unstyledColor,
|
|
111
|
+
fontSize: 12,
|
|
112
|
+
paddingBottom: 4,
|
|
113
|
+
} }, label)) : null;
|
|
114
|
+
const leftIconOutset = leftIconMode === "outset";
|
|
115
|
+
const leftIcon = leftIconName ? (React.createElement(Icon, { name: leftIconName, color: disabled ? unstyledColor : iconColor, size: iconSize, style: {
|
|
116
|
+
marginRight: 4,
|
|
117
|
+
marginLeft: 4,
|
|
118
|
+
} })) : null;
|
|
119
|
+
const rightIcon = rightIconName ? (React.createElement(Icon, { name: rightIconName, color: disabled ? unstyledColor : iconColor, size: iconSize, style: {
|
|
120
|
+
marginRight: -10,
|
|
121
|
+
marginLeft: 8,
|
|
122
|
+
} })) : null;
|
|
123
|
+
const width = stylesWithoutBordersAndMargins?.width ?? undefined;
|
|
124
|
+
const textAlign = textStyles?.textAlign;
|
|
125
|
+
const paddingLeft = leftIconOutset &&
|
|
126
|
+
(!textAlign || textAlign === "left" || textAlign === "justify")
|
|
127
|
+
? iconSize + 4
|
|
128
|
+
: 0;
|
|
129
|
+
const assistiveTextLabel = assistiveText ? (React.createElement(Text, { style: {
|
|
130
|
+
textAlign,
|
|
131
|
+
width,
|
|
132
|
+
paddingLeft,
|
|
133
|
+
color: unstyledColor,
|
|
134
|
+
fontSize: 12,
|
|
135
|
+
paddingTop: 4,
|
|
136
|
+
} }, assistiveText)) : null;
|
|
137
|
+
const primaryTextStyle = {
|
|
138
|
+
color: unstyledColor,
|
|
139
|
+
fontSize: 14,
|
|
140
|
+
...pickBy(textStyles, identity),
|
|
141
|
+
...(placeholder === internalValue ? { color: placeholderTextColor } : {}),
|
|
142
|
+
...(disabled ? { color: unstyledColor } : {}),
|
|
143
|
+
};
|
|
48
144
|
const handleValueChange = (newValue, itemIndex) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
onValueChange(newValue, itemIndex);
|
|
145
|
+
if (!placeholder || itemIndex > 0) {
|
|
146
|
+
onValueChange?.(newValue, itemIndex);
|
|
52
147
|
}
|
|
148
|
+
setInternalValue(newValue);
|
|
53
149
|
};
|
|
54
|
-
return (
|
|
150
|
+
return (
|
|
151
|
+
/* marginsContainer */
|
|
152
|
+
React.createElement(View, { style: [styles.marginsContainer, marginStyles] },
|
|
153
|
+
React.createElement(Touchable, { disabled: disabled, onPress: togglePickerVisible, style: styles.touchableContainer },
|
|
154
|
+
React.createElement(View, { pointerEvents: "none", style: [
|
|
155
|
+
styles.outsetContainer,
|
|
156
|
+
stylesWithoutBordersAndMargins,
|
|
157
|
+
// @ts-expect-error ... rejects border-related { key: undefined }
|
|
158
|
+
!leftIconOutset && borderStyles, // set border if Icon is inset
|
|
159
|
+
] },
|
|
160
|
+
leftIcon,
|
|
161
|
+
React.createElement(View, { style: [
|
|
162
|
+
styles.insetContainer,
|
|
163
|
+
// @ts-expect-error ... rejects border-related { key: undefined }
|
|
164
|
+
leftIconOutset && borderStyles, // set border if Icon is outset
|
|
165
|
+
] },
|
|
166
|
+
React.createElement(View, { style: styles.primaryTextContainer },
|
|
167
|
+
labelText,
|
|
168
|
+
React.createElement(Text, { style: primaryTextStyle }, String(selectedLabel ?? placeholder))),
|
|
169
|
+
rightIcon)),
|
|
170
|
+
assistiveTextLabel),
|
|
171
|
+
Platform.OS === "ios" && pickerVisible ? (React.createElement(Portal, null,
|
|
172
|
+
React.createElement(View, { style: [
|
|
173
|
+
styles.iosPicker,
|
|
174
|
+
{
|
|
175
|
+
backgroundColor: colors.divider,
|
|
176
|
+
},
|
|
177
|
+
] },
|
|
178
|
+
React.createElement(SafeAreaView, { style: styles.iosSafeArea },
|
|
179
|
+
React.createElement(Button, { Icon: Icon, type: "text", onPress: togglePickerVisible, style: styles.iosButton }, "Close"),
|
|
180
|
+
React.createElement(NativePicker, { style: styles.iosNativePicker, selectedValue: internalValue, onValueChange: handleValueChange }, pickerOptions.map((option) => (React.createElement(NativePicker.Item, { label: option.label, value: option.value, key: option.value })))))))) : null,
|
|
181
|
+
Platform.OS !== "ios" ? (React.createElement(NativePicker, { enabled: !disabled, selectedValue: internalValue, onValueChange: handleValueChange, style: styles.nonIosPicker }, pickerOptions.map((option) => (React.createElement(NativePicker.Item, { label: option.label, value: option.value, key: option.value }))))) : null));
|
|
55
182
|
};
|
|
56
183
|
export default withTheme(Picker);
|
|
184
|
+
const styles = StyleSheet.create({
|
|
185
|
+
marginsContainer: { alignSelf: "stretch" },
|
|
186
|
+
touchableContainer: { alignSelf: "stretch", alignItems: "center" },
|
|
187
|
+
outsetContainer: {
|
|
188
|
+
flexDirection: "row",
|
|
189
|
+
alignItems: "center",
|
|
190
|
+
justifyContent: "space-between",
|
|
191
|
+
},
|
|
192
|
+
insetContainer: {
|
|
193
|
+
flex: 1,
|
|
194
|
+
height: "100%",
|
|
195
|
+
flexDirection: "row",
|
|
196
|
+
alignItems: "center",
|
|
197
|
+
justifyContent: "space-between",
|
|
198
|
+
paddingLeft: 12,
|
|
199
|
+
paddingRight: 12,
|
|
200
|
+
},
|
|
201
|
+
primaryTextContainer: { flex: 1 },
|
|
202
|
+
iosPicker: {
|
|
203
|
+
position: "absolute",
|
|
204
|
+
bottom: 0,
|
|
205
|
+
left: 0,
|
|
206
|
+
right: 0,
|
|
207
|
+
flexDirection: "row",
|
|
208
|
+
justifyContent: "center",
|
|
209
|
+
},
|
|
210
|
+
iosSafeArea: {
|
|
211
|
+
backgroundColor: "white",
|
|
212
|
+
flexDirection: "column",
|
|
213
|
+
width: "100%",
|
|
214
|
+
},
|
|
215
|
+
iosButton: { alignSelf: "flex-end" },
|
|
216
|
+
iosNativePicker: { backgroundColor: "white" },
|
|
217
|
+
nonIosPicker: {
|
|
218
|
+
opacity: 0,
|
|
219
|
+
position: "absolute",
|
|
220
|
+
top: 0,
|
|
221
|
+
left: 0,
|
|
222
|
+
right: 0,
|
|
223
|
+
bottom: 0,
|
|
224
|
+
width: "100%",
|
|
225
|
+
},
|
|
226
|
+
});
|