ferns-ui 0.14.0 → 0.16.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/Avatar.d.ts +13 -0
- package/dist/Avatar.js +45 -25
- package/dist/Avatar.js.map +1 -1
- package/dist/Button.d.ts +4 -1
- package/dist/Button.js +50 -34
- package/dist/Button.js.map +1 -1
- package/package.json +4 -2
- package/src/Avatar.tsx +51 -6
- package/src/Button.tsx +97 -61
package/dist/Avatar.d.ts
CHANGED
|
@@ -23,6 +23,19 @@ interface AvatarProps {
|
|
|
23
23
|
* The URL of the user's image.
|
|
24
24
|
*/
|
|
25
25
|
src?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The fit for the image within the Avatar: "cover" | "contain" | "none".
|
|
28
|
+
* Default is undefined. See Image.tsx for more info
|
|
29
|
+
*/
|
|
30
|
+
imageFit?: "cover" | "contain" | "none";
|
|
31
|
+
/**
|
|
32
|
+
* Allow user to edit the image of the avatar
|
|
33
|
+
*/
|
|
34
|
+
editAvatarImage?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Function to handle the avatar image edit
|
|
37
|
+
*/
|
|
38
|
+
onChange?: (val: any) => void;
|
|
26
39
|
}
|
|
27
40
|
export declare const Avatar: (props: AvatarProps) => React.ReactElement;
|
|
28
41
|
export {};
|
package/dist/Avatar.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { launchImageLibraryAsync, MediaTypeOptions } from "expo-image-picker";
|
|
1
2
|
import React, { useState } from "react";
|
|
2
3
|
import { Image, Text, View } from "react-native";
|
|
3
4
|
import { Box } from "./Box";
|
|
5
|
+
import { iconSizeToNumber } from "./Common";
|
|
6
|
+
import { Icon } from "./Icon";
|
|
4
7
|
import { Unifier } from "./Unifier";
|
|
5
8
|
const sizes = {
|
|
6
9
|
xs: 24,
|
|
@@ -10,9 +13,10 @@ const sizes = {
|
|
|
10
13
|
xl: 120,
|
|
11
14
|
};
|
|
12
15
|
export const Avatar = (props) => {
|
|
13
|
-
var _a;
|
|
16
|
+
var _a, _b;
|
|
14
17
|
const [isImageLoaded, setIsImageLoaded] = useState(true);
|
|
15
|
-
const
|
|
18
|
+
const [src, setSrc] = useState((_a = props.src) !== null && _a !== void 0 ? _a : undefined);
|
|
19
|
+
const { name, initials, outline, size = "md", imageFit = "contain", editAvatarImage, onChange, } = props;
|
|
16
20
|
const width = sizes[size];
|
|
17
21
|
const height = sizes[size];
|
|
18
22
|
const radius = sizes[size] / 2;
|
|
@@ -24,28 +28,44 @@ export const Avatar = (props) => {
|
|
|
24
28
|
.join("")
|
|
25
29
|
.toLocaleUpperCase();
|
|
26
30
|
const handleImageError = () => setIsImageLoaded(false);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
:
|
|
48
|
-
|
|
49
|
-
|
|
31
|
+
const pickImage = async () => {
|
|
32
|
+
// TODO: Add permission request to use camera to take a picture
|
|
33
|
+
const result = await launchImageLibraryAsync({
|
|
34
|
+
mediaTypes: MediaTypeOptions.Images,
|
|
35
|
+
allowsEditing: true,
|
|
36
|
+
});
|
|
37
|
+
if (!result.cancelled) {
|
|
38
|
+
setSrc(result.uri);
|
|
39
|
+
if (onChange) {
|
|
40
|
+
onChange(result);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return (React.createElement(Box, { border: outline ? "white" : undefined, height: height, overflow: "hidden", position: "relative", rounding: "circle", width: editAvatarImage ? width + iconSizeToNumber(size) : width },
|
|
45
|
+
editAvatarImage && (React.createElement(Box, { bottom: true, position: "absolute", right: true, zIndex: 5, onClick: pickImage },
|
|
46
|
+
React.createElement(Icon, { color: "black", name: "edit", size: size }))),
|
|
47
|
+
src && isImageLoaded ? (
|
|
48
|
+
// TODO: Make our Image component rounding work so that we can use it for Avatar. Currently it creates an
|
|
49
|
+
// unrounded box around the Image.
|
|
50
|
+
React.createElement(Image, { resizeMode: imageFit, source: { uri: src, cache: "force-cache" }, style: {
|
|
51
|
+
borderRadius: radius,
|
|
52
|
+
height,
|
|
53
|
+
width,
|
|
54
|
+
display: "flex",
|
|
55
|
+
alignItems: "center",
|
|
56
|
+
justifyContent: "center",
|
|
57
|
+
overflow: "hidden",
|
|
58
|
+
}, onError: handleImageError })) : (React.createElement(View, { style: {
|
|
59
|
+
height,
|
|
60
|
+
width,
|
|
61
|
+
borderRadius: radius,
|
|
62
|
+
display: "flex",
|
|
63
|
+
alignItems: "center",
|
|
64
|
+
justifyContent: "center",
|
|
65
|
+
backgroundColor: props.backgroundColor
|
|
66
|
+
? Unifier.theme[props.backgroundColor]
|
|
67
|
+
: Unifier.theme.gray,
|
|
68
|
+
} },
|
|
69
|
+
React.createElement(Text, { style: { fontSize, color: (_b = props.textColor) !== null && _b !== void 0 ? _b : Unifier.theme.darkGray } }, computedInitials)))));
|
|
50
70
|
};
|
|
51
71
|
//# sourceMappingURL=Avatar.js.map
|
package/dist/Avatar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Avatar.js","sourceRoot":"","sources":["../src/Avatar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAC,QAAQ,EAAC,MAAM,OAAO,CAAC;AACtC,OAAO,EAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"Avatar.js","sourceRoot":"","sources":["../src/Avatar.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,uBAAuB,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAC5E,OAAO,KAAK,EAAE,EAAC,QAAQ,EAAC,MAAM,OAAO,CAAC;AACtC,OAAO,EAAC,KAAK,EAAmB,IAA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AG,EAAE,GAAG,EAAE,KAAK,EAAE,aAAa,EAAC,EACxC,KAAK,EAAE;gBACL,YAAY,EAAE,MAAM;gBACpB,MAAM;gBACN,KAAK;gBACL,OAAO,EAAE,MAAM;gBACf,UAAU,EAAE,QAAQ;gBACpB,cAAc,EAAE,QAAQ;gBACxB,QAAQ,EAAE,QAAQ;aACnB,EACD,OAAO,EAAE,gBAAgB,GACzB,CACH,CAAC,CAAC,CAAC,CACF,oBAAC,IAAI,IACH,KAAK,EAAE;gBACL,MAAM;gBACN,KAAK;gBACL,YAAY,EAAE,MAAM;gBACpB,OAAO,EAAE,MAAM;gBACf,UAAU,EAAE,QAAQ;gBACpB,cAAc,EAAE,QAAQ;gBACxB,eAAe,EAAE,KAAK,CAAC,eAAe;oBACpC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,eAAe,CAAC;oBACtC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI;aACvB;YAED,oBAAC,IAAI,IAAC,KAAK,EAAE,EAAC,QAAQ,EAAE,KAAK,QAAE,KAAK,CAAC,SAAS,mCAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAC,IACtE,gBAAgB,CACZ,CACF,CACR,CACG,CACP,CAAC;AACJ,CAAC,CAAC"}
|
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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YACpB,CAAC,EACD,GAAG,EACH,EAAC,OAAO,EAAE,IAAI,EAAC,CAChB;YAEA,IAAI,KAAK,SAAS,IAAI,CACrB,oBAAC,GAAG,IAAC,QAAQ,EAAE,CAAC;gBACd,oBAAC,IAAI,IACH,KAAK,EAAE,YAAY,CAAC,KAAc,CAAC,EACnC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,UAAU,IAAI,KAAK,EAC3B,IAAI,EAAE,IAAI,GACV,CACE,CACP;YACA,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ;YAC7B,OAAO,CAAC,IAAI,CAAC,IAAI,CAChB,oBAAC,IAAI,IACH,KAAK,EAAE,YAAY,CAAC,KAAc,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ferns-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"scripts": {
|
|
@@ -145,6 +145,7 @@
|
|
|
145
145
|
"eslint-plugin-unused-imports": "2.0.0",
|
|
146
146
|
"expo-font": "^10.0.5",
|
|
147
147
|
"expo-haptics": "~11.3.0",
|
|
148
|
+
"expo-image-picker": "^13.3.1",
|
|
148
149
|
"lodash": "^4.17.21",
|
|
149
150
|
"mixpanel-browser": "^2.38.0",
|
|
150
151
|
"moment-timezone": "^0.5.35",
|
|
@@ -176,13 +177,14 @@
|
|
|
176
177
|
"@react-native-picker/picker": "2.4.4",
|
|
177
178
|
"expo-font": "^10.0.5",
|
|
178
179
|
"expo-haptics": "~11.3.0",
|
|
180
|
+
"expo-image-picker": "^13.3.1",
|
|
179
181
|
"lodash": "^4.17.21",
|
|
180
182
|
"mixpanel-browser": "^2.38.0",
|
|
181
183
|
"moment-timezone": "^0.5.35",
|
|
182
184
|
"react": "^18.2.0",
|
|
183
185
|
"react-app-polyfill": "^3.0.0",
|
|
184
|
-
"react-dev-utils": "^12.0.1",
|
|
185
186
|
"react-datetime-picker": "^4.0.1",
|
|
187
|
+
"react-dev-utils": "^12.0.1",
|
|
186
188
|
"react-dom": "18.2.0",
|
|
187
189
|
"react-native": "0.69.4",
|
|
188
190
|
"react-native-calendars": "^1.1288.2",
|
package/src/Avatar.tsx
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import {launchImageLibraryAsync, MediaTypeOptions} from "expo-image-picker";
|
|
1
2
|
import React, {useState} from "react";
|
|
2
|
-
import {Image, Text, View} from "react-native";
|
|
3
|
+
import {Image, ImageResizeMode, Text, View} from "react-native";
|
|
3
4
|
|
|
4
5
|
import {Box} from "./Box";
|
|
5
|
-
import {AllColors} from "./Common";
|
|
6
|
+
import {AllColors, iconSizeToNumber} from "./Common";
|
|
7
|
+
import {Icon} from "./Icon";
|
|
6
8
|
import {Unifier} from "./Unifier";
|
|
7
9
|
|
|
8
10
|
const sizes = {
|
|
@@ -38,11 +40,33 @@ interface AvatarProps {
|
|
|
38
40
|
* The URL of the user's image.
|
|
39
41
|
*/
|
|
40
42
|
src?: string;
|
|
43
|
+
/**
|
|
44
|
+
* The fit for the image within the Avatar: "cover" | "contain" | "none".
|
|
45
|
+
* Default is undefined. See Image.tsx for more info
|
|
46
|
+
*/
|
|
47
|
+
imageFit?: "cover" | "contain" | "none";
|
|
48
|
+
/**
|
|
49
|
+
* Allow user to edit the image of the avatar
|
|
50
|
+
*/
|
|
51
|
+
editAvatarImage?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Function to handle the avatar image edit
|
|
54
|
+
*/
|
|
55
|
+
onChange?: (val: any) => void;
|
|
41
56
|
}
|
|
42
57
|
|
|
43
58
|
export const Avatar = (props: AvatarProps): React.ReactElement => {
|
|
44
59
|
const [isImageLoaded, setIsImageLoaded] = useState(true);
|
|
45
|
-
const
|
|
60
|
+
const [src, setSrc] = useState(props.src ?? undefined);
|
|
61
|
+
const {
|
|
62
|
+
name,
|
|
63
|
+
initials,
|
|
64
|
+
outline,
|
|
65
|
+
size = "md",
|
|
66
|
+
imageFit = "contain",
|
|
67
|
+
editAvatarImage,
|
|
68
|
+
onChange,
|
|
69
|
+
} = props;
|
|
46
70
|
const width = sizes[size];
|
|
47
71
|
const height = sizes[size];
|
|
48
72
|
const radius = sizes[size] / 2;
|
|
@@ -57,6 +81,22 @@ export const Avatar = (props: AvatarProps): React.ReactElement => {
|
|
|
57
81
|
.toLocaleUpperCase();
|
|
58
82
|
|
|
59
83
|
const handleImageError = () => setIsImageLoaded(false);
|
|
84
|
+
|
|
85
|
+
const pickImage = async () => {
|
|
86
|
+
// TODO: Add permission request to use camera to take a picture
|
|
87
|
+
const result = await launchImageLibraryAsync({
|
|
88
|
+
mediaTypes: MediaTypeOptions.Images,
|
|
89
|
+
allowsEditing: true,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (!result.cancelled) {
|
|
93
|
+
setSrc(result.uri);
|
|
94
|
+
if (onChange) {
|
|
95
|
+
onChange(result);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
60
100
|
return (
|
|
61
101
|
<Box
|
|
62
102
|
border={outline ? "white" : undefined}
|
|
@@ -64,13 +104,18 @@ export const Avatar = (props: AvatarProps): React.ReactElement => {
|
|
|
64
104
|
overflow="hidden"
|
|
65
105
|
position="relative"
|
|
66
106
|
rounding="circle"
|
|
67
|
-
width={width}
|
|
107
|
+
width={editAvatarImage ? width + iconSizeToNumber(size) : width}
|
|
68
108
|
>
|
|
109
|
+
{editAvatarImage && (
|
|
110
|
+
<Box bottom position="absolute" right zIndex={5} onClick={pickImage}>
|
|
111
|
+
<Icon color="black" name="edit" size={size} />
|
|
112
|
+
</Box>
|
|
113
|
+
)}
|
|
69
114
|
{src && isImageLoaded ? (
|
|
70
115
|
// TODO: Make our Image component rounding work so that we can use it for Avatar. Currently it creates an
|
|
71
|
-
//
|
|
116
|
+
// unrounded box around the Image.
|
|
72
117
|
<Image
|
|
73
|
-
resizeMode=
|
|
118
|
+
resizeMode={imageFit as ImageResizeMode}
|
|
74
119
|
source={{uri: src, cache: "force-cache"}}
|
|
75
120
|
style={{
|
|
76
121
|
borderRadius: radius,
|
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
|
}
|