@draftbit/core 47.0.1-cc5ccc.2 → 47.0.1-ed6e56.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 (99) hide show
  1. package/lib/commonjs/components/Button.js +15 -27
  2. package/lib/commonjs/components/Checkbox/Checkbox.js +3 -1
  3. package/lib/commonjs/components/DatePicker/DatePicker.js +1 -0
  4. package/lib/commonjs/components/DatePicker/DatePickerComponent.js +3 -9
  5. package/lib/commonjs/components/DatePicker/DatePickerComponent.web.js +0 -1
  6. package/lib/commonjs/components/DatePicker/DatePickerInput.js +133 -0
  7. package/lib/commonjs/components/DeprecatedButton.js +151 -0
  8. package/lib/commonjs/components/DeprecatedCardWrapper.js +2 -2
  9. package/lib/commonjs/components/DeprecatedFAB.js +2 -1
  10. package/lib/commonjs/components/Picker/Picker.js +4 -3
  11. package/lib/commonjs/components/Picker/PickerComponent.ios.js +2 -2
  12. package/lib/commonjs/components/Touchable.js +11 -27
  13. package/lib/commonjs/components/Touchable.web.js +9 -0
  14. package/lib/commonjs/mappings/Button.js +10 -13
  15. package/lib/commonjs/mappings/Touchable.js +20 -0
  16. package/lib/module/components/Button.js +9 -21
  17. package/lib/module/components/Checkbox/Checkbox.js +3 -2
  18. package/lib/module/components/DatePicker/DatePicker.js +1 -0
  19. package/lib/module/components/DatePicker/DatePickerComponent.js +3 -9
  20. package/lib/module/components/DatePicker/DatePickerComponent.web.js +0 -1
  21. package/lib/module/components/DatePicker/DatePickerInput.js +123 -0
  22. package/lib/module/components/DeprecatedButton.js +141 -0
  23. package/lib/module/components/DeprecatedCardWrapper.js +2 -2
  24. package/lib/module/components/DeprecatedFAB.js +3 -2
  25. package/lib/module/components/Picker/Picker.js +4 -3
  26. package/lib/module/components/Picker/PickerComponent.ios.js +1 -1
  27. package/lib/module/components/Touchable.js +10 -25
  28. package/lib/module/components/Touchable.web.js +2 -0
  29. package/lib/module/mappings/Button.js +11 -14
  30. package/lib/module/mappings/Touchable.js +13 -0
  31. package/lib/typescript/src/components/Button.d.ts +0 -2
  32. package/lib/typescript/src/components/Button.d.ts.map +1 -1
  33. package/lib/typescript/src/components/Checkbox/Checkbox.d.ts +2 -2
  34. package/lib/typescript/src/components/Checkbox/Checkbox.d.ts.map +1 -1
  35. package/lib/typescript/src/components/DatePicker/DatePicker.d.ts.map +1 -1
  36. package/lib/typescript/src/components/DatePicker/DatePickerComponent.d.ts.map +1 -1
  37. package/lib/typescript/src/components/DatePicker/DatePickerComponent.web.d.ts.map +1 -1
  38. package/lib/typescript/src/components/DatePicker/DatePickerComponentType.d.ts +2 -0
  39. package/lib/typescript/src/components/DatePicker/DatePickerComponentType.d.ts.map +1 -1
  40. package/lib/typescript/src/components/DatePicker/DatePickerInput.d.ts +18 -0
  41. package/lib/typescript/src/components/DatePicker/DatePickerInput.d.ts.map +1 -0
  42. package/lib/typescript/src/components/DeprecatedButton.d.ts +54 -0
  43. package/lib/typescript/src/components/DeprecatedButton.d.ts.map +1 -0
  44. package/lib/typescript/src/components/DeprecatedCardWrapper.d.ts.map +1 -1
  45. package/lib/typescript/src/components/DeprecatedFAB.d.ts +2 -2
  46. package/lib/typescript/src/components/DeprecatedFAB.d.ts.map +1 -1
  47. package/lib/typescript/src/components/Picker/Picker.d.ts.map +1 -1
  48. package/lib/typescript/src/components/Touchable.d.ts +2 -9
  49. package/lib/typescript/src/components/Touchable.d.ts.map +1 -1
  50. package/lib/typescript/src/components/Touchable.web.d.ts +3 -0
  51. package/lib/typescript/src/components/Touchable.web.d.ts.map +1 -0
  52. package/lib/typescript/src/mappings/Button.d.ts +4 -113
  53. package/lib/typescript/src/mappings/Button.d.ts.map +1 -1
  54. package/lib/typescript/src/mappings/Touchable.d.ts +22 -0
  55. package/lib/typescript/src/mappings/Touchable.d.ts.map +1 -0
  56. package/package.json +6 -6
  57. package/src/components/Button.js +11 -18
  58. package/src/components/Button.tsx +11 -45
  59. package/src/components/Checkbox/Checkbox.js +3 -2
  60. package/src/components/Checkbox/Checkbox.tsx +7 -5
  61. package/src/components/DatePicker/DatePicker.js +1 -1
  62. package/src/components/DatePicker/DatePicker.tsx +1 -0
  63. package/src/components/DatePicker/DatePickerComponent.js +3 -5
  64. package/src/components/DatePicker/DatePickerComponent.tsx +3 -11
  65. package/src/components/DatePicker/DatePickerComponent.web.js +1 -1
  66. package/src/components/DatePicker/DatePickerComponent.web.tsx +0 -1
  67. package/src/components/DatePicker/DatePickerComponentType.ts +9 -0
  68. package/src/components/DatePicker/DatePickerInput.js +97 -0
  69. package/src/components/DatePicker/DatePickerInput.tsx +195 -0
  70. package/src/components/DeprecatedButton.js +95 -0
  71. package/src/components/DeprecatedButton.tsx +214 -0
  72. package/src/components/DeprecatedCardWrapper.js +2 -2
  73. package/src/components/DeprecatedCardWrapper.tsx +4 -3
  74. package/src/components/DeprecatedFAB.js +3 -2
  75. package/src/components/DeprecatedFAB.tsx +5 -5
  76. package/src/components/Picker/Picker.js +4 -3
  77. package/src/components/Picker/Picker.tsx +4 -4
  78. package/src/components/Picker/PickerComponent.ios.js +1 -1
  79. package/src/components/Picker/PickerComponent.ios.tsx +1 -1
  80. package/src/components/Touchable.js +11 -16
  81. package/src/components/Touchable.tsx +11 -42
  82. package/src/components/Touchable.web.js +2 -0
  83. package/src/components/Touchable.web.tsx +3 -0
  84. package/src/mappings/Button.js +10 -13
  85. package/src/mappings/Button.ts +10 -13
  86. package/src/mappings/Touchable.js +17 -0
  87. package/src/mappings/Touchable.ts +23 -0
  88. package/lib/commonjs/components/Pressable.js +0 -48
  89. package/lib/commonjs/mappings/Pressable.js +0 -52
  90. package/lib/module/components/Pressable.js +0 -40
  91. package/lib/module/mappings/Pressable.js +0 -45
  92. package/lib/typescript/src/components/Pressable.d.ts +0 -18
  93. package/lib/typescript/src/components/Pressable.d.ts.map +0 -1
  94. package/lib/typescript/src/mappings/Pressable.d.ts +0 -76
  95. package/lib/typescript/src/mappings/Pressable.d.ts.map +0 -1
  96. package/src/components/Pressable.js +0 -17
  97. package/src/components/Pressable.tsx +0 -67
  98. package/src/mappings/Pressable.js +0 -52
  99. package/src/mappings/Pressable.ts +0 -63
