@draftbit/core 44.1.13-c10e64.0 → 44.1.14

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 (228) hide show
  1. package/lib/commonjs/components/CircularProgress.js.map +1 -1
  2. package/lib/commonjs/components/DatePicker/DatePickerComponent.web.js.map +1 -1
  3. package/lib/commonjs/components/DeprecatedCardWrapper.js +2 -14
  4. package/lib/commonjs/components/DeprecatedCardWrapper.js.map +1 -1
  5. package/lib/commonjs/components/Justification.js +0 -3
  6. package/lib/commonjs/components/Picker/Picker.js +266 -27
  7. package/lib/commonjs/components/Picker/Picker.js.map +1 -1
  8. package/lib/commonjs/components/Picker/PickerComponent.android.js +34 -110
  9. package/lib/commonjs/components/Picker/PickerComponent.android.js.map +1 -1
  10. package/lib/commonjs/components/Picker/PickerComponent.ios.js +44 -113
  11. package/lib/commonjs/components/Picker/PickerComponent.ios.js.map +1 -1
  12. package/lib/commonjs/components/Picker/PickerComponent.web.js +34 -111
  13. package/lib/commonjs/components/Picker/PickerComponent.web.js.map +1 -1
  14. package/lib/commonjs/components/ResizeMode.js +0 -3
  15. package/lib/commonjs/mappings/Picker.js +7 -1
  16. package/lib/commonjs/mappings/Picker.js.map +1 -1
  17. package/lib/commonjs/mappings/RadioButtonGroup.js.map +1 -1
  18. package/lib/commonjs/mappings/RadioButtonRow.js.map +1 -1
  19. package/lib/commonjs/utilities.js +19 -0
  20. package/lib/commonjs/utilities.js.map +1 -1
  21. package/lib/module/components/Justification.js +1 -1
  22. package/lib/module/components/Picker/Picker.js +260 -28
  23. package/lib/module/components/Picker/Picker.js.map +1 -1
  24. package/lib/module/components/Picker/PickerComponent.android.js +32 -103
  25. package/lib/module/components/Picker/PickerComponent.android.js.map +1 -1
  26. package/lib/module/components/Picker/PickerComponent.ios.js +42 -108
  27. package/lib/module/components/Picker/PickerComponent.ios.js.map +1 -1
  28. package/lib/module/components/Picker/PickerComponent.web.js +32 -104
  29. package/lib/module/components/Picker/PickerComponent.web.js.map +1 -1
  30. package/lib/module/components/ResizeMode.js +1 -1
  31. package/lib/module/mappings/Picker.js +8 -2
  32. package/lib/module/mappings/Picker.js.map +1 -1
  33. package/lib/module/utilities.js +12 -1
  34. package/lib/module/utilities.js.map +1 -1
  35. package/lib/typescript/src/components/Picker/Picker.d.ts +28 -4
  36. package/lib/typescript/src/components/Picker/PickerComponent.android.d.ts +12 -5
  37. package/lib/typescript/src/components/Picker/PickerComponent.ios.d.ts +11 -5
  38. package/lib/typescript/src/components/Picker/PickerComponent.web.d.ts +12 -5
  39. package/lib/typescript/src/mappings/Picker.d.ts +21 -0
  40. package/lib/typescript/src/utilities.d.ts +7 -0
  41. package/package.json +2 -2
  42. package/src/components/Picker/Picker.tsx +434 -34
  43. package/src/components/Picker/PickerComponent.android.tsx +44 -101
  44. package/src/components/Picker/PickerComponent.ios.tsx +63 -116
  45. package/src/components/Picker/PickerComponent.web.tsx +44 -102
  46. package/src/mappings/Picker.ts +4 -0
  47. package/src/utilities.ts +65 -1
  48. package/lib/commonjs/components/Picker/PickerTypes.js +0 -6
  49. package/lib/commonjs/components/Picker/PickerTypes.js.map +0 -1
  50. package/lib/module/components/Picker/PickerTypes.js +0 -2
  51. package/lib/module/components/Picker/PickerTypes.js.map +0 -1
  52. package/lib/typescript/src/components/Picker/PickerTypes.d.ts +0 -18
  53. package/src/Provider.js +0 -9
  54. package/src/components/Accordion/AccordionGroup.js +0 -44
  55. package/src/components/Accordion/AccordionItem.js +0 -32
  56. package/src/components/Accordion/index.js +0 -2
  57. package/src/components/ActionSheet/ActionSheet.js +0 -45
  58. package/src/components/ActionSheet/ActionSheetCancel.js +0 -6
  59. package/src/components/ActionSheet/ActionSheetItem.js +0 -30
  60. package/src/components/ActionSheet/index.js +0 -3
  61. package/src/components/AnimatedCircularProgress.js +0 -43
  62. package/src/components/AspectRatio.js +0 -18
  63. package/src/components/AvatarEdit.js +0 -30
  64. package/src/components/Banner.js +0 -109
  65. package/src/components/Button.js +0 -112
  66. package/src/components/Card.js +0 -57
  67. package/src/components/CardBlock.js +0 -54
  68. package/src/components/CardContainer.js +0 -69
  69. package/src/components/CardContainerRating.js +0 -79
  70. package/src/components/CardContainerShortImage.js +0 -33
  71. package/src/components/CardInline.js +0 -36
  72. package/src/components/Carousel.js +0 -66
  73. package/src/components/Checkbox/Checkbox.js +0 -63
  74. package/src/components/Checkbox/CheckboxGroup.js +0 -21
  75. package/src/components/Checkbox/CheckboxGroupRow.js +0 -77
  76. package/src/components/Checkbox/CheckboxRow.js +0 -78
  77. package/src/components/Checkbox/context.js +0 -14
  78. package/src/components/Checkbox/index.js +0 -3
  79. package/src/components/CircleImage.js +0 -8
  80. package/src/components/CircularProgress.js +0 -78
  81. package/src/components/Config.js +0 -63
  82. package/src/components/Container.js +0 -43
  83. package/src/components/DatePicker/DatePicker.js +0 -368
  84. package/src/components/DatePicker/DatePickerComponent.js +0 -13
  85. package/src/components/DatePicker/DatePickerComponent.web.js +0 -30
  86. package/src/components/DatePicker/DatePickerComponentType.js +0 -1
  87. package/src/components/DeprecatedButton.js +0 -95
  88. package/src/components/DeprecatedCardWrapper.js +0 -18
  89. package/src/components/DeprecatedFAB.js +0 -115
  90. package/src/components/Divider.js +0 -13
  91. package/src/components/Elevation.js +0 -20
  92. package/src/components/FAB.js +0 -46
  93. package/src/components/FieldSearchBarFull.js +0 -53
  94. package/src/components/FormRow.js +0 -19
  95. package/src/components/Header.js +0 -44
  96. package/src/components/HeaderLarge.js +0 -7
  97. package/src/components/HeaderMedium.js +0 -7
  98. package/src/components/HeaderOverline.js +0 -7
  99. package/src/components/IconButton.js +0 -35
  100. package/src/components/Image.js +0 -47
  101. package/src/components/Justification.js +0 -1
  102. package/src/components/Layout.js +0 -50
  103. package/src/components/NumberInput.js +0 -49
  104. package/src/components/Picker/Picker.js +0 -56
  105. package/src/components/Picker/PickerComponent.android.js +0 -68
  106. package/src/components/Picker/PickerComponent.ios.js +0 -78
  107. package/src/components/Picker/PickerComponent.web.js +0 -69
  108. package/src/components/Picker/PickerTypes.js +0 -1
  109. package/src/components/Picker/PickerTypes.ts +0 -18
  110. package/src/components/Portal/Portal.js +0 -35
  111. package/src/components/Portal/PortalConsumer.js +0 -28
  112. package/src/components/Portal/PortalHost.js +0 -105
  113. package/src/components/Portal/PortalManager.js +0 -29
  114. package/src/components/ProgressBar.js +0 -118
  115. package/src/components/ProgressCircle.js +0 -13
  116. package/src/components/ProgressIndicator.js +0 -27
  117. package/src/components/RadioButton/RadioButton.js +0 -17
  118. package/src/components/RadioButton/RadioButtonFieldGroup.js +0 -17
  119. package/src/components/RadioButton/RadioButtonGroup.js +0 -43
  120. package/src/components/RadioButton/RadioButtonRow.js +0 -76
  121. package/src/components/RadioButton/context.js +0 -14
  122. package/src/components/RadioButton/index.js +0 -4
  123. package/src/components/ResizeMode.js +0 -1
  124. package/src/components/Row.js +0 -48
  125. package/src/components/RowBodyIcon.js +0 -8
  126. package/src/components/RowHeadlineImageCaption.js +0 -12
  127. package/src/components/RowHeadlineImageIcon.js +0 -14
  128. package/src/components/ScreenContainer.js +0 -34
  129. package/src/components/Slider.js +0 -63
  130. package/src/components/StarRating.js +0 -50
  131. package/src/components/StepIndicator.js +0 -346
  132. package/src/components/Stepper.js +0 -39
  133. package/src/components/Surface.js +0 -32
  134. package/src/components/Swiper/Swiper.js +0 -29
  135. package/src/components/Swiper/SwiperItem.js +0 -9
  136. package/src/components/Swiper/index.js +0 -2
  137. package/src/components/Switch.js +0 -56
  138. package/src/components/Text.js +0 -28
  139. package/src/components/TextField.js +0 -420
  140. package/src/components/ToggleButton.js +0 -39
  141. package/src/components/Touchable.js +0 -12
  142. package/src/components/Touchable.web.js +0 -2
  143. package/src/components/Typography.js +0 -36
  144. package/src/components/useAuthState.js +0 -31
  145. package/src/constants.js +0 -10
  146. package/src/hooks.js +0 -12
  147. package/src/index.js +0 -52
  148. package/src/interfaces/Icon.js +0 -8
  149. package/src/mappings/Accordion.js +0 -41
  150. package/src/mappings/AccordionItem.js +0 -16
  151. package/src/mappings/ActionSheet.js +0 -13
  152. package/src/mappings/ActionSheetCancel.js +0 -19
  153. package/src/mappings/ActionSheetItem.js +0 -23
  154. package/src/mappings/ActivityIndicator.js +0 -53
  155. package/src/mappings/AudioPlayer.js +0 -20
  156. package/src/mappings/AvatarEdit.js +0 -37
  157. package/src/mappings/Banner.js +0 -32
  158. package/src/mappings/BlurView.js +0 -41
  159. package/src/mappings/Button.js +0 -56
  160. package/src/mappings/Card.js +0 -52
  161. package/src/mappings/CardBlock.js +0 -122
  162. package/src/mappings/CardContainer.js +0 -102
  163. package/src/mappings/CardContainerRating.js +0 -124
  164. package/src/mappings/CardContainerShortImage.js +0 -118
  165. package/src/mappings/CardInline.js +0 -51
  166. package/src/mappings/Carousel.js +0 -18
  167. package/src/mappings/Checkbox.js +0 -45
  168. package/src/mappings/CheckboxGroup.js +0 -25
  169. package/src/mappings/CheckboxRow.js +0 -56
  170. package/src/mappings/CircleImage.js +0 -24
  171. package/src/mappings/Container.js +0 -29
  172. package/src/mappings/CustomCode.js +0 -8
  173. package/src/mappings/DatePicker.js +0 -146
  174. package/src/mappings/Divider.js +0 -26
  175. package/src/mappings/FAB.js +0 -36
  176. package/src/mappings/Fetch.js +0 -12
  177. package/src/mappings/FieldSearchBarFull.js +0 -49
  178. package/src/mappings/FlatList.js +0 -19
  179. package/src/mappings/HeaderLarge.js +0 -28
  180. package/src/mappings/HeaderMedium.js +0 -54
  181. package/src/mappings/HeaderOverline.js +0 -54
  182. package/src/mappings/Icon.js +0 -25
  183. package/src/mappings/IconButton.js +0 -30
  184. package/src/mappings/Image.js +0 -15
  185. package/src/mappings/ImageBackground.js +0 -28
  186. package/src/mappings/KeyboardAvoidingView.js +0 -40
  187. package/src/mappings/KeyboardAwareScrollView.js +0 -49
  188. package/src/mappings/Layout.js +0 -195
  189. package/src/mappings/LinearGradient.js +0 -77
  190. package/src/mappings/MapCallout.js +0 -21
  191. package/src/mappings/MapMarker.js +0 -47
  192. package/src/mappings/MapView.js +0 -138
  193. package/src/mappings/Modal.js +0 -41
  194. package/src/mappings/Picker.js +0 -137
  195. package/src/mappings/ProgressBar.js +0 -100
  196. package/src/mappings/ProgressCircle.js +0 -108
  197. package/src/mappings/ProgressIndicator.js +0 -180
  198. package/src/mappings/RadioButton.js +0 -50
  199. package/src/mappings/RadioButtonGroup.js +0 -16
  200. package/src/mappings/RadioButtonRow.js +0 -37
  201. package/src/mappings/RowBodyIcon.js +0 -75
  202. package/src/mappings/RowHeadlineImageCaption.js +0 -167
  203. package/src/mappings/RowHeadlineImageIcon.js +0 -99
  204. package/src/mappings/SafeAreaView.js +0 -33
  205. package/src/mappings/ScrollView.js +0 -30
  206. package/src/mappings/Slider.js +0 -59
  207. package/src/mappings/StarRating.js +0 -42
  208. package/src/mappings/Stepper.js +0 -28
  209. package/src/mappings/Surface.js +0 -13
  210. package/src/mappings/Swiper.js +0 -60
  211. package/src/mappings/SwiperItem.js +0 -8
  212. package/src/mappings/Switch.js +0 -75
  213. package/src/mappings/Text.js +0 -232
  214. package/src/mappings/TextArea.js +0 -52
  215. package/src/mappings/TextField.js +0 -158
  216. package/src/mappings/TextInput.js +0 -208
  217. package/src/mappings/ToggleButton.js +0 -45
  218. package/src/mappings/Touchable.js +0 -12
  219. package/src/mappings/Video.js +0 -74
  220. package/src/mappings/View.js +0 -206
  221. package/src/mappings/WebView.js +0 -18
  222. package/src/styles/DarkTheme.js +0 -26
  223. package/src/styles/DefaultTheme.js +0 -111
  224. package/src/styles/fonts.js +0 -62
  225. package/src/styles/overlay.js +0 -60
  226. package/src/styles/shadow.js +0 -51
  227. package/src/theming.js +0 -3
  228. package/src/utilities.js +0 -54
