@draftbit/core 43.3.0 → 43.3.4-71ace3.2

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/Accordion/AccordionItem.js +21 -5
  2. package/lib/commonjs/components/Accordion/AccordionItem.js.map +1 -1
  3. package/lib/commonjs/components/DeprecatedFAB.js +20 -4
  4. package/lib/commonjs/components/DeprecatedFAB.js.map +1 -1
  5. package/lib/commonjs/components/Elevation.js +3 -14
  6. package/lib/commonjs/components/Elevation.js.map +1 -1
  7. package/lib/commonjs/components/Stepper.js +28 -19
  8. package/lib/commonjs/components/Stepper.js.map +1 -1
  9. package/lib/commonjs/components/ToggleButton.js +86 -0
  10. package/lib/commonjs/components/ToggleButton.js.map +1 -0
  11. package/lib/commonjs/index.js +8 -0
  12. package/lib/commonjs/index.js.map +1 -1
  13. package/lib/commonjs/mappings/ActionSheet.js.map +1 -1
  14. package/lib/commonjs/mappings/RadioButtonRow.js.map +1 -1
  15. package/lib/commonjs/mappings/Stepper.js +9 -0
  16. package/lib/commonjs/mappings/Stepper.js.map +1 -1
  17. package/lib/commonjs/mappings/TextArea.js +10 -1
  18. package/lib/commonjs/mappings/TextArea.js.map +1 -1
  19. package/lib/commonjs/mappings/ToggleButton.js +60 -0
  20. package/lib/commonjs/mappings/ToggleButton.js.map +1 -0
  21. package/lib/commonjs/mappings/Touchable.js.map +1 -1
  22. package/lib/commonjs/mappings/Video.js.map +1 -1
  23. package/lib/commonjs/mappings/WebView.js.map +1 -1
  24. package/lib/module/components/DatePicker/DatePickerComponent.js.map +1 -1
  25. package/lib/module/components/Picker/PickerComponent.android.js +10 -7
  26. package/lib/module/components/Picker/PickerComponent.android.js.map +1 -1
  27. package/lib/module/components/Stepper.js +27 -19
  28. package/lib/module/components/Stepper.js.map +1 -1
  29. package/lib/module/components/ToggleButton.js +67 -0
  30. package/lib/module/components/ToggleButton.js.map +1 -0
  31. package/lib/module/index.js +1 -0
  32. package/lib/module/index.js.map +1 -1
  33. package/lib/module/mappings/Stepper.js +10 -1
  34. package/lib/module/mappings/Stepper.js.map +1 -1
  35. package/lib/module/mappings/TextArea.js +10 -1
  36. package/lib/module/mappings/TextArea.js.map +1 -1
  37. package/lib/module/mappings/ToggleButton.js +51 -0
  38. package/lib/module/mappings/ToggleButton.js.map +1 -0
  39. package/lib/typescript/src/components/Stepper.d.ts +2 -0
  40. package/lib/typescript/src/components/ToggleButton.d.ts +24 -0
  41. package/lib/typescript/src/index.d.ts +1 -0
  42. package/lib/typescript/src/mappings/Stepper.d.ts +22 -0
  43. package/lib/typescript/src/mappings/TextArea.d.ts +10 -1
  44. package/lib/typescript/src/mappings/ToggleButton.d.ts +124 -0
  45. package/package.json +3 -3
  46. package/src/components/Stepper.js +23 -21
  47. package/src/components/Stepper.tsx +27 -19
  48. package/src/components/ToggleButton.js +39 -0
  49. package/src/components/ToggleButton.tsx +94 -0
  50. package/src/index.js +1 -0
  51. package/src/index.tsx +1 -0
  52. package/src/mappings/Stepper.js +10 -1
  53. package/src/mappings/Stepper.ts +10 -0
  54. package/src/mappings/TextArea.js +12 -1
  55. package/src/mappings/TextArea.ts +12 -1
  56. package/src/mappings/ToggleButton.js +50 -0
  57. package/src/mappings/ToggleButton.ts +62 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["ToggleButton.ts"],"names":["GROUPS","COMPONENT_TYPES","createIconProp","createBoolProp","createColorProp","createStaticNumberProp","createFieldNameProp","createIconSizeProp","createActionProp","Triggers","SEED_DATA","name","tag","category","deprecated","layout","triggers","OnPress","props","onPress","icon","required","iconSize","fieldName","defaultValue","valuePropName","disabled","label","description","group","basic","color","colorSecondary","borderColor","width","height","toggled"],"mappings":"AAAA,SACEA,MADF,EAEEC,eAFF,EAGEC,cAHF,EAIEC,cAJF,EAKEC,eALF,EAMEC,sBANF,EAOEC,mBAPF,EAQEC,kBARF,EASEC,gBATF,EAUEC,QAVF,QAWO,iBAXP;AAaA,OAAO,MAAMC,SAAS,GAAG;AACvBC,EAAAA,IAAI,EAAE,eADiB;AAEvBC,EAAAA,GAAG,EAAE,cAFkB;AAGvBC,EAAAA,QAAQ,EAAEZ,eAAe,CAACa,UAHH;AAIvBC,EAAAA,MAAM,EAAE,EAJe;AAKvBC,EAAAA,QAAQ,EAAE,CAACP,QAAQ,CAACQ,OAAV,CALa;AAMvBC,EAAAA,KAAK,EAAE;AACLC,IAAAA,OAAO,EAAEX,gBAAgB,EADpB;AAELY,IAAAA,IAAI,EAAElB,cAAc,CAAC;AACnBmB,MAAAA,QAAQ,EAAE;AADS,KAAD,CAFf;AAKLC,IAAAA,QAAQ,EAAEf,kBAAkB,EALvB;AAMLgB,IAAAA,SAAS,EAAEjB,mBAAmB,CAAC;AAC7BkB,MAAAA,YAAY,EAAE,KADe;AAE7BC,MAAAA,aAAa,EAAE;AAFc,KAAD,CANzB;AAULC,IAAAA,QAAQ,EAAEvB,cAAc,CAAC;AACvBwB,MAAAA,KAAK,EAAE,UADgB;AAEvBC,MAAAA,WAAW,EAAE,uCAFU;AAGvBC,MAAAA,KAAK,EAAE7B,MAAM,CAAC8B;AAHS,KAAD,CAVnB;AAeLC,IAAAA,KAAK,EAAE3B,eAAe,CAAC;AACrByB,MAAAA,KAAK,EAAE7B,MAAM,CAAC8B;AADO,KAAD,CAfjB;AAkBLE,IAAAA,cAAc,EAAE5B,eAAe,CAAC;AAC9BuB,MAAAA,KAAK,EAAE,iBADuB;AAE9BE,MAAAA,KAAK,EAAE7B,MAAM,CAAC8B;AAFgB,KAAD,CAlB1B;AAsBLG,IAAAA,WAAW,EAAE7B,eAAe,CAAC;AAC3BuB,MAAAA,KAAK,EAAE,cADoB;AAE3BE,MAAAA,KAAK,EAAE7B,MAAM,CAAC8B;AAFa,KAAD,CAtBvB;AA0BLI,IAAAA,KAAK,EAAE7B,sBAAsB,CAAC;AAC5BsB,MAAAA,KAAK,EAAE,OADqB;AAE5BC,MAAAA,WAAW,EAAE,OAFe;AAG5BJ,MAAAA,YAAY,EAAE;AAHc,KAAD,CA1BxB;AA+BLW,IAAAA,MAAM,EAAE9B,sBAAsB,CAAC;AAC7BsB,MAAAA,KAAK,EAAE,QADsB;AAE7BC,MAAAA,WAAW,EAAE,QAFgB;AAG7BJ,MAAAA,YAAY,EAAE;AAHe,KAAD,CA/BzB;AAoCLY,IAAAA,OAAO,EAAEjC,cAAc,CAAC;AACtBwB,MAAAA,KAAK,EAAE,SADe;AAEtBC,MAAAA,WAAW,EAAE,kDAFS;AAGtBJ,MAAAA,YAAY,EAAE;AAHQ,KAAD;AApClB;AANgB,CAAlB","sourcesContent":["import {\n GROUPS,\n COMPONENT_TYPES,\n createIconProp,\n createBoolProp,\n createColorProp,\n createStaticNumberProp,\n createFieldNameProp,\n createIconSizeProp,\n createActionProp,\n Triggers,\n} from \"@draftbit/types\";\n\nexport const SEED_DATA = {\n name: \"Toggle Button\",\n tag: \"ToggleButton\",\n category: COMPONENT_TYPES.deprecated,\n layout: {},\n triggers: [Triggers.OnPress],\n props: {\n onPress: createActionProp(),\n icon: createIconProp({\n required: true,\n }),\n iconSize: createIconSizeProp(),\n fieldName: createFieldNameProp({\n defaultValue: false,\n valuePropName: \"toggled\",\n }),\n disabled: createBoolProp({\n label: \"Disabled\",\n description: \"Whether the button should be disabled\",\n group: GROUPS.basic,\n }),\n color: createColorProp({\n group: GROUPS.basic,\n }),\n colorSecondary: createColorProp({\n label: \"Secondary Color\",\n group: GROUPS.basic,\n }),\n borderColor: createColorProp({\n label: \"Border Color\",\n group: GROUPS.basic,\n }),\n width: createStaticNumberProp({\n label: \"Width\",\n description: \"Width\",\n defaultValue: 50,\n }),\n height: createStaticNumberProp({\n label: \"Height\",\n description: \"Height\",\n defaultValue: 50,\n }),\n toggled: createBoolProp({\n label: \"Toggled\",\n description: \"Whether the button should show the toggled state\",\n defaultValue: false,\n }),\n },\n};\n"]}
