ferns-ui 0.6.0 → 0.6.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.
package/dist/Button.d.ts CHANGED
@@ -1,20 +1,17 @@
1
1
  import React from "react";
2
- import { ButtonProps, Color } from "./Common";
3
- interface ButtonState {
4
- loading: boolean;
2
+ import { ButtonColor, Color, GestaltIconName, IconPrefix } from "./Common";
3
+ export interface ButtonProps {
4
+ children?: React.ReactElement;
5
+ text: string;
6
+ color?: ButtonColor | Color;
7
+ disabled?: boolean;
8
+ inline?: boolean;
9
+ size?: "sm" | "md" | "lg";
10
+ type?: "solid" | "ghost" | "outline";
11
+ loading?: boolean;
12
+ onClick: any;
13
+ icon?: GestaltIconName | string;
14
+ iconPrefix?: IconPrefix;
15
+ iconColor?: ButtonColor | Color;
5
16
  }
6
- export declare class Button extends React.Component<ButtonProps, ButtonState> {
7
- state: {
8
- loading: boolean;
9
- };
10
- HEIGHTS: {
11
- sm: number;
12
- md: number;
13
- lg: number;
14
- };
15
- getBackgroundColor(color: string): string;
16
- getTextColor(color: Color): Color;
17
- getBorderColor(color: string): string;
18
- render(): JSX.Element;
19
- }
20
- export {};
17
+ export declare function Button({ disabled, type, loading: propsLoading, children, text, inline, icon, iconPrefix, size, onClick, color, }: ButtonProps): JSX.Element;
package/dist/Button.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import debounce from "lodash/debounce";
2
- import React from "react";
2
+ import React, { useState } from "react";
3
3
  import { ActivityIndicator, TouchableOpacity } from "react-native";
4
4
  import { Box } from "./Box";
5
5
  import { Icon } from "./Icon";
6
- // import {Icon} from "./Icon";
7
6
  import { Text } from "./Text";
8
7
  import { Unifier } from "./Unifier";
9
8
  const buttonTextColor = {
@@ -20,83 +19,77 @@ const buttonTextColor = {
20
19
  twitter: "white",
21
20
  google: "white",
22
21
  };
23
- export class Button extends React.Component {
24
- constructor() {
25
- super(...arguments);
26
- this.state = { loading: false };
27
- this.HEIGHTS = {
28
- sm: 36,
29
- md: 40,
30
- lg: 48,
31
- };
32
- }
33
- getBackgroundColor(color) {
34
- if (this.props.type === "ghost" || this.props.type === "outline") {
22
+ const HEIGHTS = {
23
+ sm: 36,
24
+ md: 40,
25
+ lg: 48,
26
+ };
27
+ export function Button({ disabled, type, loading: propsLoading, children, text, inline, icon, iconPrefix, size, onClick, color = "lightGray", }) {
28
+ const [loading, setLoading] = useState(propsLoading);
29
+ const getBackgroundColor = (backgroundColor) => {
30
+ if (type === "ghost" || type === "outline") {
35
31
  return "transparent";
36
32
  }
37
33
  else {
38
- return Unifier.theme[color];
34
+ return Unifier.theme[backgroundColor];
39
35
  }
40
- }
41
- getTextColor(color) {
42
- if (this.props.type === "ghost" || this.props.type === "outline") {
43
- return color;
36
+ };
37
+ const getTextColor = (textColor) => {
38
+ if (type === "ghost" || type === "outline") {
39
+ return textColor;
44
40
  }
45
- else if (color === undefined) {
41
+ else if (textColor === undefined) {
46
42
  return "darkGray";
47
43
  }
48
44
  else {
49
- return buttonTextColor[color] || "white";
45
+ return buttonTextColor[textColor] || "white";
50
46
  }
51
- }
52
- getBorderColor(color) {
53
- if (this.props.type === "outline") {
54
- return Unifier.theme[this.getTextColor(color)];
47
+ };
48
+ const getBorderColor = (borderColor) => {
49
+ if (type === "outline") {
50
+ return Unifier.theme[getTextColor(borderColor)];
55
51
  }
56
52
  else {
57
53
  return "transparent";
58
54
  }
55
+ };
56
+ if (color === "gray") {
57
+ color = "lightGray";
59
58
  }
60
- render() {
61
- let color = this.props.color || "lightGray";
62
- if (color === "gray") {
63
- color = "lightGray";
64
- }
65
- return (React.createElement(TouchableOpacity, { disabled: this.props.disabled || this.props.loading, style: {
66
- alignSelf: this.props.inline === true ? undefined : "stretch",
67
- height: this.HEIGHTS[this.props.size || "md"],
68
- backgroundColor: this.getBackgroundColor(color),
69
- // width: this.props.inline === true ? undefined : "100%",
70
- flexShrink: this.props.inline ? 1 : 0,
71
- // flexGrow: this.props.inline ? 0 : 1,
72
- alignItems: "center",
73
- justifyContent: "center",
74
- borderRadius: 5,
75
- borderColor: this.getBorderColor(color),
76
- borderWidth: this.props.type === "outline" ? 2 : 0,
77
- opacity: this.props.disabled ? 0.4 : 1,
78
- flexDirection: "row",
79
- paddingHorizontal: 4 * 2,
80
- }, onPress: debounce(async () => {
81
- Unifier.utils.haptic();
82
- this.setState({ loading: true });
83
- try {
84
- if (this.props.onClick) {
85
- await this.props.onClick();
86
- }
87
- }
88
- catch (e) {
89
- this.setState({ loading: false });
90
- throw e;
59
+ return (React.createElement(TouchableOpacity, { disabled: disabled || loading, style: {
60
+ alignSelf: inline === true ? undefined : "stretch",
61
+ height: HEIGHTS[size || "md"],
62
+ backgroundColor: getBackgroundColor(color),
63
+ // width: inline === true ? undefined : "100%",
64
+ flexShrink: inline ? 1 : 0,
65
+ // flexGrow: inline ? 0 : 1,
66
+ alignItems: "center",
67
+ justifyContent: "center",
68
+ borderRadius: 5,
69
+ borderColor: getBorderColor(color),
70
+ borderWidth: type === "outline" ? 2 : 0,
71
+ opacity: disabled ? 0.4 : 1,
72
+ flexDirection: "row",
73
+ paddingHorizontal: 4 * 2,
74
+ }, onPress: debounce(async () => {
75
+ Unifier.utils.haptic();
76
+ setLoading(true);
77
+ try {
78
+ if (onClick) {
79
+ await onClick();
91
80
  }
92
- this.setState({ loading: false });
93
- }, 500, { leading: true }) },
94
- this.props.icon !== undefined && (React.createElement(Box, { paddingX: 2 },
95
- React.createElement(Icon, { color: this.getTextColor(this.props.color), name: this.props.icon, prefix: this.props.iconPrefix || "far", size: this.props.size }))),
96
- Boolean(this.props.children) && this.props.children,
97
- Boolean(this.props.text) && (React.createElement(Text, { color: this.getTextColor(color), font: "button", inline: this.props.inline, size: this.props.size, skipLinking: true, weight: "bold" }, this.props.text)),
98
- (this.state.loading || this.props.loading) && (React.createElement(Box, { marginLeft: 2 },
99
- React.createElement(ActivityIndicator, { color: this.getTextColor(color), size: "small" })))));
100
- }
81
+ }
82
+ catch (e) {
83
+ setLoading(false);
84
+ throw e;
85
+ }
86
+ setLoading(false);
87
+ }, 500, { leading: true }) },
88
+ icon !== undefined && (React.createElement(Box, { paddingX: 2 },
89
+ React.createElement(Icon, { color: getTextColor(color), name: icon, prefix: iconPrefix || "far", size: size }))),
90
+ Boolean(children) && children,
91
+ Boolean(text) && (React.createElement(Text, { color: getTextColor(color), font: "button", inline: inline, size: size, skipLinking: true, weight: "bold" }, text)),
92
+ (loading || loading) && (React.createElement(Box, { marginLeft: 2 },
93
+ React.createElement(ActivityIndicator, { color: getTextColor(color), size: "small" })))));
101
94
  }
102
95
  //# sourceMappingURL=Button.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Button.js","sourceRoot":"","sources":["../src/Button.tsx"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,iBAAiB,EAAE,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAGjE,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,+BAA+B;AAC/B,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAMlC,MAAM,eAAe,GAAkD;IACrE,IAAI,EAAE,OAAO;IACb,SAAS,EAAE,UAAU;IACrB,GAAG,EAAE,OAAO;IACZ,WAAW,EAAE,OAAO;IACpB,KAAK,EAAE,UAAU;IACjB,OAAO,EAAE,OAAO;IAChB,SAAS,EAAE,OAAO;IAClB,MAAM,EAAE,OAAO;IACf,QAAQ,EAAE,OAAO;IACjB,QAAQ,EAAE,OAAO;IACjB,OAAO,EAAE,OAAO;IAChB,MAAM,EAAE,OAAO;CAChB,CAAC;AAEF,MAAM,OAAO,MAAO,SAAQ,KAAK,CAAC,SAAmC;IAArE;;QACE,UAAK,GAAG,EAAC,O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CACnE,CACP,CACgB,CACpB,CAAC;AACJ,CAAC"}
package/dist/Common.d.ts CHANGED
@@ -288,19 +288,6 @@ export interface BoxProps {
288
288
  onLayout?: (event: any) => void;
289
289
  }
290
290
  export declare type BoxColor = AllColors | "transparent";
291
- export interface ButtonProps {
292
- text: string;
293
- color?: ButtonColor | Color;
294
- disabled?: boolean;
295
- inline?: boolean;
296
- size?: "sm" | "md" | "lg";
297
- type?: "solid" | "ghost" | "outline";
298
- loading?: boolean;
299
- onClick: any;
300
- icon?: GestaltIconName | string;
301
- iconPrefix?: IconPrefix;
302
- iconColor?: ButtonColor | Color;
303
- }
304
291
  export interface DrawerProps {
305
292
  animationOpenTime: number;
306
293
  animationCloseTime: number;
@@ -1 +1 @@
1
- {"version":3,"file":"Common.js","sourceRoot":"","sources":["../src/Common.ts"],"names":[],"mappings":"AAgVA,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC;AAkBzB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAe,EAAE,EAAE;IAClD,OAAO;QACL,EAAE,EAAE,CAAC;QACL,EAAE,EAAE,EAAE;QACN,EAAE,EAAE,EAAE;QACN,EAAE,EAAE,EAAE;QACN,EAAE,EAAE,EAAE;KACP,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAI,GAAG,EAAE,EAAY,EAAE;IACtD,IAAI,QAAkB,CAAC;IACvB,IAAI,IAAI,GAAG,CAAC,EAAE;QACZ,QAAQ,GAAG,IAAI,CAAC;KACjB;SAAM,IAAI,IAAI,GAAG,EAAE,EAAE;QACpB,QAAQ,GAAG,IAAI,CAAC;KACjB;SAAM,IAAI,IAAI,GAAG,EAAE,EAAE;QACpB,QAAQ,GAAG,IAAI,CAAC;KACjB;SAAM,IAAI,IAAI,GAAG,EAAE,EAAE;QACpB,QAAQ,GAAG,IAAI,CAAC;KACjB;SAAM;QACL,QAAQ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SAAM,IAAI,IAAI,GAAG,EAAE,EAAE;QACpB,QAAQ,GAAG,IAAI,CAAC;KACjB;SAAM,IAAI,IAAI,GAAG,EAAE,EAAE;QACpB,QAAQ,GAAG,IAAI,CAAC;KACjB;SAAM;QACL,QAAQ,GAAG,IAAI,CAAC;KACjB;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,UAAU,eAAe,CAAC,OAAgE;IAC9F,OAAO,CAAC;QACN,SAAS,EAAE,QAAQ;QACnB,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,QAAQ;QAChB,KAAK,EAAE,KAAK;QACZ,cAAc,EAAE,KAAK;QACrB,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE,MAAM;KACjB,CAAC,OAAO,CAAC,IAAI,MAAM,CAAU,CAAC;AACjC,CAAC;AAq4BD,MAAM,UAAU,UAAU,CAAC,OAAqB;IAC9C,OAAO,CACL,OAAO;QACP,OAAO,CAAC,KAAK;QACb,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CACrF,CAAC;AACJ,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
2
  interface ImageBackgroundProps {
3
+ children?: any;
3
4
  style?: any;
4
5
  source: any;
5
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ImageBackground.js","sourceRoot":"","sources":["../src/ImageBackground.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,eAAe,IAAI,qBAAqB,EAAC,MAAM,cAAc,CAAC;AAOtE,MAAM,OAAO,eAAgB,SAAQ,KAAK,CAAC,SAAmC;IAC5E,MAAM;QACJ,OAAO,oBAAC,qBAAqB,oBAAK,IAAI,CAAC,KAAK,EAAI,CAAC;IACnD,CAAC;CACF"}
1
+ {"version":3,"file":"ImageBackground.js","sourceRoot":"","sources":["../src/ImageBackground.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,eAAe,IAAI,qBAAqB,EAAC,MAAM,cAAc,CAAC;AAQtE,MAAM,OAAO,eAAgB,SAAQ,KAAK,CAAC,SAAmC;IAC5E,MAAM;QACJ,OAAO,oBAAC,qBAAqB,oBAAK,IAAI,CAAC,KAAK,EAAI,CAAC;IACnD,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ferns-ui",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "main": "dist/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "scripts": {
@@ -158,7 +158,6 @@
158
158
  "react-native-gesture-handler": "^2.1.0",
159
159
  "react-native-haptic-feedback": "^1.10.0",
160
160
  "react-native-modalize": "^2.0.12",
161
- "react-native-navigation": "^6.12.0",
162
161
  "react-native-permissions": "^3.1.0",
163
162
  "react-native-picker-select": "^8.0.0",
164
163
  "react-native-portalize": "^1.0.7",
@@ -189,7 +188,6 @@
189
188
  "react-native-gesture-handler": "^2.1.0",
190
189
  "react-native-haptic-feedback": "^1.10.0",
191
190
  "react-native-modalize": "^2.0.12",
192
- "react-native-navigation": "^6.12.0",
193
191
  "react-native-permissions": "^3.1.0",
194
192
  "react-native-picker-select": "^8.0.0",
195
193
  "react-native-portalize": "^1.0.7",
package/src/Button.tsx CHANGED
@@ -1,17 +1,30 @@
1
1
  import debounce from "lodash/debounce";
2
- import React from "react";
2
+ import React, {useState} from "react";
3
3
  import {ActivityIndicator, TouchableOpacity} from "react-native";
4
4
 
5
- import {UnifiedTheme} from ".";
6
5
  import {Box} from "./Box";
7
- import {ButtonProps, Color} from "./Common";
6
+ import {ButtonColor, Color, GestaltIconName, IconPrefix, UnifiedTheme} from "./Common";
8
7
  import {Icon} from "./Icon";
9
- // import {Icon} from "./Icon";
10
8
  import {Text} from "./Text";
11
9
  import {Unifier} from "./Unifier";
12
10
 
13
- interface ButtonState {
14
- loading: boolean;
11
+ export interface ButtonProps {
12
+ children?: React.ReactElement;
13
+ text: string;
14
+ // TODO make this work for all colors
15
+ color?: ButtonColor | Color;
16
+ // default gray
17
+ disabled?: boolean; // default false
18
+ inline?: boolean; // default false
19
+ size?: "sm" | "md" | "lg"; // default md
20
+
21
+ // Pattern Addition
22
+ type?: "solid" | "ghost" | "outline";
23
+ loading?: boolean;
24
+ onClick: any;
25
+ icon?: GestaltIconName | string;
26
+ iconPrefix?: IconPrefix;
27
+ iconColor?: ButtonColor | Color;
15
28
  }
16
29
 
17
30
  const buttonTextColor: {[buttonColor: string]: "white" | "darkGray"} = {
@@ -29,112 +42,121 @@ const buttonTextColor: {[buttonColor: string]: "white" | "darkGray"} = {
29
42
  google: "white",
30
43
  };
31
44
 
32
- export class Button extends React.Component<ButtonProps, ButtonState> {
33
- state = {loading: false};
45
+ const HEIGHTS = {
46
+ sm: 36,
47
+ md: 40,
48
+ lg: 48,
49
+ };
34
50
 
35
- HEIGHTS = {
36
- sm: 36,
37
- md: 40,
38
- lg: 48,
39
- };
51
+ export function Button({
52
+ disabled,
53
+ type,
54
+ loading: propsLoading,
55
+ children,
56
+ text,
57
+ inline,
58
+ icon,
59
+ iconPrefix,
60
+ size,
61
+ onClick,
62
+ color = "lightGray",
63
+ }: ButtonProps) {
64
+ const [loading, setLoading] = useState(propsLoading);
40
65
 
41
- getBackgroundColor(color: string): string {
42
- if (this.props.type === "ghost" || this.props.type === "outline") {
66
+ const getBackgroundColor = (backgroundColor: string): string => {
67
+ if (type === "ghost" || type === "outline") {
43
68
  return "transparent";
44
69
  } else {
45
- return Unifier.theme[color as keyof UnifiedTheme] as string;
70
+ return Unifier.theme[backgroundColor as keyof UnifiedTheme];
46
71
  }
47
- }
72
+ };
48
73
 
49
- getTextColor(color: Color): Color {
50
- if (this.props.type === "ghost" || this.props.type === "outline") {
51
- return color;
52
- } else if (color === undefined) {
74
+ const getTextColor = (textColor: Color): Color => {
75
+ if (type === "ghost" || type === "outline") {
76
+ return textColor;
77
+ } else if (textColor === undefined) {
53
78
  return "darkGray";
54
79
  } else {
55
- return buttonTextColor[color] || "white";
80
+ return buttonTextColor[textColor] || "white";
56
81
  }
57
- }
82
+ };
58
83
 
59
- getBorderColor(color: string) {
60
- if (this.props.type === "outline") {
61
- return Unifier.theme[this.getTextColor(color as Color)];
84
+ const getBorderColor = (borderColor: string): string => {
85
+ if (type === "outline") {
86
+ return Unifier.theme[getTextColor(borderColor as Color)];
62
87
  } else {
63
88
  return "transparent";
64
89
  }
65
- }
90
+ };
66
91
 
67
- render() {
68
- let color = this.props.color || "lightGray";
69
- if (color === "gray") {
70
- color = "lightGray";
71
- }
72
- return (
73
- <TouchableOpacity
74
- disabled={this.props.disabled || this.props.loading}
75
- style={{
76
- alignSelf: this.props.inline === true ? undefined : "stretch",
77
- height: this.HEIGHTS[this.props.size || "md"],
78
- backgroundColor: this.getBackgroundColor(color),
79
- // width: this.props.inline === true ? undefined : "100%",
80
- flexShrink: this.props.inline ? 1 : 0,
81
- // flexGrow: this.props.inline ? 0 : 1,
82
- alignItems: "center",
83
- justifyContent: "center",
84
- borderRadius: 5,
85
- borderColor: this.getBorderColor(color),
86
- borderWidth: this.props.type === "outline" ? 2 : 0,
87
- opacity: this.props.disabled ? 0.4 : 1,
88
- flexDirection: "row",
89
- paddingHorizontal: 4 * 2,
90
- }}
91
- onPress={debounce(
92
- async () => {
93
- Unifier.utils.haptic();
94
- this.setState({loading: true});
95
- try {
96
- if (this.props.onClick) {
97
- await this.props.onClick();
98
- }
99
- } catch (e) {
100
- this.setState({loading: false});
101
- throw e;
102
- }
103
- this.setState({loading: false});
104
- },
105
- 500,
106
- {leading: true}
107
- )}
108
- >
109
- {this.props.icon !== undefined && (
110
- <Box paddingX={2}>
111
- <Icon
112
- color={this.getTextColor(this.props.color as Color)}
113
- name={this.props.icon}
114
- prefix={this.props.iconPrefix || "far"}
115
- size={this.props.size}
116
- />
117
- </Box>
118
- )}
119
- {Boolean(this.props.children) && this.props.children}
120
- {Boolean(this.props.text) && (
121
- <Text
122
- color={this.getTextColor(color as Color)}
123
- font="button"
124
- inline={this.props.inline}
125
- size={this.props.size}
126
- skipLinking
127
- weight="bold"
128
- >
129
- {this.props.text}
130
- </Text>
131
- )}
132
- {(this.state.loading || this.props.loading) && (
133
- <Box marginLeft={2}>
134
- <ActivityIndicator color={this.getTextColor(color as Color)} size="small" />
135
- </Box>
136
- )}
137
- </TouchableOpacity>
138
- );
92
+ if (color === "gray") {
93
+ color = "lightGray";
139
94
  }
95
+ return (
96
+ <TouchableOpacity
97
+ disabled={disabled || loading}
98
+ style={{
99
+ alignSelf: inline === true ? undefined : "stretch",
100
+ height: HEIGHTS[size || "md"],
101
+ backgroundColor: getBackgroundColor(color),
102
+ // width: inline === true ? undefined : "100%",
103
+ flexShrink: inline ? 1 : 0,
104
+ // flexGrow: inline ? 0 : 1,
105
+ alignItems: "center",
106
+ justifyContent: "center",
107
+ borderRadius: 5,
108
+ borderColor: getBorderColor(color),
109
+ borderWidth: type === "outline" ? 2 : 0,
110
+ opacity: disabled ? 0.4 : 1,
111
+ flexDirection: "row",
112
+ paddingHorizontal: 4 * 2,
113
+ }}
114
+ onPress={debounce(
115
+ async () => {
116
+ Unifier.utils.haptic();
117
+ setLoading(true);
118
+ try {
119
+ if (onClick) {
120
+ await onClick();
121
+ }
122
+ } catch (e) {
123
+ setLoading(false);
124
+ throw e;
125
+ }
126
+ setLoading(false);
127
+ },
128
+ 500,
129
+ {leading: true}
130
+ )}
131
+ >
132
+ {icon !== undefined && (
133
+ <Box paddingX={2}>
134
+ <Icon
135
+ color={getTextColor(color as Color)}
136
+ name={icon}
137
+ prefix={iconPrefix || "far"}
138
+ size={size}
139
+ />
140
+ </Box>
141
+ )}
142
+ {Boolean(children) && children}
143
+ {Boolean(text) && (
144
+ <Text
145
+ color={getTextColor(color as Color)}
146
+ font="button"
147
+ inline={inline}
148
+ size={size}
149
+ skipLinking
150
+ weight="bold"
151
+ >
152
+ {text}
153
+ </Text>
154
+ )}
155
+ {(loading || loading) && (
156
+ <Box marginLeft={2}>
157
+ <ActivityIndicator color={getTextColor(color as Color)} size="small" />
158
+ </Box>
159
+ )}
160
+ </TouchableOpacity>
161
+ );
140
162
  }
package/src/Common.ts CHANGED
@@ -584,24 +584,6 @@ export interface BoxProps {
584
584
 
585
585
  export type BoxColor = AllColors | "transparent";
586
586
 
587
- export interface ButtonProps {
588
- text: string;
589
- // TODO make this work for all colors
590
- color?: ButtonColor | Color;
591
- // default gray
592
- disabled?: boolean; // default false
593
- inline?: boolean; // default false
594
- size?: "sm" | "md" | "lg"; // default md
595
-
596
- // Pattern Addition
597
- type?: "solid" | "ghost" | "outline";
598
- loading?: boolean;
599
- onClick: any;
600
- icon?: GestaltIconName | string;
601
- iconPrefix?: IconPrefix;
602
- iconColor?: ButtonColor | Color;
603
- }
604
-
605
587
  export interface DrawerProps {
606
588
  animationOpenTime: number;
607
589
  animationCloseTime: number;
@@ -2,6 +2,7 @@ import React from "react";
2
2
  import {ImageBackground as ImageBackgroundNative} from "react-native";
3
3
 
4
4
  interface ImageBackgroundProps {
5
+ children?: any;
5
6
  style?: any;
6
7
  source: any;
7
8
  }