@draftbit/core 46.1.4-e6469c.0 → 46.2.1-435444.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/lib/commonjs/components/ActionSheet/index.js.map +1 -1
  2. package/lib/commonjs/components/CardContainer.js +16 -5
  3. package/lib/commonjs/components/CardContainer.js.map +1 -1
  4. package/lib/commonjs/components/Carousel.js +3 -1
  5. package/lib/commonjs/components/Carousel.js.map +1 -1
  6. package/lib/commonjs/components/Config.js +3 -3
  7. package/lib/commonjs/components/Config.js.map +1 -1
  8. package/lib/commonjs/components/DatePicker/DatePicker.js +3 -3
  9. package/lib/commonjs/components/DatePicker/DatePicker.js.map +1 -1
  10. package/lib/commonjs/components/DatePicker/DatePickerComponentType.js.map +1 -1
  11. package/lib/commonjs/components/DeprecatedCardWrapper.js +2 -14
  12. package/lib/commonjs/components/DeprecatedCardWrapper.js.map +1 -1
  13. package/lib/commonjs/components/Picker/Picker.js +4 -5
  14. package/lib/commonjs/components/Picker/Picker.js.map +1 -1
  15. package/lib/commonjs/components/Picker/PickerComponent.android.js +135 -0
  16. package/lib/commonjs/components/Picker/PickerComponent.android.js.map +1 -0
  17. package/lib/commonjs/components/Picker/PickerComponent.ios.js +161 -0
  18. package/lib/commonjs/components/Picker/PickerComponent.ios.js.map +1 -0
  19. package/lib/commonjs/components/Picker/PickerComponent.web.js +136 -0
  20. package/lib/commonjs/components/Picker/PickerComponent.web.js.map +1 -0
  21. package/lib/commonjs/components/Picker/PickerTypes.js +6 -0
  22. package/lib/commonjs/components/Picker/PickerTypes.js.map +1 -0
  23. package/lib/commonjs/components/RadioButton/RadioButton.js +1 -1
  24. package/lib/commonjs/components/RadioButton/RadioButton.js.map +1 -1
  25. package/lib/commonjs/components/RadioButton/RadioButtonRow.js +1 -1
  26. package/lib/commonjs/components/RadioButton/RadioButtonRow.js.map +1 -1
  27. package/lib/commonjs/components/StepIndicator.js +1 -1
  28. package/lib/commonjs/components/StepIndicator.js.map +1 -1
  29. package/lib/commonjs/components/Stepper.js +1 -1
  30. package/lib/commonjs/components/Stepper.js.map +1 -1
  31. package/lib/commonjs/mappings/NumberInput.js +241 -0
  32. package/lib/commonjs/mappings/NumberInput.js.map +1 -0
  33. package/lib/commonjs/mappings/RadioButton.js.map +1 -1
  34. package/lib/commonjs/mappings/RadioButtonGroup.js.map +1 -1
  35. package/lib/commonjs/mappings/RadioButtonRow.js.map +1 -1
  36. package/lib/commonjs/mappings/Text.js +33 -26
  37. package/lib/commonjs/mappings/Text.js.map +1 -1
  38. package/lib/commonjs/mappings/TextArea.js +181 -2
  39. package/lib/commonjs/mappings/TextArea.js.map +1 -1
  40. package/lib/commonjs/mappings/TextField.js +191 -2
  41. package/lib/commonjs/mappings/TextField.js.map +1 -1
  42. package/lib/commonjs/mappings/TextInput.js +180 -29
  43. package/lib/commonjs/mappings/TextInput.js.map +1 -1
  44. package/lib/commonjs/utilities.js +1 -1
  45. package/lib/commonjs/utilities.js.map +1 -1
  46. package/lib/module/components/Carousel.js +3 -1
  47. package/lib/module/components/Carousel.js.map +1 -1
  48. package/lib/module/components/Config.js +3 -3
  49. package/lib/module/components/Config.js.map +1 -1
  50. package/lib/module/components/Container.js +17 -5
  51. package/lib/module/components/Container.js.map +1 -1
  52. package/lib/module/components/DatePicker/DatePicker.js +3 -3
  53. package/lib/module/components/DatePicker/DatePicker.js.map +1 -1
  54. package/lib/module/components/HeaderLarge.js.map +1 -1
  55. package/lib/module/components/HeaderMedium.js.map +1 -1
  56. package/lib/module/components/Picker/Picker.js +4 -5
  57. package/lib/module/components/Picker/Picker.js.map +1 -1
  58. package/lib/module/components/Picker/PickerComponent.android.js +112 -0
  59. package/lib/module/components/Picker/PickerComponent.android.js.map +1 -0
  60. package/lib/module/components/Picker/PickerComponent.ios.js +135 -0
  61. package/lib/module/components/Picker/PickerComponent.ios.js.map +1 -0
  62. package/lib/module/components/Picker/PickerComponent.web.js +113 -0
  63. package/lib/module/components/Picker/PickerComponent.web.js.map +1 -0
  64. package/lib/module/components/Picker/PickerTypes.js +2 -0
  65. package/lib/module/components/Picker/PickerTypes.js.map +1 -0
  66. package/lib/module/components/RadioButton/RadioButton.js +1 -1
  67. package/lib/module/components/RadioButton/RadioButton.js.map +1 -1
  68. package/lib/module/components/RadioButton/RadioButtonRow.js +1 -1
  69. package/lib/module/components/RadioButton/RadioButtonRow.js.map +1 -1
  70. package/lib/module/components/StepIndicator.js +1 -1
  71. package/lib/module/components/StepIndicator.js.map +1 -1
  72. package/lib/module/components/Stepper.js +1 -1
  73. package/lib/module/components/Stepper.js.map +1 -1
  74. package/lib/module/components/Touchable.js +2 -16
  75. package/lib/module/components/Touchable.js.map +1 -1
  76. package/lib/module/mappings/NumberInput.js +231 -0
  77. package/lib/module/mappings/NumberInput.js.map +1 -0
  78. package/lib/module/mappings/Text.js +33 -26
  79. package/lib/module/mappings/Text.js.map +1 -1
  80. package/lib/module/mappings/TextArea.js +182 -3
  81. package/lib/module/mappings/TextArea.js.map +1 -1
  82. package/lib/module/mappings/TextField.js +192 -3
  83. package/lib/module/mappings/TextField.js.map +1 -1
  84. package/lib/module/mappings/TextInput.js +180 -29
  85. package/lib/module/mappings/TextInput.js.map +1 -1
  86. package/lib/module/utilities.js +1 -1
  87. package/lib/module/utilities.js.map +1 -1
  88. package/lib/typescript/src/components/Picker/PickerComponent.android.d.ts +6 -0
  89. package/lib/typescript/src/components/Picker/PickerComponent.ios.d.ts +7 -0
  90. package/lib/typescript/src/components/Picker/PickerComponent.web.d.ts +6 -0
  91. package/lib/typescript/src/components/Picker/PickerTypes.d.ts +18 -0
  92. package/lib/typescript/src/mappings/NumberInput.d.ts +297 -0
  93. package/lib/typescript/src/mappings/Text.d.ts +24 -10
  94. package/lib/typescript/src/mappings/TextArea.d.ts +1 -11
  95. package/lib/typescript/src/mappings/TextField.d.ts +4 -4
  96. package/lib/typescript/src/mappings/TextInput.d.ts +3 -254
  97. package/package.json +3 -3
  98. package/src/components/ActionSheet/ActionSheet.js +1 -1
  99. package/src/components/Carousel.js +4 -2
  100. package/src/components/Checkbox/Checkbox.js +3 -3
  101. package/src/components/Checkbox/CheckboxGroupRow.js +2 -2
  102. package/src/components/Checkbox/CheckboxRow.js +3 -3
  103. package/src/components/CircularProgress.js +29 -26
  104. package/src/components/DatePicker/DatePicker.js +1 -1
  105. package/src/components/NumberInput.js +1 -1
  106. package/src/components/Picker/Picker.js +8 -8
  107. package/src/components/Picker/Picker.tsx +8 -6
  108. package/src/components/Picker/PickerComponent.android.js +69 -0
  109. package/src/components/Picker/PickerComponent.android.tsx +116 -0
  110. package/src/components/Picker/PickerComponent.ios.js +79 -0
  111. package/src/components/Picker/PickerComponent.ios.tsx +142 -0
  112. package/src/components/Picker/PickerComponent.web.js +70 -0
  113. package/src/components/Picker/PickerComponent.web.tsx +117 -0
  114. package/src/components/Picker/PickerTypes.js +1 -0
  115. package/src/components/Picker/PickerTypes.ts +18 -0
  116. package/src/components/Portal/Portal.js +2 -2
  117. package/src/components/Portal/PortalConsumer.js +0 -1
  118. package/src/components/Portal/PortalHost.js +43 -41
  119. package/src/components/Portal/PortalManager.js +21 -18
  120. package/src/components/ProgressBar.js +9 -9
  121. package/src/components/RadioButton/RadioButton.js +3 -3
  122. package/src/components/RadioButton/RadioButtonGroup.js +1 -1
  123. package/src/components/RadioButton/RadioButtonRow.js +3 -3
  124. package/src/components/StepIndicator.js +225 -225
  125. package/src/components/Stepper.js +2 -2
  126. package/src/components/Text.js +0 -1
  127. package/src/components/TextField.js +62 -59
  128. package/src/constants.js +1 -1
  129. package/src/mappings/NumberInput.js +248 -0
  130. package/src/mappings/NumberInput.ts +267 -0
  131. package/src/mappings/Text.js +33 -26
  132. package/src/mappings/Text.ts +34 -27
  133. package/src/mappings/TextArea.js +210 -3
  134. package/src/mappings/TextArea.ts +216 -3
  135. package/src/mappings/TextField.js +220 -3
  136. package/src/mappings/TextField.ts +227 -3
  137. package/src/mappings/TextInput.js +208 -31
  138. package/src/mappings/TextInput.ts +214 -34
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@draftbit/core",
3
- "version": "46.1.4-e6469c.0+e6469ca2",
3
+ "version": "46.2.1-435444.1+435444b0",
4
4
  "description": "Core (non-native) Components",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
