@react-spectrum/toast 3.0.0-beta.12 → 3.0.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Toast.main.js +14 -10
- package/dist/Toast.main.js.map +1 -1
- package/dist/Toast.mjs +16 -12
- package/dist/Toast.module.js +16 -12
- package/dist/Toast.module.js.map +1 -1
- package/dist/ToastContainer.main.js +12 -3
- package/dist/ToastContainer.main.js.map +1 -1
- package/dist/ToastContainer.mjs +16 -3
- package/dist/ToastContainer.module.js +16 -3
- package/dist/ToastContainer.module.js.map +1 -1
- package/dist/Toaster.main.js +8 -7
- package/dist/Toaster.main.js.map +1 -1
- package/dist/Toaster.mjs +8 -6
- package/dist/Toaster.module.js +8 -6
- package/dist/Toaster.module.js.map +1 -1
- package/dist/{toastContainer.b596792c.css → toastContainer.da404f80.css} +27 -3
- package/dist/toastContainer.da404f80.css.map +1 -0
- package/dist/toastContainer_css.main.js +16 -7
- package/dist/toastContainer_css.main.js.map +1 -1
- package/dist/toastContainer_css.mjs +16 -7
- package/dist/toastContainer_css.module.js +16 -7
- package/dist/toastContainer_css.module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/{vars.85cde188.css → vars.c6e65b7e.css} +4 -7
- package/dist/vars.c6e65b7e.css.map +1 -0
- package/package.json +14 -14
- package/src/Toast.tsx +27 -22
- package/src/ToastContainer.tsx +15 -7
- package/src/Toaster.tsx +18 -15
- package/src/toastContainer.css +32 -2
- package/dist/toastContainer.b596792c.css.map +0 -1
- package/dist/vars.85cde188.css.map +0 -1
package/dist/Toast.main.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
var $1e709ec471c88b75$exports = require("./intlStrings.main.js");
|
|
2
|
-
require("./vars.
|
|
2
|
+
require("./vars.c6e65b7e.css");
|
|
3
3
|
var $b6e6aa676f8f9e47$exports = require("./toast_vars_css.main.js");
|
|
4
|
-
require("./toastContainer.
|
|
4
|
+
require("./toastContainer.da404f80.css");
|
|
5
5
|
var $e20782d0579ed886$exports = require("./toastContainer_css.main.js");
|
|
6
|
-
var $5b9f2c86c1b1395c$exports = require("./Toaster.main.js");
|
|
7
6
|
var $8Jify$spectrumiconsuiAlertMedium = require("@spectrum-icons/ui/AlertMedium");
|
|
8
7
|
var $8Jify$reactspectrumbutton = require("@react-spectrum/button");
|
|
9
8
|
var $8Jify$reactspectrumutils = require("@react-spectrum/utils");
|
|
@@ -12,6 +11,7 @@ var $8Jify$reactariautils = require("@react-aria/utils");
|
|
|
12
11
|
var $8Jify$spectrumiconsuiInfoMedium = require("@spectrum-icons/ui/InfoMedium");
|
|
13
12
|
var $8Jify$react = require("react");
|
|
14
13
|
var $8Jify$spectrumiconsuiSuccessMedium = require("@spectrum-icons/ui/SuccessMedium");
|
|
14
|
+
var $8Jify$reactariafocus = require("@react-aria/focus");
|
|
15
15
|
var $8Jify$reactariai18n = require("@react-aria/i18n");
|
|
16
16
|
var $8Jify$reactariatoast = require("@react-aria/toast");
|
|
17
17
|
|
|
@@ -55,28 +55,27 @@ const $6c5bd1047ecc310e$export$fde44257752a9f60 = {
|
|
|
55
55
|
positive: (0, ($parcel$interopDefault($8Jify$spectrumiconsuiSuccessMedium)))
|
|
56
56
|
};
|
|
57
57
|
function $6c5bd1047ecc310e$var$Toast(props, ref) {
|
|
58
|
-
var _state_visibleToasts_;
|
|
59
58
|
let { toast: { key: key, animation: animation, content: { children: children, variant: variant, actionLabel: actionLabel, onAction: onAction, shouldCloseOnAction: shouldCloseOnAction } }, state: state, ...otherProps } = props;
|
|
60
59
|
let domRef = (0, $8Jify$reactspectrumutils.useDOMRef)(ref);
|
|
61
|
-
let { closeButtonProps: closeButtonProps, titleProps: titleProps, toastProps: toastProps } = (0, $8Jify$reactariatoast.useToast)(props, state, domRef);
|
|
60
|
+
let { closeButtonProps: closeButtonProps, titleProps: titleProps, toastProps: toastProps, contentProps: contentProps } = (0, $8Jify$reactariatoast.useToast)(props, state, domRef);
|
|
62
61
|
let { styleProps: styleProps } = (0, $8Jify$reactspectrumutils.useStyleProps)(otherProps);
|
|
63
62
|
let stringFormatter = (0, $8Jify$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($1e709ec471c88b75$exports))), '@react-spectrum/toast');
|
|
64
63
|
let iconLabel = variant && variant !== 'neutral' ? stringFormatter.format(variant) : null;
|
|
65
64
|
let Icon = $6c5bd1047ecc310e$export$fde44257752a9f60[variant];
|
|
66
|
-
let isFocusVisible = (0, $8Jify$
|
|
65
|
+
let { isFocusVisible: isFocusVisible, focusProps: focusProps } = (0, $8Jify$reactariafocus.useFocusRing)();
|
|
67
66
|
const handleAction = ()=>{
|
|
68
67
|
if (onAction) onAction();
|
|
69
68
|
if (shouldCloseOnAction) state.close(key);
|
|
70
69
|
};
|
|
71
70
|
return /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement("div", {
|
|
72
71
|
...styleProps,
|
|
73
|
-
...toastProps,
|
|
72
|
+
...(0, $8Jify$reactariautils.mergeProps)(toastProps, focusProps),
|
|
74
73
|
...(0, $8Jify$reactariautils.filterDOMProps)(props.toast.content),
|
|
75
74
|
ref: domRef,
|
|
76
75
|
className: (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($b6e6aa676f8f9e47$exports))), 'spectrum-Toast', {
|
|
77
76
|
['spectrum-Toast--' + variant]: variant
|
|
78
77
|
}, styleProps.className, (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($e20782d0579ed886$exports))), 'spectrum-Toast', {
|
|
79
|
-
'focus-ring':
|
|
78
|
+
'focus-ring': isFocusVisible
|
|
80
79
|
})),
|
|
81
80
|
style: {
|
|
82
81
|
...styleProps.style,
|
|
@@ -86,20 +85,25 @@ function $6c5bd1047ecc310e$var$Toast(props, ref) {
|
|
|
86
85
|
onAnimationEnd: ()=>{
|
|
87
86
|
if (animation === 'exiting') state.remove(key);
|
|
88
87
|
}
|
|
88
|
+
}, /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement("div", {
|
|
89
|
+
...contentProps,
|
|
90
|
+
className: (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($e20782d0579ed886$exports))), 'spectrum-Toast-contentWrapper')
|
|
89
91
|
}, Icon && /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement(Icon, {
|
|
90
92
|
"aria-label": iconLabel,
|
|
91
93
|
UNSAFE_className: (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($b6e6aa676f8f9e47$exports))), 'spectrum-Toast-typeIcon')
|
|
92
94
|
}), /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement("div", {
|
|
93
|
-
className: (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($b6e6aa676f8f9e47$exports))), 'spectrum-Toast-body')
|
|
95
|
+
className: (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($b6e6aa676f8f9e47$exports))), 'spectrum-Toast-body'),
|
|
96
|
+
role: "presentation"
|
|
94
97
|
}, /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement("div", {
|
|
95
98
|
className: (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($b6e6aa676f8f9e47$exports))), 'spectrum-Toast-content'),
|
|
99
|
+
role: "presentation",
|
|
96
100
|
...titleProps
|
|
97
101
|
}, children), actionLabel && /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement((0, $8Jify$reactspectrumbutton.Button), {
|
|
98
102
|
onPress: handleAction,
|
|
99
103
|
UNSAFE_className: (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($b6e6aa676f8f9e47$exports))), 'spectrum-Button'),
|
|
100
104
|
variant: "secondary",
|
|
101
105
|
staticColor: "white"
|
|
102
|
-
}, actionLabel)), /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement("div", {
|
|
106
|
+
}, actionLabel))), /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement("div", {
|
|
103
107
|
className: (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($b6e6aa676f8f9e47$exports))), 'spectrum-Toast-buttons')
|
|
104
108
|
}, /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement((0, $8Jify$reactspectrumbutton.ClearButton), {
|
|
105
109
|
...closeButtonProps,
|
package/dist/Toast.main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;AAkCM,MAAM,4CAAQ;IACnB,MAAM,CAAA,GAAA,0DAAS;IACf,UAAU,CAAA,GAAA,2DAAU;IACpB,UAAU,CAAA,GAAA,6DAAY;AACxB;AAEA,SAAS,4BAAM,KAAyB,EAAE,GAA2B;
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;AAkCM,MAAM,4CAAQ;IACnB,MAAM,CAAA,GAAA,0DAAS;IACf,UAAU,CAAA,GAAA,2DAAU;IACpB,UAAU,CAAA,GAAA,6DAAY;AACxB;AAEA,SAAS,4BAAM,KAAyB,EAAE,GAA2B;IACnE,IAAI,EACF,OAAO,OACL,GAAG,aACH,SAAS,EACT,SAAS,YACP,QAAQ,WACR,OAAO,eACP,WAAW,YACX,QAAQ,uBACR,mBAAmB,EACpB,EACF,SACD,KAAK,EACL,GAAG,YACJ,GAAG;IACJ,IAAI,SAAS,CAAA,GAAA,mCAAQ,EAAE;IACvB,IAAI,oBACF,gBAAgB,cAChB,UAAU,cACV,UAAU,gBACV,YAAY,EACb,GAAG,CAAA,GAAA,8BAAO,EAAE,OAAO,OAAO;IAC3B,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,uCAAY,EAAE;IAEjC,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,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CAAK;QACJ,SAAS;QACT,kBAAkB,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,mDAAK,GAAG;QACrC,SAAQ;QACR,aAAY;OACX,8BAKT,0DAAC;QAAI,WAAW,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,mDAAK,GAAG;qBACjC,0DAAC,CAAA,GAAA,sCAAU;QAAG,GAAG,gBAAgB;QAAE,SAAQ;qBACzC,0DAAC,CAAA,GAAA,2DAAU;AAKrB;AAEA,IAAI,0DAAS,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC","sources":["packages/@react-spectrum/toast/src/Toast.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport AlertMedium from '@spectrum-icons/ui/AlertMedium';\nimport {Button, ClearButton} from '@react-spectrum/button';\nimport {classNames, useDOMRef, useStyleProps} from '@react-spectrum/utils';\nimport CrossMedium from '@spectrum-icons/ui/CrossMedium';\nimport {DOMProps, DOMRef} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport InfoMedium from '@spectrum-icons/ui/InfoMedium';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {QueuedToast, ToastState} from '@react-stately/toast';\nimport React from 'react';\nimport styles from '@adobe/spectrum-css-temp/components/toast/vars.css';\nimport SuccessMedium from '@spectrum-icons/ui/SuccessMedium';\nimport toastContainerStyles from './toastContainer.css';\nimport {useFocusRing} from '@react-aria/focus';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useToast} from '@react-aria/toast';\n\nexport interface SpectrumToastValue extends DOMProps {\n children: string,\n variant: 'positive' | 'negative' | 'info' | 'neutral',\n actionLabel?: string,\n onAction?: () => void,\n shouldCloseOnAction?: boolean\n}\n\nexport interface SpectrumToastProps {\n toast: QueuedToast<SpectrumToastValue>,\n state: ToastState<SpectrumToastValue>\n}\n\n// TODO: express should use filled icons...\nexport const ICONS = {\n info: InfoMedium,\n negative: AlertMedium,\n positive: SuccessMedium\n};\n\nfunction Toast(props: SpectrumToastProps, ref: DOMRef<HTMLDivElement>) {\n let {\n toast: {\n key,\n animation,\n content: {\n children,\n variant,\n actionLabel,\n onAction,\n shouldCloseOnAction\n }\n },\n state,\n ...otherProps\n } = props;\n let domRef = useDOMRef(ref);\n let {\n closeButtonProps,\n titleProps,\n toastProps,\n contentProps\n } = useToast(props, state, domRef);\n let {styleProps} = useStyleProps(otherProps);\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/toast');\n let iconLabel = variant && variant !== 'neutral' ? stringFormatter.format(variant) : null;\n let Icon = ICONS[variant];\n let {isFocusVisible, focusProps} = useFocusRing();\n\n const handleAction = () => {\n if (onAction) {\n onAction();\n }\n\n if (shouldCloseOnAction) {\n state.close(key);\n }\n };\n\n return (\n <div\n {...styleProps}\n {...mergeProps(toastProps, focusProps)}\n {...filterDOMProps(props.toast.content)}\n ref={domRef}\n className={classNames(styles,\n 'spectrum-Toast',\n {['spectrum-Toast--' + variant]: variant},\n styleProps.className,\n classNames(\n toastContainerStyles,\n 'spectrum-Toast',\n {'focus-ring': isFocusVisible}\n )\n )}\n style={{\n ...styleProps.style,\n zIndex: props.toast.priority\n }}\n data-animation={animation}\n onAnimationEnd={() => {\n if (animation === 'exiting') {\n state.remove(key);\n }\n }}>\n <div\n {...contentProps}\n className={classNames(toastContainerStyles, 'spectrum-Toast-contentWrapper')}>\n {Icon &&\n <Icon\n aria-label={iconLabel}\n UNSAFE_className={classNames(styles, 'spectrum-Toast-typeIcon')} />\n }\n <div className={classNames(styles, 'spectrum-Toast-body')} role=\"presentation\">\n <div className={classNames(styles, 'spectrum-Toast-content')} role=\"presentation\" {...titleProps}>{children}</div>\n {actionLabel &&\n <Button\n onPress={handleAction}\n UNSAFE_className={classNames(styles, 'spectrum-Button')}\n variant=\"secondary\"\n staticColor=\"white\">\n {actionLabel}\n </Button>\n }\n </div>\n </div>\n <div className={classNames(styles, 'spectrum-Toast-buttons')}>\n <ClearButton {...closeButtonProps} variant=\"overBackground\">\n <CrossMedium />\n </ClearButton>\n </div>\n </div>\n );\n}\n\nlet _Toast = React.forwardRef(Toast);\nexport {_Toast as Toast};\n"],"names":[],"version":3,"file":"Toast.main.js.map"}
|
package/dist/Toast.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import $iu2Jc$intlStringsmodulejs from "./intlStrings.mjs";
|
|
2
|
-
import "./vars.
|
|
2
|
+
import "./vars.c6e65b7e.css";
|
|
3
3
|
import $iu2Jc$toast_vars_cssmodulejs from "./toast_vars_css.mjs";
|
|
4
|
-
import "./toastContainer.
|
|
4
|
+
import "./toastContainer.da404f80.css";
|
|
5
5
|
import $iu2Jc$toastContainer_cssmodulejs from "./toastContainer_css.mjs";
|
|
6
|
-
import {ToasterContext as $e46feef4e4c28a4b$export$9194c0aa0cd7a9ff} from "./Toaster.mjs";
|
|
7
6
|
import $iu2Jc$spectrumiconsuiAlertMedium from "@spectrum-icons/ui/AlertMedium";
|
|
8
7
|
import {Button as $iu2Jc$Button, ClearButton as $iu2Jc$ClearButton} from "@react-spectrum/button";
|
|
9
8
|
import {useDOMRef as $iu2Jc$useDOMRef, useStyleProps as $iu2Jc$useStyleProps, classNames as $iu2Jc$classNames} from "@react-spectrum/utils";
|
|
10
9
|
import $iu2Jc$spectrumiconsuiCrossMedium from "@spectrum-icons/ui/CrossMedium";
|
|
11
|
-
import {filterDOMProps as $iu2Jc$filterDOMProps} from "@react-aria/utils";
|
|
10
|
+
import {mergeProps as $iu2Jc$mergeProps, filterDOMProps as $iu2Jc$filterDOMProps} from "@react-aria/utils";
|
|
12
11
|
import $iu2Jc$spectrumiconsuiInfoMedium from "@spectrum-icons/ui/InfoMedium";
|
|
13
|
-
import $iu2Jc$react
|
|
12
|
+
import $iu2Jc$react from "react";
|
|
14
13
|
import $iu2Jc$spectrumiconsuiSuccessMedium from "@spectrum-icons/ui/SuccessMedium";
|
|
14
|
+
import {useFocusRing as $iu2Jc$useFocusRing} from "@react-aria/focus";
|
|
15
15
|
import {useLocalizedStringFormatter as $iu2Jc$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
16
16
|
import {useToast as $iu2Jc$useToast} from "@react-aria/toast";
|
|
17
17
|
|
|
@@ -49,28 +49,27 @@ const $7e7a2952509f3a56$export$fde44257752a9f60 = {
|
|
|
49
49
|
positive: (0, $iu2Jc$spectrumiconsuiSuccessMedium)
|
|
50
50
|
};
|
|
51
51
|
function $7e7a2952509f3a56$var$Toast(props, ref) {
|
|
52
|
-
var _state_visibleToasts_;
|
|
53
52
|
let { toast: { key: key, animation: animation, content: { children: children, variant: variant, actionLabel: actionLabel, onAction: onAction, shouldCloseOnAction: shouldCloseOnAction } }, state: state, ...otherProps } = props;
|
|
54
53
|
let domRef = (0, $iu2Jc$useDOMRef)(ref);
|
|
55
|
-
let { closeButtonProps: closeButtonProps, titleProps: titleProps, toastProps: toastProps } = (0, $iu2Jc$useToast)(props, state, domRef);
|
|
54
|
+
let { closeButtonProps: closeButtonProps, titleProps: titleProps, toastProps: toastProps, contentProps: contentProps } = (0, $iu2Jc$useToast)(props, state, domRef);
|
|
56
55
|
let { styleProps: styleProps } = (0, $iu2Jc$useStyleProps)(otherProps);
|
|
57
56
|
let stringFormatter = (0, $iu2Jc$useLocalizedStringFormatter)((0, ($parcel$interopDefault($iu2Jc$intlStringsmodulejs))), '@react-spectrum/toast');
|
|
58
57
|
let iconLabel = variant && variant !== 'neutral' ? stringFormatter.format(variant) : null;
|
|
59
58
|
let Icon = $7e7a2952509f3a56$export$fde44257752a9f60[variant];
|
|
60
|
-
let isFocusVisible = (0, $iu2Jc$
|
|
59
|
+
let { isFocusVisible: isFocusVisible, focusProps: focusProps } = (0, $iu2Jc$useFocusRing)();
|
|
61
60
|
const handleAction = ()=>{
|
|
62
61
|
if (onAction) onAction();
|
|
63
62
|
if (shouldCloseOnAction) state.close(key);
|
|
64
63
|
};
|
|
65
64
|
return /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
66
65
|
...styleProps,
|
|
67
|
-
...toastProps,
|
|
66
|
+
...(0, $iu2Jc$mergeProps)(toastProps, focusProps),
|
|
68
67
|
...(0, $iu2Jc$filterDOMProps)(props.toast.content),
|
|
69
68
|
ref: domRef,
|
|
70
69
|
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast', {
|
|
71
70
|
['spectrum-Toast--' + variant]: variant
|
|
72
71
|
}, styleProps.className, (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toastContainer_cssmodulejs))), 'spectrum-Toast', {
|
|
73
|
-
'focus-ring':
|
|
72
|
+
'focus-ring': isFocusVisible
|
|
74
73
|
})),
|
|
75
74
|
style: {
|
|
76
75
|
...styleProps.style,
|
|
@@ -80,20 +79,25 @@ function $7e7a2952509f3a56$var$Toast(props, ref) {
|
|
|
80
79
|
onAnimationEnd: ()=>{
|
|
81
80
|
if (animation === 'exiting') state.remove(key);
|
|
82
81
|
}
|
|
82
|
+
}, /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
83
|
+
...contentProps,
|
|
84
|
+
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toastContainer_cssmodulejs))), 'spectrum-Toast-contentWrapper')
|
|
83
85
|
}, Icon && /*#__PURE__*/ (0, $iu2Jc$react).createElement(Icon, {
|
|
84
86
|
"aria-label": iconLabel,
|
|
85
87
|
UNSAFE_className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-typeIcon')
|
|
86
88
|
}), /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
87
|
-
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-body')
|
|
89
|
+
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-body'),
|
|
90
|
+
role: "presentation"
|
|
88
91
|
}, /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
89
92
|
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-content'),
|
|
93
|
+
role: "presentation",
|
|
90
94
|
...titleProps
|
|
91
95
|
}, children), actionLabel && /*#__PURE__*/ (0, $iu2Jc$react).createElement((0, $iu2Jc$Button), {
|
|
92
96
|
onPress: handleAction,
|
|
93
97
|
UNSAFE_className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Button'),
|
|
94
98
|
variant: "secondary",
|
|
95
99
|
staticColor: "white"
|
|
96
|
-
}, actionLabel)), /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
100
|
+
}, actionLabel))), /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
97
101
|
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-buttons')
|
|
98
102
|
}, /*#__PURE__*/ (0, $iu2Jc$react).createElement((0, $iu2Jc$ClearButton), {
|
|
99
103
|
...closeButtonProps,
|
package/dist/Toast.module.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import $iu2Jc$intlStringsmodulejs from "./intlStrings.module.js";
|
|
2
|
-
import "./vars.
|
|
2
|
+
import "./vars.c6e65b7e.css";
|
|
3
3
|
import $iu2Jc$toast_vars_cssmodulejs from "./toast_vars_css.module.js";
|
|
4
|
-
import "./toastContainer.
|
|
4
|
+
import "./toastContainer.da404f80.css";
|
|
5
5
|
import $iu2Jc$toastContainer_cssmodulejs from "./toastContainer_css.module.js";
|
|
6
|
-
import {ToasterContext as $e46feef4e4c28a4b$export$9194c0aa0cd7a9ff} from "./Toaster.module.js";
|
|
7
6
|
import $iu2Jc$spectrumiconsuiAlertMedium from "@spectrum-icons/ui/AlertMedium";
|
|
8
7
|
import {Button as $iu2Jc$Button, ClearButton as $iu2Jc$ClearButton} from "@react-spectrum/button";
|
|
9
8
|
import {useDOMRef as $iu2Jc$useDOMRef, useStyleProps as $iu2Jc$useStyleProps, classNames as $iu2Jc$classNames} from "@react-spectrum/utils";
|
|
10
9
|
import $iu2Jc$spectrumiconsuiCrossMedium from "@spectrum-icons/ui/CrossMedium";
|
|
11
|
-
import {filterDOMProps as $iu2Jc$filterDOMProps} from "@react-aria/utils";
|
|
10
|
+
import {mergeProps as $iu2Jc$mergeProps, filterDOMProps as $iu2Jc$filterDOMProps} from "@react-aria/utils";
|
|
12
11
|
import $iu2Jc$spectrumiconsuiInfoMedium from "@spectrum-icons/ui/InfoMedium";
|
|
13
|
-
import $iu2Jc$react
|
|
12
|
+
import $iu2Jc$react from "react";
|
|
14
13
|
import $iu2Jc$spectrumiconsuiSuccessMedium from "@spectrum-icons/ui/SuccessMedium";
|
|
14
|
+
import {useFocusRing as $iu2Jc$useFocusRing} from "@react-aria/focus";
|
|
15
15
|
import {useLocalizedStringFormatter as $iu2Jc$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
16
16
|
import {useToast as $iu2Jc$useToast} from "@react-aria/toast";
|
|
17
17
|
|
|
@@ -49,28 +49,27 @@ const $7e7a2952509f3a56$export$fde44257752a9f60 = {
|
|
|
49
49
|
positive: (0, $iu2Jc$spectrumiconsuiSuccessMedium)
|
|
50
50
|
};
|
|
51
51
|
function $7e7a2952509f3a56$var$Toast(props, ref) {
|
|
52
|
-
var _state_visibleToasts_;
|
|
53
52
|
let { toast: { key: key, animation: animation, content: { children: children, variant: variant, actionLabel: actionLabel, onAction: onAction, shouldCloseOnAction: shouldCloseOnAction } }, state: state, ...otherProps } = props;
|
|
54
53
|
let domRef = (0, $iu2Jc$useDOMRef)(ref);
|
|
55
|
-
let { closeButtonProps: closeButtonProps, titleProps: titleProps, toastProps: toastProps } = (0, $iu2Jc$useToast)(props, state, domRef);
|
|
54
|
+
let { closeButtonProps: closeButtonProps, titleProps: titleProps, toastProps: toastProps, contentProps: contentProps } = (0, $iu2Jc$useToast)(props, state, domRef);
|
|
56
55
|
let { styleProps: styleProps } = (0, $iu2Jc$useStyleProps)(otherProps);
|
|
57
56
|
let stringFormatter = (0, $iu2Jc$useLocalizedStringFormatter)((0, ($parcel$interopDefault($iu2Jc$intlStringsmodulejs))), '@react-spectrum/toast');
|
|
58
57
|
let iconLabel = variant && variant !== 'neutral' ? stringFormatter.format(variant) : null;
|
|
59
58
|
let Icon = $7e7a2952509f3a56$export$fde44257752a9f60[variant];
|
|
60
|
-
let isFocusVisible = (0, $iu2Jc$
|
|
59
|
+
let { isFocusVisible: isFocusVisible, focusProps: focusProps } = (0, $iu2Jc$useFocusRing)();
|
|
61
60
|
const handleAction = ()=>{
|
|
62
61
|
if (onAction) onAction();
|
|
63
62
|
if (shouldCloseOnAction) state.close(key);
|
|
64
63
|
};
|
|
65
64
|
return /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
66
65
|
...styleProps,
|
|
67
|
-
...toastProps,
|
|
66
|
+
...(0, $iu2Jc$mergeProps)(toastProps, focusProps),
|
|
68
67
|
...(0, $iu2Jc$filterDOMProps)(props.toast.content),
|
|
69
68
|
ref: domRef,
|
|
70
69
|
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast', {
|
|
71
70
|
['spectrum-Toast--' + variant]: variant
|
|
72
71
|
}, styleProps.className, (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toastContainer_cssmodulejs))), 'spectrum-Toast', {
|
|
73
|
-
'focus-ring':
|
|
72
|
+
'focus-ring': isFocusVisible
|
|
74
73
|
})),
|
|
75
74
|
style: {
|
|
76
75
|
...styleProps.style,
|
|
@@ -80,20 +79,25 @@ function $7e7a2952509f3a56$var$Toast(props, ref) {
|
|
|
80
79
|
onAnimationEnd: ()=>{
|
|
81
80
|
if (animation === 'exiting') state.remove(key);
|
|
82
81
|
}
|
|
82
|
+
}, /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
83
|
+
...contentProps,
|
|
84
|
+
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toastContainer_cssmodulejs))), 'spectrum-Toast-contentWrapper')
|
|
83
85
|
}, Icon && /*#__PURE__*/ (0, $iu2Jc$react).createElement(Icon, {
|
|
84
86
|
"aria-label": iconLabel,
|
|
85
87
|
UNSAFE_className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-typeIcon')
|
|
86
88
|
}), /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
87
|
-
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-body')
|
|
89
|
+
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-body'),
|
|
90
|
+
role: "presentation"
|
|
88
91
|
}, /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
89
92
|
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-content'),
|
|
93
|
+
role: "presentation",
|
|
90
94
|
...titleProps
|
|
91
95
|
}, children), actionLabel && /*#__PURE__*/ (0, $iu2Jc$react).createElement((0, $iu2Jc$Button), {
|
|
92
96
|
onPress: handleAction,
|
|
93
97
|
UNSAFE_className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Button'),
|
|
94
98
|
variant: "secondary",
|
|
95
99
|
staticColor: "white"
|
|
96
|
-
}, actionLabel)), /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
100
|
+
}, actionLabel))), /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
97
101
|
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-buttons')
|
|
98
102
|
}, /*#__PURE__*/ (0, $iu2Jc$react).createElement((0, $iu2Jc$ClearButton), {
|
|
99
103
|
...closeButtonProps,
|
package/dist/Toast.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;AAkCM,MAAM,4CAAQ;IACnB,MAAM,CAAA,GAAA,gCAAS;IACf,UAAU,CAAA,GAAA,iCAAU;IACpB,UAAU,CAAA,GAAA,mCAAY;AACxB;AAEA,SAAS,4BAAM,KAAyB,EAAE,GAA2B;
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;AAkCM,MAAM,4CAAQ;IACnB,MAAM,CAAA,GAAA,gCAAS;IACf,UAAU,CAAA,GAAA,iCAAU;IACpB,UAAU,CAAA,GAAA,mCAAY;AACxB;AAEA,SAAS,4BAAM,KAAyB,EAAE,GAA2B;IACnE,IAAI,EACF,OAAO,OACL,GAAG,aACH,SAAS,EACT,SAAS,YACP,QAAQ,WACR,OAAO,eACP,WAAW,YACX,QAAQ,uBACR,mBAAmB,EACpB,EACF,SACD,KAAK,EACL,GAAG,YACJ,GAAG;IACJ,IAAI,SAAS,CAAA,GAAA,gBAAQ,EAAE;IACvB,IAAI,oBACF,gBAAgB,cAChB,UAAU,cACV,UAAU,gBACV,YAAY,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B,MAAK;qBAC9D,gCAAC;QAAI,WAAW,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,uDAAK,GAAG;QAA2B,MAAK;QAAgB,GAAG,UAAU;OAAG,WAClG,6BACC,gCAAC,CAAA,GAAA,aAAK;QACJ,SAAS;QACT,kBAAkB,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,uDAAK,GAAG;QACrC,SAAQ;QACR,aAAY;OACX,8BAKT,gCAAC;QAAI,WAAW,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,uDAAK,GAAG;qBACjC,gCAAC,CAAA,GAAA,kBAAU;QAAG,GAAG,gBAAgB;QAAE,SAAQ;qBACzC,gCAAC,CAAA,GAAA,iCAAU;AAKrB;AAEA,IAAI,0DAAS,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC","sources":["packages/@react-spectrum/toast/src/Toast.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport AlertMedium from '@spectrum-icons/ui/AlertMedium';\nimport {Button, ClearButton} from '@react-spectrum/button';\nimport {classNames, useDOMRef, useStyleProps} from '@react-spectrum/utils';\nimport CrossMedium from '@spectrum-icons/ui/CrossMedium';\nimport {DOMProps, DOMRef} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport InfoMedium from '@spectrum-icons/ui/InfoMedium';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {QueuedToast, ToastState} from '@react-stately/toast';\nimport React from 'react';\nimport styles from '@adobe/spectrum-css-temp/components/toast/vars.css';\nimport SuccessMedium from '@spectrum-icons/ui/SuccessMedium';\nimport toastContainerStyles from './toastContainer.css';\nimport {useFocusRing} from '@react-aria/focus';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useToast} from '@react-aria/toast';\n\nexport interface SpectrumToastValue extends DOMProps {\n children: string,\n variant: 'positive' | 'negative' | 'info' | 'neutral',\n actionLabel?: string,\n onAction?: () => void,\n shouldCloseOnAction?: boolean\n}\n\nexport interface SpectrumToastProps {\n toast: QueuedToast<SpectrumToastValue>,\n state: ToastState<SpectrumToastValue>\n}\n\n// TODO: express should use filled icons...\nexport const ICONS = {\n info: InfoMedium,\n negative: AlertMedium,\n positive: SuccessMedium\n};\n\nfunction Toast(props: SpectrumToastProps, ref: DOMRef<HTMLDivElement>) {\n let {\n toast: {\n key,\n animation,\n content: {\n children,\n variant,\n actionLabel,\n onAction,\n shouldCloseOnAction\n }\n },\n state,\n ...otherProps\n } = props;\n let domRef = useDOMRef(ref);\n let {\n closeButtonProps,\n titleProps,\n toastProps,\n contentProps\n } = useToast(props, state, domRef);\n let {styleProps} = useStyleProps(otherProps);\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/toast');\n let iconLabel = variant && variant !== 'neutral' ? stringFormatter.format(variant) : null;\n let Icon = ICONS[variant];\n let {isFocusVisible, focusProps} = useFocusRing();\n\n const handleAction = () => {\n if (onAction) {\n onAction();\n }\n\n if (shouldCloseOnAction) {\n state.close(key);\n }\n };\n\n return (\n <div\n {...styleProps}\n {...mergeProps(toastProps, focusProps)}\n {...filterDOMProps(props.toast.content)}\n ref={domRef}\n className={classNames(styles,\n 'spectrum-Toast',\n {['spectrum-Toast--' + variant]: variant},\n styleProps.className,\n classNames(\n toastContainerStyles,\n 'spectrum-Toast',\n {'focus-ring': isFocusVisible}\n )\n )}\n style={{\n ...styleProps.style,\n zIndex: props.toast.priority\n }}\n data-animation={animation}\n onAnimationEnd={() => {\n if (animation === 'exiting') {\n state.remove(key);\n }\n }}>\n <div\n {...contentProps}\n className={classNames(toastContainerStyles, 'spectrum-Toast-contentWrapper')}>\n {Icon &&\n <Icon\n aria-label={iconLabel}\n UNSAFE_className={classNames(styles, 'spectrum-Toast-typeIcon')} />\n }\n <div className={classNames(styles, 'spectrum-Toast-body')} role=\"presentation\">\n <div className={classNames(styles, 'spectrum-Toast-content')} role=\"presentation\" {...titleProps}>{children}</div>\n {actionLabel &&\n <Button\n onPress={handleAction}\n UNSAFE_className={classNames(styles, 'spectrum-Button')}\n variant=\"secondary\"\n staticColor=\"white\">\n {actionLabel}\n </Button>\n }\n </div>\n </div>\n <div className={classNames(styles, 'spectrum-Toast-buttons')}>\n <ClearButton {...closeButtonProps} variant=\"overBackground\">\n <CrossMedium />\n </ClearButton>\n </div>\n </div>\n );\n}\n\nlet _Toast = React.forwardRef(Toast);\nexport {_Toast as Toast};\n"],"names":[],"version":3,"file":"Toast.module.js.map"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
var $6c5bd1047ecc310e$exports = require("./Toast.main.js");
|
|
2
|
+
require("./toastContainer.da404f80.css");
|
|
3
|
+
var $e20782d0579ed886$exports = require("./toastContainer_css.main.js");
|
|
2
4
|
var $5b9f2c86c1b1395c$exports = require("./Toaster.main.js");
|
|
5
|
+
var $5IVGU$reactspectrumutils = require("@react-spectrum/utils");
|
|
3
6
|
var $5IVGU$reactariautils = require("@react-aria/utils");
|
|
4
7
|
var $5IVGU$react = require("react");
|
|
5
8
|
var $5IVGU$reactstatelytoast = require("@react-stately/toast");
|
|
@@ -32,6 +35,8 @@ $parcel$export(module.exports, "ToastQueue", () => $56cdf77f3be52eaf$export$f1f8
|
|
|
32
35
|
|
|
33
36
|
|
|
34
37
|
|
|
38
|
+
|
|
39
|
+
|
|
35
40
|
// There is a single global toast queue instance for the whole app, initialized lazily.
|
|
36
41
|
let $56cdf77f3be52eaf$var$globalToastQueue = null;
|
|
37
42
|
function $56cdf77f3be52eaf$var$getGlobalToastQueue() {
|
|
@@ -64,7 +69,7 @@ function $56cdf77f3be52eaf$export$f2815235e76a62b9(props) {
|
|
|
64
69
|
// Only the first one will actually render.
|
|
65
70
|
// We use a ref to do this, since it will have a stable identity
|
|
66
71
|
// over the lifetime of the component.
|
|
67
|
-
let ref = (0, $5IVGU$react.useRef)();
|
|
72
|
+
let ref = (0, $5IVGU$react.useRef)(undefined);
|
|
68
73
|
// eslint-disable-next-line arrow-body-style
|
|
69
74
|
(0, $5IVGU$react.useEffect)(()=>{
|
|
70
75
|
$56cdf77f3be52eaf$var$toastProviders.add(ref);
|
|
@@ -86,11 +91,15 @@ function $56cdf77f3be52eaf$export$f2815235e76a62b9(props) {
|
|
|
86
91
|
if (ref === activeToastContainer && state.visibleToasts.length > 0) return /*#__PURE__*/ (0, ($parcel$interopDefault($5IVGU$react))).createElement((0, $5b9f2c86c1b1395c$exports.Toaster), {
|
|
87
92
|
state: state,
|
|
88
93
|
...props
|
|
89
|
-
},
|
|
94
|
+
}, /*#__PURE__*/ (0, ($parcel$interopDefault($5IVGU$react))).createElement("ol", {
|
|
95
|
+
className: (0, $5IVGU$reactspectrumutils.classNames)((0, ($parcel$interopDefault($e20782d0579ed886$exports))), 'spectrum-ToastContainer-list')
|
|
96
|
+
}, state.visibleToasts.slice().reverse().map((toast)=>/*#__PURE__*/ (0, ($parcel$interopDefault($5IVGU$react))).createElement("li", {
|
|
90
97
|
key: toast.key,
|
|
98
|
+
className: (0, $5IVGU$reactspectrumutils.classNames)((0, ($parcel$interopDefault($e20782d0579ed886$exports))), 'spectrum-ToastContainer-listitem')
|
|
99
|
+
}, /*#__PURE__*/ (0, ($parcel$interopDefault($5IVGU$react))).createElement((0, $6c5bd1047ecc310e$exports.Toast), {
|
|
91
100
|
toast: toast,
|
|
92
101
|
state: state
|
|
93
|
-
})));
|
|
102
|
+
})))));
|
|
94
103
|
return null;
|
|
95
104
|
}
|
|
96
105
|
function $56cdf77f3be52eaf$var$addToast(children, variant, options = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"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AS,QAAgB,EAAE,UAAgC,CAAC,CAAC;QAC3D,OAAO,+BAAS,UAAU,YAAY;IACxC;IACA,6BAA6B,GAC7B,UAAS,QAAgB,EAAE,UAAgC,CAAC,CAAC;QAC3D,OAAO,+BAAS,UAAU,YAAY;IACxC;IACA,mCAAmC,GACnC,MAAK,QAAgB,EAAE,UAAgC,CAAC,CAAC;QACvD,OAAO,+BAAS,UAAU,QAAQ;IACpC;AACF","sources":["packages/@react-spectrum/toast/src/ToastContainer.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaToastRegionProps} from '@react-aria/toast';\nimport {classNames} from '@react-spectrum/utils';\nimport {DOMProps} from '@react-types/shared';\nimport {filterDOMProps} from '@react-aria/utils';\nimport React, {ReactElement, useEffect, useRef} from 'react';\nimport {SpectrumToastValue, Toast} from './Toast';\nimport toastContainerStyles from './toastContainer.css';\nimport {Toaster} from './Toaster';\nimport {ToastOptions, ToastQueue, useToastQueue} from '@react-stately/toast';\nimport {useSyncExternalStore} from 'use-sync-external-store/shim/index.js';\n\nexport interface SpectrumToastContainerProps extends AriaToastRegionProps {}\n\nexport interface SpectrumToastOptions extends Omit<ToastOptions, 'priority'>, DOMProps {\n /** A label for the action button within the toast. */\n actionLabel?: string,\n /** Handler that is called when the action button is pressed. */\n onAction?: () => void,\n /** Whether the toast should automatically close when an action is performed. */\n shouldCloseOnAction?: boolean\n}\n\ntype CloseFunction = () => void;\n\n// There is a single global toast queue instance for the whole app, initialized lazily.\nlet globalToastQueue: ToastQueue<SpectrumToastValue> | null = null;\nfunction getGlobalToastQueue() {\n if (!globalToastQueue) {\n globalToastQueue = new ToastQueue({\n maxVisibleToasts: Infinity,\n hasExitAnimation: true\n });\n }\n\n return globalToastQueue;\n}\n\n// For testing. Not exported from the package index.\nexport function clearToastQueue() {\n globalToastQueue = null;\n}\n\nlet toastProviders = new Set();\nlet subscriptions = new Set<() => void>();\nfunction subscribe(fn: () => void) {\n subscriptions.add(fn);\n return () => subscriptions.delete(fn);\n}\n\nfunction triggerSubscriptions() {\n for (let fn of subscriptions) {\n fn();\n }\n}\n\nfunction getActiveToastContainer() {\n return toastProviders.values().next().value;\n}\n\nfunction useActiveToastContainer() {\n return useSyncExternalStore(subscribe, getActiveToastContainer, getActiveToastContainer);\n}\n\n/**\n * A ToastContainer renders the queued toasts in an application. It should be placed\n * at the root of the app.\n */\nexport function ToastContainer(props: SpectrumToastContainerProps): ReactElement {\n // Track all toast provider instances in a set.\n // Only the first one will actually render.\n // We use a ref to do this, since it will have a stable identity\n // over the lifetime of the component.\n let ref = useRef(undefined);\n\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n toastProviders.add(ref);\n triggerSubscriptions();\n\n return () => {\n // When this toast provider unmounts, reset all animations so that\n // when the new toast provider renders, it is seamless.\n for (let toast of getGlobalToastQueue().visibleToasts) {\n toast.animation = null;\n }\n\n // Remove this toast provider, and call subscriptions.\n // This will cause all other instances to re-render,\n // and the first one to become the new active toast provider.\n toastProviders.delete(ref);\n triggerSubscriptions();\n };\n }, []);\n\n // Only render if this is the active toast provider instance, and there are visible toasts.\n let activeToastContainer = useActiveToastContainer();\n let state = useToastQueue(getGlobalToastQueue());\n\n if (ref === activeToastContainer && state.visibleToasts.length > 0) {\n return (\n <Toaster state={state} {...props}>\n <ol className={classNames(toastContainerStyles, 'spectrum-ToastContainer-list')}>\n {state.visibleToasts.slice().reverse().map((toast) => (\n <li\n key={toast.key}\n className={classNames(toastContainerStyles, 'spectrum-ToastContainer-listitem')}>\n <Toast\n toast={toast}\n state={state} />\n </li>\n ))}\n </ol>\n </Toaster>\n );\n }\n\n return null;\n}\n\nfunction addToast(children: string, variant: SpectrumToastValue['variant'], options: SpectrumToastOptions = {}) {\n // Dispatch a custom event so that toasts can be intercepted and re-targeted, e.g. when inside an iframe.\n if (typeof CustomEvent !== 'undefined' && typeof window !== 'undefined') {\n let event = new CustomEvent('react-spectrum-toast', {\n cancelable: true,\n bubbles: true,\n detail: {\n children,\n variant,\n options\n }\n });\n\n let shouldContinue = window.dispatchEvent(event);\n if (!shouldContinue) {\n return;\n }\n }\n\n let value = {\n children,\n variant,\n actionLabel: options.actionLabel,\n onAction: options.onAction,\n shouldCloseOnAction: options.shouldCloseOnAction,\n ...filterDOMProps(options)\n };\n\n // Minimum time of 5s from https://spectrum.adobe.com/page/toast/#Auto-dismissible\n // Actionable toasts cannot be auto dismissed. That would fail WCAG SC 2.2.1.\n // It is debatable whether non-actionable toasts would also fail.\n let timeout = options.timeout && !options.onAction ? Math.max(options.timeout, 5000) : null;\n let queue = getGlobalToastQueue();\n let key = queue.add(value, {timeout, onClose: options.onClose});\n return () => queue.close(key);\n}\n\nconst SpectrumToastQueue = {\n /** Queues a neutral toast. */\n neutral(children: string, options: SpectrumToastOptions = {}): CloseFunction {\n return addToast(children, 'neutral', options);\n },\n /** Queues a positive toast. */\n positive(children: string, options: SpectrumToastOptions = {}): CloseFunction {\n return addToast(children, 'positive', options);\n },\n /** Queues a negative toast. */\n negative(children: string, options: SpectrumToastOptions = {}): CloseFunction {\n return addToast(children, 'negative', options);\n },\n /** Queues an informational toast. */\n info(children: string, options: SpectrumToastOptions = {}): CloseFunction {\n return addToast(children, 'info', options);\n }\n};\n\nexport {SpectrumToastQueue as ToastQueue};\n"],"names":[],"version":3,"file":"ToastContainer.main.js.map"}
|
package/dist/ToastContainer.mjs
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import {Toast as $7e7a2952509f3a56$export$8d8dc7d5f743331b} from "./Toast.mjs";
|
|
2
|
+
import "./toastContainer.da404f80.css";
|
|
3
|
+
import $5lmgI$toastContainer_cssmodulejs from "./toastContainer_css.mjs";
|
|
2
4
|
import {Toaster as $e46feef4e4c28a4b$export$fb98e3a2a4cd92d7} from "./Toaster.mjs";
|
|
5
|
+
import {classNames as $5lmgI$classNames} from "@react-spectrum/utils";
|
|
3
6
|
import {filterDOMProps as $5lmgI$filterDOMProps} from "@react-aria/utils";
|
|
4
7
|
import $5lmgI$react, {useRef as $5lmgI$useRef, useEffect as $5lmgI$useEffect} from "react";
|
|
5
8
|
import {ToastQueue as $5lmgI$ToastQueue, useToastQueue as $5lmgI$useToastQueue} from "@react-stately/toast";
|
|
6
9
|
import {useSyncExternalStore as $5lmgI$useSyncExternalStore} from "use-sync-external-store/shim/index.js";
|
|
7
10
|
|
|
11
|
+
|
|
12
|
+
function $parcel$interopDefault(a) {
|
|
13
|
+
return a && a.__esModule ? a.default : a;
|
|
14
|
+
}
|
|
8
15
|
/*
|
|
9
16
|
* Copyright 2020 Adobe. All rights reserved.
|
|
10
17
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -21,6 +28,8 @@ import {useSyncExternalStore as $5lmgI$useSyncExternalStore} from "use-sync-exte
|
|
|
21
28
|
|
|
22
29
|
|
|
23
30
|
|
|
31
|
+
|
|
32
|
+
|
|
24
33
|
// There is a single global toast queue instance for the whole app, initialized lazily.
|
|
25
34
|
let $02c59b34bd70955a$var$globalToastQueue = null;
|
|
26
35
|
function $02c59b34bd70955a$var$getGlobalToastQueue() {
|
|
@@ -53,7 +62,7 @@ function $02c59b34bd70955a$export$f2815235e76a62b9(props) {
|
|
|
53
62
|
// Only the first one will actually render.
|
|
54
63
|
// We use a ref to do this, since it will have a stable identity
|
|
55
64
|
// over the lifetime of the component.
|
|
56
|
-
let ref = (0, $5lmgI$useRef)();
|
|
65
|
+
let ref = (0, $5lmgI$useRef)(undefined);
|
|
57
66
|
// eslint-disable-next-line arrow-body-style
|
|
58
67
|
(0, $5lmgI$useEffect)(()=>{
|
|
59
68
|
$02c59b34bd70955a$var$toastProviders.add(ref);
|
|
@@ -75,11 +84,15 @@ function $02c59b34bd70955a$export$f2815235e76a62b9(props) {
|
|
|
75
84
|
if (ref === activeToastContainer && state.visibleToasts.length > 0) return /*#__PURE__*/ (0, $5lmgI$react).createElement((0, $e46feef4e4c28a4b$export$fb98e3a2a4cd92d7), {
|
|
76
85
|
state: state,
|
|
77
86
|
...props
|
|
78
|
-
},
|
|
87
|
+
}, /*#__PURE__*/ (0, $5lmgI$react).createElement("ol", {
|
|
88
|
+
className: (0, $5lmgI$classNames)((0, ($parcel$interopDefault($5lmgI$toastContainer_cssmodulejs))), 'spectrum-ToastContainer-list')
|
|
89
|
+
}, state.visibleToasts.slice().reverse().map((toast)=>/*#__PURE__*/ (0, $5lmgI$react).createElement("li", {
|
|
79
90
|
key: toast.key,
|
|
91
|
+
className: (0, $5lmgI$classNames)((0, ($parcel$interopDefault($5lmgI$toastContainer_cssmodulejs))), 'spectrum-ToastContainer-listitem')
|
|
92
|
+
}, /*#__PURE__*/ (0, $5lmgI$react).createElement((0, $7e7a2952509f3a56$export$8d8dc7d5f743331b), {
|
|
80
93
|
toast: toast,
|
|
81
94
|
state: state
|
|
82
|
-
})));
|
|
95
|
+
})))));
|
|
83
96
|
return null;
|
|
84
97
|
}
|
|
85
98
|
function $02c59b34bd70955a$var$addToast(children, variant, options = {}) {
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import {Toast as $7e7a2952509f3a56$export$8d8dc7d5f743331b} from "./Toast.module.js";
|
|
2
|
+
import "./toastContainer.da404f80.css";
|
|
3
|
+
import $5lmgI$toastContainer_cssmodulejs from "./toastContainer_css.module.js";
|
|
2
4
|
import {Toaster as $e46feef4e4c28a4b$export$fb98e3a2a4cd92d7} from "./Toaster.module.js";
|
|
5
|
+
import {classNames as $5lmgI$classNames} from "@react-spectrum/utils";
|
|
3
6
|
import {filterDOMProps as $5lmgI$filterDOMProps} from "@react-aria/utils";
|
|
4
7
|
import $5lmgI$react, {useRef as $5lmgI$useRef, useEffect as $5lmgI$useEffect} from "react";
|
|
5
8
|
import {ToastQueue as $5lmgI$ToastQueue, useToastQueue as $5lmgI$useToastQueue} from "@react-stately/toast";
|
|
6
9
|
import {useSyncExternalStore as $5lmgI$useSyncExternalStore} from "use-sync-external-store/shim/index.js";
|
|
7
10
|
|
|
11
|
+
|
|
12
|
+
function $parcel$interopDefault(a) {
|
|
13
|
+
return a && a.__esModule ? a.default : a;
|
|
14
|
+
}
|
|
8
15
|
/*
|
|
9
16
|
* Copyright 2020 Adobe. All rights reserved.
|
|
10
17
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -21,6 +28,8 @@ import {useSyncExternalStore as $5lmgI$useSyncExternalStore} from "use-sync-exte
|
|
|
21
28
|
|
|
22
29
|
|
|
23
30
|
|
|
31
|
+
|
|
32
|
+
|
|
24
33
|
// There is a single global toast queue instance for the whole app, initialized lazily.
|
|
25
34
|
let $02c59b34bd70955a$var$globalToastQueue = null;
|
|
26
35
|
function $02c59b34bd70955a$var$getGlobalToastQueue() {
|
|
@@ -53,7 +62,7 @@ function $02c59b34bd70955a$export$f2815235e76a62b9(props) {
|
|
|
53
62
|
// Only the first one will actually render.
|
|
54
63
|
// We use a ref to do this, since it will have a stable identity
|
|
55
64
|
// over the lifetime of the component.
|
|
56
|
-
let ref = (0, $5lmgI$useRef)();
|
|
65
|
+
let ref = (0, $5lmgI$useRef)(undefined);
|
|
57
66
|
// eslint-disable-next-line arrow-body-style
|
|
58
67
|
(0, $5lmgI$useEffect)(()=>{
|
|
59
68
|
$02c59b34bd70955a$var$toastProviders.add(ref);
|
|
@@ -75,11 +84,15 @@ function $02c59b34bd70955a$export$f2815235e76a62b9(props) {
|
|
|
75
84
|
if (ref === activeToastContainer && state.visibleToasts.length > 0) return /*#__PURE__*/ (0, $5lmgI$react).createElement((0, $e46feef4e4c28a4b$export$fb98e3a2a4cd92d7), {
|
|
76
85
|
state: state,
|
|
77
86
|
...props
|
|
78
|
-
},
|
|
87
|
+
}, /*#__PURE__*/ (0, $5lmgI$react).createElement("ol", {
|
|
88
|
+
className: (0, $5lmgI$classNames)((0, ($parcel$interopDefault($5lmgI$toastContainer_cssmodulejs))), 'spectrum-ToastContainer-list')
|
|
89
|
+
}, state.visibleToasts.slice().reverse().map((toast)=>/*#__PURE__*/ (0, $5lmgI$react).createElement("li", {
|
|
79
90
|
key: toast.key,
|
|
91
|
+
className: (0, $5lmgI$classNames)((0, ($parcel$interopDefault($5lmgI$toastContainer_cssmodulejs))), 'spectrum-ToastContainer-listitem')
|
|
92
|
+
}, /*#__PURE__*/ (0, $5lmgI$react).createElement((0, $7e7a2952509f3a56$export$8d8dc7d5f743331b), {
|
|
80
93
|
toast: toast,
|
|
81
94
|
state: state
|
|
82
|
-
})));
|
|
95
|
+
})))));
|
|
83
96
|
return null;
|
|
84
97
|
}
|
|
85
98
|
function $02c59b34bd70955a$var$addToast(children, variant, options = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AA0BD,uFAAuF;AACvF,IAAI,yCAA0D;AAC9D,SAAS;IACP,IAAI,CAAC,wCACH,yCAAmB,IAAI,CAAA,GAAA,iBAAS,EAAE;QAChC,kBAAkB;QAClB,kBAAkB;IACpB;IAGF,OAAO;AACT;AAGO,SAAS;IACd,yCAAmB;AACrB;AAEA,IAAI,uCAAiB,IAAI;AACzB,IAAI,sCAAgB,IAAI;AACxB,SAAS,gCAAU,EAAc;IAC/B,oCAAc,GAAG,CAAC;IAClB,OAAO,IAAM,oCAAc,MAAM,CAAC;AACpC;AAEA,SAAS;IACP,KAAK,IAAI,MAAM,oCACb;AAEJ;AAEA,SAAS;IACP,OAAO,qCAAe,MAAM,GAAG,IAAI,GAAG,KAAK;AAC7C;AAEA,SAAS;IACP,OAAO,CAAA,GAAA,2BAAmB,EAAE,iCAAW,+CA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C1C,IAAI,CAAC,gBACH;IAEJ;IAEA,IAAI,QAAQ;kBACV;iBACA;QACA,aAAa,QAAQ,WAAW;QAChC,UAAU,QAAQ,QAAQ;QAC1B,qBAAqB,QAAQ,mBAAmB;QAChD,GAAG,CAAA,GAAA,qBAAa,EAAE,QAAQ;IAC5B;IAEA,kFAAkF;IAClF,6EAA6E;IAC7E,iEAAiE;IACjE,IAAI,UAAU,QAAQ,OAAO,IAAI,CAAC,QAAQ,QAAQ,GAAG,KAAK,GAAG,CAAC,QAAQ,OAAO,EAAE,QAAQ;IACvF,IAAI,QAAQ;IACZ,IAAI,MAAM,MAAM,GAAG,CAAC,OAAO;iBAAC;QAAS,SAAS,QAAQ,OAAO;IAAA;IAC7D,OAAO,IAAM,MAAM,KAAK,CAAC;AAC3B;AAEA,MAAM,4CAAqB;IACzB,4BAA4B,GAC5B,SAAQ,QAAgB,EAAE,UAAgC,CAAC,CAAC;QAC1D,OAAO,+BAAS,UAAU,WAAW;IACvC;IACA,6BAA6B,GAC7B,UAAS,QAAgB,EAAE,UAAgC,CAAC,CAAC;QAC3D,OAAO,+BAAS,UAAU,YAAY;IACxC;IACA,6BAA6B,GAC7B,UAAS,QAAgB,EAAE,UAAgC,CAAC,CAAC;QAC3D,OAAO,+BAAS,UAAU,YAAY;IACxC;IACA,mCAAmC,GACnC,MAAK,QAAgB,EAAE,UAAgC,CAAC,CAAC;QACvD,OAAO,+BAAS,UAAU,QAAQ;IACpC;AACF","sources":["packages/@react-spectrum/toast/src/ToastContainer.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaToastRegionProps} from '@react-aria/toast';\nimport {classNames} from '@react-spectrum/utils';\nimport {DOMProps} from '@react-types/shared';\nimport {filterDOMProps} from '@react-aria/utils';\nimport React, {ReactElement, useEffect, useRef} from 'react';\nimport {SpectrumToastValue, Toast} from './Toast';\nimport toastContainerStyles from './toastContainer.css';\nimport {Toaster} from './Toaster';\nimport {ToastOptions, ToastQueue, useToastQueue} from '@react-stately/toast';\nimport {useSyncExternalStore} from 'use-sync-external-store/shim/index.js';\n\nexport interface SpectrumToastContainerProps extends AriaToastRegionProps {}\n\nexport interface SpectrumToastOptions extends Omit<ToastOptions, 'priority'>, DOMProps {\n /** A label for the action button within the toast. */\n actionLabel?: string,\n /** Handler that is called when the action button is pressed. */\n onAction?: () => void,\n /** Whether the toast should automatically close when an action is performed. */\n shouldCloseOnAction?: boolean\n}\n\ntype CloseFunction = () => void;\n\n// There is a single global toast queue instance for the whole app, initialized lazily.\nlet globalToastQueue: ToastQueue<SpectrumToastValue> | null = null;\nfunction getGlobalToastQueue() {\n if (!globalToastQueue) {\n globalToastQueue = new ToastQueue({\n maxVisibleToasts: Infinity,\n hasExitAnimation: true\n });\n }\n\n return globalToastQueue;\n}\n\n// For testing. Not exported from the package index.\nexport function clearToastQueue() {\n globalToastQueue = null;\n}\n\nlet toastProviders = new Set();\nlet subscriptions = new Set<() => void>();\nfunction subscribe(fn: () => void) {\n subscriptions.add(fn);\n return () => subscriptions.delete(fn);\n}\n\nfunction triggerSubscriptions() {\n for (let fn of subscriptions) {\n fn();\n }\n}\n\nfunction getActiveToastContainer() {\n return toastProviders.values().next().value;\n}\n\nfunction useActiveToastContainer() {\n return useSyncExternalStore(subscribe, getActiveToastContainer, getActiveToastContainer);\n}\n\n/**\n * A ToastContainer renders the queued toasts in an application. It should be placed\n * at the root of the app.\n */\nexport function ToastContainer(props: SpectrumToastContainerProps): ReactElement {\n // Track all toast provider instances in a set.\n // Only the first one will actually render.\n // We use a ref to do this, since it will have a stable identity\n // over the lifetime of the component.\n let ref = useRef(undefined);\n\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n toastProviders.add(ref);\n triggerSubscriptions();\n\n return () => {\n // When this toast provider unmounts, reset all animations so that\n // when the new toast provider renders, it is seamless.\n for (let toast of getGlobalToastQueue().visibleToasts) {\n toast.animation = null;\n }\n\n // Remove this toast provider, and call subscriptions.\n // This will cause all other instances to re-render,\n // and the first one to become the new active toast provider.\n toastProviders.delete(ref);\n triggerSubscriptions();\n };\n }, []);\n\n // Only render if this is the active toast provider instance, and there are visible toasts.\n let activeToastContainer = useActiveToastContainer();\n let state = useToastQueue(getGlobalToastQueue());\n\n if (ref === activeToastContainer && state.visibleToasts.length > 0) {\n return (\n <Toaster state={state} {...props}>\n <ol className={classNames(toastContainerStyles, 'spectrum-ToastContainer-list')}>\n {state.visibleToasts.slice().reverse().map((toast) => (\n <li\n key={toast.key}\n className={classNames(toastContainerStyles, 'spectrum-ToastContainer-listitem')}>\n <Toast\n toast={toast}\n state={state} />\n </li>\n ))}\n </ol>\n </Toaster>\n );\n }\n\n return null;\n}\n\nfunction addToast(children: string, variant: SpectrumToastValue['variant'], options: SpectrumToastOptions = {}) {\n // Dispatch a custom event so that toasts can be intercepted and re-targeted, e.g. when inside an iframe.\n if (typeof CustomEvent !== 'undefined' && typeof window !== 'undefined') {\n let event = new CustomEvent('react-spectrum-toast', {\n cancelable: true,\n bubbles: true,\n detail: {\n children,\n variant,\n options\n }\n });\n\n let shouldContinue = window.dispatchEvent(event);\n if (!shouldContinue) {\n return;\n }\n }\n\n let value = {\n children,\n variant,\n actionLabel: options.actionLabel,\n onAction: options.onAction,\n shouldCloseOnAction: options.shouldCloseOnAction,\n ...filterDOMProps(options)\n };\n\n // Minimum time of 5s from https://spectrum.adobe.com/page/toast/#Auto-dismissible\n // Actionable toasts cannot be auto dismissed. That would fail WCAG SC 2.2.1.\n // It is debatable whether non-actionable toasts would also fail.\n let timeout = options.timeout && !options.onAction ? Math.max(options.timeout, 5000) : null;\n let queue = getGlobalToastQueue();\n let key = queue.add(value, {timeout, onClose: options.onClose});\n return () => queue.close(key);\n}\n\nconst SpectrumToastQueue = {\n /** Queues a neutral toast. */\n neutral(children: string, options: SpectrumToastOptions = {}): CloseFunction {\n return addToast(children, 'neutral', options);\n },\n /** Queues a positive toast. */\n positive(children: string, options: SpectrumToastOptions = {}): CloseFunction {\n return addToast(children, 'positive', options);\n },\n /** Queues a negative toast. */\n negative(children: string, options: SpectrumToastOptions = {}): CloseFunction {\n return addToast(children, 'negative', options);\n },\n /** Queues an informational toast. */\n info(children: string, options: SpectrumToastOptions = {}): CloseFunction {\n return addToast(children, 'info', options);\n }\n};\n\nexport {SpectrumToastQueue as ToastQueue};\n"],"names":[],"version":3,"file":"ToastContainer.module.js.map"}
|