@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
@@ -1,31 +1,76 @@
1
1
  import * as React from "react";
2
+ import {
3
+ View,
4
+ StyleSheet,
5
+ Text,
6
+ Platform,
7
+ ViewStyle,
8
+ StyleProp,
9
+ } from "react-native";
10
+ import { omit, pickBy, identity, isObject } from "lodash";
11
+ import { SafeAreaView } from "react-native-safe-area-context";
12
+ import { Picker as NativePicker } from "@react-native-picker/picker";
13
+
2
14
  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";
15
+ import Portal from "../Portal/Portal";
16
+ import Button from "../DeprecatedButton";
17
+ import Touchable from "../Touchable";
18
+ import type { Theme } from "../../styles/DefaultTheme";
19
+ import type { IconSlot } from "../../interfaces/Icon";
20
+ import {
21
+ extractStyles,
22
+ extractBorderAndMarginStyles,
23
+ borderStyleNames,
24
+ marginStyleNames,
25
+ } from "../../utilities";
26
+
27
+ export interface PickerOption {
28
+ value: string;
29
+ label: string;
30
+ }
6
31
 
7
- type Props = PickerComponentProps & {
32
+ export type PickerProps = {
33
+ error?: any;
8
34
  placeholder?: string;
35
+ disabled?: boolean;
36
+ style?: StyleProp<ViewStyle> & { height?: number };
9
37
  value?: string;
10
38
  options: PickerOption[] | string[];
39
+ onValueChange: (value: string, index: number) => void;
40
+ defaultValue?: string;
41
+ assistiveText?: string;
42
+ label?: string;
43
+ iconColor?: string;
44
+ iconSize?: number;
45
+ leftIconMode?: "inset" | "outset";
46
+ leftIconName?: string;
47
+ placeholderTextColor?: string;
48
+ rightIconName?: string;
49
+ type?: "solid" | "underline";
50
+ theme: Theme;
51
+ Icon: IconSlot["Icon"];
11
52
  };
12
53
 
13
- function normalizeOptions(options: Props["options"]): PickerOption[] {
54
+ function normalizeOptions(options: PickerProps["options"]): PickerOption[] {
14
55
  if (options.length === 0) {
15
56
  return [];
16
57
  }
17
58
 
18
- if (typeof options[0] === "string") {
59
+ if (typeof options[0] === ("string" || "number")) {
19
60
  return (options as string[]).map((option) => ({
20
- label: option,
61
+ label: String(option),
21
62
  value: String(option),
22
63
  }));
23
64
  }
24
65
 
25
- if (options[0].label && options[0].value) {
26
- return options.map((option) => {
66
+ if (
67
+ isObject(options[0]) &&
68
+ options[0].value !== null &&
69
+ options[0].label !== null
70
+ ) {
71
+ return (options as PickerOption[]).map((option) => {
27
72
  return {
28
- label: option.label,
73
+ label: String(option.label),
29
74
  value: String(option.value),
30
75
  };
31
76
  });
@@ -36,18 +81,40 @@ function normalizeOptions(options: Props["options"]): PickerOption[] {
36
81
  );
37
82
  }
38
83
 
39
- const Picker: React.FC<Props> = ({
84
+ const unstyledColor = "rgba(165, 173, 183, 1)";
85
+ const disabledColor = "rgb(240, 240, 240)";
86
+ const errorColor = "rgba(255, 69, 100, 1)";
87
+
88
+ const Picker: React.FC<PickerProps> = ({
89
+ error,
40
90
  options = [],
91
+ onValueChange,
92
+ defaultValue,
93
+ Icon,
94
+ style,
41
95
  placeholder,
42
- onValueChange: onValueChangeOverride,
43
96
  value,
44
- defaultValue,
45
- ...props
97
+ disabled = false,
98
+ theme,
99
+ assistiveText,
100
+ label,
101
+ iconColor = unstyledColor,
102
+ iconSize = 24,
103
+ leftIconMode = "inset",
104
+ leftIconName,
105
+ placeholderTextColor = unstyledColor,
106
+ rightIconName,
107
+ type = "solid",
46
108
  }) => {
47
109
  const [internalValue, setInternalValue] = React.useState<string | undefined>(
48
110
  value || defaultValue
49
111
  );
50
112
 
113
+ const [pickerVisible, togglePickerVisible] = React.useReducer(
114
+ (state) => !state,
115
+ false
116
+ );
117
+
51
118
  React.useEffect(() => {
52
119
  if (value != null) {
53
120
  setInternalValue(value);
@@ -60,39 +127,300 @@ const Picker: React.FC<Props> = ({
60
127
  }
61
128
  }, [defaultValue]);
62
129
 
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
- );
73
-
74
130
  const normalizedOptions = normalizeOptions(options);
75
131
 
76
132
  const pickerOptions = placeholder
77
133
  ? [{ value: placeholder, label: placeholder }, ...normalizedOptions]
78
134
  : normalizedOptions;
79
135
 
136
+ const { colors } = theme;
137
+
138
+ const { viewStyles, textStyles } = extractStyles(style);
139
+
140
+ const { marginStyles, borderStyles: extractedBorderStyles } =
141
+ extractBorderAndMarginStyles(viewStyles, ["backgroundColor"]);
142
+
143
+ const borderStyles = {
144
+ ...{
145
+ ...(type === "solid"
146
+ ? {
147
+ borderTopLeftRadius: 5,
148
+ borderTopRightRadius: 5,
149
+ borderBottomRightRadius: 5,
150
+ borderBottomLeftRadius: 5,
151
+ borderTopWidth: 1,
152
+ borderRightWidth: 1,
153
+ borderLeftWidth: 1,
154
+ }
155
+ : {}),
156
+ borderBottomWidth: 1,
157
+ borderColor: unstyledColor,
158
+ borderStyle: "solid",
159
+ },
160
+ // ...pick(viewStyles, borders),
161
+ ...pickBy(extractedBorderStyles, identity),
162
+ ...(error ? { borderColor: errorColor } : {}),
163
+ ...(disabled
164
+ ? { borderColor: "transparent", backgroundColor: disabledColor }
165
+ : {}),
166
+ };
167
+
168
+ const platform = Platform.OS;
169
+
170
+ const stylesWithoutBordersAndMargins = {
171
+ ...{
172
+ height: 60,
173
+ width: "100%",
174
+ flex: platform === "web" ? undefined : 1,
175
+ },
176
+ ...omit(viewStyles, [
177
+ ...borderStyleNames,
178
+ ...marginStyleNames,
179
+ "backgroundColor",
180
+ ]),
181
+ };
182
+
183
+ const selectedLabel =
184
+ internalValue &&
185
+ ((pickerOptions as unknown as PickerOption[]).find(
186
+ (option) => option.value === internalValue
187
+ )?.label ??
188
+ internalValue);
189
+
190
+ const labelText = label ? (
191
+ <Text
192
+ style={{
193
+ textAlign: textStyles.textAlign,
194
+ color: unstyledColor,
195
+ fontSize: 12,
196
+ paddingBottom: 4,
197
+ }}
198
+ >
199
+ {label}
200
+ </Text>
201
+ ) : null;
202
+
203
+ const leftIconOutset = leftIconMode === "outset";
204
+
205
+ const leftIcon = leftIconName ? (
206
+ <Icon
207
+ name={leftIconName}
208
+ color={disabled ? unstyledColor : iconColor}
209
+ size={iconSize}
210
+ style={{
211
+ marginRight: 4,
212
+ marginLeft: 4,
213
+ }}
214
+ />
215
+ ) : null;
216
+
217
+ const rightIcon = rightIconName ? (
218
+ <Icon
219
+ name={rightIconName}
220
+ color={disabled ? unstyledColor : iconColor}
221
+ size={iconSize}
222
+ style={{
223
+ marginRight: -10,
224
+ marginLeft: 8,
225
+ }}
226
+ />
227
+ ) : null;
228
+
229
+ const width = stylesWithoutBordersAndMargins?.width;
230
+
231
+ const textAlign = textStyles?.textAlign;
232
+
233
+ const paddingLeft =
234
+ leftIconOutset &&
235
+ (!textAlign || textAlign === "left" || textAlign === "justify")
236
+ ? iconSize + 4
237
+ : 0;
238
+
239
+ const assistiveTextLabel = assistiveText ? (
240
+ <Text
241
+ style={{
242
+ textAlign,
243
+ width,
244
+ paddingLeft,
245
+ color: unstyledColor,
246
+ fontSize: 12,
247
+ paddingTop: 4,
248
+ }}
249
+ >
250
+ {assistiveText}
251
+ </Text>
252
+ ) : null;
253
+
254
+ const primaryTextStyle = {
255
+ color: unstyledColor,
256
+ fontSize: 14,
257
+ ...pickBy(textStyles, identity),
258
+ ...(placeholder === internalValue ? { color: placeholderTextColor } : {}),
259
+ ...(disabled ? { color: unstyledColor } : {}),
260
+ };
261
+
80
262
  const handleValueChange = (newValue: string, itemIndex: number) => {
81
- setInternalValue(newValue);
82
- if (onValueChange) {
83
- onValueChange(newValue, itemIndex);
263
+ if (!placeholder || itemIndex > 0) {
264
+ onValueChange?.(newValue, itemIndex);
84
265
  }
266
+ setInternalValue(newValue);
85
267
  };
86
268
 
87
269
  return (
88
- <PickerComponent
89
- {...props}
90
- selectedValue={String(internalValue)}
91
- placeholder={placeholder}
92
- options={pickerOptions}
93
- onValueChange={handleValueChange}
94
- />
270
+ /* marginsContainer */
271
+ <View style={[styles.marginsContainer, marginStyles]}>
272
+ {/* touchableContainer */}
273
+ <Touchable
274
+ disabled={disabled}
275
+ onPress={togglePickerVisible}
276
+ style={styles.touchableContainer}
277
+ >
278
+ {/* outsetContainer */}
279
+ <View
280
+ pointerEvents="none"
281
+ style={[
282
+ styles.outsetContainer,
283
+ stylesWithoutBordersAndMargins,
284
+ !leftIconOutset ? (borderStyles as PickerProps["style"]) : {},
285
+ ]}
286
+ >
287
+ {leftIcon}
288
+
289
+ {/* insetContainer */}
290
+ <View
291
+ style={[
292
+ styles.insetContainer,
293
+ leftIconOutset ? (borderStyles as PickerProps["style"]) : {},
294
+ ]}
295
+ >
296
+ {/* primaryTextContainer */}
297
+ <View style={styles.primaryTextContainer}>
298
+ {labelText}
299
+
300
+ <Text style={primaryTextStyle}>
301
+ {String(selectedLabel ?? placeholder)}
302
+ </Text>
303
+ </View>
304
+
305
+ {rightIcon}
306
+ </View>
307
+ </View>
308
+ {assistiveTextLabel}
309
+ </Touchable>
310
+
311
+ {/* iosPicker */}
312
+ {platform === "ios" && pickerVisible ? (
313
+ <Portal>
314
+ <View
315
+ style={[
316
+ styles.iosPicker,
317
+ {
318
+ backgroundColor: colors.divider,
319
+ },
320
+ ]}
321
+ >
322
+ <SafeAreaView style={styles.iosSafeArea}>
323
+ <Button
324
+ Icon={Icon}
325
+ type="text"
326
+ onPress={togglePickerVisible}
327
+ style={styles.iosButton}
328
+ >
329
+ {"Close"}
330
+ </Button>
331
+
332
+ <NativePicker
333
+ style={styles.iosNativePicker}
334
+ selectedValue={internalValue}
335
+ onValueChange={handleValueChange}
336
+ >
337
+ {(pickerOptions as unknown as PickerOption[]).map((option) => (
338
+ <NativePicker.Item
339
+ label={option.label}
340
+ value={option.value}
341
+ key={option.value}
342
+ />
343
+ ))}
344
+ </NativePicker>
345
+ </SafeAreaView>
346
+ </View>
347
+ </Portal>
348
+ ) : null}
349
+
350
+ {/* nonIosPicker */}
351
+ {platform !== "ios" ? (
352
+ <NativePicker
353
+ enabled={!disabled}
354
+ selectedValue={internalValue}
355
+ onValueChange={handleValueChange}
356
+ style={styles.nonIosPicker}
357
+ >
358
+ {(pickerOptions as unknown as PickerOption[]).map((option) => (
359
+ <NativePicker.Item
360
+ label={option.label}
361
+ value={option.value}
362
+ key={option.value}
363
+ />
364
+ ))}
365
+ </NativePicker>
366
+ ) : null}
367
+ </View>
95
368
  );
96
369
  };
97
370
 
98
371
  export default withTheme(Picker);
372
+
373
+ const styles = StyleSheet.create({
374
+ marginsContainer: {
375
+ alignSelf: "stretch",
376
+ },
377
+ touchableContainer: {
378
+ alignSelf: "stretch",
379
+ alignItems: "center",
380
+ },
381
+ outsetContainer: {
382
+ flexDirection: "row",
383
+ alignItems: "center",
384
+ justifyContent: "space-between",
385
+ },
386
+ insetContainer: {
387
+ flex: 1,
388
+ height: "100%",
389
+ flexDirection: "row",
390
+ alignItems: "center",
391
+ justifyContent: "space-between",
392
+ paddingLeft: 12,
393
+ paddingRight: 12,
394
+ },
395
+ primaryTextContainer: {
396
+ flex: 1,
397
+ },
398
+ iosPicker: {
399
+ position: "absolute",
400
+ bottom: 0,
401
+ left: 0,
402
+ right: 0,
403
+ flexDirection: "row",
404
+ justifyContent: "center",
405
+ },
406
+ iosSafeArea: {
407
+ backgroundColor: "white",
408
+ flexDirection: "column",
409
+ width: "100%",
410
+ },
411
+ iosButton: {
412
+ alignSelf: "flex-end",
413
+ },
414
+ iosNativePicker: {
415
+ backgroundColor: "white",
416
+ },
417
+ nonIosPicker: {
418
+ opacity: 0,
419
+ position: "absolute",
420
+ top: 0,
421
+ left: 0,
422
+ right: 0,
423
+ bottom: 0,
424
+ width: "100%",
425
+ },
426
+ });
@@ -1,4 +1,4 @@
1
- import { COMPONENT_TYPES, Triggers, GROUPS, FORM_TYPES, PROP_TYPES, FIELD_NAME, } from "@draftbit/types";
1
+ import { COMPONENT_TYPES, Triggers, GROUPS, FORM_TYPES, PROP_TYPES, FIELD_NAME, createIconSizeProp, createColorProp, } from "@draftbit/types";
2
2
  const SEED_DATA_PROPS = {
3
3
  label: {
4
4
  group: GROUPS.data,
@@ -131,6 +131,8 @@ export const SEED_DATA = [
131
131
  required: true,
132
132
  group: GROUPS.basic,
133
133
  },
134
+ iconSize: createIconSizeProp(),
135
+ iconColor: createColorProp(),
134
136
  },
135
137
  layout: {},
136
138
  },
@@ -5,6 +5,8 @@ import {
5
5
  FORM_TYPES,
6
6
  PROP_TYPES,
7
7
  FIELD_NAME,
8
+ createIconSizeProp,
9
+ createColorProp,
8
10
  } from "@draftbit/types";
9
11
 
10
12
  const SEED_DATA_PROPS = {
@@ -143,6 +145,8 @@ export const SEED_DATA = [
143
145
  required: true,
144
146
  group: GROUPS.basic,
145
147
  },
148
+ iconSize: createIconSizeProp(),
149
+ iconColor: createColorProp(),
146
150
  },
147
151
  layout: {},
148
152
  },
package/src/utilities.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { StyleSheet } from "react-native";
2
- import { isString, isNumber } from "lodash";
2
+ import { isString, isNumber, pick } from "lodash";
3
3
  export function extractStyles(style) {
4
4
  const { color, fontFamily, fontWeight, fontSize, lineHeight, letterSpacing, textTransform, textAlign, textDecorationLine, textDecorationColor, textDecorationStyle, ...viewStyles } = StyleSheet.flatten(style || {});
5
5
  const textStyles = {
@@ -17,6 +17,37 @@ export function extractStyles(style) {
17
17
  };
18
18
  return { viewStyles, textStyles };
19
19
  }
20
+ export const borderStyleNames = [
21
+ "borderRadius",
22
+ "borderTopLeftRadius",
23
+ "borderTopRightRadius",
24
+ "borderBottomRightRadius",
25
+ "borderBottomLeftRadius",
26
+ "borderTopWidth",
27
+ "borderRightWidth",
28
+ "borderBottomWidth",
29
+ "borderLeftWidth",
30
+ "borderColor",
31
+ "borderStyle",
32
+ ];
33
+ export const marginStyleNames = [
34
+ "marginLeft",
35
+ "marginRight",
36
+ "marginTop",
37
+ "marginBottom",
38
+ ];
39
+ export function extractBorderAndMarginStyles(style, additionalBorderStyles, additionalMarginStyles) {
40
+ const flatStyle = StyleSheet.flatten(style || {});
41
+ const borderStyles = pick(flatStyle, [
42
+ ...borderStyleNames,
43
+ ...(additionalBorderStyles ? additionalBorderStyles : []),
44
+ ]);
45
+ const marginStyles = pick(flatStyle, [
46
+ ...marginStyleNames,
47
+ ...(additionalMarginStyles ? additionalMarginStyles : []),
48
+ ]);
49
+ return { borderStyles, marginStyles };
50
+ }
20
51
  /**
21
52
  * Merges a style object on top of another style object. In React Native,
22
53
  * keys with undefined values in a style object will still override styles
package/src/utilities.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { StyleSheet, StyleProp, TextStyle } from "react-native";
2
- import { isString, isNumber } from "lodash";
2
+ import { isString, isNumber, pick } from "lodash";
3
3
 
4
4
  export function extractStyles(style: StyleProp<any>) {
5
5
  const {
@@ -34,6 +34,47 @@ export function extractStyles(style: StyleProp<any>) {
34
34
  return { viewStyles, textStyles };
35
35
  }
36
36
 
37
+ export const borderStyleNames = [
38
+ "borderRadius",
39
+ "borderTopLeftRadius",
40
+ "borderTopRightRadius",
41
+ "borderBottomRightRadius",
42
+ "borderBottomLeftRadius",
43
+ "borderTopWidth",
44
+ "borderRightWidth",
45
+ "borderBottomWidth",
46
+ "borderLeftWidth",
47
+ "borderColor",
48
+ "borderStyle",
49
+ ];
50
+
51
+ export const marginStyleNames = [
52
+ "marginLeft",
53
+ "marginRight",
54
+ "marginTop",
55
+ "marginBottom",
56
+ ];
57
+
58
+ export function extractBorderAndMarginStyles(
59
+ style: StyleProp<any>,
60
+ additionalBorderStyles?: string[],
61
+ additionalMarginStyles?: string[]
62
+ ) {
63
+ const flatStyle = StyleSheet.flatten(style || {});
64
+
65
+ const borderStyles = pick(flatStyle, [
66
+ ...borderStyleNames,
67
+ ...(additionalBorderStyles ? additionalBorderStyles : []),
68
+ ]);
69
+
70
+ const marginStyles = pick(flatStyle, [
71
+ ...marginStyleNames,
72
+ ...(additionalMarginStyles ? additionalMarginStyles : []),
73
+ ]);
74
+
75
+ return { borderStyles, marginStyles };
76
+ }
77
+
37
78
  /**
38
79
  * Merges a style object on top of another style object. In React Native,
39
80
  * keys with undefined values in a style object will still override styles