@@ -4,6 +4,8 @@ import type { Theme } from "../styles/DefaultTheme";
4
4
  import type { IconSlot } from "../interfaces/Icon";
5
5
  declare type Props = {
6
6
  value?: number;
7
+ min?: number;
8
+ max?: number;
7
9
  theme: Theme;
8
10
  style?: StyleProp<ViewStyle>;
9
11
  onChange?: (value: number) => void;
@@ -0,0 +1,24 @@
1
+ import * as React from "react";
2
+ import { colorTypes } from "@draftbit/types";
3
+ import { StyleProp, ViewStyle } from "react-native";
4
+ import type { Theme } from "../styles/DefaultTheme";
5
+ import type { IconSlot } from "../interfaces/Icon";
6
+ declare type Props = {
7
+ icon: string;
8
+ toggled?: boolean;
9
+ onPress?: (value: boolean) => void;
10
+ defaultValue?: boolean;
11
+ disabled?: boolean;
12
+ color?: colorTypes;
13
+ colorSecondary?: colorTypes;
14
+ borderColor?: colorTypes;
15
+ iconSize?: number;
16
+ width?: number;
17
+ height?: number;
18
+ style?: StyleProp<ViewStyle>;
19
+ theme: Theme;
20
+ } & IconSlot;
21
+ declare const _default: React.ComponentType<import("@draftbit/react-theme-provider").$Without<Props, "theme"> & {
22
+ theme?: import("@draftbit/react-theme-provider").$DeepPartial<any> | undefined;
23
+ }> & import("@draftbit/react-theme-provider/typings/hoist-non-react-statics").NonReactStatics<React.ComponentType<Props> & React.FC<Props>, {}>;
24
+ export default _default;
@@ -22,6 +22,7 @@ export { default as StarRating } from "./components/StarRating";
22
22
  export { default as Surface } from "./components/Surface";
23
23
  export { default as Switch, SwitchRow } from "./components/Switch";
24
24
  export { default as TextField } from "./components/TextField";
25
+ export { default as ToggleButton } from "./components/ToggleButton";
25
26
  export { default as Touchable } from "./components/Touchable";
26
27
  export { AccordionGroup, AccordionItem } from "./components/Accordion";
27
28
  export { ActionSheet, ActionSheetItem, ActionSheetCancel, } from "./components/ActionSheet";
@@ -39,5 +39,27 @@ export declare const SEED_DATA: {
39
39
  formType: string;
40
40
  propType: string;
41
41
  };
42
+ min: {
43
+ label: string;
44
+ description: string;
45
+ formType: string;
46
+ propType: string;
47
+ group: string;
48
+ defaultValue: null;
49
+ editable: boolean;
50
+ required: boolean;
51
+ step: number;
52
+ };
53
+ max: {
54
+ label: string;
55
+ description: string;
56
+ formType: string;
57
+ propType: string;
58
+ group: string;
59
+ defaultValue: null;
60
+ editable: boolean;
61
+ required: boolean;
62
+ step: number;
63
+ };
42
64
  };
