@draftbit/core 44.1.13-9a8dff.0 → 44.1.13-c10e64.0

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 (57) 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/DeprecatedButton.js +4 -19
  4. package/lib/commonjs/components/DeprecatedButton.js.map +1 -1
  5. package/lib/commonjs/components/Picker/Picker.js +27 -266
  6. package/lib/commonjs/components/Picker/Picker.js.map +1 -1
  7. package/lib/commonjs/components/Picker/PickerComponent.android.js +120 -19
  8. package/lib/commonjs/components/Picker/PickerComponent.android.js.map +1 -1
  9. package/lib/commonjs/components/Picker/PickerComponent.ios.js +146 -35
  10. package/lib/commonjs/components/Picker/PickerComponent.ios.js.map +1 -1
  11. package/lib/commonjs/components/Picker/PickerComponent.web.js +121 -19
  12. package/lib/commonjs/components/Picker/PickerComponent.web.js.map +1 -1
  13. package/lib/commonjs/components/Picker/PickerTypes.js +6 -0
  14. package/lib/commonjs/components/Picker/PickerTypes.js.map +1 -0
  15. package/lib/commonjs/mappings/Picker.js +1 -7
  16. package/lib/commonjs/mappings/Picker.js.map +1 -1
  17. package/lib/commonjs/utilities.js +0 -19
  18. package/lib/commonjs/utilities.js.map +1 -1
  19. package/lib/module/components/Carousel.js +5 -20
  20. package/lib/module/components/Carousel.js.map +1 -1
  21. package/lib/module/components/Picker/Picker.js +28 -260
  22. package/lib/module/components/Picker/Picker.js.map +1 -1
  23. package/lib/module/components/Picker/PickerComponent.android.js +109 -18
  24. package/lib/module/components/Picker/PickerComponent.android.js.map +1 -1
  25. package/lib/module/components/Picker/PickerComponent.ios.js +132 -35
  26. package/lib/module/components/Picker/PickerComponent.ios.js.map +1 -1
  27. package/lib/module/components/Picker/PickerComponent.web.js +110 -18
  28. package/lib/module/components/Picker/PickerComponent.web.js.map +1 -1
  29. package/lib/module/components/Picker/PickerTypes.js +2 -0
  30. package/lib/module/components/Picker/PickerTypes.js.map +1 -0
  31. package/lib/module/mappings/CheckboxRow.js.map +1 -1
  32. package/lib/module/mappings/Picker.js +2 -8
  33. package/lib/module/mappings/Picker.js.map +1 -1
  34. package/lib/module/utilities.js +1 -12
  35. package/lib/module/utilities.js.map +1 -1
  36. package/lib/typescript/src/components/Picker/Picker.d.ts +4 -28
  37. package/lib/typescript/src/components/Picker/PickerComponent.android.d.ts +5 -12
  38. package/lib/typescript/src/components/Picker/PickerComponent.ios.d.ts +5 -11
  39. package/lib/typescript/src/components/Picker/PickerComponent.web.d.ts +5 -12
  40. package/lib/typescript/src/components/Picker/PickerTypes.d.ts +18 -0
  41. package/lib/typescript/src/mappings/Picker.d.ts +0 -21
  42. package/lib/typescript/src/utilities.d.ts +0 -7
  43. package/package.json +2 -2
  44. package/src/components/Picker/Picker.js +17 -229
  45. package/src/components/Picker/Picker.tsx +34 -434
  46. package/src/components/Picker/PickerComponent.android.js +66 -16
  47. package/src/components/Picker/PickerComponent.android.tsx +107 -28
  48. package/src/components/Picker/PickerComponent.ios.js +76 -32
  49. package/src/components/Picker/PickerComponent.ios.tsx +137 -49
  50. package/src/components/Picker/PickerComponent.web.js +67 -16
  51. package/src/components/Picker/PickerComponent.web.tsx +108 -28
  52. package/src/components/Picker/PickerTypes.js +1 -0
  53. package/src/components/Picker/PickerTypes.ts +18 -0
  54. package/src/mappings/Picker.js +1 -3
  55. package/src/mappings/Picker.ts +0 -4
  56. package/src/utilities.js +1 -49
  57. package/src/utilities.ts +1 -65
@@ -1,37 +1,117 @@
1
1
  import * as React from "react";
2
- import { /* StyleSheet, Dimensions, */ Text } from "react-native";
2
+ import { View, StyleSheet } from "react-native";
3
+ import { Picker as NativePicker } from "@react-native-picker/picker";
4
+ import omit from "lodash.omit";
5
+ import { withTheme } from "../../theming";
6
+ import { extractStyles } from "../../utilities";
3
7
 
4
- // import { Picker as NativePicker } from "@react-native-picker/picker";
8
+ import TextField from "../TextField";
9
+ import Touchable from "../Touchable";
10
+ import { PickerComponentProps } from "./PickerTypes";
5
11
 
