ferns-ui 0.15.0 → 0.17.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.
- package/dist/Button.d.ts +4 -1
- package/dist/Button.js +50 -34
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +3 -0
- package/dist/Common.js.map +1 -1
- package/dist/IconButton.d.ts +2 -4
- package/dist/IconButton.js +43 -26
- package/dist/IconButton.js.map +1 -1
- package/package.json +1 -1
- package/src/Button.tsx +97 -61
- package/src/Common.ts +3 -0
- package/src/IconButton.tsx +66 -29
package/dist/Button.d.ts
CHANGED
|
@@ -13,5 +13,8 @@ export interface ButtonProps {
|
|
|
13
13
|
icon?: GestaltIconName | string;
|
|
14
14
|
iconPrefix?: IconPrefix;
|
|
15
15
|
iconColor?: ButtonColor | Color;
|
|
16
|
+
withConfirmation?: boolean;
|
|
17
|
+
confirmationText?: string;
|
|
18
|
+
confirmationHeading?: string;
|
|
16
19
|
}
|
|
17
|
-
export declare function Button({ disabled, type, loading: propsLoading, children, text, inline, icon, iconPrefix, size, onClick, color, }: ButtonProps): JSX.Element;
|
|
20
|
+
export declare function Button({ disabled, type, loading: propsLoading, children, text, inline, icon, iconPrefix, size, onClick, color, withConfirmation, confirmationText, confirmationHeading, }: ButtonProps): JSX.Element;
|
package/dist/Button.js
CHANGED
|
@@ -3,6 +3,7 @@ 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 { Modal } from "./Modal";
|
|
6
7
|
import { Text } from "./Text";
|
|
7
8
|
import { Unifier } from "./Unifier";
|
|
8
9
|
const buttonTextColor = {
|
|
@@ -24,8 +25,9 @@ const HEIGHTS = {
|
|
|
24
25
|
md: 40,
|
|
25
26
|
lg: 48,
|
|
26
27
|
};
|
|
27
|
-
export function Button({ disabled, type, loading: propsLoading, children, text, inline, icon, iconPrefix, size, onClick, color = "lightGray", }) {
|
|
28
|
+
export function Button({ disabled, type, loading: propsLoading, children, text, inline, icon, iconPrefix, size, onClick, color = "lightGray", withConfirmation = false, confirmationText = "Are you sure you want to continue?", confirmationHeading = "Confirm", }) {
|
|
28
29
|
const [loading, setLoading] = useState(propsLoading);
|
|
30
|
+
const [showConfirmation, setShowConfirmation] = useState(false);
|
|
29
31
|
const getBackgroundColor = (backgroundColor) => {
|
|
30
32
|
if (type === "ghost" || type === "outline") {
|
|
31
33
|
return "transparent";
|
|
@@ -56,40 +58,54 @@ export function Button({ disabled, type, loading: propsLoading, children, text,
|
|
|
56
58
|
if (color === "gray") {
|
|
57
59
|
color = "lightGray";
|
|
58
60
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
61
|
+
const renderConfirmation = () => {
|
|
62
|
+
return (React.createElement(Modal, { heading: confirmationHeading, primaryButtonOnClick: () => {
|
|
63
|
+
onClick();
|
|
64
|
+
setShowConfirmation(false);
|
|
65
|
+
}, primaryButtonText: "Confirm", secondaryButtonOnClick: () => setShowConfirmation(false), secondaryButtonText: "Cancel", size: "sm", visible: showConfirmation, onDismiss: () => {
|
|
66
|
+
setShowConfirmation(false);
|
|
67
|
+
} },
|
|
68
|
+
React.createElement(Text, null, confirmationText)));
|
|
69
|
+
};
|
|
70
|
+
return (React.createElement(React.Fragment, null,
|
|
71
|
+
React.createElement(TouchableOpacity, { disabled: disabled || loading, style: {
|
|
72
|
+
alignSelf: inline === true ? undefined : "stretch",
|
|
73
|
+
height: HEIGHTS[size || "md"],
|
|
74
|
+
backgroundColor: getBackgroundColor(color),
|
|
75
|
+
// width: inline === true ? undefined : "100%",
|
|
76
|
+
flexShrink: inline ? 1 : 0,
|
|
77
|
+
// flexGrow: inline ? 0 : 1,
|
|
78
|
+
alignItems: "center",
|
|
79
|
+
justifyContent: "center",
|
|
80
|
+
borderRadius: 5,
|
|
81
|
+
borderColor: getBorderColor(color),
|
|
82
|
+
borderWidth: type === "outline" ? 2 : 0,
|
|
83
|
+
opacity: disabled ? 0.4 : 1,
|
|
84
|
+
flexDirection: "row",
|
|
85
|
+
paddingHorizontal: 4 * 2,
|
|
86
|
+
}, onPress: debounce(async () => {
|
|
87
|
+
Unifier.utils.haptic();
|
|
88
|
+
setLoading(true);
|
|
89
|
+
try {
|
|
90
|
+
if (withConfirmation && !showConfirmation) {
|
|
91
|
+
setShowConfirmation(true);
|
|
92
|
+
}
|
|
93
|
+
else if (onClick) {
|
|
94
|
+
await onClick();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
setLoading(false);
|
|
99
|
+
throw e;
|
|
80
100
|
}
|
|
81
|
-
}
|
|
82
|
-
catch (e) {
|
|
83
101
|
setLoading(false);
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
React.createElement(
|
|
90
|
-
|
|
91
|
-
Boolean(
|
|
92
|
-
(loading || loading) && (React.createElement(Box, { marginLeft: 2 },
|
|
93
|
-
React.createElement(ActivityIndicator, { color: getTextColor(color), size: "small" })))));
|
|
102
|
+
}, 500, { leading: true }) },
|
|
103
|
+
icon !== undefined && (React.createElement(Box, { paddingX: 2 },
|
|
104
|
+
React.createElement(Icon, { color: getTextColor(color), name: icon, prefix: iconPrefix || "far", size: size }))),
|
|
105
|
+
Boolean(children) && children,
|
|
106
|
+
Boolean(text) && (React.createElement(Text, { color: getTextColor(color), font: "button", inline: inline, size: size, skipLinking: true, weight: "bold" }, text)),
|
|
107
|
+
Boolean(loading) && (React.createElement(Box, { marginLeft: 2 },
|
|
108
|
+
React.createElement(ActivityIndicator, { color: getTextColor(color), size: "small" })))),
|
|
109
|
+
Boolean(withConfirmation) && renderConfirmation()));
|
|
94
110
|
}
|
|
95
111
|
//# sourceMappingURL=Button.js.map
|
package/dist/Button.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.js","sourceRoot":"","sources":["../src/Button.tsx"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,KAAK,EAAE,EAAC,QAAQ,EAAC,MAAM,OAAO,CAAC;AACtC,OAAO,EAAC,iBAAiB,EAAE,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"Button.js","sourceRoot":"","sources":["../src/Button.tsx"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,KAAK,EAAE,EAAC,QAAQ,EAAC,MAAM,OAAO,CAAC;AACtC,OAAO,EAAC,iBAAiB,EAAE,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAwBlC,MAAM,eAAe,GAAkD;IACrE,IAAI,EAAE,OAAO;IACb,SAAS,EAAE,UAAU;IACrB,GAAG,EAAE,OAAO;IACZ,WAAW,EAAE,OAAO;IACpB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,CAAC,EACnC,IAAI,EAAC,QAAQ,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,WAAW,QACX,MAAM,EAAC,MAAM,IAEZ,IAAI,CACA,CACR;YACA,OAAO,CAAC,OAAO,CAAC,IAAI,CACnB,oBAAC,GAAG,IAAC,UAAU,EAAE,CAAC;gBAChB,oBAAC,iBAAiB,IAAC,KAAK,EAAE,YAAY,CAAC,KAAc,CAAC,EAAE,IAAI,EAAC,OAAO,GAAG,CACnE,CACP,CACgB;QAClB,OAAO,CAAC,gBAAgB,CAAC,IAAI,kBAAkB,EAAE,CACjD,CACJ,CAAC;AACJ,CAAC"}
|
package/dist/Common.d.ts
CHANGED
|
@@ -328,6 +328,9 @@ export interface IconButtonProps {
|
|
|
328
328
|
bgColor?: "transparent" | "transparentDarkGray" | "gray" | "lightGray" | "white";
|
|
329
329
|
disabled?: boolean;
|
|
330
330
|
selected?: boolean;
|
|
331
|
+
withConfirmation?: boolean;
|
|
332
|
+
confirmationText?: string;
|
|
333
|
+
confirmationHeading?: string;
|
|
331
334
|
}
|
|
332
335
|
export interface NavigatorProps {
|
|
333
336
|
config?: any;
|
package/dist/Common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Common.js","sourceRoot":"","sources":["../src/Common.ts"],"names":[],"mappings":"AAkVA,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;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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,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;AAg5BD,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"}
|
package/dist/IconButton.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { IconButtonProps } from "./Common";
|
|
3
|
-
export declare
|
|
4
|
-
render(): JSX.Element;
|
|
5
|
-
}
|
|
3
|
+
export declare function IconButton({ prefix, icon, iconColor, onClick, size, bgColor, withConfirmation, confirmationText, confirmationHeading, }: IconButtonProps): JSX.Element;
|
package/dist/IconButton.js
CHANGED
|
@@ -1,41 +1,58 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useState } from "react";
|
|
2
2
|
import { TouchableOpacity } from "react-native";
|
|
3
3
|
import { iconSizeToNumber } from "./Common";
|
|
4
4
|
import { Icon } from "./Icon";
|
|
5
|
+
import { Modal } from "./Modal";
|
|
6
|
+
import { Text } from "./Text";
|
|
5
7
|
import { Unifier } from "./Unifier";
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
export function IconButton({ prefix, icon, iconColor, onClick, size, bgColor = "transparent", withConfirmation = false, confirmationText = "Are you sure you want to continue?", confirmationHeading = "Confirm", }) {
|
|
9
|
+
const [showConfirmation, setShowConfirmation] = useState(false);
|
|
10
|
+
let opacity = 1;
|
|
11
|
+
let color;
|
|
12
|
+
if (bgColor === "transparentDarkGray") {
|
|
13
|
+
opacity = 0.8;
|
|
14
|
+
color = Unifier.theme.darkGray;
|
|
15
|
+
}
|
|
16
|
+
else if (bgColor === "transparent" || !bgColor) {
|
|
17
|
+
opacity = 0.0;
|
|
18
|
+
color = Unifier.theme.white;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
color = Unifier.theme[bgColor];
|
|
22
|
+
}
|
|
23
|
+
const renderConfirmation = () => {
|
|
24
|
+
return (React.createElement(Modal, { heading: confirmationHeading, primaryButtonOnClick: () => {
|
|
25
|
+
onClick();
|
|
26
|
+
setShowConfirmation(false);
|
|
27
|
+
}, primaryButtonText: "Confirm", secondaryButtonOnClick: () => setShowConfirmation(false), secondaryButtonText: "Cancel", size: "sm", visible: showConfirmation, onDismiss: () => {
|
|
28
|
+
setShowConfirmation(false);
|
|
29
|
+
} },
|
|
30
|
+
React.createElement(Text, null, confirmationText)));
|
|
31
|
+
};
|
|
32
|
+
return (React.createElement(React.Fragment, null,
|
|
33
|
+
React.createElement(TouchableOpacity, { hitSlop: { top: 10, left: 10, bottom: 10, right: 10 }, style: {
|
|
22
34
|
opacity,
|
|
23
35
|
backgroundColor: color,
|
|
24
36
|
borderRadius: 100,
|
|
25
|
-
// paddingBottom: iconSizeToNumber(
|
|
26
|
-
// paddingTop: iconSizeToNumber(
|
|
27
|
-
// paddingLeft: iconSizeToNumber(
|
|
28
|
-
// paddingRight: iconSizeToNumber(
|
|
29
|
-
width: iconSizeToNumber(
|
|
30
|
-
height: iconSizeToNumber(
|
|
37
|
+
// paddingBottom: iconSizeToNumber(size) / 4,
|
|
38
|
+
// paddingTop: iconSizeToNumber(size) / 4,
|
|
39
|
+
// paddingLeft: iconSizeToNumber(size) / 2,
|
|
40
|
+
// paddingRight: iconSizeToNumber(size) / 2,
|
|
41
|
+
width: iconSizeToNumber(size) * 2.5,
|
|
42
|
+
height: iconSizeToNumber(size) * 2.5,
|
|
31
43
|
display: "flex",
|
|
32
44
|
justifyContent: "center",
|
|
33
45
|
alignItems: "center",
|
|
34
46
|
}, onPress: () => {
|
|
35
47
|
Unifier.utils.haptic();
|
|
36
|
-
|
|
48
|
+
if (withConfirmation && !showConfirmation) {
|
|
49
|
+
setShowConfirmation(true);
|
|
50
|
+
}
|
|
51
|
+
else if (onClick) {
|
|
52
|
+
onClick();
|
|
53
|
+
}
|
|
37
54
|
} },
|
|
38
|
-
React.createElement(Icon, { color:
|
|
39
|
-
|
|
55
|
+
React.createElement(Icon, { color: iconColor, name: icon, prefix: prefix || "fas", size: size })),
|
|
56
|
+
Boolean(withConfirmation) && renderConfirmation()));
|
|
40
57
|
}
|
|
41
58
|
//# sourceMappingURL=IconButton.js.map
|
package/dist/IconButton.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconButton.js","sourceRoot":"","sources":["../src/IconButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"IconButton.js","sourceRoot":"","sources":["../src/IconButton.tsx"],"names":[],"mappings":"A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D;QAClB,OAAO,CAAC,gBAAgB,CAAC,IAAI,kBAAkB,EAAE,CACjD,CACJ,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
package/src/Button.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import {ActivityIndicator, TouchableOpacity} from "react-native";
|
|
|
5
5
|
import {Box} from "./Box";
|
|
6
6
|
import {ButtonColor, Color, GestaltIconName, IconPrefix, UnifiedTheme} from "./Common";
|
|
7
7
|
import {Icon} from "./Icon";
|
|
8
|
+
import {Modal} from "./Modal";
|
|
8
9
|
import {Text} from "./Text";
|
|
9
10
|
import {Unifier} from "./Unifier";
|
|
10
11
|
|
|
@@ -25,6 +26,9 @@ export interface ButtonProps {
|
|
|
25
26
|
icon?: GestaltIconName | string;
|
|
26
27
|
iconPrefix?: IconPrefix;
|
|
27
28
|
iconColor?: ButtonColor | Color;
|
|
29
|
+
withConfirmation?: boolean;
|
|
30
|
+
confirmationText?: string;
|
|
31
|
+
confirmationHeading?: string;
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
const buttonTextColor: {[buttonColor: string]: "white" | "darkGray"} = {
|
|
@@ -60,8 +64,12 @@ export function Button({
|
|
|
60
64
|
size,
|
|
61
65
|
onClick,
|
|
62
66
|
color = "lightGray",
|
|
67
|
+
withConfirmation = false,
|
|
68
|
+
confirmationText = "Are you sure you want to continue?",
|
|
69
|
+
confirmationHeading = "Confirm",
|
|
63
70
|
}: ButtonProps) {
|
|
64
71
|
const [loading, setLoading] = useState(propsLoading);
|
|
72
|
+
const [showConfirmation, setShowConfirmation] = useState(false);
|
|
65
73
|
|
|
66
74
|
const getBackgroundColor = (backgroundColor: string): string => {
|
|
67
75
|
if (type === "ghost" || type === "outline") {
|
|
@@ -92,71 +100,99 @@ export function Button({
|
|
|
92
100
|
if (color === "gray") {
|
|
93
101
|
color = "lightGray";
|
|
94
102
|
}
|
|
103
|
+
|
|
104
|
+
const renderConfirmation = () => {
|
|
105
|
+
return (
|
|
106
|
+
<Modal
|
|
107
|
+
heading={confirmationHeading}
|
|
108
|
+
primaryButtonOnClick={() => {
|
|
109
|
+
onClick();
|
|
110
|
+
setShowConfirmation(false);
|
|
111
|
+
}}
|
|
112
|
+
primaryButtonText="Confirm"
|
|
113
|
+
secondaryButtonOnClick={(): void => setShowConfirmation(false)}
|
|
114
|
+
secondaryButtonText="Cancel"
|
|
115
|
+
size="sm"
|
|
116
|
+
visible={showConfirmation}
|
|
117
|
+
onDismiss={(): void => {
|
|
118
|
+
setShowConfirmation(false);
|
|
119
|
+
}}
|
|
120
|
+
>
|
|
121
|
+
<Text>{confirmationText}</Text>
|
|
122
|
+
</Modal>
|
|
123
|
+
);
|
|
124
|
+
};
|
|
125
|
+
|
|
95
126
|
return (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
127
|
+
<>
|
|
128
|
+
<TouchableOpacity
|
|
129
|
+
disabled={disabled || loading}
|
|
130
|
+
style={{
|
|
131
|
+
alignSelf: inline === true ? undefined : "stretch",
|
|
132
|
+
height: HEIGHTS[size || "md"],
|
|
133
|
+
backgroundColor: getBackgroundColor(color),
|
|
134
|
+
// width: inline === true ? undefined : "100%",
|
|
135
|
+
flexShrink: inline ? 1 : 0,
|
|
136
|
+
// flexGrow: inline ? 0 : 1,
|
|
137
|
+
alignItems: "center",
|
|
138
|
+
justifyContent: "center",
|
|
139
|
+
borderRadius: 5,
|
|
140
|
+
borderColor: getBorderColor(color),
|
|
141
|
+
borderWidth: type === "outline" ? 2 : 0,
|
|
142
|
+
opacity: disabled ? 0.4 : 1,
|
|
143
|
+
flexDirection: "row",
|
|
144
|
+
paddingHorizontal: 4 * 2,
|
|
145
|
+
}}
|
|
146
|
+
onPress={debounce(
|
|
147
|
+
async () => {
|
|
148
|
+
Unifier.utils.haptic();
|
|
149
|
+
setLoading(true);
|
|
150
|
+
try {
|
|
151
|
+
if (withConfirmation && !showConfirmation) {
|
|
152
|
+
setShowConfirmation(true);
|
|
153
|
+
} else if (onClick) {
|
|
154
|
+
await onClick();
|
|
155
|
+
}
|
|
156
|
+
} catch (e) {
|
|
157
|
+
setLoading(false);
|
|
158
|
+
throw e;
|
|
121
159
|
}
|
|
122
|
-
} catch (e) {
|
|
123
160
|
setLoading(false);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
{
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
161
|
+
},
|
|
162
|
+
500,
|
|
163
|
+
{leading: true}
|
|
164
|
+
)}
|
|
165
|
+
>
|
|
166
|
+
{icon !== undefined && (
|
|
167
|
+
<Box paddingX={2}>
|
|
168
|
+
<Icon
|
|
169
|
+
color={getTextColor(color as Color)}
|
|
170
|
+
name={icon}
|
|
171
|
+
prefix={iconPrefix || "far"}
|
|
172
|
+
size={size}
|
|
173
|
+
/>
|
|
174
|
+
</Box>
|
|
175
|
+
)}
|
|
176
|
+
{Boolean(children) && children}
|
|
177
|
+
{Boolean(text) && (
|
|
178
|
+
<Text
|
|
135
179
|
color={getTextColor(color as Color)}
|
|
136
|
-
|
|
137
|
-
|
|
180
|
+
font="button"
|
|
181
|
+
inline={inline}
|
|
138
182
|
size={size}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
</Text>
|
|
154
|
-
)}
|
|
155
|
-
{(loading || loading) && (
|
|
156
|
-
<Box marginLeft={2}>
|
|
157
|
-
<ActivityIndicator color={getTextColor(color as Color)} size="small" />
|
|
158
|
-
</Box>
|
|
159
|
-
)}
|
|
160
|
-
</TouchableOpacity>
|
|
183
|
+
skipLinking
|
|
184
|
+
weight="bold"
|
|
185
|
+
>
|
|
186
|
+
{text}
|
|
187
|
+
</Text>
|
|
188
|
+
)}
|
|
189
|
+
{Boolean(loading) && (
|
|
190
|
+
<Box marginLeft={2}>
|
|
191
|
+
<ActivityIndicator color={getTextColor(color as Color)} size="small" />
|
|
192
|
+
</Box>
|
|
193
|
+
)}
|
|
194
|
+
</TouchableOpacity>
|
|
195
|
+
{Boolean(withConfirmation) && renderConfirmation()}
|
|
196
|
+
</>
|
|
161
197
|
);
|
|
162
198
|
}
|
package/src/Common.ts
CHANGED
|
@@ -630,6 +630,9 @@ export interface IconButtonProps {
|
|
|
630
630
|
bgColor?: "transparent" | "transparentDarkGray" | "gray" | "lightGray" | "white"; // default transparent
|
|
631
631
|
disabled?: boolean;
|
|
632
632
|
selected?: boolean;
|
|
633
|
+
withConfirmation?: boolean;
|
|
634
|
+
confirmationText?: string;
|
|
635
|
+
confirmationHeading?: string;
|
|
633
636
|
}
|
|
634
637
|
|
|
635
638
|
export interface NavigatorProps {
|
package/src/IconButton.tsx
CHANGED
|
@@ -1,52 +1,89 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, {useState} from "react";
|
|
2
2
|
import {TouchableOpacity} from "react-native";
|
|
3
3
|
|
|
4
4
|
import {IconButtonProps, iconSizeToNumber} from "./Common";
|
|
5
5
|
import {Icon} from "./Icon";
|
|
6
|
+
import {Modal} from "./Modal";
|
|
7
|
+
import {Text} from "./Text";
|
|
6
8
|
import {Unifier} from "./Unifier";
|
|
7
9
|
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
export function IconButton({
|
|
11
|
+
prefix,
|
|
12
|
+
icon,
|
|
13
|
+
iconColor,
|
|
14
|
+
onClick,
|
|
15
|
+
size,
|
|
16
|
+
bgColor = "transparent",
|
|
17
|
+
withConfirmation = false,
|
|
18
|
+
confirmationText = "Are you sure you want to continue?",
|
|
19
|
+
confirmationHeading = "Confirm",
|
|
20
|
+
}: IconButtonProps) {
|
|
21
|
+
const [showConfirmation, setShowConfirmation] = useState(false);
|
|
22
|
+
|
|
23
|
+
let opacity = 1;
|
|
24
|
+
let color;
|
|
25
|
+
if (bgColor === "transparentDarkGray") {
|
|
26
|
+
opacity = 0.8;
|
|
27
|
+
color = Unifier.theme.darkGray;
|
|
28
|
+
} else if (bgColor === "transparent" || !bgColor) {
|
|
29
|
+
opacity = 0.0;
|
|
30
|
+
color = Unifier.theme.white;
|
|
31
|
+
} else {
|
|
32
|
+
color = Unifier.theme[bgColor];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const renderConfirmation = () => {
|
|
21
36
|
return (
|
|
37
|
+
<Modal
|
|
38
|
+
heading={confirmationHeading}
|
|
39
|
+
primaryButtonOnClick={() => {
|
|
40
|
+
onClick();
|
|
41
|
+
setShowConfirmation(false);
|
|
42
|
+
}}
|
|
43
|
+
primaryButtonText="Confirm"
|
|
44
|
+
secondaryButtonOnClick={(): void => setShowConfirmation(false)}
|
|
45
|
+
secondaryButtonText="Cancel"
|
|
46
|
+
size="sm"
|
|
47
|
+
visible={showConfirmation}
|
|
48
|
+
onDismiss={(): void => {
|
|
49
|
+
setShowConfirmation(false);
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
<Text>{confirmationText}</Text>
|
|
53
|
+
</Modal>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
22
59
|
<TouchableOpacity
|
|
23
60
|
hitSlop={{top: 10, left: 10, bottom: 10, right: 10}}
|
|
24
61
|
style={{
|
|
25
62
|
opacity,
|
|
26
63
|
backgroundColor: color,
|
|
27
64
|
borderRadius: 100,
|
|
28
|
-
// paddingBottom: iconSizeToNumber(
|
|
29
|
-
// paddingTop: iconSizeToNumber(
|
|
30
|
-
// paddingLeft: iconSizeToNumber(
|
|
31
|
-
// paddingRight: iconSizeToNumber(
|
|
32
|
-
width: iconSizeToNumber(
|
|
33
|
-
height: iconSizeToNumber(
|
|
65
|
+
// paddingBottom: iconSizeToNumber(size) / 4,
|
|
66
|
+
// paddingTop: iconSizeToNumber(size) / 4,
|
|
67
|
+
// paddingLeft: iconSizeToNumber(size) / 2,
|
|
68
|
+
// paddingRight: iconSizeToNumber(size) / 2,
|
|
69
|
+
width: iconSizeToNumber(size) * 2.5,
|
|
70
|
+
height: iconSizeToNumber(size) * 2.5,
|
|
34
71
|
display: "flex",
|
|
35
72
|
justifyContent: "center",
|
|
36
73
|
alignItems: "center",
|
|
37
74
|
}}
|
|
38
75
|
onPress={() => {
|
|
39
76
|
Unifier.utils.haptic();
|
|
40
|
-
|
|
77
|
+
if (withConfirmation && !showConfirmation) {
|
|
78
|
+
setShowConfirmation(true);
|
|
79
|
+
} else if (onClick) {
|
|
80
|
+
onClick();
|
|
81
|
+
}
|
|
41
82
|
}}
|
|
42
83
|
>
|
|
43
|
-
<Icon
|
|
44
|
-
color={this.props.iconColor}
|
|
45
|
-
name={this.props.icon}
|
|
46
|
-
prefix={this.props.prefix || "fas"}
|
|
47
|
-
size={this.props.size}
|
|
48
|
-
/>
|
|
84
|
+
<Icon color={iconColor} name={icon} prefix={prefix || "fas"} size={size} />
|
|
49
85
|
</TouchableOpacity>
|
|
50
|
-
|
|
51
|
-
|
|
86
|
+
{Boolean(withConfirmation) && renderConfirmation()}
|
|
87
|
+
</>
|
|
88
|
+
);
|
|
52
89
|
}
|