43
65
  }[];
@@ -4,7 +4,16 @@ export declare const SEED_DATA: {
4
4
  description: string;
5
5
  category: string;
6
6
  layout: {
7
- flex: number;
7
+ borderLeftWidth: number;
8
+ borderRightWidth: number;
9
+ borderTopWidth: number;
10
+ borderBottomWidth: number;
11
+ borderColor: string;
12
+ paddingLeft: number;
13
+ paddingRight: number;
14
+ paddingTop: number;
15
+ paddingBottom: number;
16
+ borderRadius: number;
8
17
  };
9
18
  triggers: string[];
10
19
  props: {
@@ -0,0 +1,124 @@
1
+ export declare const SEED_DATA: {
2
+ name: string;
3
+ tag: string;
4
+ category: string;
5
+ layout: {};
6
+ triggers: string[];
7
+ props: {
8
+ onPress: {
9
+ label: string;
10
+ description: string;
11
+ editable: boolean;
12
+ required: boolean;
13
+ formType: string;
14
+ propType: string;
15
+ defaultValue: null;
16
+ group: string;
17
+ };
18
+ icon: {
19
+ label: string;
20
+ description: string;
21
+ formType: string;
22
+ propType: string;
23
+ defaultValue: string;
24
+ required: boolean;
25
+ editable: boolean;
26
+ group: string;
27
+ };
28
+ iconSize: {
29
+ group: string;
30
+ label: string;
31
+ description: string;
32
+ editable: boolean;
33
+ required: boolean;
34
+ formType: string;
35
+ propType: string;
36
+ defaultValue: number;
37
+ options: number[];
38
+ };
39
+ fieldName: {
40
+ handlerPropName: string;
41
+ group: string;
42
+ label: string;
43
+ description: string;
44
+ formType: string;
45
+ propType: string;
46
+ defaultValue: string;
47
+ valuePropName: string;
48
+ editable: boolean;
49
+ required: boolean;
50
+ };
51
+ disabled: {
52
+ label: string;
53
+ description: string;
54
+ formType: string;
55
+ propType: string;
56
+ defaultValue: boolean;
57
+ editable: boolean;
58
+ required: boolean;
59
+ group: string;
60
+ };
61
+ color: {
62
+ group: string;
63
+ label: string;
64
+ description: string;
65
+ editable: boolean;
66
+ required: boolean;
67
+ defaultValue: null;
68
+ formType: string;
69
+ propType: string;
70
+ };
71
+ colorSecondary: {
72
+ group: string;
73
+ label: string;
74
+ description: string;
75
+ editable: boolean;
76
+ required: boolean;
77
+ defaultValue: null;
78
+ formType: string;
79
+ propType: string;
80
+ };
81
+ borderColor: {
82
+ group: string;
83
+ label: string;
84
+ description: string;
85
+ editable: boolean;
86
+ required: boolean;
87
+ defaultValue: null;
88
+ formType: string;
89
+ propType: string;
90
+ };
91
+ width: {
92
+ label: string;
93
+ description: string;
94
+ formType: string;
95
+ propType: string;
96
+ group: string;
97
+ defaultValue: null;
98
+ editable: boolean;
99
+ required: boolean;
100
+ step: number;
101
+ };
102
+ height: {
103
+ label: string;
104
+ description: string;
105
+ formType: string;
106
+ propType: string;
107
+ group: string;
108
+ defaultValue: null;
109
+ editable: boolean;
110
+ required: boolean;
111
+ step: number;
112
+ };
113
+ toggled: {
114
+ label: string;
115
+ description: string;
116
+ formType: string;
117
+ propType: string;
118
+ defaultValue: boolean;
119
+ editable: boolean;
120
+ required: boolean;
121
+ group: string;
122
+ };
123
+ };
124
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@draftbit/core",
3
- "version": "43.3.0",
3
+ "version": "43.3.4-71ace3.2+71ace3d4",
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": "^43.3.0",
44
+ "@draftbit/types": "^43.3.4-71ace3.2+71ace3d4",
45
45
  "@material-ui/core": "^4.11.0",
46
46
  "@material-ui/pickers": "^3.2.10",
47
47
  "@react-native-community/slider": "4.1.7",
@@ -79,5 +79,5 @@
79
79
  ]
80
80
  ]
81
81
  },
