@metamask-previews/design-system-react-native 0.0.0-preview.ff8ed96 → 0.2.0-preview.a7d80d5
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/CHANGELOG.md +38 -1
- package/dist/components/AvatarBase/AvatarBase.types.d.cts +0 -1
- package/dist/components/AvatarBase/AvatarBase.types.d.cts.map +1 -1
- package/dist/components/AvatarBase/AvatarBase.types.d.mts +0 -1
- package/dist/components/AvatarBase/AvatarBase.types.d.mts.map +1 -1
- package/dist/components/AvatarFavicon/AvatarFavicon.cjs.map +1 -1
- package/dist/components/AvatarFavicon/AvatarFavicon.mjs.map +1 -1
- package/dist/components/AvatarGroup/AvatarGroup.cjs +2 -2
- package/dist/components/AvatarGroup/AvatarGroup.cjs.map +1 -1
- package/dist/components/AvatarGroup/AvatarGroup.mjs +3 -3
- package/dist/components/AvatarGroup/AvatarGroup.mjs.map +1 -1
- package/dist/components/AvatarNetwork/AvatarNetwork.cjs.map +1 -1
- package/dist/components/AvatarNetwork/AvatarNetwork.mjs.map +1 -1
- package/dist/components/AvatarToken/AvatarToken.cjs.map +1 -1
- package/dist/components/AvatarToken/AvatarToken.mjs.map +1 -1
- package/dist/components/BadgeWrapper/BadgeWrapper.cjs +1 -1
- package/dist/components/BadgeWrapper/BadgeWrapper.cjs.map +1 -1
- package/dist/components/BadgeWrapper/BadgeWrapper.mjs +1 -1
- package/dist/components/BadgeWrapper/BadgeWrapper.mjs.map +1 -1
- package/dist/components/BadgeWrapper/BadgeWrapper.types.d.cts +0 -1
- package/dist/components/BadgeWrapper/BadgeWrapper.types.d.cts.map +1 -1
- package/dist/components/BadgeWrapper/BadgeWrapper.types.d.mts +0 -1
- package/dist/components/BadgeWrapper/BadgeWrapper.types.d.mts.map +1 -1
- package/dist/components/Box/Box.cjs +22 -5
- package/dist/components/Box/Box.cjs.map +1 -1
- package/dist/components/Box/Box.constants.cjs +218 -1
- package/dist/components/Box/Box.constants.cjs.map +1 -1
- package/dist/components/Box/Box.constants.d.cts +16 -1
- package/dist/components/Box/Box.constants.d.cts.map +1 -1
- package/dist/components/Box/Box.constants.d.mts +16 -1
- package/dist/components/Box/Box.constants.d.mts.map +1 -1
- package/dist/components/Box/Box.constants.mjs +217 -0
- package/dist/components/Box/Box.constants.mjs.map +1 -1
- package/dist/components/Box/Box.d.cts +1 -1
- package/dist/components/Box/Box.d.cts.map +1 -1
- package/dist/components/Box/Box.d.mts +1 -1
- package/dist/components/Box/Box.d.mts.map +1 -1
- package/dist/components/Box/Box.mjs +23 -6
- package/dist/components/Box/Box.mjs.map +1 -1
- package/dist/components/Box/Box.types.cjs.map +1 -1
- package/dist/components/Box/Box.types.d.cts +84 -1
- package/dist/components/Box/Box.types.d.cts.map +1 -1
- package/dist/components/Box/Box.types.d.mts +84 -1
- package/dist/components/Box/Box.types.d.mts.map +1 -1
- package/dist/components/Box/Box.types.mjs.map +1 -1
- package/dist/components/Box/index.cjs.map +1 -1
- package/dist/components/Box/index.d.cts +1 -1
- package/dist/components/Box/index.d.cts.map +1 -1
- package/dist/components/Box/index.d.mts +1 -1
- package/dist/components/Box/index.d.mts.map +1 -1
- package/dist/components/Box/index.mjs.map +1 -1
- package/dist/components/Button/Button.cjs +1 -1
- package/dist/components/Button/Button.cjs.map +1 -1
- package/dist/components/Button/Button.mjs +1 -1
- package/dist/components/Button/Button.mjs.map +1 -1
- package/dist/components/Button/variants/ButtonPrimary/ButtonPrimary.cjs +29 -57
- package/dist/components/Button/variants/ButtonPrimary/ButtonPrimary.cjs.map +1 -1
- package/dist/components/Button/variants/ButtonPrimary/ButtonPrimary.d.cts +1 -1
- package/dist/components/Button/variants/ButtonPrimary/ButtonPrimary.d.cts.map +1 -1
- package/dist/components/Button/variants/ButtonPrimary/ButtonPrimary.d.mts +1 -1
- package/dist/components/Button/variants/ButtonPrimary/ButtonPrimary.d.mts.map +1 -1
- package/dist/components/Button/variants/ButtonPrimary/ButtonPrimary.mjs +30 -58
- package/dist/components/Button/variants/ButtonPrimary/ButtonPrimary.mjs.map +1 -1
- package/dist/components/Button/variants/ButtonSecondary/ButtonSecondary.cjs +46 -53
- package/dist/components/Button/variants/ButtonSecondary/ButtonSecondary.cjs.map +1 -1
- package/dist/components/Button/variants/ButtonSecondary/ButtonSecondary.d.cts +1 -1
- package/dist/components/Button/variants/ButtonSecondary/ButtonSecondary.d.cts.map +1 -1
- package/dist/components/Button/variants/ButtonSecondary/ButtonSecondary.d.mts +1 -1
- package/dist/components/Button/variants/ButtonSecondary/ButtonSecondary.d.mts.map +1 -1
- package/dist/components/Button/variants/ButtonSecondary/ButtonSecondary.mjs +47 -54
- package/dist/components/Button/variants/ButtonSecondary/ButtonSecondary.mjs.map +1 -1
- package/dist/components/Button/variants/ButtonTertiary/ButtonTertiary.cjs +53 -59
- package/dist/components/Button/variants/ButtonTertiary/ButtonTertiary.cjs.map +1 -1
- package/dist/components/Button/variants/ButtonTertiary/ButtonTertiary.d.cts +1 -1
- package/dist/components/Button/variants/ButtonTertiary/ButtonTertiary.d.cts.map +1 -1
- package/dist/components/Button/variants/ButtonTertiary/ButtonTertiary.d.mts +1 -1
- package/dist/components/Button/variants/ButtonTertiary/ButtonTertiary.d.mts.map +1 -1
- package/dist/components/Button/variants/ButtonTertiary/ButtonTertiary.mjs +54 -60
- package/dist/components/Button/variants/ButtonTertiary/ButtonTertiary.mjs.map +1 -1
- package/dist/components/ButtonBase/ButtonBase.cjs +110 -28
- package/dist/components/ButtonBase/ButtonBase.cjs.map +1 -1
- package/dist/components/ButtonBase/ButtonBase.constants.cjs +10 -0
- package/dist/components/ButtonBase/ButtonBase.constants.cjs.map +1 -0
- package/dist/components/ButtonBase/ButtonBase.constants.d.cts +3 -0
- package/dist/components/ButtonBase/ButtonBase.constants.d.cts.map +1 -0
- package/dist/components/ButtonBase/ButtonBase.constants.d.mts +3 -0
- package/dist/components/ButtonBase/ButtonBase.constants.d.mts.map +1 -0
- package/dist/components/ButtonBase/ButtonBase.constants.mjs +7 -0
- package/dist/components/ButtonBase/ButtonBase.constants.mjs.map +1 -0
- package/dist/components/ButtonBase/ButtonBase.d.cts +1 -1
- package/dist/components/ButtonBase/ButtonBase.d.cts.map +1 -1
- package/dist/components/ButtonBase/ButtonBase.d.mts +1 -1
- package/dist/components/ButtonBase/ButtonBase.d.mts.map +1 -1
- package/dist/components/ButtonBase/ButtonBase.mjs +88 -26
- package/dist/components/ButtonBase/ButtonBase.mjs.map +1 -1
- package/dist/components/ButtonBase/ButtonBase.types.cjs.map +1 -1
- package/dist/components/ButtonBase/ButtonBase.types.d.cts +42 -3
- package/dist/components/ButtonBase/ButtonBase.types.d.cts.map +1 -1
- package/dist/components/ButtonBase/ButtonBase.types.d.mts +42 -3
- package/dist/components/ButtonBase/ButtonBase.types.d.mts.map +1 -1
- package/dist/components/ButtonBase/ButtonBase.types.mjs.map +1 -1
- package/dist/components/ButtonBase/index.cjs +3 -1
- package/dist/components/ButtonBase/index.cjs.map +1 -1
- package/dist/components/ButtonBase/index.d.cts +1 -0
- package/dist/components/ButtonBase/index.d.cts.map +1 -1
- package/dist/components/ButtonBase/index.d.mts +1 -0
- package/dist/components/ButtonBase/index.d.mts.map +1 -1
- package/dist/components/ButtonBase/index.mjs +1 -0
- package/dist/components/ButtonBase/index.mjs.map +1 -1
- package/dist/components/ButtonIcon/ButtonIcon.cjs +9 -1
- package/dist/components/ButtonIcon/ButtonIcon.cjs.map +1 -1
- package/dist/components/ButtonIcon/ButtonIcon.d.cts.map +1 -1
- package/dist/components/ButtonIcon/ButtonIcon.d.mts.map +1 -1
- package/dist/components/ButtonIcon/ButtonIcon.mjs +9 -1
- package/dist/components/ButtonIcon/ButtonIcon.mjs.map +1 -1
- package/dist/components/Checkbox/Checkbox.cjs +1 -1
- package/dist/components/Checkbox/Checkbox.cjs.map +1 -1
- package/dist/components/Checkbox/Checkbox.mjs +1 -1
- package/dist/components/Checkbox/Checkbox.mjs.map +1 -1
- package/dist/components/Checkbox/Checkbox.types.d.cts +0 -1
- package/dist/components/Checkbox/Checkbox.types.d.cts.map +1 -1
- package/dist/components/Checkbox/Checkbox.types.d.mts +0 -1
- package/dist/components/Checkbox/Checkbox.types.d.mts.map +1 -1
- package/dist/components/Icon/Icon.assets.cjs +2 -3
- package/dist/components/Icon/Icon.assets.cjs.map +1 -1
- package/dist/components/Icon/Icon.assets.mjs +2 -3
- package/dist/components/Icon/Icon.assets.mjs.map +1 -1
- package/dist/components/Text/Text.constants.cjs +9 -0
- package/dist/components/Text/Text.constants.cjs.map +1 -1
- package/dist/components/Text/Text.constants.d.cts.map +1 -1
- package/dist/components/Text/Text.constants.d.mts.map +1 -1
- package/dist/components/Text/Text.constants.mjs +9 -0
- package/dist/components/Text/Text.constants.mjs.map +1 -1
- package/dist/components/Text/Text.types.cjs.map +1 -1
- package/dist/components/Text/Text.types.d.cts +1 -2
- package/dist/components/Text/Text.types.d.cts.map +1 -1
- package/dist/components/Text/Text.types.d.mts +1 -2
- package/dist/components/Text/Text.types.d.mts.map +1 -1
- package/dist/components/Text/Text.types.mjs.map +1 -1
- package/dist/components/TextButton/TextButton.cjs +1 -0
- package/dist/components/TextButton/TextButton.cjs.map +1 -1
- package/dist/components/TextButton/TextButton.d.cts.map +1 -1
- package/dist/components/TextButton/TextButton.d.mts.map +1 -1
- package/dist/components/TextButton/TextButton.mjs +1 -0
- package/dist/components/TextButton/TextButton.mjs.map +1 -1
- package/dist/components/TextButton/TextButton.types.d.cts +0 -1
- package/dist/components/TextButton/TextButton.types.d.cts.map +1 -1
- package/dist/components/TextButton/TextButton.types.d.mts +0 -1
- package/dist/components/TextButton/TextButton.types.d.mts.map +1 -1
- package/dist/components/temp-components/ImageOrSvg/ImageOrSvg.types.d.cts +0 -1
- package/dist/components/temp-components/ImageOrSvg/ImageOrSvg.types.d.cts.map +1 -1
- package/dist/components/temp-components/ImageOrSvg/ImageOrSvg.types.d.mts +0 -1
- package/dist/components/temp-components/ImageOrSvg/ImageOrSvg.types.d.mts.map +1 -1
- package/dist/components/temp-components/TextOrChildren/TextOrChildren.types.d.cts +0 -1
- package/dist/components/temp-components/TextOrChildren/TextOrChildren.types.d.cts.map +1 -1
- package/dist/components/temp-components/TextOrChildren/TextOrChildren.types.d.mts +0 -1
- package/dist/components/temp-components/TextOrChildren/TextOrChildren.types.d.mts.map +1 -1
- package/dist/types/index.cjs +143 -4
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +141 -4
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.mts +141 -4
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs +142 -3
- package/dist/types/index.mjs.map +1 -1
- package/package.json +13 -13
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { ButtonTertiaryProps } from "./ButtonTertiary.types.mjs";
|
|
3
|
-
export declare const ButtonTertiary: ({ children, textProps, spinnerProps, startIconProps, endIconProps, isDanger, isInverse, isLoading,
|
|
3
|
+
export declare const ButtonTertiary: ({ children, textProps, spinnerProps, startIconProps, endIconProps, isDanger, isInverse, isLoading, twClassName, style, ...props }: ButtonTertiaryProps) => React.JSX.Element;
|
|
4
4
|
//# sourceMappingURL=ButtonTertiary.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ButtonTertiary.d.mts","sourceRoot":"","sources":["../../../../../src/components/Button/variants/ButtonTertiary/ButtonTertiary.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ButtonTertiary.d.mts","sourceRoot":"","sources":["../../../../../src/components/Button/variants/ButtonTertiary/ButtonTertiary.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsB,cAAc;AAM3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,mCAA+B;AAElE,eAAO,MAAM,cAAc,sIAYxB,mBAAmB,sBA6FrB,CAAC"}
|
|
@@ -4,85 +4,79 @@ function $importDefault(module) {
|
|
|
4
4
|
}
|
|
5
5
|
return module;
|
|
6
6
|
}
|
|
7
|
-
import {
|
|
8
|
-
import $React, { useState } from "react";
|
|
7
|
+
import $React, { useCallback } from "react";
|
|
9
8
|
const React = $importDefault($React);
|
|
10
9
|
import { ButtonBase } from "../../../ButtonBase/index.mjs";
|
|
11
10
|
import { IconSize } from "../../../Icon/index.mjs";
|
|
12
11
|
import { TextVariant, FontWeight } from "../../../Text/index.mjs";
|
|
13
|
-
export const ButtonTertiary = ({ children, textProps, spinnerProps, startIconProps, endIconProps, isDanger = false, isInverse = false, isLoading = false,
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
: 'bg-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
? '
|
|
28
|
-
: '
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
: '
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
12
|
+
export const ButtonTertiary = ({ children, textProps, spinnerProps, startIconProps, endIconProps, isDanger = false, isInverse = false, isLoading = false, twClassName = '', style, ...props }) => {
|
|
13
|
+
const getContainerClassName = useCallback((pressed) => {
|
|
14
|
+
const classNameStr = typeof twClassName === 'function' ? twClassName(pressed) : twClassName;
|
|
15
|
+
const baseClasses = `
|
|
16
|
+
${isInverse && !isDanger ? 'border-[1.5px]' : 'border-0'}
|
|
17
|
+
${classNameStr}
|
|
18
|
+
`;
|
|
19
|
+
let backgroundClass = '';
|
|
20
|
+
let borderClass = '';
|
|
21
|
+
if (isInverse && isDanger) {
|
|
22
|
+
backgroundClass =
|
|
23
|
+
pressed || isLoading ? 'bg-default-pressed' : 'bg-default';
|
|
24
|
+
borderClass =
|
|
25
|
+
pressed || isLoading
|
|
26
|
+
? 'border-background-default-pressed'
|
|
27
|
+
: 'border-background-default';
|
|
28
|
+
}
|
|
29
|
+
else if (isDanger) {
|
|
30
|
+
backgroundClass =
|
|
31
|
+
pressed || isLoading ? 'bg-error-muted-pressed' : 'bg-transparent';
|
|
32
|
+
borderClass =
|
|
33
|
+
pressed || isLoading
|
|
34
|
+
? 'border-error-muted-pressed'
|
|
35
|
+
: 'border-transparent';
|
|
36
|
+
}
|
|
37
|
+
else if (isInverse) {
|
|
38
|
+
backgroundClass =
|
|
39
|
+
pressed || isLoading ? 'bg-pressed' : 'bg-transparent';
|
|
40
|
+
borderClass = 'border-primary-inverse';
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
backgroundClass =
|
|
44
|
+
pressed || isLoading ? 'bg-pressed' : 'bg-transparent';
|
|
45
|
+
borderClass =
|
|
46
|
+
pressed || isLoading
|
|
44
47
|
? 'border-background-pressed'
|
|
45
|
-
: 'border-transparent'
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
onPressOut?.(event);
|
|
63
|
-
};
|
|
48
|
+
: 'border-transparent';
|
|
49
|
+
}
|
|
50
|
+
return `${backgroundClass} ${borderClass} ${baseClasses}`;
|
|
51
|
+
}, [isInverse, isDanger, isLoading, twClassName]);
|
|
52
|
+
const getTextClassName = useCallback((pressed) => {
|
|
53
|
+
if (isDanger) {
|
|
54
|
+
return pressed || isLoading
|
|
55
|
+
? 'text-error-default-pressed'
|
|
56
|
+
: 'text-error-default';
|
|
57
|
+
}
|
|
58
|
+
if (isInverse) {
|
|
59
|
+
return 'text-primary-inverse';
|
|
60
|
+
}
|
|
61
|
+
return pressed || isLoading
|
|
62
|
+
? 'text-primary-default-pressed'
|
|
63
|
+
: 'text-primary-default';
|
|
64
|
+
}, [isDanger, isInverse, isLoading]);
|
|
64
65
|
return (<ButtonBase textProps={{
|
|
65
66
|
variant: TextVariant.BodyMd,
|
|
66
67
|
fontWeight: FontWeight.Medium,
|
|
67
68
|
numberOfLines: 1,
|
|
68
69
|
ellipsizeMode: 'clip',
|
|
69
70
|
...textProps,
|
|
70
|
-
twClassName: `${twTextClassNames} ${textProps?.twClassName ?? ''}`,
|
|
71
71
|
}} spinnerProps={{
|
|
72
|
-
color: twTextClassNames,
|
|
73
|
-
loadingTextProps: {
|
|
74
|
-
twClassName: twTextClassNames,
|
|
75
|
-
},
|
|
76
72
|
...spinnerProps,
|
|
77
73
|
}} startIconProps={{
|
|
78
74
|
size: IconSize.Sm,
|
|
79
75
|
...startIconProps,
|
|
80
|
-
twClassName: `${twTextClassNames} ${startIconProps?.twClassName ?? ''}`,
|
|
81
76
|
}} endIconProps={{
|
|
82
77
|
size: IconSize.Sm,
|
|
83
78
|
...endIconProps,
|
|
84
|
-
|
|
85
|
-
}} isLoading={isLoading} onPressIn={onPressInHandler} onPressOut={onPressOutHandler} style={[tw `${twContainerClassNames}`, style]} {...props}>
|
|
79
|
+
}} isLoading={isLoading} twClassName={getContainerClassName} textClassName={getTextClassName} iconClassName={getTextClassName} style={style} {...props}>
|
|
86
80
|
{children}
|
|
87
81
|
</ButtonBase>);
|
|
88
82
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ButtonTertiary.mjs","sourceRoot":"","sources":["../../../../../src/components/Button/variants/ButtonTertiary/ButtonTertiary.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ButtonTertiary.mjs","sourceRoot":"","sources":["../../../../../src/components/Button/variants/ButtonTertiary/ButtonTertiary.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,QAAO,EAAE,WAAW,EAAE,cAAc;;AAE3C,OAAO,EAAE,UAAU,EAAE,sCAA4B;AACjD,OAAO,EAAE,QAAQ,EAAE,gCAAsB;AACzC,OAAO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Y;SAChB,CAAC,CACF,SAAS,CAAC,CAAC,SAAS,CAAC,CACrB,WAAW,CAAC,CAAC,qBAAqB,CAAC,CACnC,aAAa,CAAC,CAAC,gBAAgB,CAAC,CAChC,aAAa,CAAC,CAAC,gBAAgB,CAAC,CAChC,KAAK,CAAC,CAAC,KAAK,CAAC,CACb,IAAI,KAAK,CAAC,CAEV;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,UAAU,CAAC,CACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React, { useCallback } from 'react';\n\nimport { ButtonBase } from '../../../ButtonBase';\nimport { IconSize } from '../../../Icon';\nimport { TextVariant, FontWeight } from '../../../Text';\n\nimport type { ButtonTertiaryProps } from './ButtonTertiary.types';\n\nexport const ButtonTertiary = ({\n children,\n textProps,\n spinnerProps,\n startIconProps,\n endIconProps,\n isDanger = false,\n isInverse = false,\n isLoading = false,\n twClassName = '',\n style,\n ...props\n}: ButtonTertiaryProps) => {\n const getContainerClassName = useCallback(\n (pressed: boolean): string => {\n const classNameStr =\n typeof twClassName === 'function' ? twClassName(pressed) : twClassName;\n\n const baseClasses = `\n ${isInverse && !isDanger ? 'border-[1.5px]' : 'border-0'}\n ${classNameStr}\n `;\n\n let backgroundClass = '';\n let borderClass = '';\n\n if (isInverse && isDanger) {\n backgroundClass =\n pressed || isLoading ? 'bg-default-pressed' : 'bg-default';\n borderClass =\n pressed || isLoading\n ? 'border-background-default-pressed'\n : 'border-background-default';\n } else if (isDanger) {\n backgroundClass =\n pressed || isLoading ? 'bg-error-muted-pressed' : 'bg-transparent';\n borderClass =\n pressed || isLoading\n ? 'border-error-muted-pressed'\n : 'border-transparent';\n } else if (isInverse) {\n backgroundClass =\n pressed || isLoading ? 'bg-pressed' : 'bg-transparent';\n borderClass = 'border-primary-inverse';\n } else {\n backgroundClass =\n pressed || isLoading ? 'bg-pressed' : 'bg-transparent';\n borderClass =\n pressed || isLoading\n ? 'border-background-pressed'\n : 'border-transparent';\n }\n\n return `${backgroundClass} ${borderClass} ${baseClasses}`;\n },\n [isInverse, isDanger, isLoading, twClassName],\n );\n\n const getTextClassName = useCallback(\n (pressed: boolean): string => {\n if (isDanger) {\n return pressed || isLoading\n ? 'text-error-default-pressed'\n : 'text-error-default';\n }\n if (isInverse) {\n return 'text-primary-inverse';\n }\n return pressed || isLoading\n ? 'text-primary-default-pressed'\n : 'text-primary-default';\n },\n [isDanger, isInverse, isLoading],\n );\n\n return (\n <ButtonBase\n textProps={{\n variant: TextVariant.BodyMd,\n fontWeight: FontWeight.Medium,\n numberOfLines: 1,\n ellipsizeMode: 'clip',\n ...textProps,\n }}\n spinnerProps={{\n ...spinnerProps,\n }}\n startIconProps={{\n size: IconSize.Sm,\n ...startIconProps,\n }}\n endIconProps={{\n size: IconSize.Sm,\n ...endIconProps,\n }}\n isLoading={isLoading}\n twClassName={getContainerClassName}\n textClassName={getTextClassName}\n iconClassName={getTextClassName}\n style={style}\n {...props}\n >\n {children}\n </ButtonBase>\n );\n};\n"]}
|
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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;
|
|
4
24
|
};
|
|
5
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
26
|
exports.ButtonBase = void 0;
|
|
7
27
|
const design_system_twrnc_preset_1 = require("@metamask-previews/design-system-twrnc-preset");
|
|
8
|
-
const react_1 =
|
|
28
|
+
const react_1 = __importStar(require("react"));
|
|
9
29
|
const react_native_1 = require("react-native/index.js");
|
|
10
30
|
const types_1 = require("../../types/index.cjs");
|
|
11
31
|
const Icon_1 = require("../Icon/index.cjs");
|
|
@@ -14,34 +34,96 @@ const ButtonAnimated_1 = require("../temp-components/ButtonAnimated/index.cjs");
|
|
|
14
34
|
const Spinner_1 = require("../temp-components/Spinner/index.cjs");
|
|
15
35
|
const TextOrChildren_1 = require("../temp-components/TextOrChildren/TextOrChildren.cjs");
|
|
16
36
|
const Text_1 = require("../Text/index.cjs");
|
|
17
|
-
const
|
|
37
|
+
const ButtonBase_constants_1 = require("./ButtonBase.constants.cjs");
|
|
38
|
+
const ButtonBase = ({ children, textProps, size = types_1.ButtonBaseSize.Lg, isLoading, loadingText, spinnerProps, startIconName, startIconProps, startAccessory, endIconName, endIconProps, endAccessory, isDisabled, isFullWidth, twClassName = '', textClassName, iconClassName, style, accessibilityLabel, accessibilityHint, accessibilityRole = 'button', accessibilityActions, onAccessibilityAction, ...props }) => {
|
|
18
39
|
const tw = (0, design_system_twrnc_preset_1.useTailwind)();
|
|
19
|
-
const twContainerClassNames = `
|
|
20
|
-
flex-row items-center justify-center rounded-full bg-muted px-4 min-w-[80px] overflow-hidden
|
|
21
|
-
h-[${size}px]
|
|
22
|
-
${isDisabled ? 'opacity-50' : 'opacity-100'}
|
|
23
|
-
${isFullWidth ? 'self-stretch' : 'self-start'}
|
|
24
|
-
${twClassName}
|
|
25
|
-
`;
|
|
26
40
|
const finalStartIconName = startIconName ?? startIconProps?.name;
|
|
27
41
|
const finalEndIconName = endIconName ?? endIconProps?.name;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
// Generate accessibility label if not provided
|
|
43
|
+
const finalAccessibilityLabel = (0, react_1.useMemo)(() => {
|
|
44
|
+
if (accessibilityLabel) {
|
|
45
|
+
return accessibilityLabel;
|
|
46
|
+
}
|
|
47
|
+
// For loading state with loadingText, prioritize loadingText
|
|
48
|
+
if (isLoading && loadingText) {
|
|
49
|
+
return loadingText;
|
|
50
|
+
}
|
|
51
|
+
// If children is a string, use it as the label
|
|
52
|
+
if (typeof children === 'string') {
|
|
53
|
+
return children;
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}, [accessibilityLabel, children, isLoading, loadingText]);
|
|
57
|
+
// Generate accessibility hint for loading state if not provided
|
|
58
|
+
const finalAccessibilityHint = (0, react_1.useMemo)(() => {
|
|
59
|
+
if (accessibilityHint) {
|
|
60
|
+
return accessibilityHint;
|
|
61
|
+
}
|
|
62
|
+
if (isLoading) {
|
|
63
|
+
return 'Button is currently loading, please wait';
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}, [accessibilityHint, isLoading]);
|
|
67
|
+
// Create accessibilityState object with only truthy values
|
|
68
|
+
const accessibilityState = (0, react_1.useMemo)(() => {
|
|
69
|
+
const state = {};
|
|
70
|
+
if (isDisabled || isLoading) {
|
|
71
|
+
state.disabled = true;
|
|
72
|
+
}
|
|
73
|
+
if (isLoading) {
|
|
74
|
+
state.busy = true;
|
|
75
|
+
}
|
|
76
|
+
return state;
|
|
77
|
+
}, [isDisabled, isLoading]);
|
|
78
|
+
return (<ButtonAnimated_1.ButtonAnimated disabled={isDisabled || isLoading} accessibilityRole={accessibilityRole} accessibilityLabel={finalAccessibilityLabel} accessibilityHint={finalAccessibilityHint} accessibilityActions={accessibilityActions} onAccessibilityAction={onAccessibilityAction} accessibilityState={accessibilityState} accessible style={({ pressed }) => {
|
|
79
|
+
const containerClassName = typeof twClassName === 'function'
|
|
80
|
+
? twClassName(pressed)
|
|
81
|
+
: twClassName;
|
|
82
|
+
const baseContainerClassNames = `
|
|
83
|
+
flex-row items-center justify-center rounded-xl bg-muted px-4 min-w-[80px] overflow-hidden
|
|
84
|
+
${ButtonBase_constants_1.TWCLASSMAP_BUTTONBASE_SIZE_DIMENSION[size]}
|
|
85
|
+
${isDisabled ? 'opacity-50' : 'opacity-100'}
|
|
86
|
+
${isFullWidth ? 'w-full' : 'w-auto'}
|
|
87
|
+
${containerClassName}
|
|
88
|
+
`;
|
|
89
|
+
const computedStyle = [
|
|
90
|
+
tw `${baseContainerClassNames}`,
|
|
91
|
+
];
|
|
92
|
+
if (typeof style === 'function') {
|
|
93
|
+
const additionalStyle = style({ pressed });
|
|
94
|
+
if (additionalStyle) {
|
|
95
|
+
computedStyle.push(additionalStyle);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else if (style) {
|
|
99
|
+
computedStyle.push(style);
|
|
100
|
+
}
|
|
101
|
+
return computedStyle;
|
|
102
|
+
}} {...props}>
|
|
103
|
+
{({ pressed }) => (<>
|
|
104
|
+
<react_native_1.View style={tw `absolute inset-0 flex items-center justify-center ${isLoading ? 'opacity-100' : 'opacity-0'}`} testID="spinner-container">
|
|
105
|
+
<Spinner_1.Spinner color={textClassName
|
|
106
|
+
? textClassName(pressed)
|
|
107
|
+
: Icon_2.IconColor.IconDefault} loadingText={loadingText} loadingTextProps={{
|
|
108
|
+
numberOfLines: 1,
|
|
109
|
+
twClassName: textClassName ? textClassName(pressed) : '',
|
|
110
|
+
...spinnerProps?.loadingTextProps,
|
|
111
|
+
}} {...spinnerProps}/>
|
|
112
|
+
</react_native_1.View>
|
|
113
|
+
<react_native_1.View style={tw `flex-row items-center justify-center gap-x-2 ${isLoading ? 'opacity-0' : 'opacity-100'}`} testID="content-container">
|
|
114
|
+
{finalStartIconName ? (<Icon_1.Icon name={finalStartIconName} size={Icon_2.IconSize.Sm} twClassName={`shrink-0 ${iconClassName ? iconClassName(pressed) : ''}`} {...startIconProps}/>) : (startAccessory)}
|
|
115
|
+
<TextOrChildren_1.TextOrChildren textProps={{
|
|
116
|
+
variant: Text_1.TextVariant.BodyMd,
|
|
117
|
+
fontWeight: Text_1.FontWeight.Medium,
|
|
118
|
+
color: Text_1.TextColor.TextDefault,
|
|
119
|
+
twClassName: `shrink grow-0 flex-wrap text-center ${textClassName ? textClassName(pressed) : ''}`,
|
|
120
|
+
...textProps,
|
|
121
|
+
}}>
|
|
122
|
+
{children}
|
|
123
|
+
</TextOrChildren_1.TextOrChildren>
|
|
124
|
+
{finalEndIconName ? (<Icon_1.Icon name={finalEndIconName} size={Icon_2.IconSize.Sm} twClassName={`shrink-0 ${iconClassName ? iconClassName(pressed) : ''}`} {...endIconProps}/>) : (endAccessory)}
|
|
125
|
+
</react_native_1.View>
|
|
126
|
+
</>)}
|
|
45
127
|
</ButtonAnimated_1.ButtonAnimated>);
|
|
46
128
|
};
|
|
47
129
|
exports.ButtonBase = ButtonBase;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ButtonBase.cjs","sourceRoot":"","sources":["../../../src/components/ButtonBase/ButtonBase.tsx"],"names":[],"mappings":";;;;;;AAAA,8FAA4E;AAC5E,kDAA0B;AAC1B,wDAAoC;AAEpC,iDAA6C;AAC7C,4CAA+B;AAC/B,4CAA8C;AAC9C,gFAAmE;AACnE,kEAAqD;AACrD,yFAAkF;AAClF,4CAA6D;A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ErB;MAAA,EAAE,mBAAI,CACN;MAAA,CAAC,mBAAI,CACH,KAAK,CAAC,CAAC,EAAE,CAAA,gDACP,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,aAC5B,EAAE,CAAC,CACH,MAAM,CAAC,mBAAmB,CAE1B;QAAA,CAAC,kBAAkB,CAAC,CAAC,CAAC,CACpB,CAAC,WAAI,CACH,IAAI,CAAC,CAAC,kBAAkB,CAAC,CACzB,IAAI,CAAC,CAAC,eAAQ,CAAC,EAAE,CAAC,CAClB,WAAW,CAAC,UAAU,CACtB,IAAI,cAAc,CAAC,EACnB,CACH,CAAC,CAAC,CAAC,CACF,cAAc,CACf,CACD;QAAA,CAAC,+BAAc,CACb,SAAS,CAAC,CAAC;YACT,OAAO,EAAE,kBAAW,CAAC,MAAM;YAC3B,UAAU,EAAE,iBAAU,CAAC,MAAM;YAC7B,KAAK,EAAE,gBAAS,CAAC,WAAW;YAC5B,WAAW,EAAE,qCAAqC;YAClD,GAAG,SAAS;SACb,CAAC,CAEF;UAAA,CAAC,QAAQ,CACX;QAAA,EAAE,+BAAc,CAChB;QAAA,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAClB,CAAC,WAAI,CACH,IAAI,CAAC,CAAC,gBAAgB,CAAC,CACvB,IAAI,CAAC,CAAC,eAAQ,CAAC,EAAE,CAAC,CAClB,WAAW,CAAC,UAAU,CACtB,IAAI,YAAY,CAAC,EACjB,CACH,CAAC,CAAC,CAAC,CACF,YAAY,CACb,CACH;MAAA,EAAE,mBAAI,CACR;IAAA,EAAE,+BAAc,CAAC,CAClB,CAAC;AACJ,CAAC,CAAC;AA5FW,QAAA,UAAU,cA4FrB","sourcesContent":["import { useTailwind } from '@metamask-previews/design-system-twrnc-preset';\nimport React from 'react';\nimport { View } from 'react-native';\n\nimport { ButtonBaseSize } from '../../types';\nimport { Icon } from '../Icon';\nimport { IconColor, IconSize } from '../Icon';\nimport { ButtonAnimated } from '../temp-components/ButtonAnimated';\nimport { Spinner } from '../temp-components/Spinner';\nimport { TextOrChildren } from '../temp-components/TextOrChildren/TextOrChildren';\nimport { TextVariant, FontWeight, TextColor } from '../Text';\n\nimport type { ButtonBaseProps } from './ButtonBase.types';\n\nexport const ButtonBase = ({\n children,\n textProps,\n size = ButtonBaseSize.Lg,\n isLoading,\n loadingText,\n spinnerProps,\n startIconName,\n startIconProps,\n startAccessory,\n endIconName,\n endIconProps,\n endAccessory,\n isDisabled,\n isFullWidth,\n twClassName = '',\n style,\n ...props\n}: ButtonBaseProps) => {\n const tw = useTailwind();\n const twContainerClassNames = `\n flex-row items-center justify-center rounded-full bg-muted px-4 min-w-[80px] overflow-hidden\n h-[${size}px]\n ${isDisabled ? 'opacity-50' : 'opacity-100'}\n ${isFullWidth ? 'self-stretch' : 'self-start'}\n ${twClassName}\n `;\n\n const finalStartIconName = startIconName ?? startIconProps?.name;\n const finalEndIconName = endIconName ?? endIconProps?.name;\n\n return (\n <ButtonAnimated\n disabled={isDisabled || isLoading}\n accessibilityRole=\"button\"\n accessible\n style={[tw`${twContainerClassNames}`, style]}\n {...props}\n >\n <View\n style={tw`absolute inset-0 flex items-center justify-center ${\n isLoading ? 'opacity-100' : 'opacity-0'\n }`}\n testID=\"spinner-container\"\n >\n <Spinner\n color={IconColor.IconDefault}\n loadingText={loadingText}\n loadingTextProps={{ numberOfLines: 1 }}\n {...spinnerProps}\n />\n </View>\n <View\n style={tw`flex-row items-center justify-center gap-x-2 ${\n isLoading ? 'opacity-0' : 'opacity-100'\n }`}\n testID=\"content-container\"\n >\n {finalStartIconName ? (\n <Icon\n name={finalStartIconName}\n size={IconSize.Sm}\n twClassName=\"shrink-0\"\n {...startIconProps}\n />\n ) : (\n startAccessory\n )}\n <TextOrChildren\n textProps={{\n variant: TextVariant.BodyMd,\n fontWeight: FontWeight.Medium,\n color: TextColor.TextDefault,\n twClassName: 'shrink grow-0 flex-wrap text-center',\n ...textProps,\n }}\n >\n {children}\n </TextOrChildren>\n {finalEndIconName ? (\n <Icon\n name={finalEndIconName}\n size={IconSize.Sm}\n twClassName=\"shrink-0\"\n {...endIconProps}\n />\n ) : (\n endAccessory\n )}\n </View>\n </ButtonAnimated>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"ButtonBase.cjs","sourceRoot":"","sources":["../../../src/components/ButtonBase/ButtonBase.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8FAA4E;AAC5E,+CAAuC;AACvC,wDAAoC;AAGpC,iDAA6C;AAC7C,4CAA+B;AAC/B,4CAA8C;AAC9C,gFAAmE;AACnE,kEAAqD;AACrD,yFAAkF;AAClF,4CAA6D;AAE7D,qEAA8E;AAGvE,MAAM,UAAU,GAAG,CAAC,EACzB,QAAQ,EACR,SAAS,EACT,IAAI,GAAG,sBAAc,CAAC,EAAE,EACxB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,aAAa,EACb,cAAc,EACd,cAAc,EACd,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,WAAW,EACX,WAAW,GAAG,EAAE,EAChB,aAAa,EACb,aAAa,EACb,KAAK,EACL,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,GAAG,QAAQ,EAC5B,oBAAoB,EACpB,qBAAqB,EACrB,GAAG,KAAK,EACQ,EAAE,EAAE;IACpB,MAAM,EAAE,GAAG,IAAA,wCAAW,GAAE,CAAC;IAEzB,MAAM,kBAAkB,GAAG,aAAa,IAAI,cAAc,EAAE,IAAI,CAAC;IACjE,MAAM,gBAAgB,GAAG,WAAW,IAAI,YAAY,EAAE,IAAI,CAAC;IAE3D,+CAA+C;IAC/C,MAAM,uBAAuB,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QAC3C,IAAI,kBAAkB,EAAE;YACtB,OAAO,kBAAkB,CAAC;SAC3B;QAED,6DAA6D;QAC7D,IAAI,SAAS,IAAI,WAAW,EAAE;YAC5B,OAAO,WAAW,CAAC;SACpB;QAED,+CAA+C;QAC/C,IAA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E,CAAC,CACvE,IAAI,YAAY,CAAC,EACjB,CACH,CAAC,CAAC,CAAC,CACF,YAAY,CACb,CACH;UAAA,EAAE,mBAAI,CACR;QAAA,GAAG,CACJ,CACH;IAAA,EAAE,+BAAc,CAAC,CAClB,CAAC;AACJ,CAAC,CAAC;AAvLW,QAAA,UAAU,cAuLrB","sourcesContent":["import { useTailwind } from '@metamask-previews/design-system-twrnc-preset';\nimport React, { useMemo } from 'react';\nimport { View } from 'react-native';\nimport type { StyleProp, ViewStyle } from 'react-native';\n\nimport { ButtonBaseSize } from '../../types';\nimport { Icon } from '../Icon';\nimport { IconColor, IconSize } from '../Icon';\nimport { ButtonAnimated } from '../temp-components/ButtonAnimated';\nimport { Spinner } from '../temp-components/Spinner';\nimport { TextOrChildren } from '../temp-components/TextOrChildren/TextOrChildren';\nimport { TextVariant, FontWeight, TextColor } from '../Text';\n\nimport { TWCLASSMAP_BUTTONBASE_SIZE_DIMENSION } from './ButtonBase.constants';\nimport type { ButtonBaseProps } from './ButtonBase.types';\n\nexport const ButtonBase = ({\n children,\n textProps,\n size = ButtonBaseSize.Lg,\n isLoading,\n loadingText,\n spinnerProps,\n startIconName,\n startIconProps,\n startAccessory,\n endIconName,\n endIconProps,\n endAccessory,\n isDisabled,\n isFullWidth,\n twClassName = '',\n textClassName,\n iconClassName,\n style,\n accessibilityLabel,\n accessibilityHint,\n accessibilityRole = 'button',\n accessibilityActions,\n onAccessibilityAction,\n ...props\n}: ButtonBaseProps) => {\n const tw = useTailwind();\n\n const finalStartIconName = startIconName ?? startIconProps?.name;\n const finalEndIconName = endIconName ?? endIconProps?.name;\n\n // Generate accessibility label if not provided\n const finalAccessibilityLabel = useMemo(() => {\n if (accessibilityLabel) {\n return accessibilityLabel;\n }\n\n // For loading state with loadingText, prioritize loadingText\n if (isLoading && loadingText) {\n return loadingText;\n }\n\n // If children is a string, use it as the label\n if (typeof children === 'string') {\n return children;\n }\n\n return undefined;\n }, [accessibilityLabel, children, isLoading, loadingText]);\n\n // Generate accessibility hint for loading state if not provided\n const finalAccessibilityHint = useMemo(() => {\n if (accessibilityHint) {\n return accessibilityHint;\n }\n\n if (isLoading) {\n return 'Button is currently loading, please wait';\n }\n\n return undefined;\n }, [accessibilityHint, isLoading]);\n\n // Create accessibilityState object with only truthy values\n const accessibilityState = useMemo(() => {\n const state: { disabled?: boolean; busy?: boolean } = {};\n\n if (isDisabled || isLoading) {\n state.disabled = true;\n }\n\n if (isLoading) {\n state.busy = true;\n }\n\n return state;\n }, [isDisabled, isLoading]);\n\n return (\n <ButtonAnimated\n disabled={isDisabled || isLoading}\n accessibilityRole={accessibilityRole}\n accessibilityLabel={finalAccessibilityLabel}\n accessibilityHint={finalAccessibilityHint}\n accessibilityActions={accessibilityActions}\n onAccessibilityAction={onAccessibilityAction}\n accessibilityState={accessibilityState}\n accessible\n style={({ pressed }) => {\n const containerClassName =\n typeof twClassName === 'function'\n ? twClassName(pressed)\n : twClassName;\n\n const baseContainerClassNames = `\n flex-row items-center justify-center rounded-xl bg-muted px-4 min-w-[80px] overflow-hidden\n ${TWCLASSMAP_BUTTONBASE_SIZE_DIMENSION[size]}\n ${isDisabled ? 'opacity-50' : 'opacity-100'}\n ${isFullWidth ? 'w-full' : 'w-auto'}\n ${containerClassName}\n `;\n\n const computedStyle: StyleProp<ViewStyle>[] = [\n tw`${baseContainerClassNames}`,\n ];\n if (typeof style === 'function') {\n const additionalStyle = style({ pressed });\n if (additionalStyle) {\n computedStyle.push(additionalStyle);\n }\n } else if (style) {\n computedStyle.push(style);\n }\n\n return computedStyle;\n }}\n {...props}\n >\n {({ pressed }) => (\n <>\n <View\n style={tw`absolute inset-0 flex items-center justify-center ${\n isLoading ? 'opacity-100' : 'opacity-0'\n }`}\n testID=\"spinner-container\"\n >\n <Spinner\n color={\n textClassName\n ? (textClassName(pressed) as IconColor)\n : IconColor.IconDefault\n }\n loadingText={loadingText}\n loadingTextProps={{\n numberOfLines: 1,\n twClassName: textClassName ? textClassName(pressed) : '',\n ...spinnerProps?.loadingTextProps,\n }}\n {...spinnerProps}\n />\n </View>\n <View\n style={tw`flex-row items-center justify-center gap-x-2 ${\n isLoading ? 'opacity-0' : 'opacity-100'\n }`}\n testID=\"content-container\"\n >\n {finalStartIconName ? (\n <Icon\n name={finalStartIconName}\n size={IconSize.Sm}\n twClassName={`shrink-0 ${iconClassName ? iconClassName(pressed) : ''}`}\n {...startIconProps}\n />\n ) : (\n startAccessory\n )}\n <TextOrChildren\n textProps={{\n variant: TextVariant.BodyMd,\n fontWeight: FontWeight.Medium,\n color: TextColor.TextDefault,\n twClassName: `shrink grow-0 flex-wrap text-center ${textClassName ? textClassName(pressed) : ''}`,\n ...textProps,\n }}\n >\n {children}\n </TextOrChildren>\n {finalEndIconName ? (\n <Icon\n name={finalEndIconName}\n size={IconSize.Sm}\n twClassName={`shrink-0 ${iconClassName ? iconClassName(pressed) : ''}`}\n {...endIconProps}\n />\n ) : (\n endAccessory\n )}\n </View>\n </>\n )}\n </ButtonAnimated>\n );\n};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TWCLASSMAP_BUTTONBASE_SIZE_DIMENSION = void 0;
|
|
4
|
+
const types_1 = require("../../types/index.cjs");
|
|
5
|
+
exports.TWCLASSMAP_BUTTONBASE_SIZE_DIMENSION = {
|
|
6
|
+
[types_1.ButtonBaseSize.Sm]: 'h-8',
|
|
7
|
+
[types_1.ButtonBaseSize.Md]: 'h-10',
|
|
8
|
+
[types_1.ButtonBaseSize.Lg]: 'h-12', // size (48px).
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=ButtonBase.constants.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ButtonBase.constants.cjs","sourceRoot":"","sources":["../../../src/components/ButtonBase/ButtonBase.constants.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAEhC,QAAA,oCAAoC,GAG7C;IACF,CAAC,sBAAc,CAAC,EAAE,CAAC,EAAE,KAAK;IAC1B,CAAC,sBAAc,CAAC,EAAE,CAAC,EAAE,MAAM;IAC3B,CAAC,sBAAc,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,eAAe;CAC7C,CAAC","sourcesContent":["import { ButtonBaseSize } from '../../types';\n\nexport const TWCLASSMAP_BUTTONBASE_SIZE_DIMENSION: Record<\n ButtonBaseSize,\n string\n> = {\n [ButtonBaseSize.Sm]: 'h-8', // size (32px).\n [ButtonBaseSize.Md]: 'h-10', // size (40px).\n [ButtonBaseSize.Lg]: 'h-12', // size (48px).\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ButtonBase.constants.d.cts","sourceRoot":"","sources":["../../../src/components/ButtonBase/ButtonBase.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,8BAAoB;AAE7C,eAAO,MAAM,oCAAoC,EAAE,MAAM,CACvD,cAAc,EACd,MAAM,CAKP,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ButtonBase.constants.d.mts","sourceRoot":"","sources":["../../../src/components/ButtonBase/ButtonBase.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,8BAAoB;AAE7C,eAAO,MAAM,oCAAoC,EAAE,MAAM,CACvD,cAAc,EACd,MAAM,CAKP,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ButtonBaseSize } from "../../types/index.mjs";
|
|
2
|
+
export const TWCLASSMAP_BUTTONBASE_SIZE_DIMENSION = {
|
|
3
|
+
[ButtonBaseSize.Sm]: 'h-8',
|
|
4
|
+
[ButtonBaseSize.Md]: 'h-10',
|
|
5
|
+
[ButtonBaseSize.Lg]: 'h-12', // size (48px).
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=ButtonBase.constants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ButtonBase.constants.mjs","sourceRoot":"","sources":["../../../src/components/ButtonBase/ButtonBase.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,8BAAoB;AAE7C,MAAM,CAAC,MAAM,oCAAoC,GAG7C;IACF,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,KAAK;IAC1B,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,MAAM;IAC3B,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,eAAe;CAC7C,CAAC","sourcesContent":["import { ButtonBaseSize } from '../../types';\n\nexport const TWCLASSMAP_BUTTONBASE_SIZE_DIMENSION: Record<\n ButtonBaseSize,\n string\n> = {\n [ButtonBaseSize.Sm]: 'h-8', // size (32px).\n [ButtonBaseSize.Md]: 'h-10', // size (40px).\n [ButtonBaseSize.Lg]: 'h-12', // size (48px).\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { ButtonBaseProps } from "./ButtonBase.types.cjs";
|
|
3
|
-
export declare const ButtonBase: ({ children, textProps, size, isLoading, loadingText, spinnerProps, startIconName, startIconProps, startAccessory, endIconName, endIconProps, endAccessory, isDisabled, isFullWidth, twClassName, style, ...props }: ButtonBaseProps) => React.JSX.Element;
|
|
3
|
+
export declare const ButtonBase: ({ children, textProps, size, isLoading, loadingText, spinnerProps, startIconName, startIconProps, startAccessory, endIconName, endIconProps, endAccessory, isDisabled, isFullWidth, twClassName, textClassName, iconClassName, style, accessibilityLabel, accessibilityHint, accessibilityRole, accessibilityActions, onAccessibilityAction, ...props }: ButtonBaseProps) => React.JSX.Element;
|
|
4
4
|
//# sourceMappingURL=ButtonBase.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ButtonBase.d.cts","sourceRoot":"","sources":["../../../src/components/ButtonBase/ButtonBase.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"ButtonBase.d.cts","sourceRoot":"","sources":["../../../src/components/ButtonBase/ButtonBase.tsx"],"names":[],"mappings":"AACA,OAAO,KAAkB,cAAc;AAavC,OAAO,KAAK,EAAE,eAAe,EAAE,+BAA2B;AAE1D,eAAO,MAAM,UAAU,4VAyBpB,eAAe,sBA8JjB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { ButtonBaseProps } from "./ButtonBase.types.mjs";
|
|
3
|
-
export declare const ButtonBase: ({ children, textProps, size, isLoading, loadingText, spinnerProps, startIconName, startIconProps, startAccessory, endIconName, endIconProps, endAccessory, isDisabled, isFullWidth, twClassName, style, ...props }: ButtonBaseProps) => React.JSX.Element;
|
|
3
|
+
export declare const ButtonBase: ({ children, textProps, size, isLoading, loadingText, spinnerProps, startIconName, startIconProps, startAccessory, endIconName, endIconProps, endAccessory, isDisabled, isFullWidth, twClassName, textClassName, iconClassName, style, accessibilityLabel, accessibilityHint, accessibilityRole, accessibilityActions, onAccessibilityAction, ...props }: ButtonBaseProps) => React.JSX.Element;
|
|
4
4
|
//# sourceMappingURL=ButtonBase.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ButtonBase.d.mts","sourceRoot":"","sources":["../../../src/components/ButtonBase/ButtonBase.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"ButtonBase.d.mts","sourceRoot":"","sources":["../../../src/components/ButtonBase/ButtonBase.tsx"],"names":[],"mappings":"AACA,OAAO,KAAkB,cAAc;AAavC,OAAO,KAAK,EAAE,eAAe,EAAE,+BAA2B;AAE1D,eAAO,MAAM,UAAU,4VAyBpB,eAAe,sBA8JjB,CAAC"}
|
|
@@ -5,7 +5,7 @@ function $importDefault(module) {
|
|
|
5
5
|
return module;
|
|
6
6
|
}
|
|
7
7
|
import { useTailwind } from "@metamask-previews/design-system-twrnc-preset";
|
|
8
|
-
import $React from "react";
|
|
8
|
+
import $React, { useMemo } from "react";
|
|
9
9
|
const React = $importDefault($React);
|
|
10
10
|
import { View } from "react-native/index.js";
|
|
11
11
|
import { ButtonBaseSize } from "../../types/index.mjs";
|
|
@@ -15,34 +15,96 @@ import { ButtonAnimated } from "../temp-components/ButtonAnimated/index.mjs";
|
|
|
15
15
|
import { Spinner } from "../temp-components/Spinner/index.mjs";
|
|
16
16
|
import { TextOrChildren } from "../temp-components/TextOrChildren/TextOrChildren.mjs";
|
|
17
17
|
import { TextVariant, FontWeight, TextColor } from "../Text/index.mjs";
|
|
18
|
-
|
|
18
|
+
import { TWCLASSMAP_BUTTONBASE_SIZE_DIMENSION } from "./ButtonBase.constants.mjs";
|
|
19
|
+
export const ButtonBase = ({ children, textProps, size = ButtonBaseSize.Lg, isLoading, loadingText, spinnerProps, startIconName, startIconProps, startAccessory, endIconName, endIconProps, endAccessory, isDisabled, isFullWidth, twClassName = '', textClassName, iconClassName, style, accessibilityLabel, accessibilityHint, accessibilityRole = 'button', accessibilityActions, onAccessibilityAction, ...props }) => {
|
|
19
20
|
const tw = useTailwind();
|
|
20
|
-
const twContainerClassNames = `
|
|
21
|
-
flex-row items-center justify-center rounded-full bg-muted px-4 min-w-[80px] overflow-hidden
|
|
22
|
-
h-[${size}px]
|
|
23
|
-
${isDisabled ? 'opacity-50' : 'opacity-100'}
|
|
24
|
-
${isFullWidth ? 'self-stretch' : 'self-start'}
|
|
25
|
-
${twClassName}
|
|
26
|
-
`;
|
|
27
21
|
const finalStartIconName = startIconName ?? startIconProps?.name;
|
|
28
22
|
const finalEndIconName = endIconName ?? endIconProps?.name;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
23
|
+
// Generate accessibility label if not provided
|
|
24
|
+
const finalAccessibilityLabel = useMemo(() => {
|
|
25
|
+
if (accessibilityLabel) {
|
|
26
|
+
return accessibilityLabel;
|
|
27
|
+
}
|
|
28
|
+
// For loading state with loadingText, prioritize loadingText
|
|
29
|
+
if (isLoading && loadingText) {
|
|
30
|
+
return loadingText;
|
|
31
|
+
}
|
|
32
|
+
// If children is a string, use it as the label
|
|
33
|
+
if (typeof children === 'string') {
|
|
34
|
+
return children;
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}, [accessibilityLabel, children, isLoading, loadingText]);
|
|
38
|
+
// Generate accessibility hint for loading state if not provided
|
|
39
|
+
const finalAccessibilityHint = useMemo(() => {
|
|
40
|
+
if (accessibilityHint) {
|
|
41
|
+
return accessibilityHint;
|
|
42
|
+
}
|
|
43
|
+
if (isLoading) {
|
|
44
|
+
return 'Button is currently loading, please wait';
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}, [accessibilityHint, isLoading]);
|
|
48
|
+
// Create accessibilityState object with only truthy values
|
|
49
|
+
const accessibilityState = useMemo(() => {
|
|
50
|
+
const state = {};
|
|
51
|
+
if (isDisabled || isLoading) {
|
|
52
|
+
state.disabled = true;
|
|
53
|
+
}
|
|
54
|
+
if (isLoading) {
|
|
55
|
+
state.busy = true;
|
|
56
|
+
}
|
|
57
|
+
return state;
|
|
58
|
+
}, [isDisabled, isLoading]);
|
|
59
|
+
return (<ButtonAnimated disabled={isDisabled || isLoading} accessibilityRole={accessibilityRole} accessibilityLabel={finalAccessibilityLabel} accessibilityHint={finalAccessibilityHint} accessibilityActions={accessibilityActions} onAccessibilityAction={onAccessibilityAction} accessibilityState={accessibilityState} accessible style={({ pressed }) => {
|
|
60
|
+
const containerClassName = typeof twClassName === 'function'
|
|
61
|
+
? twClassName(pressed)
|
|
62
|
+
: twClassName;
|
|
63
|
+
const baseContainerClassNames = `
|
|
64
|
+
flex-row items-center justify-center rounded-xl bg-muted px-4 min-w-[80px] overflow-hidden
|
|
65
|
+
${TWCLASSMAP_BUTTONBASE_SIZE_DIMENSION[size]}
|
|
66
|
+
${isDisabled ? 'opacity-50' : 'opacity-100'}
|
|
67
|
+
${isFullWidth ? 'w-full' : 'w-auto'}
|
|
68
|
+
${containerClassName}
|
|
69
|
+
`;
|
|
70
|
+
const computedStyle = [
|
|
71
|
+
tw `${baseContainerClassNames}`,
|
|
72
|
+
];
|
|
73
|
+
if (typeof style === 'function') {
|
|
74
|
+
const additionalStyle = style({ pressed });
|
|
75
|
+
if (additionalStyle) {
|
|
76
|
+
computedStyle.push(additionalStyle);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (style) {
|
|
80
|
+
computedStyle.push(style);
|
|
81
|
+
}
|
|
82
|
+
return computedStyle;
|
|
83
|
+
}} {...props}>
|
|
84
|
+
{({ pressed }) => (<>
|
|
85
|
+
<View style={tw `absolute inset-0 flex items-center justify-center ${isLoading ? 'opacity-100' : 'opacity-0'}`} testID="spinner-container">
|
|
86
|
+
<Spinner color={textClassName
|
|
87
|
+
? textClassName(pressed)
|
|
88
|
+
: IconColor.IconDefault} loadingText={loadingText} loadingTextProps={{
|
|
89
|
+
numberOfLines: 1,
|
|
90
|
+
twClassName: textClassName ? textClassName(pressed) : '',
|
|
91
|
+
...spinnerProps?.loadingTextProps,
|
|
92
|
+
}} {...spinnerProps}/>
|
|
93
|
+
</View>
|
|
94
|
+
<View style={tw `flex-row items-center justify-center gap-x-2 ${isLoading ? 'opacity-0' : 'opacity-100'}`} testID="content-container">
|
|
95
|
+
{finalStartIconName ? (<Icon name={finalStartIconName} size={IconSize.Sm} twClassName={`shrink-0 ${iconClassName ? iconClassName(pressed) : ''}`} {...startIconProps}/>) : (startAccessory)}
|
|
96
|
+
<TextOrChildren textProps={{
|
|
97
|
+
variant: TextVariant.BodyMd,
|
|
98
|
+
fontWeight: FontWeight.Medium,
|
|
99
|
+
color: TextColor.TextDefault,
|
|
100
|
+
twClassName: `shrink grow-0 flex-wrap text-center ${textClassName ? textClassName(pressed) : ''}`,
|
|
101
|
+
...textProps,
|
|
102
|
+
}}>
|
|
103
|
+
{children}
|
|
104
|
+
</TextOrChildren>
|
|
105
|
+
{finalEndIconName ? (<Icon name={finalEndIconName} size={IconSize.Sm} twClassName={`shrink-0 ${iconClassName ? iconClassName(pressed) : ''}`} {...endIconProps}/>) : (endAccessory)}
|
|
106
|
+
</View>
|
|
107
|
+
</>)}
|
|
46
108
|
</ButtonAnimated>);
|
|
47
109
|
};
|
|
48
110
|
//# sourceMappingURL=ButtonBase.mjs.map
|