6
- import type { IconSlot } from "../../interfaces/Icon";
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);
7
39
 
8
- import { PickerOption } from "./Picker";
40
+ const textField = React.useRef<typeof TextField | undefined>(undefined);
9
41
 
10
- // const { width: deviceWidth, height: deviceHeight } = Dimensions.get("screen");
42
+ const onValueChange = (itemValue: string, itemIndex: number) => {
43
+ toggleFocus();
44
+ onValueChangeOverride(itemValue, itemIndex);
45
+ };
11
46
 
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
- }
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
+ };
20
53
 
21
- export const PickerComponent: React.FC<PickerComponentProps> = () => {
22
- return <Text>web</Text>;
54
+ const stylesWithoutMargin =
55
+ style &&
56
+ omit(StyleSheet.flatten(style), [
57
+ "margin",
58
+ "marginTop",
59
+ "marginRight",
60
+ "marginBottom",
61
+ "marginLeft",
62
+ ]);
63
+
64
+ const selectedLabel =
65
+ selectedValue &&
66
+ (options.find((o) => o.value === selectedValue)?.label ?? selectedValue);
67
+
68
+ return (
69
+ <Touchable
70
+ disabled={disabled}
71
+ onPress={toggleFocus}
72
+ style={[styles.container, viewStyles]}
73
+ >
74
+ <View>
75
+ <NativePicker
76
+ enabled={!disabled}
77
+ selectedValue={selectedValue}
78
+ onValueChange={onValueChange}
79
+ style={{
80
+ flex: 1,
81
+ opacity: 0,
82
+ position: "absolute",
83
+ top: 0,
84
+ left: 0,
85
+ right: 0,
86
+ bottom: 0,
87
+ width: "100%",
88
+ }}
89
+ >
90
+ {options.map((o) => (
91
+ <NativePicker.Item label={o.label} value={o.value} key={o.value} />
92
+ ))}
93
+ </NativePicker>
94
+ <View pointerEvents="none">
95
+ <TextField
96
+ {...props}
97
+ value={selectedLabel}
98
+ placeholder={placeholder}
99
+ // @ts-ignore
100
+ ref={textField} // cannot determine if ref is of correct type due to component being wrapped in a withTheme()
101
+ disabled={disabled}
102
+ // @ts-expect-error
103
+ style={stylesWithoutMargin}
104
+ />
105
+ </View>
106
+ </View>
107
+ </Touchable>
108
+ );
23
109
  };
24
110
 
25
- // const styles = StyleSheet.create({
26
- // nonIosPicker: {
27
- // opacity: 0,
28
- // position: "absolute",
29
- // top: 0,
30
- // left: 0,
31
- // right: 0,
32
- // bottom: 0,
33
- // width: "100%",
34
- // maxWidth: deviceWidth,
35
- // maxHeight: deviceHeight,
36
- // },
37
- // });
111
+ const styles = StyleSheet.create({
112
+ container: {
113
+ alignSelf: "stretch",
114
+ },
115
+ });
116
+
117
+ export default withTheme(Picker);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import { ViewStyle } from "react-native";
2
+ import { StyleProp } from "react-native";
3
+ import { Props as TextFieldProps } from "../TextField";
4
+
5
+ export interface PickerOption {
6
+ value: string;
7
+ label: string;
8
+ }
9
+
10
+ export interface PickerComponentProps extends TextFieldProps {
11
+ style?: StyleProp<ViewStyle> & { height?: number };
12
+ options: PickerOption[];
13
+ placeholder?: string;
14
+ selectedValue: string;
15
+ disabled?: boolean;
16
+ onValueChange?: (value: string, index: number) => void;
17
+ defaultValue?: string;
18
+ }
@@ -1,4 +1,4 @@
1
- import { COMPONENT_TYPES, Triggers, GROUPS, FORM_TYPES, PROP_TYPES, FIELD_NAME, createIconSizeProp, createColorProp, } from "@draftbit/types";
1
+ import { COMPONENT_TYPES, Triggers, GROUPS, FORM_TYPES, PROP_TYPES, FIELD_NAME, } from "@draftbit/types";
2
2
  const SEED_DATA_PROPS = {
3
3
  label: {
4
4
  group: GROUPS.data,
@@ -131,8 +131,6 @@ export const SEED_DATA = [
131
131
  required: true,
132
132
  group: GROUPS.basic,
133
133
  },
134
- iconSize: createIconSizeProp({ defaultValue: 24 }),
135
- iconColor: createColorProp({ label: "Icon Color" }),
136
134
  },
137
135
  layout: {},
138
136
  },
@@ -5,8 +5,6 @@ import {
5
5
  FORM_TYPES,
6
6
  PROP_TYPES,
7
7
  FIELD_NAME,
8
- createIconSizeProp,
9
- createColorProp,
10
8
  } from "@draftbit/types";
11
9
 
