@draftbit/core 44.1.15 → 44.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/lib/commonjs/components/Picker/Picker.js +289 -26
  2. package/lib/commonjs/components/Picker/Picker.js.map +1 -1
  3. package/lib/module/components/Picker/Picker.js +281 -28
  4. package/lib/module/components/Picker/Picker.js.map +1 -1
  5. package/lib/typescript/src/components/Picker/Picker.d.ts +28 -4
  6. package/package.json +3 -4
  7. package/src/components/Picker/Picker.tsx +416 -34
  8. package/lib/commonjs/components/Picker/PickerComponent.android.js +0 -135
  9. package/lib/commonjs/components/Picker/PickerComponent.android.js.map +0 -1
  10. package/lib/commonjs/components/Picker/PickerComponent.ios.js +0 -161
  11. package/lib/commonjs/components/Picker/PickerComponent.ios.js.map +0 -1
  12. package/lib/commonjs/components/Picker/PickerComponent.web.js +0 -136
  13. package/lib/commonjs/components/Picker/PickerComponent.web.js.map +0 -1
  14. package/lib/commonjs/components/Picker/PickerTypes.js +0 -6
  15. package/lib/commonjs/components/Picker/PickerTypes.js.map +0 -1
  16. package/lib/module/components/Picker/PickerComponent.android.js +0 -112
  17. package/lib/module/components/Picker/PickerComponent.android.js.map +0 -1
  18. package/lib/module/components/Picker/PickerComponent.ios.js +0 -135
  19. package/lib/module/components/Picker/PickerComponent.ios.js.map +0 -1
  20. package/lib/module/components/Picker/PickerComponent.web.js +0 -113
  21. package/lib/module/components/Picker/PickerComponent.web.js.map +0 -1
  22. package/lib/module/components/Picker/PickerTypes.js +0 -2
  23. package/lib/module/components/Picker/PickerTypes.js.map +0 -1
  24. package/lib/typescript/src/components/Picker/PickerComponent.android.d.ts +0 -6
  25. package/lib/typescript/src/components/Picker/PickerComponent.ios.d.ts +0 -7
  26. package/lib/typescript/src/components/Picker/PickerComponent.web.d.ts +0 -6
  27. package/lib/typescript/src/components/Picker/PickerTypes.d.ts +0 -18
  28. package/src/components/Picker/PickerComponent.android.tsx +0 -116
  29. package/src/components/Picker/PickerComponent.ios.tsx +0 -142
  30. package/src/components/Picker/PickerComponent.web.tsx +0 -117
  31. package/src/components/Picker/PickerTypes.ts +0 -18
