@draftbit/core 44.1.8-8983ea.1 → 44.1.9-55c084.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 (107) hide show
  1. package/lib/commonjs/components/AspectRatio.js +3 -16
  2. package/lib/commonjs/components/AspectRatio.js.map +1 -1
  3. package/lib/commonjs/components/CardContainer.js +5 -16
  4. package/lib/commonjs/components/CardContainer.js.map +1 -1
  5. package/lib/commonjs/components/DeprecatedCardWrapper.js +14 -2
  6. package/lib/commonjs/components/DeprecatedCardWrapper.js.map +1 -1
  7. package/lib/commonjs/components/Picker/Picker.js +244 -27
  8. package/lib/commonjs/components/Picker/Picker.js.map +1 -1
  9. package/lib/commonjs/components/Portal/PortalManager.js.map +1 -1
  10. package/lib/commonjs/components/RadioButton/RadioButton.js +3 -15
  11. package/lib/commonjs/components/RadioButton/RadioButton.js.map +1 -1
  12. package/lib/commonjs/components/ResizeMode.js +1 -2
  13. package/lib/commonjs/components/Swiper/SwiperItem.js.map +1 -1
  14. package/lib/commonjs/components/Swiper/index.js.map +1 -1
  15. package/lib/commonjs/components/ToggleButton.js +3 -17
  16. package/lib/commonjs/components/ToggleButton.js.map +1 -1
  17. package/lib/commonjs/components/Touchable.js +3 -16
  18. package/lib/commonjs/components/Touchable.js.map +1 -1
  19. package/lib/commonjs/components/Typography.js.map +1 -1
  20. package/lib/commonjs/mappings/ActionSheet.js.map +1 -1
  21. package/lib/commonjs/mappings/AudioPlayer.js.map +1 -1
  22. package/lib/commonjs/mappings/AvatarEdit.js.map +1 -1
  23. package/lib/commonjs/mappings/BlurView.js.map +1 -1
  24. package/lib/commonjs/mappings/MapCallout.js.map +1 -1
  25. package/lib/commonjs/mappings/Modal.js.map +1 -1
  26. package/lib/commonjs/mappings/Picker.js +3 -1
  27. package/lib/commonjs/mappings/Picker.js.map +1 -1
  28. package/lib/commonjs/mappings/RadioButton.js.map +1 -1
  29. package/lib/commonjs/mappings/Surface.js.map +1 -1
  30. package/lib/commonjs/mappings/Text.js.map +1 -1
  31. package/lib/commonjs/mappings/WebView.js.map +1 -1
  32. package/lib/commonjs/utilities.js +19 -0
  33. package/lib/commonjs/utilities.js.map +1 -1
  34. package/lib/module/components/ActionSheet/ActionSheetCancel.js.map +1 -1
  35. package/lib/module/components/Banner.js +4 -21
  36. package/lib/module/components/Banner.js.map +1 -1
  37. package/lib/module/components/Card.js.map +1 -1
  38. package/lib/module/components/CardContainer.js +5 -14
  39. package/lib/module/components/CardContainer.js.map +1 -1
  40. package/lib/module/components/Carousel.js +5 -20
  41. package/lib/module/components/Carousel.js.map +1 -1
  42. package/lib/module/components/FormRow.js +4 -17
  43. package/lib/module/components/FormRow.js.map +1 -1
  44. package/lib/module/components/Image.js +3 -18
  45. package/lib/module/components/Image.js.map +1 -1
  46. package/lib/module/components/Picker/Picker.js +237 -29
  47. package/lib/module/components/Picker/Picker.js.map +1 -1
  48. package/lib/module/components/ScreenContainer.js +5 -21
  49. package/lib/module/components/ScreenContainer.js.map +1 -1
  50. package/lib/module/components/Stepper.js.map +1 -1
  51. package/lib/module/components/Surface.js +2 -15
  52. package/lib/module/components/Surface.js.map +1 -1
  53. package/lib/module/index.js.map +1 -1
  54. package/lib/module/mappings/CardInline.js.map +1 -1
  55. package/lib/module/mappings/CheckboxGroup.js.map +1 -1
  56. package/lib/module/mappings/Container.js.map +1 -1
  57. package/lib/module/mappings/DatePicker.js.map +1 -1
  58. package/lib/module/mappings/Divider.js.map +1 -1
  59. package/lib/module/mappings/FieldSearchBarFull.js +1 -1
  60. package/lib/module/mappings/FieldSearchBarFull.js.map +1 -1
  61. package/lib/module/mappings/ImageBackground.js.map +1 -1
  62. package/lib/module/mappings/KeyboardAwareScrollView.js.map +1 -1
  63. package/lib/module/mappings/MapMarker.js.map +1 -1
  64. package/lib/module/mappings/Picker.js +4 -2
  65. package/lib/module/mappings/Picker.js.map +1 -1
  66. package/lib/module/mappings/RowHeadlineImageIcon.js.map +1 -1
  67. package/lib/module/mappings/Text.js.map +1 -1
  68. package/lib/module/utilities.js +12 -1
  69. package/lib/module/utilities.js.map +1 -1
  70. package/lib/typescript/src/components/Picker/Picker.d.ts +28 -4
  71. package/lib/typescript/src/mappings/Picker.d.ts +21 -0
  72. package/lib/typescript/src/utilities.d.ts +6 -0
  73. package/package.json +2 -2
  74. package/src/components/Picker/Picker.js +185 -18
  75. package/src/components/Picker/Picker.tsx +363 -35
  76. package/src/mappings/Picker.js +3 -1
  77. package/src/mappings/Picker.ts +4 -0
  78. package/src/utilities.js +32 -1
  79. package/src/utilities.ts +42 -1
  80. package/lib/commonjs/components/Picker/PickerComponent.android.js +0 -135
  81. package/lib/commonjs/components/Picker/PickerComponent.android.js.map +0 -1
  82. package/lib/commonjs/components/Picker/PickerComponent.ios.js +0 -161
  83. package/lib/commonjs/components/Picker/PickerComponent.ios.js.map +0 -1
  84. package/lib/commonjs/components/Picker/PickerComponent.web.js +0 -136
  85. package/lib/commonjs/components/Picker/PickerComponent.web.js.map +0 -1
  86. package/lib/commonjs/components/Picker/PickerTypes.js +0 -6
  87. package/lib/commonjs/components/Picker/PickerTypes.js.map +0 -1
  88. package/lib/module/components/Picker/PickerComponent.android.js +0 -112
  89. package/lib/module/components/Picker/PickerComponent.android.js.map +0 -1
  90. package/lib/module/components/Picker/PickerComponent.ios.js +0 -154
  91. package/lib/module/components/Picker/PickerComponent.ios.js.map +0 -1
  92. package/lib/module/components/Picker/PickerComponent.web.js +0 -113
  93. package/lib/module/components/Picker/PickerComponent.web.js.map +0 -1
  94. package/lib/module/components/Picker/PickerTypes.js +0 -2
  95. package/lib/module/components/Picker/PickerTypes.js.map +0 -1
  96. package/lib/typescript/src/components/Picker/PickerComponent.android.d.ts +0 -6
  97. package/lib/typescript/src/components/Picker/PickerComponent.ios.d.ts +0 -7
  98. package/lib/typescript/src/components/Picker/PickerComponent.web.d.ts +0 -6
  99. package/lib/typescript/src/components/Picker/PickerTypes.d.ts +0 -18
  100. package/src/components/Picker/PickerComponent.android.js +0 -68
  101. package/src/components/Picker/PickerComponent.android.tsx +0 -116
  102. package/src/components/Picker/PickerComponent.ios.js +0 -78
  103. package/src/components/Picker/PickerComponent.ios.tsx +0 -142
  104. package/src/components/Picker/PickerComponent.web.js +0 -69
  105. package/src/components/Picker/PickerComponent.web.tsx +0 -117
  106. package/src/components/Picker/PickerTypes.js +0 -1
  107. package/src/components/Picker/PickerTypes.ts +0 -18
