atlas-design-system 1.8.2 → 1.9.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/components/Button/Button.d.ts +1 -6
- package/dist/components/Button/Button.js +6 -59
- package/dist/components/Button/index.d.ts +3 -2
- package/dist/components/Button/index.js +1 -0
- package/dist/components/Button/styles/ButtonStyle.d.ts +9 -2
- package/dist/components/Button/styles/ButtonStyle.js +79 -35
- package/package.json +1 -1
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { StyleProp, ViewStyle } from "react-native";
|
|
3
|
-
export declare enum ButtonType {
|
|
4
|
-
Primary = 0,
|
|
5
|
-
Destructive = 1
|
|
6
|
-
}
|
|
7
3
|
export interface ButtonProps {
|
|
8
4
|
disabled?: boolean;
|
|
9
|
-
type?: ButtonType;
|
|
10
5
|
onPress?: () => void;
|
|
11
6
|
text: string;
|
|
12
7
|
loading?: boolean;
|
|
@@ -14,5 +9,5 @@ export interface ButtonProps {
|
|
|
14
9
|
containerStyle?: StyleProp<ViewStyle>;
|
|
15
10
|
appearance?: "primary" | "secondary" | "destructive";
|
|
16
11
|
}
|
|
17
|
-
export declare const Button: ({ testID, disabled, onPress, text, loading, containerStyle, appearance,
|
|
12
|
+
export declare const Button: ({ testID, disabled, onPress, text, loading, containerStyle, appearance, }: ButtonProps) => React.JSX.Element;
|
|
18
13
|
export default Button;
|
|
@@ -1,70 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.Button =
|
|
30
|
-
const react_1 =
|
|
6
|
+
exports.Button = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
31
8
|
const react_native_1 = require("react-native");
|
|
32
9
|
const ButtonStyle_1 = require("./styles/ButtonStyle");
|
|
33
10
|
const Text_1 = __importDefault(require("../Text"));
|
|
34
|
-
|
|
35
|
-
(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
})(ButtonType || (exports.ButtonType = ButtonType = {}));
|
|
39
|
-
const getButtonStyle = (styles, appearance, disabled) => {
|
|
40
|
-
const style = [styles.primary];
|
|
41
|
-
if (appearance === "secondary") {
|
|
42
|
-
style.push(styles.secondary);
|
|
43
|
-
}
|
|
44
|
-
if (appearance === "destructive") {
|
|
45
|
-
style.push(styles.destructive);
|
|
46
|
-
}
|
|
47
|
-
if (disabled) {
|
|
48
|
-
style.push(styles.disabled);
|
|
49
|
-
}
|
|
50
|
-
return style;
|
|
51
|
-
};
|
|
52
|
-
const Button = ({ testID, disabled = false, onPress, text, loading, containerStyle = {}, appearance = "primary", type, }) => {
|
|
53
|
-
const { styles, theme } = (0, ButtonStyle_1.useButtonStyles)();
|
|
54
|
-
const buttonStyle = (0, react_1.useMemo)(() => {
|
|
55
|
-
let _apperance = appearance;
|
|
56
|
-
if (type) {
|
|
57
|
-
_apperance = type === ButtonType.Destructive ? "destructive" : "primary";
|
|
58
|
-
}
|
|
59
|
-
return getButtonStyle({
|
|
60
|
-
disabled: styles.disabled,
|
|
61
|
-
primary: styles.default,
|
|
62
|
-
destructive: styles.destructiveContainer,
|
|
63
|
-
secondary: styles.secondary,
|
|
64
|
-
}, _apperance, disabled);
|
|
65
|
-
}, [styles, appearance, disabled, type]);
|
|
66
|
-
return (<react_native_1.TouchableOpacity testID={testID} style={[buttonStyle, disabled && styles.disabled, containerStyle]} onPress={onPress} disabled={disabled || loading}>
|
|
67
|
-
{loading ? (<react_native_1.ActivityIndicator size="small" color={theme.colors.foregroundOnPrimary}/>) : (<Text_1.default category="h3" style={[styles.defaultText, disabled && styles.disabledText]}>
|
|
11
|
+
const Button = ({ testID, disabled = false, onPress, text, loading, containerStyle = {}, appearance = "primary", }) => {
|
|
12
|
+
const { buttonStyle, styles, textStyle } = (0, ButtonStyle_1.useButtonStyles)(appearance, disabled);
|
|
13
|
+
return (<react_native_1.TouchableOpacity testID={testID} style={[buttonStyle, containerStyle]} onPress={onPress} disabled={disabled || loading}>
|
|
14
|
+
{loading ? (<react_native_1.ActivityIndicator size="small" color={styles.loadingIndicator.color}/>) : (<Text_1.default category="h3" style={textStyle}>
|
|
68
15
|
{text}
|
|
69
16
|
</Text_1.default>)}
|
|
70
17
|
</react_native_1.TouchableOpacity>);
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { default } from
|
|
2
|
-
export * from
|
|
1
|
+
export { default } from "./Button";
|
|
2
|
+
export * from "./Button";
|
|
3
|
+
export * from "./styles/ButtonStyle";
|
|
@@ -21,3 +21,4 @@ exports.default = void 0;
|
|
|
21
21
|
var Button_1 = require("./Button");
|
|
22
22
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(Button_1).default; } });
|
|
23
23
|
__exportStar(require("./Button"), exports);
|
|
24
|
+
__exportStar(require("./styles/ButtonStyle"), exports);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { StyleProp, TextStyle, ViewStyle } from "react-native";
|
|
2
|
+
import { ButtonProps } from "../Button";
|
|
3
|
+
import { AtlasTheme } from "../../../types";
|
|
4
|
+
export declare const useButtonStyles: (appearance?: ButtonProps["appearance"], disabled?: boolean, themeOverride?: AtlasTheme) => {
|
|
3
5
|
styles: {
|
|
4
6
|
default: {
|
|
5
7
|
borderRadius: number;
|
|
@@ -34,5 +36,10 @@ export declare const useButtonStyles: () => {
|
|
|
34
36
|
disabledText: {
|
|
35
37
|
color: string;
|
|
36
38
|
};
|
|
39
|
+
loadingIndicator: {
|
|
40
|
+
color: string;
|
|
41
|
+
};
|
|
37
42
|
};
|
|
43
|
+
buttonStyle: StyleProp<ViewStyle>[];
|
|
44
|
+
textStyle: StyleProp<TextStyle>[];
|
|
38
45
|
};
|
|
@@ -4,39 +4,83 @@ exports.useButtonStyles = void 0;
|
|
|
4
4
|
const react_native_1 = require("react-native");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const hooks_1 = require("../../../hooks");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
7
|
+
const getButtonStyle = (styles, appearance, disabled) => {
|
|
8
|
+
const style = [styles.primary];
|
|
9
|
+
if (appearance === "secondary") {
|
|
10
|
+
style.push(styles.secondary);
|
|
11
|
+
}
|
|
12
|
+
if (appearance === "destructive") {
|
|
13
|
+
style.push(styles.destructive);
|
|
14
|
+
}
|
|
15
|
+
if (disabled) {
|
|
16
|
+
style.push(styles.disabled);
|
|
17
|
+
}
|
|
18
|
+
return style;
|
|
19
|
+
};
|
|
20
|
+
const getButtonTextStyle = (styles, appearance, disabled) => {
|
|
21
|
+
const style = [styles.primary];
|
|
22
|
+
if (disabled) {
|
|
23
|
+
style.push(styles.disabled);
|
|
24
|
+
}
|
|
25
|
+
return style;
|
|
26
|
+
};
|
|
27
|
+
const useButtonStyles = (appearance = "primary", disabled = false, themeOverride) => {
|
|
28
|
+
const styles = (0, hooks_1.useThemedStyle)((0, react_1.useCallback)((t) => {
|
|
29
|
+
const theme = t;
|
|
30
|
+
if (themeOverride) {
|
|
31
|
+
t = themeOverride;
|
|
32
|
+
}
|
|
33
|
+
return react_native_1.StyleSheet.create({
|
|
34
|
+
default: {
|
|
35
|
+
borderRadius: theme.borderRadius,
|
|
36
|
+
justifyContent: "center",
|
|
37
|
+
backgroundColor: theme.colors.primary,
|
|
38
|
+
paddingHorizontal: theme.size.baseSize * 4,
|
|
39
|
+
paddingVertical: theme.size.baseSize * 2,
|
|
40
|
+
textAlign: "center",
|
|
41
|
+
},
|
|
42
|
+
secondary: {
|
|
43
|
+
backgroundColor: theme.colors.foregroundLowContrast,
|
|
44
|
+
},
|
|
45
|
+
destructiveContainer: {
|
|
46
|
+
borderRadius: theme.borderRadius,
|
|
47
|
+
justifyContent: "center",
|
|
48
|
+
paddingHorizontal: theme.size.baseSize * 4,
|
|
49
|
+
paddingVertical: theme.size.baseSize * 2,
|
|
50
|
+
textAlign: "center",
|
|
51
|
+
backgroundColor: theme.colors.secondaryNegative,
|
|
52
|
+
},
|
|
53
|
+
destructiveText: {
|
|
54
|
+
textAlign: "center",
|
|
55
|
+
color: theme.colors.backgroundPrimary,
|
|
56
|
+
},
|
|
57
|
+
defaultText: {
|
|
58
|
+
textAlign: "center",
|
|
59
|
+
color: theme.colors.foregroundOnPrimary,
|
|
60
|
+
},
|
|
61
|
+
disabled: {
|
|
62
|
+
backgroundColor: theme.colors.primaryLowContrast,
|
|
63
|
+
},
|
|
64
|
+
disabledText: {
|
|
65
|
+
color: theme.colors.foregroundOnPrimary,
|
|
66
|
+
},
|
|
67
|
+
loadingIndicator: {
|
|
68
|
+
color: theme.colors.foregroundOnPrimary,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}, [themeOverride])).styles;
|
|
72
|
+
const buttonStyle = (0, react_1.useMemo)(() => {
|
|
73
|
+
return getButtonStyle({
|
|
74
|
+
disabled: styles.disabled,
|
|
75
|
+
primary: styles.default,
|
|
76
|
+
destructive: styles.destructiveContainer,
|
|
77
|
+
secondary: styles.secondary,
|
|
78
|
+
}, appearance, disabled);
|
|
79
|
+
}, [styles, appearance, disabled]);
|
|
80
|
+
const textStyle = (0, react_1.useMemo)(() => getButtonTextStyle({
|
|
81
|
+
disabled: styles.disabledText,
|
|
82
|
+
primary: styles.defaultText,
|
|
83
|
+
}, appearance, disabled), [styles, appearance, disabled]);
|
|
84
|
+
return { styles, buttonStyle, textStyle };
|
|
85
|
+
};
|
|
42
86
|
exports.useButtonStyles = useButtonStyles;
|