@proximus/lavender-button-native 0.1.0-alpha.15 → 0.1.0-alpha.16
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/PxButton.d.ts +3 -1
- package/dist/PxButton.d.ts.map +1 -1
- package/dist/PxButton.js +32 -16
- package/package.json +1 -1
package/dist/PxButton.d.ts
CHANGED
|
@@ -8,7 +8,9 @@ export interface IProps extends AccessibilityProps {
|
|
|
8
8
|
titleStyle?: StyleProp<TextStyle>;
|
|
9
9
|
wrapperStyle?: StyleProp<ViewStyle>;
|
|
10
10
|
onPress?: () => void;
|
|
11
|
+
/** @deprecated Use `variant` instead. */
|
|
11
12
|
type?: Variant;
|
|
13
|
+
variant?: Variant;
|
|
12
14
|
isRoundedBottomCorner?: boolean;
|
|
13
15
|
theme?: ITheme;
|
|
14
16
|
disabled?: boolean;
|
|
@@ -17,5 +19,5 @@ export interface IProps extends AccessibilityProps {
|
|
|
17
19
|
suffix?: ReactNode;
|
|
18
20
|
inverted?: boolean;
|
|
19
21
|
}
|
|
20
|
-
export declare function PxButton(
|
|
22
|
+
export declare function PxButton(props: IProps): React.JSX.Element;
|
|
21
23
|
//# sourceMappingURL=PxButton.d.ts.map
|
package/dist/PxButton.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PxButton.d.ts","sourceRoot":"","sources":["../src/PxButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,SAAS,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EACV,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,SAAS,EACV,MAAM,cAAc,CAAC;AAGtB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAIhE,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC;AAE3D,MAAM,WAAW,MAAO,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AK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAgGD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,qBA0HrC"}
|
package/dist/PxButton.js
CHANGED
|
@@ -3,10 +3,24 @@ import { StyleSheet, TouchableOpacity, View } from 'react-native';
|
|
|
3
3
|
import { a11y, e2eID } from '@proximus/lavender-common-native';
|
|
4
4
|
import { useTheme } from '@proximus/lavender-styling-native';
|
|
5
5
|
import { Header } from '@proximus/lavender-texts-native';
|
|
6
|
+
/**
|
|
7
|
+
* Keeps backward compatibility for `type` prop.
|
|
8
|
+
* @param props
|
|
9
|
+
*/
|
|
10
|
+
function useVariant(props) {
|
|
11
|
+
const { variant, type } = props;
|
|
12
|
+
if (type && !variant) {
|
|
13
|
+
return type;
|
|
14
|
+
}
|
|
15
|
+
else if (!variant) {
|
|
16
|
+
return 'primary';
|
|
17
|
+
}
|
|
18
|
+
return variant;
|
|
19
|
+
}
|
|
6
20
|
function getButtonColors(props, theme) {
|
|
7
|
-
const {
|
|
21
|
+
const { variant, inverted = false } = props;
|
|
8
22
|
const invertedSuffix = inverted ? 'Inverted' : 'Default';
|
|
9
|
-
switch (
|
|
23
|
+
switch (variant) {
|
|
10
24
|
case 'secondary': {
|
|
11
25
|
return {
|
|
12
26
|
backgroundColor: theme.t(`ColorBackgroundContainerSecondary${invertedSuffix}`),
|
|
@@ -37,9 +51,9 @@ function getButtonColors(props, theme) {
|
|
|
37
51
|
}
|
|
38
52
|
}
|
|
39
53
|
function getIconColor(props, theme) {
|
|
40
|
-
const {
|
|
54
|
+
const { variant, disabled, inverted } = props;
|
|
41
55
|
const invertedSuffix = inverted ? 'Inverted' : 'Default';
|
|
42
|
-
switch (
|
|
56
|
+
switch (variant) {
|
|
43
57
|
case 'primary':
|
|
44
58
|
return disabled
|
|
45
59
|
? theme.t(`ColorIconStateDisabled${invertedSuffix}`)
|
|
@@ -53,9 +67,9 @@ function getIconColor(props, theme) {
|
|
|
53
67
|
}
|
|
54
68
|
}
|
|
55
69
|
function getIconBackgroundColor(props, theme) {
|
|
56
|
-
const {
|
|
70
|
+
const { variant, disabled, inverted } = props;
|
|
57
71
|
const invertedSuffix = inverted ? 'Inverted' : 'Default';
|
|
58
|
-
switch (
|
|
72
|
+
switch (variant) {
|
|
59
73
|
case 'tertiary':
|
|
60
74
|
return disabled
|
|
61
75
|
? theme.t(`ColorBackgroundStateDisabled${invertedSuffix}`)
|
|
@@ -64,25 +78,27 @@ function getIconBackgroundColor(props, theme) {
|
|
|
64
78
|
return undefined;
|
|
65
79
|
}
|
|
66
80
|
}
|
|
67
|
-
export function PxButton(
|
|
81
|
+
export function PxButton(props) {
|
|
82
|
+
const { title, wrapperStyle, titleStyle, isRoundedBottomCorner = true, testID, disabled = false, prefix, suffix, onPress, accessibilityLabel, accessibilityHint, inverted, } = props;
|
|
68
83
|
const { theme } = useTheme();
|
|
69
|
-
const
|
|
84
|
+
const variant = useVariant(props);
|
|
85
|
+
const buttonColors = getButtonColors({ variant, inverted }, theme);
|
|
70
86
|
const iconStyles = {
|
|
71
87
|
size: 'Xs',
|
|
72
|
-
|
|
88
|
+
deprecatedColor: getIconColor({ variant, disabled, inverted }, theme),
|
|
73
89
|
padding: theme.t('Padding2xsMobile').number,
|
|
74
90
|
};
|
|
75
91
|
const iconBackgroundStyles = {
|
|
76
|
-
backgroundColor: getIconBackgroundColor({
|
|
92
|
+
backgroundColor: getIconBackgroundColor({ variant, disabled, inverted }, theme),
|
|
77
93
|
borderRadius: theme.t('RadiusPill').number,
|
|
78
94
|
marginHorizontal: theme.t('SpacingXsMobile').number,
|
|
79
95
|
};
|
|
80
96
|
let adaptedPrefix = prefix && React.cloneElement(prefix, iconStyles);
|
|
81
97
|
adaptedPrefix =
|
|
82
|
-
prefix &&
|
|
98
|
+
prefix && variant === 'tertiary' ? (React.createElement(View, { style: iconBackgroundStyles }, adaptedPrefix)) : (adaptedPrefix);
|
|
83
99
|
let adaptedSuffix = suffix && React.cloneElement(suffix, iconStyles);
|
|
84
100
|
adaptedSuffix =
|
|
85
|
-
suffix &&
|
|
101
|
+
suffix && variant === 'tertiary' ? (React.createElement(View, { style: iconBackgroundStyles }, adaptedSuffix)) : (adaptedSuffix);
|
|
86
102
|
return (React.createElement(TouchableOpacity, { ...e2eID(testID), onPress: onPress, focusable: true, disabled: disabled, ...a11y({
|
|
87
103
|
accessibilityRole: 'button',
|
|
88
104
|
accessible: true,
|
|
@@ -101,19 +117,19 @@ export function PxButton({ title, wrapperStyle, titleStyle, isRoundedBottomCorne
|
|
|
101
117
|
...(isRoundedBottomCorner && {
|
|
102
118
|
borderBottomEndRadius: theme.t('RadiusButtonBig').number,
|
|
103
119
|
}),
|
|
104
|
-
paddingHorizontal:
|
|
105
|
-
paddingVertical:
|
|
120
|
+
paddingHorizontal: variant === 'tertiary' ? 0 : theme.t('PaddingMMobile').number,
|
|
121
|
+
paddingVertical: variant === 'tertiary'
|
|
106
122
|
? theme.t('Padding2xsMobile').number
|
|
107
123
|
: theme.t('PaddingXsMobile').number,
|
|
108
124
|
gap: theme.t('Spacing2xsMobile').number,
|
|
109
|
-
...(
|
|
125
|
+
...(variant !== 'tertiary' && {
|
|
110
126
|
minHeight: theme.t('SpacingLMobile').number,
|
|
111
127
|
}),
|
|
112
128
|
},
|
|
113
129
|
disabled && {
|
|
114
130
|
backgroundColor: buttonColors.disabledBackgroundColor,
|
|
115
131
|
},
|
|
116
|
-
|
|
132
|
+
variant === 'tertiary' && {
|
|
117
133
|
paddingVertical: 4,
|
|
118
134
|
paddingHorizontal: 0,
|
|
119
135
|
},
|