@@ -3,6 +3,12 @@ export declare function extractStyles(style: StyleProp<any>): {
3
3
  viewStyles: any;
4
4
  textStyles: TextStyle;
5
5
  };
6
+ export declare const borderStyleNames: string[];
7
+ export declare const marginStyleNames: string[];
8
+ export declare function extractBorderAndMarginStyles(style: StyleProp<any>, additionalBorderStyles?: string[], additionalMarginStyles?: string[]): {
9
+ borderStyles: Pick<any, string>;
10
+ marginStyles: Pick<any, string>;
11
+ };
6
12
  /**
7
13
  * Merges a style object on top of another style object. In React Native,
8
14
  * keys with undefined values in a style object will still override styles
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@draftbit/core",
3
- "version": "44.1.8-8983ea.1+8983ea38",
3
+ "version": "44.1.9-55c084.1+55c0842b",
4
4
  "description": "Core (non-native) Components",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
@@ -79,5 +79,5 @@
79
79
  ]
80
80
  ]
81
81
  },
82
- "gitHead": "8983ea38122305cf0e4d72a309d0c8ac4786a20f"
82
+ "gitHead": "55c0842b1f44bb4cdef4af999f179bdbd0a4d23f"
83
83
  }
@@ -1,29 +1,41 @@
1
1
  import * as React from "react";
2
+ import { View, StyleSheet, Text, Platform, } from "react-native";
3
+ import { omit, pickBy, identity, isObject } from "lodash";
4
+ import { SafeAreaView } from "react-native-safe-area-context";
5
+ import { Picker as NativePicker } from "@react-native-picker/picker";
2
6
  import { withTheme } from "../../theming";
3
- //@ts-ignore
4
- import PickerComponent from "./PickerComponent"; //unable to find file due to using .android/.web/.ios
7
+ import Portal from "../Portal/Portal";
8
+ import Button from "../DeprecatedButton";
9
+ import Touchable from "../Touchable";
10
+ import { extractStyles, extractBorderAndMarginStyles, borderStyleNames, marginStyleNames, } from "../../utilities";
5
11
  function normalizeOptions(options) {
6
12
  if (options.length === 0) {
7
13
  return [];
8
14
  }
9
- if (typeof options[0] === "string") {
15
+ if (typeof options[0] === ("string" || "number")) {
10
16
  return options.map((option) => ({
11
- label: option,
17
+ label: String(option),
12
18
  value: String(option),
13
19
  }));
14
20
  }
15
- if (options[0].label && options[0].value) {
21
+ if (isObject(options[0]) &&
22
+ options[0].value !== null &&
23
+ options[0].label !== null) {
16
24
  return options.map((option) => {
17
25
  return {
18
- label: option.label,
26
+ label: String(option.label),
19
27
  value: String(option.value),
20
28
  };
21
29
  });
22
30
  }
23
31
  throw new Error('Picker options must be either an array of strings or array of { "label": string; "value": string; } objects.');
24
32
  }
25
- const Picker = ({ options = [], placeholder, onValueChange: onValueChangeOverride, value, defaultValue, ...props }) => {
33
+ const unstyledColor = "rgba(165, 173, 183, 1)";
34
+ const disabledColor = "rgb(240, 240, 240)";
35
+ const errorColor = "rgba(255, 69, 100, 1)";
36
+ 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", }) => {
26
37
  const [internalValue, setInternalValue] = React.useState(value || defaultValue);
38
+ const [pickerVisible, togglePickerVisible] = React.useReducer((state) => !state, false);
27
39
  React.useEffect(() => {
28
40
  if (value != null) {
29
41
  setInternalValue(value);
@@ -34,23 +46,178 @@ const Picker = ({ options = [], placeholder, onValueChange: onValueChangeOverrid
34
46
  setInternalValue(defaultValue);
35
47
  }
36
48
  }, [defaultValue]);
37
- const onValueChange = React.useCallback((itemValue, itemIndex) => {
38
- if (placeholder && itemIndex === 0) {
39
- return;
40
- }
41
- onValueChangeOverride &&
42
- onValueChangeOverride(String(itemValue), itemIndex);
43
- }, [placeholder, onValueChangeOverride]);
44
49
  const normalizedOptions = normalizeOptions(options);
45
50
  const pickerOptions = placeholder
46
51
  ? [{ value: placeholder, label: placeholder }, ...normalizedOptions]
47
52
  : normalizedOptions;
53
+ const { colors } = theme;
54
+ const { viewStyles, textStyles } = extractStyles(style);
55
+ const { marginStyles, borderStyles: extractedBorderStyles } = extractBorderAndMarginStyles(viewStyles, ["backgroundColor"]);
56
+ const borderStyles = {
57
+ ...{
58
+ ...(type === "solid"
59
+ ? {
60
+ borderTopLeftRadius: 5,
61
+ borderTopRightRadius: 5,
62
+ borderBottomRightRadius: 5,
63
+ borderBottomLeftRadius: 5,
64
+ borderTopWidth: 1,
65
+ borderRightWidth: 1,
66
+ borderLeftWidth: 1,
67
+ }
68
+ : {}),
69
+ borderBottomWidth: 1,
70
+ borderColor: unstyledColor,
71
+ borderStyle: "solid",
72
+ },
73
+ // ...pick(viewStyles, borders),
74
+ ...pickBy(extractedBorderStyles, identity),
75
+ ...(error ? { borderColor: errorColor } : {}),
76
+ ...(disabled
77
+ ? { borderColor: "transparent", backgroundColor: disabledColor }
78
+ : {}),
79
+ };
80
+ const platform = Platform.OS;
81
+ const stylesWithoutBordersAndMargins = {
82
+ ...{
83
+ height: 60,
84
+ width: "100%",
85
+ flex: platform === "web" ? undefined : 1,
86
+ },
87
+ ...omit(viewStyles, [
88
+ ...borderStyleNames,
89
+ ...marginStyleNames,
90
+ "backgroundColor",
91
+ ]),
92
+ };
93
+ const selectedLabel = internalValue &&
94
+ (pickerOptions.find((option) => option.value === internalValue)?.label ??
95
+ internalValue);
96
+ const labelText = label ? (React.createElement(Text, { style: {
97
+ textAlign: textStyles.textAlign,
98
+ color: unstyledColor,
99
+ fontSize: 12,
100
+ paddingBottom: 4,
101
+ } }, label)) : null;
102
+ const leftIconOutset = leftIconMode === "outset";
103
+ const leftIcon = leftIconName ? (React.createElement(Icon, { name: leftIconName, color: disabled ? unstyledColor : iconColor, size: iconSize, style: {
104
+ marginRight: 4,
105
+ marginLeft: 4,
106
+ } })) : null;
107
+ const rightIcon = rightIconName ? (React.createElement(Icon, { name: rightIconName, color: disabled ? unstyledColor : iconColor, size: iconSize, style: {
108
+ marginRight: -10,
109
+ marginLeft: 8,
110
+ } })) : null;
111
+ const width = stylesWithoutBordersAndMargins?.width;
112
+ const textAlign = textStyles?.textAlign;
113
+ const paddingLeft = leftIconOutset &&
114
+ (!textAlign || textAlign === "left" || textAlign === "justify")
115
+ ? iconSize + 4
116
+ : 0;
117
+ const assistiveTextLabel = assistiveText ? (React.createElement(Text, { style: {
118
+ textAlign,
119
+ width,
120
+ paddingLeft,
121
+ color: unstyledColor,
122
+ fontSize: 12,
123
+ paddingTop: 4,
124
+ } }, assistiveText)) : null;
125
+ const primaryTextStyle = {
126
+ color: unstyledColor,
127
+ fontSize: 14,
128
+ ...pickBy(textStyles, identity),
129
+ ...(placeholder === internalValue ? { color: placeholderTextColor } : {}),
130
+ ...(disabled ? { color: unstyledColor } : {}),
131
+ };
48
132
  const handleValueChange = (newValue, itemIndex) => {
49
- setInternalValue(newValue);
50
- if (onValueChange) {
51
- onValueChange(newValue, itemIndex);
133
+ if (!placeholder || itemIndex > 0) {
134
+ onValueChange?.(newValue, itemIndex);
52
135
  }
136
+ setInternalValue(newValue);
53
137
  };
54
- return (React.createElement(PickerComponent, { ...props, selectedValue: String(internalValue), placeholder: placeholder, options: pickerOptions, onValueChange: handleValueChange }));
138
+ return (
139
+ /* marginsContainer */
140
+ React.createElement(View, { style: [styles.marginsContainer, marginStyles] },
141
+ React.createElement(Touchable, { disabled: disabled, onPress: togglePickerVisible, style: styles.touchableContainer },
142
+ React.createElement(View, { pointerEvents: "none", style: [
143
+ styles.outsetContainer,
144
+ stylesWithoutBordersAndMargins,
145
+ !leftIconOutset ? borderStyles : {},
146
+ ] },
147
+ leftIcon,
148
+ React.createElement(View, { style: [
149
+ styles.insetContainer,
150
+ leftIconOutset ? borderStyles : {},
151
+ ] },
152
+ React.createElement(View, { style: styles.primaryTextContainer },
153
+ labelText,
154
+ React.createElement(Text, { style: primaryTextStyle }, String(selectedLabel ?? placeholder))),
155
+ rightIcon)),
156
+ assistiveTextLabel),
157
+ platform === "ios" && pickerVisible ? (React.createElement(Portal, null,
158
+ React.createElement(View, { style: [
159
+ styles.iosPicker,
160
+ {
161
+ backgroundColor: colors.divider,
162
+ },
163
+ ] },
164
+ React.createElement(SafeAreaView, { style: styles.iosSafeArea },
165
+ React.createElement(Button, { Icon: Icon, type: "text", onPress: togglePickerVisible, style: styles.iosButton }, "Close"),
166
+ React.createElement(NativePicker, { style: styles.iosNativePicker, selectedValue: internalValue, onValueChange: handleValueChange }, pickerOptions.map((option) => (React.createElement(NativePicker.Item, { label: option.label, value: option.value, key: option.value })))))))) : null,
167
+ platform !== "ios" ? (React.createElement(NativePicker, { enabled: !disabled, selectedValue: internalValue, onValueChange: handleValueChange, style: styles.nonIosPicker }, pickerOptions.map((option) => (React.createElement(NativePicker.Item, { label: option.label, value: option.value, key: option.value }))))) : null));
55
168
  };
