@metamask/design-system-react 0.25.0 → 0.27.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 +27 -1
- package/dist/components/AvatarIcon/AvatarIcon.constants.cjs +2 -2
- package/dist/components/AvatarIcon/AvatarIcon.constants.cjs.map +1 -1
- package/dist/components/AvatarIcon/AvatarIcon.constants.mjs +2 -2
- package/dist/components/AvatarIcon/AvatarIcon.constants.mjs.map +1 -1
- package/dist/components/AvatarNetwork/AvatarNetwork.cjs +1 -2
- package/dist/components/AvatarNetwork/AvatarNetwork.cjs.map +1 -1
- package/dist/components/AvatarNetwork/AvatarNetwork.d.cts.map +1 -1
- package/dist/components/AvatarNetwork/AvatarNetwork.d.mts.map +1 -1
- package/dist/components/AvatarNetwork/AvatarNetwork.mjs +1 -2
- package/dist/components/AvatarNetwork/AvatarNetwork.mjs.map +1 -1
- package/dist/components/AvatarNetwork/index.cjs +2 -2
- package/dist/components/AvatarNetwork/index.cjs.map +1 -1
- package/dist/components/AvatarNetwork/index.d.cts +1 -1
- package/dist/components/AvatarNetwork/index.d.cts.map +1 -1
- package/dist/components/AvatarNetwork/index.d.mts +1 -1
- package/dist/components/AvatarNetwork/index.d.mts.map +1 -1
- package/dist/components/AvatarNetwork/index.mjs +1 -1
- package/dist/components/AvatarNetwork/index.mjs.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.cjs +1 -2
- package/dist/components/BannerAlert/BannerAlert.cjs.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.constants.cjs +8 -9
- package/dist/components/BannerAlert/BannerAlert.constants.cjs.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.constants.d.cts +1 -2
- package/dist/components/BannerAlert/BannerAlert.constants.d.cts.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.constants.d.mts +1 -2
- package/dist/components/BannerAlert/BannerAlert.constants.d.mts.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.constants.mjs +1 -2
- package/dist/components/BannerAlert/BannerAlert.constants.mjs.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.d.cts.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.d.mts.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.mjs +1 -2
- package/dist/components/BannerAlert/BannerAlert.mjs.map +1 -1
- package/dist/components/Icon/Icon.cjs +2 -2
- package/dist/components/Icon/Icon.cjs.map +1 -1
- package/dist/components/Icon/Icon.constants.cjs +6 -6
- package/dist/components/Icon/Icon.constants.cjs.map +1 -1
- package/dist/components/Icon/Icon.constants.d.cts +1 -1
- package/dist/components/Icon/Icon.constants.d.cts.map +1 -1
- package/dist/components/Icon/Icon.constants.d.mts +1 -1
- package/dist/components/Icon/Icon.constants.d.mts.map +1 -1
- package/dist/components/Icon/Icon.constants.mjs +1 -1
- package/dist/components/Icon/Icon.constants.mjs.map +1 -1
- package/dist/components/Icon/Icon.d.cts.map +1 -1
- package/dist/components/Icon/Icon.d.mts.map +1 -1
- package/dist/components/Icon/Icon.mjs +1 -1
- package/dist/components/Icon/Icon.mjs.map +1 -1
- package/dist/components/Icon/icons/Trophy.cjs +32 -0
- package/dist/components/Icon/icons/Trophy.cjs.map +1 -0
- package/dist/components/Icon/icons/Trophy.d.cts +4 -0
- package/dist/components/Icon/icons/Trophy.d.cts.map +1 -0
- package/dist/components/Icon/icons/Trophy.d.mts +4 -0
- package/dist/components/Icon/icons/Trophy.d.mts.map +1 -0
- package/dist/components/Icon/icons/Trophy.mjs +7 -0
- package/dist/components/Icon/icons/Trophy.mjs.map +1 -0
- package/dist/components/Icon/icons/index.cjs +2 -0
- package/dist/components/Icon/icons/index.cjs.map +1 -1
- package/dist/components/Icon/icons/index.d.cts +1 -0
- package/dist/components/Icon/icons/index.d.cts.map +1 -1
- package/dist/components/Icon/icons/index.d.mts +1 -0
- package/dist/components/Icon/icons/index.d.mts.map +1 -1
- package/dist/components/Icon/icons/index.mjs +2 -0
- package/dist/components/Icon/icons/index.mjs.map +1 -1
- package/dist/components/Icon/index.cjs +4 -4
- package/dist/components/Icon/index.cjs.map +1 -1
- package/dist/components/Icon/index.d.cts +1 -1
- package/dist/components/Icon/index.d.cts.map +1 -1
- package/dist/components/Icon/index.d.mts +1 -1
- package/dist/components/Icon/index.d.mts.map +1 -1
- package/dist/components/Icon/index.mjs +1 -1
- package/dist/components/Icon/index.mjs.map +1 -1
- package/dist/components/Tag/Tag.cjs +51 -0
- package/dist/components/Tag/Tag.cjs.map +1 -0
- package/dist/components/Tag/Tag.constants.cjs +26 -0
- package/dist/components/Tag/Tag.constants.cjs.map +1 -0
- package/dist/components/Tag/Tag.constants.d.cts +5 -0
- package/dist/components/Tag/Tag.constants.d.cts.map +1 -0
- package/dist/components/Tag/Tag.constants.d.mts +5 -0
- package/dist/components/Tag/Tag.constants.d.mts.map +1 -0
- package/dist/components/Tag/Tag.constants.mjs +23 -0
- package/dist/components/Tag/Tag.constants.mjs.map +1 -0
- package/dist/components/Tag/Tag.d.cts +4 -0
- package/dist/components/Tag/Tag.d.cts.map +1 -0
- package/dist/components/Tag/Tag.d.mts +4 -0
- package/dist/components/Tag/Tag.d.mts.map +1 -0
- package/dist/components/Tag/Tag.mjs +32 -0
- package/dist/components/Tag/Tag.mjs.map +1 -0
- package/dist/components/Tag/Tag.types.cjs +3 -0
- package/dist/components/Tag/Tag.types.cjs.map +1 -0
- package/dist/components/Tag/Tag.types.d.cts +31 -0
- package/dist/components/Tag/Tag.types.d.cts.map +1 -0
- package/dist/components/Tag/Tag.types.d.mts +31 -0
- package/dist/components/Tag/Tag.types.d.mts.map +1 -0
- package/dist/components/Tag/Tag.types.mjs +2 -0
- package/dist/components/Tag/Tag.types.mjs.map +1 -0
- package/dist/components/Tag/index.cjs +8 -0
- package/dist/components/Tag/index.cjs.map +1 -0
- package/dist/components/Tag/index.d.cts +4 -0
- package/dist/components/Tag/index.d.cts.map +1 -0
- package/dist/components/Tag/index.d.mts +4 -0
- package/dist/components/Tag/index.d.mts.map +1 -0
- package/dist/components/Tag/index.mjs +3 -0
- package/dist/components/Tag/index.mjs.map +1 -0
- package/dist/components/TextButton/TextButton.cjs +7 -28
- package/dist/components/TextButton/TextButton.cjs.map +1 -1
- package/dist/components/TextButton/TextButton.d.cts.map +1 -1
- package/dist/components/TextButton/TextButton.d.mts.map +1 -1
- package/dist/components/TextButton/TextButton.mjs +7 -28
- package/dist/components/TextButton/TextButton.mjs.map +1 -1
- package/dist/components/TextButton/TextButton.types.cjs.map +1 -1
- package/dist/components/TextButton/TextButton.types.d.cts +9 -25
- package/dist/components/TextButton/TextButton.types.d.cts.map +1 -1
- package/dist/components/TextButton/TextButton.types.d.mts +9 -25
- package/dist/components/TextButton/TextButton.types.d.mts.map +1 -1
- package/dist/components/TextButton/TextButton.types.mjs.map +1 -1
- package/dist/components/TextButton/index.cjs +1 -3
- package/dist/components/TextButton/index.cjs.map +1 -1
- package/dist/components/TextButton/index.d.cts +0 -1
- package/dist/components/TextButton/index.d.cts.map +1 -1
- package/dist/components/TextButton/index.d.mts +0 -1
- package/dist/components/TextButton/index.d.mts.map +1 -1
- package/dist/components/TextButton/index.mjs +0 -1
- package/dist/components/TextButton/index.mjs.map +1 -1
- package/dist/components/Toast/Toast.cjs +73 -0
- package/dist/components/Toast/Toast.cjs.map +1 -0
- package/dist/components/Toast/Toast.constants.cjs +24 -0
- package/dist/components/Toast/Toast.constants.cjs.map +1 -0
- package/dist/components/Toast/Toast.constants.d.cts +16 -0
- package/dist/components/Toast/Toast.constants.d.cts.map +1 -0
- package/dist/components/Toast/Toast.constants.d.mts +16 -0
- package/dist/components/Toast/Toast.constants.d.mts.map +1 -0
- package/dist/components/Toast/Toast.constants.mjs +19 -0
- package/dist/components/Toast/Toast.constants.mjs.map +1 -0
- package/dist/components/Toast/Toast.d.cts +4 -0
- package/dist/components/Toast/Toast.d.cts.map +1 -0
- package/dist/components/Toast/Toast.d.mts +4 -0
- package/dist/components/Toast/Toast.d.mts.map +1 -0
- package/dist/components/Toast/Toast.mjs +54 -0
- package/dist/components/Toast/Toast.mjs.map +1 -0
- package/dist/components/Toast/Toast.types.cjs +3 -0
- package/dist/components/Toast/Toast.types.cjs.map +1 -0
- package/dist/components/Toast/Toast.types.d.cts +60 -0
- package/dist/components/Toast/Toast.types.d.cts.map +1 -0
- package/dist/components/Toast/Toast.types.d.mts +60 -0
- package/dist/components/Toast/Toast.types.d.mts.map +1 -0
- package/dist/components/Toast/Toast.types.mjs +2 -0
- package/dist/components/Toast/Toast.types.mjs.map +1 -0
- package/dist/components/Toast/Toaster.cjs +210 -0
- package/dist/components/Toast/Toaster.cjs.map +1 -0
- package/dist/components/Toast/Toaster.d.cts +11 -0
- package/dist/components/Toast/Toaster.d.cts.map +1 -0
- package/dist/components/Toast/Toaster.d.mts +11 -0
- package/dist/components/Toast/Toaster.d.mts.map +1 -0
- package/dist/components/Toast/Toaster.mjs +191 -0
- package/dist/components/Toast/Toaster.mjs.map +1 -0
- package/dist/components/Toast/index.cjs +11 -0
- package/dist/components/Toast/index.cjs.map +1 -0
- package/dist/components/Toast/index.d.cts +5 -0
- package/dist/components/Toast/index.d.cts.map +1 -0
- package/dist/components/Toast/index.d.mts +5 -0
- package/dist/components/Toast/index.d.mts.map +1 -0
- package/dist/components/Toast/index.mjs +4 -0
- package/dist/components/Toast/index.mjs.map +1 -0
- package/dist/components/index.cjs +10 -2
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +5 -1
- package/dist/components/index.d.cts.map +1 -1
- package/dist/components/index.d.mts +5 -1
- package/dist/components/index.d.mts.map +1 -1
- package/dist/components/index.mjs +3 -1
- package/dist/components/index.mjs.map +1 -1
- package/dist/types/index.cjs +2 -23
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +1 -14
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.mts +1 -14
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs +1 -15
- package/dist/types/index.mjs.map +1 -1
- package/package.json +4 -2
- package/dist/components/TextButton/TextButton.constants.cjs +0 -12
- package/dist/components/TextButton/TextButton.constants.cjs.map +0 -1
- package/dist/components/TextButton/TextButton.constants.d.cts +0 -4
- package/dist/components/TextButton/TextButton.constants.d.cts.map +0 -1
- package/dist/components/TextButton/TextButton.constants.d.mts +0 -4
- package/dist/components/TextButton/TextButton.constants.d.mts.map +0 -1
- package/dist/components/TextButton/TextButton.constants.mjs +0 -9
- package/dist/components/TextButton/TextButton.constants.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/components/TextButton/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/components/TextButton/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,yBAAqB","sourcesContent":["export { TextButton } from './TextButton';\nexport type { TextButtonProps } from './TextButton.types';\n"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Toast = void 0;
|
|
27
|
+
const design_system_shared_1 = require("@metamask/design-system-shared");
|
|
28
|
+
const react_1 = __importStar(require("react"));
|
|
29
|
+
const tw_merge_1 = require("../../utils/tw-merge.cjs");
|
|
30
|
+
const BannerBase_1 = require("../BannerBase/index.cjs");
|
|
31
|
+
const Icon_1 = require("../Icon/index.cjs");
|
|
32
|
+
const Toast_constants_1 = require("./Toast.constants.cjs");
|
|
33
|
+
const renderSeverityAccessory = ({ severity, startAccessory, iconProps, }) => {
|
|
34
|
+
if (startAccessory !== null && startAccessory !== undefined) {
|
|
35
|
+
return startAccessory;
|
|
36
|
+
}
|
|
37
|
+
if (!severity || severity === design_system_shared_1.ToastSeverity.Default) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const { name, color } = Toast_constants_1.TOAST_SEVERITY_ICON_MAP[severity];
|
|
41
|
+
return react_1.default.createElement(Icon_1.Icon, { name: name, color: color, size: design_system_shared_1.IconSize.Lg, ...iconProps });
|
|
42
|
+
};
|
|
43
|
+
exports.Toast = (0, react_1.forwardRef)(({ actionButtonLabel, actionButtonOnClick, actionButtonProps, className, closeButtonProps, iconProps, onClose, severity = design_system_shared_1.ToastSeverity.Default, startAccessory, ...props }, ref) => {
|
|
44
|
+
// Only pass action props through when both the label and handler are set so
|
|
45
|
+
// BannerBase can keep its action button contract simple.
|
|
46
|
+
const resolvedActionProps = actionButtonLabel && actionButtonOnClick
|
|
47
|
+
? {
|
|
48
|
+
actionButtonLabel,
|
|
49
|
+
actionButtonOnClick,
|
|
50
|
+
actionButtonProps: {
|
|
51
|
+
size: design_system_shared_1.ButtonSize.Sm,
|
|
52
|
+
...actionButtonProps,
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
: {};
|
|
56
|
+
// Derive the close button config from the Toast API, keeping the button
|
|
57
|
+
// visible whenever the consumer provides dismiss behavior or overrides.
|
|
58
|
+
const resolvedCloseButtonProps = onClose || closeButtonProps
|
|
59
|
+
? {
|
|
60
|
+
ariaLabel: 'Close toast',
|
|
61
|
+
...closeButtonProps,
|
|
62
|
+
}
|
|
63
|
+
: undefined;
|
|
64
|
+
// Toast reuses BannerBase so the web surface stays aligned with the shared
|
|
65
|
+
// banner layout and the React Native Toast API.
|
|
66
|
+
return (react_1.default.createElement(BannerBase_1.BannerBase, { ref: ref, ...resolvedActionProps, ...props, backgroundColor: design_system_shared_1.BoxBackgroundColor.BackgroundSection, borderColor: design_system_shared_1.BoxBorderColor.BorderMuted, borderWidth: 1, className: (0, tw_merge_1.twMerge)('rounded-xl', className), closeButtonProps: resolvedCloseButtonProps, onClose: onClose, startAccessory: renderSeverityAccessory({
|
|
67
|
+
severity,
|
|
68
|
+
startAccessory,
|
|
69
|
+
iconProps,
|
|
70
|
+
}) }));
|
|
71
|
+
});
|
|
72
|
+
exports.Toast.displayName = 'Toast';
|
|
73
|
+
//# sourceMappingURL=Toast.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.cjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAMwC;AACxC,+CAA0C;AAE1C,uDAA+C;AAC/C,wDAA2C;AAC3C,4CAA+B;AAE/B,2DAA4D;AAG5D,MAAM,uBAAuB,GAAG,CAAC,EAC/B,QAAQ,EACR,cAAc,EACd,SAAS,GACqD,EAAE,EAAE;IAClE,IAAI,cAAc,KAAK,IAAI,IAAI,cAAc,KAAK,SAAS,EAAE;QAC3D,OAAO,cAAc,CAAC;KACvB;IAED,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,oCAAa,CAAC,OAAO,EAAE;QACnD,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,yCAAuB,CAAC,QAAQ,CAAC,CAAC;IAE1D,OAAO,8BAAC,WAAI,IAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,+BAAQ,CAAC,EAAE,KAAM,SAAS,GAAI,CAAC;AAC9E,CAAC,CAAC;AAEW,QAAA,KAAK,GAAG,IAAA,kBAAU,EAC7B,CACE,EACE,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,OAAO,EACP,QAAQ,GAAG,oCAAa,CAAC,OAAO,EAChC,cAAc,EACd,GAAG,KAAK,EACT,EACD,GAAG,EACH,EAAE;IACF,4EAA4E;IAC5E,yDAAyD;IACzD,MAAM,mBAAmB,GACvB,iBAAiB,IAAI,mBAAmB;QACtC,CAAC,CAAC;YACE,iBAAiB;YACjB,mBAAmB;YACnB,iBAAiB,EAAE;gBACjB,IAAI,EAAE,iCAAU,CAAC,EAAE;gBACnB,GAAG,iBAAiB;aACrB;SACF;QACH,CAAC,CAAC,EAAE,CAAC;IAET,wEAAwE;IACxE,wEAAwE;IACxE,MAAM,wBAAwB,GAC5B,OAAO,IAAI,gBAAgB;QACzB,CAAC,CAAC;YACE,SAAS,EAAE,aAAa;YACxB,GAAG,gBAAgB;SACpB;QACH,CAAC,CAAC,SAAS,CAAC;IAEhB,2EAA2E;IAC3E,gDAAgD;IAChD,OAAO,CACL,8BAAC,uBAAU,IACT,GAAG,EAAE,GAAG,KACJ,mBAAmB,KACnB,KAAK,EACT,eAAe,EAAE,yCAAkB,CAAC,iBAAiB,EACrD,WAAW,EAAE,qCAAc,CAAC,WAAW,EACvC,WAAW,EAAE,CAAC,EACd,SAAS,EAAE,IAAA,kBAAO,EAAC,YAAY,EAAE,SAAS,CAAC,EAC3C,gBAAgB,EAAE,wBAAwB,EAC1C,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,uBAAuB,CAAC;YACtC,QAAQ;YACR,cAAc;YACd,SAAS;SACV,CAAC,GACF,CACH,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,aAAK,CAAC,WAAW,GAAG,OAAO,CAAC","sourcesContent":["import {\n BoxBackgroundColor,\n BoxBorderColor,\n ButtonSize,\n IconSize,\n ToastSeverity,\n} from '@metamask/design-system-shared';\nimport React, { forwardRef } from 'react';\n\nimport { twMerge } from '../../utils/tw-merge';\nimport { BannerBase } from '../BannerBase';\nimport { Icon } from '../Icon';\n\nimport { TOAST_SEVERITY_ICON_MAP } from './Toast.constants';\nimport type { ToastProps } from './Toast.types';\n\nconst renderSeverityAccessory = ({\n severity,\n startAccessory,\n iconProps,\n}: Pick<ToastProps, 'severity' | 'startAccessory' | 'iconProps'>) => {\n if (startAccessory !== null && startAccessory !== undefined) {\n return startAccessory;\n }\n\n if (!severity || severity === ToastSeverity.Default) {\n return undefined;\n }\n\n const { name, color } = TOAST_SEVERITY_ICON_MAP[severity];\n\n return <Icon name={name} color={color} size={IconSize.Lg} {...iconProps} />;\n};\n\nexport const Toast = forwardRef<HTMLDivElement, ToastProps>(\n (\n {\n actionButtonLabel,\n actionButtonOnClick,\n actionButtonProps,\n className,\n closeButtonProps,\n iconProps,\n onClose,\n severity = ToastSeverity.Default,\n startAccessory,\n ...props\n },\n ref,\n ) => {\n // Only pass action props through when both the label and handler are set so\n // BannerBase can keep its action button contract simple.\n const resolvedActionProps =\n actionButtonLabel && actionButtonOnClick\n ? {\n actionButtonLabel,\n actionButtonOnClick,\n actionButtonProps: {\n size: ButtonSize.Sm,\n ...actionButtonProps,\n },\n }\n : {};\n\n // Derive the close button config from the Toast API, keeping the button\n // visible whenever the consumer provides dismiss behavior or overrides.\n const resolvedCloseButtonProps =\n onClose || closeButtonProps\n ? {\n ariaLabel: 'Close toast',\n ...closeButtonProps,\n }\n : undefined;\n\n // Toast reuses BannerBase so the web surface stays aligned with the shared\n // banner layout and the React Native Toast API.\n return (\n <BannerBase\n ref={ref}\n {...resolvedActionProps}\n {...props}\n backgroundColor={BoxBackgroundColor.BackgroundSection}\n borderColor={BoxBorderColor.BorderMuted}\n borderWidth={1}\n className={twMerge('rounded-xl', className)}\n closeButtonProps={resolvedCloseButtonProps}\n onClose={onClose}\n startAccessory={renderSeverityAccessory({\n severity,\n startAccessory,\n iconProps,\n })}\n />\n );\n },\n);\n\nToast.displayName = 'Toast';\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TOAST_SEVERITY_ICON_MAP = exports.TOAST_VISIBILITY_DURATION = exports.TOAST_ANIMATION_DURATION = void 0;
|
|
4
|
+
const design_system_shared_1 = require("@metamask/design-system-shared");
|
|
5
|
+
var design_system_shared_2 = require("@metamask/design-system-shared");
|
|
6
|
+
Object.defineProperty(exports, "TOAST_ANIMATION_DURATION", { enumerable: true, get: function () { return design_system_shared_2.TOAST_ANIMATION_DURATION; } });
|
|
7
|
+
Object.defineProperty(exports, "TOAST_VISIBILITY_DURATION", { enumerable: true, get: function () { return design_system_shared_2.TOAST_VISIBILITY_DURATION; } });
|
|
8
|
+
// TODO: Replace this map with a web IconAlert component once the shared
|
|
9
|
+
// alert-icon primitive exists in React.
|
|
10
|
+
exports.TOAST_SEVERITY_ICON_MAP = {
|
|
11
|
+
[design_system_shared_1.ToastSeverity.Success]: {
|
|
12
|
+
name: design_system_shared_1.IconName.Confirmation,
|
|
13
|
+
color: design_system_shared_1.IconColor.SuccessDefault,
|
|
14
|
+
},
|
|
15
|
+
[design_system_shared_1.ToastSeverity.Warning]: {
|
|
16
|
+
name: design_system_shared_1.IconName.Danger,
|
|
17
|
+
color: design_system_shared_1.IconColor.WarningDefault,
|
|
18
|
+
},
|
|
19
|
+
[design_system_shared_1.ToastSeverity.Danger]: {
|
|
20
|
+
name: design_system_shared_1.IconName.Danger,
|
|
21
|
+
color: design_system_shared_1.IconColor.ErrorDefault,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=Toast.constants.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.constants.cjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.constants.ts"],"names":[],"mappings":";;;AAAA,yEAIwC;AAExC,uEAGwC;AAFtC,gIAAA,wBAAwB,OAAA;AACxB,iIAAA,yBAAyB,OAAA;AAG3B,wEAAwE;AACxE,wCAAwC;AAC3B,QAAA,uBAAuB,GAAG;IACrC,CAAC,oCAAa,CAAC,OAAO,CAAC,EAAE;QACvB,IAAI,EAAE,+BAAQ,CAAC,YAAY;QAC3B,KAAK,EAAE,gCAAS,CAAC,cAAc;KAChC;IACD,CAAC,oCAAa,CAAC,OAAO,CAAC,EAAE;QACvB,IAAI,EAAE,+BAAQ,CAAC,MAAM;QACrB,KAAK,EAAE,gCAAS,CAAC,cAAc;KAChC;IACD,CAAC,oCAAa,CAAC,MAAM,CAAC,EAAE;QACtB,IAAI,EAAE,+BAAQ,CAAC,MAAM;QACrB,KAAK,EAAE,gCAAS,CAAC,YAAY;KAC9B;CACO,CAAC","sourcesContent":["import {\n IconColor,\n IconName,\n ToastSeverity,\n} from '@metamask/design-system-shared';\n\nexport {\n TOAST_ANIMATION_DURATION,\n TOAST_VISIBILITY_DURATION,\n} from '@metamask/design-system-shared';\n\n// TODO: Replace this map with a web IconAlert component once the shared\n// alert-icon primitive exists in React.\nexport const TOAST_SEVERITY_ICON_MAP = {\n [ToastSeverity.Success]: {\n name: IconName.Confirmation,\n color: IconColor.SuccessDefault,\n },\n [ToastSeverity.Warning]: {\n name: IconName.Danger,\n color: IconColor.WarningDefault,\n },\n [ToastSeverity.Danger]: {\n name: IconName.Danger,\n color: IconColor.ErrorDefault,\n },\n} as const;\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { TOAST_ANIMATION_DURATION, TOAST_VISIBILITY_DURATION, } from "@metamask/design-system-shared";
|
|
2
|
+
export declare const TOAST_SEVERITY_ICON_MAP: {
|
|
3
|
+
readonly success: {
|
|
4
|
+
readonly name: "Confirmation";
|
|
5
|
+
readonly color: "text-success-default";
|
|
6
|
+
};
|
|
7
|
+
readonly warning: {
|
|
8
|
+
readonly name: "Danger";
|
|
9
|
+
readonly color: "text-warning-default";
|
|
10
|
+
};
|
|
11
|
+
readonly danger: {
|
|
12
|
+
readonly name: "Danger";
|
|
13
|
+
readonly color: "text-error-default";
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=Toast.constants.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.constants.d.cts","sourceRoot":"","sources":["../../../src/components/Toast/Toast.constants.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,uCAAuC;AAIxC,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;CAa1B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { TOAST_ANIMATION_DURATION, TOAST_VISIBILITY_DURATION, } from "@metamask/design-system-shared";
|
|
2
|
+
export declare const TOAST_SEVERITY_ICON_MAP: {
|
|
3
|
+
readonly success: {
|
|
4
|
+
readonly name: "Confirmation";
|
|
5
|
+
readonly color: "text-success-default";
|
|
6
|
+
};
|
|
7
|
+
readonly warning: {
|
|
8
|
+
readonly name: "Danger";
|
|
9
|
+
readonly color: "text-warning-default";
|
|
10
|
+
};
|
|
11
|
+
readonly danger: {
|
|
12
|
+
readonly name: "Danger";
|
|
13
|
+
readonly color: "text-error-default";
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=Toast.constants.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.constants.d.mts","sourceRoot":"","sources":["../../../src/components/Toast/Toast.constants.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,uCAAuC;AAIxC,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;CAa1B,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IconColor, IconName, ToastSeverity } from "@metamask/design-system-shared";
|
|
2
|
+
export { TOAST_ANIMATION_DURATION, TOAST_VISIBILITY_DURATION } from "@metamask/design-system-shared";
|
|
3
|
+
// TODO: Replace this map with a web IconAlert component once the shared
|
|
4
|
+
// alert-icon primitive exists in React.
|
|
5
|
+
export const TOAST_SEVERITY_ICON_MAP = {
|
|
6
|
+
[ToastSeverity.Success]: {
|
|
7
|
+
name: IconName.Confirmation,
|
|
8
|
+
color: IconColor.SuccessDefault,
|
|
9
|
+
},
|
|
10
|
+
[ToastSeverity.Warning]: {
|
|
11
|
+
name: IconName.Danger,
|
|
12
|
+
color: IconColor.WarningDefault,
|
|
13
|
+
},
|
|
14
|
+
[ToastSeverity.Danger]: {
|
|
15
|
+
name: IconName.Danger,
|
|
16
|
+
color: IconColor.ErrorDefault,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=Toast.constants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.constants.mjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,QAAQ,EACR,aAAa,EACd,uCAAuC;AAExC,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EAC1B,uCAAuC;AAExC,wEAAwE;AACxE,wCAAwC;AACxC,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;QACvB,IAAI,EAAE,QAAQ,CAAC,YAAY;QAC3B,KAAK,EAAE,SAAS,CAAC,cAAc;KAChC;IACD,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;QACvB,IAAI,EAAE,QAAQ,CAAC,MAAM;QACrB,KAAK,EAAE,SAAS,CAAC,cAAc;KAChC;IACD,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE;QACtB,IAAI,EAAE,QAAQ,CAAC,MAAM;QACrB,KAAK,EAAE,SAAS,CAAC,YAAY;KAC9B;CACO,CAAC","sourcesContent":["import {\n IconColor,\n IconName,\n ToastSeverity,\n} from '@metamask/design-system-shared';\n\nexport {\n TOAST_ANIMATION_DURATION,\n TOAST_VISIBILITY_DURATION,\n} from '@metamask/design-system-shared';\n\n// TODO: Replace this map with a web IconAlert component once the shared\n// alert-icon primitive exists in React.\nexport const TOAST_SEVERITY_ICON_MAP = {\n [ToastSeverity.Success]: {\n name: IconName.Confirmation,\n color: IconColor.SuccessDefault,\n },\n [ToastSeverity.Warning]: {\n name: IconName.Danger,\n color: IconColor.WarningDefault,\n },\n [ToastSeverity.Danger]: {\n name: IconName.Danger,\n color: IconColor.ErrorDefault,\n },\n} as const;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.d.cts","sourceRoot":"","sources":["../../../src/components/Toast/Toast.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAqB,cAAc;AAO1C,OAAO,KAAK,EAAE,UAAU,EAAE,0BAAsB;AAoBhD,eAAO,MAAM,KAAK,gGA6DjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.d.mts","sourceRoot":"","sources":["../../../src/components/Toast/Toast.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAqB,cAAc;AAO1C,OAAO,KAAK,EAAE,UAAU,EAAE,0BAAsB;AAoBhD,eAAO,MAAM,KAAK,gGA6DjB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function $importDefault(module) {
|
|
2
|
+
if (module?.__esModule) {
|
|
3
|
+
return module.default;
|
|
4
|
+
}
|
|
5
|
+
return module;
|
|
6
|
+
}
|
|
7
|
+
import { BoxBackgroundColor, BoxBorderColor, ButtonSize, IconSize, ToastSeverity } from "@metamask/design-system-shared";
|
|
8
|
+
import $React, { forwardRef } from "react";
|
|
9
|
+
const React = $importDefault($React);
|
|
10
|
+
import { twMerge } from "../../utils/tw-merge.mjs";
|
|
11
|
+
import { BannerBase } from "../BannerBase/index.mjs";
|
|
12
|
+
import { Icon } from "../Icon/index.mjs";
|
|
13
|
+
import { TOAST_SEVERITY_ICON_MAP } from "./Toast.constants.mjs";
|
|
14
|
+
const renderSeverityAccessory = ({ severity, startAccessory, iconProps, }) => {
|
|
15
|
+
if (startAccessory !== null && startAccessory !== undefined) {
|
|
16
|
+
return startAccessory;
|
|
17
|
+
}
|
|
18
|
+
if (!severity || severity === ToastSeverity.Default) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const { name, color } = TOAST_SEVERITY_ICON_MAP[severity];
|
|
22
|
+
return React.createElement(Icon, { name: name, color: color, size: IconSize.Lg, ...iconProps });
|
|
23
|
+
};
|
|
24
|
+
export const Toast = forwardRef(({ actionButtonLabel, actionButtonOnClick, actionButtonProps, className, closeButtonProps, iconProps, onClose, severity = ToastSeverity.Default, startAccessory, ...props }, ref) => {
|
|
25
|
+
// Only pass action props through when both the label and handler are set so
|
|
26
|
+
// BannerBase can keep its action button contract simple.
|
|
27
|
+
const resolvedActionProps = actionButtonLabel && actionButtonOnClick
|
|
28
|
+
? {
|
|
29
|
+
actionButtonLabel,
|
|
30
|
+
actionButtonOnClick,
|
|
31
|
+
actionButtonProps: {
|
|
32
|
+
size: ButtonSize.Sm,
|
|
33
|
+
...actionButtonProps,
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
: {};
|
|
37
|
+
// Derive the close button config from the Toast API, keeping the button
|
|
38
|
+
// visible whenever the consumer provides dismiss behavior or overrides.
|
|
39
|
+
const resolvedCloseButtonProps = onClose || closeButtonProps
|
|
40
|
+
? {
|
|
41
|
+
ariaLabel: 'Close toast',
|
|
42
|
+
...closeButtonProps,
|
|
43
|
+
}
|
|
44
|
+
: undefined;
|
|
45
|
+
// Toast reuses BannerBase so the web surface stays aligned with the shared
|
|
46
|
+
// banner layout and the React Native Toast API.
|
|
47
|
+
return (React.createElement(BannerBase, { ref: ref, ...resolvedActionProps, ...props, backgroundColor: BoxBackgroundColor.BackgroundSection, borderColor: BoxBorderColor.BorderMuted, borderWidth: 1, className: twMerge('rounded-xl', className), closeButtonProps: resolvedCloseButtonProps, onClose: onClose, startAccessory: renderSeverityAccessory({
|
|
48
|
+
severity,
|
|
49
|
+
startAccessory,
|
|
50
|
+
iconProps,
|
|
51
|
+
}) }));
|
|
52
|
+
});
|
|
53
|
+
Toast.displayName = 'Toast';
|
|
54
|
+
//# sourceMappingURL=Toast.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.mjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,QAAQ,EACR,aAAa,EACd,uCAAuC;AACxC,OAAO,QAAO,EAAE,UAAU,EAAE,cAAc;;AAE1C,OAAO,EAAE,OAAO,EAAE,iCAA6B;AAC/C,OAAO,EAAE,UAAU,EAAE,gCAAsB;AAC3C,OAAO,EAAE,IAAI,EAAE,0BAAgB;AAE/B,OAAO,EAAE,uBAAuB,EAAE,8BAA0B;AAG5D,MAAM,uBAAuB,GAAG,CAAC,EAC/B,QAAQ,EACR,cAAc,EACd,SAAS,GACqD,EAAE,EAAE;IAClE,IAAI,cAAc,KAAK,IAAI,IAAI,cAAc,KAAK,SAAS,EAAE;QAC3D,OAAO,cAAc,CAAC;KACvB;IAED,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,aAAa,CAAC,OAAO,EAAE;QACnD,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAE1D,OAAO,oBAAC,IAAI,IAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,KAAM,SAAS,GAAI,CAAC;AAC9E,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG,UAAU,CAC7B,CACE,EACE,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,OAAO,EACP,QAAQ,GAAG,aAAa,CAAC,OAAO,EAChC,cAAc,EACd,GAAG,KAAK,EACT,EACD,GAAG,EACH,EAAE;IACF,4EAA4E;IAC5E,yDAAyD;IACzD,MAAM,mBAAmB,GACvB,iBAAiB,IAAI,mBAAmB;QACtC,CAAC,CAAC;YACE,iBAAiB;YACjB,mBAAmB;YACnB,iBAAiB,EAAE;gBACjB,IAAI,EAAE,UAAU,CAAC,EAAE;gBACnB,GAAG,iBAAiB;aACrB;SACF;QACH,CAAC,CAAC,EAAE,CAAC;IAET,wEAAwE;IACxE,wEAAwE;IACxE,MAAM,wBAAwB,GAC5B,OAAO,IAAI,gBAAgB;QACzB,CAAC,CAAC;YACE,SAAS,EAAE,aAAa;YACxB,GAAG,gBAAgB;SACpB;QACH,CAAC,CAAC,SAAS,CAAC;IAEhB,2EAA2E;IAC3E,gDAAgD;IAChD,OAAO,CACL,oBAAC,UAAU,IACT,GAAG,EAAE,GAAG,KACJ,mBAAmB,KACnB,KAAK,EACT,eAAe,EAAE,kBAAkB,CAAC,iBAAiB,EACrD,WAAW,EAAE,cAAc,CAAC,WAAW,EACvC,WAAW,EAAE,CAAC,EACd,SAAS,EAAE,OAAO,CAAC,YAAY,EAAE,SAAS,CAAC,EAC3C,gBAAgB,EAAE,wBAAwB,EAC1C,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,uBAAuB,CAAC;YACtC,QAAQ;YACR,cAAc;YACd,SAAS;SACV,CAAC,GACF,CACH,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,KAAK,CAAC,WAAW,GAAG,OAAO,CAAC","sourcesContent":["import {\n BoxBackgroundColor,\n BoxBorderColor,\n ButtonSize,\n IconSize,\n ToastSeverity,\n} from '@metamask/design-system-shared';\nimport React, { forwardRef } from 'react';\n\nimport { twMerge } from '../../utils/tw-merge';\nimport { BannerBase } from '../BannerBase';\nimport { Icon } from '../Icon';\n\nimport { TOAST_SEVERITY_ICON_MAP } from './Toast.constants';\nimport type { ToastProps } from './Toast.types';\n\nconst renderSeverityAccessory = ({\n severity,\n startAccessory,\n iconProps,\n}: Pick<ToastProps, 'severity' | 'startAccessory' | 'iconProps'>) => {\n if (startAccessory !== null && startAccessory !== undefined) {\n return startAccessory;\n }\n\n if (!severity || severity === ToastSeverity.Default) {\n return undefined;\n }\n\n const { name, color } = TOAST_SEVERITY_ICON_MAP[severity];\n\n return <Icon name={name} color={color} size={IconSize.Lg} {...iconProps} />;\n};\n\nexport const Toast = forwardRef<HTMLDivElement, ToastProps>(\n (\n {\n actionButtonLabel,\n actionButtonOnClick,\n actionButtonProps,\n className,\n closeButtonProps,\n iconProps,\n onClose,\n severity = ToastSeverity.Default,\n startAccessory,\n ...props\n },\n ref,\n ) => {\n // Only pass action props through when both the label and handler are set so\n // BannerBase can keep its action button contract simple.\n const resolvedActionProps =\n actionButtonLabel && actionButtonOnClick\n ? {\n actionButtonLabel,\n actionButtonOnClick,\n actionButtonProps: {\n size: ButtonSize.Sm,\n ...actionButtonProps,\n },\n }\n : {};\n\n // Derive the close button config from the Toast API, keeping the button\n // visible whenever the consumer provides dismiss behavior or overrides.\n const resolvedCloseButtonProps =\n onClose || closeButtonProps\n ? {\n ariaLabel: 'Close toast',\n ...closeButtonProps,\n }\n : undefined;\n\n // Toast reuses BannerBase so the web surface stays aligned with the shared\n // banner layout and the React Native Toast API.\n return (\n <BannerBase\n ref={ref}\n {...resolvedActionProps}\n {...props}\n backgroundColor={BoxBackgroundColor.BackgroundSection}\n borderColor={BoxBorderColor.BorderMuted}\n borderWidth={1}\n className={twMerge('rounded-xl', className)}\n closeButtonProps={resolvedCloseButtonProps}\n onClose={onClose}\n startAccessory={renderSeverityAccessory({\n severity,\n startAccessory,\n iconProps,\n })}\n />\n );\n },\n);\n\nToast.displayName = 'Toast';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.types.cjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ToastPropsShared } from '@metamask/design-system-shared';\n\nimport type { BannerBaseProps } from '../BannerBase';\nimport type { IconProps } from '../Icon';\n\ntype ToastCloseButtonProps = Omit<\n NonNullable<BannerBaseProps['closeButtonProps']>,\n 'onClick'\n>;\n\n/**\n * Props for the Toast visual component.\n * Extends the platform BannerBase props with severity and an icon override.\n * `onClose` is simplified to `() => void` (no MouseEvent) to align with the\n * React Native API and the imperative `toast()` pattern.\n */\nexport type ToastProps = Omit<BannerBaseProps, 'closeButtonProps' | 'onClose'> &\n ToastPropsShared & {\n /**\n * Optional handler called when the close button is pressed.\n * When provided, a close button is shown.\n */\n onClose?: () => void;\n /**\n * Optional props passed to the severity `Icon`.\n * Only used when `severity` is not `Default` and `startAccessory` is not provided.\n */\n iconProps?: Omit<IconProps, 'name' | 'color'>;\n /**\n * Optional props for the close `ButtonIcon`.\n * `ariaLabel` defaults to `'Close toast'`.\n */\n closeButtonProps?: ToastCloseButtonProps;\n /**\n * Optional test identifier forwarded to the root Toast element.\n */\n 'data-testid'?: string;\n };\n\n/**\n * Options passed to the imperative `toast(...)` API.\n */\nexport type ToastOptions = ToastProps & {\n /**\n * When true the toast stays visible until explicitly dismissed.\n * Defaults to false.\n */\n hasNoTimeout?: boolean;\n};\n\n/**\n * Imperative handle exposed by `<Toaster ref={...} />`.\n */\nexport type ToasterRef = {\n showToast: (options: ToastOptions) => void;\n closeToast: () => void;\n};\n\n/**\n * Props for the `<Toaster />` container component.\n */\nexport type ToasterProps = {\n /**\n * Optional extra CSS classes applied to the fixed outer container.\n */\n className?: string;\n} & Omit<React.HTMLAttributes<HTMLDivElement>, 'style'>;\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ToastPropsShared } from "@metamask/design-system-shared";
|
|
3
|
+
import type { BannerBaseProps } from "../BannerBase/index.cjs";
|
|
4
|
+
import type { IconProps } from "../Icon/index.cjs";
|
|
5
|
+
type ToastCloseButtonProps = Omit<NonNullable<BannerBaseProps['closeButtonProps']>, 'onClick'>;
|
|
6
|
+
/**
|
|
7
|
+
* Props for the Toast visual component.
|
|
8
|
+
* Extends the platform BannerBase props with severity and an icon override.
|
|
9
|
+
* `onClose` is simplified to `() => void` (no MouseEvent) to align with the
|
|
10
|
+
* React Native API and the imperative `toast()` pattern.
|
|
11
|
+
*/
|
|
12
|
+
export type ToastProps = Omit<BannerBaseProps, 'closeButtonProps' | 'onClose'> & ToastPropsShared & {
|
|
13
|
+
/**
|
|
14
|
+
* Optional handler called when the close button is pressed.
|
|
15
|
+
* When provided, a close button is shown.
|
|
16
|
+
*/
|
|
17
|
+
onClose?: () => void;
|
|
18
|
+
/**
|
|
19
|
+
* Optional props passed to the severity `Icon`.
|
|
20
|
+
* Only used when `severity` is not `Default` and `startAccessory` is not provided.
|
|
21
|
+
*/
|
|
22
|
+
iconProps?: Omit<IconProps, 'name' | 'color'>;
|
|
23
|
+
/**
|
|
24
|
+
* Optional props for the close `ButtonIcon`.
|
|
25
|
+
* `ariaLabel` defaults to `'Close toast'`.
|
|
26
|
+
*/
|
|
27
|
+
closeButtonProps?: ToastCloseButtonProps;
|
|
28
|
+
/**
|
|
29
|
+
* Optional test identifier forwarded to the root Toast element.
|
|
30
|
+
*/
|
|
31
|
+
'data-testid'?: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Options passed to the imperative `toast(...)` API.
|
|
35
|
+
*/
|
|
36
|
+
export type ToastOptions = ToastProps & {
|
|
37
|
+
/**
|
|
38
|
+
* When true the toast stays visible until explicitly dismissed.
|
|
39
|
+
* Defaults to false.
|
|
40
|
+
*/
|
|
41
|
+
hasNoTimeout?: boolean;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Imperative handle exposed by `<Toaster ref={...} />`.
|
|
45
|
+
*/
|
|
46
|
+
export type ToasterRef = {
|
|
47
|
+
showToast: (options: ToastOptions) => void;
|
|
48
|
+
closeToast: () => void;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Props for the `<Toaster />` container component.
|
|
52
|
+
*/
|
|
53
|
+
export type ToasterProps = {
|
|
54
|
+
/**
|
|
55
|
+
* Optional extra CSS classes applied to the fixed outer container.
|
|
56
|
+
*/
|
|
57
|
+
className?: string;
|
|
58
|
+
} & Omit<React.HTMLAttributes<HTMLDivElement>, 'style'>;
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=Toast.types.d.cts.map
|
|
@@ -0,0 +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;AAEvE,OAAO,KAAK,EAAE,eAAe,EAAE,gCAAsB;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,0BAAgB;AAEzC,KAAK,qBAAqB,GAAG,IAAI,CAC/B,WAAW,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,EAChD,SAAS,CACV,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,EAAE,kBAAkB,GAAG,SAAS,CAAC,GAC5E,gBAAgB,GAAG;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;IAC9C;;;OAGG;IACH,gBAAgB,CAAC,EAAE,qBAAqB,CAAC;IACzC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG;IACtC;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC;IAC3C,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ToastPropsShared } from "@metamask/design-system-shared";
|
|
3
|
+
import type { BannerBaseProps } from "../BannerBase/index.mjs";
|
|
4
|
+
import type { IconProps } from "../Icon/index.mjs";
|
|
5
|
+
type ToastCloseButtonProps = Omit<NonNullable<BannerBaseProps['closeButtonProps']>, 'onClick'>;
|
|
6
|
+
/**
|
|
7
|
+
* Props for the Toast visual component.
|
|
8
|
+
* Extends the platform BannerBase props with severity and an icon override.
|
|
9
|
+
* `onClose` is simplified to `() => void` (no MouseEvent) to align with the
|
|
10
|
+
* React Native API and the imperative `toast()` pattern.
|
|
11
|
+
*/
|
|
12
|
+
export type ToastProps = Omit<BannerBaseProps, 'closeButtonProps' | 'onClose'> & ToastPropsShared & {
|
|
13
|
+
/**
|
|
14
|
+
* Optional handler called when the close button is pressed.
|
|
15
|
+
* When provided, a close button is shown.
|
|
16
|
+
*/
|
|
17
|
+
onClose?: () => void;
|
|
18
|
+
/**
|
|
19
|
+
* Optional props passed to the severity `Icon`.
|
|
20
|
+
* Only used when `severity` is not `Default` and `startAccessory` is not provided.
|
|
21
|
+
*/
|
|
22
|
+
iconProps?: Omit<IconProps, 'name' | 'color'>;
|
|
23
|
+
/**
|
|
24
|
+
* Optional props for the close `ButtonIcon`.
|
|
25
|
+
* `ariaLabel` defaults to `'Close toast'`.
|
|
26
|
+
*/
|
|
27
|
+
closeButtonProps?: ToastCloseButtonProps;
|
|
28
|
+
/**
|
|
29
|
+
* Optional test identifier forwarded to the root Toast element.
|
|
30
|
+
*/
|
|
31
|
+
'data-testid'?: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Options passed to the imperative `toast(...)` API.
|
|
35
|
+
*/
|
|
36
|
+
export type ToastOptions = ToastProps & {
|
|
37
|
+
/**
|
|
38
|
+
* When true the toast stays visible until explicitly dismissed.
|
|
39
|
+
* Defaults to false.
|
|
40
|
+
*/
|
|
41
|
+
hasNoTimeout?: boolean;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Imperative handle exposed by `<Toaster ref={...} />`.
|
|
45
|
+
*/
|
|
46
|
+
export type ToasterRef = {
|
|
47
|
+
showToast: (options: ToastOptions) => void;
|
|
48
|
+
closeToast: () => void;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Props for the `<Toaster />` container component.
|
|
52
|
+
*/
|
|
53
|
+
export type ToasterProps = {
|
|
54
|
+
/**
|
|
55
|
+
* Optional extra CSS classes applied to the fixed outer container.
|
|
56
|
+
*/
|
|
57
|
+
className?: string;
|
|
58
|
+
} & Omit<React.HTMLAttributes<HTMLDivElement>, 'style'>;
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=Toast.types.d.mts.map
|
|
@@ -0,0 +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;AAEvE,OAAO,KAAK,EAAE,eAAe,EAAE,gCAAsB;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,0BAAgB;AAEzC,KAAK,qBAAqB,GAAG,IAAI,CAC/B,WAAW,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,EAChD,SAAS,CACV,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,EAAE,kBAAkB,GAAG,SAAS,CAAC,GAC5E,gBAAgB,GAAG;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;IAC9C;;;OAGG;IACH,gBAAgB,CAAC,EAAE,qBAAqB,CAAC;IACzC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG;IACtC;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC;IAC3C,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.types.mjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ToastPropsShared } from '@metamask/design-system-shared';\n\nimport type { BannerBaseProps } from '../BannerBase';\nimport type { IconProps } from '../Icon';\n\ntype ToastCloseButtonProps = Omit<\n NonNullable<BannerBaseProps['closeButtonProps']>,\n 'onClick'\n>;\n\n/**\n * Props for the Toast visual component.\n * Extends the platform BannerBase props with severity and an icon override.\n * `onClose` is simplified to `() => void` (no MouseEvent) to align with the\n * React Native API and the imperative `toast()` pattern.\n */\nexport type ToastProps = Omit<BannerBaseProps, 'closeButtonProps' | 'onClose'> &\n ToastPropsShared & {\n /**\n * Optional handler called when the close button is pressed.\n * When provided, a close button is shown.\n */\n onClose?: () => void;\n /**\n * Optional props passed to the severity `Icon`.\n * Only used when `severity` is not `Default` and `startAccessory` is not provided.\n */\n iconProps?: Omit<IconProps, 'name' | 'color'>;\n /**\n * Optional props for the close `ButtonIcon`.\n * `ariaLabel` defaults to `'Close toast'`.\n */\n closeButtonProps?: ToastCloseButtonProps;\n /**\n * Optional test identifier forwarded to the root Toast element.\n */\n 'data-testid'?: string;\n };\n\n/**\n * Options passed to the imperative `toast(...)` API.\n */\nexport type ToastOptions = ToastProps & {\n /**\n * When true the toast stays visible until explicitly dismissed.\n * Defaults to false.\n */\n hasNoTimeout?: boolean;\n};\n\n/**\n * Imperative handle exposed by `<Toaster ref={...} />`.\n */\nexport type ToasterRef = {\n showToast: (options: ToastOptions) => void;\n closeToast: () => void;\n};\n\n/**\n * Props for the `<Toaster />` container component.\n */\nexport type ToasterProps = {\n /**\n * Optional extra CSS classes applied to the fixed outer container.\n */\n className?: string;\n} & Omit<React.HTMLAttributes<HTMLDivElement>, 'style'>;\n"]}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.toast = exports.Toaster = void 0;
|
|
27
|
+
const react_1 = __importStar(require("react"));
|
|
28
|
+
const tw_merge_1 = require("../../utils/tw-merge.cjs");
|
|
29
|
+
const Toast_1 = require("./Toast.cjs");
|
|
30
|
+
const Toast_constants_1 = require("./Toast.constants.cjs");
|
|
31
|
+
let storeToastOptions;
|
|
32
|
+
const toastStoreListeners = new Set();
|
|
33
|
+
const normalizeToastOptions = (options) => ({
|
|
34
|
+
hasNoTimeout: false,
|
|
35
|
+
...options,
|
|
36
|
+
});
|
|
37
|
+
const emitToastStoreChange = () => {
|
|
38
|
+
toastStoreListeners.forEach((listener) => listener(storeToastOptions));
|
|
39
|
+
};
|
|
40
|
+
const setStoreToastOptions = (options) => {
|
|
41
|
+
storeToastOptions = normalizeToastOptions(options);
|
|
42
|
+
emitToastStoreChange();
|
|
43
|
+
};
|
|
44
|
+
const clearStoreToastOptions = () => {
|
|
45
|
+
storeToastOptions = undefined;
|
|
46
|
+
emitToastStoreChange();
|
|
47
|
+
};
|
|
48
|
+
const subscribeToToastStore = (listener) => {
|
|
49
|
+
toastStoreListeners.add(listener);
|
|
50
|
+
listener(storeToastOptions);
|
|
51
|
+
return () => {
|
|
52
|
+
toastStoreListeners.delete(listener);
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
const getToastProps = ({ hasNoTimeout: _hasNoTimeout, ...toastProps }) => toastProps;
|
|
56
|
+
const ToasterComponent = (0, react_1.forwardRef)(({ className, ...props }, ref) => {
|
|
57
|
+
const [toastOptions, setToastOptions] = (0, react_1.useState)(undefined);
|
|
58
|
+
const toastOptionsRef = (0, react_1.useRef)(undefined);
|
|
59
|
+
const [isVisible, setIsVisible] = (0, react_1.useState)(false);
|
|
60
|
+
const isVisibleRef = (0, react_1.useRef)(false);
|
|
61
|
+
const replacementTimerRef = (0, react_1.useRef)(null);
|
|
62
|
+
const autoDismissTimerRef = (0, react_1.useRef)(null);
|
|
63
|
+
const exitTimerRef = (0, react_1.useRef)(null);
|
|
64
|
+
const enterAnimationFrameRef = (0, react_1.useRef)(null);
|
|
65
|
+
const pendingToastRef = (0, react_1.useRef)(undefined);
|
|
66
|
+
const setCurrentToastOptions = (0, react_1.useCallback)((options) => {
|
|
67
|
+
toastOptionsRef.current = options;
|
|
68
|
+
setToastOptions(options);
|
|
69
|
+
}, []);
|
|
70
|
+
const setCurrentIsVisible = (0, react_1.useCallback)((nextIsVisible) => {
|
|
71
|
+
isVisibleRef.current = nextIsVisible;
|
|
72
|
+
setIsVisible(nextIsVisible);
|
|
73
|
+
}, []);
|
|
74
|
+
const clearPendingTimers = (0, react_1.useCallback)(() => {
|
|
75
|
+
if (replacementTimerRef.current !== null) {
|
|
76
|
+
clearTimeout(replacementTimerRef.current);
|
|
77
|
+
replacementTimerRef.current = null;
|
|
78
|
+
}
|
|
79
|
+
if (autoDismissTimerRef.current !== null) {
|
|
80
|
+
clearTimeout(autoDismissTimerRef.current);
|
|
81
|
+
autoDismissTimerRef.current = null;
|
|
82
|
+
}
|
|
83
|
+
if (exitTimerRef.current !== null) {
|
|
84
|
+
clearTimeout(exitTimerRef.current);
|
|
85
|
+
exitTimerRef.current = null;
|
|
86
|
+
}
|
|
87
|
+
if (enterAnimationFrameRef.current !== null) {
|
|
88
|
+
cancelAnimationFrame(enterAnimationFrameRef.current);
|
|
89
|
+
enterAnimationFrameRef.current = null;
|
|
90
|
+
}
|
|
91
|
+
}, []);
|
|
92
|
+
const closeRenderedToast = (0, react_1.useCallback)(() => {
|
|
93
|
+
if (!toastOptionsRef.current && !isVisibleRef.current) {
|
|
94
|
+
clearPendingTimers();
|
|
95
|
+
pendingToastRef.current = undefined;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
clearPendingTimers();
|
|
99
|
+
pendingToastRef.current = undefined;
|
|
100
|
+
setCurrentIsVisible(false);
|
|
101
|
+
exitTimerRef.current = setTimeout(() => {
|
|
102
|
+
exitTimerRef.current = null;
|
|
103
|
+
setCurrentToastOptions(undefined);
|
|
104
|
+
}, Toast_constants_1.TOAST_ANIMATION_DURATION);
|
|
105
|
+
}, [clearPendingTimers, setCurrentIsVisible, setCurrentToastOptions]);
|
|
106
|
+
// Replace the currently mounted toast rather than queueing multiple toasts.
|
|
107
|
+
// This mirrors the old app-level toast service behavior while keeping the
|
|
108
|
+
// imperative API centered in the shared single-toast store.
|
|
109
|
+
const showRenderedToast = (0, react_1.useCallback)((options) => {
|
|
110
|
+
const normalizedOptions = normalizeToastOptions(options);
|
|
111
|
+
const timeoutDuration = 0;
|
|
112
|
+
if (toastOptionsRef.current) {
|
|
113
|
+
pendingToastRef.current = normalizedOptions;
|
|
114
|
+
setCurrentIsVisible(false);
|
|
115
|
+
if (exitTimerRef.current !== null) {
|
|
116
|
+
clearTimeout(exitTimerRef.current);
|
|
117
|
+
exitTimerRef.current = null;
|
|
118
|
+
}
|
|
119
|
+
exitTimerRef.current = setTimeout(() => {
|
|
120
|
+
exitTimerRef.current = null;
|
|
121
|
+
setCurrentToastOptions(pendingToastRef.current);
|
|
122
|
+
pendingToastRef.current = undefined;
|
|
123
|
+
}, Toast_constants_1.TOAST_ANIMATION_DURATION);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (replacementTimerRef.current !== null) {
|
|
127
|
+
clearTimeout(replacementTimerRef.current);
|
|
128
|
+
}
|
|
129
|
+
replacementTimerRef.current = setTimeout(() => {
|
|
130
|
+
replacementTimerRef.current = null;
|
|
131
|
+
setCurrentToastOptions(normalizedOptions);
|
|
132
|
+
}, timeoutDuration);
|
|
133
|
+
}, [setCurrentIsVisible, setCurrentToastOptions]);
|
|
134
|
+
(0, react_1.useImperativeHandle)(ref, () => ({
|
|
135
|
+
closeToast: clearStoreToastOptions,
|
|
136
|
+
showToast: setStoreToastOptions,
|
|
137
|
+
}), []);
|
|
138
|
+
// Subscribe before sibling passive effects run so toast() can be called
|
|
139
|
+
// from anywhere once the app root has rendered <Toaster />.
|
|
140
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
141
|
+
return subscribeToToastStore((options) => {
|
|
142
|
+
if (options) {
|
|
143
|
+
showRenderedToast(options);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
closeRenderedToast();
|
|
147
|
+
});
|
|
148
|
+
}, [closeRenderedToast, showRenderedToast]);
|
|
149
|
+
// Delay the enter transition until after mount so the DOM can paint the
|
|
150
|
+
// offscreen starting position before we slide the toast into view.
|
|
151
|
+
(0, react_1.useEffect)(() => {
|
|
152
|
+
if (toastOptions && !isVisible) {
|
|
153
|
+
enterAnimationFrameRef.current = requestAnimationFrame(() => {
|
|
154
|
+
enterAnimationFrameRef.current = requestAnimationFrame(() => {
|
|
155
|
+
setCurrentIsVisible(true);
|
|
156
|
+
enterAnimationFrameRef.current = null;
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return () => {
|
|
161
|
+
clearPendingTimers();
|
|
162
|
+
};
|
|
163
|
+
}, [clearPendingTimers, setCurrentIsVisible, toastOptions]); // intentionally omit isVisible — only react to new toast options
|
|
164
|
+
// Auto-dismiss once the toast is visible, unless the caller requested a
|
|
165
|
+
// persistent toast.
|
|
166
|
+
(0, react_1.useEffect)(() => {
|
|
167
|
+
if (isVisible && toastOptions && !toastOptions.hasNoTimeout) {
|
|
168
|
+
autoDismissTimerRef.current = setTimeout(() => {
|
|
169
|
+
autoDismissTimerRef.current = null;
|
|
170
|
+
clearStoreToastOptions();
|
|
171
|
+
}, Toast_constants_1.TOAST_VISIBILITY_DURATION);
|
|
172
|
+
return () => {
|
|
173
|
+
clearPendingTimers();
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
return undefined;
|
|
177
|
+
}, [clearPendingTimers, isVisible, toastOptions]);
|
|
178
|
+
(0, react_1.useEffect)(() => {
|
|
179
|
+
return () => {
|
|
180
|
+
clearPendingTimers();
|
|
181
|
+
pendingToastRef.current = undefined;
|
|
182
|
+
toastOptionsRef.current = undefined;
|
|
183
|
+
isVisibleRef.current = false;
|
|
184
|
+
};
|
|
185
|
+
}, [clearPendingTimers]);
|
|
186
|
+
if (!toastOptions) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
const { onClose: toastOnClose, className: toastClassName, ...toastProps } = getToastProps(toastOptions);
|
|
190
|
+
return (react_1.default.createElement("div", { role: "status", "aria-live": "polite", "aria-atomic": "true", className: (0, tw_merge_1.twMerge)('pointer-events-none fixed inset-x-4 bottom-4 z-[1000] flex justify-center', className), ...props },
|
|
191
|
+
react_1.default.createElement("div", { className: "pointer-events-auto w-full transition-transform ease-in-out", style: {
|
|
192
|
+
transitionDuration: `${Toast_constants_1.TOAST_ANIMATION_DURATION}ms`,
|
|
193
|
+
transform: isVisible
|
|
194
|
+
? 'translateY(0)'
|
|
195
|
+
: 'translateY(calc(100% + 16px))',
|
|
196
|
+
} },
|
|
197
|
+
react_1.default.createElement(Toast_1.Toast, { ...toastProps, className: toastClassName, onClose: () => {
|
|
198
|
+
clearStoreToastOptions();
|
|
199
|
+
toastOnClose?.();
|
|
200
|
+
} }))));
|
|
201
|
+
});
|
|
202
|
+
ToasterComponent.displayName = 'Toaster';
|
|
203
|
+
exports.Toaster = ToasterComponent;
|
|
204
|
+
exports.toast = ((options) => {
|
|
205
|
+
setStoreToastOptions(options);
|
|
206
|
+
});
|
|
207
|
+
exports.toast.dismiss = () => {
|
|
208
|
+
clearStoreToastOptions();
|
|
209
|
+
};
|
|
210
|
+
//# sourceMappingURL=Toaster.cjs.map
|