@@ -515,6 +515,7 @@ const DatePicker: React.FC<React.PropsWithChildren<Props>> = ({
515
515
  <DateTimePicker
516
516
  value={getValidDate()}
517
517
  mode={mode}
518
+ displayMode="default"
518
519
  isVisible={pickerVisible}
519
520
  toggleVisibility={toggleVisibility}
520
521
  onChange={(_event: any, data: any) => {
@@ -1,13 +1,11 @@
1
1
  import React from "react";
2
- import { Platform } from "react-native";
3
- import DateTimePicker from "@react-native-community/datetimepicker";
4
2
  import DateTimePickerModal from "react-native-modal-datetime-picker";
5
- const DatePickerComponent = ({ value, onChange, mode, toggleVisibility, }) => {
6
- return Platform.OS === "ios" || Platform.OS === "android" ? (React.createElement(DateTimePickerModal, { date: value, mode: mode, isVisible: true, display: Platform.OS === "ios" ? "spinner" : "default", onCancel: () => {
3
+ const DatePickerComponent = ({ value, onChange, displayMode = "default", mode, toggleVisibility, }) => {
4
+ return (React.createElement(DateTimePickerModal, { date: value, mode: mode, isVisible: true, display: displayMode, onCancel: () => {
7
5
  console.log("Picker cancelled before selecting anything.");
8
6
  toggleVisibility();
9
7
  }, onConfirm: (data) => {
10
8
  onChange(null, data);
11
- } })) : (React.createElement(DateTimePicker, { value: value, mode: mode, onChange: onChange, display: "default" }));
9
+ } }));
12
10
  };
13
11
  export default DatePickerComponent;
@@ -1,21 +1,20 @@
1
1
  import React from "react";
2
- import { Platform } from "react-native";
3
- import DateTimePicker from "@react-native-community/datetimepicker";
4
2
  import DateTimePickerModal from "react-native-modal-datetime-picker";
5
3
  import { DatePickerComponentProps as Props } from "./DatePickerComponentType";
6
4
 
7
5
  const DatePickerComponent: React.FC<React.PropsWithChildren<Props>> = ({
8
6
  value,
9
7
  onChange,
8
+ displayMode = "default",
10
9
  mode,
11
10
  toggleVisibility,
12
11
  }) => {
13
- return Platform.OS === "ios" || Platform.OS === "android" ? (
12
+ return (
14
13
  <DateTimePickerModal
15
14
  date={value}
16
15
  mode={mode}
17
16
  isVisible={true}
18
- display={Platform.OS === "ios" ? "spinner" : "default"}
17
+ display={displayMode}
19
18
  onCancel={() => {
20
19
  console.log("Picker cancelled before selecting anything.");
21
20
  toggleVisibility();
@@ -24,13 +23,6 @@ const DatePickerComponent: React.FC<React.PropsWithChildren<Props>> = ({
24
23
  onChange(null, data);
25
24
  }}
26
25
  />
27
- ) : (
28
- <DateTimePicker
29
- value={value}
30
- mode={mode}
31
- onChange={onChange}
32
- display={"default"}
33
- />
34
26
  );
35
27
  };
36
28
 
@@ -25,6 +25,6 @@ const DatePickerComponent = ({ value, onChange, mode, toggleVisibility, isVisibl
25
25
  React.createElement(Picker, { value: value, open: isVisible, onChange: (d) => {
26
26
  toggleVisibility();
27
27
  onChange(null, d);
28
- }, onClose: () => toggleVisibility(), variant: "dialog", TextFieldComponent: () => null }))));
28
+ }, onClose: () => toggleVisibility(), TextFieldComponent: () => null }))));
29
29
  };