12
10
  const SEED_DATA_PROPS = {
@@ -145,8 +143,6 @@ export const SEED_DATA = [
145
143
  required: true,
146
144
  group: GROUPS.basic,
147
145
  },
148
- iconSize: createIconSizeProp({ defaultValue: 24 }),
149
- iconColor: createColorProp({ label: "Icon Color" }),
150
146
  },
151
147
  layout: {},
152
148
  },
package/src/utilities.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { StyleSheet } from "react-native";
2
- import { isString, isNumber, pick, pickBy, identity } from "lodash";
2
+ import { isString, isNumber } 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,54 +17,6 @@ export function extractStyles(style) {
17
17
  };
18
18
  return { viewStyles, textStyles };
19
19
  }
20
- export const borderStyleNames = [
21
- "borderRadius",
22
- "borderBottomColor",
23
- "borderBottomEndRadius",
24
- "borderBottomLeftRadius",
25
- "borderBottomRightRadius",
26
- "borderBottomStartRadius",
27
- "borderBottomWidth",
28
- "borderColor",
29
- "borderEndColor",
30
- "borderLeftColor",
31
- "borderLeftWidth",
32
- "borderRadius",
33
- "borderRightColor",
34
- "borderRightWidth",
35
- "borderStartColor",
36
- "borderStyle",
37
- "borderTopColor",
38
- "borderTopEndRadius",
39
- "borderTopLeftRadius",
40
- "borderTopRightRadius",
41
- "borderTopStartRadius",
42
- "borderTopWidth",
43
- "borderWidth",
44
- ];
45
- export const marginStyleNames = [
46
- "margin",
47
- "marginBottom",
48
- "marginEnd",
49
- "marginHorizontal",
50
- "marginLeft",
51
- "marginRight",
52
- "marginStart",
53
- "marginTop",
54
- "marginVertical",
55
- ];
56
- export function extractBorderAndMarginStyles(style, additionalBorderStyles, additionalMarginStyles) {
57
- const flatStyle = StyleSheet.flatten(style || {});
58
- const borderStyles = pickBy(pick(flatStyle, [
59
- ...borderStyleNames,
60
- ...(additionalBorderStyles ? additionalBorderStyles : []),
61
- ]), identity);
62
- const marginStyles = pickBy(pick(flatStyle, [
63
- ...marginStyleNames,
64
- ...(additionalMarginStyles ? additionalMarginStyles : []),
65
- ]), identity);
66
- return { borderStyles, marginStyles };
67
- }
68
20
  /**
69
21
  * Merges a style object on top of another style object. In React Native,
70
22
  * 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, pick, pickBy, identity } from "lodash";
2
+ import { isString, isNumber } from "lodash";
3
3
 
4
4
  export function extractStyles(style: StyleProp<any>) {
5
5
  const {
@@ -34,70 +34,6 @@ export function extractStyles(style: StyleProp<any>) {
34
34
  return { viewStyles, textStyles };
35
35
  }
36
36
 
37
- export const borderStyleNames = [
38
- "borderRadius",
39
- "borderBottomColor",
40
- "borderBottomEndRadius",
41
- "borderBottomLeftRadius",
42
- "borderBottomRightRadius",
43
- "borderBottomStartRadius",
44
- "borderBottomWidth",
45
- "borderColor",
46
- "borderEndColor",
47
- "borderLeftColor",
48
- "borderLeftWidth",
49
- "borderRadius",
50
- "borderRightColor",
51
- "borderRightWidth",
52
- "borderStartColor",
53
- "borderStyle",
54
- "borderTopColor",
55
- "borderTopEndRadius",
56
- "borderTopLeftRadius",
57
- "borderTopRightRadius",
58
- "borderTopStartRadius",
59
- "borderTopWidth",
60
- "borderWidth",
61
- ];
62
-
63
- export const marginStyleNames = [
64
- "margin",
65
- "marginBottom",
66
- "marginEnd",
67
- "marginHorizontal",
68
- "marginLeft",
69
- "marginRight",
70
- "marginStart",
71
- "marginTop",
72
- "marginVertical",
73
- ];
74
-
75
- export function extractBorderAndMarginStyles(
76
- style: StyleProp<any>,
77
- additionalBorderStyles?: string[],
78
- additionalMarginStyles?: string[]
79
- ) {
80
- const flatStyle = StyleSheet.flatten(style || {});
81
-
82
- const borderStyles = pickBy(
83
- pick(flatStyle, [
84
- ...borderStyleNames,
85
- ...(additionalBorderStyles ? additionalBorderStyles : []),
86
- ]),
87
- identity
88
- );
89
-
90
- const marginStyles = pickBy(
91
- pick(flatStyle, [
92
- ...marginStyleNames,
93
- ...(additionalMarginStyles ? additionalMarginStyles : []),
94
- ]),
95
- identity
96
- );
97
-
98
- return { borderStyles, marginStyles };
99
- }
100
-
101
37
  /**
102
38
  * Merges a style object on top of another style object. In React Native,
103
39
  * keys with undefined values in a style object will still override styles