@draftbit/core 44.1.16 → 44.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/components/DeprecatedButton.js +19 -4
- package/lib/commonjs/components/DeprecatedButton.js.map +1 -1
- package/lib/commonjs/components/DeprecatedCardWrapper.js +14 -2
- package/lib/commonjs/components/DeprecatedCardWrapper.js.map +1 -1
- package/lib/commonjs/components/Justification.js +3 -0
- package/lib/commonjs/components/Picker/Picker.js +26 -289
- package/lib/commonjs/components/Picker/Picker.js.map +1 -1
- package/lib/commonjs/components/Picker/PickerComponent.android.js +135 -0
- package/lib/commonjs/components/Picker/PickerComponent.android.js.map +1 -0
- package/lib/commonjs/components/Picker/PickerComponent.ios.js +161 -0
- package/lib/commonjs/components/Picker/PickerComponent.ios.js.map +1 -0
- package/lib/commonjs/components/Picker/PickerComponent.web.js +136 -0
- package/lib/commonjs/components/Picker/PickerComponent.web.js.map +1 -0
- package/lib/commonjs/components/Picker/PickerTypes.js +6 -0
- package/lib/commonjs/components/Picker/PickerTypes.js.map +1 -0
- package/lib/commonjs/components/ResizeMode.js +3 -0
- package/lib/commonjs/mappings/Picker.js +1 -7
- package/lib/commonjs/mappings/Picker.js.map +1 -1
- package/lib/commonjs/mappings/RadioButtonGroup.js.map +1 -1
- package/lib/commonjs/mappings/RadioButtonRow.js.map +1 -1
- package/lib/commonjs/utilities.js +0 -19
- package/lib/commonjs/utilities.js.map +1 -1
- package/lib/module/components/Justification.js +1 -1
- package/lib/module/components/Picker/Picker.js +28 -281
- package/lib/module/components/Picker/Picker.js.map +1 -1
- package/lib/module/components/Picker/PickerComponent.android.js +112 -0
- package/lib/module/components/Picker/PickerComponent.android.js.map +1 -0
- package/lib/module/components/Picker/PickerComponent.ios.js +135 -0
- package/lib/module/components/Picker/PickerComponent.ios.js.map +1 -0
- package/lib/module/components/Picker/PickerComponent.web.js +113 -0
- package/lib/module/components/Picker/PickerComponent.web.js.map +1 -0
- package/lib/module/components/Picker/PickerTypes.js +2 -0
- package/lib/module/components/Picker/PickerTypes.js.map +1 -0
- package/lib/module/components/ResizeMode.js +1 -1
- package/lib/module/mappings/Picker.js +2 -8
- package/lib/module/mappings/Picker.js.map +1 -1
- package/lib/module/utilities.js +1 -12
- package/lib/module/utilities.js.map +1 -1
- package/lib/typescript/src/components/Picker/Picker.d.ts +4 -28
- package/lib/typescript/src/components/Picker/PickerComponent.android.d.ts +6 -0
- package/lib/typescript/src/components/Picker/PickerComponent.ios.d.ts +7 -0
- package/lib/typescript/src/components/Picker/PickerComponent.web.d.ts +6 -0
- package/lib/typescript/src/components/Picker/PickerTypes.d.ts +18 -0
- package/lib/typescript/src/mappings/Picker.d.ts +0 -21
- package/lib/typescript/src/utilities.d.ts +0 -7
- package/package.json +4 -3
- package/src/Provider.js +9 -0
- package/src/components/Accordion/AccordionGroup.js +44 -0
- package/src/components/Accordion/AccordionItem.js +32 -0
- package/src/components/Accordion/index.js +2 -0
- package/src/components/ActionSheet/ActionSheet.js +45 -0
- package/src/components/ActionSheet/ActionSheetCancel.js +6 -0
- package/src/components/ActionSheet/ActionSheetItem.js +30 -0
- package/src/components/ActionSheet/index.js +3 -0
- package/src/components/AnimatedCircularProgress.js +43 -0
- package/src/components/AspectRatio.js +18 -0
- package/src/components/AvatarEdit.js +30 -0
- package/src/components/Banner.js +109 -0
- package/src/components/Button.js +112 -0
- package/src/components/Card.js +57 -0
- package/src/components/CardBlock.js +54 -0
- package/src/components/CardContainer.js +69 -0
- package/src/components/CardContainerRating.js +79 -0
- package/src/components/CardContainerShortImage.js +33 -0
- package/src/components/CardInline.js +36 -0
- package/src/components/Carousel.js +66 -0
- package/src/components/Checkbox/Checkbox.js +63 -0
- package/src/components/Checkbox/CheckboxGroup.js +21 -0
- package/src/components/Checkbox/CheckboxGroupRow.js +77 -0
- package/src/components/Checkbox/CheckboxRow.js +78 -0
- package/src/components/Checkbox/context.js +14 -0
- package/src/components/Checkbox/index.js +3 -0
- package/src/components/CircleImage.js +8 -0
- package/src/components/CircularProgress.js +78 -0
- package/src/components/Config.js +63 -0
- package/src/components/Container.js +43 -0
- package/src/components/DatePicker/DatePicker.js +368 -0
- package/src/components/DatePicker/DatePickerComponent.js +13 -0
- package/src/components/DatePicker/DatePickerComponent.web.js +30 -0
- package/src/components/DatePicker/DatePickerComponentType.js +1 -0
- package/src/components/DeprecatedButton.js +95 -0
- package/src/components/DeprecatedCardWrapper.js +18 -0
- package/src/components/DeprecatedFAB.js +115 -0
- package/src/components/Divider.js +13 -0
- package/src/components/Elevation.js +20 -0
- package/src/components/FAB.js +46 -0
- package/src/components/FieldSearchBarFull.js +53 -0
- package/src/components/FormRow.js +19 -0
- package/src/components/Header.js +44 -0
- package/src/components/HeaderLarge.js +7 -0
- package/src/components/HeaderMedium.js +7 -0
- package/src/components/HeaderOverline.js +7 -0
- package/src/components/IconButton.js +35 -0
- package/src/components/Image.js +47 -0
- package/src/components/Justification.js +1 -0
- package/src/components/Layout.js +50 -0
- package/src/components/NumberInput.js +49 -0
- package/src/components/Picker/Picker.js +56 -0
- package/src/components/Picker/Picker.tsx +34 -416
- package/src/components/Picker/PickerComponent.android.js +68 -0
- package/src/components/Picker/PickerComponent.android.tsx +116 -0
- package/src/components/Picker/PickerComponent.ios.js +78 -0
- package/src/components/Picker/PickerComponent.ios.tsx +142 -0
- package/src/components/Picker/PickerComponent.web.js +69 -0
- package/src/components/Picker/PickerComponent.web.tsx +117 -0
- package/src/components/Picker/PickerTypes.js +1 -0
- package/src/components/Picker/PickerTypes.ts +18 -0
- package/src/components/Portal/Portal.js +35 -0
- package/src/components/Portal/PortalConsumer.js +28 -0
- package/src/components/Portal/PortalHost.js +105 -0
- package/src/components/Portal/PortalManager.js +29 -0
- package/src/components/ProgressBar.js +118 -0
- package/src/components/ProgressCircle.js +13 -0
- package/src/components/ProgressIndicator.js +27 -0
- package/src/components/RadioButton/RadioButton.js +17 -0
- package/src/components/RadioButton/RadioButtonFieldGroup.js +17 -0
- package/src/components/RadioButton/RadioButtonGroup.js +43 -0
- package/src/components/RadioButton/RadioButtonRow.js +76 -0
- package/src/components/RadioButton/context.js +14 -0
- package/src/components/RadioButton/index.js +4 -0
- package/src/components/ResizeMode.js +1 -0
- package/src/components/Row.js +48 -0
- package/src/components/RowBodyIcon.js +8 -0
- package/src/components/RowHeadlineImageCaption.js +12 -0
- package/src/components/RowHeadlineImageIcon.js +14 -0
- package/src/components/ScreenContainer.js +34 -0
- package/src/components/Slider.js +63 -0
- package/src/components/StarRating.js +50 -0
- package/src/components/StepIndicator.js +346 -0
- package/src/components/Stepper.js +39 -0
- package/src/components/Surface.js +32 -0
- package/src/components/Swiper/Swiper.js +29 -0
- package/src/components/Swiper/SwiperItem.js +9 -0
- package/src/components/Swiper/index.js +2 -0
- package/src/components/Switch.js +56 -0
- package/src/components/Text.js +28 -0
- package/src/components/TextField.js +420 -0
- package/src/components/ToggleButton.js +39 -0
- package/src/components/Touchable.js +12 -0
- package/src/components/Touchable.web.js +2 -0
- package/src/components/Typography.js +36 -0
- package/src/components/useAuthState.js +31 -0
- package/src/constants.js +10 -0
- package/src/hooks.js +12 -0
- package/src/index.js +52 -0
- package/src/interfaces/Icon.js +8 -0
- package/src/mappings/Accordion.js +41 -0
- package/src/mappings/AccordionItem.js +16 -0
- package/src/mappings/ActionSheet.js +13 -0
- package/src/mappings/ActionSheetCancel.js +19 -0
- package/src/mappings/ActionSheetItem.js +23 -0
- package/src/mappings/ActivityIndicator.js +53 -0
- package/src/mappings/AudioPlayer.js +20 -0
- package/src/mappings/AvatarEdit.js +37 -0
- package/src/mappings/Banner.js +32 -0
- package/src/mappings/BlurView.js +41 -0
- package/src/mappings/Button.js +56 -0
- package/src/mappings/Card.js +52 -0
- package/src/mappings/CardBlock.js +122 -0
- package/src/mappings/CardContainer.js +102 -0
- package/src/mappings/CardContainerRating.js +124 -0
- package/src/mappings/CardContainerShortImage.js +118 -0
- package/src/mappings/CardInline.js +51 -0
- package/src/mappings/Carousel.js +18 -0
- package/src/mappings/Checkbox.js +45 -0
- package/src/mappings/CheckboxGroup.js +25 -0
- package/src/mappings/CheckboxRow.js +56 -0
- package/src/mappings/CircleImage.js +24 -0
- package/src/mappings/Container.js +29 -0
- package/src/mappings/CustomCode.js +8 -0
- package/src/mappings/DatePicker.js +146 -0
- package/src/mappings/Divider.js +26 -0
- package/src/mappings/FAB.js +36 -0
- package/src/mappings/Fetch.js +12 -0
- package/src/mappings/FieldSearchBarFull.js +49 -0
- package/src/mappings/FlatList.js +19 -0
- package/src/mappings/HeaderLarge.js +28 -0
- package/src/mappings/HeaderMedium.js +54 -0
- package/src/mappings/HeaderOverline.js +54 -0
- package/src/mappings/Icon.js +25 -0
- package/src/mappings/IconButton.js +30 -0
- package/src/mappings/Image.js +15 -0
- package/src/mappings/ImageBackground.js +28 -0
- package/src/mappings/KeyboardAvoidingView.js +40 -0
- package/src/mappings/KeyboardAwareScrollView.js +49 -0
- package/src/mappings/Layout.js +195 -0
- package/src/mappings/LinearGradient.js +77 -0
- package/src/mappings/MapCallout.js +21 -0
- package/src/mappings/MapMarker.js +47 -0
- package/src/mappings/MapView.js +138 -0
- package/src/mappings/Modal.js +41 -0
- package/src/mappings/Picker.js +137 -0
- package/src/mappings/Picker.ts +0 -4
- package/src/mappings/ProgressBar.js +100 -0
- package/src/mappings/ProgressCircle.js +108 -0
- package/src/mappings/ProgressIndicator.js +180 -0
- package/src/mappings/RadioButton.js +50 -0
- package/src/mappings/RadioButtonGroup.js +16 -0
- package/src/mappings/RadioButtonRow.js +37 -0
- package/src/mappings/RowBodyIcon.js +75 -0
- package/src/mappings/RowHeadlineImageCaption.js +167 -0
- package/src/mappings/RowHeadlineImageIcon.js +99 -0
- package/src/mappings/SafeAreaView.js +33 -0
- package/src/mappings/ScrollView.js +30 -0
- package/src/mappings/Slider.js +59 -0
- package/src/mappings/StarRating.js +42 -0
- package/src/mappings/Stepper.js +28 -0
- package/src/mappings/Surface.js +13 -0
- package/src/mappings/Swiper.js +60 -0
- package/src/mappings/SwiperItem.js +8 -0
- package/src/mappings/Switch.js +75 -0
- package/src/mappings/Text.js +232 -0
- package/src/mappings/TextArea.js +52 -0
- package/src/mappings/TextField.js +158 -0
- package/src/mappings/TextInput.js +208 -0
- package/src/mappings/ToggleButton.js +45 -0
- package/src/mappings/Touchable.js +12 -0
- package/src/mappings/Video.js +74 -0
- package/src/mappings/View.js +206 -0
- package/src/mappings/WebView.js +18 -0
- package/src/styles/DarkTheme.js +26 -0
- package/src/styles/DefaultTheme.js +111 -0
- package/src/styles/fonts.js +62 -0
- package/src/styles/overlay.js +60 -0
- package/src/styles/shadow.js +51 -0
- package/src/theming.js +3 -0
- package/src/utilities.js +54 -0
- package/src/utilities.ts +1 -65
|
@@ -1,77 +1,31 @@
|
|
|
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
|
-
|
|
15
2
|
import { withTheme } from "../../theming";
|
|
16
|
-
|
|
17
|
-
import
|
|
18
|
-
import
|
|
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
|
-
}
|
|
3
|
+
//@ts-ignore
|
|
4
|
+
import PickerComponent from "./PickerComponent"; //unable to find file due to using .android/.web/.ios
|
|
5
|
+
import { PickerComponentProps, PickerOption } from "./PickerTypes";
|
|
32
6
|
|
|
33
|
-
|
|
34
|
-
error?: any;
|
|
7
|
+
type Props = PickerComponentProps & {
|
|
35
8
|
placeholder?: string;
|
|
36
|
-
disabled?: boolean;
|
|
37
|
-
style?: StyleProp<ViewStyle> & { height?: number };
|
|
38
9
|
value?: string;
|
|
39
10
|
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"];
|
|
53
11
|
};
|
|
54
12
|
|
|
55
|
-
function normalizeOptions(options:
|
|
13
|
+
function normalizeOptions(options: Props["options"]): PickerOption[] {
|
|
56
14
|
if (options.length === 0) {
|
|
57
15
|
return [];
|
|
58
16
|
}
|
|
59
17
|
|
|
60
|
-
if (typeof options[0] ===
|
|
18
|
+
if (typeof options[0] === "string") {
|
|
61
19
|
return (options as string[]).map((option) => ({
|
|
62
|
-
label:
|
|
20
|
+
label: option,
|
|
63
21
|
value: String(option),
|
|
64
22
|
}));
|
|
65
23
|
}
|
|
66
24
|
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
options[0].value !== null &&
|
|
70
|
-
options[0].label !== null
|
|
71
|
-
) {
|
|
72
|
-
return (options as PickerOption[]).map((option) => {
|
|
25
|
+
if (options[0].label && options[0].value) {
|
|
26
|
+
return options.map((option) => {
|
|
73
27
|
return {
|
|
74
|
-
label:
|
|
28
|
+
label: option.label,
|
|
75
29
|
value: String(option.value),
|
|
76
30
|
};
|
|
77
31
|
});
|
|
@@ -82,45 +36,18 @@ function normalizeOptions(options: PickerProps["options"]): PickerOption[] {
|
|
|
82
36
|
);
|
|
83
37
|
}
|
|
84
38
|
|
|
85
|
-
const
|
|
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,
|
|
39
|
+
const Picker: React.FC<Props> = ({
|
|
93
40
|
options = [],
|
|
94
|
-
onValueChange,
|
|
95
|
-
defaultValue,
|
|
96
|
-
Icon,
|
|
97
|
-
style,
|
|
98
41
|
placeholder,
|
|
42
|
+
onValueChange: onValueChangeOverride,
|
|
99
43
|
value,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
assistiveText,
|
|
103
|
-
label,
|
|
104
|
-
iconColor = unstyledColor,
|
|
105
|
-
iconSize = 24,
|
|
106
|
-
leftIconMode = "inset",
|
|
107
|
-
leftIconName,
|
|
108
|
-
placeholderTextColor = unstyledColor,
|
|
109
|
-
rightIconName,
|
|
110
|
-
type = "solid",
|
|
44
|
+
defaultValue,
|
|
45
|
+
...props
|
|
111
46
|
}) => {
|
|
112
|
-
const androidPickerRef = React.useRef<any | undefined>(undefined);
|
|
113
|
-
|
|
114
47
|
const [internalValue, setInternalValue] = React.useState<string | undefined>(
|
|
115
48
|
value || defaultValue
|
|
116
49
|
);
|
|
117
50
|
|
|
118
|
-
const [pickerVisible, setPickerVisible] = React.useState(false);
|
|
119
|
-
|
|
120
|
-
const togglePickerVisible = () => {
|
|
121
|
-
setPickerVisible(!pickerVisible);
|
|
122
|
-
};
|
|
123
|
-
|
|
124
51
|
React.useEffect(() => {
|
|
125
52
|
if (value != null) {
|
|
126
53
|
setInternalValue(value);
|
|
@@ -133,11 +60,16 @@ const Picker: React.FC<PickerProps> = ({
|
|
|
133
60
|
}
|
|
134
61
|
}, [defaultValue]);
|
|
135
62
|
|
|
136
|
-
React.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
63
|
+
const onValueChange = React.useCallback(
|
|
64
|
+
(itemValue: string, itemIndex: number) => {
|
|
65
|
+
if (placeholder && itemIndex === 0) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
onValueChangeOverride &&
|
|
69
|
+
onValueChangeOverride(String(itemValue), itemIndex);
|
|
70
|
+
},
|
|
71
|
+
[placeholder, onValueChangeOverride]
|
|
72
|
+
);
|
|
141
73
|
|
|
142
74
|
const normalizedOptions = normalizeOptions(options);
|
|
143
75
|
|
|
@@ -145,336 +77,22 @@ const Picker: React.FC<PickerProps> = ({
|
|
|
145
77
|
? [{ value: placeholder, label: placeholder }, ...normalizedOptions]
|
|
146
78
|
: normalizedOptions;
|
|
147
79
|
|
|
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
|
-
|
|
298
80
|
const handleValueChange = (newValue: string, itemIndex: number) => {
|
|
299
|
-
if (!placeholder || itemIndex > 0) {
|
|
300
|
-
onValueChange?.(newValue, itemIndex);
|
|
301
|
-
}
|
|
302
81
|
setInternalValue(newValue);
|
|
82
|
+
if (onValueChange) {
|
|
83
|
+
onValueChange(newValue, itemIndex);
|
|
84
|
+
}
|
|
303
85
|
};
|
|
304
86
|
|
|
305
87
|
return (
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
{
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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>
|
|
88
|
+
<PickerComponent
|
|
89
|
+
{...props}
|
|
90
|
+
selectedValue={String(internalValue)}
|
|
91
|
+
placeholder={placeholder}
|
|
92
|
+
options={pickerOptions}
|
|
93
|
+
onValueChange={handleValueChange}
|
|
94
|
+
/>
|
|
406
95
|
);
|
|
407
96
|
};
|
|
408
97
|
|
|
409
98
|
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
|
-
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet } from "react-native";
|
|
3
|
+
import omit from "lodash.omit";
|
|
4
|
+
import { withTheme } from "../../theming";
|
|
5
|
+
import { Picker as NativePicker } from "@react-native-picker/picker";
|
|
6
|
+
import { extractStyles } from "../../utilities";
|
|
7
|
+
import TextField from "../TextField";
|
|
8
|
+
import Touchable from "../Touchable";
|
|
9
|
+
const Picker = ({ style, options, placeholder, selectedValue, disabled = false, onValueChange: onValueChangeOverride = () => { }, ...props }) => {
|
|
10
|
+
const { viewStyles: { borderRadius, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
11
|
+
borderWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
12
|
+
borderTopWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
13
|
+
borderRightWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
14
|
+
borderBottomWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
15
|
+
borderLeftWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
16
|
+
borderColor, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
17
|
+
backgroundColor, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
18
|
+
padding, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
19
|
+
paddingTop, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
20
|
+
paddingRight, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
21
|
+
paddingBottom, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
22
|
+
paddingLeft, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
23
|
+
...viewStyles }, } = extractStyles(style);
|
|
24
|
+
const textField = React.useRef(undefined);
|
|
25
|
+
const onValueChange = (itemValue, itemIndex) => {
|
|
26
|
+
toggleFocus();
|
|
27
|
+
onValueChangeOverride(itemValue, itemIndex);
|
|
28
|
+
};
|
|
29
|
+
const toggleFocus = () => {
|
|
30
|
+
if (!disabled) {
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
textField.current.toggleFocus(); // cannot determine if method exists due to component being wrapped in a withTheme()
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const stylesWithoutMargin = style &&
|
|
36
|
+
omit(StyleSheet.flatten(style), [
|
|
37
|
+
"margin",
|
|
38
|
+
"marginTop",
|
|
39
|
+
"marginRight",
|
|
40
|
+
"marginBottom",
|
|
41
|
+
"marginLeft",
|
|
42
|
+
]);
|
|
43
|
+
const selectedLabel = selectedValue &&
|
|
44
|
+
(options.find((o) => o.value === selectedValue)?.label ?? selectedValue);
|
|
45
|
+
return (React.createElement(Touchable, { disabled: disabled, onPress: toggleFocus, style: [styles.container, viewStyles] },
|
|
46
|
+
React.createElement(View, null,
|
|
47
|
+
React.createElement(NativePicker, { enabled: !disabled, selectedValue: selectedValue, onValueChange: onValueChange, style: {
|
|
48
|
+
opacity: 0,
|
|
49
|
+
position: "absolute",
|
|
50
|
+
top: 0,
|
|
51
|
+
left: 0,
|
|
52
|
+
right: 0,
|
|
53
|
+
bottom: 0,
|
|
54
|
+
width: "100%",
|
|
55
|
+
} }, options.map((o) => (React.createElement(NativePicker.Item, { label: o.label, value: o.value, key: o.value })))),
|
|
56
|
+
React.createElement(View, { pointerEvents: "none" },
|
|
57
|
+
React.createElement(TextField, { ...props, value: selectedLabel, placeholder: placeholder,
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
ref: textField, disabled: disabled,
|
|
60
|
+
// @ts-expect-error
|
|
61
|
+
style: stylesWithoutMargin })))));
|
|
62
|
+
};
|
|
63
|
+
const styles = StyleSheet.create({
|
|
64
|
+
container: {
|
|
65
|
+
alignSelf: "stretch",
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
export default withTheme(Picker);
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet } from "react-native";
|
|
3
|
+
import omit from "lodash.omit";
|
|
4
|
+
import { withTheme } from "../../theming";
|
|
5
|
+
import { Picker as NativePicker } from "@react-native-picker/picker";
|
|
6
|
+
import { extractStyles } from "../../utilities";
|
|
7
|
+
|
|
8
|
+
import TextField from "../TextField";
|
|
9
|
+
import Touchable from "../Touchable";
|
|
10
|
+
import { PickerComponentProps } from "./PickerTypes";
|
|
11
|
+
|
|
12
|
+
const Picker: React.FC<PickerComponentProps> = ({
|
|
13
|
+
style,
|
|
14
|
+
options,
|
|
15
|
+
placeholder,
|
|
16
|
+
selectedValue,
|
|
17
|
+
disabled = false,
|
|
18
|
+
onValueChange: onValueChangeOverride = () => {},
|
|
19
|
+
...props
|
|
20
|
+
}) => {
|
|
21
|
+
const {
|
|
22
|
+
viewStyles: {
|
|
23
|
+
borderRadius, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
24
|
+
borderWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
25
|
+
borderTopWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
26
|
+
borderRightWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
27
|
+
borderBottomWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
28
|
+
borderLeftWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
29
|
+
borderColor, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
30
|
+
backgroundColor, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
31
|
+
padding, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
32
|
+
paddingTop, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
33
|
+
paddingRight, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
34
|
+
paddingBottom, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
35
|
+
paddingLeft, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
36
|
+
...viewStyles
|
|
37
|
+
},
|
|
38
|
+
} = extractStyles(style);
|
|
39
|
+
|
|
40
|
+
const textField = React.useRef<typeof TextField | undefined>(undefined);
|
|
41
|
+
|
|
42
|
+
const onValueChange = (itemValue: string, itemIndex: number) => {
|
|
43
|
+
toggleFocus();
|
|
44
|
+
onValueChangeOverride(itemValue, itemIndex);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const toggleFocus = () => {
|
|
48
|
+
if (!disabled) {
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
textField.current.toggleFocus(); // cannot determine if method exists due to component being wrapped in a withTheme()
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const stylesWithoutMargin =
|
|
55
|
+
style &&
|
|
56
|
+
omit(StyleSheet.flatten(style), [
|
|
57
|
+
"margin",
|
|
58
|
+
"marginTop",
|
|
59
|
+
"marginRight",
|
|
60
|
+
"marginBottom",
|
|
61
|
+
"marginLeft",
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
const selectedLabel =
|
|
65
|
+
selectedValue &&
|
|
66
|
+
(options.find((o) => o.value === selectedValue)?.label ?? selectedValue);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<Touchable
|
|
70
|
+
disabled={disabled}
|
|
71
|
+
onPress={toggleFocus}
|
|
72
|
+
style={[styles.container, viewStyles]}
|
|
73
|
+
>
|
|
74
|
+
<View>
|
|
75
|
+
<NativePicker
|
|
76
|
+
enabled={!disabled}
|
|
77
|
+
selectedValue={selectedValue}
|
|
78
|
+
onValueChange={onValueChange}
|
|
79
|
+
style={{
|
|
80
|
+
opacity: 0,
|
|
81
|
+
position: "absolute",
|
|
82
|
+
top: 0,
|
|
83
|
+
left: 0,
|
|
84
|
+
right: 0,
|
|
85
|
+
bottom: 0,
|
|
86
|
+
width: "100%",
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
{options.map((o) => (
|
|
90
|
+
<NativePicker.Item label={o.label} value={o.value} key={o.value} />
|
|
91
|
+
))}
|
|
92
|
+
</NativePicker>
|
|
93
|
+
<View pointerEvents="none">
|
|
94
|
+
<TextField
|
|
95
|
+
{...props}
|
|
96
|
+
value={selectedLabel}
|
|
97
|
+
placeholder={placeholder}
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
ref={textField} // cannot determine if ref is of correct type due to component being wrapped in a withTheme()
|
|
100
|
+
disabled={disabled}
|
|
101
|
+
// @ts-expect-error
|
|
102
|
+
style={stylesWithoutMargin}
|
|
103
|
+
/>
|
|
104
|
+
</View>
|
|
105
|
+
</View>
|
|
106
|
+
</Touchable>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const styles = StyleSheet.create({
|
|
111
|
+
container: {
|
|
112
|
+
alignSelf: "stretch",
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
export default withTheme(Picker);
|