@metamask/design-system-react-native 0.40.0 → 0.41.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/CHANGELOG.md +16 -1
- package/dist/components/BannerBase/BannerBase.cjs +88 -11
- package/dist/components/BannerBase/BannerBase.cjs.map +1 -1
- package/dist/components/BannerBase/BannerBase.d.cts.map +1 -1
- package/dist/components/BannerBase/BannerBase.d.mts.map +1 -1
- package/dist/components/BannerBase/BannerBase.mjs +66 -9
- package/dist/components/BannerBase/BannerBase.mjs.map +1 -1
- package/dist/components/Checkbox/Checkbox.cjs +2 -4
- package/dist/components/Checkbox/Checkbox.cjs.map +1 -1
- package/dist/components/Checkbox/Checkbox.d.cts.map +1 -1
- package/dist/components/Checkbox/Checkbox.d.mts.map +1 -1
- package/dist/components/Checkbox/Checkbox.mjs +2 -4
- package/dist/components/Checkbox/Checkbox.mjs.map +1 -1
- package/dist/components/Toast/Toast.types.cjs.map +1 -1
- package/dist/components/Toast/Toast.types.d.cts +6 -0
- package/dist/components/Toast/Toast.types.d.cts.map +1 -1
- package/dist/components/Toast/Toast.types.d.mts +6 -0
- package/dist/components/Toast/Toast.types.d.mts.map +1 -1
- package/dist/components/Toast/Toast.types.mjs.map +1 -1
- package/dist/components/Toast/Toaster.cjs +9 -9
- package/dist/components/Toast/Toaster.cjs.map +1 -1
- package/dist/components/Toast/Toaster.d.cts.map +1 -1
- package/dist/components/Toast/Toaster.d.mts.map +1 -1
- package/dist/components/Toast/Toaster.mjs +9 -9
- package/dist/components/Toast/Toaster.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.41.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Added `showCloseButton` to `ToastOptions` for the imperative `toast(...)` API (default `true`); when `false`, the close button is hidden while swipe-to-dismiss, auto-dismiss, and `toast.dismiss()` still work ([#1446](https://github.com/MetaMask/metamask-design-system/pull/1446))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Updated `BannerBase` to center-align compact content (title-only, description-only, or title with a single-line description or string children) and top-align multi-line stacks, custom React node children, or below-action layouts; inherited by `BannerAlert` and `Toast` ([#1447](https://github.com/MetaMask/metamask-design-system/pull/1447))
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- Fixed `Checkbox` unselected state to use a transparent background instead of `background.default` ([#1451](https://github.com/MetaMask/metamask-design-system/pull/1451))
|
|
23
|
+
|
|
10
24
|
## [0.40.0]
|
|
11
25
|
|
|
12
26
|
### Added
|
|
@@ -683,7 +697,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
683
697
|
- Full TypeScript support with type definitions and enums
|
|
684
698
|
- React Native integration with TWRNC preset support
|
|
685
699
|
|
|
686
|
-
[Unreleased]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.
|
|
700
|
+
[Unreleased]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.41.0...HEAD
|
|
701
|
+
[0.41.0]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.40.0...@metamask/design-system-react-native@0.41.0
|
|
687
702
|
[0.40.0]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.39.1...@metamask/design-system-react-native@0.40.0
|
|
688
703
|
[0.39.1]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.39.0...@metamask/design-system-react-native@0.39.1
|
|
689
704
|
[0.39.0]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react-native@0.38.1...@metamask/design-system-react-native@0.39.0
|
|
@@ -1,43 +1,118 @@
|
|
|
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.BannerBase = void 0;
|
|
7
27
|
const design_system_shared_1 = require("@metamask/design-system-shared");
|
|
8
|
-
const
|
|
28
|
+
const design_tokens_1 = require("@metamask/design-tokens");
|
|
29
|
+
const react_1 = __importStar(require("react"));
|
|
9
30
|
const Box_1 = require("../Box/index.cjs");
|
|
10
31
|
const Button_1 = require("../Button/index.cjs");
|
|
11
32
|
const ButtonIcon_1 = require("../ButtonIcon/index.cjs");
|
|
12
33
|
const Text_1 = require("../Text/index.cjs");
|
|
34
|
+
/** BodyMd line height — title block. */
|
|
35
|
+
const BODY_MD_LINE_HEIGHT = design_tokens_1.typography.sBodyMD.lineHeight;
|
|
36
|
+
/** BodySm line height — description block. */
|
|
37
|
+
const BODY_SM_LINE_HEIGHT = design_tokens_1.typography.sBodySM.lineHeight;
|
|
38
|
+
/** `mt-0.5` between title and description. */
|
|
39
|
+
const TITLE_DESCRIPTION_GAP = 2;
|
|
40
|
+
/** Sub-pixel / font rounding allowance when comparing stack height. */
|
|
41
|
+
const COMPACT_HEIGHT_TOLERANCE = 4;
|
|
13
42
|
const isTextContent = (content) => typeof content === 'string' || typeof content === 'number';
|
|
14
43
|
const hasContent = (content) => content !== null && content !== undefined;
|
|
15
|
-
const
|
|
44
|
+
const getCompactContentMaxHeight = ({ hasTitle, hasDescription, hasChildren, }) => {
|
|
45
|
+
let maxHeight = 0;
|
|
46
|
+
if (hasTitle) {
|
|
47
|
+
maxHeight += BODY_MD_LINE_HEIGHT;
|
|
48
|
+
}
|
|
49
|
+
if (hasDescription) {
|
|
50
|
+
if (hasTitle) {
|
|
51
|
+
maxHeight += TITLE_DESCRIPTION_GAP;
|
|
52
|
+
}
|
|
53
|
+
maxHeight += BODY_SM_LINE_HEIGHT;
|
|
54
|
+
}
|
|
55
|
+
if (hasChildren) {
|
|
56
|
+
maxHeight += BODY_MD_LINE_HEIGHT;
|
|
57
|
+
}
|
|
58
|
+
return maxHeight + COMPACT_HEIGHT_TOLERANCE;
|
|
59
|
+
};
|
|
60
|
+
const BannerBase = ({ title, titleProps, description, descriptionProps, children, childrenWrapperProps, actionButtonLabel, actionButtonOnPress, actionButtonProps, actionButtonLayout = design_system_shared_1.BannerBaseActionButtonLayout.Below, startAccessory, onClose, closeButtonProps, twClassName, backgroundColor = design_system_shared_1.BoxBackgroundColor.BackgroundDefault, ...props }) => {
|
|
16
61
|
const resolvedActionButtonProps = actionButtonProps ?? {};
|
|
17
62
|
const { accessibilityLabel: closeButtonAccessibilityLabel = 'Close banner', twClassName: closeButtonTwClassName, ...resolvedCloseButtonProps } = closeButtonProps ?? {};
|
|
18
63
|
const shouldShowCloseButton = Boolean(onClose);
|
|
19
64
|
const shouldShowActionButton = Boolean(actionButtonOnPress);
|
|
20
65
|
const isActionButtonLayoutEnd = actionButtonLayout === design_system_shared_1.BannerBaseActionButtonLayout.End;
|
|
21
66
|
const hasActionButtonBelow = shouldShowActionButton && !isActionButtonLayoutEnd;
|
|
67
|
+
const hasTitle = hasContent(title);
|
|
68
|
+
const hasDescription = hasContent(description);
|
|
69
|
+
const hasChildren = hasContent(children);
|
|
70
|
+
// Custom nodes can't be measured reliably — keep top-aligned.
|
|
71
|
+
const hasUnmeasuredContent = (hasTitle && !isTextContent(title)) ||
|
|
72
|
+
(hasDescription && !isTextContent(description)) ||
|
|
73
|
+
(hasChildren && !isTextContent(children));
|
|
74
|
+
// Multiple text blocks: default top-aligned until the stack measures as
|
|
75
|
+
// single-line per block. A single title, description, or children block
|
|
76
|
+
// always centers (including wraps). Avoids multiline stacks sticking
|
|
77
|
+
// centered when layout callbacks are delayed or skipped.
|
|
78
|
+
const [isCompactContent, setIsCompactContent] = (0, react_1.useState)(false);
|
|
79
|
+
const isSingleTextBlock = [hasTitle, hasDescription, hasChildren].filter(Boolean).length === 1;
|
|
80
|
+
const isCenterAligned = !hasActionButtonBelow &&
|
|
81
|
+
!hasUnmeasuredContent &&
|
|
82
|
+
(hasTitle || hasDescription || hasChildren) &&
|
|
83
|
+
(isSingleTextBlock || isCompactContent);
|
|
84
|
+
const handleContentLayout = (event) => {
|
|
85
|
+
if (hasUnmeasuredContent || hasActionButtonBelow || isSingleTextBlock) {
|
|
86
|
+
setIsCompactContent(false);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const { height } = event.nativeEvent.layout;
|
|
90
|
+
const maxCompactHeight = getCompactContentMaxHeight({
|
|
91
|
+
hasTitle,
|
|
92
|
+
hasDescription,
|
|
93
|
+
hasChildren,
|
|
94
|
+
});
|
|
95
|
+
setIsCompactContent(height > 0 && height <= maxCompactHeight);
|
|
96
|
+
};
|
|
22
97
|
const actionButton = shouldShowActionButton ? (<Button_1.Button size={design_system_shared_1.ButtonSize.Md} onPress={actionButtonOnPress} {...resolvedActionButtonProps} variant={design_system_shared_1.ButtonVariant.Secondary}>
|
|
23
98
|
{actionButtonLabel}
|
|
24
99
|
</Button_1.Button>) : null;
|
|
25
|
-
return (<Box_1.Box flexDirection={design_system_shared_1.BoxFlexDirection.Row} alignItems={design_system_shared_1.BoxAlignItems.Start} gap={4} backgroundColor={
|
|
100
|
+
return (<Box_1.Box {...props} flexDirection={design_system_shared_1.BoxFlexDirection.Row} alignItems={isCenterAligned ? design_system_shared_1.BoxAlignItems.Center : design_system_shared_1.BoxAlignItems.Start} gap={4} backgroundColor={backgroundColor} paddingTop={3} paddingBottom={hasActionButtonBelow ? 4 : 3} paddingLeft={4} paddingRight={shouldShowCloseButton ? 2 : 4} twClassName={(0, design_system_shared_1.mergeTwClassName)('rounded-xl', twClassName)}>
|
|
26
101
|
{startAccessory}
|
|
27
102
|
|
|
28
|
-
<Box_1.Box twClassName="flex-1">
|
|
29
|
-
{
|
|
103
|
+
<Box_1.Box twClassName="flex-1" onLayout={handleContentLayout}>
|
|
104
|
+
{hasTitle &&
|
|
30
105
|
(isTextContent(title) ? (<Text_1.Text variant={design_system_shared_1.TextVariant.BodyMd} fontWeight={design_system_shared_1.FontWeight.Medium} {...titleProps}>
|
|
31
106
|
{title}
|
|
32
107
|
</Text_1.Text>) : (title))}
|
|
33
108
|
|
|
34
|
-
{
|
|
109
|
+
{hasDescription && (<Box_1.Box twClassName={hasTitle ? 'mt-0.5' : undefined}>
|
|
35
110
|
{isTextContent(description) ? (<Text_1.Text variant={design_system_shared_1.TextVariant.BodySm} {...descriptionProps}>
|
|
36
111
|
{description}
|
|
37
112
|
</Text_1.Text>) : (description)}
|
|
38
113
|
</Box_1.Box>)}
|
|
39
114
|
|
|
40
|
-
{
|
|
115
|
+
{hasChildren &&
|
|
41
116
|
(isTextContent(children) ? (<Text_1.Text variant={design_system_shared_1.TextVariant.BodyMd} {...childrenWrapperProps}>
|
|
42
117
|
{children}
|
|
43
118
|
</Text_1.Text>) : (children))}
|
|
@@ -45,9 +120,11 @@ const BannerBase = ({ title, titleProps, description, descriptionProps, children
|
|
|
45
120
|
{hasActionButtonBelow && <Box_1.Box twClassName="mt-2">{actionButton}</Box_1.Box>}
|
|
46
121
|
</Box_1.Box>
|
|
47
122
|
|
|
48
|
-
{shouldShowActionButton && isActionButtonLayoutEnd && actionButton}
|
|
123
|
+
{shouldShowActionButton && isActionButtonLayoutEnd && (<Box_1.Box twClassName="self-center">{actionButton}</Box_1.Box>)}
|
|
49
124
|
|
|
50
|
-
{shouldShowCloseButton && (<ButtonIcon_1.ButtonIcon twClassName={
|
|
125
|
+
{shouldShowCloseButton && (<ButtonIcon_1.ButtonIcon twClassName={isCenterAligned
|
|
126
|
+
? closeButtonTwClassName
|
|
127
|
+
: (0, design_system_shared_1.mergeTwClassName)('-mt-1', closeButtonTwClassName)} iconName={design_system_shared_1.IconName.Close} size={design_system_shared_1.ButtonIconSize.Md} accessibilityLabel={closeButtonAccessibilityLabel} onPress={onClose} {...resolvedCloseButtonProps}/>)}
|
|
51
128
|
</Box_1.Box>);
|
|
52
129
|
};
|
|
53
130
|
exports.BannerBase = BannerBase;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BannerBase.cjs","sourceRoot":"","sources":["../../../src/components/BannerBase/BannerBase.tsx"],"names":[],"mappings":";;;;;;AAAA,yEAYwC;AACxC,kDAA0B;AAE1B,0CAA6B;AAC7B,gDAAmC;AACnC,wDAA2C;AAC3C,4CAA+B;AAI/B,MAAM,aAAa,GAAG,CAAC,OAAwB,EAA8B,EAAE,CAC7E,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC;AAE7D,MAAM,UAAU,GAAG,CAAC,OAAwB,EAAE,EAAE,CAC9C,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,CAAC;AAErC,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;QAAA,CAAC,UAAU,CAAC,QAAQ,CAAC;YACnB,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CACzB,CAAC,WAAI,CAAC,OAAO,CAAC,CAAC,kCAAW,CAAC,MAAM,CAAC,CAAC,IAAI,oBAAoB,CAAC,CAC1D;cAAA,CAAC,QAAQ,CACX;YAAA,EAAE,WAAI,CAAC,CACR,CAAC,CAAC,CAAC,CACF,QAAQ,CACT,CAAC,CAEJ;;QAAA,CAAC,oBAAoB,IAAI,CAAC,SAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,EAAE,SAAG,CAAC,CACvE;MAAA,EAAE,SAAG,CAEL;;MAAA,CAAC,sBAAsB,IAAI,uBAAuB,IAAI,YAAY,CAElE;;MAAA,CAAC,qBAAqB,IAAI,CACxB,CAAC,uBAAU,CACT,WAAW,CAAC,CAAC,IAAA,uCAAgB,EAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAC/D,QAAQ,CAAC,CAAC,+BAAQ,CAAC,KAAK,CAAC,CACzB,IAAI,CAAC,CAAC,qCAAc,CAAC,EAAE,CAAC,CACxB,kBAAkB,CAAC,CAAC,6BAA6B,CAAC,CAClD,OAAO,CAAC,CAAC,OAAO,CAAC,CACjB,IAAI,wBAAwB,CAAC,EAC7B,CACH,CACH;IAAA,EAAE,SAAG,CAAC,CACP,CAAC;AACJ,CAAC,CAAC;AA9GW,QAAA,UAAU,cA8GrB","sourcesContent":["import {\n BannerBaseActionButtonLayout,\n BoxAlignItems,\n BoxBackgroundColor,\n BoxFlexDirection,\n ButtonIconSize,\n ButtonSize,\n ButtonVariant,\n FontWeight,\n IconName,\n mergeTwClassName,\n TextVariant,\n} from '@metamask/design-system-shared';\nimport React from 'react';\n\nimport { Box } from '../Box';\nimport { Button } from '../Button';\nimport { ButtonIcon } from '../ButtonIcon';\nimport { Text } from '../Text';\n\nimport type { BannerBaseProps } from './BannerBase.types';\n\nconst isTextContent = (content: React.ReactNode): content is string | number =>\n typeof content === 'string' || typeof content === 'number';\n\nconst hasContent = (content: React.ReactNode) =>\n content !== null && content !== undefined;\n\nexport const BannerBase: React.FC<BannerBaseProps> = ({\n title,\n titleProps,\n description,\n descriptionProps,\n children,\n childrenWrapperProps,\n actionButtonLabel,\n actionButtonOnPress,\n actionButtonProps,\n actionButtonLayout = BannerBaseActionButtonLayout.Below,\n startAccessory,\n onClose,\n closeButtonProps,\n twClassName,\n ...props\n}) => {\n const resolvedActionButtonProps = actionButtonProps ?? {};\n\n const {\n accessibilityLabel: closeButtonAccessibilityLabel = 'Close banner',\n twClassName: closeButtonTwClassName,\n ...resolvedCloseButtonProps\n } = closeButtonProps ?? {};\n\n const shouldShowCloseButton = Boolean(onClose);\n const shouldShowActionButton = Boolean(actionButtonOnPress);\n const isActionButtonLayoutEnd =\n actionButtonLayout === BannerBaseActionButtonLayout.End;\n const hasActionButtonBelow =\n shouldShowActionButton && !isActionButtonLayoutEnd;\n\n const actionButton = shouldShowActionButton ? (\n <Button\n size={ButtonSize.Md}\n onPress={actionButtonOnPress}\n {...resolvedActionButtonProps}\n variant={ButtonVariant.Secondary}\n >\n {actionButtonLabel}\n </Button>\n ) : null;\n\n return (\n <Box\n flexDirection={BoxFlexDirection.Row}\n alignItems={BoxAlignItems.Start}\n gap={4}\n backgroundColor={BoxBackgroundColor.BackgroundDefault}\n paddingTop={3}\n paddingBottom={hasActionButtonBelow ? 4 : 3}\n paddingLeft={4}\n paddingRight={shouldShowCloseButton ? 2 : 4}\n twClassName={mergeTwClassName('rounded-xl', twClassName)}\n {...props}\n >\n {startAccessory}\n\n <Box twClassName=\"flex-1\">\n {hasContent(title) &&\n (isTextContent(title) ? (\n <Text\n variant={TextVariant.BodyMd}\n fontWeight={FontWeight.Medium}\n {...titleProps}\n >\n {title}\n </Text>\n ) : (\n title\n ))}\n\n {hasContent(description) && (\n <Box twClassName={hasContent(title) ? 'mt-0.5' : undefined}>\n {isTextContent(description) ? (\n <Text variant={TextVariant.BodySm} {...descriptionProps}>\n {description}\n </Text>\n ) : (\n description\n )}\n </Box>\n )}\n\n {hasContent(children) &&\n (isTextContent(children) ? (\n <Text variant={TextVariant.BodyMd} {...childrenWrapperProps}>\n {children}\n </Text>\n ) : (\n children\n ))}\n\n {hasActionButtonBelow && <Box twClassName=\"mt-2\">{actionButton}</Box>}\n </Box>\n\n {shouldShowActionButton && isActionButtonLayoutEnd && actionButton}\n\n {shouldShowCloseButton && (\n <ButtonIcon\n twClassName={mergeTwClassName('-mt-1', closeButtonTwClassName)}\n iconName={IconName.Close}\n size={ButtonIconSize.Md}\n accessibilityLabel={closeButtonAccessibilityLabel}\n onPress={onClose}\n {...resolvedCloseButtonProps}\n />\n )}\n </Box>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"BannerBase.cjs","sourceRoot":"","sources":["../../../src/components/BannerBase/BannerBase.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAYwC;AACxC,2DAAqD;AACrD,+CAAwC;AAGxC,0CAA6B;AAC7B,gDAAmC;AACnC,wDAA2C;AAC3C,4CAA+B;AAI/B,wCAAwC;AACxC,MAAM,mBAAmB,GAAG,0BAAU,CAAC,OAAO,CAAC,UAAU,CAAC;AAC1D,8CAA8C;AAC9C,MAAM,mBAAmB,GAAG,0BAAU,CAAC,OAAO,CAAC,UAAU,CAAC;AAC1D,8CAA8C;AAC9C,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,uEAAuE;AACvE,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAEnC,MAAM,aAAa,GAAG,CAAC,OAAwB,EAA8B,EAAE,CAC7E,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC;AAE7D,MAAM,UAAU,GAAG,CAAC,OAAwB,EAAE,EAAE,CAC9C,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,CAAC;AAE5C,MAAM,0BAA0B,GAAG,CAAC,EAClC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C,+BAAQ,CAAC,KAAK,CAAC,CACzB,IAAI,CAAC,CAAC,qCAAc,CAAC,EAAE,CAAC,CACxB,kBAAkB,CAAC,CAAC,6BAA6B,CAAC,CAClD,OAAO,CAAC,CAAC,OAAO,CAAC,CACjB,IAAI,wBAAwB,CAAC,EAC7B,CACH,CACH;IAAA,EAAE,SAAG,CAAC,CACP,CAAC;AACJ,CAAC,CAAC;AA1JW,QAAA,UAAU,cA0JrB","sourcesContent":["import {\n BannerBaseActionButtonLayout,\n BoxAlignItems,\n BoxBackgroundColor,\n BoxFlexDirection,\n ButtonIconSize,\n ButtonSize,\n ButtonVariant,\n FontWeight,\n IconName,\n mergeTwClassName,\n TextVariant,\n} from '@metamask/design-system-shared';\nimport { typography } from '@metamask/design-tokens';\nimport React, { useState } from 'react';\nimport type { LayoutChangeEvent } from 'react-native';\n\nimport { Box } from '../Box';\nimport { Button } from '../Button';\nimport { ButtonIcon } from '../ButtonIcon';\nimport { Text } from '../Text';\n\nimport type { BannerBaseProps } from './BannerBase.types';\n\n/** BodyMd line height — title block. */\nconst BODY_MD_LINE_HEIGHT = typography.sBodyMD.lineHeight;\n/** BodySm line height — description block. */\nconst BODY_SM_LINE_HEIGHT = typography.sBodySM.lineHeight;\n/** `mt-0.5` between title and description. */\nconst TITLE_DESCRIPTION_GAP = 2;\n/** Sub-pixel / font rounding allowance when comparing stack height. */\nconst COMPACT_HEIGHT_TOLERANCE = 4;\n\nconst isTextContent = (content: React.ReactNode): content is string | number =>\n typeof content === 'string' || typeof content === 'number';\n\nconst hasContent = (content: React.ReactNode) =>\n content !== null && content !== undefined;\n\nconst getCompactContentMaxHeight = ({\n hasTitle,\n hasDescription,\n hasChildren,\n}: {\n hasTitle: boolean;\n hasDescription: boolean;\n hasChildren: boolean;\n}) => {\n let maxHeight = 0;\n\n if (hasTitle) {\n maxHeight += BODY_MD_LINE_HEIGHT;\n }\n if (hasDescription) {\n if (hasTitle) {\n maxHeight += TITLE_DESCRIPTION_GAP;\n }\n maxHeight += BODY_SM_LINE_HEIGHT;\n }\n if (hasChildren) {\n maxHeight += BODY_MD_LINE_HEIGHT;\n }\n\n return maxHeight + COMPACT_HEIGHT_TOLERANCE;\n};\n\nexport const BannerBase: React.FC<BannerBaseProps> = ({\n title,\n titleProps,\n description,\n descriptionProps,\n children,\n childrenWrapperProps,\n actionButtonLabel,\n actionButtonOnPress,\n actionButtonProps,\n actionButtonLayout = BannerBaseActionButtonLayout.Below,\n startAccessory,\n onClose,\n closeButtonProps,\n twClassName,\n backgroundColor = BoxBackgroundColor.BackgroundDefault,\n ...props\n}) => {\n const resolvedActionButtonProps = actionButtonProps ?? {};\n\n const {\n accessibilityLabel: closeButtonAccessibilityLabel = 'Close banner',\n twClassName: closeButtonTwClassName,\n ...resolvedCloseButtonProps\n } = closeButtonProps ?? {};\n\n const shouldShowCloseButton = Boolean(onClose);\n const shouldShowActionButton = Boolean(actionButtonOnPress);\n const isActionButtonLayoutEnd =\n actionButtonLayout === BannerBaseActionButtonLayout.End;\n const hasActionButtonBelow =\n shouldShowActionButton && !isActionButtonLayoutEnd;\n const hasTitle = hasContent(title);\n const hasDescription = hasContent(description);\n const hasChildren = hasContent(children);\n // Custom nodes can't be measured reliably — keep top-aligned.\n const hasUnmeasuredContent =\n (hasTitle && !isTextContent(title)) ||\n (hasDescription && !isTextContent(description)) ||\n (hasChildren && !isTextContent(children));\n\n // Multiple text blocks: default top-aligned until the stack measures as\n // single-line per block. A single title, description, or children block\n // always centers (including wraps). Avoids multiline stacks sticking\n // centered when layout callbacks are delayed or skipped.\n const [isCompactContent, setIsCompactContent] = useState(false);\n const isSingleTextBlock =\n [hasTitle, hasDescription, hasChildren].filter(Boolean).length === 1;\n\n const isCenterAligned =\n !hasActionButtonBelow &&\n !hasUnmeasuredContent &&\n (hasTitle || hasDescription || hasChildren) &&\n (isSingleTextBlock || isCompactContent);\n\n const handleContentLayout = (event: LayoutChangeEvent) => {\n if (hasUnmeasuredContent || hasActionButtonBelow || isSingleTextBlock) {\n setIsCompactContent(false);\n return;\n }\n\n const { height } = event.nativeEvent.layout;\n const maxCompactHeight = getCompactContentMaxHeight({\n hasTitle,\n hasDescription,\n hasChildren,\n });\n setIsCompactContent(height > 0 && height <= maxCompactHeight);\n };\n\n const actionButton = shouldShowActionButton ? (\n <Button\n size={ButtonSize.Md}\n onPress={actionButtonOnPress}\n {...resolvedActionButtonProps}\n variant={ButtonVariant.Secondary}\n >\n {actionButtonLabel}\n </Button>\n ) : null;\n\n return (\n <Box\n {...props}\n flexDirection={BoxFlexDirection.Row}\n alignItems={isCenterAligned ? BoxAlignItems.Center : BoxAlignItems.Start}\n gap={4}\n backgroundColor={backgroundColor}\n paddingTop={3}\n paddingBottom={hasActionButtonBelow ? 4 : 3}\n paddingLeft={4}\n paddingRight={shouldShowCloseButton ? 2 : 4}\n twClassName={mergeTwClassName('rounded-xl', twClassName)}\n >\n {startAccessory}\n\n <Box twClassName=\"flex-1\" onLayout={handleContentLayout}>\n {hasTitle &&\n (isTextContent(title) ? (\n <Text\n variant={TextVariant.BodyMd}\n fontWeight={FontWeight.Medium}\n {...titleProps}\n >\n {title}\n </Text>\n ) : (\n title\n ))}\n\n {hasDescription && (\n <Box twClassName={hasTitle ? 'mt-0.5' : undefined}>\n {isTextContent(description) ? (\n <Text variant={TextVariant.BodySm} {...descriptionProps}>\n {description}\n </Text>\n ) : (\n description\n )}\n </Box>\n )}\n\n {hasChildren &&\n (isTextContent(children) ? (\n <Text variant={TextVariant.BodyMd} {...childrenWrapperProps}>\n {children}\n </Text>\n ) : (\n children\n ))}\n\n {hasActionButtonBelow && <Box twClassName=\"mt-2\">{actionButton}</Box>}\n </Box>\n\n {shouldShowActionButton && isActionButtonLayoutEnd && (\n <Box twClassName=\"self-center\">{actionButton}</Box>\n )}\n\n {shouldShowCloseButton && (\n <ButtonIcon\n twClassName={\n isCenterAligned\n ? closeButtonTwClassName\n : mergeTwClassName('-mt-1', closeButtonTwClassName)\n }\n iconName={IconName.Close}\n size={ButtonIconSize.Md}\n accessibilityLabel={closeButtonAccessibilityLabel}\n onPress={onClose}\n {...resolvedCloseButtonProps}\n />\n )}\n </Box>\n );\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BannerBase.d.cts","sourceRoot":"","sources":["../../../src/components/BannerBase/BannerBase.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BannerBase.d.cts","sourceRoot":"","sources":["../../../src/components/BannerBase/BannerBase.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAmB,cAAc;AAQxC,OAAO,KAAK,EAAE,eAAe,EAAE,+BAA2B;AA4C1D,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CA0JhD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BannerBase.d.mts","sourceRoot":"","sources":["../../../src/components/BannerBase/BannerBase.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BannerBase.d.mts","sourceRoot":"","sources":["../../../src/components/BannerBase/BannerBase.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAmB,cAAc;AAQxC,OAAO,KAAK,EAAE,eAAe,EAAE,+BAA2B;AA4C1D,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CA0JhD,CAAC"}
|
|
@@ -5,40 +5,95 @@ function $importDefault(module) {
|
|
|
5
5
|
return module;
|
|
6
6
|
}
|
|
7
7
|
import { BannerBaseActionButtonLayout, BoxAlignItems, BoxBackgroundColor, BoxFlexDirection, ButtonIconSize, ButtonSize, ButtonVariant, FontWeight, IconName, mergeTwClassName, TextVariant } from "@metamask/design-system-shared";
|
|
8
|
-
import
|
|
8
|
+
import { typography } from "@metamask/design-tokens";
|
|
9
|
+
import $React, { useState } from "react";
|
|
9
10
|
const React = $importDefault($React);
|
|
10
11
|
import { Box } from "../Box/index.mjs";
|
|
11
12
|
import { Button } from "../Button/index.mjs";
|
|
12
13
|
import { ButtonIcon } from "../ButtonIcon/index.mjs";
|
|
13
14
|
import { Text } from "../Text/index.mjs";
|
|
15
|
+
/** BodyMd line height — title block. */
|
|
16
|
+
const BODY_MD_LINE_HEIGHT = typography.sBodyMD.lineHeight;
|
|
17
|
+
/** BodySm line height — description block. */
|
|
18
|
+
const BODY_SM_LINE_HEIGHT = typography.sBodySM.lineHeight;
|
|
19
|
+
/** `mt-0.5` between title and description. */
|
|
20
|
+
const TITLE_DESCRIPTION_GAP = 2;
|
|
21
|
+
/** Sub-pixel / font rounding allowance when comparing stack height. */
|
|
22
|
+
const COMPACT_HEIGHT_TOLERANCE = 4;
|
|
14
23
|
const isTextContent = (content) => typeof content === 'string' || typeof content === 'number';
|
|
15
24
|
const hasContent = (content) => content !== null && content !== undefined;
|
|
16
|
-
|
|
25
|
+
const getCompactContentMaxHeight = ({ hasTitle, hasDescription, hasChildren, }) => {
|
|
26
|
+
let maxHeight = 0;
|
|
27
|
+
if (hasTitle) {
|
|
28
|
+
maxHeight += BODY_MD_LINE_HEIGHT;
|
|
29
|
+
}
|
|
30
|
+
if (hasDescription) {
|
|
31
|
+
if (hasTitle) {
|
|
32
|
+
maxHeight += TITLE_DESCRIPTION_GAP;
|
|
33
|
+
}
|
|
34
|
+
maxHeight += BODY_SM_LINE_HEIGHT;
|
|
35
|
+
}
|
|
36
|
+
if (hasChildren) {
|
|
37
|
+
maxHeight += BODY_MD_LINE_HEIGHT;
|
|
38
|
+
}
|
|
39
|
+
return maxHeight + COMPACT_HEIGHT_TOLERANCE;
|
|
40
|
+
};
|
|
41
|
+
export const BannerBase = ({ title, titleProps, description, descriptionProps, children, childrenWrapperProps, actionButtonLabel, actionButtonOnPress, actionButtonProps, actionButtonLayout = BannerBaseActionButtonLayout.Below, startAccessory, onClose, closeButtonProps, twClassName, backgroundColor = BoxBackgroundColor.BackgroundDefault, ...props }) => {
|
|
17
42
|
const resolvedActionButtonProps = actionButtonProps ?? {};
|
|
18
43
|
const { accessibilityLabel: closeButtonAccessibilityLabel = 'Close banner', twClassName: closeButtonTwClassName, ...resolvedCloseButtonProps } = closeButtonProps ?? {};
|
|
19
44
|
const shouldShowCloseButton = Boolean(onClose);
|
|
20
45
|
const shouldShowActionButton = Boolean(actionButtonOnPress);
|
|
21
46
|
const isActionButtonLayoutEnd = actionButtonLayout === BannerBaseActionButtonLayout.End;
|
|
22
47
|
const hasActionButtonBelow = shouldShowActionButton && !isActionButtonLayoutEnd;
|
|
48
|
+
const hasTitle = hasContent(title);
|
|
49
|
+
const hasDescription = hasContent(description);
|
|
50
|
+
const hasChildren = hasContent(children);
|
|
51
|
+
// Custom nodes can't be measured reliably — keep top-aligned.
|
|
52
|
+
const hasUnmeasuredContent = (hasTitle && !isTextContent(title)) ||
|
|
53
|
+
(hasDescription && !isTextContent(description)) ||
|
|
54
|
+
(hasChildren && !isTextContent(children));
|
|
55
|
+
// Multiple text blocks: default top-aligned until the stack measures as
|
|
56
|
+
// single-line per block. A single title, description, or children block
|
|
57
|
+
// always centers (including wraps). Avoids multiline stacks sticking
|
|
58
|
+
// centered when layout callbacks are delayed or skipped.
|
|
59
|
+
const [isCompactContent, setIsCompactContent] = useState(false);
|
|
60
|
+
const isSingleTextBlock = [hasTitle, hasDescription, hasChildren].filter(Boolean).length === 1;
|
|
61
|
+
const isCenterAligned = !hasActionButtonBelow &&
|
|
62
|
+
!hasUnmeasuredContent &&
|
|
63
|
+
(hasTitle || hasDescription || hasChildren) &&
|
|
64
|
+
(isSingleTextBlock || isCompactContent);
|
|
65
|
+
const handleContentLayout = (event) => {
|
|
66
|
+
if (hasUnmeasuredContent || hasActionButtonBelow || isSingleTextBlock) {
|
|
67
|
+
setIsCompactContent(false);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const { height } = event.nativeEvent.layout;
|
|
71
|
+
const maxCompactHeight = getCompactContentMaxHeight({
|
|
72
|
+
hasTitle,
|
|
73
|
+
hasDescription,
|
|
74
|
+
hasChildren,
|
|
75
|
+
});
|
|
76
|
+
setIsCompactContent(height > 0 && height <= maxCompactHeight);
|
|
77
|
+
};
|
|
23
78
|
const actionButton = shouldShowActionButton ? (<Button size={ButtonSize.Md} onPress={actionButtonOnPress} {...resolvedActionButtonProps} variant={ButtonVariant.Secondary}>
|
|
24
79
|
{actionButtonLabel}
|
|
25
80
|
</Button>) : null;
|
|
26
|
-
return (<Box flexDirection={BoxFlexDirection.Row} alignItems={BoxAlignItems.Start} gap={4} backgroundColor={
|
|
81
|
+
return (<Box {...props} flexDirection={BoxFlexDirection.Row} alignItems={isCenterAligned ? BoxAlignItems.Center : BoxAlignItems.Start} gap={4} backgroundColor={backgroundColor} paddingTop={3} paddingBottom={hasActionButtonBelow ? 4 : 3} paddingLeft={4} paddingRight={shouldShowCloseButton ? 2 : 4} twClassName={mergeTwClassName('rounded-xl', twClassName)}>
|
|
27
82
|
{startAccessory}
|
|
28
83
|
|
|
29
|
-
<Box twClassName="flex-1">
|
|
30
|
-
{
|
|
84
|
+
<Box twClassName="flex-1" onLayout={handleContentLayout}>
|
|
85
|
+
{hasTitle &&
|
|
31
86
|
(isTextContent(title) ? (<Text variant={TextVariant.BodyMd} fontWeight={FontWeight.Medium} {...titleProps}>
|
|
32
87
|
{title}
|
|
33
88
|
</Text>) : (title))}
|
|
34
89
|
|
|
35
|
-
{
|
|
90
|
+
{hasDescription && (<Box twClassName={hasTitle ? 'mt-0.5' : undefined}>
|
|
36
91
|
{isTextContent(description) ? (<Text variant={TextVariant.BodySm} {...descriptionProps}>
|
|
37
92
|
{description}
|
|
38
93
|
</Text>) : (description)}
|
|
39
94
|
</Box>)}
|
|
40
95
|
|
|
41
|
-
{
|
|
96
|
+
{hasChildren &&
|
|
42
97
|
(isTextContent(children) ? (<Text variant={TextVariant.BodyMd} {...childrenWrapperProps}>
|
|
43
98
|
{children}
|
|
44
99
|
</Text>) : (children))}
|
|
@@ -46,9 +101,11 @@ export const BannerBase = ({ title, titleProps, description, descriptionProps, c
|
|
|
46
101
|
{hasActionButtonBelow && <Box twClassName="mt-2">{actionButton}</Box>}
|
|
47
102
|
</Box>
|
|
48
103
|
|
|
49
|
-
{shouldShowActionButton && isActionButtonLayoutEnd && actionButton}
|
|
104
|
+
{shouldShowActionButton && isActionButtonLayoutEnd && (<Box twClassName="self-center">{actionButton}</Box>)}
|
|
50
105
|
|
|
51
|
-
{shouldShowCloseButton && (<ButtonIcon twClassName={
|
|
106
|
+
{shouldShowCloseButton && (<ButtonIcon twClassName={isCenterAligned
|
|
107
|
+
? closeButtonTwClassName
|
|
108
|
+
: mergeTwClassName('-mt-1', closeButtonTwClassName)} iconName={IconName.Close} size={ButtonIconSize.Md} accessibilityLabel={closeButtonAccessibilityLabel} onPress={onClose} {...resolvedCloseButtonProps}/>)}
|
|
52
109
|
</Box>);
|
|
53
110
|
};
|
|
54
111
|
//# sourceMappingURL=BannerBase.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BannerBase.mjs","sourceRoot":"","sources":["../../../src/components/BannerBase/BannerBase.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,4BAA4B,EAC5B,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,aAAa,EACb,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACZ,uCAAuC;AACxC,OAAO,MAAK,cAAc;;AAE1B,OAAO,EAAE,GAAG,EAAE,yBAAe;AAC7B,OAAO,EAAE,MAAM,EAAE,4BAAkB;AACnC,OAAO,EAAE,UAAU,EAAE,gCAAsB;AAC3C,OAAO,EAAE,IAAI,EAAE,0BAAgB;AAI/B,MAAM,aAAa,GAAG,CAAC,OAAwB,EAA8B,EAAE,CAC7E,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC;AAE7D,MAAM,UAAU,GAAG,CAAC,OAAwB,EAAE,EAAE,CAC9C,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,CAAC;AAE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ED;;QAAA,CAAC,UAAU,CAAC,QAAQ,CAAC;YACnB,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CACzB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,oBAAoB,CAAC,CAC1D;cAAA,CAAC,QAAQ,CACX;YAAA,EAAE,IAAI,CAAC,CACR,CAAC,CAAC,CAAC,CACF,QAAQ,CACT,CAAC,CAEJ;;QAAA,CAAC,oBAAoB,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,CACvE;MAAA,EAAE,GAAG,CAEL;;MAAA,CAAC,sBAAsB,IAAI,uBAAuB,IAAI,YAAY,CAElE;;MAAA,CAAC,qBAAqB,IAAI,CACxB,CAAC,UAAU,CACT,WAAW,CAAC,CAAC,gBAAgB,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAC/D,QAAQ,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CACzB,IAAI,CAAC,CAAC,cAAc,CAAC,EAAE,CAAC,CACxB,kBAAkB,CAAC,CAAC,6BAA6B,CAAC,CAClD,OAAO,CAAC,CAAC,OAAO,CAAC,CACjB,IAAI,wBAAwB,CAAC,EAC7B,CACH,CACH;IAAA,EAAE,GAAG,CAAC,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n BannerBaseActionButtonLayout,\n BoxAlignItems,\n BoxBackgroundColor,\n BoxFlexDirection,\n ButtonIconSize,\n ButtonSize,\n ButtonVariant,\n FontWeight,\n IconName,\n mergeTwClassName,\n TextVariant,\n} from '@metamask/design-system-shared';\nimport React from 'react';\n\nimport { Box } from '../Box';\nimport { Button } from '../Button';\nimport { ButtonIcon } from '../ButtonIcon';\nimport { Text } from '../Text';\n\nimport type { BannerBaseProps } from './BannerBase.types';\n\nconst isTextContent = (content: React.ReactNode): content is string | number =>\n typeof content === 'string' || typeof content === 'number';\n\nconst hasContent = (content: React.ReactNode) =>\n content !== null && content !== undefined;\n\nexport const BannerBase: React.FC<BannerBaseProps> = ({\n title,\n titleProps,\n description,\n descriptionProps,\n children,\n childrenWrapperProps,\n actionButtonLabel,\n actionButtonOnPress,\n actionButtonProps,\n actionButtonLayout = BannerBaseActionButtonLayout.Below,\n startAccessory,\n onClose,\n closeButtonProps,\n twClassName,\n ...props\n}) => {\n const resolvedActionButtonProps = actionButtonProps ?? {};\n\n const {\n accessibilityLabel: closeButtonAccessibilityLabel = 'Close banner',\n twClassName: closeButtonTwClassName,\n ...resolvedCloseButtonProps\n } = closeButtonProps ?? {};\n\n const shouldShowCloseButton = Boolean(onClose);\n const shouldShowActionButton = Boolean(actionButtonOnPress);\n const isActionButtonLayoutEnd =\n actionButtonLayout === BannerBaseActionButtonLayout.End;\n const hasActionButtonBelow =\n shouldShowActionButton && !isActionButtonLayoutEnd;\n\n const actionButton = shouldShowActionButton ? (\n <Button\n size={ButtonSize.Md}\n onPress={actionButtonOnPress}\n {...resolvedActionButtonProps}\n variant={ButtonVariant.Secondary}\n >\n {actionButtonLabel}\n </Button>\n ) : null;\n\n return (\n <Box\n flexDirection={BoxFlexDirection.Row}\n alignItems={BoxAlignItems.Start}\n gap={4}\n backgroundColor={BoxBackgroundColor.BackgroundDefault}\n paddingTop={3}\n paddingBottom={hasActionButtonBelow ? 4 : 3}\n paddingLeft={4}\n paddingRight={shouldShowCloseButton ? 2 : 4}\n twClassName={mergeTwClassName('rounded-xl', twClassName)}\n {...props}\n >\n {startAccessory}\n\n <Box twClassName=\"flex-1\">\n {hasContent(title) &&\n (isTextContent(title) ? (\n <Text\n variant={TextVariant.BodyMd}\n fontWeight={FontWeight.Medium}\n {...titleProps}\n >\n {title}\n </Text>\n ) : (\n title\n ))}\n\n {hasContent(description) && (\n <Box twClassName={hasContent(title) ? 'mt-0.5' : undefined}>\n {isTextContent(description) ? (\n <Text variant={TextVariant.BodySm} {...descriptionProps}>\n {description}\n </Text>\n ) : (\n description\n )}\n </Box>\n )}\n\n {hasContent(children) &&\n (isTextContent(children) ? (\n <Text variant={TextVariant.BodyMd} {...childrenWrapperProps}>\n {children}\n </Text>\n ) : (\n children\n ))}\n\n {hasActionButtonBelow && <Box twClassName=\"mt-2\">{actionButton}</Box>}\n </Box>\n\n {shouldShowActionButton && isActionButtonLayoutEnd && actionButton}\n\n {shouldShowCloseButton && (\n <ButtonIcon\n twClassName={mergeTwClassName('-mt-1', closeButtonTwClassName)}\n iconName={IconName.Close}\n size={ButtonIconSize.Md}\n accessibilityLabel={closeButtonAccessibilityLabel}\n onPress={onClose}\n {...resolvedCloseButtonProps}\n />\n )}\n </Box>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"BannerBase.mjs","sourceRoot":"","sources":["../../../src/components/BannerBase/BannerBase.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,4BAA4B,EAC5B,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,aAAa,EACb,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACZ,uCAAuC;AACxC,OAAO,EAAE,UAAU,EAAE,gCAAgC;AACrD,OAAO,QAAO,EAAE,QAAQ,EAAE,cAAc;;AAGxC,OAAO,EAAE,GAAG,EAAE,yBAAe;AAC7B,OAAO,EAAE,MAAM,EAAE,4BAAkB;AACnC,OAAO,EAAE,UAAU,EAAE,gCAAsB;AAC3C,OAAO,EAAE,IAAI,EAAE,0BAAgB;AAI/B,wCAAwC;AACxC,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC;AAC1D,8CAA8C;AAC9C,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC;AAC1D,8CAA8C;AAC9C,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,uEAAuE;AACvE,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAEnC,MAAM,aAAa,GAAG,CAAC,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EAAE,GAAG,CAAC,CACpD,CAED;;MAAA,CAAC,qBAAqB,IAAI,CACxB,CAAC,UAAU,CACT,WAAW,CAAC,CACV,eAAe;gBACb,CAAC,CAAC,sBAAsB;gBACxB,CAAC,CAAC,gBAAgB,CAAC,OAAO,EAAE,sBAAsB,CAAC,CACtD,CACD,QAAQ,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CACzB,IAAI,CAAC,CAAC,cAAc,CAAC,EAAE,CAAC,CACxB,kBAAkB,CAAC,CAAC,6BAA6B,CAAC,CAClD,OAAO,CAAC,CAAC,OAAO,CAAC,CACjB,IAAI,wBAAwB,CAAC,EAC7B,CACH,CACH;IAAA,EAAE,GAAG,CAAC,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n BannerBaseActionButtonLayout,\n BoxAlignItems,\n BoxBackgroundColor,\n BoxFlexDirection,\n ButtonIconSize,\n ButtonSize,\n ButtonVariant,\n FontWeight,\n IconName,\n mergeTwClassName,\n TextVariant,\n} from '@metamask/design-system-shared';\nimport { typography } from '@metamask/design-tokens';\nimport React, { useState } from 'react';\nimport type { LayoutChangeEvent } from 'react-native';\n\nimport { Box } from '../Box';\nimport { Button } from '../Button';\nimport { ButtonIcon } from '../ButtonIcon';\nimport { Text } from '../Text';\n\nimport type { BannerBaseProps } from './BannerBase.types';\n\n/** BodyMd line height — title block. */\nconst BODY_MD_LINE_HEIGHT = typography.sBodyMD.lineHeight;\n/** BodySm line height — description block. */\nconst BODY_SM_LINE_HEIGHT = typography.sBodySM.lineHeight;\n/** `mt-0.5` between title and description. */\nconst TITLE_DESCRIPTION_GAP = 2;\n/** Sub-pixel / font rounding allowance when comparing stack height. */\nconst COMPACT_HEIGHT_TOLERANCE = 4;\n\nconst isTextContent = (content: React.ReactNode): content is string | number =>\n typeof content === 'string' || typeof content === 'number';\n\nconst hasContent = (content: React.ReactNode) =>\n content !== null && content !== undefined;\n\nconst getCompactContentMaxHeight = ({\n hasTitle,\n hasDescription,\n hasChildren,\n}: {\n hasTitle: boolean;\n hasDescription: boolean;\n hasChildren: boolean;\n}) => {\n let maxHeight = 0;\n\n if (hasTitle) {\n maxHeight += BODY_MD_LINE_HEIGHT;\n }\n if (hasDescription) {\n if (hasTitle) {\n maxHeight += TITLE_DESCRIPTION_GAP;\n }\n maxHeight += BODY_SM_LINE_HEIGHT;\n }\n if (hasChildren) {\n maxHeight += BODY_MD_LINE_HEIGHT;\n }\n\n return maxHeight + COMPACT_HEIGHT_TOLERANCE;\n};\n\nexport const BannerBase: React.FC<BannerBaseProps> = ({\n title,\n titleProps,\n description,\n descriptionProps,\n children,\n childrenWrapperProps,\n actionButtonLabel,\n actionButtonOnPress,\n actionButtonProps,\n actionButtonLayout = BannerBaseActionButtonLayout.Below,\n startAccessory,\n onClose,\n closeButtonProps,\n twClassName,\n backgroundColor = BoxBackgroundColor.BackgroundDefault,\n ...props\n}) => {\n const resolvedActionButtonProps = actionButtonProps ?? {};\n\n const {\n accessibilityLabel: closeButtonAccessibilityLabel = 'Close banner',\n twClassName: closeButtonTwClassName,\n ...resolvedCloseButtonProps\n } = closeButtonProps ?? {};\n\n const shouldShowCloseButton = Boolean(onClose);\n const shouldShowActionButton = Boolean(actionButtonOnPress);\n const isActionButtonLayoutEnd =\n actionButtonLayout === BannerBaseActionButtonLayout.End;\n const hasActionButtonBelow =\n shouldShowActionButton && !isActionButtonLayoutEnd;\n const hasTitle = hasContent(title);\n const hasDescription = hasContent(description);\n const hasChildren = hasContent(children);\n // Custom nodes can't be measured reliably — keep top-aligned.\n const hasUnmeasuredContent =\n (hasTitle && !isTextContent(title)) ||\n (hasDescription && !isTextContent(description)) ||\n (hasChildren && !isTextContent(children));\n\n // Multiple text blocks: default top-aligned until the stack measures as\n // single-line per block. A single title, description, or children block\n // always centers (including wraps). Avoids multiline stacks sticking\n // centered when layout callbacks are delayed or skipped.\n const [isCompactContent, setIsCompactContent] = useState(false);\n const isSingleTextBlock =\n [hasTitle, hasDescription, hasChildren].filter(Boolean).length === 1;\n\n const isCenterAligned =\n !hasActionButtonBelow &&\n !hasUnmeasuredContent &&\n (hasTitle || hasDescription || hasChildren) &&\n (isSingleTextBlock || isCompactContent);\n\n const handleContentLayout = (event: LayoutChangeEvent) => {\n if (hasUnmeasuredContent || hasActionButtonBelow || isSingleTextBlock) {\n setIsCompactContent(false);\n return;\n }\n\n const { height } = event.nativeEvent.layout;\n const maxCompactHeight = getCompactContentMaxHeight({\n hasTitle,\n hasDescription,\n hasChildren,\n });\n setIsCompactContent(height > 0 && height <= maxCompactHeight);\n };\n\n const actionButton = shouldShowActionButton ? (\n <Button\n size={ButtonSize.Md}\n onPress={actionButtonOnPress}\n {...resolvedActionButtonProps}\n variant={ButtonVariant.Secondary}\n >\n {actionButtonLabel}\n </Button>\n ) : null;\n\n return (\n <Box\n {...props}\n flexDirection={BoxFlexDirection.Row}\n alignItems={isCenterAligned ? BoxAlignItems.Center : BoxAlignItems.Start}\n gap={4}\n backgroundColor={backgroundColor}\n paddingTop={3}\n paddingBottom={hasActionButtonBelow ? 4 : 3}\n paddingLeft={4}\n paddingRight={shouldShowCloseButton ? 2 : 4}\n twClassName={mergeTwClassName('rounded-xl', twClassName)}\n >\n {startAccessory}\n\n <Box twClassName=\"flex-1\" onLayout={handleContentLayout}>\n {hasTitle &&\n (isTextContent(title) ? (\n <Text\n variant={TextVariant.BodyMd}\n fontWeight={FontWeight.Medium}\n {...titleProps}\n >\n {title}\n </Text>\n ) : (\n title\n ))}\n\n {hasDescription && (\n <Box twClassName={hasTitle ? 'mt-0.5' : undefined}>\n {isTextContent(description) ? (\n <Text variant={TextVariant.BodySm} {...descriptionProps}>\n {description}\n </Text>\n ) : (\n description\n )}\n </Box>\n )}\n\n {hasChildren &&\n (isTextContent(children) ? (\n <Text variant={TextVariant.BodyMd} {...childrenWrapperProps}>\n {children}\n </Text>\n ) : (\n children\n ))}\n\n {hasActionButtonBelow && <Box twClassName=\"mt-2\">{actionButton}</Box>}\n </Box>\n\n {shouldShowActionButton && isActionButtonLayoutEnd && (\n <Box twClassName=\"self-center\">{actionButton}</Box>\n )}\n\n {shouldShowCloseButton && (\n <ButtonIcon\n twClassName={\n isCenterAligned\n ? closeButtonTwClassName\n : mergeTwClassName('-mt-1', closeButtonTwClassName)\n }\n iconName={IconName.Close}\n size={ButtonIconSize.Md}\n accessibilityLabel={closeButtonAccessibilityLabel}\n onPress={onClose}\n {...resolvedCloseButtonProps}\n />\n )}\n </Box>\n );\n};\n"]}
|
|
@@ -72,7 +72,7 @@ exports.Checkbox = (0, react_1.forwardRef)(({ isSelected, isDisabled = false, is
|
|
|
72
72
|
const tw = (0, design_system_twrnc_preset_1.useTailwind)();
|
|
73
73
|
const twContainerClassNames = tw.style('flex-row items-center', isDisabled ? 'opacity-50' : 'opacity-100', twClassName);
|
|
74
74
|
const getCheckboxContainerStyle = (0, react_1.useCallback)((pressed) => {
|
|
75
|
-
const baseBg = isSelected ? 'bg-icon-default' : 'bg-
|
|
75
|
+
const baseBg = isSelected ? 'bg-icon-default' : 'bg-transparent';
|
|
76
76
|
let baseBorder = 'border-default';
|
|
77
77
|
if (isSelected) {
|
|
78
78
|
baseBorder = 'border-icon-default';
|
|
@@ -80,9 +80,7 @@ exports.Checkbox = (0, react_1.forwardRef)(({ isSelected, isDisabled = false, is
|
|
|
80
80
|
else if (isInvalid) {
|
|
81
81
|
baseBorder = 'border-error-default';
|
|
82
82
|
}
|
|
83
|
-
const pressedBg = isSelected
|
|
84
|
-
? 'bg-icon-default-pressed'
|
|
85
|
-
: 'bg-default-pressed';
|
|
83
|
+
const pressedBg = isSelected ? 'bg-icon-default-pressed' : 'bg-pressed';
|
|
86
84
|
let pressedBorder = 'border-default';
|
|
87
85
|
if (isSelected) {
|
|
88
86
|
pressedBorder = 'border-icon-default-pressed';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.cjs","sourceRoot":"","sources":["../../../src/components/Checkbox/Checkbox.tsx"],"names":[],"mappings":";;;;;;;;;;;;;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KAAK,CAAC,CAAC,gBAAS,CAAC,WAAW,CAAC,CAC7B,IAAI,CAAC,CAAC,eAAQ,CAAC,EAAE,CAAC,CAClB,IAAI,gBAAgB,CAAC,EAEzB;cAAA,EAAE,uBAAQ,CAAC,IAAI,CACjB;YAAA,EAAE,YAAY,CACd;YAAA,CAAC,KAAK,CAAC,CAAC,CAAC,CACP,CAAC,+BAAc,CACb,SAAS,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAElD;gBAAA,CAAC,KAAK,CACR;cAAA,EAAE,+BAAc,CAAC,CAClB,CAAC,CAAC,CAAC,IAAI,CACV;UAAA,GAAG,CACJ,CACH;MAAA,EAAE,wBAAS,CAAC,CACb,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["import { useTailwind } from '@metamask/design-system-twrnc-preset';\nimport React, {\n forwardRef,\n useRef,\n useImperativeHandle,\n useCallback,\n useEffect,\n} from 'react';\nimport type { PressableStateCallbackType } from 'react-native';\nimport { Pressable, Animated, Easing } from 'react-native';\n\nimport { Icon, IconName, IconColor, IconSize } from '../Icon';\nimport { TextOrChildren } from '../temp-components/TextOrChildren';\n\nimport type { CheckboxProps } from './Checkbox.types';\n\nconst AnimatedView = Animated.View;\n\nexport const Checkbox = forwardRef<{ toggle: () => void }, CheckboxProps>(\n (\n {\n isSelected,\n isDisabled = false,\n isInvalid = false,\n label = '',\n labelProps,\n onChange,\n checkboxContainerProps,\n checkedIconProps,\n twClassName,\n style,\n ...props\n },\n ref,\n ) => {\n // Animation values\n const scaleAnim = useRef(new Animated.Value(1)).current;\n const iconAnim = useRef(new Animated.Value(isSelected ? 1 : 0)).current;\n\n // Sync icon opacity whenever selection changes\n useEffect(() => {\n Animated.timing(iconAnim, {\n toValue: isSelected ? 1 : 0,\n duration: 300,\n easing: Easing.ease,\n useNativeDriver: true,\n }).start();\n }, [isSelected, iconAnim]);\n\n // Bounce effect when toggling\n const animateScale = useCallback(() => {\n Animated.sequence([\n Animated.timing(scaleAnim, {\n toValue: 1.15,\n duration: 100,\n easing: Easing.ease,\n useNativeDriver: true,\n }),\n Animated.timing(scaleAnim, {\n toValue: 1,\n duration: 100,\n easing: Easing.ease,\n useNativeDriver: true,\n }),\n ]).start();\n }, [scaleAnim]);\n\n // Press handler: notify parent, then bounce\n const handlePress = () => {\n if (isDisabled) {\n return;\n }\n onChange?.(!isSelected);\n animateScale();\n };\n\n useImperativeHandle(ref, () => ({ toggle: handlePress }), [handlePress]);\n\n const tw = useTailwind();\n const twContainerClassNames = tw.style(\n 'flex-row items-center',\n isDisabled ? 'opacity-50' : 'opacity-100',\n twClassName,\n );\n\n const getCheckboxContainerStyle = useCallback(\n (pressed: boolean): string => {\n const baseBg = isSelected ? 'bg-icon-default' : 'bg-transparent';\n let baseBorder = 'border-default';\n if (isSelected) {\n baseBorder = 'border-icon-default';\n } else if (isInvalid) {\n baseBorder = 'border-error-default';\n }\n const pressedBg = isSelected ? 'bg-icon-default-pressed' : 'bg-pressed';\n let pressedBorder = 'border-default';\n if (isSelected) {\n pressedBorder = 'border-icon-default-pressed';\n } else if (isInvalid) {\n pressedBorder = 'border-error-default';\n }\n return pressed\n ? `${pressedBg} ${pressedBorder}`\n : `${baseBg} ${baseBorder}`;\n },\n [isSelected, isInvalid],\n );\n\n return (\n <Pressable\n onPress={handlePress}\n accessible\n accessibilityRole=\"checkbox\"\n accessibilityState={{\n checked: isSelected,\n disabled: isDisabled,\n }}\n accessibilityLabel={typeof label === 'string' ? label : undefined}\n disabled={isDisabled}\n {...props}\n style={(state: PressableStateCallbackType) => [\n twContainerClassNames,\n typeof style === 'function' ? style(state) : style,\n ]}\n >\n {({ pressed }) => (\n <>\n <AnimatedView\n {...checkboxContainerProps}\n style={[\n tw`${getCheckboxContainerStyle(pressed)} flex size-[22px] items-center justify-center rounded border-2`,\n { transform: [{ scale: scaleAnim }] },\n ]}\n >\n {/* Always render icon, opacity driven by iconAnim */}\n <Animated.View style={{ opacity: iconAnim }}>\n <Icon\n name={IconName.Check}\n color={IconColor.IconInverse}\n size={IconSize.Sm}\n {...checkedIconProps}\n />\n </Animated.View>\n </AnimatedView>\n {label ? (\n <TextOrChildren\n textProps={{ ...labelProps, twClassName: 'ml-3' }}\n >\n {label}\n </TextOrChildren>\n ) : null}\n </>\n )}\n </Pressable>\n );\n },\n);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.d.cts","sourceRoot":"","sources":["../../../src/components/Checkbox/Checkbox.tsx"],"names":[],"mappings":"AACA,OAAO,KAMN,cAAc;AACf,OAAO,KAAK,EAAE,0BAA0B,EAAE,qBAAqB;AAU/D,eAAO,MAAM,QAAQ;;;;;;;YAAwB,MAAM,IAAI;
|
|
1
|
+
{"version":3,"file":"Checkbox.d.cts","sourceRoot":"","sources":["../../../src/components/Checkbox/Checkbox.tsx"],"names":[],"mappings":"AACA,OAAO,KAMN,cAAc;AACf,OAAO,KAAK,EAAE,0BAA0B,EAAE,qBAAqB;AAU/D,eAAO,MAAM,QAAQ;;;;;;;YAAwB,MAAM,IAAI;GA0ItD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.d.mts","sourceRoot":"","sources":["../../../src/components/Checkbox/Checkbox.tsx"],"names":[],"mappings":"AACA,OAAO,KAMN,cAAc;AACf,OAAO,KAAK,EAAE,0BAA0B,EAAE,qBAAqB;AAU/D,eAAO,MAAM,QAAQ;;;;;;;YAAwB,MAAM,IAAI;
|
|
1
|
+
{"version":3,"file":"Checkbox.d.mts","sourceRoot":"","sources":["../../../src/components/Checkbox/Checkbox.tsx"],"names":[],"mappings":"AACA,OAAO,KAMN,cAAc;AACf,OAAO,KAAK,EAAE,0BAA0B,EAAE,qBAAqB;AAU/D,eAAO,MAAM,QAAQ;;;;;;;YAAwB,MAAM,IAAI;GA0ItD,CAAC"}
|
|
@@ -53,7 +53,7 @@ export const Checkbox = forwardRef(({ isSelected, isDisabled = false, isInvalid
|
|
|
53
53
|
const tw = useTailwind();
|
|
54
54
|
const twContainerClassNames = tw.style('flex-row items-center', isDisabled ? 'opacity-50' : 'opacity-100', twClassName);
|
|
55
55
|
const getCheckboxContainerStyle = useCallback((pressed) => {
|
|
56
|
-
const baseBg = isSelected ? 'bg-icon-default' : 'bg-
|
|
56
|
+
const baseBg = isSelected ? 'bg-icon-default' : 'bg-transparent';
|
|
57
57
|
let baseBorder = 'border-default';
|
|
58
58
|
if (isSelected) {
|
|
59
59
|
baseBorder = 'border-icon-default';
|
|
@@ -61,9 +61,7 @@ export const Checkbox = forwardRef(({ isSelected, isDisabled = false, isInvalid
|
|
|
61
61
|
else if (isInvalid) {
|
|
62
62
|
baseBorder = 'border-error-default';
|
|
63
63
|
}
|
|
64
|
-
const pressedBg = isSelected
|
|
65
|
-
? 'bg-icon-default-pressed'
|
|
66
|
-
: 'bg-default-pressed';
|
|
64
|
+
const pressedBg = isSelected ? 'bg-icon-default-pressed' : 'bg-pressed';
|
|
67
65
|
let pressedBorder = 'border-default';
|
|
68
66
|
if (isSelected) {
|
|
69
67
|
pressedBorder = 'border-icon-default-pressed';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.mjs","sourceRoot":"","sources":["../../../src/components/Checkbox/Checkbox.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,6CAA6C;AACnE,OAAO,QAAO,EACZ,UAAU,EACV,MAAM,EACN,mBAAmB,EACnB,WAAW,EACX,SAAS,EACV,cAAc;;AAEf,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,qBAAqB;AAE3D,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,0BAAgB;AAC9D,OAAO,EAAE,cAAc,EAAE,oDAA0C;AAInE,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC;AAEnC,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CACh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,CAAC,CAClB,IAAI,gBAAgB,CAAC,EAEzB;cAAA,EAAE,QAAQ,CAAC,IAAI,CACjB;YAAA,EAAE,YAAY,CACd;YAAA,CAAC,KAAK,CAAC,CAAC,CAAC,CACP,CAAC,cAAc,CACb,SAAS,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAElD;gBAAA,CAAC,KAAK,CACR;cAAA,EAAE,cAAc,CAAC,CAClB,CAAC,CAAC,CAAC,IAAI,CACV;UAAA,GAAG,CACJ,CACH;MAAA,EAAE,SAAS,CAAC,CACb,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["import { useTailwind } from '@metamask/design-system-twrnc-preset';\nimport React, {\n forwardRef,\n useRef,\n useImperativeHandle,\n useCallback,\n useEffect,\n} from 'react';\nimport type { PressableStateCallbackType } from 'react-native';\nimport { Pressable, Animated, Easing } from 'react-native';\n\nimport { Icon, IconName, IconColor, IconSize } from '../Icon';\nimport { TextOrChildren } from '../temp-components/TextOrChildren';\n\nimport type { CheckboxProps } from './Checkbox.types';\n\nconst AnimatedView = Animated.View;\n\nexport const Checkbox = forwardRef<{ toggle: () => void }, CheckboxProps>(\n (\n {\n isSelected,\n isDisabled = false,\n isInvalid = false,\n label = '',\n labelProps,\n onChange,\n checkboxContainerProps,\n checkedIconProps,\n twClassName,\n style,\n ...props\n },\n ref,\n ) => {\n // Animation values\n const scaleAnim = useRef(new Animated.Value(1)).current;\n const iconAnim = useRef(new Animated.Value(isSelected ? 1 : 0)).current;\n\n // Sync icon opacity whenever selection changes\n useEffect(() => {\n Animated.timing(iconAnim, {\n toValue: isSelected ? 1 : 0,\n duration: 300,\n easing: Easing.ease,\n useNativeDriver: true,\n }).start();\n }, [isSelected, iconAnim]);\n\n // Bounce effect when toggling\n const animateScale = useCallback(() => {\n Animated.sequence([\n Animated.timing(scaleAnim, {\n toValue: 1.15,\n duration: 100,\n easing: Easing.ease,\n useNativeDriver: true,\n }),\n Animated.timing(scaleAnim, {\n toValue: 1,\n duration: 100,\n easing: Easing.ease,\n useNativeDriver: true,\n }),\n ]).start();\n }, [scaleAnim]);\n\n // Press handler: notify parent, then bounce\n const handlePress = () => {\n if (isDisabled) {\n return;\n }\n onChange?.(!isSelected);\n animateScale();\n };\n\n useImperativeHandle(ref, () => ({ toggle: handlePress }), [handlePress]);\n\n const tw = useTailwind();\n const twContainerClassNames = tw.style(\n 'flex-row items-center',\n isDisabled ? 'opacity-50' : 'opacity-100',\n twClassName,\n );\n\n const getCheckboxContainerStyle = useCallback(\n (pressed: boolean): string => {\n const baseBg = isSelected ? 'bg-icon-default' : 'bg-transparent';\n let baseBorder = 'border-default';\n if (isSelected) {\n baseBorder = 'border-icon-default';\n } else if (isInvalid) {\n baseBorder = 'border-error-default';\n }\n const pressedBg = isSelected ? 'bg-icon-default-pressed' : 'bg-pressed';\n let pressedBorder = 'border-default';\n if (isSelected) {\n pressedBorder = 'border-icon-default-pressed';\n } else if (isInvalid) {\n pressedBorder = 'border-error-default';\n }\n return pressed\n ? `${pressedBg} ${pressedBorder}`\n : `${baseBg} ${baseBorder}`;\n },\n [isSelected, isInvalid],\n );\n\n return (\n <Pressable\n onPress={handlePress}\n accessible\n accessibilityRole=\"checkbox\"\n accessibilityState={{\n checked: isSelected,\n disabled: isDisabled,\n }}\n accessibilityLabel={typeof label === 'string' ? label : undefined}\n disabled={isDisabled}\n {...props}\n style={(state: PressableStateCallbackType) => [\n twContainerClassNames,\n typeof style === 'function' ? style(state) : style,\n ]}\n >\n {({ pressed }) => (\n <>\n <AnimatedView\n {...checkboxContainerProps}\n style={[\n tw`${getCheckboxContainerStyle(pressed)} flex size-[22px] items-center justify-center rounded border-2`,\n { transform: [{ scale: scaleAnim }] },\n ]}\n >\n {/* Always render icon, opacity driven by iconAnim */}\n <Animated.View style={{ opacity: iconAnim }}>\n <Icon\n name={IconName.Check}\n color={IconColor.IconInverse}\n size={IconSize.Sm}\n {...checkedIconProps}\n />\n </Animated.View>\n </AnimatedView>\n {label ? (\n <TextOrChildren\n textProps={{ ...labelProps, twClassName: 'ml-3' }}\n >\n {label}\n </TextOrChildren>\n ) : null}\n </>\n )}\n </Pressable>\n );\n },\n);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.types.cjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":";;;AACA,yEAA+D;AAMtD,8FANA,oCAAa,OAMA","sourcesContent":["import type { ToastPropsShared } from '@metamask/design-system-shared';\nimport { ToastSeverity } from '@metamask/design-system-shared';\nimport type { ViewProps } from 'react-native';\n\nimport type { BannerBaseProps } from '../BannerBase';\nimport type { IconProps } from '../Icon/Icon.types';\n\nexport { ToastSeverity };\nexport type { ToastPropsShared };\n\n/**\n * Optional props for the leading severity `Icon`.\n */\nexport type ToastIconProps = Omit<IconProps, 'name' | 'size' | 'color'>;\n\n/**\n * Shared toast props aligned with BannerBase, plus optional severity/icon props.\n */\nexport type ToastSharedProps = Omit<BannerBaseProps, 'closeButtonProps'> & {\n closeButtonProps?: Omit<\n NonNullable<BannerBaseProps['closeButtonProps']>,\n 'onPress'\n >;\n severity?: ToastSeverity;\n iconAlertProps?: ToastIconProps;\n};\n\n/**\n * Toast options used by the imperative `toast(...)` API.\n */\nexport type ToastOptions = ToastSharedProps & {\n hasNoTimeout?: boolean;\n topOffset?: number;\n};\n\n/**\n * Toaster component reference.\n */\nexport type ToasterRef = {\n showToast: (toastOptions: ToastOptions) => void;\n closeToast: () => void;\n};\n\n/**\n * Toast component props intended for direct rendering of a single toast surface.\n */\nexport type ToastProps = ToastSharedProps;\n\n/**\n * Toaster component props.\n * Extends ViewProps to inherit standard React Native props such as testID and accessibilityLabel.\n */\nexport type ToasterProps = {\n /**\n * Optional Tailwind CSS classes for the toast container.\n */\n twClassName?: string;\n} & Omit<ViewProps, 'style'>;\n"]}
|
|
1
|
+
{"version":3,"file":"Toast.types.cjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":";;;AACA,yEAA+D;AAMtD,8FANA,oCAAa,OAMA","sourcesContent":["import type { ToastPropsShared } from '@metamask/design-system-shared';\nimport { ToastSeverity } from '@metamask/design-system-shared';\nimport type { ViewProps } from 'react-native';\n\nimport type { BannerBaseProps } from '../BannerBase';\nimport type { IconProps } from '../Icon/Icon.types';\n\nexport { ToastSeverity };\nexport type { ToastPropsShared };\n\n/**\n * Optional props for the leading severity `Icon`.\n */\nexport type ToastIconProps = Omit<IconProps, 'name' | 'size' | 'color'>;\n\n/**\n * Shared toast props aligned with BannerBase, plus optional severity/icon props.\n */\nexport type ToastSharedProps = Omit<BannerBaseProps, 'closeButtonProps'> & {\n closeButtonProps?: Omit<\n NonNullable<BannerBaseProps['closeButtonProps']>,\n 'onPress'\n >;\n severity?: ToastSeverity;\n iconAlertProps?: ToastIconProps;\n};\n\n/**\n * Toast options used by the imperative `toast(...)` API.\n */\nexport type ToastOptions = ToastSharedProps & {\n hasNoTimeout?: boolean;\n topOffset?: number;\n /**\n * When `false`, hides the close button on the imperative toast.\n * Swipe-to-dismiss, auto-dismiss, and `toast.dismiss()` still work.\n * Defaults to `true`.\n */\n showCloseButton?: boolean;\n};\n\n/**\n * Toaster component reference.\n */\nexport type ToasterRef = {\n showToast: (toastOptions: ToastOptions) => void;\n closeToast: () => void;\n};\n\n/**\n * Toast component props intended for direct rendering of a single toast surface.\n */\nexport type ToastProps = ToastSharedProps;\n\n/**\n * Toaster component props.\n * Extends ViewProps to inherit standard React Native props such as testID and accessibilityLabel.\n */\nexport type ToasterProps = {\n /**\n * Optional Tailwind CSS classes for the toast container.\n */\n twClassName?: string;\n} & Omit<ViewProps, 'style'>;\n"]}
|
|
@@ -23,6 +23,12 @@ export type ToastSharedProps = Omit<BannerBaseProps, 'closeButtonProps'> & {
|
|
|
23
23
|
export type ToastOptions = ToastSharedProps & {
|
|
24
24
|
hasNoTimeout?: boolean;
|
|
25
25
|
topOffset?: number;
|
|
26
|
+
/**
|
|
27
|
+
* When `false`, hides the close button on the imperative toast.
|
|
28
|
+
* Swipe-to-dismiss, auto-dismiss, and `toast.dismiss()` still work.
|
|
29
|
+
* Defaults to `true`.
|
|
30
|
+
*/
|
|
31
|
+
showCloseButton?: boolean;
|
|
26
32
|
};
|
|
27
33
|
/**
|
|
28
34
|
* Toaster component reference.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.types.d.cts","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uCAAuC;AACvE,OAAO,EAAE,aAAa,EAAE,uCAAuC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB;AAE9C,OAAO,KAAK,EAAE,eAAe,EAAE,gCAAsB;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,+BAA2B;AAEpD,OAAO,EAAE,aAAa,EAAE,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAEjC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG;IACzE,gBAAgB,CAAC,EAAE,IAAI,CACrB,WAAW,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,EAChD,SAAS,CACV,CAAC;IACF,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG;IAC5C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"Toast.types.d.cts","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"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,CAAC"}
|
|
@@ -23,6 +23,12 @@ export type ToastSharedProps = Omit<BannerBaseProps, 'closeButtonProps'> & {
|
|
|
23
23
|
export type ToastOptions = ToastSharedProps & {
|
|
24
24
|
hasNoTimeout?: boolean;
|
|
25
25
|
topOffset?: number;
|
|
26
|
+
/**
|
|
27
|
+
* When `false`, hides the close button on the imperative toast.
|
|
28
|
+
* Swipe-to-dismiss, auto-dismiss, and `toast.dismiss()` still work.
|
|
29
|
+
* Defaults to `true`.
|
|
30
|
+
*/
|
|
31
|
+
showCloseButton?: boolean;
|
|
26
32
|
};
|
|
27
33
|
/**
|
|
28
34
|
* Toaster component reference.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.types.d.mts","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uCAAuC;AACvE,OAAO,EAAE,aAAa,EAAE,uCAAuC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB;AAE9C,OAAO,KAAK,EAAE,eAAe,EAAE,gCAAsB;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,+BAA2B;AAEpD,OAAO,EAAE,aAAa,EAAE,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAEjC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG;IACzE,gBAAgB,CAAC,EAAE,IAAI,CACrB,WAAW,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,EAChD,SAAS,CACV,CAAC;IACF,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YA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;AACH,MAAM,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAE1C;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.types.mjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,uCAAuC;AAM/D,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import type { ToastPropsShared } from '@metamask/design-system-shared';\nimport { ToastSeverity } from '@metamask/design-system-shared';\nimport type { ViewProps } from 'react-native';\n\nimport type { BannerBaseProps } from '../BannerBase';\nimport type { IconProps } from '../Icon/Icon.types';\n\nexport { ToastSeverity };\nexport type { ToastPropsShared };\n\n/**\n * Optional props for the leading severity `Icon`.\n */\nexport type ToastIconProps = Omit<IconProps, 'name' | 'size' | 'color'>;\n\n/**\n * Shared toast props aligned with BannerBase, plus optional severity/icon props.\n */\nexport type ToastSharedProps = Omit<BannerBaseProps, 'closeButtonProps'> & {\n closeButtonProps?: Omit<\n NonNullable<BannerBaseProps['closeButtonProps']>,\n 'onPress'\n >;\n severity?: ToastSeverity;\n iconAlertProps?: ToastIconProps;\n};\n\n/**\n * Toast options used by the imperative `toast(...)` API.\n */\nexport type ToastOptions = ToastSharedProps & {\n hasNoTimeout?: boolean;\n topOffset?: number;\n};\n\n/**\n * Toaster component reference.\n */\nexport type ToasterRef = {\n showToast: (toastOptions: ToastOptions) => void;\n closeToast: () => void;\n};\n\n/**\n * Toast component props intended for direct rendering of a single toast surface.\n */\nexport type ToastProps = ToastSharedProps;\n\n/**\n * Toaster component props.\n * Extends ViewProps to inherit standard React Native props such as testID and accessibilityLabel.\n */\nexport type ToasterProps = {\n /**\n * Optional Tailwind CSS classes for the toast container.\n */\n twClassName?: string;\n} & Omit<ViewProps, 'style'>;\n"]}
|
|
1
|
+
{"version":3,"file":"Toast.types.mjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,uCAAuC;AAM/D,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import type { ToastPropsShared } from '@metamask/design-system-shared';\nimport { ToastSeverity } from '@metamask/design-system-shared';\nimport type { ViewProps } from 'react-native';\n\nimport type { BannerBaseProps } from '../BannerBase';\nimport type { IconProps } from '../Icon/Icon.types';\n\nexport { ToastSeverity };\nexport type { ToastPropsShared };\n\n/**\n * Optional props for the leading severity `Icon`.\n */\nexport type ToastIconProps = Omit<IconProps, 'name' | 'size' | 'color'>;\n\n/**\n * Shared toast props aligned with BannerBase, plus optional severity/icon props.\n */\nexport type ToastSharedProps = Omit<BannerBaseProps, 'closeButtonProps'> & {\n closeButtonProps?: Omit<\n NonNullable<BannerBaseProps['closeButtonProps']>,\n 'onPress'\n >;\n severity?: ToastSeverity;\n iconAlertProps?: ToastIconProps;\n};\n\n/**\n * Toast options used by the imperative `toast(...)` API.\n */\nexport type ToastOptions = ToastSharedProps & {\n hasNoTimeout?: boolean;\n topOffset?: number;\n /**\n * When `false`, hides the close button on the imperative toast.\n * Swipe-to-dismiss, auto-dismiss, and `toast.dismiss()` still work.\n * Defaults to `true`.\n */\n showCloseButton?: boolean;\n};\n\n/**\n * Toaster component reference.\n */\nexport type ToasterRef = {\n showToast: (toastOptions: ToastOptions) => void;\n closeToast: () => void;\n};\n\n/**\n * Toast component props intended for direct rendering of a single toast surface.\n */\nexport type ToastProps = ToastSharedProps;\n\n/**\n * Toaster component props.\n * Extends ViewProps to inherit standard React Native props such as testID and accessibilityLabel.\n */\nexport type ToasterProps = {\n /**\n * Optional Tailwind CSS classes for the toast container.\n */\n twClassName?: string;\n} & Omit<ViewProps, 'style'>;\n"]}
|
|
@@ -44,7 +44,7 @@ const assertRegisteredRef = (method) => {
|
|
|
44
44
|
}
|
|
45
45
|
return registeredRef.current;
|
|
46
46
|
};
|
|
47
|
-
const getToastProps = ({ hasNoTimeout: _hasNoTimeout, onClose: _onClose, topOffset: _topOffset, twClassName: _twClassName, ...toastProps }) => toastProps;
|
|
47
|
+
const getToastProps = ({ hasNoTimeout: _hasNoTimeout, onClose: _onClose, topOffset: _topOffset, twClassName: _twClassName, showCloseButton: _showCloseButton, ...toastProps }) => toastProps;
|
|
48
48
|
const getHiddenTranslateY = (height, offset) => -(height + offset);
|
|
49
49
|
const ToasterComponent = (0, react_1.forwardRef)(({ twClassName, ...props }, ref) => {
|
|
50
50
|
const tw = (0, design_system_twrnc_preset_1.useTailwind)();
|
|
@@ -286,12 +286,18 @@ const ToasterComponent = (0, react_1.forwardRef)(({ twClassName, ...props }, ref
|
|
|
286
286
|
if (!toastOptions) {
|
|
287
287
|
return null;
|
|
288
288
|
}
|
|
289
|
-
const { onClose: toastOnClose, twClassName: toastTwClassName } = toastOptions;
|
|
289
|
+
const { onClose: toastOnClose, showCloseButton = true, twClassName: toastTwClassName, } = toastOptions;
|
|
290
290
|
const toastProps = getToastProps(toastOptions);
|
|
291
291
|
const { actionButtonLabel, actionButtonOnPress, ...restToastProps } = toastProps;
|
|
292
292
|
const toastTwClassNames = [twClassName, toastTwClassName]
|
|
293
293
|
.filter(Boolean)
|
|
294
294
|
.join(' ');
|
|
295
|
+
const handleClose = showCloseButton
|
|
296
|
+
? () => {
|
|
297
|
+
closeToast();
|
|
298
|
+
toastOnClose?.();
|
|
299
|
+
}
|
|
300
|
+
: undefined;
|
|
295
301
|
const onAnimatedViewLayout = (e) => {
|
|
296
302
|
const { height } = e.nativeEvent.layout;
|
|
297
303
|
const nextHiddenTranslateY = getHiddenTranslateY(height, topOffset);
|
|
@@ -317,13 +323,7 @@ const ToasterComponent = (0, react_1.forwardRef)(({ twClassName, ...props }, ref
|
|
|
317
323
|
};
|
|
318
324
|
return (<react_native_gesture_handler_1.GestureDetector gesture={swipeGesture}>
|
|
319
325
|
<react_native_reanimated_1.default.View onLayout={onAnimatedViewLayout} style={baseStyle} {...props}>
|
|
320
|
-
{actionButtonLabel && actionButtonOnPress ? (<Toast_1.Toast {...toastProps} actionButtonLabel={actionButtonLabel} actionButtonOnPress={actionButtonOnPress} onClose={
|
|
321
|
-
closeToast();
|
|
322
|
-
toastOnClose?.();
|
|
323
|
-
}} twClassName={toastTwClassNames}/>) : (<Toast_1.Toast {...restToastProps} onClose={() => {
|
|
324
|
-
closeToast();
|
|
325
|
-
toastOnClose?.();
|
|
326
|
-
}} twClassName={toastTwClassNames}/>)}
|
|
326
|
+
{actionButtonLabel && actionButtonOnPress ? (<Toast_1.Toast {...toastProps} actionButtonLabel={actionButtonLabel} actionButtonOnPress={actionButtonOnPress} onClose={handleClose} twClassName={toastTwClassNames}/>) : (<Toast_1.Toast {...restToastProps} onClose={handleClose} twClassName={toastTwClassNames}/>)}
|
|
327
327
|
</react_native_reanimated_1.default.View>
|
|
328
328
|
</react_native_gesture_handler_1.GestureDetector>);
|
|
329
329
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toaster.cjs","sourceRoot":"","sources":["../../../src/components/Toast/Toaster.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAA4B;AAC5B,qFAAmE;AACnE,+CAOe;AAEf,+CAA0C;AAE1C,+EAAwE;AACxE,mFAKiC;AACjC,mFAAmE;AACnE,iEAAqD;AAErD,yBAAyB;AACzB,uCAAgC;AAChC,2DAS2B;AAQ3B,MAAM,YAAY,GAAG,yBAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;AAErD,IAAI,aAAa,GAAwC,IAAI,CAAC;AAE9D,MAAM,mBAAmB,GAAG,CAAC,MAA2B,EAAc,EAAE;IACtE,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE;QAC3B,MAAM,UAAU,GAAG,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,SA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,CACnB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,gBAAgB,CAAC,WAAW,GAAG,SAAS,CAAC;AAM5B,QAAA,OAAO,GAAG,gBAAgB,CAAC;AAE3B,QAAA,KAAK,GAAG,CAAC,CAAC,OAAqB,EAAE,EAAE;IAC9C,mBAAmB,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AAClD,CAAC,CAAkB,CAAC;AAEpB,aAAK,CAAC,OAAO,GAAG,GAAG,EAAE;IACnB,mBAAmB,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;AAC9C,CAAC,CAAC","sourcesContent":["// Third party dependencies.\nimport { useTailwind } from '@metamask/design-system-twrnc-preset';\nimport React, {\n forwardRef,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport type { RefObject } from 'react';\nimport { Dimensions } from 'react-native';\nimport type { LayoutChangeEvent, StyleProp, ViewStyle } from 'react-native';\nimport { Gesture, GestureDetector } from 'react-native-gesture-handler';\nimport Animated, {\n cancelAnimation,\n useAnimatedStyle,\n useSharedValue,\n withSpring,\n} from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport { scheduleOnRN } from 'react-native-worklets';\n\n// Internal dependencies.\nimport { Toast } from './Toast';\nimport {\n TOAST_DISMISS_DISTANCE_THRESHOLD,\n TOAST_DISMISS_MIN_DISTANCE,\n TOAST_DISMISS_VELOCITY_THRESHOLD,\n TOAST_SPRING_CONFIG,\n TOAST_SWIPE_ACTIVE_OFFSET_Y,\n TOAST_SWIPE_FAIL_OFFSET_X,\n TOAST_TOP_PADDING,\n TOAST_VISIBILITY_DURATION,\n} from './Toast.constants';\nimport type {\n ToastOptions,\n ToastProps,\n ToasterProps,\n ToasterRef,\n} from './Toast.types';\n\nconst screenHeight = Dimensions.get('window').height;\n\nlet registeredRef: RefObject<ToasterRef | null> | null = null;\n\nconst assertRegisteredRef = (method: 'dismiss' | 'toast'): ToasterRef => {\n if (!registeredRef?.current) {\n const invocation = method === 'toast' ? 'toast()' : `toast.${method}()`;\n throw new Error(\n `${invocation} called before <Toaster /> mounted. Render <Toaster /> once at the root of your app.`,\n );\n }\n return registeredRef.current;\n};\n\nconst getToastProps = ({\n hasNoTimeout: _hasNoTimeout,\n onClose: _onClose,\n topOffset: _topOffset,\n twClassName: _twClassName,\n ...toastProps\n}: ToastOptions): Omit<ToastProps, 'twClassName'> => toastProps;\n\nconst getHiddenTranslateY = (height: number, offset: number) =>\n -(height + offset);\n\nconst ToasterComponent = forwardRef<ToasterRef, ToasterProps>(\n ({ twClassName, ...props }, ref) => {\n const tw = useTailwind();\n const [toastOptions, setToastOptions] = useState<ToastOptions | undefined>(\n undefined,\n );\n const replacementTimerRef = useRef<ReturnType<typeof setTimeout> | null>(\n null,\n );\n const autoDismissTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(\n null,\n );\n const animationStartedRef = useRef(false);\n const visibleAtRef = useRef<number | null>(null);\n const hasNoTimeoutRef = useRef(false);\n // Invalidates queued spring-back resumes after replace/dismiss. A completed\n // spring cannot be cancelled, so scheduleOnRN(resume) can still run later.\n const toastGenerationRef = useRef(0);\n const { top: topInset } = useSafeAreaInsets();\n const toastHeight = useSharedValue(screenHeight);\n const hiddenTranslateY = useSharedValue(-screenHeight);\n const visibleTranslateY = useSharedValue(0);\n const gestureStartY = useSharedValue(0);\n const translateYProgress = useSharedValue(-screenHeight);\n const isDismissing = useSharedValue(false);\n // True after onStart until onEnd/onFinalize recovers. Used so a failed pan\n // (e.g. failOffsetX after activation) still springs back and resumes dismiss.\n const isSwipeActive = useSharedValue(false);\n const toastGeneration = useSharedValue(0);\n const topOffset = toastOptions?.topOffset ?? 0;\n hasNoTimeoutRef.current = Boolean(toastOptions?.hasNoTimeout);\n const animatedStyle = useAnimatedStyle(() => ({\n transform: [{ translateY: translateYProgress.value + topOffset }],\n }));\n const baseStyle = useMemo(\n () =>\n [\n tw.style('absolute left-4 right-4 top-0'),\n animatedStyle,\n ] as StyleProp<ViewStyle>,\n [tw, animatedStyle],\n );\n const innerRef = useRef<ToasterRef | null>(null);\n\n const clearScheduledAutoDismiss = () => {\n if (autoDismissTimeoutRef.current !== null) {\n clearTimeout(autoDismissTimeoutRef.current);\n autoDismissTimeoutRef.current = null;\n }\n };\n\n const bumpToastGeneration = () => {\n toastGenerationRef.current += 1;\n toastGeneration.value = toastGenerationRef.current;\n };\n\n const resetState = () => {\n animationStartedRef.current = false;\n visibleAtRef.current = null;\n isDismissing.value = false;\n isSwipeActive.value = false;\n clearScheduledAutoDismiss();\n setToastOptions(undefined);\n };\n\n const startDismissAnimation = () => {\n bumpToastGeneration();\n clearScheduledAutoDismiss();\n isDismissing.value = true;\n visibleAtRef.current = null;\n translateYProgress.value = withSpring(\n hiddenTranslateY.value,\n TOAST_SPRING_CONFIG,\n (finished) => {\n if (finished) {\n scheduleOnRN(resetState);\n }\n },\n );\n };\n\n const scheduleAutoDismiss = (delayMs: number) => {\n clearScheduledAutoDismiss();\n autoDismissTimeoutRef.current = setTimeout(() => {\n autoDismissTimeoutRef.current = null;\n startDismissAnimation();\n }, delayMs);\n };\n\n const beginAutoDismiss = () => {\n visibleAtRef.current = Date.now();\n scheduleAutoDismiss(TOAST_VISIBILITY_DURATION);\n };\n\n const resumeAutoDismissAfterSwipe = () => {\n if (hasNoTimeoutRef.current || isDismissing.value) {\n return;\n }\n\n // Entrance was interrupted before auto-dismiss started — start a full timer.\n if (visibleAtRef.current === null) {\n beginAutoDismiss();\n return;\n }\n\n const elapsed = Date.now() - visibleAtRef.current;\n if (elapsed >= TOAST_VISIBILITY_DURATION) {\n startDismissAnimation();\n return;\n }\n\n scheduleAutoDismiss(TOAST_VISIBILITY_DURATION - elapsed);\n };\n\n const showToast = (options: ToastOptions) => {\n bumpToastGeneration();\n let timeoutDuration = 0;\n const normalizedOptions = {\n hasNoTimeout: false,\n ...options,\n };\n if (toastOptions) {\n // Always clear any pending auto-dismiss from the previous toast, including\n // when the replacement is persistent (hasNoTimeout). Otherwise the old\n // timer can fire and dismiss the new toast.\n clearScheduledAutoDismiss();\n cancelAnimation(translateYProgress);\n timeoutDuration = 100;\n animationStartedRef.current = false;\n visibleAtRef.current = null;\n isDismissing.value = false;\n isSwipeActive.value = false;\n setToastOptions(undefined);\n }\n if (replacementTimerRef.current !== null) {\n clearTimeout(replacementTimerRef.current);\n }\n replacementTimerRef.current = setTimeout(() => {\n replacementTimerRef.current = null;\n setToastOptions(normalizedOptions);\n }, timeoutDuration);\n };\n\n const closeToast = () => {\n if (replacementTimerRef.current !== null) {\n clearTimeout(replacementTimerRef.current);\n replacementTimerRef.current = null;\n }\n startDismissAnimation();\n };\n\n const closeToastRef = useRef(closeToast);\n const resumeAutoDismissAfterSwipeRef = useRef(resumeAutoDismissAfterSwipe);\n const clearScheduledAutoDismissRef = useRef(clearScheduledAutoDismiss);\n closeToastRef.current = closeToast;\n resumeAutoDismissAfterSwipeRef.current = resumeAutoDismissAfterSwipe;\n clearScheduledAutoDismissRef.current = clearScheduledAutoDismiss;\n\n const dismissToastFromSwipe = () => {\n closeToastRef.current();\n };\n\n const resumeAutoDismissFromSwipe = (generation: number) => {\n // Ignore resumes from a toast that was replaced or dismissed after the\n // spring-back started (completed springs cannot be cancelled).\n if (generation !== toastGenerationRef.current) {\n return;\n }\n resumeAutoDismissAfterSwipeRef.current();\n };\n\n const clearScheduledAutoDismissFromSwipe = () => {\n clearScheduledAutoDismissRef.current();\n };\n\n const swipeGesture = useMemo(() => {\n // These gesture callbacks need explicit 'worklet' directives because this\n // package ships a pre-built dist compiled by ts-bridge (tsc), which emits the\n // gesture chain as a namespaced call (react_native_gesture_handler_1.Gesture).\n // The consumer's Reanimated/Worklets Babel plugin does run over dist, but its\n // gesture auto-detection doesn't recognize that compiled namespaced form.\n const springBackAfterSwipe = () => {\n 'worklet';\n\n const generationAtSpringStart = toastGeneration.value;\n translateYProgress.value = withSpring(\n visibleTranslateY.value,\n TOAST_SPRING_CONFIG,\n (finished) => {\n // A new pan cancels this spring via cancelAnimation; only resume\n // auto-dismiss when the spring-back completed naturally.\n if (finished) {\n scheduleOnRN(resumeAutoDismissFromSwipe, generationAtSpringStart);\n }\n },\n );\n };\n\n return Gesture.Pan()\n .activeOffsetY(TOAST_SWIPE_ACTIVE_OFFSET_Y)\n .failOffsetX([-TOAST_SWIPE_FAIL_OFFSET_X, TOAST_SWIPE_FAIL_OFFSET_X])\n .onStart(() => {\n 'worklet';\n\n // Don't interrupt an in-progress dismiss animation.\n if (isDismissing.value) {\n return;\n }\n isSwipeActive.value = true;\n scheduleOnRN(clearScheduledAutoDismissFromSwipe);\n cancelAnimation(translateYProgress);\n gestureStartY.value = translateYProgress.value;\n })\n .onUpdate((event) => {\n 'worklet';\n\n if (isDismissing.value || !isSwipeActive.value) {\n return;\n }\n const nextTranslateY = gestureStartY.value + event.translationY;\n // Toast sits at the top; only allow dragging upward (more negative).\n translateYProgress.value = Math.min(\n nextTranslateY,\n visibleTranslateY.value,\n );\n })\n .onEnd((event) => {\n 'worklet';\n\n if (!isSwipeActive.value) {\n return;\n }\n isSwipeActive.value = false;\n\n if (isDismissing.value) {\n return;\n }\n const { translationY, velocityY } = event;\n const dismissDistance = Math.max(\n toastHeight.value * TOAST_DISMISS_DISTANCE_THRESHOLD,\n TOAST_DISMISS_MIN_DISTANCE,\n );\n const hasReachedDismissOffset = translationY <= -dismissDistance;\n const hasReachedSwipeThreshold =\n Math.abs(velocityY) > TOAST_DISMISS_VELOCITY_THRESHOLD;\n const isQuickDismissing = velocityY < 0;\n\n const shouldDismiss =\n hasReachedDismissOffset ||\n (hasReachedSwipeThreshold && isQuickDismissing);\n\n if (shouldDismiss) {\n scheduleOnRN(dismissToastFromSwipe);\n return;\n }\n\n springBackAfterSwipe();\n })\n .onFinalize(() => {\n 'worklet';\n\n // onEnd is skipped when the pan fails/cancels after activation\n // (e.g. horizontal travel past failOffsetX). Recover position and\n // auto-dismiss so the toast is not left stuck mid-offset.\n if (!isSwipeActive.value) {\n return;\n }\n // Clear before the dismiss check — same order as onEnd — so a pan\n // cancelled mid-dismiss cannot leave isSwipeActive stuck true for a\n // later toast (resetState alone is not enough if finalize races it).\n isSwipeActive.value = false;\n\n if (isDismissing.value) {\n return;\n }\n springBackAfterSwipe();\n });\n // Shared values and swipe JS wrappers are stable for the component lifetime.\n }, []);\n\n innerRef.current = {\n closeToast,\n showToast,\n };\n\n useImperativeHandle(ref, () => innerRef.current as ToasterRef);\n\n useLayoutEffect(() => {\n registeredRef = innerRef;\n return () => {\n if (registeredRef === innerRef) {\n registeredRef = null;\n }\n };\n }, []);\n\n if (!toastOptions) {\n return null;\n }\n\n const { onClose: toastOnClose, twClassName: toastTwClassName } =\n toastOptions;\n const toastProps = getToastProps(toastOptions);\n const { actionButtonLabel, actionButtonOnPress, ...restToastProps } =\n toastProps;\n const toastTwClassNames = [twClassName, toastTwClassName]\n .filter(Boolean)\n .join(' ');\n\n const onAnimatedViewLayout = (e: LayoutChangeEvent) => {\n const { height } = e.nativeEvent.layout;\n const nextHiddenTranslateY = getHiddenTranslateY(height, topOffset);\n const nextVisibleTranslateY = topInset + TOAST_TOP_PADDING;\n\n hiddenTranslateY.value = nextHiddenTranslateY;\n visibleTranslateY.value = nextVisibleTranslateY;\n toastHeight.value = height;\n\n if (animationStartedRef.current) {\n return;\n }\n\n animationStartedRef.current = true;\n translateYProgress.value = nextHiddenTranslateY;\n\n if (toastOptions.hasNoTimeout) {\n translateYProgress.value = withSpring(\n nextVisibleTranslateY,\n TOAST_SPRING_CONFIG,\n );\n } else {\n translateYProgress.value = withSpring(\n nextVisibleTranslateY,\n TOAST_SPRING_CONFIG,\n (finished) => {\n if (finished) {\n scheduleOnRN(beginAutoDismiss);\n }\n },\n );\n }\n };\n\n return (\n <GestureDetector gesture={swipeGesture}>\n <Animated.View\n onLayout={onAnimatedViewLayout}\n style={baseStyle}\n {...props}\n >\n {actionButtonLabel && actionButtonOnPress ? (\n <Toast\n {...toastProps}\n actionButtonLabel={actionButtonLabel}\n actionButtonOnPress={actionButtonOnPress}\n onClose={() => {\n closeToast();\n toastOnClose?.();\n }}\n twClassName={toastTwClassNames}\n />\n ) : (\n <Toast\n {...restToastProps}\n onClose={() => {\n closeToast();\n toastOnClose?.();\n }}\n twClassName={toastTwClassNames}\n />\n )}\n </Animated.View>\n </GestureDetector>\n );\n },\n);\n\nToasterComponent.displayName = 'Toaster';\n\ntype ToastFunction = ((options: ToastOptions) => void) & {\n dismiss: () => void;\n};\n\nexport const Toaster = ToasterComponent;\n\nexport const toast = ((options: ToastOptions) => {\n assertRegisteredRef('toast').showToast(options);\n}) as ToastFunction;\n\ntoast.dismiss = () => {\n assertRegisteredRef('dismiss').closeToast();\n};\n"]}
|
|
1
|
+
{"version":3,"file":"Toaster.cjs","sourceRoot":"","sources":["../../../src/components/Toast/Toaster.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAA4B;AAC5B,qFAAmE;AACnE,+CAOe;AAEf,+CAA0C;AAE1C,+EAAwE;AACxE,mFAKiC;AACjC,mFAAmE;AACnE,iEAAqD;AAErD,yBAAyB;AACzB,uCAAgC;AAChC,2DAS2B;AAQ3B,MAAM,YAAY,GAAG,yBAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;AAErD,IAAI,aAAa,GAAwC,IAAI,CAAC;AAE9D,MAAM,mBAAmB,GAAG,CAAC,MAA2B,EAAc,EAAE;IACtE,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE;QAC3B,MAAM,UAAU,GAAG,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC;QACxE,MAAM,IAAI,KAAK,CACb,GAAG,UAAU,sFAAsF,CACpG,CAAC;KACH;IACD,OAAO,aAAa,CAAC,OAAO,CAAC;AAC/B,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,CAAC,EACrB,YAAY,EAAE,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C,OAAqB,EAAE,EAAE;IAC9C,mBAAmB,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AAClD,CAAC,CAAkB,CAAC;AAEpB,aAAK,CAAC,OAAO,GAAG,GAAG,EAAE;IACnB,mBAAmB,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;AAC9C,CAAC,CAAC","sourcesContent":["// Third party dependencies.\nimport { useTailwind } from '@metamask/design-system-twrnc-preset';\nimport React, {\n forwardRef,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport type { RefObject } from 'react';\nimport { Dimensions } from 'react-native';\nimport type { LayoutChangeEvent, StyleProp, ViewStyle } from 'react-native';\nimport { Gesture, GestureDetector } from 'react-native-gesture-handler';\nimport Animated, {\n cancelAnimation,\n useAnimatedStyle,\n useSharedValue,\n withSpring,\n} from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport { scheduleOnRN } from 'react-native-worklets';\n\n// Internal dependencies.\nimport { Toast } from './Toast';\nimport {\n TOAST_DISMISS_DISTANCE_THRESHOLD,\n TOAST_DISMISS_MIN_DISTANCE,\n TOAST_DISMISS_VELOCITY_THRESHOLD,\n TOAST_SPRING_CONFIG,\n TOAST_SWIPE_ACTIVE_OFFSET_Y,\n TOAST_SWIPE_FAIL_OFFSET_X,\n TOAST_TOP_PADDING,\n TOAST_VISIBILITY_DURATION,\n} from './Toast.constants';\nimport type {\n ToastOptions,\n ToastProps,\n ToasterProps,\n ToasterRef,\n} from './Toast.types';\n\nconst screenHeight = Dimensions.get('window').height;\n\nlet registeredRef: RefObject<ToasterRef | null> | null = null;\n\nconst assertRegisteredRef = (method: 'dismiss' | 'toast'): ToasterRef => {\n if (!registeredRef?.current) {\n const invocation = method === 'toast' ? 'toast()' : `toast.${method}()`;\n throw new Error(\n `${invocation} called before <Toaster /> mounted. Render <Toaster /> once at the root of your app.`,\n );\n }\n return registeredRef.current;\n};\n\nconst getToastProps = ({\n hasNoTimeout: _hasNoTimeout,\n onClose: _onClose,\n topOffset: _topOffset,\n twClassName: _twClassName,\n showCloseButton: _showCloseButton,\n ...toastProps\n}: ToastOptions): Omit<ToastProps, 'twClassName'> => toastProps;\n\nconst getHiddenTranslateY = (height: number, offset: number) =>\n -(height + offset);\n\nconst ToasterComponent = forwardRef<ToasterRef, ToasterProps>(\n ({ twClassName, ...props }, ref) => {\n const tw = useTailwind();\n const [toastOptions, setToastOptions] = useState<ToastOptions | undefined>(\n undefined,\n );\n const replacementTimerRef = useRef<ReturnType<typeof setTimeout> | null>(\n null,\n );\n const autoDismissTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(\n null,\n );\n const animationStartedRef = useRef(false);\n const visibleAtRef = useRef<number | null>(null);\n const hasNoTimeoutRef = useRef(false);\n // Invalidates queued spring-back resumes after replace/dismiss. A completed\n // spring cannot be cancelled, so scheduleOnRN(resume) can still run later.\n const toastGenerationRef = useRef(0);\n const { top: topInset } = useSafeAreaInsets();\n const toastHeight = useSharedValue(screenHeight);\n const hiddenTranslateY = useSharedValue(-screenHeight);\n const visibleTranslateY = useSharedValue(0);\n const gestureStartY = useSharedValue(0);\n const translateYProgress = useSharedValue(-screenHeight);\n const isDismissing = useSharedValue(false);\n // True after onStart until onEnd/onFinalize recovers. Used so a failed pan\n // (e.g. failOffsetX after activation) still springs back and resumes dismiss.\n const isSwipeActive = useSharedValue(false);\n const toastGeneration = useSharedValue(0);\n const topOffset = toastOptions?.topOffset ?? 0;\n hasNoTimeoutRef.current = Boolean(toastOptions?.hasNoTimeout);\n const animatedStyle = useAnimatedStyle(() => ({\n transform: [{ translateY: translateYProgress.value + topOffset }],\n }));\n const baseStyle = useMemo(\n () =>\n [\n tw.style('absolute left-4 right-4 top-0'),\n animatedStyle,\n ] as StyleProp<ViewStyle>,\n [tw, animatedStyle],\n );\n const innerRef = useRef<ToasterRef | null>(null);\n\n const clearScheduledAutoDismiss = () => {\n if (autoDismissTimeoutRef.current !== null) {\n clearTimeout(autoDismissTimeoutRef.current);\n autoDismissTimeoutRef.current = null;\n }\n };\n\n const bumpToastGeneration = () => {\n toastGenerationRef.current += 1;\n toastGeneration.value = toastGenerationRef.current;\n };\n\n const resetState = () => {\n animationStartedRef.current = false;\n visibleAtRef.current = null;\n isDismissing.value = false;\n isSwipeActive.value = false;\n clearScheduledAutoDismiss();\n setToastOptions(undefined);\n };\n\n const startDismissAnimation = () => {\n bumpToastGeneration();\n clearScheduledAutoDismiss();\n isDismissing.value = true;\n visibleAtRef.current = null;\n translateYProgress.value = withSpring(\n hiddenTranslateY.value,\n TOAST_SPRING_CONFIG,\n (finished) => {\n if (finished) {\n scheduleOnRN(resetState);\n }\n },\n );\n };\n\n const scheduleAutoDismiss = (delayMs: number) => {\n clearScheduledAutoDismiss();\n autoDismissTimeoutRef.current = setTimeout(() => {\n autoDismissTimeoutRef.current = null;\n startDismissAnimation();\n }, delayMs);\n };\n\n const beginAutoDismiss = () => {\n visibleAtRef.current = Date.now();\n scheduleAutoDismiss(TOAST_VISIBILITY_DURATION);\n };\n\n const resumeAutoDismissAfterSwipe = () => {\n if (hasNoTimeoutRef.current || isDismissing.value) {\n return;\n }\n\n // Entrance was interrupted before auto-dismiss started — start a full timer.\n if (visibleAtRef.current === null) {\n beginAutoDismiss();\n return;\n }\n\n const elapsed = Date.now() - visibleAtRef.current;\n if (elapsed >= TOAST_VISIBILITY_DURATION) {\n startDismissAnimation();\n return;\n }\n\n scheduleAutoDismiss(TOAST_VISIBILITY_DURATION - elapsed);\n };\n\n const showToast = (options: ToastOptions) => {\n bumpToastGeneration();\n let timeoutDuration = 0;\n const normalizedOptions = {\n hasNoTimeout: false,\n ...options,\n };\n if (toastOptions) {\n // Always clear any pending auto-dismiss from the previous toast, including\n // when the replacement is persistent (hasNoTimeout). Otherwise the old\n // timer can fire and dismiss the new toast.\n clearScheduledAutoDismiss();\n cancelAnimation(translateYProgress);\n timeoutDuration = 100;\n animationStartedRef.current = false;\n visibleAtRef.current = null;\n isDismissing.value = false;\n isSwipeActive.value = false;\n setToastOptions(undefined);\n }\n if (replacementTimerRef.current !== null) {\n clearTimeout(replacementTimerRef.current);\n }\n replacementTimerRef.current = setTimeout(() => {\n replacementTimerRef.current = null;\n setToastOptions(normalizedOptions);\n }, timeoutDuration);\n };\n\n const closeToast = () => {\n if (replacementTimerRef.current !== null) {\n clearTimeout(replacementTimerRef.current);\n replacementTimerRef.current = null;\n }\n startDismissAnimation();\n };\n\n const closeToastRef = useRef(closeToast);\n const resumeAutoDismissAfterSwipeRef = useRef(resumeAutoDismissAfterSwipe);\n const clearScheduledAutoDismissRef = useRef(clearScheduledAutoDismiss);\n closeToastRef.current = closeToast;\n resumeAutoDismissAfterSwipeRef.current = resumeAutoDismissAfterSwipe;\n clearScheduledAutoDismissRef.current = clearScheduledAutoDismiss;\n\n const dismissToastFromSwipe = () => {\n closeToastRef.current();\n };\n\n const resumeAutoDismissFromSwipe = (generation: number) => {\n // Ignore resumes from a toast that was replaced or dismissed after the\n // spring-back started (completed springs cannot be cancelled).\n if (generation !== toastGenerationRef.current) {\n return;\n }\n resumeAutoDismissAfterSwipeRef.current();\n };\n\n const clearScheduledAutoDismissFromSwipe = () => {\n clearScheduledAutoDismissRef.current();\n };\n\n const swipeGesture = useMemo(() => {\n // These gesture callbacks need explicit 'worklet' directives because this\n // package ships a pre-built dist compiled by ts-bridge (tsc), which emits the\n // gesture chain as a namespaced call (react_native_gesture_handler_1.Gesture).\n // The consumer's Reanimated/Worklets Babel plugin does run over dist, but its\n // gesture auto-detection doesn't recognize that compiled namespaced form.\n const springBackAfterSwipe = () => {\n 'worklet';\n\n const generationAtSpringStart = toastGeneration.value;\n translateYProgress.value = withSpring(\n visibleTranslateY.value,\n TOAST_SPRING_CONFIG,\n (finished) => {\n // A new pan cancels this spring via cancelAnimation; only resume\n // auto-dismiss when the spring-back completed naturally.\n if (finished) {\n scheduleOnRN(resumeAutoDismissFromSwipe, generationAtSpringStart);\n }\n },\n );\n };\n\n return Gesture.Pan()\n .activeOffsetY(TOAST_SWIPE_ACTIVE_OFFSET_Y)\n .failOffsetX([-TOAST_SWIPE_FAIL_OFFSET_X, TOAST_SWIPE_FAIL_OFFSET_X])\n .onStart(() => {\n 'worklet';\n\n // Don't interrupt an in-progress dismiss animation.\n if (isDismissing.value) {\n return;\n }\n isSwipeActive.value = true;\n scheduleOnRN(clearScheduledAutoDismissFromSwipe);\n cancelAnimation(translateYProgress);\n gestureStartY.value = translateYProgress.value;\n })\n .onUpdate((event) => {\n 'worklet';\n\n if (isDismissing.value || !isSwipeActive.value) {\n return;\n }\n const nextTranslateY = gestureStartY.value + event.translationY;\n // Toast sits at the top; only allow dragging upward (more negative).\n translateYProgress.value = Math.min(\n nextTranslateY,\n visibleTranslateY.value,\n );\n })\n .onEnd((event) => {\n 'worklet';\n\n if (!isSwipeActive.value) {\n return;\n }\n isSwipeActive.value = false;\n\n if (isDismissing.value) {\n return;\n }\n const { translationY, velocityY } = event;\n const dismissDistance = Math.max(\n toastHeight.value * TOAST_DISMISS_DISTANCE_THRESHOLD,\n TOAST_DISMISS_MIN_DISTANCE,\n );\n const hasReachedDismissOffset = translationY <= -dismissDistance;\n const hasReachedSwipeThreshold =\n Math.abs(velocityY) > TOAST_DISMISS_VELOCITY_THRESHOLD;\n const isQuickDismissing = velocityY < 0;\n\n const shouldDismiss =\n hasReachedDismissOffset ||\n (hasReachedSwipeThreshold && isQuickDismissing);\n\n if (shouldDismiss) {\n scheduleOnRN(dismissToastFromSwipe);\n return;\n }\n\n springBackAfterSwipe();\n })\n .onFinalize(() => {\n 'worklet';\n\n // onEnd is skipped when the pan fails/cancels after activation\n // (e.g. horizontal travel past failOffsetX). Recover position and\n // auto-dismiss so the toast is not left stuck mid-offset.\n if (!isSwipeActive.value) {\n return;\n }\n // Clear before the dismiss check — same order as onEnd — so a pan\n // cancelled mid-dismiss cannot leave isSwipeActive stuck true for a\n // later toast (resetState alone is not enough if finalize races it).\n isSwipeActive.value = false;\n\n if (isDismissing.value) {\n return;\n }\n springBackAfterSwipe();\n });\n // Shared values and swipe JS wrappers are stable for the component lifetime.\n }, []);\n\n innerRef.current = {\n closeToast,\n showToast,\n };\n\n useImperativeHandle(ref, () => innerRef.current as ToasterRef);\n\n useLayoutEffect(() => {\n registeredRef = innerRef;\n return () => {\n if (registeredRef === innerRef) {\n registeredRef = null;\n }\n };\n }, []);\n\n if (!toastOptions) {\n return null;\n }\n\n const {\n onClose: toastOnClose,\n showCloseButton = true,\n twClassName: toastTwClassName,\n } = toastOptions;\n const toastProps = getToastProps(toastOptions);\n const { actionButtonLabel, actionButtonOnPress, ...restToastProps } =\n toastProps;\n const toastTwClassNames = [twClassName, toastTwClassName]\n .filter(Boolean)\n .join(' ');\n const handleClose = showCloseButton\n ? () => {\n closeToast();\n toastOnClose?.();\n }\n : undefined;\n\n const onAnimatedViewLayout = (e: LayoutChangeEvent) => {\n const { height } = e.nativeEvent.layout;\n const nextHiddenTranslateY = getHiddenTranslateY(height, topOffset);\n const nextVisibleTranslateY = topInset + TOAST_TOP_PADDING;\n\n hiddenTranslateY.value = nextHiddenTranslateY;\n visibleTranslateY.value = nextVisibleTranslateY;\n toastHeight.value = height;\n\n if (animationStartedRef.current) {\n return;\n }\n\n animationStartedRef.current = true;\n translateYProgress.value = nextHiddenTranslateY;\n\n if (toastOptions.hasNoTimeout) {\n translateYProgress.value = withSpring(\n nextVisibleTranslateY,\n TOAST_SPRING_CONFIG,\n );\n } else {\n translateYProgress.value = withSpring(\n nextVisibleTranslateY,\n TOAST_SPRING_CONFIG,\n (finished) => {\n if (finished) {\n scheduleOnRN(beginAutoDismiss);\n }\n },\n );\n }\n };\n\n return (\n <GestureDetector gesture={swipeGesture}>\n <Animated.View\n onLayout={onAnimatedViewLayout}\n style={baseStyle}\n {...props}\n >\n {actionButtonLabel && actionButtonOnPress ? (\n <Toast\n {...toastProps}\n actionButtonLabel={actionButtonLabel}\n actionButtonOnPress={actionButtonOnPress}\n onClose={handleClose}\n twClassName={toastTwClassNames}\n />\n ) : (\n <Toast\n {...restToastProps}\n onClose={handleClose}\n twClassName={toastTwClassNames}\n />\n )}\n </Animated.View>\n </GestureDetector>\n );\n },\n);\n\nToasterComponent.displayName = 'Toaster';\n\ntype ToastFunction = ((options: ToastOptions) => void) & {\n dismiss: () => void;\n};\n\nexport const Toaster = ToasterComponent;\n\nexport const toast = ((options: ToastOptions) => {\n assertRegisteredRef('toast').showToast(options);\n}) as ToastFunction;\n\ntoast.dismiss = () => {\n assertRegisteredRef('dismiss').closeToast();\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toaster.d.cts","sourceRoot":"","sources":["../../../src/components/Toast/Toaster.tsx"],"names":[],"mappings":"AAEA,OAAO,KAON,cAAc;AA0Bf,OAAO,KAAK,EACV,YAAY,EAGZ,UAAU,EACX,0BAAsB;
|
|
1
|
+
{"version":3,"file":"Toaster.d.cts","sourceRoot":"","sources":["../../../src/components/Toast/Toaster.tsx"],"names":[],"mappings":"AAEA,OAAO,KAON,cAAc;AA0Bf,OAAO,KAAK,EACV,YAAY,EAGZ,UAAU,EACX,0BAAsB;AA0ZvB,KAAK,aAAa,GAAG,CAAC,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC,GAAG;IACvD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,OAAO;;sFAAmB,CAAC;AAExC,eAAO,MAAM,KAAK,eAEC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toaster.d.mts","sourceRoot":"","sources":["../../../src/components/Toast/Toaster.tsx"],"names":[],"mappings":"AAEA,OAAO,KAON,cAAc;AA0Bf,OAAO,KAAK,EACV,YAAY,EAGZ,UAAU,EACX,0BAAsB;
|
|
1
|
+
{"version":3,"file":"Toaster.d.mts","sourceRoot":"","sources":["../../../src/components/Toast/Toaster.tsx"],"names":[],"mappings":"AAEA,OAAO,KAON,cAAc;AA0Bf,OAAO,KAAK,EACV,YAAY,EAGZ,UAAU,EACX,0BAAsB;AA0ZvB,KAAK,aAAa,GAAG,CAAC,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC,GAAG;IACvD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,OAAO;;sFAAmB,CAAC;AAExC,eAAO,MAAM,KAAK,eAEC,CAAC"}
|
|
@@ -25,7 +25,7 @@ const assertRegisteredRef = (method) => {
|
|
|
25
25
|
}
|
|
26
26
|
return registeredRef.current;
|
|
27
27
|
};
|
|
28
|
-
const getToastProps = ({ hasNoTimeout: _hasNoTimeout, onClose: _onClose, topOffset: _topOffset, twClassName: _twClassName, ...toastProps }) => toastProps;
|
|
28
|
+
const getToastProps = ({ hasNoTimeout: _hasNoTimeout, onClose: _onClose, topOffset: _topOffset, twClassName: _twClassName, showCloseButton: _showCloseButton, ...toastProps }) => toastProps;
|
|
29
29
|
const getHiddenTranslateY = (height, offset) => -(height + offset);
|
|
30
30
|
const ToasterComponent = forwardRef(({ twClassName, ...props }, ref) => {
|
|
31
31
|
const tw = useTailwind();
|
|
@@ -267,12 +267,18 @@ const ToasterComponent = forwardRef(({ twClassName, ...props }, ref) => {
|
|
|
267
267
|
if (!toastOptions) {
|
|
268
268
|
return null;
|
|
269
269
|
}
|
|
270
|
-
const { onClose: toastOnClose, twClassName: toastTwClassName } = toastOptions;
|
|
270
|
+
const { onClose: toastOnClose, showCloseButton = true, twClassName: toastTwClassName, } = toastOptions;
|
|
271
271
|
const toastProps = getToastProps(toastOptions);
|
|
272
272
|
const { actionButtonLabel, actionButtonOnPress, ...restToastProps } = toastProps;
|
|
273
273
|
const toastTwClassNames = [twClassName, toastTwClassName]
|
|
274
274
|
.filter(Boolean)
|
|
275
275
|
.join(' ');
|
|
276
|
+
const handleClose = showCloseButton
|
|
277
|
+
? () => {
|
|
278
|
+
closeToast();
|
|
279
|
+
toastOnClose?.();
|
|
280
|
+
}
|
|
281
|
+
: undefined;
|
|
276
282
|
const onAnimatedViewLayout = (e) => {
|
|
277
283
|
const { height } = e.nativeEvent.layout;
|
|
278
284
|
const nextHiddenTranslateY = getHiddenTranslateY(height, topOffset);
|
|
@@ -298,13 +304,7 @@ const ToasterComponent = forwardRef(({ twClassName, ...props }, ref) => {
|
|
|
298
304
|
};
|
|
299
305
|
return (<GestureDetector gesture={swipeGesture}>
|
|
300
306
|
<Animated.View onLayout={onAnimatedViewLayout} style={baseStyle} {...props}>
|
|
301
|
-
{actionButtonLabel && actionButtonOnPress ? (<Toast {...toastProps} actionButtonLabel={actionButtonLabel} actionButtonOnPress={actionButtonOnPress} onClose={
|
|
302
|
-
closeToast();
|
|
303
|
-
toastOnClose?.();
|
|
304
|
-
}} twClassName={toastTwClassNames}/>) : (<Toast {...restToastProps} onClose={() => {
|
|
305
|
-
closeToast();
|
|
306
|
-
toastOnClose?.();
|
|
307
|
-
}} twClassName={toastTwClassNames}/>)}
|
|
307
|
+
{actionButtonLabel && actionButtonOnPress ? (<Toast {...toastProps} actionButtonLabel={actionButtonLabel} actionButtonOnPress={actionButtonOnPress} onClose={handleClose} twClassName={toastTwClassNames}/>) : (<Toast {...restToastProps} onClose={handleClose} twClassName={toastTwClassNames}/>)}
|
|
308
308
|
</Animated.View>
|
|
309
309
|
</GestureDetector>);
|
|
310
310
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toaster.mjs","sourceRoot":"","sources":["../../../src/components/Toast/Toaster.tsx"],"names":[],"mappings":";;;;;;AAAA,4BAA4B;AAC5B,OAAO,EAAE,WAAW,EAAE,6CAA6C;AACnE,OAAO,QAAO,EACZ,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,MAAM,EACN,QAAQ,EACT,cAAc;;AAEf,OAAO,EAAE,UAAU,EAAE,qBAAqB;AAE1C,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,qCAAqC;AACxE,OAAO,QAAQ,EAAE,E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;YACnB,CAAC,CAAC,CACF,WAAW,CAAC,CAAC,iBAAiB,CAAC,EAC/B,CACH,CAAC,CAAC,CAAC,CACF,CAAC,KAAK,CACJ,IAAI,cAAc,CAAC,CACnB,OAAO,CAAC,CAAC,GAAG,EAAE;gBACZ,UAAU,EAAE,CAAC;gBACb,YAAY,EAAE,EAAE,CAAC;YACnB,CAAC,CAAC,CACF,WAAW,CAAC,CAAC,iBAAiB,CAAC,EAC/B,CACH,CACH;QAAA,EAAE,QAAQ,CAAC,IAAI,CACjB;MAAA,EAAE,eAAe,CAAC,CACnB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,gBAAgB,CAAC,WAAW,GAAG,SAAS,CAAC;AAMzC,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC;AAExC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,OAAqB,EAAE,EAAE;IAC9C,mBAAmB,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AAClD,CAAC,CAAkB,CAAC;AAEpB,KAAK,CAAC,OAAO,GAAG,GAAG,EAAE;IACnB,mBAAmB,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;AAC9C,CAAC,CAAC","sourcesContent":["// Third party dependencies.\nimport { useTailwind } from '@metamask/design-system-twrnc-preset';\nimport React, {\n forwardRef,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport type { RefObject } from 'react';\nimport { Dimensions } from 'react-native';\nimport type { LayoutChangeEvent, StyleProp, ViewStyle } from 'react-native';\nimport { Gesture, GestureDetector } from 'react-native-gesture-handler';\nimport Animated, {\n cancelAnimation,\n useAnimatedStyle,\n useSharedValue,\n withSpring,\n} from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport { scheduleOnRN } from 'react-native-worklets';\n\n// Internal dependencies.\nimport { Toast } from './Toast';\nimport {\n TOAST_DISMISS_DISTANCE_THRESHOLD,\n TOAST_DISMISS_MIN_DISTANCE,\n TOAST_DISMISS_VELOCITY_THRESHOLD,\n TOAST_SPRING_CONFIG,\n TOAST_SWIPE_ACTIVE_OFFSET_Y,\n TOAST_SWIPE_FAIL_OFFSET_X,\n TOAST_TOP_PADDING,\n TOAST_VISIBILITY_DURATION,\n} from './Toast.constants';\nimport type {\n ToastOptions,\n ToastProps,\n ToasterProps,\n ToasterRef,\n} from './Toast.types';\n\nconst screenHeight = Dimensions.get('window').height;\n\nlet registeredRef: RefObject<ToasterRef | null> | null = null;\n\nconst assertRegisteredRef = (method: 'dismiss' | 'toast'): ToasterRef => {\n if (!registeredRef?.current) {\n const invocation = method === 'toast' ? 'toast()' : `toast.${method}()`;\n throw new Error(\n `${invocation} called before <Toaster /> mounted. Render <Toaster /> once at the root of your app.`,\n );\n }\n return registeredRef.current;\n};\n\nconst getToastProps = ({\n hasNoTimeout: _hasNoTimeout,\n onClose: _onClose,\n topOffset: _topOffset,\n twClassName: _twClassName,\n ...toastProps\n}: ToastOptions): Omit<ToastProps, 'twClassName'> => toastProps;\n\nconst getHiddenTranslateY = (height: number, offset: number) =>\n -(height + offset);\n\nconst ToasterComponent = forwardRef<ToasterRef, ToasterProps>(\n ({ twClassName, ...props }, ref) => {\n const tw = useTailwind();\n const [toastOptions, setToastOptions] = useState<ToastOptions | undefined>(\n undefined,\n );\n const replacementTimerRef = useRef<ReturnType<typeof setTimeout> | null>(\n null,\n );\n const autoDismissTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(\n null,\n );\n const animationStartedRef = useRef(false);\n const visibleAtRef = useRef<number | null>(null);\n const hasNoTimeoutRef = useRef(false);\n // Invalidates queued spring-back resumes after replace/dismiss. A completed\n // spring cannot be cancelled, so scheduleOnRN(resume) can still run later.\n const toastGenerationRef = useRef(0);\n const { top: topInset } = useSafeAreaInsets();\n const toastHeight = useSharedValue(screenHeight);\n const hiddenTranslateY = useSharedValue(-screenHeight);\n const visibleTranslateY = useSharedValue(0);\n const gestureStartY = useSharedValue(0);\n const translateYProgress = useSharedValue(-screenHeight);\n const isDismissing = useSharedValue(false);\n // True after onStart until onEnd/onFinalize recovers. Used so a failed pan\n // (e.g. failOffsetX after activation) still springs back and resumes dismiss.\n const isSwipeActive = useSharedValue(false);\n const toastGeneration = useSharedValue(0);\n const topOffset = toastOptions?.topOffset ?? 0;\n hasNoTimeoutRef.current = Boolean(toastOptions?.hasNoTimeout);\n const animatedStyle = useAnimatedStyle(() => ({\n transform: [{ translateY: translateYProgress.value + topOffset }],\n }));\n const baseStyle = useMemo(\n () =>\n [\n tw.style('absolute left-4 right-4 top-0'),\n animatedStyle,\n ] as StyleProp<ViewStyle>,\n [tw, animatedStyle],\n );\n const innerRef = useRef<ToasterRef | null>(null);\n\n const clearScheduledAutoDismiss = () => {\n if (autoDismissTimeoutRef.current !== null) {\n clearTimeout(autoDismissTimeoutRef.current);\n autoDismissTimeoutRef.current = null;\n }\n };\n\n const bumpToastGeneration = () => {\n toastGenerationRef.current += 1;\n toastGeneration.value = toastGenerationRef.current;\n };\n\n const resetState = () => {\n animationStartedRef.current = false;\n visibleAtRef.current = null;\n isDismissing.value = false;\n isSwipeActive.value = false;\n clearScheduledAutoDismiss();\n setToastOptions(undefined);\n };\n\n const startDismissAnimation = () => {\n bumpToastGeneration();\n clearScheduledAutoDismiss();\n isDismissing.value = true;\n visibleAtRef.current = null;\n translateYProgress.value = withSpring(\n hiddenTranslateY.value,\n TOAST_SPRING_CONFIG,\n (finished) => {\n if (finished) {\n scheduleOnRN(resetState);\n }\n },\n );\n };\n\n const scheduleAutoDismiss = (delayMs: number) => {\n clearScheduledAutoDismiss();\n autoDismissTimeoutRef.current = setTimeout(() => {\n autoDismissTimeoutRef.current = null;\n startDismissAnimation();\n }, delayMs);\n };\n\n const beginAutoDismiss = () => {\n visibleAtRef.current = Date.now();\n scheduleAutoDismiss(TOAST_VISIBILITY_DURATION);\n };\n\n const resumeAutoDismissAfterSwipe = () => {\n if (hasNoTimeoutRef.current || isDismissing.value) {\n return;\n }\n\n // Entrance was interrupted before auto-dismiss started — start a full timer.\n if (visibleAtRef.current === null) {\n beginAutoDismiss();\n return;\n }\n\n const elapsed = Date.now() - visibleAtRef.current;\n if (elapsed >= TOAST_VISIBILITY_DURATION) {\n startDismissAnimation();\n return;\n }\n\n scheduleAutoDismiss(TOAST_VISIBILITY_DURATION - elapsed);\n };\n\n const showToast = (options: ToastOptions) => {\n bumpToastGeneration();\n let timeoutDuration = 0;\n const normalizedOptions = {\n hasNoTimeout: false,\n ...options,\n };\n if (toastOptions) {\n // Always clear any pending auto-dismiss from the previous toast, including\n // when the replacement is persistent (hasNoTimeout). Otherwise the old\n // timer can fire and dismiss the new toast.\n clearScheduledAutoDismiss();\n cancelAnimation(translateYProgress);\n timeoutDuration = 100;\n animationStartedRef.current = false;\n visibleAtRef.current = null;\n isDismissing.value = false;\n isSwipeActive.value = false;\n setToastOptions(undefined);\n }\n if (replacementTimerRef.current !== null) {\n clearTimeout(replacementTimerRef.current);\n }\n replacementTimerRef.current = setTimeout(() => {\n replacementTimerRef.current = null;\n setToastOptions(normalizedOptions);\n }, timeoutDuration);\n };\n\n const closeToast = () => {\n if (replacementTimerRef.current !== null) {\n clearTimeout(replacementTimerRef.current);\n replacementTimerRef.current = null;\n }\n startDismissAnimation();\n };\n\n const closeToastRef = useRef(closeToast);\n const resumeAutoDismissAfterSwipeRef = useRef(resumeAutoDismissAfterSwipe);\n const clearScheduledAutoDismissRef = useRef(clearScheduledAutoDismiss);\n closeToastRef.current = closeToast;\n resumeAutoDismissAfterSwipeRef.current = resumeAutoDismissAfterSwipe;\n clearScheduledAutoDismissRef.current = clearScheduledAutoDismiss;\n\n const dismissToastFromSwipe = () => {\n closeToastRef.current();\n };\n\n const resumeAutoDismissFromSwipe = (generation: number) => {\n // Ignore resumes from a toast that was replaced or dismissed after the\n // spring-back started (completed springs cannot be cancelled).\n if (generation !== toastGenerationRef.current) {\n return;\n }\n resumeAutoDismissAfterSwipeRef.current();\n };\n\n const clearScheduledAutoDismissFromSwipe = () => {\n clearScheduledAutoDismissRef.current();\n };\n\n const swipeGesture = useMemo(() => {\n // These gesture callbacks need explicit 'worklet' directives because this\n // package ships a pre-built dist compiled by ts-bridge (tsc), which emits the\n // gesture chain as a namespaced call (react_native_gesture_handler_1.Gesture).\n // The consumer's Reanimated/Worklets Babel plugin does run over dist, but its\n // gesture auto-detection doesn't recognize that compiled namespaced form.\n const springBackAfterSwipe = () => {\n 'worklet';\n\n const generationAtSpringStart = toastGeneration.value;\n translateYProgress.value = withSpring(\n visibleTranslateY.value,\n TOAST_SPRING_CONFIG,\n (finished) => {\n // A new pan cancels this spring via cancelAnimation; only resume\n // auto-dismiss when the spring-back completed naturally.\n if (finished) {\n scheduleOnRN(resumeAutoDismissFromSwipe, generationAtSpringStart);\n }\n },\n );\n };\n\n return Gesture.Pan()\n .activeOffsetY(TOAST_SWIPE_ACTIVE_OFFSET_Y)\n .failOffsetX([-TOAST_SWIPE_FAIL_OFFSET_X, TOAST_SWIPE_FAIL_OFFSET_X])\n .onStart(() => {\n 'worklet';\n\n // Don't interrupt an in-progress dismiss animation.\n if (isDismissing.value) {\n return;\n }\n isSwipeActive.value = true;\n scheduleOnRN(clearScheduledAutoDismissFromSwipe);\n cancelAnimation(translateYProgress);\n gestureStartY.value = translateYProgress.value;\n })\n .onUpdate((event) => {\n 'worklet';\n\n if (isDismissing.value || !isSwipeActive.value) {\n return;\n }\n const nextTranslateY = gestureStartY.value + event.translationY;\n // Toast sits at the top; only allow dragging upward (more negative).\n translateYProgress.value = Math.min(\n nextTranslateY,\n visibleTranslateY.value,\n );\n })\n .onEnd((event) => {\n 'worklet';\n\n if (!isSwipeActive.value) {\n return;\n }\n isSwipeActive.value = false;\n\n if (isDismissing.value) {\n return;\n }\n const { translationY, velocityY } = event;\n const dismissDistance = Math.max(\n toastHeight.value * TOAST_DISMISS_DISTANCE_THRESHOLD,\n TOAST_DISMISS_MIN_DISTANCE,\n );\n const hasReachedDismissOffset = translationY <= -dismissDistance;\n const hasReachedSwipeThreshold =\n Math.abs(velocityY) > TOAST_DISMISS_VELOCITY_THRESHOLD;\n const isQuickDismissing = velocityY < 0;\n\n const shouldDismiss =\n hasReachedDismissOffset ||\n (hasReachedSwipeThreshold && isQuickDismissing);\n\n if (shouldDismiss) {\n scheduleOnRN(dismissToastFromSwipe);\n return;\n }\n\n springBackAfterSwipe();\n })\n .onFinalize(() => {\n 'worklet';\n\n // onEnd is skipped when the pan fails/cancels after activation\n // (e.g. horizontal travel past failOffsetX). Recover position and\n // auto-dismiss so the toast is not left stuck mid-offset.\n if (!isSwipeActive.value) {\n return;\n }\n // Clear before the dismiss check — same order as onEnd — so a pan\n // cancelled mid-dismiss cannot leave isSwipeActive stuck true for a\n // later toast (resetState alone is not enough if finalize races it).\n isSwipeActive.value = false;\n\n if (isDismissing.value) {\n return;\n }\n springBackAfterSwipe();\n });\n // Shared values and swipe JS wrappers are stable for the component lifetime.\n }, []);\n\n innerRef.current = {\n closeToast,\n showToast,\n };\n\n useImperativeHandle(ref, () => innerRef.current as ToasterRef);\n\n useLayoutEffect(() => {\n registeredRef = innerRef;\n return () => {\n if (registeredRef === innerRef) {\n registeredRef = null;\n }\n };\n }, []);\n\n if (!toastOptions) {\n return null;\n }\n\n const { onClose: toastOnClose, twClassName: toastTwClassName } =\n toastOptions;\n const toastProps = getToastProps(toastOptions);\n const { actionButtonLabel, actionButtonOnPress, ...restToastProps } =\n toastProps;\n const toastTwClassNames = [twClassName, toastTwClassName]\n .filter(Boolean)\n .join(' ');\n\n const onAnimatedViewLayout = (e: LayoutChangeEvent) => {\n const { height } = e.nativeEvent.layout;\n const nextHiddenTranslateY = getHiddenTranslateY(height, topOffset);\n const nextVisibleTranslateY = topInset + TOAST_TOP_PADDING;\n\n hiddenTranslateY.value = nextHiddenTranslateY;\n visibleTranslateY.value = nextVisibleTranslateY;\n toastHeight.value = height;\n\n if (animationStartedRef.current) {\n return;\n }\n\n animationStartedRef.current = true;\n translateYProgress.value = nextHiddenTranslateY;\n\n if (toastOptions.hasNoTimeout) {\n translateYProgress.value = withSpring(\n nextVisibleTranslateY,\n TOAST_SPRING_CONFIG,\n );\n } else {\n translateYProgress.value = withSpring(\n nextVisibleTranslateY,\n TOAST_SPRING_CONFIG,\n (finished) => {\n if (finished) {\n scheduleOnRN(beginAutoDismiss);\n }\n },\n );\n }\n };\n\n return (\n <GestureDetector gesture={swipeGesture}>\n <Animated.View\n onLayout={onAnimatedViewLayout}\n style={baseStyle}\n {...props}\n >\n {actionButtonLabel && actionButtonOnPress ? (\n <Toast\n {...toastProps}\n actionButtonLabel={actionButtonLabel}\n actionButtonOnPress={actionButtonOnPress}\n onClose={() => {\n closeToast();\n toastOnClose?.();\n }}\n twClassName={toastTwClassNames}\n />\n ) : (\n <Toast\n {...restToastProps}\n onClose={() => {\n closeToast();\n toastOnClose?.();\n }}\n twClassName={toastTwClassNames}\n />\n )}\n </Animated.View>\n </GestureDetector>\n );\n },\n);\n\nToasterComponent.displayName = 'Toaster';\n\ntype ToastFunction = ((options: ToastOptions) => void) & {\n dismiss: () => void;\n};\n\nexport const Toaster = ToasterComponent;\n\nexport const toast = ((options: ToastOptions) => {\n assertRegisteredRef('toast').showToast(options);\n}) as ToastFunction;\n\ntoast.dismiss = () => {\n assertRegisteredRef('dismiss').closeToast();\n};\n"]}
|
|
1
|
+
{"version":3,"file":"Toaster.mjs","sourceRoot":"","sources":["../../../src/components/Toast/Toaster.tsx"],"names":[],"mappings":";;;;;;AAAA,4BAA4B;AAC5B,OAAO,EAAE,WAAW,EAAE,6CAA6C;AACnE,OAAO,QAAO,EACZ,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,MAAM,EACN,QAAQ,EACT,cAAc;;AAEf,OAAO,EAAE,UAAU,EAAE,qBAAqB;AAE1C,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,qCAAqC;AACxE,OAAO,QAAQ,EAAE,EACf,eAAe,EACf,gBAAgB,EAChB,cA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,CACf,iBAAiB,CAAC,CAAC,iBAAiB,CAAC,CACrC,mBAAmB,CAAC,CAAC,mBAAmB,CAAC,CACzC,OAAO,CAAC,CAAC,WAAW,CAAC,CACrB,WAAW,CAAC,CAAC,iBAAiB,CAAC,EAC/B,CACH,CAAC,CAAC,CAAC,CACF,CAAC,KAAK,CACJ,IAAI,cAAc,CAAC,CACnB,OAAO,CAAC,CAAC,WAAW,CAAC,CACrB,WAAW,CAAC,CAAC,iBAAiB,CAAC,EAC/B,CACH,CACH;QAAA,EAAE,QAAQ,CAAC,IAAI,CACjB;MAAA,EAAE,eAAe,CAAC,CACnB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,gBAAgB,CAAC,WAAW,GAAG,SAAS,CAAC;AAMzC,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC;AAExC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,OAAqB,EAAE,EAAE;IAC9C,mBAAmB,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AAClD,CAAC,CAAkB,CAAC;AAEpB,KAAK,CAAC,OAAO,GAAG,GAAG,EAAE;IACnB,mBAAmB,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;AAC9C,CAAC,CAAC","sourcesContent":["// Third party dependencies.\nimport { useTailwind } from '@metamask/design-system-twrnc-preset';\nimport React, {\n forwardRef,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport type { RefObject } from 'react';\nimport { Dimensions } from 'react-native';\nimport type { LayoutChangeEvent, StyleProp, ViewStyle } from 'react-native';\nimport { Gesture, GestureDetector } from 'react-native-gesture-handler';\nimport Animated, {\n cancelAnimation,\n useAnimatedStyle,\n useSharedValue,\n withSpring,\n} from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport { scheduleOnRN } from 'react-native-worklets';\n\n// Internal dependencies.\nimport { Toast } from './Toast';\nimport {\n TOAST_DISMISS_DISTANCE_THRESHOLD,\n TOAST_DISMISS_MIN_DISTANCE,\n TOAST_DISMISS_VELOCITY_THRESHOLD,\n TOAST_SPRING_CONFIG,\n TOAST_SWIPE_ACTIVE_OFFSET_Y,\n TOAST_SWIPE_FAIL_OFFSET_X,\n TOAST_TOP_PADDING,\n TOAST_VISIBILITY_DURATION,\n} from './Toast.constants';\nimport type {\n ToastOptions,\n ToastProps,\n ToasterProps,\n ToasterRef,\n} from './Toast.types';\n\nconst screenHeight = Dimensions.get('window').height;\n\nlet registeredRef: RefObject<ToasterRef | null> | null = null;\n\nconst assertRegisteredRef = (method: 'dismiss' | 'toast'): ToasterRef => {\n if (!registeredRef?.current) {\n const invocation = method === 'toast' ? 'toast()' : `toast.${method}()`;\n throw new Error(\n `${invocation} called before <Toaster /> mounted. Render <Toaster /> once at the root of your app.`,\n );\n }\n return registeredRef.current;\n};\n\nconst getToastProps = ({\n hasNoTimeout: _hasNoTimeout,\n onClose: _onClose,\n topOffset: _topOffset,\n twClassName: _twClassName,\n showCloseButton: _showCloseButton,\n ...toastProps\n}: ToastOptions): Omit<ToastProps, 'twClassName'> => toastProps;\n\nconst getHiddenTranslateY = (height: number, offset: number) =>\n -(height + offset);\n\nconst ToasterComponent = forwardRef<ToasterRef, ToasterProps>(\n ({ twClassName, ...props }, ref) => {\n const tw = useTailwind();\n const [toastOptions, setToastOptions] = useState<ToastOptions | undefined>(\n undefined,\n );\n const replacementTimerRef = useRef<ReturnType<typeof setTimeout> | null>(\n null,\n );\n const autoDismissTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(\n null,\n );\n const animationStartedRef = useRef(false);\n const visibleAtRef = useRef<number | null>(null);\n const hasNoTimeoutRef = useRef(false);\n // Invalidates queued spring-back resumes after replace/dismiss. A completed\n // spring cannot be cancelled, so scheduleOnRN(resume) can still run later.\n const toastGenerationRef = useRef(0);\n const { top: topInset } = useSafeAreaInsets();\n const toastHeight = useSharedValue(screenHeight);\n const hiddenTranslateY = useSharedValue(-screenHeight);\n const visibleTranslateY = useSharedValue(0);\n const gestureStartY = useSharedValue(0);\n const translateYProgress = useSharedValue(-screenHeight);\n const isDismissing = useSharedValue(false);\n // True after onStart until onEnd/onFinalize recovers. Used so a failed pan\n // (e.g. failOffsetX after activation) still springs back and resumes dismiss.\n const isSwipeActive = useSharedValue(false);\n const toastGeneration = useSharedValue(0);\n const topOffset = toastOptions?.topOffset ?? 0;\n hasNoTimeoutRef.current = Boolean(toastOptions?.hasNoTimeout);\n const animatedStyle = useAnimatedStyle(() => ({\n transform: [{ translateY: translateYProgress.value + topOffset }],\n }));\n const baseStyle = useMemo(\n () =>\n [\n tw.style('absolute left-4 right-4 top-0'),\n animatedStyle,\n ] as StyleProp<ViewStyle>,\n [tw, animatedStyle],\n );\n const innerRef = useRef<ToasterRef | null>(null);\n\n const clearScheduledAutoDismiss = () => {\n if (autoDismissTimeoutRef.current !== null) {\n clearTimeout(autoDismissTimeoutRef.current);\n autoDismissTimeoutRef.current = null;\n }\n };\n\n const bumpToastGeneration = () => {\n toastGenerationRef.current += 1;\n toastGeneration.value = toastGenerationRef.current;\n };\n\n const resetState = () => {\n animationStartedRef.current = false;\n visibleAtRef.current = null;\n isDismissing.value = false;\n isSwipeActive.value = false;\n clearScheduledAutoDismiss();\n setToastOptions(undefined);\n };\n\n const startDismissAnimation = () => {\n bumpToastGeneration();\n clearScheduledAutoDismiss();\n isDismissing.value = true;\n visibleAtRef.current = null;\n translateYProgress.value = withSpring(\n hiddenTranslateY.value,\n TOAST_SPRING_CONFIG,\n (finished) => {\n if (finished) {\n scheduleOnRN(resetState);\n }\n },\n );\n };\n\n const scheduleAutoDismiss = (delayMs: number) => {\n clearScheduledAutoDismiss();\n autoDismissTimeoutRef.current = setTimeout(() => {\n autoDismissTimeoutRef.current = null;\n startDismissAnimation();\n }, delayMs);\n };\n\n const beginAutoDismiss = () => {\n visibleAtRef.current = Date.now();\n scheduleAutoDismiss(TOAST_VISIBILITY_DURATION);\n };\n\n const resumeAutoDismissAfterSwipe = () => {\n if (hasNoTimeoutRef.current || isDismissing.value) {\n return;\n }\n\n // Entrance was interrupted before auto-dismiss started — start a full timer.\n if (visibleAtRef.current === null) {\n beginAutoDismiss();\n return;\n }\n\n const elapsed = Date.now() - visibleAtRef.current;\n if (elapsed >= TOAST_VISIBILITY_DURATION) {\n startDismissAnimation();\n return;\n }\n\n scheduleAutoDismiss(TOAST_VISIBILITY_DURATION - elapsed);\n };\n\n const showToast = (options: ToastOptions) => {\n bumpToastGeneration();\n let timeoutDuration = 0;\n const normalizedOptions = {\n hasNoTimeout: false,\n ...options,\n };\n if (toastOptions) {\n // Always clear any pending auto-dismiss from the previous toast, including\n // when the replacement is persistent (hasNoTimeout). Otherwise the old\n // timer can fire and dismiss the new toast.\n clearScheduledAutoDismiss();\n cancelAnimation(translateYProgress);\n timeoutDuration = 100;\n animationStartedRef.current = false;\n visibleAtRef.current = null;\n isDismissing.value = false;\n isSwipeActive.value = false;\n setToastOptions(undefined);\n }\n if (replacementTimerRef.current !== null) {\n clearTimeout(replacementTimerRef.current);\n }\n replacementTimerRef.current = setTimeout(() => {\n replacementTimerRef.current = null;\n setToastOptions(normalizedOptions);\n }, timeoutDuration);\n };\n\n const closeToast = () => {\n if (replacementTimerRef.current !== null) {\n clearTimeout(replacementTimerRef.current);\n replacementTimerRef.current = null;\n }\n startDismissAnimation();\n };\n\n const closeToastRef = useRef(closeToast);\n const resumeAutoDismissAfterSwipeRef = useRef(resumeAutoDismissAfterSwipe);\n const clearScheduledAutoDismissRef = useRef(clearScheduledAutoDismiss);\n closeToastRef.current = closeToast;\n resumeAutoDismissAfterSwipeRef.current = resumeAutoDismissAfterSwipe;\n clearScheduledAutoDismissRef.current = clearScheduledAutoDismiss;\n\n const dismissToastFromSwipe = () => {\n closeToastRef.current();\n };\n\n const resumeAutoDismissFromSwipe = (generation: number) => {\n // Ignore resumes from a toast that was replaced or dismissed after the\n // spring-back started (completed springs cannot be cancelled).\n if (generation !== toastGenerationRef.current) {\n return;\n }\n resumeAutoDismissAfterSwipeRef.current();\n };\n\n const clearScheduledAutoDismissFromSwipe = () => {\n clearScheduledAutoDismissRef.current();\n };\n\n const swipeGesture = useMemo(() => {\n // These gesture callbacks need explicit 'worklet' directives because this\n // package ships a pre-built dist compiled by ts-bridge (tsc), which emits the\n // gesture chain as a namespaced call (react_native_gesture_handler_1.Gesture).\n // The consumer's Reanimated/Worklets Babel plugin does run over dist, but its\n // gesture auto-detection doesn't recognize that compiled namespaced form.\n const springBackAfterSwipe = () => {\n 'worklet';\n\n const generationAtSpringStart = toastGeneration.value;\n translateYProgress.value = withSpring(\n visibleTranslateY.value,\n TOAST_SPRING_CONFIG,\n (finished) => {\n // A new pan cancels this spring via cancelAnimation; only resume\n // auto-dismiss when the spring-back completed naturally.\n if (finished) {\n scheduleOnRN(resumeAutoDismissFromSwipe, generationAtSpringStart);\n }\n },\n );\n };\n\n return Gesture.Pan()\n .activeOffsetY(TOAST_SWIPE_ACTIVE_OFFSET_Y)\n .failOffsetX([-TOAST_SWIPE_FAIL_OFFSET_X, TOAST_SWIPE_FAIL_OFFSET_X])\n .onStart(() => {\n 'worklet';\n\n // Don't interrupt an in-progress dismiss animation.\n if (isDismissing.value) {\n return;\n }\n isSwipeActive.value = true;\n scheduleOnRN(clearScheduledAutoDismissFromSwipe);\n cancelAnimation(translateYProgress);\n gestureStartY.value = translateYProgress.value;\n })\n .onUpdate((event) => {\n 'worklet';\n\n if (isDismissing.value || !isSwipeActive.value) {\n return;\n }\n const nextTranslateY = gestureStartY.value + event.translationY;\n // Toast sits at the top; only allow dragging upward (more negative).\n translateYProgress.value = Math.min(\n nextTranslateY,\n visibleTranslateY.value,\n );\n })\n .onEnd((event) => {\n 'worklet';\n\n if (!isSwipeActive.value) {\n return;\n }\n isSwipeActive.value = false;\n\n if (isDismissing.value) {\n return;\n }\n const { translationY, velocityY } = event;\n const dismissDistance = Math.max(\n toastHeight.value * TOAST_DISMISS_DISTANCE_THRESHOLD,\n TOAST_DISMISS_MIN_DISTANCE,\n );\n const hasReachedDismissOffset = translationY <= -dismissDistance;\n const hasReachedSwipeThreshold =\n Math.abs(velocityY) > TOAST_DISMISS_VELOCITY_THRESHOLD;\n const isQuickDismissing = velocityY < 0;\n\n const shouldDismiss =\n hasReachedDismissOffset ||\n (hasReachedSwipeThreshold && isQuickDismissing);\n\n if (shouldDismiss) {\n scheduleOnRN(dismissToastFromSwipe);\n return;\n }\n\n springBackAfterSwipe();\n })\n .onFinalize(() => {\n 'worklet';\n\n // onEnd is skipped when the pan fails/cancels after activation\n // (e.g. horizontal travel past failOffsetX). Recover position and\n // auto-dismiss so the toast is not left stuck mid-offset.\n if (!isSwipeActive.value) {\n return;\n }\n // Clear before the dismiss check — same order as onEnd — so a pan\n // cancelled mid-dismiss cannot leave isSwipeActive stuck true for a\n // later toast (resetState alone is not enough if finalize races it).\n isSwipeActive.value = false;\n\n if (isDismissing.value) {\n return;\n }\n springBackAfterSwipe();\n });\n // Shared values and swipe JS wrappers are stable for the component lifetime.\n }, []);\n\n innerRef.current = {\n closeToast,\n showToast,\n };\n\n useImperativeHandle(ref, () => innerRef.current as ToasterRef);\n\n useLayoutEffect(() => {\n registeredRef = innerRef;\n return () => {\n if (registeredRef === innerRef) {\n registeredRef = null;\n }\n };\n }, []);\n\n if (!toastOptions) {\n return null;\n }\n\n const {\n onClose: toastOnClose,\n showCloseButton = true,\n twClassName: toastTwClassName,\n } = toastOptions;\n const toastProps = getToastProps(toastOptions);\n const { actionButtonLabel, actionButtonOnPress, ...restToastProps } =\n toastProps;\n const toastTwClassNames = [twClassName, toastTwClassName]\n .filter(Boolean)\n .join(' ');\n const handleClose = showCloseButton\n ? () => {\n closeToast();\n toastOnClose?.();\n }\n : undefined;\n\n const onAnimatedViewLayout = (e: LayoutChangeEvent) => {\n const { height } = e.nativeEvent.layout;\n const nextHiddenTranslateY = getHiddenTranslateY(height, topOffset);\n const nextVisibleTranslateY = topInset + TOAST_TOP_PADDING;\n\n hiddenTranslateY.value = nextHiddenTranslateY;\n visibleTranslateY.value = nextVisibleTranslateY;\n toastHeight.value = height;\n\n if (animationStartedRef.current) {\n return;\n }\n\n animationStartedRef.current = true;\n translateYProgress.value = nextHiddenTranslateY;\n\n if (toastOptions.hasNoTimeout) {\n translateYProgress.value = withSpring(\n nextVisibleTranslateY,\n TOAST_SPRING_CONFIG,\n );\n } else {\n translateYProgress.value = withSpring(\n nextVisibleTranslateY,\n TOAST_SPRING_CONFIG,\n (finished) => {\n if (finished) {\n scheduleOnRN(beginAutoDismiss);\n }\n },\n );\n }\n };\n\n return (\n <GestureDetector gesture={swipeGesture}>\n <Animated.View\n onLayout={onAnimatedViewLayout}\n style={baseStyle}\n {...props}\n >\n {actionButtonLabel && actionButtonOnPress ? (\n <Toast\n {...toastProps}\n actionButtonLabel={actionButtonLabel}\n actionButtonOnPress={actionButtonOnPress}\n onClose={handleClose}\n twClassName={toastTwClassNames}\n />\n ) : (\n <Toast\n {...restToastProps}\n onClose={handleClose}\n twClassName={toastTwClassNames}\n />\n )}\n </Animated.View>\n </GestureDetector>\n );\n },\n);\n\nToasterComponent.displayName = 'Toaster';\n\ntype ToastFunction = ((options: ToastOptions) => void) & {\n dismiss: () => void;\n};\n\nexport const Toaster = ToasterComponent;\n\nexport const toast = ((options: ToastOptions) => {\n assertRegisteredRef('toast').showToast(options);\n}) as ToastFunction;\n\ntoast.dismiss = () => {\n assertRegisteredRef('dismiss').closeToast();\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/design-system-react-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"description": "Design System React Native",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@babel/preset-typescript": "^7.23.3",
|
|
58
58
|
"@figma/code-connect": "^1.4.9",
|
|
59
59
|
"@gorhom/bottom-sheet": "^5.1.3",
|
|
60
|
-
"@metamask/auto-changelog": "^6.
|
|
60
|
+
"@metamask/auto-changelog": "^6.2.0",
|
|
61
61
|
"@metamask/design-system-twrnc-preset": "^0.9.0",
|
|
62
62
|
"@metamask/design-tokens": "^9.0.0",
|
|
63
63
|
"@metamask/utils": "^11.11.0",
|