@@ -41,7 +41,7 @@
41
41
  "dependencies": {
42
42
  "@date-io/date-fns": "^1.3.13",
43
43
  "@draftbit/react-theme-provider": "^2.1.1",
44
- "@draftbit/types": "^46.1.1",
44
+ "@draftbit/types": "^46.1.4",
45
45
  "@material-ui/core": "^4.11.0",
46
46
  "@material-ui/pickers": "^3.2.10",
47
47
  "@react-native-community/slider": "4.2.3",
@@ -79,5 +79,5 @@
79
79
  ]
80
80
  ]
81
81
  },
82
- "gitHead": "e6469ca2737c7bb1742ee5f5897d212003e00cdd"
82
+ "gitHead": "435444b067e0ee2566cc321ee7b5ceec8149ce59"
83
83
  }
@@ -8,7 +8,7 @@ const ActionSheet = ({ visible = false, onClose, children }) => {
8
8
  React.createElement(Touchable, { style: styles.wrapper, onPress: onClose },
9
9
  React.createElement(View, { style: styles.overlay }),
10
10
  React.createElement(View, { style: styles.groupWrapper },
11
- React.createElement(View, { style: styles.group }, React.Children.toArray(children).filter((child) => child?.type !== ActionSheetCancel)),
11
+ React.createElement(View, { style: styles.group }, React.Children.toArray(children).filter((child) => (child === null || child === void 0 ? void 0 : child.type) !== ActionSheetCancel)),
12
12
  React.createElement(View, { style: styles.group }, React.Children.toArray(children).filter((child) => child.type === ActionSheetCancel)))))) : (React.createElement(React.Fragment, null));