@@ -1,31 +1,79 @@
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
+
2
15
  import { withTheme } from "../../theming";
3
- //@ts-ignore
4
- import PickerComponent from "./PickerComponent"; //unable to find file due to using .android/.web/.ios
5
- import { PickerComponentProps, PickerOption } from "./PickerTypes";
16
+ // import Portal from "../Portal/Portal";
17
+ // import Button from "../DeprecatedButton";
18
+ import Touchable from "../Touchable";
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
+ // @ts-expect-error
28
+ import { PickerComponent } from "./PickerComponent";
29
+
30
+ export interface PickerOption {
31
+ value: string;
32
+ label: string;
33
+ }
6
34
 
7
- type Props = PickerComponentProps & {
35
+ export type PickerProps = {
36
+ error?: any;
8
37
  placeholder?: string;
38
+ disabled?: boolean;
39
+ style?: StyleProp<ViewStyle> & { height?: number };
9
40
  value?: string;
10
41
  options: PickerOption[] | string[];
42
+ onValueChange: (value: string, index: number) => void;
43
+ defaultValue?: string;
44
+ assistiveText?: string;
45
+ label?: string;
46
+ iconColor?: string;
47
+ iconSize?: number;
48
+ leftIconMode?: "inset" | "outset";
49
+ leftIconName?: string;
50
+ placeholderTextColor?: string;
51
+ rightIconName?: string;
52
+ type?: "solid" | "underline";
53
+ theme: Theme;
54
+ Icon: IconSlot["Icon"];
11
55
  };
12
56
 
13
- function normalizeOptions(options: Props["options"]): PickerOption[] {
57
+ function normalizeOptions(options: PickerProps["options"]): PickerOption[] {
14
58
  if (options.length === 0) {
15
59
  return [];
16
60
  }
17
61
 
18
- if (typeof options[0] === "string") {
62
+ if (typeof options[0] === ("string" || "number")) {
19
63
  return (options as string[]).map((option) => ({
20
- label: option,
64
+ label: String(option),
21
65
  value: String(option),
22
66
  }));
23
67
  }
24
68
 
25
- if (options[0].label && options[0].value) {
26
- return options.map((option) => {
69
+ if (
70
+ isObject(options[0]) &&
71
+ options[0].value !== null &&
72
+ options[0].label !== null
73
+ ) {
74
+ return (options as PickerOption[]).map((option) => {
27
75
  return {
28
- label: option.label,
76
+ label: String(option.label),
29
77
  value: String(option.value),
30
78
  };
31
79
  });
@@ -36,18 +84,45 @@ function normalizeOptions(options: Props["options"]): PickerOption[] {
36
84
  );
37
85
  }
38
86
 
39
- const Picker: React.FC<Props> = ({
87
+ const { width: deviceWidth, height: deviceHeight } = Dimensions.get("screen");
88
+ // const isIos = Platform.OS === "ios";
89
+ const unstyledColor = "rgba(165, 173, 183, 1)";
90
+ const disabledColor = "rgb(240, 240, 240)";
91
+ const errorColor = "rgba(255, 69, 100, 1)";
92
+
93
+ const Picker: React.FC<PickerProps> = ({
94
+ error,
40
95
  options = [],
96
+ onValueChange,
97
+ defaultValue,
98
+ Icon,
99
+ style,
41
100
  placeholder,
42
- onValueChange: onValueChangeOverride,
43
101
  value,
44
- defaultValue,
45
- ...props
102
+ disabled = false,
103
+ // theme,
104
+ assistiveText,
105
+ label,
106
+ iconColor = unstyledColor,
107
+ iconSize = 24,
108
+ leftIconMode = "inset",
109
+ leftIconName,
110
+ placeholderTextColor = unstyledColor,
111
+ rightIconName,
112
+ type = "solid",
46
113
  }) => {
114
+ const androidPickerRef = React.useRef<any | undefined>(undefined);
115
+
47
116
  const [internalValue, setInternalValue] = React.useState<string | undefined>(
48
117
  value || defaultValue
49
118
  );
50
119
 
120
+ const [pickerVisible, setPickerVisible] = React.useState(false);
121
+
122
+ const togglePickerVisible = () => {
123
+ setPickerVisible(!pickerVisible);
124
+ };
125
+
51
126
  React.useEffect(() => {
52
127
  if (value != null) {
53
128
  setInternalValue(value);
@@ -60,16 +135,11 @@ const Picker: React.FC<Props> = ({
60
135
  }
61
136
  }, [defaultValue]);
62
137
 
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
- );
138
+ React.useEffect(() => {
139
+ if (pickerVisible && androidPickerRef.current) {
140
+ androidPickerRef?.current?.focus();
141
+ }
142
+ }, [pickerVisible, androidPickerRef]);
73
143
 
74
144
  const normalizedOptions = normalizeOptions(options);
75
145
 
@@ -77,22 +147,352 @@ const Picker: React.FC<Props> = ({
77
147
  ? [{ value: placeholder, label: placeholder }, ...normalizedOptions]
78
148
  : normalizedOptions;
79
149
 
150
+ // const { colors } = theme;
151
+
152
+ const { viewStyles, textStyles } = extractStyles(style);
153
+
154
+ const additionalBorderStyles = ["backgroundColor"];
155
+
156
+ const additionalMarginStyles = [
157
+ "bottom",
158
+ "height",
159
+ "left",
160
+ "maxHeight",
161
+ "maxWidth",
162
+ "minHeight",
163
+ "minWidth",
164
+ "overflow",
165
+ "position",
166
+ "right",
167
+ "top",
168
+ "width",
169
+ "zIndex",
170
+ ];
171
+
172
+ const {
173
+ borderStyles: extractedBorderStyles,
174
+ marginStyles: extractedMarginStyles,
175
+ } = extractBorderAndMarginStyles(
176
+ viewStyles,
177
+ additionalBorderStyles,
178
+ additionalMarginStyles
179
+ );
180
+
181
+ const borderStyles = {
182
+ ...{
183
+ ...(type === "solid"
184
+ ? {
185
+ borderTopLeftRadius: 5,
186
+ borderTopRightRadius: 5,
187
+ borderBottomRightRadius: 5,
188
+ borderBottomLeftRadius: 5,
189
+ borderTopWidth: 1,
190
+ borderRightWidth: 1,
191
+ borderLeftWidth: 1,
192
+ }
193
+ : {}),
194
+ borderBottomWidth: 1,
195
+ borderColor: unstyledColor,
196
+ borderStyle: "solid",
197
+ },
198
+ ...extractedBorderStyles,
199
+ ...(error ? { borderColor: errorColor } : {}),
200
+ ...(disabled
201
+ ? { borderColor: "transparent", backgroundColor: disabledColor }
202
+ : {}),
203
+ };
204
+
205
+ const marginStyles = {
206
+ height: 60,
207
+ ...extractedMarginStyles,
208
+ };
209
+
210
+ const stylesWithoutBordersAndMargins = omit(viewStyles, [
211
+ ...borderStyleNames,
212
+ ...marginStyleNames,
213
+ ...additionalBorderStyles,
214
+ ...additionalMarginStyles,
215
+ ]);
216
+
217
+ const selectedLabel =
218
+ internalValue &&
219
+ ((pickerOptions as unknown as PickerOption[]).find(
220
+ (option) => option.value === internalValue
221
+ )?.label ??
222
+ internalValue);
223
+
224
+ const labelText = label ? (
225
+ <Text
226
+ style={{
227
+ textAlign: textStyles.textAlign,
228
+ color: unstyledColor,
229
+ fontSize: 12,
230
+ paddingBottom: 4,
231
+ }}
232
+ >
233
+ {label}
234
+ </Text>
235
+ ) : null;
236
+
237
+ const leftIconOutset = leftIconMode === "outset";
238
+
239
+ const leftIcon = leftIconName ? (
240
+ <Icon
241
+ name={leftIconName}
242
+ color={disabled ? unstyledColor : iconColor}
243
+ size={iconSize}
244
+ style={{
245
+ marginRight: 4,
246
+ marginLeft: 4,
247
+ }}
248
+ />
249
+ ) : null;
250
+
251
+ const rightIcon = rightIconName ? (
252
+ <Icon
253
+ name={rightIconName}
254
+ color={disabled ? unstyledColor : iconColor}
255
+ size={iconSize}
256
+ style={{
257
+ marginRight: -10,
258
+ marginLeft: 8,
259
+ }}
260
+ />
261
+ ) : null;
262
+
263
+ const textAlign = textStyles?.textAlign;
264
+
265
+ const calculateLeftPadding = () => {
266
+ if (leftIconOutset) {
267
+ if (textAlign === "center") {
268
+ return iconSize - Math.abs(8 - iconSize);
269
+ }
270
+
271
+ return iconSize + 8;
272
+ }
273
+
274
+ return 0;
275
+ };
276
+
277
+ const assistiveTextLabel = assistiveText ? (
278
+ <Text
279
+ style={{
280
+ textAlign,
281
+ width: "100%",
282
+ paddingLeft: calculateLeftPadding(),
283
+ color: unstyledColor,
284
+ fontSize: 12,
285
+ paddingTop: 4,
286
+ }}
287
+ >
288
+ {assistiveText}
289
+ </Text>
290
+ ) : null;
291
+
292
+ const primaryTextStyle = {
293
+ color: unstyledColor,
294
+ fontSize: 14,
295
+ ...pickBy(textStyles, identity),
296
+ ...(placeholder === internalValue ? { color: placeholderTextColor } : {}),
297
+ ...(disabled ? { color: unstyledColor } : {}),
298
+ };
299
+
80
300
  const handleValueChange = (newValue: string, itemIndex: number) => {
81
- setInternalValue(newValue);
82
- if (onValueChange) {
83
- onValueChange(newValue, itemIndex);
301
+ if (!placeholder || itemIndex > 0) {
302
+ onValueChange?.(newValue, itemIndex);
84
303
  }
304
+ setInternalValue(newValue);
85
305
  };
86
306
 
87
307
  return (
88
- <PickerComponent
89
- {...props}
90
- selectedValue={String(internalValue)}
91
- placeholder={placeholder}
92
- options={pickerOptions}
93
- onValueChange={handleValueChange}
94
- />
308
+ /* marginsContainer */
309
+ <View style={[styles.marginsContainer, marginStyles]}>
310
+ {/* touchableContainer */}
311
+ <Touchable
312
+ disabled={disabled}
313
+ onPress={togglePickerVisible}
314
+ style={styles.touchableContainer}
315
+ >
316
+ {/* outsetContainer */}
317
+ <View
318
+ pointerEvents="none"
319
+ style={[
320
+ styles.outsetContainer,
321
+ stylesWithoutBordersAndMargins,
322
+ !leftIconOutset ? (borderStyles as PickerProps["style"]) : {},
323
+ ]}
324
+ >
325
+ {leftIcon}
326
+
327
+ {/* insetContainer */}
328
+ <View
329
+ style={[
330
+ styles.insetContainer,
331
+ leftIconOutset ? (borderStyles as PickerProps["style"]) : {},
332
+ ]}
333
+ >
334
+ {/* primaryTextContainer */}
335
+ <View style={styles.primaryTextContainer}>
336
+ {labelText}
337
+
338
+ <Text style={primaryTextStyle}>
339
+ {String(selectedLabel ?? placeholder)}
340
+ </Text>
341
+ </View>
342
+
343
+ {rightIcon}
344
+ </View>
345
+ </View>
346
+ {assistiveTextLabel}
347
+ </Touchable>
348
+
349
+ <View>
350
+ {pickerVisible ? (
351
+ <PickerComponent
352
+ {...{
353
+ Icon,
354
+ androidPickerRef,
355
+ togglePickerVisible,
356
+ pickerOptions,
357
+ internalValue,
358
+ handleValueChange,
359
+ }}
360
+ />
361
+ ) : null}
362
+ </View>
363
+
364
+ {/* iosPicker */}
365
+ {/* isIos && pickerVisible ? (
366
+ <Portal>
367
+ <View
368
+ style={[
369
+ styles.iosPicker,
370
+ {
371
+ backgroundColor: colors.divider,
372
+ },
373
+ ]}
374
+ >
375
+ <SafeAreaView style={styles.iosSafeArea}>
376
+ <Button
377
+ Icon={Icon}
378
+ type="text"
379
+ onPress={togglePickerVisible}
380
+ style={styles.iosButton}
381
+ >
382
+ {"Close"}
383
+ </Button>
384
+
385
+ <NativePicker
386
+ style={styles.iosNativePicker}
387
+ selectedValue={internalValue}
388
+ onValueChange={handleValueChange}
389
+ >
390
+ {(pickerOptions as unknown as PickerOption[]).map((option) => (
391
+ <NativePicker.Item
392
+ label={option.label}
393
+ value={option.value}
394
+ key={option.value}
395
+ />
396
+ ))}
397
+ </NativePicker>
398
+ </SafeAreaView>
399
+ </View>
400
+ </Portal>
401
+ ) : null */}
402
+
403
+ {/* nonIosPicker */}
404
+ {/* !isIos && pickerVisible ? (
405
+ <NativePicker
406
+ enabled={pickerVisible}
407
+ selectedValue={internalValue}
408
+ onValueChange={handleValueChange}
409
+ style={styles.nonIosPicker}
410
+ ref={androidPickerRef}
411
+ onBlur={() => setPickerVisible(false)}
412
+ >
413
+ {(pickerOptions as unknown as PickerOption[]).map((option) => (
414
+ <NativePicker.Item
415
+ label={option.label}
416
+ value={option.value}
417
+ key={option.value}
418
+ />
419
+ ))}
420
+ </NativePicker>
421
+ ) : null */}
422
+ </View>
95
423
  );
96
424
  };
97
425
 
98
426
  export default withTheme(Picker);
427
+
428
+ const styles = StyleSheet.create({
429
+ marginsContainer: {
430
+ alignSelf: "stretch",
431
+ alignItems: "center",
432
+ width: "100%",
433
+ maxWidth: deviceWidth,
434
+ },
435
+ touchableContainer: {
436
+ flex: 1,
437
+ height: "100%",
438
+ width: "100%",
439
+ alignSelf: "stretch",
440
+ alignItems: "center",
441
+ backgroundColor: "pink", // TODO
442
+ },
443
+ outsetContainer: {
444
+ flex: 1,
445
+ height: "100%",
446
+ width: "100%",
447
+ flexDirection: "row",
448
+ alignItems: "center",
449
+ justifyContent: "space-between",
450
+ },
451
+ insetContainer: {
452
+ flex: 1,
453
+ height: "100%",
454
+ width: "100%",
455
+ flexDirection: "row",
456
+ alignItems: "center",
457
+ justifyContent: "space-between",
458
+ paddingLeft: 12,
459
+ paddingRight: 12,
460
+ },
461
+ primaryTextContainer: {
462
+ flex: 1,
463
+ },
464
+ iosPicker: {
465
+ position: "absolute",
466
+ bottom: 0,
467
+ left: 0,
468
+ right: 0,
469
+ flexDirection: "row",
470
+ justifyContent: "center",
471
+ width: "100%",
472
+ maxWidth: deviceWidth,
473
+ maxHeight: deviceHeight,
474
+ },
475
+ iosSafeArea: {
476
+ backgroundColor: "white",
477
+ flexDirection: "column",
478
+ width: "100%",
479
+ maxWidth: deviceWidth,
480
+ },
481
+ iosButton: {
482
+ alignSelf: "flex-end",
483
+ },
484
+ iosNativePicker: {
485
+ backgroundColor: "white",
486
+ },
487
+ nonIosPicker: {
488
+ opacity: 0,
489
+ position: "absolute",
490
+ top: 0,
491
+ left: 0,
492
+ right: 0,
493
+ bottom: 0,
494
+ width: "100%",
495
+ maxWidth: deviceWidth,
496
+ maxHeight: deviceHeight,
497
+ },
498
+ });
@@ -1,116 +1,59 @@
1
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);
2
+ import { StyleSheet, Dimensions } from "react-native";
39
3
 
40
- const textField = React.useRef<typeof TextField | undefined>(undefined);
4
+ import { Picker as NativePicker } from "@react-native-picker/picker";
41
5
 
42
- const onValueChange = (itemValue: string, itemIndex: number) => {
43
- toggleFocus();
44
- onValueChangeOverride(itemValue, itemIndex);
45
- };
6
+ import type { IconSlot } from "../../interfaces/Icon";
46
7
 
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
- };
8
+ import { PickerOption } from "./Picker";
53
9
 
54
- const stylesWithoutMargin =
55
- style &&
56
- omit(StyleSheet.flatten(style), [
57
- "margin",
58
- "marginTop",
59
- "marginRight",
60
- "marginBottom",
61
- "marginLeft",
62
- ]);
10
+ const { width: deviceWidth, height: deviceHeight } = Dimensions.get("screen");
63
11
 
64
- const selectedLabel =
65
- selectedValue &&
66
- (options.find((o) => o.value === selectedValue)?.label ?? selectedValue);
12
+ interface PickerComponentProps {
13
+ Icon: IconSlot["Icon"];
14
+ androidPickerRef: React.RefObject<any>;
15
+ togglePickerVisible: () => void;
16
+ pickerOptions: PickerOption[];
17
+ internalValue: string | undefined;
18
+ handleValueChange: (newValue: string, itemIndex: number) => void;
19
+ }
67
20
 
21
+ export const PickerComponent: React.FC<PickerComponentProps> = ({
22
+ androidPickerRef,
23
+ togglePickerVisible,
24
+ pickerOptions,
25
+ internalValue,
26
+ handleValueChange,
27
+ }) => {
68
28
  return (
69
- <Touchable
70
- disabled={disabled}
71
- onPress={toggleFocus}
72
- style={[styles.container, viewStyles]}
29
+ <NativePicker
30
+ selectedValue={internalValue}
31
+ onValueChange={handleValueChange}
32
+ style={styles.nonIosPicker}
33
+ ref={androidPickerRef}
34
+ onBlur={togglePickerVisible}
73
35
  >
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>
36
+ {(pickerOptions as unknown as PickerOption[]).map((option) => (
37
+ <NativePicker.Item
38
+ label={option.label}
39
+ value={option.value}
40
+ key={option.value}
41
+ />
42
+ ))}
43
+ </NativePicker>
107
44
  );
108
45
  };
109
46
 
110
47
  const styles = StyleSheet.create({
111
- container: {
112
- alignSelf: "stretch",
48
+ nonIosPicker: {
49
+ opacity: 0,
50
+ position: "absolute",
51
+ top: 0,
52
+ left: 0,
53
+ right: 0,
54
+ bottom: 0,
55
+ width: "100%",
56
+ maxWidth: deviceWidth,
57
+ maxHeight: deviceHeight,
113
58
  },
114
59
  });
115
-
116
- export default withTheme(Picker);