@@ -1,113 +0,0 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- import * as React from "react";
4
- import { View, StyleSheet } from "react-native";
5
- import { Picker as NativePicker } from "@react-native-picker/picker";
6
- import omit from "lodash.omit";
7
- import { withTheme } from "../../theming";
8
- import { extractStyles } from "../../utilities";
9
- import TextField from "../TextField";
10
- import Touchable from "../Touchable";
11
-
12
- const Picker = _ref => {
13
- var _options$find$label, _options$find;
14
-
15
- let {
16
- style,
17
- options,
18
- placeholder,
19
- selectedValue,
20
- disabled = false,
21
- onValueChange: onValueChangeOverride = () => {},
22
- ...props
23
- } = _ref;
24
- const {
25
- viewStyles: {
26
- borderRadius,
27
- // eslint-disable-line @typescript-eslint/no-unused-vars
28
- borderWidth,
29
- // eslint-disable-line @typescript-eslint/no-unused-vars
30
- borderTopWidth,
31
- // eslint-disable-line @typescript-eslint/no-unused-vars
32
- borderRightWidth,
33
- // eslint-disable-line @typescript-eslint/no-unused-vars
34
- borderBottomWidth,
35
- // eslint-disable-line @typescript-eslint/no-unused-vars
36
- borderLeftWidth,
37
- // eslint-disable-line @typescript-eslint/no-unused-vars
38
- borderColor,
39
- // eslint-disable-line @typescript-eslint/no-unused-vars
40
- backgroundColor,
41
- // eslint-disable-line @typescript-eslint/no-unused-vars
42
- padding,
43
- // eslint-disable-line @typescript-eslint/no-unused-vars
44
- paddingTop,
45
- // eslint-disable-line @typescript-eslint/no-unused-vars
46
- paddingRight,
47
- // eslint-disable-line @typescript-eslint/no-unused-vars
48
- paddingBottom,
49
- // eslint-disable-line @typescript-eslint/no-unused-vars
50
- paddingLeft,
51
- // eslint-disable-line @typescript-eslint/no-unused-vars
52
- ...viewStyles
53
- }
54
- } = extractStyles(style);
55
- const textField = React.useRef(undefined);
56
-
57
- const onValueChange = (itemValue, itemIndex) => {
58
- toggleFocus();
59
- onValueChangeOverride(itemValue, itemIndex);
60
- };
61
-
62
- const toggleFocus = () => {
63
- if (!disabled) {
64
- // @ts-ignore
65
- textField.current.toggleFocus(); // cannot determine if method exists due to component being wrapped in a withTheme()
66
- }
67
- };
68
-
69
- const stylesWithoutMargin = style && omit(StyleSheet.flatten(style), ["margin", "marginTop", "marginRight", "marginBottom", "marginLeft"]);
70
- const selectedLabel = selectedValue && ((_options$find$label = (_options$find = options.find(o => o.value === selectedValue)) === null || _options$find === void 0 ? void 0 : _options$find.label) !== null && _options$find$label !== void 0 ? _options$find$label : selectedValue);
71
- return /*#__PURE__*/React.createElement(Touchable, {
72
- disabled: disabled,
73
- onPress: toggleFocus,
74
- style: [styles.container, viewStyles]
75
- }, /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(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
- }, options.map(o => /*#__PURE__*/React.createElement(NativePicker.Item, {
90
- label: o.label,
91
- value: o.value,
92
- key: o.value
93
- }))), /*#__PURE__*/React.createElement(View, {
94
- pointerEvents: "none"
95
- }, /*#__PURE__*/React.createElement(TextField, _extends({}, props, {
96
- value: selectedLabel,
97
- placeholder: placeholder // @ts-ignore
98
- ,
99
- ref: textField // cannot determine if ref is of correct type due to component being wrapped in a withTheme()
100
- ,
101
- disabled: disabled // @ts-expect-error
102
- ,
103
- style: stylesWithoutMargin
104
- })))));
105
- };
106
-
107
- const styles = StyleSheet.create({
108
- container: {
109
- alignSelf: "stretch"
110
- }
111
- });
112
- export default withTheme(Picker);
113
- //# sourceMappingURL=PickerComponent.web.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["PickerComponent.web.tsx"],"names":["React","View","StyleSheet","Picker","NativePicker","omit","withTheme","extractStyles","TextField","Touchable","style","options","placeholder","selectedValue","disabled","onValueChange","onValueChangeOverride","props","viewStyles","borderRadius","borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderColor","backgroundColor","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","textField","useRef","undefined","itemValue","itemIndex","toggleFocus","current","stylesWithoutMargin","flatten","selectedLabel","find","o","value","label","styles","container","flex","opacity","position","top","left","right","bottom","width","map","create","alignSelf"],"mappings":"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","sourcesContent":["import * as React from \"react\";\nimport { View, StyleSheet } from \"react-native\";\nimport { Picker as NativePicker } from \"@react-native-picker/picker\";\nimport omit from \"lodash.omit\";\nimport { withTheme } from \"../../theming\";\nimport { extractStyles } from \"../../utilities\";\n\nimport TextField from \"../TextField\";\nimport Touchable from \"../Touchable\";\nimport { PickerComponentProps } from \"./PickerTypes\";\n\nconst Picker: React.FC<PickerComponentProps> = ({\n style,\n options,\n placeholder,\n selectedValue,\n disabled = false,\n onValueChange: onValueChangeOverride = () => {},\n ...props\n}) => {\n const {\n viewStyles: {\n borderRadius, // eslint-disable-line @typescript-eslint/no-unused-vars\n borderWidth, // eslint-disable-line @typescript-eslint/no-unused-vars\n borderTopWidth, // eslint-disable-line @typescript-eslint/no-unused-vars\n borderRightWidth, // eslint-disable-line @typescript-eslint/no-unused-vars\n borderBottomWidth, // eslint-disable-line @typescript-eslint/no-unused-vars\n borderLeftWidth, // eslint-disable-line @typescript-eslint/no-unused-vars\n borderColor, // eslint-disable-line @typescript-eslint/no-unused-vars\n backgroundColor, // eslint-disable-line @typescript-eslint/no-unused-vars\n padding, // eslint-disable-line @typescript-eslint/no-unused-vars\n paddingTop, // eslint-disable-line @typescript-eslint/no-unused-vars\n paddingRight, // eslint-disable-line @typescript-eslint/no-unused-vars\n paddingBottom, // eslint-disable-line @typescript-eslint/no-unused-vars\n paddingLeft, // eslint-disable-line @typescript-eslint/no-unused-vars\n ...viewStyles\n },\n } = extractStyles(style);\n\n const textField = React.useRef<typeof TextField | undefined>(undefined);\n\n const onValueChange = (itemValue: string, itemIndex: number) => {\n toggleFocus();\n onValueChangeOverride(itemValue, itemIndex);\n };\n\n const toggleFocus = () => {\n if (!disabled) {\n // @ts-ignore\n textField.current.toggleFocus(); // cannot determine if method exists due to component being wrapped in a withTheme()\n }\n };\n\n const stylesWithoutMargin =\n style &&\n omit(StyleSheet.flatten(style), [\n \"margin\",\n \"marginTop\",\n \"marginRight\",\n \"marginBottom\",\n \"marginLeft\",\n ]);\n\n const selectedLabel =\n selectedValue &&\n (options.find((o) => o.value === selectedValue)?.label ?? selectedValue);\n\n return (\n <Touchable\n disabled={disabled}\n onPress={toggleFocus}\n style={[styles.container, viewStyles]}\n >\n <View>\n <NativePicker\n enabled={!disabled}\n selectedValue={selectedValue}\n onValueChange={onValueChange}\n style={{\n flex: 1,\n opacity: 0,\n position: \"absolute\",\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n width: \"100%\",\n }}\n >\n {options.map((o) => (\n <NativePicker.Item label={o.label} value={o.value} key={o.value} />\n ))}\n </NativePicker>\n <View pointerEvents=\"none\">\n <TextField\n {...props}\n value={selectedLabel}\n placeholder={placeholder}\n // @ts-ignore\n ref={textField} // cannot determine if ref is of correct type due to component being wrapped in a withTheme()\n disabled={disabled}\n // @ts-expect-error\n style={stylesWithoutMargin}\n />\n </View>\n </View>\n </Touchable>\n );\n};\n\nconst styles = StyleSheet.create({\n container: {\n alignSelf: \"stretch\",\n },\n});\n\nexport default withTheme(Picker);\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=PickerTypes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -1,6 +0,0 @@
1
- import * as React from "react";
2
- import { PickerComponentProps } from "./PickerTypes";
3
- declare const _default: React.ComponentType<import("@draftbit/react-theme-provider").$Without<PickerComponentProps, "theme"> & {
4
- theme?: import("@draftbit/react-theme-provider").$DeepPartial<any> | undefined;
5
- }> & import("@draftbit/react-theme-provider/typings/hoist-non-react-statics").NonReactStatics<React.ComponentType<PickerComponentProps> & React.FC<PickerComponentProps>, {}>;
6
- export default _default;
@@ -1,7 +0,0 @@
1
- import * as React from "react";
2
- import { PickerComponentProps } from "./PickerTypes";
3
- import type { IconSlot } from "../../interfaces/Icon";
4
- declare const _default: React.ComponentType<import("@draftbit/react-theme-provider").$Without<PickerComponentProps & IconSlot, "theme"> & {
5
- theme?: import("@draftbit/react-theme-provider").$DeepPartial<any> | undefined;
6
- }> & import("@draftbit/react-theme-provider/typings/hoist-non-react-statics").NonReactStatics<React.ComponentType<PickerComponentProps & IconSlot> & React.FC<PickerComponentProps & IconSlot>, {}>;
7
- export default _default;
@@ -1,6 +0,0 @@
1
- import * as React from "react";
2
- import { PickerComponentProps } from "./PickerTypes";
3
- declare const _default: React.ComponentType<import("@draftbit/react-theme-provider").$Without<PickerComponentProps, "theme"> & {
4
- theme?: import("@draftbit/react-theme-provider").$DeepPartial<any> | undefined;
5
- }> & import("@draftbit/react-theme-provider/typings/hoist-non-react-statics").NonReactStatics<React.ComponentType<PickerComponentProps> & React.FC<PickerComponentProps>, {}>;
6
- export default _default;
@@ -1,18 +0,0 @@
1
- import { ViewStyle } from "react-native";
2
- import { StyleProp } from "react-native";
3
- import { Props as TextFieldProps } from "../TextField";
4
- export interface PickerOption {
5
- value: string;
6
- label: string;
7
- }
8
- export interface PickerComponentProps extends TextFieldProps {
9
- style?: StyleProp<ViewStyle> & {
10
- height?: number;
11
- };
12
- options: PickerOption[];
13
- placeholder?: string;
14
- selectedValue: string;
15
- disabled?: boolean;
16
- onValueChange?: (value: string, index: number) => void;
17
- defaultValue?: string;
18
- }
@@ -1,116 +0,0 @@
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);
@@ -1,142 +0,0 @@
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
-
6
- import { Picker as NativePicker } from "@react-native-picker/picker";
7
-
8
- import { withTheme } from "../../theming";
9
-
10
- import Portal from "../Portal/Portal";
11
- import Button from "../DeprecatedButton";
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";
17
-
18
- const Picker: React.FC<PickerComponentProps & IconSlot> = ({
19
- Icon,
20
- style,
21
- options,
22
- placeholder,
23
- selectedValue,
24
- disabled = false,
25
- onValueChange = () => {},
26
- theme: { colors },
27
- ...props
28
- }) => {
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);
50
-
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>
117
- );
118
- };
119
-
120
- const styles = StyleSheet.create({
121
- container: {
122
- alignSelf: "stretch",
123
- },
124
- picker: {
125
- position: "absolute",
126
- bottom: 0,
127
- left: 0,
128
- right: 0,
129
- flexDirection: "row",
130
- justifyContent: "center",
131
- },
132
- pickerContainer: {
133
- backgroundColor: "white",
134
- flexDirection: "column",
135
- width: "100%",
136
- },
137
- closeButton: {
138
- alignSelf: "flex-end",
139
- },
140
- });
141
-
142
- export default withTheme(Picker);
@@ -1,117 +0,0 @@
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
-
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
- 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>
108
- );
109
- };
110
-
111
- const styles = StyleSheet.create({
112
- container: {
113
- alignSelf: "stretch",
114
- },
115
- });
116
-
117
- export default withTheme(Picker);
@@ -1,18 +0,0 @@
1
- import { ViewStyle } from "react-native";
2
- import { StyleProp } from "react-native";
3
- import { Props as TextFieldProps } from "../TextField";
4
-
5
- export interface PickerOption {
6
- value: string;
7
- label: string;
8
- }
9
-
10
- export interface PickerComponentProps extends TextFieldProps {
11
- style?: StyleProp<ViewStyle> & { height?: number };
12
- options: PickerOption[];
13
- placeholder?: string;
14
- selectedValue: string;
15
- disabled?: boolean;
16
- onValueChange?: (value: string, index: number) => void;
17
- defaultValue?: string;
18
- }