13
13
  };
14
14
  const styles = StyleSheet.create({
@@ -15,9 +15,10 @@ function Pager({ color, index, length, }) {
15
15
  })));
16
16
  }
17
17
  function Carousel({ data, children, dotColor = "strong", style, ...rest }) {
18
+ var _a;
18
19
  const [index, setIndex] = React.useState(0);
19
20
  const length = React.Children.count(children);
20
- const itemsLength = (data?.length ?? 0) + length;
21
+ const itemsLength = ((_a = data === null || data === void 0 ? void 0 : data.length) !== null && _a !== void 0 ? _a : 0) + length;
21
22
  const slides = Array.isArray(data) ? data : [];
22
23
  const { width, height } = StyleSheet.flatten(style || {});
23
24
  const slideWidth = width || screenWidth;
@@ -35,7 +36,8 @@ function Carousel({ data, children, dotColor = "strong", style, ...rest }) {
35
36
  })
36
37
  : null,
37
38
  React.Children.map(children, (child) => {
38
- const s = child?.props?.style || {};
39
+ var _a;
40
+ const s = ((_a = child === null || child === void 0 ? void 0 : child.props) === null || _a === void 0 ? void 0 : _a.style) || {};
39
41
  return (React.createElement(View, { style: { width: slideWidth } }, React.cloneElement(child, {
40
42
  style: { ...s, width: slideWidth },
41
43
  })));
@@ -25,12 +25,12 @@ const Checkbox = ({ Icon, status, disabled = false, onPress, onCheck, onUncheck,
25
25
  const handlePress = () => {
26
26
  const newValue = !internalValue;
27
27
  setInternalValue(newValue);
28
- onPress?.(newValue);
28
+ onPress === null || onPress === void 0 ? void 0 : onPress(newValue);
29
29
  if (newValue) {
30
- onCheck?.();
30
+ onCheck === null || onCheck === void 0 ? void 0 : onCheck();
31
31
  }
32
32
  if (!newValue) {
33
- onUncheck?.();
33
+ onUncheck === null || onUncheck === void 0 ? void 0 : onUncheck();
34
34
  }
35
35
  };
36
36
  return (React.createElement(Touchable, { ...rest, onPress: handlePress, disabled: disabled, accessibilityState: { disabled }, accessibilityRole: "button", accessibilityLiveRegion: "polite", style: [styles.container, style, { width: size, height: size }] },
@@ -36,8 +36,8 @@ const CheckboxGroupRow = ({ Icon, label = "Label", status, value, onPress, label
36
36
  const isChecked = status || values.includes(value);
37
37
  const handlePress = () => {
38
38
  if (!disabled) {
39
- onPress?.(!isChecked);
40
- onValueChange?.(value, !isChecked);
39
+ onPress === null || onPress === void 0 ? void 0 : onPress(!isChecked);
40
+ onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(value, !isChecked);
41
41
  }
42
42
  };
43
43
  const { textStyles, viewStyles } = extractStyles(style);
@@ -37,12 +37,12 @@ const CheckboxRow = ({ label = "Label", labelStyle, labelContainerStyle, checkbo
37
37
  const handlePress = () => {
38
38
  const newValue = !internalValue;
39
39
  setInternalValue(newValue);
40
- onPress?.(newValue);
40
+ onPress === null || onPress === void 0 ? void 0 : onPress(newValue);
41
41
  if (newValue) {
42
- onCheck?.();
42
+ onCheck === null || onCheck === void 0 ? void 0 : onCheck();
43
43
  }
44
44
  if (!newValue) {
45
- onUncheck?.();
45
+ onUncheck === null || onUncheck === void 0 ? void 0 : onUncheck();
46
46
  }
47
47
  };
48
48
  const { textStyles, viewStyles } = extractStyles(style);
@@ -2,33 +2,36 @@ import React from "react";
2
2
  import { View } from "react-native";
3
3
  import { Svg, Path, G } from "react-native-svg";
4
4
  class CircularProgress extends React.Component {
5
- polarToCartesian = (centerX, centerY, radius, angleInDegrees) => {
6
- var angleInRadians = ((angleInDegrees - 90) * Math.PI) / 180.0;
7
- return {
8
- x: centerX + radius * Math.cos(angleInRadians),
9
- y: centerY + radius * Math.sin(angleInRadians),
5
+ constructor() {
6
+ super(...arguments);
7
+ this.polarToCartesian = (centerX, centerY, radius, angleInDegrees) => {
8
+ var angleInRadians = ((angleInDegrees - 90) * Math.PI) / 180.0;
9
+ return {
10
+ x: centerX + radius * Math.cos(angleInRadians),
11
+ y: centerY + radius * Math.sin(angleInRadians),
12
+ };
10
13
  };
11
- };
12
- circlePath = (x, y, radius, startAngle, endAngle) => {
13
- var start = this.polarToCartesian(x, y, radius, endAngle * 0.9999);
14
- var end = this.polarToCartesian(x, y, radius, startAngle);
15
- var largeArcFlag = endAngle - startAngle <= 180 ? "0" : "1";
16
- var d = [
17
- "M",
18
- start.x,
19
- start.y,
20
- "A",
21
- radius,
22
- radius,
23
- 0,
24
- largeArcFlag,
25
- 0,
26
- end.x,
27
- end.y,
28
- ];
29
- return d.join(" ");
30
- };
31
- clampFill = (fill) => Math.min(100, Math.max(0, fill));
14
+ this.circlePath = (x, y, radius, startAngle, endAngle) => {
15
+ var start = this.polarToCartesian(x, y, radius, endAngle * 0.9999);
16
+ var end = this.polarToCartesian(x, y, radius, startAngle);
17
+ var largeArcFlag = endAngle - startAngle <= 180 ? "0" : "1";
18
+ var d = [
19
+ "M",
20
+ start.x,
21
+ start.y,
22
+ "A",
23
+ radius,
24
+ radius,
25
+ 0,
26
+ largeArcFlag,
27
+ 0,
28
+ end.x,
29
+ end.y,
30
+ ];
31
+ return d.join(" ");
32
+ };
33
+ this.clampFill = (fill) => Math.min(100, Math.max(0, fill));
34
+ }
32
35
  render() {
33
36
  const { size, width, backgroundWidth, tintColor = "black", tintTransparency = true, backgroundColor, style, rotation = 90, lineCap = "butt", arcSweepAngle = 360, fill, children, childrenContainerStyle, padding = 0, renderCap, dashedBackground = { width: 0, gap: 0 }, dashedTint = { width: 0, gap: 0 }, } = this.props;
34
37
  const maxWidthCircle = backgroundWidth
@@ -40,7 +40,7 @@ const DatePicker = ({ Icon, style, theme: { colors, typography, roundness, disab
40
40
  if (!value) {
41
41
  return new Date();
42
42
  }
43
- return typeof value?.getMonth === "function" ? value : new Date();
43
+ return typeof (value === null || value === void 0 ? void 0 : value.getMonth) === "function" ? value : new Date();
44
44
  };
45
45
  const formatDate = () => {
46
46
  if (!value)
@@ -34,7 +34,7 @@ const NumberInput = ({ onChangeText, value, defaultValue, ...props }) => {
34
34
  const newStringNumberValue = formatValueToStringNumber(newValue);
35
35
  const number = parseFloat(newStringNumberValue);
36
36
  setCurrentStringNumberValue(newStringNumberValue);
37
- onChangeText?.(number);
37
+ onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(number);
38
38
  };
39
39
  // run handleChangeText with value prop only when value prop changes (and first render to reset currentStringNumberValue)
40
40
  useEffect(() => {
@@ -36,6 +36,7 @@ const unstyledColor = "rgba(165, 173, 183, 1)";
36
36
  const disabledColor = "rgb(240, 240, 240)";
37
37
  const errorColor = "rgba(255, 69, 100, 1)";
38
38
  const Picker = ({ error, options = [], onValueChange, defaultValue, Icon, style, placeholder, value, disabled = false, theme, assistiveText, label, iconColor = unstyledColor, iconSize = 24, leftIconMode = "inset", leftIconName, placeholderTextColor = unstyledColor, rightIconName, type = "solid", }) => {
39
+ var _a, _b;
39
40
  const androidPickerRef = React.useRef(undefined);
40
41
  const [internalValue, setInternalValue] = React.useState(value || defaultValue);
41
42
  const [pickerVisible, setPickerVisible] = React.useState(false);
@@ -53,8 +54,9 @@ const Picker = ({ error, options = [], onValueChange, defaultValue, Icon, style,
53
54
  }
54
55
  }, [defaultValue]);
55
56
  React.useEffect(() => {
57
+ var _a;
56
58
  if (pickerVisible && androidPickerRef.current) {
57
- androidPickerRef?.current?.focus();
59
+ (_a = androidPickerRef === null || androidPickerRef === void 0 ? void 0 : androidPickerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
58
60
  }
59
61
  }, [pickerVisible, androidPickerRef]);
60
62
  const normalizedOptions = normalizeOptions(options);
@@ -113,10 +115,8 @@ const Picker = ({ error, options = [], onValueChange, defaultValue, Icon, style,
113
115
  ...additionalBorderStyles,
114
116
  ...additionalMarginStyles,
115
117
  ]);
116
- const optionExists = internalValue
117
- ? pickerOptions.find((option) => option.value === internalValue)
118
- : { label: null };
119
- const selectedLabel = optionExists && optionExists.label ? optionExists.label : placeholder;
118
+ const selectedLabel = internalValue &&
119
+ ((_b = (_a = pickerOptions.find((option) => option.value === internalValue)) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : internalValue);
120
120
  const labelText = label ? (React.createElement(Text, { style: {
121
121
  textAlign: textStyles.textAlign,
122
122
  color: unstyledColor,
@@ -132,7 +132,7 @@ const Picker = ({ error, options = [], onValueChange, defaultValue, Icon, style,
132
132
  marginRight: -10,
133
133
  marginLeft: 8,
134
134
  } })) : null;
135
- const textAlign = textStyles?.textAlign;
135
+ const textAlign = textStyles === null || textStyles === void 0 ? void 0 : textStyles.textAlign;
136
136
  const calculateLeftPadding = () => {
137
137
  if (leftIconOutset) {
138
138
  if (textAlign === "center") {
@@ -159,7 +159,7 @@ const Picker = ({ error, options = [], onValueChange, defaultValue, Icon, style,
159
159
  };
160
160
  const handleValueChange = (newValue, itemIndex) => {
161
161
  if (!placeholder || itemIndex > 0) {
162
- onValueChange?.(newValue, itemIndex);
162
+ onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(newValue, itemIndex);
163
163
  }
164
164
  setInternalValue(newValue);
165
165
  };
@@ -179,7 +179,7 @@ const Picker = ({ error, options = [], onValueChange, defaultValue, Icon, style,
179
179
  ] },
180
180
  React.createElement(View, { style: styles.primaryTextContainer },
181
181
  labelText,
182
- React.createElement(Text, { style: primaryTextStyle }, String(selectedLabel))),
182
+ React.createElement(Text, { style: primaryTextStyle }, String(selectedLabel !== null && selectedLabel !== void 0 ? selectedLabel : placeholder))),
183
183
  rightIcon)),
184
184
  assistiveTextLabel),
185
185
  isIos && pickerVisible ? (React.createElement(Portal, null,
@@ -212,12 +212,12 @@ const Picker: React.FC<PickerProps> = ({
212
212
  ...additionalMarginStyles,
213
213
  ]);
214
214
 
215
- const optionExists = internalValue
216
- ? pickerOptions.find((option) => option.value === internalValue)
217
- : { label: null };
218
-
219
215
  const selectedLabel =
220
- optionExists && optionExists.label ? optionExists.label : placeholder;
216
+ internalValue &&
217
+ ((pickerOptions as unknown as PickerOption[]).find(
218
+ (option) => option.value === internalValue
219
+ )?.label ??
220
+ internalValue);
221
221
 
222
222
  const labelText = label ? (
223
223
  <Text
@@ -333,7 +333,9 @@ const Picker: React.FC<PickerProps> = ({
333
333
  <View style={styles.primaryTextContainer}>
334
334
  {labelText}
335
335
 
336
- <Text style={primaryTextStyle}>{String(selectedLabel)}</Text>
336
+ <Text style={primaryTextStyle}>
337
+ {String(selectedLabel ?? placeholder)}
338
+ </Text>
337
339
  </View>
338
340
 
339
341
  {rightIcon}
@@ -0,0 +1,69 @@
1
+ import * as React from "react";
2
+ import { View, StyleSheet } from "react-native";
3
+ import omit from "lodash.omit";
4
+ import { withTheme } from "../../theming";
5
+ import { Picker as NativePicker } from "@react-native-picker/picker";
6
+ import { extractStyles } from "../../utilities";
7
+ import TextField from "../TextField";
8
+ import Touchable from "../Touchable";
9
+ const Picker = ({ style, options, placeholder, selectedValue, disabled = false, onValueChange: onValueChangeOverride = () => { }, ...props }) => {
10
+ var _a, _b;
11
+ const { viewStyles: { borderRadius, // eslint-disable-line @typescript-eslint/no-unused-vars
12
+ borderWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
13
+ borderTopWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
14
+ borderRightWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
15
+ borderBottomWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
16
+ borderLeftWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
17
+ borderColor, // eslint-disable-line @typescript-eslint/no-unused-vars
18
+ backgroundColor, // eslint-disable-line @typescript-eslint/no-unused-vars
19
+ padding, // eslint-disable-line @typescript-eslint/no-unused-vars
20
+ paddingTop, // eslint-disable-line @typescript-eslint/no-unused-vars
21
+ paddingRight, // eslint-disable-line @typescript-eslint/no-unused-vars
22
+ paddingBottom, // eslint-disable-line @typescript-eslint/no-unused-vars
23
+ paddingLeft, // eslint-disable-line @typescript-eslint/no-unused-vars
24
+ ...viewStyles }, } = extractStyles(style);
25
+ const textField = React.useRef(undefined);
26
+ const onValueChange = (itemValue, itemIndex) => {
27
+ toggleFocus();
28
+ onValueChangeOverride(itemValue, itemIndex);
29
+ };
30
+ const toggleFocus = () => {
31
+ if (!disabled) {
32
+ // @ts-ignore
33
+ textField.current.toggleFocus(); // cannot determine if method exists due to component being wrapped in a withTheme()
34
+ }
35
+ };
36
+ const stylesWithoutMargin = style &&
37
+ omit(StyleSheet.flatten(style), [
38
+ "margin",
39
+ "marginTop",
40
+ "marginRight",
41
+ "marginBottom",
42
+ "marginLeft",
43
+ ]);
44
+ const selectedLabel = selectedValue &&
45
+ ((_b = (_a = options.find((o) => o.value === selectedValue)) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : selectedValue);
46
+ return (React.createElement(Touchable, { disabled: disabled, onPress: toggleFocus, style: [styles.container, viewStyles] },
47
+ React.createElement(View, null,
48
+ React.createElement(NativePicker, { enabled: !disabled, selectedValue: selectedValue, onValueChange: onValueChange, style: {
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);
@@ -0,0 +1,116 @@
1
+ import * as React from "react";
2
+ import { View, StyleSheet } from "react-native";
3
+ import omit from "lodash.omit";
4
+ import { withTheme } from "../../theming";
5
+ import { Picker as NativePicker } from "@react-native-picker/picker";
6
+ import { extractStyles } from "../../utilities";
7
+
8
+ import TextField from "../TextField";
9
+ import Touchable from "../Touchable";
10
+ import { PickerComponentProps } from "./PickerTypes";
11
+
12
+ const Picker: React.FC<PickerComponentProps> = ({
13
+ style,
14
+ options,
15
+ placeholder,
16
+ selectedValue,
17
+ disabled = false,
18
+ onValueChange: onValueChangeOverride = () => {},
19
+ ...props
20
+ }) => {
21
+ const {
22
+ viewStyles: {
23
+ borderRadius, // eslint-disable-line @typescript-eslint/no-unused-vars
24
+ borderWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
25
+ borderTopWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
26
+ borderRightWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
27
+ borderBottomWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
28
+ borderLeftWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
29
+ borderColor, // eslint-disable-line @typescript-eslint/no-unused-vars
30
+ backgroundColor, // eslint-disable-line @typescript-eslint/no-unused-vars
31
+ padding, // eslint-disable-line @typescript-eslint/no-unused-vars
32
+ paddingTop, // eslint-disable-line @typescript-eslint/no-unused-vars
33
+ paddingRight, // eslint-disable-line @typescript-eslint/no-unused-vars
34
+ paddingBottom, // eslint-disable-line @typescript-eslint/no-unused-vars
35
+ paddingLeft, // eslint-disable-line @typescript-eslint/no-unused-vars
36
+ ...viewStyles
37
+ },
38
+ } = extractStyles(style);
39
+
40
+ const textField = React.useRef<typeof TextField | undefined>(undefined);
41
+
42
+ const onValueChange = (itemValue: string, itemIndex: number) => {
43
+ toggleFocus();
44
+ onValueChangeOverride(itemValue, itemIndex);
45
+ };
46
+
47
+ const toggleFocus = () => {
48
+ if (!disabled) {
49
+ // @ts-ignore
50
+ textField.current.toggleFocus(); // cannot determine if method exists due to component being wrapped in a withTheme()
51
+ }
52
+ };
53
+
54
+ const stylesWithoutMargin =
55
+ style &&
56
+ omit(StyleSheet.flatten(style), [
57
+ "margin",
58
+ "marginTop",
59
+ "marginRight",
60
+ "marginBottom",
61
+ "marginLeft",
62
+ ]);
63
+
64
+ const selectedLabel =
65
+ selectedValue &&
66
+ (options.find((o) => o.value === selectedValue)?.label ?? selectedValue);
67
+
68
+ return (
69
+ <Touchable
70
+ disabled={disabled}
71
+ onPress={toggleFocus}
72
+ style={[styles.container, viewStyles]}
73
+ >
74
+ <View>
75
+ <NativePicker
76
+ enabled={!disabled}
77
+ selectedValue={selectedValue}
78
+ onValueChange={onValueChange}
79
+ style={{
80
+ opacity: 0,
81
+ position: "absolute",
82
+ top: 0,
83
+ left: 0,
84
+ right: 0,
85
+ bottom: 0,
86
+ width: "100%",
87
+ }}
88
+ >
89
+ {options.map((o) => (
90
+ <NativePicker.Item label={o.label} value={o.value} key={o.value} />
91
+ ))}
92
+ </NativePicker>
93
+ <View pointerEvents="none">
94
+ <TextField
95
+ {...props}
96
+ value={selectedLabel}
97
+ placeholder={placeholder}
98
+ // @ts-ignore
99
+ ref={textField} // cannot determine if ref is of correct type due to component being wrapped in a withTheme()
100
+ disabled={disabled}
101
+ // @ts-expect-error
102
+ style={stylesWithoutMargin}
103
+ />
104
+ </View>
105
+ </View>
106
+ </Touchable>
107
+ );
108
+ };
109
+
110
+ const styles = StyleSheet.create({
111
+ container: {
112
+ alignSelf: "stretch",
113
+ },
114
+ });
115
+
116
+ export default withTheme(Picker);
@@ -0,0 +1,79 @@
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
+ var _a, _b;
14
+ const { viewStyles: { borderRadius, // eslint-disable-line @typescript-eslint/no-unused-vars
15
+ borderWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
16
+ borderTopWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
17
+ borderRightWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
18
+ borderBottomWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
19
+ borderLeftWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
20
+ borderColor, // eslint-disable-line @typescript-eslint/no-unused-vars
21
+ backgroundColor, // eslint-disable-line @typescript-eslint/no-unused-vars
22
+ padding, // eslint-disable-line @typescript-eslint/no-unused-vars
23
+ paddingTop, // eslint-disable-line @typescript-eslint/no-unused-vars
24
+ paddingRight, // eslint-disable-line @typescript-eslint/no-unused-vars
25
+ paddingBottom, // eslint-disable-line @typescript-eslint/no-unused-vars
26
+ paddingLeft, // eslint-disable-line @typescript-eslint/no-unused-vars
27
+ ...viewStyles }, } = extractStyles(style);
28
+ const textField = React.useRef(undefined);
29
+ const [pickerVisible, setIsPickerVisible] = React.useState(false);
30
+ const toggleVisibility = () => {
31
+ setIsPickerVisible(!pickerVisible);
32
+ // @ts-ignore
33
+ textField.current.toggleFocus(); // cannot determine if method exists due to component being wrapped in a withTheme()
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
+ ((_b = (_a = options.find((o) => o.value === selectedValue)) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : selectedValue);
45
+ return (React.createElement(View, { style: [styles.container, viewStyles] },
46
+ React.createElement(Touchable, { disabled: disabled, onPress: toggleVisibility },
47
+ React.createElement(TextField, { ...props, value: String(selectedLabel), placeholder: placeholder,
48
+ // @ts-ignore
49
+ ref: textField, disabled: disabled, pointerEvents: "none",
50
+ // @ts-expect-error
51
+ style: stylesWithoutMargin, Icon: Icon })),
52
+ pickerVisible && (React.createElement(Portal, null,
53
+ React.createElement(View, { style: [styles.picker, { backgroundColor: colors.divider }] },
54
+ React.createElement(SafeAreaView, { style: styles.pickerContainer },
55
+ React.createElement(Button, { Icon: Icon, type: "text", onPress: toggleVisibility, style: styles.closeButton }, "Close"),
56
+ 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 }))))))))));
57
+ };
58
+ const styles = StyleSheet.create({
59
+ container: {
60
+ alignSelf: "stretch",
61
+ },
62
+ picker: {
63
+ position: "absolute",
64
+ bottom: 0,
65
+ left: 0,
66
+ right: 0,
67
+ flexDirection: "row",
68
+ justifyContent: "center",
69
+ },
70
+ pickerContainer: {
71
+ backgroundColor: "white",
72
+ flexDirection: "column",
73
+ width: "100%",
74
+ },
75
+ closeButton: {
76
+ alignSelf: "flex-end",
77
+ },
78
+ });
79
+ export default withTheme(Picker);