@draftbit/core 44.1.14 → 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 +27 -266
- package/lib/commonjs/components/Picker/Picker.js.map +1 -1
- package/lib/commonjs/components/Picker/PickerComponent.android.js +110 -34
- package/lib/commonjs/components/Picker/PickerComponent.android.js.map +1 -1
- package/lib/commonjs/components/Picker/PickerComponent.ios.js +113 -44
- package/lib/commonjs/components/Picker/PickerComponent.ios.js.map +1 -1
- package/lib/commonjs/components/Picker/PickerComponent.web.js +111 -34
- package/lib/commonjs/components/Picker/PickerComponent.web.js.map +1 -1
- 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 -260
- package/lib/module/components/Picker/Picker.js.map +1 -1
- package/lib/module/components/Picker/PickerComponent.android.js +103 -32
- package/lib/module/components/Picker/PickerComponent.android.js.map +1 -1
- package/lib/module/components/Picker/PickerComponent.ios.js +108 -42
- package/lib/module/components/Picker/PickerComponent.ios.js.map +1 -1
- package/lib/module/components/Picker/PickerComponent.web.js +104 -32
- package/lib/module/components/Picker/PickerComponent.web.js.map +1 -1
- 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 +5 -12
- package/lib/typescript/src/components/Picker/PickerComponent.ios.d.ts +5 -11
- package/lib/typescript/src/components/Picker/PickerComponent.web.d.ts +5 -12
- 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 +2 -2
- 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 -434
- package/src/components/Picker/PickerComponent.android.js +68 -0
- package/src/components/Picker/PickerComponent.android.tsx +101 -44
- package/src/components/Picker/PickerComponent.ios.js +78 -0
- package/src/components/Picker/PickerComponent.ios.tsx +116 -63
- package/src/components/Picker/PickerComponent.web.js +69 -0
- package/src/components/Picker/PickerComponent.web.tsx +102 -44
- 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,59 +1,116 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { View, StyleSheet } from "react-native";
|
|
3
|
+
import omit from "lodash.omit";
|
|
4
|
+
import { withTheme } from "../../theming";
|
|
4
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";
|
|
5
11
|
|
|
6
|
-
|
|
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);
|
|
7
39
|
|
|
8
|
-
|
|
40
|
+
const textField = React.useRef<typeof TextField | undefined>(undefined);
|
|
9
41
|
|
|
10
|
-
const
|
|
42
|
+
const onValueChange = (itemValue: string, itemIndex: number) => {
|
|
43
|
+
toggleFocus();
|
|
44
|
+
onValueChangeOverride(itemValue, itemIndex);
|
|
45
|
+
};
|
|
11
46
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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);
|
|
20
67
|
|
|
21
|
-
export const PickerComponent: React.FC<PickerComponentProps> = ({
|
|
22
|
-
androidPickerRef,
|
|
23
|
-
togglePickerVisible,
|
|
24
|
-
pickerOptions,
|
|
25
|
-
internalValue,
|
|
26
|
-
handleValueChange,
|
|
27
|
-
}) => {
|
|
28
68
|
return (
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
style={styles.
|
|
33
|
-
ref={androidPickerRef}
|
|
34
|
-
onBlur={togglePickerVisible}
|
|
69
|
+
<Touchable
|
|
70
|
+
disabled={disabled}
|
|
71
|
+
onPress={toggleFocus}
|
|
72
|
+
style={[styles.container, viewStyles]}
|
|
35
73
|
>
|
|
36
|
-
|
|
37
|
-
<NativePicker
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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>
|
|
44
107
|
);
|
|
45
108
|
};
|
|
46
109
|
|
|
47
110
|
const styles = StyleSheet.create({
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
position: "absolute",
|
|
51
|
-
top: 0,
|
|
52
|
-
left: 0,
|
|
53
|
-
right: 0,
|
|
54
|
-
bottom: 0,
|
|
55
|
-
width: "100%",
|
|
56
|
-
maxWidth: deviceWidth,
|
|
57
|
-
maxHeight: deviceHeight,
|
|
111
|
+
container: {
|
|
112
|
+
alignSelf: "stretch",
|
|
58
113
|
},
|
|
59
114
|
});
|
|
115
|
+
|
|
116
|
+
export default withTheme(Picker);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet } from "react-native";
|
|
3
|
+
import { SafeAreaView } from "react-native-safe-area-context";
|
|
4
|
+
import omit from "lodash.omit";
|
|
5
|
+
import { Picker as NativePicker } from "@react-native-picker/picker";
|
|
6
|
+
import { withTheme } from "../../theming";
|
|
7
|
+
import Portal from "../Portal/Portal";
|
|
8
|
+
import Button from "../DeprecatedButton";
|
|
9
|
+
import TextField from "../TextField";
|
|
10
|
+
import Touchable from "../Touchable";
|
|
11
|
+
import { extractStyles } from "../../utilities";
|
|
12
|
+
const Picker = ({ Icon, style, options, placeholder, selectedValue, disabled = false, onValueChange = () => { }, theme: { colors }, ...props }) => {
|
|
13
|
+
const { viewStyles: { borderRadius, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
14
|
+
borderWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
15
|
+
borderTopWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
16
|
+
borderRightWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
17
|
+
borderBottomWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
18
|
+
borderLeftWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
19
|
+
borderColor, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
20
|
+
backgroundColor, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
21
|
+
padding, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
22
|
+
paddingTop, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
23
|
+
paddingRight, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
24
|
+
paddingBottom, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
25
|
+
paddingLeft, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
26
|
+
...viewStyles }, } = extractStyles(style);
|
|
27
|
+
const textField = React.useRef(undefined);
|
|
28
|
+
const [pickerVisible, setIsPickerVisible] = React.useState(false);
|
|
29
|
+
const toggleVisibility = () => {
|
|
30
|
+
setIsPickerVisible(!pickerVisible);
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
textField.current.toggleFocus(); // cannot determine if method exists due to component being wrapped in a withTheme()
|
|
33
|
+
};
|
|
34
|
+
const stylesWithoutMargin = style &&
|
|
35
|
+
omit(StyleSheet.flatten(style), [
|
|
36
|
+
"margin",
|
|
37
|
+
"marginTop",
|
|
38
|
+
"marginRight",
|
|
39
|
+
"marginBottom",
|
|
40
|
+
"marginLeft",
|
|
41
|
+
]);
|
|
42
|
+
const selectedLabel = selectedValue &&
|
|
43
|
+
(options.find((o) => o.value === selectedValue)?.label ?? selectedValue);
|
|
44
|
+
return (React.createElement(View, { style: [styles.container, viewStyles] },
|
|
45
|
+
React.createElement(Touchable, { disabled: disabled, onPress: toggleVisibility },
|
|
46
|
+
React.createElement(TextField, { ...props, value: String(selectedLabel), placeholder: placeholder,
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
ref: textField, disabled: disabled, pointerEvents: "none",
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
style: stylesWithoutMargin, Icon: Icon })),
|
|
51
|
+
pickerVisible && (React.createElement(Portal, null,
|
|
52
|
+
React.createElement(View, { style: [styles.picker, { backgroundColor: colors.divider }] },
|
|
53
|
+
React.createElement(SafeAreaView, { style: styles.pickerContainer },
|
|
54
|
+
React.createElement(Button, { Icon: Icon, type: "text", onPress: toggleVisibility, style: styles.closeButton }, "Close"),
|
|
55
|
+
React.createElement(NativePicker, { style: { backgroundColor: "white" }, selectedValue: selectedValue, onValueChange: onValueChange }, options.map((o) => (React.createElement(NativePicker.Item, { label: o.label, value: o.value, key: o.value }))))))))));
|
|
56
|
+
};
|
|
57
|
+
const styles = StyleSheet.create({
|
|
58
|
+
container: {
|
|
59
|
+
alignSelf: "stretch",
|
|
60
|
+
},
|
|
61
|
+
picker: {
|
|
62
|
+
position: "absolute",
|
|
63
|
+
bottom: 0,
|
|
64
|
+
left: 0,
|
|
65
|
+
right: 0,
|
|
66
|
+
flexDirection: "row",
|
|
67
|
+
justifyContent: "center",
|
|
68
|
+
},
|
|
69
|
+
pickerContainer: {
|
|
70
|
+
backgroundColor: "white",
|
|
71
|
+
flexDirection: "column",
|
|
72
|
+
width: "100%",
|
|
73
|
+
},
|
|
74
|
+
closeButton: {
|
|
75
|
+
alignSelf: "flex-end",
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
export default withTheme(Picker);
|
|
@@ -1,89 +1,142 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { View, StyleSheet
|
|
2
|
+
import { View, StyleSheet } from "react-native";
|
|
3
3
|
import { SafeAreaView } from "react-native-safe-area-context";
|
|
4
|
+
import omit from "lodash.omit";
|
|
5
|
+
|
|
4
6
|
import { Picker as NativePicker } from "@react-native-picker/picker";
|
|
5
7
|
|
|
6
|
-
import
|
|
8
|
+
import { withTheme } from "../../theming";
|
|
9
|
+
|
|
7
10
|
import Portal from "../Portal/Portal";
|
|
8
11
|
import Button from "../DeprecatedButton";
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Icon: IconSlot["Icon"];
|
|
15
|
-
androidPickerRef: React.RefObject<any>;
|
|
16
|
-
togglePickerVisible: () => void;
|
|
17
|
-
pickerOptions: PickerOption[];
|
|
18
|
-
internalValue: string | undefined;
|
|
19
|
-
handleValueChange: (newValue: string, itemIndex: number) => void;
|
|
20
|
-
}
|
|
12
|
+
import TextField from "../TextField";
|
|
13
|
+
import Touchable from "../Touchable";
|
|
14
|
+
import { PickerComponentProps } from "./PickerTypes";
|
|
15
|
+
import { extractStyles } from "../../utilities";
|
|
16
|
+
import type { IconSlot } from "../../interfaces/Icon";
|
|
21
17
|
|
|
22
|
-
|
|
18
|
+
const Picker: React.FC<PickerComponentProps & IconSlot> = ({
|
|
23
19
|
Icon,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
style,
|
|
21
|
+
options,
|
|
22
|
+
placeholder,
|
|
23
|
+
selectedValue,
|
|
24
|
+
disabled = false,
|
|
25
|
+
onValueChange = () => {},
|
|
26
|
+
theme: { colors },
|
|
27
|
+
...props
|
|
28
28
|
}) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
const {
|
|
30
|
+
viewStyles: {
|
|
31
|
+
borderRadius, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
32
|
+
borderWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
33
|
+
borderTopWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
34
|
+
borderRightWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
35
|
+
borderBottomWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
36
|
+
borderLeftWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
37
|
+
borderColor, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
38
|
+
backgroundColor, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
39
|
+
padding, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
40
|
+
paddingTop, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
41
|
+
paddingRight, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
42
|
+
paddingBottom, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
43
|
+
paddingLeft, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
44
|
+
...viewStyles
|
|
45
|
+
},
|
|
46
|
+
} = extractStyles(style);
|
|
47
|
+
|
|
48
|
+
const textField = React.useRef<typeof TextField | undefined>(undefined);
|
|
49
|
+
const [pickerVisible, setIsPickerVisible] = React.useState(false);
|
|
41
50
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
const toggleVisibility = () => {
|
|
52
|
+
setIsPickerVisible(!pickerVisible);
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
textField.current.toggleFocus(); // cannot determine if method exists due to component being wrapped in a withTheme()
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const stylesWithoutMargin =
|
|
58
|
+
style &&
|
|
59
|
+
omit(StyleSheet.flatten(style), [
|
|
60
|
+
"margin",
|
|
61
|
+
"marginTop",
|
|
62
|
+
"marginRight",
|
|
63
|
+
"marginBottom",
|
|
64
|
+
"marginLeft",
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
const selectedLabel =
|
|
68
|
+
selectedValue &&
|
|
69
|
+
(options.find((o) => o.value === selectedValue)?.label ?? selectedValue);
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<View style={[styles.container, viewStyles]}>
|
|
73
|
+
<Touchable disabled={disabled} onPress={toggleVisibility}>
|
|
74
|
+
<TextField
|
|
75
|
+
{...props}
|
|
76
|
+
value={String(selectedLabel)}
|
|
77
|
+
placeholder={placeholder}
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
ref={textField} // cannot determine if ref is of correct type due to component being wrapped in a withTheme()
|
|
80
|
+
disabled={disabled}
|
|
81
|
+
pointerEvents="none"
|
|
82
|
+
// @ts-expect-error
|
|
83
|
+
style={stylesWithoutMargin}
|
|
84
|
+
Icon={Icon}
|
|
85
|
+
/>
|
|
86
|
+
</Touchable>
|
|
87
|
+
{pickerVisible && (
|
|
88
|
+
<Portal>
|
|
89
|
+
<View style={[styles.picker, { backgroundColor: colors.divider }]}>
|
|
90
|
+
<SafeAreaView style={styles.pickerContainer}>
|
|
91
|
+
<Button
|
|
92
|
+
Icon={Icon}
|
|
93
|
+
type="text"
|
|
94
|
+
onPress={toggleVisibility}
|
|
95
|
+
style={styles.closeButton}
|
|
96
|
+
>
|
|
97
|
+
Close
|
|
98
|
+
</Button>
|
|
99
|
+
<NativePicker
|
|
100
|
+
style={{ backgroundColor: "white" }}
|
|
101
|
+
selectedValue={selectedValue}
|
|
102
|
+
onValueChange={onValueChange}
|
|
103
|
+
>
|
|
104
|
+
{options.map((o: any) => (
|
|
105
|
+
<NativePicker.Item
|
|
106
|
+
label={o.label}
|
|
107
|
+
value={o.value}
|
|
108
|
+
key={o.value}
|
|
109
|
+
/>
|
|
110
|
+
))}
|
|
111
|
+
</NativePicker>
|
|
112
|
+
</SafeAreaView>
|
|
113
|
+
</View>
|
|
114
|
+
</Portal>
|
|
115
|
+
)}
|
|
116
|
+
</View>
|
|
58
117
|
);
|
|
59
118
|
};
|
|
60
119
|
|
|
61
120
|
const styles = StyleSheet.create({
|
|
62
|
-
|
|
121
|
+
container: {
|
|
122
|
+
alignSelf: "stretch",
|
|
123
|
+
},
|
|
124
|
+
picker: {
|
|
63
125
|
position: "absolute",
|
|
64
126
|
bottom: 0,
|
|
65
127
|
left: 0,
|
|
66
128
|
right: 0,
|
|
67
129
|
flexDirection: "row",
|
|
68
130
|
justifyContent: "center",
|
|
69
|
-
width: deviceWidth, // TODO
|
|
70
|
-
maxWidth: deviceWidth,
|
|
71
|
-
maxHeight: deviceHeight,
|
|
72
|
-
backgroundColor: "green", // TODO
|
|
73
|
-
// backgroundColor: "rgba(255, 255, 255, 1)",
|
|
74
131
|
},
|
|
75
|
-
|
|
76
|
-
backgroundColor: "
|
|
77
|
-
// backgroundColor: "white",// TODO
|
|
132
|
+
pickerContainer: {
|
|
133
|
+
backgroundColor: "white",
|
|
78
134
|
flexDirection: "column",
|
|
79
|
-
width:
|
|
80
|
-
maxWidth: deviceWidth,
|
|
135
|
+
width: "100%",
|
|
81
136
|
},
|
|
82
|
-
|
|
137
|
+
closeButton: {
|
|
83
138
|
alignSelf: "flex-end",
|
|
84
139
|
},
|
|
85
|
-
iosNativePicker: {
|
|
86
|
-
//backgroundColor: "white",// TODO
|
|
87
|
-
backgroundColor: "red",
|
|
88
|
-
},
|
|
89
140
|
});
|
|
141
|
+
|
|
142
|
+
export default withTheme(Picker);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet } from "react-native";
|
|
3
|
+
import { Picker as NativePicker } from "@react-native-picker/picker";
|
|
4
|
+
import omit from "lodash.omit";
|
|
5
|
+
import { withTheme } from "../../theming";
|
|
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
|
+
flex: 1,
|
|
49
|
+
opacity: 0,
|
|
50
|
+
position: "absolute",
|
|
51
|
+
top: 0,
|
|
52
|
+
left: 0,
|
|
53
|
+
right: 0,
|
|
54
|
+
bottom: 0,
|
|
55
|
+
width: "100%",
|
|
56
|
+
} }, options.map((o) => (React.createElement(NativePicker.Item, { label: o.label, value: o.value, key: o.value })))),
|
|
57
|
+
React.createElement(View, { pointerEvents: "none" },
|
|
58
|
+
React.createElement(TextField, { ...props, value: selectedLabel, placeholder: placeholder,
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
ref: textField, disabled: disabled,
|
|
61
|
+
// @ts-expect-error
|
|
62
|
+
style: stylesWithoutMargin })))));
|
|
63
|
+
};
|
|
64
|
+
const styles = StyleSheet.create({
|
|
65
|
+
container: {
|
|
66
|
+
alignSelf: "stretch",
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
export default withTheme(Picker);
|
|
@@ -1,59 +1,117 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { View, StyleSheet } from "react-native";
|
|
4
3
|
import { Picker as NativePicker } from "@react-native-picker/picker";
|
|
4
|
+
import omit from "lodash.omit";
|
|
5
|
+
import { withTheme } from "../../theming";
|
|
6
|
+
import { extractStyles } from "../../utilities";
|
|
7
|
+
|
|
8
|
+
import TextField from "../TextField";
|
|
9
|
+
import Touchable from "../Touchable";
|
|
10
|
+
import { PickerComponentProps } from "./PickerTypes";
|
|
5
11
|
|
|
6
|
-
|
|
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);
|
|
7
39
|
|
|
8
|
-
|
|
40
|
+
const textField = React.useRef<typeof TextField | undefined>(undefined);
|
|
9
41
|
|
|
10
|
-
const
|
|
42
|
+
const onValueChange = (itemValue: string, itemIndex: number) => {
|
|
43
|
+
toggleFocus();
|
|
44
|
+
onValueChangeOverride(itemValue, itemIndex);
|
|
45
|
+
};
|
|
11
46
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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);
|
|
20
67
|
|
|
21
|
-
export const PickerComponent: React.FC<PickerComponentProps> = ({
|
|
22
|
-
androidPickerRef,
|
|
23
|
-
togglePickerVisible,
|
|
24
|
-
pickerOptions,
|
|
25
|
-
internalValue,
|
|
26
|
-
handleValueChange,
|
|
27
|
-
}) => {
|
|
28
68
|
return (
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
style={styles.
|
|
33
|
-
ref={androidPickerRef}
|
|
34
|
-
onBlur={togglePickerVisible}
|
|
69
|
+
<Touchable
|
|
70
|
+
disabled={disabled}
|
|
71
|
+
onPress={toggleFocus}
|
|
72
|
+
style={[styles.container, viewStyles]}
|
|
35
73
|
>
|
|
36
|
-
|
|
37
|
-
<NativePicker
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
74
|
+
<View>
|
|
75
|
+
<NativePicker
|
|
76
|
+
enabled={!disabled}
|
|
77
|
+
selectedValue={selectedValue}
|
|
78
|
+
onValueChange={onValueChange}
|
|
79
|
+
style={{
|
|
80
|
+
flex: 1,
|
|
81
|
+
opacity: 0,
|
|
82
|
+
position: "absolute",
|
|
83
|
+
top: 0,
|
|
84
|
+
left: 0,
|
|
85
|
+
right: 0,
|
|
86
|
+
bottom: 0,
|
|
87
|
+
width: "100%",
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
{options.map((o) => (
|
|
91
|
+
<NativePicker.Item label={o.label} value={o.value} key={o.value} />
|
|
92
|
+
))}
|
|
93
|
+
</NativePicker>
|
|
94
|
+
<View pointerEvents="none">
|
|
95
|
+
<TextField
|
|
96
|
+
{...props}
|
|
97
|
+
value={selectedLabel}
|
|
98
|
+
placeholder={placeholder}
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
ref={textField} // cannot determine if ref is of correct type due to component being wrapped in a withTheme()
|
|
101
|
+
disabled={disabled}
|
|
102
|
+
// @ts-expect-error
|
|
103
|
+
style={stylesWithoutMargin}
|
|
104
|
+
/>
|
|
105
|
+
</View>
|
|
106
|
+
</View>
|
|
107
|
+
</Touchable>
|
|
44
108
|
);
|
|
45
109
|
};
|
|
46
110
|
|
|
47
111
|
const styles = StyleSheet.create({
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
position: "absolute",
|
|
51
|
-
top: 0,
|
|
52
|
-
left: 0,
|
|
53
|
-
right: 0,
|
|
54
|
-
bottom: 0,
|
|
55
|
-
width: "100%",
|
|
56
|
-
maxWidth: deviceWidth,
|
|
57
|
-
maxHeight: deviceHeight,
|
|
112
|
+
container: {
|
|
113
|
+
alignSelf: "stretch",
|
|
58
114
|
},
|
|
59
115
|
});
|
|
116
|
+
|
|
117
|
+
export default withTheme(Picker);
|