30
30
  export default withTheme(DatePickerComponent);
@@ -48,7 +48,6 @@ const DatePickerComponent: React.FC<Props & { theme: typeof Theme }> = ({
48
48
  onChange(null, d);
49
49
  }}
50
50
  onClose={() => toggleVisibility()}
51
- variant="dialog"
52
51
  TextFieldComponent={() => null}
53
52
  />
54
53
  </ThemeProvider>
@@ -6,5 +6,14 @@ export interface DatePickerComponentProps {
6
6
  mode: "date" | "time" | "datetime";
7
7
  toggleVisibility: () => void;
8
8
  isVisible?: boolean;
9
+ displayMode?:
10
+ | "default"
11
+ | "compact"
12
+ | "inline"
13
+ | "spinner"
14
+ | "clock"
15
+ | "calendar"
16
+ | undefined;
17
+ variant?: "dialog" | "inline" | undefined;
9
18
  theme?: typeof theme;
10
19
  }
@@ -0,0 +1,97 @@
1
+ import * as React from "react";
2
+ import { View, TextInput, Platform, } from "react-native";
3
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
4
+ import dateFormat from "dateformat";
5
+ import Portal from "../Portal/Portal";
6
+ import Touchable from "../Touchable";
7
+ import DateTimePicker from "./DatePickerComponent";
8
+ const MONTHS = [
9
+ "January",
10
+ "February",
11
+ "March",
12
+ "April",
13
+ "May",
14
+ "June",
15
+ "July",
16
+ "August",
17
+ "September",
18
+ "October",
19
+ "November",
20
+ "December",
21
+ ];
22
+ const DatePickerInput = ({ style, date, onDateChange = () => { }, defaultValue, disabled = false, mode = "date", format, androidDisplay = "default", iosDisplay = "default", webDisplay = "dialog", placeholder, ...props }) => {
23
+ const [value, setValue] = React.useState(date || defaultValue);
24
+ React.useEffect(() => {
25
+ if (defaultValue != null) {
26
+ setValue(defaultValue);
27
+ }
28
+ }, [defaultValue]);
29
+ const [pickerVisible, setPickerVisible] = React.useState(false);
30
+ const [focused, setFocused] = React.useState(false);
31
+ const getValidDate = () => {
32
+ if (!value) {
33
+ return new Date();
34
+ }
35
+ return typeof (value === null || value === void 0 ? void 0 : value.getMonth) === "function" ? value : new Date();
36
+ };
37
+ const formatDate = () => {
38
+ if (!value)
39
+ return "";
40
+ let newDate = getValidDate();
41
+ if (format)
42
+ return dateFormat(newDate, format);
43
+ if (mode === "time") {
44
+ return `${newDate.toLocaleTimeString()}`;
45
+ }
46
+ if (mode === "datetime") {
47
+ return `${newDate.toLocaleString()}`;
48
+ }
49
+ return `${MONTHS[newDate.getMonth()]} ${newDate.getDate()}, ${newDate.getFullYear()}`;
50
+ };
51
+ const toggleVisibility = async () => {
52
+ setPickerVisible(!pickerVisible);
53
+ focused ? _handleBlur() : _handleFocus();
54
+ };
55
+ const insets = useSafeAreaInsets();
56
+ React.useEffect(() => {
57
+ setValue(date);
58
+ }, [date]);
59
+ const _handleFocus = () => {
60
+ if (disabled) {
61
+ return;
62
+ }
63
+ setFocused(true);
64
+ };
65
+ const _handleBlur = () => {
66
+ if (disabled) {
67
+ return;
68
+ }
69
+ setFocused(false);
70
+ };
71
+ return (React.createElement(View, null,
72
+ React.createElement(Touchable, { disabled: disabled, onPress: toggleVisibility },
73
+ React.createElement(TextInput, { value: formatDate(), placeholder: placeholder, editable: !disabled, onFocus: _handleFocus, onBlur: _handleBlur, style: style, ...props })),
74
+ pickerVisible && (React.createElement(Portal, null,
75
+ React.createElement(View, { style: {
76
+ paddingTop: insets.top,
77
+ paddingBottom: insets.bottom,
78
+ paddingLeft: insets.left,
79
+ paddingRight: insets.right,
80
+ } },
81
+ Platform.OS === "web" && (React.createElement(DateTimePicker, { value: getValidDate(), mode: mode, isVisible: pickerVisible, toggleVisibility: toggleVisibility, onChange: (_event, data) => {
82
+ toggleVisibility();
83
+ setValue(data);
84
+ onDateChange(data);
85
+ } })),
86
+ Platform.OS === "ios" && (React.createElement(DateTimePicker, { value: getValidDate(), mode: mode, displayMode: iosDisplay, isVisible: pickerVisible, toggleVisibility: toggleVisibility, onChange: (_event, data) => {
87
+ toggleVisibility();
88
+ setValue(data);
89
+ onDateChange(data);
90
+ } })),
91
+ Platform.OS === "android" && (React.createElement(DateTimePicker, { value: getValidDate(), mode: mode, variant: webDisplay, displayMode: androidDisplay, isVisible: pickerVisible, toggleVisibility: toggleVisibility, onChange: (_event, data) => {
92
+ toggleVisibility();
93
+ setValue(data);
94
+ onDateChange(data);
95
+ } })))))));
96
+ };
97
+ export default DatePickerInput;
@@ -0,0 +1,195 @@
1
+ import * as React from "react";
2
+ import {
3
+ View,
4
+ StyleProp,
5
+ ViewStyle,
6
+ TextInputProps,
7
+ TextInput,
8
+ Platform,
9
+ } from "react-native";
10
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
11
+
12
+ import dateFormat from "dateformat";
13
+ import Portal from "../Portal/Portal";
14
+ import Touchable from "../Touchable";
15
+ import DateTimePicker from "./DatePickerComponent";
16
+
17
+ type Props = {
18
+ style?: StyleProp<ViewStyle>;
19
+ date?: Date;
20
+ format?: string;
21
+ onDateChange?: (data?: Date) => void;
22
+ defaultValue?: Date;
23
+ disabled?: boolean;
24
+ mode?: "date" | "time" | "datetime";
25
+ androidDisplay: "default" | "spinner" | "calendar" | "clock";
26
+ iosDisplay: "default" | "spinner" | "compact" | "inline";
27
+ webDisplay: "dialog" | "inline";
28
+ placeholder?: string;
29
+ } & TextInputProps;
30
+
31
+ const MONTHS = [
32
+ "January",
33
+ "February",
34
+ "March",
35
+ "April",
36
+ "May",
37
+ "June",
38
+ "July",
39
+ "August",
40
+ "September",
41
+ "October",
42
+ "November",
43
+ "December",
44
+ ];
45
+
46
+ const DatePickerInput: React.FC<React.PropsWithChildren<Props>> = ({
47
+ style,
48
+ date,
49
+ onDateChange = () => {},
50
+ defaultValue,
51
+ disabled = false,
52
+ mode = "date",
53
+ format,
54
+ androidDisplay = "default",
55
+ iosDisplay = "default",
56
+ webDisplay = "dialog",
57
+ placeholder,
58
+ ...props
59
+ }) => {
60
+ const [value, setValue] = React.useState<any>(date || defaultValue);
61
+
62
+ React.useEffect(() => {
63
+ if (defaultValue != null) {
64
+ setValue(defaultValue);
65
+ }
66
+ }, [defaultValue]);
67
+
68
+ const [pickerVisible, setPickerVisible] = React.useState(false);
69
+ const [focused, setFocused] = React.useState<boolean>(false);
70
+
71
+ const getValidDate = (): Date => {
72
+ if (!value) {
73
+ return new Date();
74
+ }
75
+ return typeof value?.getMonth === "function" ? value : new Date();
76
+ };
77
+
78
+ const formatDate = (): string => {
79
+ if (!value) return "";
80
+ let newDate = getValidDate();
81
+
82
+ if (format) return dateFormat(newDate, format);
83
+
84
+ if (mode === "time") {
85
+ return `${newDate.toLocaleTimeString()}`;
86
+ }
87
+
88
+ if (mode === "datetime") {
89
+ return `${newDate.toLocaleString()}`;
90
+ }
91
+
92
+ return `${
93
+ MONTHS[newDate.getMonth()]
94
+ } ${newDate.getDate()}, ${newDate.getFullYear()}`;
95
+ };
96
+
97
+ const toggleVisibility = async () => {
98
+ setPickerVisible(!pickerVisible);
99
+ focused ? _handleBlur() : _handleFocus();
100
+ };
101
+
102
+ const insets = useSafeAreaInsets();
103
+
104
+ React.useEffect(() => {
105
+ setValue(date);
106
+ }, [date]);
107
+
108
+ const _handleFocus = () => {
109
+ if (disabled) {
110
+ return;
111
+ }
112
+
113
+ setFocused(true);
114
+ };
115
+
116
+ const _handleBlur = () => {
117
+ if (disabled) {
118
+ return;
119
+ }
120
+ setFocused(false);
121
+ };
122
+
123
+ return (
124
+ <View>
125
+ <Touchable disabled={disabled} onPress={toggleVisibility}>
126
+ <TextInput
127
+ value={formatDate()}
128
+ placeholder={placeholder}
129
+ editable={!disabled}
130
+ onFocus={_handleFocus}
131
+ onBlur={_handleBlur}
132
+ style={style}
133
+ {...props}
134
+ />
135
+ </Touchable>
136
+ {pickerVisible && (
137
+ <Portal>
138
+ <View
139
+ style={{
140
+ paddingTop: insets.top,
141
+ paddingBottom: insets.bottom,
142
+ paddingLeft: insets.left,
143
+ paddingRight: insets.right,
144
+ }}
145
+ >
146
+ {Platform.OS === "web" && (
147
+ <DateTimePicker
148
+ value={getValidDate()}
149
+ mode={mode}
150
+ isVisible={pickerVisible}
151
+ toggleVisibility={toggleVisibility}
152
+ onChange={(_event: any, data: any) => {
153
+ toggleVisibility();
154
+ setValue(data);
155
+ onDateChange(data);
156
+ }}
157
+ />
158
+ )}
159
+ {Platform.OS === "ios" && (
160
+ <DateTimePicker
161
+ value={getValidDate()}
162
+ mode={mode}
163
+ displayMode={iosDisplay}
164
+ isVisible={pickerVisible}
165
+ toggleVisibility={toggleVisibility}
166
+ onChange={(_event: any, data: any) => {
167
+ toggleVisibility();
168
+ setValue(data);
169
+ onDateChange(data);
170
+ }}
171
+ />
172
+ )}
173
+ {Platform.OS === "android" && (
174
+ <DateTimePicker
175
+ value={getValidDate()}
176
+ mode={mode}
177
+ variant={webDisplay}
178
+ displayMode={androidDisplay}
179
+ isVisible={pickerVisible}
180
+ toggleVisibility={toggleVisibility}
181
+ onChange={(_event: any, data: any) => {
182
+ toggleVisibility();
183
+ setValue(data);
184
+ onDateChange(data);
185
+ }}
186
+ />
187
+ )}
188
+ </View>
189
+ </Portal>
190
+ )}
191
+ </View>
192
+ );
193
+ };
194
+
195
+ export default DatePickerInput;
@@ -0,0 +1,95 @@
1
+ import * as React from "react";
2
+ import { ActivityIndicator, View, Text, StyleSheet, } from "react-native";
3
+ import color from "color";
4
+ import Config from "./Config";
5
+ import Touchable from "./Touchable";
6
+ import Elevation from "./Elevation";
7
+ import { withTheme } from "../theming";
8
+ const Button = ({ Icon, icon, disabled = false, type = "solid", loading = false, labelColor, color: colorOverride, children, onPress, elevation = 0, style, theme: { colors, disabledOpacity, roundness, typography }, ...rest }) => {
9
+ let backgroundColor, borderColor, textColor, borderWidth;
10
+ const buttonColor = colorOverride || colors.primary;
11
+ if (type === "solid") {
12
+ backgroundColor = buttonColor;
13
+ if (disabled) {
14
+ textColor = color(colors.surface).alpha(disabledOpacity).rgb().string();
15
+ }
16
+ else {
17
+ textColor = labelColor || colors.surface;
18
+ }
19
+ }
20
+ else {
21
+ backgroundColor = "transparent";
22
+ if (disabled) {
23
+ textColor = color(buttonColor).alpha(disabledOpacity).rgb().string();
24
+ }
25
+ else {
26
+ textColor = labelColor || buttonColor;
27
+ }
28
+ }
29
+ if (type === "outline") {
30
+ if (disabled) {
31
+ borderColor = color(buttonColor).alpha(disabledOpacity).rgb().string();
32
+ }
33
+ else {
34
+ borderColor = buttonColor;
35
+ }
36
+ borderWidth = StyleSheet.hairlineWidth;
37
+ }
38
+ else {
39
+ borderColor = "transparent";
40
+ borderWidth = 0;
41
+ }
42
+ const buttonStyle = {
43
+ backgroundColor,
44
+ borderColor,
45
+ borderWidth,
46
+ borderRadius: roundness,
47
+ };
48
+ const textStyle = {
49
+ textAlign: "center",
50
+ color: textColor,
51
+ marginVertical: 16,
52
+ marginHorizontal: 16,
53
+ };
54
+ const iconStyle = [
55
+ styles.icon,
56
+ {
57
+ marginLeft: 16,
58
+ marginRight: -8,
59
+ width: Config.buttonIconSize,
60
+ },
61
+ ];
62
+ const { margin, marginEnd, marginTop, marginLeft, marginRight, marginBottom, marginHorizontal, marginVertical, ...innerStyles } = StyleSheet.flatten(style || {});
63
+ const margins = {
64
+ margin,
65
+ marginEnd,
66
+ marginTop,
67
+ marginLeft,
68
+ marginRight,
69
+ marginBottom,
70
+ marginHorizontal,
71
+ marginVertical,
72
+ };
73
+ return (React.createElement(Elevation, { style: { elevation, alignSelf: "stretch", ...margins } },
74
+ React.createElement(Touchable, { ...rest, onPress: onPress, accessibilityState: { disabled }, accessibilityRole: "button", disabled: disabled || loading, style: [styles.button, buttonStyle, innerStyles] },
75
+ React.createElement(View, { style: styles.content },
76
+ icon && loading !== true ? (React.createElement(View, { style: iconStyle },
77
+ React.createElement(Icon, { name: icon, size: Config.buttonIconSize, color: textColor }))) : null,
78
+ loading ? (React.createElement(ActivityIndicator, { size: "small", color: textColor, style: iconStyle })) : null,
79
+ React.createElement(Text, { numberOfLines: 1, style: [textStyle, typography.button] }, children)))));
80
+ };
81
+ const styles = StyleSheet.create({
82
+ button: {
83
+ minWidth: 64,
84
+ borderStyle: "solid",
85
+ },
86
+ content: {
87
+ flexDirection: "row",
88
+ alignItems: "center",
89
+ justifyContent: "center",
90
+ },
91
+ icon: {
92
+ width: Config.buttonIconSize,
93
+ },
94
+ });
95
+ export default withTheme(Button);
@@ -0,0 +1,214 @@
1
+ import * as React from "react";
2
+ import {
3
+ ActivityIndicator,
4
+ View,
5
+ Text,
6
+ StyleSheet,
7
+ TouchableHighlightProps,
8
+ StyleProp,
9
+ ViewStyle,
10
+ TextStyle,
11
+ } from "react-native";
12
+ import color from "color";
13
+ import Config from "./Config";
14
+ import Touchable from "./Touchable";
15
+ import Elevation from "./Elevation";
16
+ import { withTheme } from "../theming";
17
+
18
+ import type { Theme } from "../styles/DefaultTheme";
19
+ import type { IconSlot } from "../interfaces/Icon";
20
+
21
+ /**
22
+ * A button is component that the user can press to trigger an action.
23
+ *
24
+ * <div class="screenshots">
25
+ * <figure>
26
+ * <img src="screenshots/button-1.png" />
27
+ * <figcaption>Text button</figcaption>
28
+ * </figure>
29
+ * <figure>
30
+ * <img src="screenshots/button-2.png" />
31
+ * <figcaption>Outlined button</figcaption>
32
+ * </figure>
33
+ * <figure>
34
+ * <img src="screenshots/button-3.png" />
35
+ * <figcaption>Contained button</figcaption>
36
+ * </figure>
37
+ * </div>
38
+ *
39
+ * ## Usage
40
+ * ```js
41
+ * import * as React from 'react';
42
+ * import { Button } from '@draftbit/ui';
43
+ *
44
+ * const MyComponent = () => (
45
+ * <Button icon="add-a-photo" type="solid" onPress={() => console.log('Pressed')}>
46
+ * Press me
47
+ * </Button>
48
+ * );
49
+ *
50
+ * export default MyComponent;
51
+ * ```
52
+ */
53
+
54
+ type Props = {
55
+ disabled?: boolean;
56
+ type?: "solid" | "outline" | "text";
57
+ loading?: boolean;
58
+ icon?: string;
59
+ labelColor?: string;
60
+ color?: string;
61
+ children?: React.ReactNode;
62
+ onPress: () => void;
63
+ elevation?: number;
64
+ style?: StyleProp<ViewStyle>;
65
+ theme: Theme;
66
+ } & TouchableHighlightProps &
67
+ IconSlot;
68
+
69
+ const Button: React.FC<React.PropsWithChildren<Props>> = ({
70
+ Icon,
71
+ icon,
72
+ disabled = false,
73
+ type = "solid",
74
+ loading = false,
75
+ labelColor,
76
+ color: colorOverride,
77
+ children,
78
+ onPress,
79
+ elevation = 0,
80
+ style,
81
+ theme: { colors, disabledOpacity, roundness, typography },
82
+ ...rest
83
+ }) => {
84
+ let backgroundColor, borderColor, textColor, borderWidth;
85
+ const buttonColor = colorOverride || colors.primary;
86
+
87
+ if (type === "solid") {
88
+ backgroundColor = buttonColor;
89
+
90
+ if (disabled) {
91
+ textColor = color(colors.surface).alpha(disabledOpacity).rgb().string();
92
+ } else {
93
+ textColor = labelColor || colors.surface;
94
+ }
95
+ } else {
96
+ backgroundColor = "transparent";
97
+
98
+ if (disabled) {
99
+ textColor = color(buttonColor).alpha(disabledOpacity).rgb().string();
100
+ } else {
101
+ textColor = labelColor || buttonColor;
102
+ }
103
+ }
104
+
105
+ if (type === "outline") {
106
+ if (disabled) {
107
+ borderColor = color(buttonColor).alpha(disabledOpacity).rgb().string();
108
+ } else {
109
+ borderColor = buttonColor;
110
+ }
111
+ borderWidth = StyleSheet.hairlineWidth;
112
+ } else {
113
+ borderColor = "transparent";
114
+ borderWidth = 0;
115
+ }
116
+
117
+ const buttonStyle = {
118
+ backgroundColor,
119
+ borderColor,
120
+ borderWidth,
121
+ borderRadius: roundness,
122
+ };
123
+
124
+ const textStyle: StyleProp<TextStyle> = {
125
+ textAlign: "center",
126
+ color: textColor,
127
+ marginVertical: 16,
128
+ marginHorizontal: 16,
129
+ };
130
+
131
+ const iconStyle = [
132
+ styles.icon,
133
+ {
134
+ marginLeft: 16,
135
+ marginRight: -8,
136
+ width: Config.buttonIconSize,
137
+ },
138
+ ];
139
+
140
+ const {
141
+ margin,
142
+ marginEnd,
143
+ marginTop,
144
+ marginLeft,
145
+ marginRight,
146
+ marginBottom,
147
+ marginHorizontal,
148
+ marginVertical,
149
+ ...innerStyles
150
+ } = StyleSheet.flatten(style || {});
151
+
152
+ const margins = {
153
+ margin,
154
+ marginEnd,
155
+ marginTop,
156
+ marginLeft,
157
+ marginRight,
158
+ marginBottom,
159
+ marginHorizontal,
160
+ marginVertical,
161
+ };
162
+
163
+ return (
164
+ <Elevation style={{ elevation, alignSelf: "stretch", ...margins }}>
165
+ <Touchable
166
+ {...rest}
167
+ onPress={onPress}
168
+ accessibilityState={{ disabled }}
169
+ accessibilityRole="button"
170
+ disabled={disabled || loading}
171
+ style={[styles.button, buttonStyle, innerStyles]}
172
+ >
173
+ <View style={styles.content}>
174
+ {icon && loading !== true ? (
175
+ <View style={iconStyle}>
176
+ <Icon
177
+ name={icon}
178
+ size={Config.buttonIconSize}
179
+ color={textColor}
180
+ />
181
+ </View>
182
+ ) : null}
183
+ {loading ? (
184
+ <ActivityIndicator
185
+ size="small"
186
+ color={textColor}
187
+ style={iconStyle}
188
+ />
189
+ ) : null}
190
+ <Text numberOfLines={1} style={[textStyle, typography.button]}>
191
+ {children}
192
+ </Text>
193
+ </View>
194
+ </Touchable>
195
+ </Elevation>
196
+ );
197
+ };
198
+
199
+ const styles = StyleSheet.create({
200
+ button: {
201
+ minWidth: 64,
202
+ borderStyle: "solid",
203
+ },
204
+ content: {
205
+ flexDirection: "row",
206
+ alignItems: "center",
207
+ justifyContent: "center",
208
+ },
209
+ icon: {
210
+ width: Config.buttonIconSize,
211
+ },
212
+ });
213
+
214
+ export default withTheme(Button);