56
169
  export default withTheme(Picker);
170
+ const styles = StyleSheet.create({
171
+ marginsContainer: {
172
+ alignSelf: "stretch",
173
+ },
174
+ touchableContainer: {
175
+ alignSelf: "stretch",
176
+ alignItems: "center",
177
+ },
178
+ outsetContainer: {
179
+ flexDirection: "row",
180
+ alignItems: "center",
181
+ justifyContent: "space-between",
182
+ },
183
+ insetContainer: {
184
+ flex: 1,
185
+ height: "100%",
186
+ flexDirection: "row",
187
+ alignItems: "center",
188
+ justifyContent: "space-between",
189
+ paddingLeft: 12,
190
+ paddingRight: 12,
191
+ },
192
+ primaryTextContainer: {
193
+ flex: 1,
194
+ },
195
+ iosPicker: {
196
+ position: "absolute",
197
+ bottom: 0,
198
+ left: 0,
199
+ right: 0,
200
+ flexDirection: "row",
201
+ justifyContent: "center",
202
+ },
203
+ iosSafeArea: {
204
+ backgroundColor: "white",
205
+ flexDirection: "column",
206
+ width: "100%",
207
+ },
208
+ iosButton: {
209
+ alignSelf: "flex-end",
210
+ },
211
+ iosNativePicker: {
212
+ backgroundColor: "white",
213
+ },
214
+ nonIosPicker: {
215
+ opacity: 0,
216
+ position: "absolute",
217
+ top: 0,
218
+ left: 0,
219
+ right: 0,
220
+ bottom: 0,
221
+ width: "100%",
222
+ },
223
+ });