82
- "gitHead": "cee0c8738a921c590f61de7eb85f5e2285950835"
82
+ "gitHead": "71ace3d435b4b435e4af58ef91c77b243e8af91c"
83
83
  }
@@ -2,40 +2,42 @@ import * as React from "react";
2
2
  import { View, Text } from "react-native";
3
3
  import { withTheme } from "../theming";
4
4
  import IconButton from "./IconButton";
5
- const Stepper = ({ Icon, value, style, onChange, defaultValue, theme: { colors, typography, roundness }, iconSize = 24, iconColor = colors.strong, borderRadius = roundness, typeStyle, }) => {
5
+ import isNumber from "lodash.isnumber";
6
+ const Stepper = ({ Icon, value, min, max, style, onChange, defaultValue, theme: { colors, typography, roundness }, iconSize = 24, iconColor = colors.strong, borderRadius = roundness, typeStyle, }) => {
6
7
  const [stateValue, setStateValue] = React.useState(value || defaultValue || 0);
7
8
  React.useEffect(() => {
8
- if (value != null) {
9
- setStateValue(value);
9
+ if (value || value === 0) {
10
+ onChange && onChange(stateValue);
10
11
  }
11
- }, [value]);
12
+ }, [onChange, stateValue, value]);
12
13
  React.useEffect(() => {
13
- if (defaultValue != null) {
14
- setStateValue(defaultValue);
15
- }
16
- }, [defaultValue]);
17
- const handleMinus = () => {
18
- if (value || value === 0) {
19
- onChange && onChange(value - 1);
14
+ let newValue = value || defaultValue || 0;
15
+ if (isNumber(max) && newValue > max) {
16
+ newValue = max;
20
17
  }
21
- else {
22
- setStateValue(stateValue - 1);
18
+ if (isNumber(min) && newValue < min) {
19
+ newValue = min;
23
20
  }
24
- };
25
- const handlePlus = () => {
26
- if (value || value === 0) {
27
- onChange && onChange(value + 1);
21
+ setStateValue(newValue);
22
+ }, [defaultValue, value, min, max]);
23
+ const handleMinus = React.useCallback(() => {
24
+ if (isNumber(min) && value === min) {
25
+ return;
28
26
  }
29
- else {
30
- setStateValue(stateValue + 1);
27
+ setStateValue(stateValue - 1);
28
+ }, [min, stateValue, value]);
29
+ const handlePlus = React.useCallback(() => {
30
+ if (isNumber(max) && value === max) {
31
+ return;
31
32
  }
32
- };
33
+ setStateValue(stateValue + 1);
34
+ }, [max, stateValue, value]);
33
35
  return (React.createElement(View, { style: [
34
36
  { flexDirection: "row" },
35
37
  style,
36
38
  borderRadius ? { borderRadius } : {},
37
39
  ] },
38
- React.createElement(IconButton, { Icon: Icon, icon: "MaterialIcons/remove", onPress: handleMinus, size: iconSize, color: iconColor, disabled: value ? value === 0 : stateValue === 0 }),
40
+ React.createElement(IconButton, { Icon: Icon, icon: "MaterialIcons/remove", onPress: handleMinus, size: iconSize, color: iconColor, disabled: stateValue === 0 }),
39
41
  React.createElement(Text, { style: [
40
42
  typography.body1,
41
43
  {
@@ -5,9 +5,12 @@ import type { Theme } from "../styles/DefaultTheme";
5
5
  import type { IconSlot } from "../interfaces/Icon";
6
6
 
7
7
  import IconButton from "./IconButton";
8
+ import isNumber from "lodash.isnumber";
8
9
 
9
10
  type Props = {
10
11
  value?: number;
12
+ min?: number;
13
+ max?: number;
11
14
  theme: Theme;
12
15
  style?: StyleProp<ViewStyle>;
13
16
  onChange?: (value: number) => void;
@@ -21,6 +24,8 @@ type Props = {
21
24
  const Stepper: React.FC<Props> = ({
22
25
  Icon,
23
26
  value,
27
+ min,
28
+ max,
24
29
  style,
25
30
  onChange,
26
31
  defaultValue,
@@ -35,32 +40,35 @@ const Stepper: React.FC<Props> = ({
35
40
  );
36
41
 
37
42
  React.useEffect(() => {
38
- if (value != null) {
39
- setStateValue(value);
43
+ if (value || value === 0) {
44
+ onChange && onChange(stateValue);
40
45
  }
41
- }, [value]);
46
+ }, [onChange, stateValue, value]);
42
47
 
43
48
  React.useEffect(() => {
44
- if (defaultValue != null) {
45
- setStateValue(defaultValue);
49
+ let newValue = value || defaultValue || 0;
50
+ if (isNumber(max) && newValue > max) {
51
+ newValue = max;
52
+ }
53
+ if (isNumber(min) && newValue < min) {
54
+ newValue = min;
46
55
  }
47
- }, [defaultValue]);
56
+ setStateValue(newValue);
57
+ }, [defaultValue, value, min, max]);
48
58
 
49
- const handleMinus = () => {
50
- if (value || value === 0) {
51
- onChange && onChange(value - 1);
52
- } else {
53
- setStateValue(stateValue - 1);
59
+ const handleMinus = React.useCallback(() => {
60
+ if (isNumber(min) && value === min) {
61
+ return;
54
62
  }
55
- };
63
+ setStateValue(stateValue - 1);
64
+ }, [min, stateValue, value]);
56
65
 
57
- const handlePlus = () => {
58
- if (value || value === 0) {
59
- onChange && onChange(value + 1);
60
- } else {
61
- setStateValue(stateValue + 1);
66
+ const handlePlus = React.useCallback(() => {
67
+ if (isNumber(max) && value === max) {
68
+ return;
62
69
  }
63
- };
70
+ setStateValue(stateValue + 1);
71
+ }, [max, stateValue, value]);
64
72
 
65
73
  return (
66
74
  <View
@@ -76,7 +84,7 @@ const Stepper: React.FC<Props> = ({
76
84
  onPress={handleMinus}
77
85
  size={iconSize}
78
86
  color={iconColor}
79
- disabled={value ? value === 0 : stateValue === 0}
87
+ disabled={stateValue === 0}
80
88
  />
81
89
  <Text
82
90
  style={[
@@ -0,0 +1,39 @@
1
+ import * as React from "react";
2
+ import { withTheme } from "../theming";
3
+ import { StyleSheet } from "react-native";
4
+ import IconButton from "./IconButton";
5
+ const ToggleButton = ({ Icon, icon, toggled = false, onPress = () => { }, defaultValue, disabled = false, color = "primary", colorSecondary = "surface", borderColor = "divider", iconSize = 25, width = 50, height = 50, theme: { colors }, style, ...rest }) => {
6
+ const [internalValue, setInternalValue] = React.useState(toggled || defaultValue || false);
7
+ React.useEffect(() => {
8
+ if (toggled != null) {
9
+ setInternalValue(toggled);
10
+ }
11
+ }, [toggled]);
12
+ React.useEffect(() => {
13
+ if (defaultValue != null) {
14
+ setInternalValue(defaultValue);
15
+ }
16
+ }, [defaultValue]);
17
+ const handlePress = () => {
18
+ setInternalValue(!internalValue);
19
+ onPress(!internalValue);
20
+ };
21
+ return (React.createElement(IconButton, { Icon: Icon, icon: icon, size: iconSize, color: internalValue ? colors[color] : colors[colorSecondary], onPress: handlePress, disabled: disabled, style: [
22
+ styles.mainContainer,
23
+ {
24
+ width,
25
+ height,
26
+ backgroundColor: internalValue
27
+ ? colors[colorSecondary]
28
+ : colors[color],
29
+ borderColor: colors[borderColor],
30
+ },
31
+ style,
32
+ ], ...rest }));
33
+ };
34
+ const styles = StyleSheet.create({
35
+ mainContainer: {
36
+ borderWidth: 1,
37
+ },
38
+ });
39
+ export default withTheme(ToggleButton);
@@ -0,0 +1,94 @@
1
+ import * as React from "react";
2
+ import { withTheme } from "../theming";
3
+ import { colorTypes } from "@draftbit/types";
4
+ import { StyleProp, StyleSheet, ViewStyle } from "react-native";
5
+ import IconButton from "./IconButton";
6
+ import type { Theme } from "../styles/DefaultTheme";
7
+ import type { IconSlot } from "../interfaces/Icon";
8
+
9
+ type Props = {
10
+ icon: string;
11
+ toggled?: boolean;
12
+ onPress?: (value: boolean) => void;
13
+ defaultValue?: boolean;
14
+ disabled?: boolean;
15
+ color?: colorTypes;
16
+ colorSecondary?: colorTypes;
17
+ borderColor?: colorTypes;
18
+ iconSize?: number;
19
+ width?: number;
20
+ height?: number;
21
+ style?: StyleProp<ViewStyle>;
22
+ theme: Theme;
23
+ } & IconSlot;
24
+
25
+ const ToggleButton: React.FC<Props> = ({
26
+ Icon,
27
+ icon,
28
+ toggled = false,
29
+ onPress = () => {},
30
+ defaultValue,
31
+ disabled = false,
32
+ color = "primary",
33
+ colorSecondary = "surface",
34
+ borderColor = "divider",
35
+ iconSize = 25,
36
+ width = 50,
37
+ height = 50,
38
+ theme: { colors },
39
+ style,
40
+ ...rest
41
+ }) => {
42
+ const [internalValue, setInternalValue] = React.useState<boolean>(
43
+ toggled || defaultValue || false
44
+ );
45
+
46
+ React.useEffect(() => {
47
+ if (toggled != null) {
48
+ setInternalValue(toggled);
49
+ }
50
+ }, [toggled]);
51
+
52
+ React.useEffect(() => {
53
+ if (defaultValue != null) {
54
+ setInternalValue(defaultValue);
55
+ }
56
+ }, [defaultValue]);
57
+
58
+ const handlePress = () => {
59
+ setInternalValue(!internalValue);
60
+ onPress(!internalValue);
61
+ };
62
+
63
+ return (
64
+ <IconButton
65
+ Icon={Icon}
66
+ icon={icon}
67
+ size={iconSize}
68
+ color={internalValue ? colors[color] : colors[colorSecondary]}
69
+ onPress={handlePress}
70
+ disabled={disabled}
71
+ style={[
72
+ styles.mainContainer,
73
+ {
74
+ width,
75
+ height,
76
+ backgroundColor: internalValue
77
+ ? colors[colorSecondary]
78
+ : colors[color],
79
+ borderColor: colors[borderColor],
80
+ },
81
+ style,
82
+ ]}
83
+ {...rest}
84
+ />
85
+ );
86
+ };
87
+
88
+ const styles = StyleSheet.create({
89
+ mainContainer: {
90
+ borderWidth: 1,
91
+ },
92
+ });
93
+
94
+ export default withTheme(ToggleButton);
package/src/index.js CHANGED
@@ -22,6 +22,7 @@ export { default as StarRating } from "./components/StarRating";
22
22
  export { default as Surface } from "./components/Surface";
23
23
  export { default as Switch, SwitchRow } from "./components/Switch";
24
24
  export { default as TextField } from "./components/TextField";
25
+ export { default as ToggleButton } from "./components/ToggleButton";
25
26
  export { default as Touchable } from "./components/Touchable";
26
27
  export { AccordionGroup, AccordionItem } from "./components/Accordion";
27
28
  export { ActionSheet, ActionSheetItem, ActionSheetCancel, } from "./components/ActionSheet";
package/src/index.tsx CHANGED
@@ -23,6 +23,7 @@ export { default as StarRating } from "./components/StarRating";
23
23
  export { default as Surface } from "./components/Surface";
24
24
  export { default as Switch, SwitchRow } from "./components/Switch";
25
25
  export { default as TextField } from "./components/TextField";
26
+ export { default as ToggleButton } from "./components/ToggleButton";
26
27
  export { default as Touchable } from "./components/Touchable";
27
28
  export { AccordionGroup, AccordionItem } from "./components/Accordion";
28
29
  export {
@@ -1,4 +1,4 @@
1
- import { COMPONENT_TYPES, createIconSizeProp, createColorProp, createFieldNameProp, Triggers, } from "@draftbit/types";
1
+ import { COMPONENT_TYPES, createIconSizeProp, createColorProp, createFieldNameProp, createStaticNumberProp, Triggers, } from "@draftbit/types";
2
2
  export const SEED_DATA = [
3
3
  {
4
4
  name: "Stepper",
@@ -15,6 +15,15 @@ export const SEED_DATA = [
15
15
  }),
16
16
  iconSize: createIconSizeProp({ defaultValue: 24 }),
17
17
  iconColor: createColorProp({ defaultValue: "strong" }),
18
+ min: createStaticNumberProp({
19
+ label: "Minimum",
20
+ description: "Minimum Number",
21
+ defaultValue: 0,
22
+ }),
23
+ max: createStaticNumberProp({
24
+ label: "Maximum",
25
+ description: "Maximum Number",
26
+ }),
18
27
  },
19
28
  },
20
29
  ];
@@ -3,6 +3,7 @@ import {
3
3
  createIconSizeProp,
4
4
  createColorProp,
5
5
  createFieldNameProp,
6
+ createStaticNumberProp,
6
7
  Triggers,
7
8
  } from "@draftbit/types";
8
9
 
@@ -22,6 +23,15 @@ export const SEED_DATA = [
22
23
  }),
23
24
  iconSize: createIconSizeProp({ defaultValue: 24 }),
24
25
  iconColor: createColorProp({ defaultValue: "strong" }),
26
+ min: createStaticNumberProp({
27
+ label: "Minimum",
28
+ description: "Minimum Number",
29
+ defaultValue: 0,
30
+ }),
31
+ max: createStaticNumberProp({
32
+ label: "Maximum",
33
+ description: "Maximum Number",
34
+ }),
25
35
  },
26
36
  },
27
37
  ];
@@ -4,7 +4,18 @@ export const SEED_DATA = {
4
4
  tag: "TextInput",
5
5
  description: "An input field that allows for multiple lines.",
6
6
  category: COMPONENT_TYPES.input,
7
- layout: { flex: 1 },
7
+ layout: {
8
+ borderLeftWidth: 1,
9
+ borderRightWidth: 1,
10
+ borderTopWidth: 1,
11
+ borderBottomWidth: 1,
12
+ borderColor: "divider",
13
+ paddingLeft: 8,
14
+ paddingRight: 8,
15
+ paddingTop: 8,
16
+ paddingBottom: 8,
17
+ borderRadius: 8,
18
+ },
8
19
  triggers: [Triggers.OnChangeText],
9
20
  props: {
10
21
  ...TEXT_INPUT_PROPS,
@@ -13,7 +13,18 @@ export const SEED_DATA = {
13
13
  tag: "TextInput",
14
14
  description: "An input field that allows for multiple lines.",
15
15
  category: COMPONENT_TYPES.input,
16
- layout: { flex: 1 },
16
+ layout: {
17
+ borderLeftWidth: 1,
18
+ borderRightWidth: 1,
19
+ borderTopWidth: 1,
20
+ borderBottomWidth: 1,
21
+ borderColor: "divider",
22
+ paddingLeft: 8,
23
+ paddingRight: 8,
24
+ paddingTop: 8,
25
+ paddingBottom: 8,
26
+ borderRadius: 8,
27
+ },
17
28
  triggers: [Triggers.OnChangeText],
18
29
  props: {
19
30
  ...TEXT_INPUT_PROPS,