@react-spectrum/toast 3.0.0-beta.10 → 3.0.0-beta.12
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 +112 -0
- package/dist/Toast.main.js.map +1 -0
- package/dist/Toast.mjs +107 -0
- package/dist/Toast.module.js +107 -0
- package/dist/Toast.module.js.map +1 -0
- package/dist/ToastContainer.main.js +146 -0
- package/dist/ToastContainer.main.js.map +1 -0
- package/dist/ToastContainer.mjs +136 -0
- package/dist/ToastContainer.module.js +136 -0
- package/dist/ToastContainer.module.js.map +1 -0
- package/dist/Toaster.main.js +67 -0
- package/dist/Toaster.main.js.map +1 -0
- package/dist/Toaster.mjs +61 -0
- package/dist/Toaster.module.js +61 -0
- package/dist/Toaster.module.js.map +1 -0
- package/dist/import.mjs +1 -451
- package/dist/intlStrings.main.js +108 -0
- package/dist/intlStrings.main.js.map +1 -0
- package/dist/intlStrings.mjs +110 -0
- package/dist/intlStrings.module.js +110 -0
- package/dist/intlStrings.module.js.map +1 -0
- package/dist/main.js +3 -449
- package/dist/main.js.map +1 -1
- package/dist/module.js +1 -451
- package/dist/module.js.map +1 -1
- package/dist/{main.css → toastContainer.b596792c.css} +16 -119
- package/dist/toastContainer.b596792c.css.map +1 -0
- package/dist/toastContainer_css.main.js +34 -0
- package/dist/toastContainer_css.main.js.map +1 -0
- package/dist/toastContainer_css.mjs +36 -0
- package/dist/toastContainer_css.module.js +36 -0
- package/dist/toastContainer_css.module.js.map +1 -0
- package/dist/toast_vars_css.main.js +38 -0
- package/dist/toast_vars_css.main.js.map +1 -0
- package/dist/toast_vars_css.mjs +40 -0
- package/dist/toast_vars_css.module.js +40 -0
- package/dist/toast_vars_css.module.js.map +1 -0
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/vars.85cde188.css +94 -0
- package/dist/vars.85cde188.css.map +1 -0
- package/package.json +13 -12
- package/src/Toast.tsx +4 -2
- package/src/ToastContainer.tsx +7 -21
- package/src/Toaster.tsx +3 -1
- package/src/toastContainer.css +4 -4
- package/dist/main.css.map +0 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var $1e709ec471c88b75$exports = require("./intlStrings.main.js");
|
|
2
|
+
require("./vars.85cde188.css");
|
|
3
|
+
var $b6e6aa676f8f9e47$exports = require("./toast_vars_css.main.js");
|
|
4
|
+
require("./toastContainer.b596792c.css");
|
|
5
|
+
var $e20782d0579ed886$exports = require("./toastContainer_css.main.js");
|
|
6
|
+
var $5b9f2c86c1b1395c$exports = require("./Toaster.main.js");
|
|
7
|
+
var $8Jify$spectrumiconsuiAlertMedium = require("@spectrum-icons/ui/AlertMedium");
|
|
8
|
+
var $8Jify$reactspectrumbutton = require("@react-spectrum/button");
|
|
9
|
+
var $8Jify$reactspectrumutils = require("@react-spectrum/utils");
|
|
10
|
+
var $8Jify$spectrumiconsuiCrossMedium = require("@spectrum-icons/ui/CrossMedium");
|
|
11
|
+
var $8Jify$reactariautils = require("@react-aria/utils");
|
|
12
|
+
var $8Jify$spectrumiconsuiInfoMedium = require("@spectrum-icons/ui/InfoMedium");
|
|
13
|
+
var $8Jify$react = require("react");
|
|
14
|
+
var $8Jify$spectrumiconsuiSuccessMedium = require("@spectrum-icons/ui/SuccessMedium");
|
|
15
|
+
var $8Jify$reactariai18n = require("@react-aria/i18n");
|
|
16
|
+
var $8Jify$reactariatoast = require("@react-aria/toast");
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
function $parcel$interopDefault(a) {
|
|
20
|
+
return a && a.__esModule ? a.default : a;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function $parcel$export(e, n, v, s) {
|
|
24
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
$parcel$export(module.exports, "Toast", () => $6c5bd1047ecc310e$export$8d8dc7d5f743331b);
|
|
28
|
+
/*
|
|
29
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
30
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
31
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
32
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
33
|
+
*
|
|
34
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
35
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
36
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
37
|
+
* governing permissions and limitations under the License.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
const $6c5bd1047ecc310e$export$fde44257752a9f60 = {
|
|
53
|
+
info: (0, ($parcel$interopDefault($8Jify$spectrumiconsuiInfoMedium))),
|
|
54
|
+
negative: (0, ($parcel$interopDefault($8Jify$spectrumiconsuiAlertMedium))),
|
|
55
|
+
positive: (0, ($parcel$interopDefault($8Jify$spectrumiconsuiSuccessMedium)))
|
|
56
|
+
};
|
|
57
|
+
function $6c5bd1047ecc310e$var$Toast(props, ref) {
|
|
58
|
+
var _state_visibleToasts_;
|
|
59
|
+
let { toast: { key: key, animation: animation, content: { children: children, variant: variant, actionLabel: actionLabel, onAction: onAction, shouldCloseOnAction: shouldCloseOnAction } }, state: state, ...otherProps } = props;
|
|
60
|
+
let domRef = (0, $8Jify$reactspectrumutils.useDOMRef)(ref);
|
|
61
|
+
let { closeButtonProps: closeButtonProps, titleProps: titleProps, toastProps: toastProps } = (0, $8Jify$reactariatoast.useToast)(props, state, domRef);
|
|
62
|
+
let { styleProps: styleProps } = (0, $8Jify$reactspectrumutils.useStyleProps)(otherProps);
|
|
63
|
+
let stringFormatter = (0, $8Jify$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($1e709ec471c88b75$exports))), '@react-spectrum/toast');
|
|
64
|
+
let iconLabel = variant && variant !== 'neutral' ? stringFormatter.format(variant) : null;
|
|
65
|
+
let Icon = $6c5bd1047ecc310e$export$fde44257752a9f60[variant];
|
|
66
|
+
let isFocusVisible = (0, $8Jify$react.useContext)((0, $5b9f2c86c1b1395c$exports.ToasterContext));
|
|
67
|
+
const handleAction = ()=>{
|
|
68
|
+
if (onAction) onAction();
|
|
69
|
+
if (shouldCloseOnAction) state.close(key);
|
|
70
|
+
};
|
|
71
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement("div", {
|
|
72
|
+
...styleProps,
|
|
73
|
+
...toastProps,
|
|
74
|
+
...(0, $8Jify$reactariautils.filterDOMProps)(props.toast.content),
|
|
75
|
+
ref: domRef,
|
|
76
|
+
className: (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($b6e6aa676f8f9e47$exports))), 'spectrum-Toast', {
|
|
77
|
+
['spectrum-Toast--' + variant]: variant
|
|
78
|
+
}, styleProps.className, (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($e20782d0579ed886$exports))), 'spectrum-Toast', {
|
|
79
|
+
'focus-ring': props.toast.key === ((_state_visibleToasts_ = state.visibleToasts[0]) === null || _state_visibleToasts_ === void 0 ? void 0 : _state_visibleToasts_.key) && isFocusVisible
|
|
80
|
+
})),
|
|
81
|
+
style: {
|
|
82
|
+
...styleProps.style,
|
|
83
|
+
zIndex: props.toast.priority
|
|
84
|
+
},
|
|
85
|
+
"data-animation": animation,
|
|
86
|
+
onAnimationEnd: ()=>{
|
|
87
|
+
if (animation === 'exiting') state.remove(key);
|
|
88
|
+
}
|
|
89
|
+
}, Icon && /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement(Icon, {
|
|
90
|
+
"aria-label": iconLabel,
|
|
91
|
+
UNSAFE_className: (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($b6e6aa676f8f9e47$exports))), 'spectrum-Toast-typeIcon')
|
|
92
|
+
}), /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement("div", {
|
|
93
|
+
className: (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($b6e6aa676f8f9e47$exports))), 'spectrum-Toast-body')
|
|
94
|
+
}, /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement("div", {
|
|
95
|
+
className: (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($b6e6aa676f8f9e47$exports))), 'spectrum-Toast-content'),
|
|
96
|
+
...titleProps
|
|
97
|
+
}, children), actionLabel && /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement((0, $8Jify$reactspectrumbutton.Button), {
|
|
98
|
+
onPress: handleAction,
|
|
99
|
+
UNSAFE_className: (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($b6e6aa676f8f9e47$exports))), 'spectrum-Button'),
|
|
100
|
+
variant: "secondary",
|
|
101
|
+
staticColor: "white"
|
|
102
|
+
}, actionLabel)), /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement("div", {
|
|
103
|
+
className: (0, $8Jify$reactspectrumutils.classNames)((0, ($parcel$interopDefault($b6e6aa676f8f9e47$exports))), 'spectrum-Toast-buttons')
|
|
104
|
+
}, /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement((0, $8Jify$reactspectrumbutton.ClearButton), {
|
|
105
|
+
...closeButtonProps,
|
|
106
|
+
variant: "overBackground"
|
|
107
|
+
}, /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).createElement((0, ($parcel$interopDefault($8Jify$spectrumiconsuiCrossMedium))), null))));
|
|
108
|
+
}
|
|
109
|
+
let $6c5bd1047ecc310e$export$8d8dc7d5f743331b = /*#__PURE__*/ (0, ($parcel$interopDefault($8Jify$react))).forwardRef($6c5bd1047ecc310e$var$Toast);
|
|
110
|
+
|
|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,QAAQ,EAAE;QAAO,GACxC,WAAW,SAAS,EACpB,CAAA,GAAA,oCAAS,EACP,CAAA,GAAA,mDAAmB,GACnB,kBACA;YAAC,cAAc,MAAM,KAAK,CAAC,GAAG,OAAK,wBAAA,MAAM,aAAa,CAAC,EAAE,cAAtB,4CAAA,sBAAwB,GAAG,KAAI;QAAc;QAGpF,OAAO;YACL,GAAG,WAAW,KAAK;YACnB,QAAQ,MAAM,KAAK,CAAC,QAAQ;QAC9B;QACA,kBAAgB;QAChB,gBAAgB;YACd,IAAI,cAAc,WAChB,MAAM,MAAM,CAAC;QAEjB;OACC,sBACC,0DAAC;QACC,cAAY;QACZ,kBAAkB,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,mDAAK,GAAG;sBAEzC,0DAAC;QAAI,WAAW,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,mDAAK,GAAG;qBACjC,0DAAC;QAAI,WAAW,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,mDAAK,GAAG;QAA4B,GAAG,UAAU;OAAG,WAC9E,6BACC,0DAAC,CAAA,GAAA,iCAAK;QACJ,SAAS;QACT,kBAAkB,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,mDAAK,GAAG;QACrC,SAAQ;QACR,aAAY;OACX,6BAIP,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} 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, {useContext} 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 {ToasterContext} from './Toaster';\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 } = 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 = useContext(ToasterContext);\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 {...toastProps}\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': props.toast.key === state.visibleToasts[0]?.key && 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 {Icon &&\n <Icon\n aria-label={iconLabel}\n UNSAFE_className={classNames(styles, 'spectrum-Toast-typeIcon')} />\n }\n <div className={classNames(styles, 'spectrum-Toast-body')}>\n <div className={classNames(styles, 'spectrum-Toast-content')} {...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 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
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import $iu2Jc$intlStringsmodulejs from "./intlStrings.mjs";
|
|
2
|
+
import "./vars.85cde188.css";
|
|
3
|
+
import $iu2Jc$toast_vars_cssmodulejs from "./toast_vars_css.mjs";
|
|
4
|
+
import "./toastContainer.b596792c.css";
|
|
5
|
+
import $iu2Jc$toastContainer_cssmodulejs from "./toastContainer_css.mjs";
|
|
6
|
+
import {ToasterContext as $e46feef4e4c28a4b$export$9194c0aa0cd7a9ff} from "./Toaster.mjs";
|
|
7
|
+
import $iu2Jc$spectrumiconsuiAlertMedium from "@spectrum-icons/ui/AlertMedium";
|
|
8
|
+
import {Button as $iu2Jc$Button, ClearButton as $iu2Jc$ClearButton} from "@react-spectrum/button";
|
|
9
|
+
import {useDOMRef as $iu2Jc$useDOMRef, useStyleProps as $iu2Jc$useStyleProps, classNames as $iu2Jc$classNames} from "@react-spectrum/utils";
|
|
10
|
+
import $iu2Jc$spectrumiconsuiCrossMedium from "@spectrum-icons/ui/CrossMedium";
|
|
11
|
+
import {filterDOMProps as $iu2Jc$filterDOMProps} from "@react-aria/utils";
|
|
12
|
+
import $iu2Jc$spectrumiconsuiInfoMedium from "@spectrum-icons/ui/InfoMedium";
|
|
13
|
+
import $iu2Jc$react, {useContext as $iu2Jc$useContext} from "react";
|
|
14
|
+
import $iu2Jc$spectrumiconsuiSuccessMedium from "@spectrum-icons/ui/SuccessMedium";
|
|
15
|
+
import {useLocalizedStringFormatter as $iu2Jc$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
16
|
+
import {useToast as $iu2Jc$useToast} from "@react-aria/toast";
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
function $parcel$interopDefault(a) {
|
|
20
|
+
return a && a.__esModule ? a.default : a;
|
|
21
|
+
}
|
|
22
|
+
/*
|
|
23
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
24
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
25
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
26
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
27
|
+
*
|
|
28
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
29
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
30
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
31
|
+
* governing permissions and limitations under the License.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const $7e7a2952509f3a56$export$fde44257752a9f60 = {
|
|
47
|
+
info: (0, $iu2Jc$spectrumiconsuiInfoMedium),
|
|
48
|
+
negative: (0, $iu2Jc$spectrumiconsuiAlertMedium),
|
|
49
|
+
positive: (0, $iu2Jc$spectrumiconsuiSuccessMedium)
|
|
50
|
+
};
|
|
51
|
+
function $7e7a2952509f3a56$var$Toast(props, ref) {
|
|
52
|
+
var _state_visibleToasts_;
|
|
53
|
+
let { toast: { key: key, animation: animation, content: { children: children, variant: variant, actionLabel: actionLabel, onAction: onAction, shouldCloseOnAction: shouldCloseOnAction } }, state: state, ...otherProps } = props;
|
|
54
|
+
let domRef = (0, $iu2Jc$useDOMRef)(ref);
|
|
55
|
+
let { closeButtonProps: closeButtonProps, titleProps: titleProps, toastProps: toastProps } = (0, $iu2Jc$useToast)(props, state, domRef);
|
|
56
|
+
let { styleProps: styleProps } = (0, $iu2Jc$useStyleProps)(otherProps);
|
|
57
|
+
let stringFormatter = (0, $iu2Jc$useLocalizedStringFormatter)((0, ($parcel$interopDefault($iu2Jc$intlStringsmodulejs))), '@react-spectrum/toast');
|
|
58
|
+
let iconLabel = variant && variant !== 'neutral' ? stringFormatter.format(variant) : null;
|
|
59
|
+
let Icon = $7e7a2952509f3a56$export$fde44257752a9f60[variant];
|
|
60
|
+
let isFocusVisible = (0, $iu2Jc$useContext)((0, $e46feef4e4c28a4b$export$9194c0aa0cd7a9ff));
|
|
61
|
+
const handleAction = ()=>{
|
|
62
|
+
if (onAction) onAction();
|
|
63
|
+
if (shouldCloseOnAction) state.close(key);
|
|
64
|
+
};
|
|
65
|
+
return /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
66
|
+
...styleProps,
|
|
67
|
+
...toastProps,
|
|
68
|
+
...(0, $iu2Jc$filterDOMProps)(props.toast.content),
|
|
69
|
+
ref: domRef,
|
|
70
|
+
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast', {
|
|
71
|
+
['spectrum-Toast--' + variant]: variant
|
|
72
|
+
}, styleProps.className, (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toastContainer_cssmodulejs))), 'spectrum-Toast', {
|
|
73
|
+
'focus-ring': props.toast.key === ((_state_visibleToasts_ = state.visibleToasts[0]) === null || _state_visibleToasts_ === void 0 ? void 0 : _state_visibleToasts_.key) && isFocusVisible
|
|
74
|
+
})),
|
|
75
|
+
style: {
|
|
76
|
+
...styleProps.style,
|
|
77
|
+
zIndex: props.toast.priority
|
|
78
|
+
},
|
|
79
|
+
"data-animation": animation,
|
|
80
|
+
onAnimationEnd: ()=>{
|
|
81
|
+
if (animation === 'exiting') state.remove(key);
|
|
82
|
+
}
|
|
83
|
+
}, Icon && /*#__PURE__*/ (0, $iu2Jc$react).createElement(Icon, {
|
|
84
|
+
"aria-label": iconLabel,
|
|
85
|
+
UNSAFE_className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-typeIcon')
|
|
86
|
+
}), /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
87
|
+
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-body')
|
|
88
|
+
}, /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
89
|
+
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-content'),
|
|
90
|
+
...titleProps
|
|
91
|
+
}, children), actionLabel && /*#__PURE__*/ (0, $iu2Jc$react).createElement((0, $iu2Jc$Button), {
|
|
92
|
+
onPress: handleAction,
|
|
93
|
+
UNSAFE_className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Button'),
|
|
94
|
+
variant: "secondary",
|
|
95
|
+
staticColor: "white"
|
|
96
|
+
}, actionLabel)), /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
97
|
+
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-buttons')
|
|
98
|
+
}, /*#__PURE__*/ (0, $iu2Jc$react).createElement((0, $iu2Jc$ClearButton), {
|
|
99
|
+
...closeButtonProps,
|
|
100
|
+
variant: "overBackground"
|
|
101
|
+
}, /*#__PURE__*/ (0, $iu2Jc$react).createElement((0, $iu2Jc$spectrumiconsuiCrossMedium), null))));
|
|
102
|
+
}
|
|
103
|
+
let $7e7a2952509f3a56$export$8d8dc7d5f743331b = /*#__PURE__*/ (0, $iu2Jc$react).forwardRef($7e7a2952509f3a56$var$Toast);
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
export {$7e7a2952509f3a56$export$fde44257752a9f60 as ICONS, $7e7a2952509f3a56$export$8d8dc7d5f743331b as Toast};
|
|
107
|
+
//# sourceMappingURL=Toast.module.js.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import $iu2Jc$intlStringsmodulejs from "./intlStrings.module.js";
|
|
2
|
+
import "./vars.85cde188.css";
|
|
3
|
+
import $iu2Jc$toast_vars_cssmodulejs from "./toast_vars_css.module.js";
|
|
4
|
+
import "./toastContainer.b596792c.css";
|
|
5
|
+
import $iu2Jc$toastContainer_cssmodulejs from "./toastContainer_css.module.js";
|
|
6
|
+
import {ToasterContext as $e46feef4e4c28a4b$export$9194c0aa0cd7a9ff} from "./Toaster.module.js";
|
|
7
|
+
import $iu2Jc$spectrumiconsuiAlertMedium from "@spectrum-icons/ui/AlertMedium";
|
|
8
|
+
import {Button as $iu2Jc$Button, ClearButton as $iu2Jc$ClearButton} from "@react-spectrum/button";
|
|
9
|
+
import {useDOMRef as $iu2Jc$useDOMRef, useStyleProps as $iu2Jc$useStyleProps, classNames as $iu2Jc$classNames} from "@react-spectrum/utils";
|
|
10
|
+
import $iu2Jc$spectrumiconsuiCrossMedium from "@spectrum-icons/ui/CrossMedium";
|
|
11
|
+
import {filterDOMProps as $iu2Jc$filterDOMProps} from "@react-aria/utils";
|
|
12
|
+
import $iu2Jc$spectrumiconsuiInfoMedium from "@spectrum-icons/ui/InfoMedium";
|
|
13
|
+
import $iu2Jc$react, {useContext as $iu2Jc$useContext} from "react";
|
|
14
|
+
import $iu2Jc$spectrumiconsuiSuccessMedium from "@spectrum-icons/ui/SuccessMedium";
|
|
15
|
+
import {useLocalizedStringFormatter as $iu2Jc$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
16
|
+
import {useToast as $iu2Jc$useToast} from "@react-aria/toast";
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
function $parcel$interopDefault(a) {
|
|
20
|
+
return a && a.__esModule ? a.default : a;
|
|
21
|
+
}
|
|
22
|
+
/*
|
|
23
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
24
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
25
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
26
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
27
|
+
*
|
|
28
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
29
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
30
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
31
|
+
* governing permissions and limitations under the License.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const $7e7a2952509f3a56$export$fde44257752a9f60 = {
|
|
47
|
+
info: (0, $iu2Jc$spectrumiconsuiInfoMedium),
|
|
48
|
+
negative: (0, $iu2Jc$spectrumiconsuiAlertMedium),
|
|
49
|
+
positive: (0, $iu2Jc$spectrumiconsuiSuccessMedium)
|
|
50
|
+
};
|
|
51
|
+
function $7e7a2952509f3a56$var$Toast(props, ref) {
|
|
52
|
+
var _state_visibleToasts_;
|
|
53
|
+
let { toast: { key: key, animation: animation, content: { children: children, variant: variant, actionLabel: actionLabel, onAction: onAction, shouldCloseOnAction: shouldCloseOnAction } }, state: state, ...otherProps } = props;
|
|
54
|
+
let domRef = (0, $iu2Jc$useDOMRef)(ref);
|
|
55
|
+
let { closeButtonProps: closeButtonProps, titleProps: titleProps, toastProps: toastProps } = (0, $iu2Jc$useToast)(props, state, domRef);
|
|
56
|
+
let { styleProps: styleProps } = (0, $iu2Jc$useStyleProps)(otherProps);
|
|
57
|
+
let stringFormatter = (0, $iu2Jc$useLocalizedStringFormatter)((0, ($parcel$interopDefault($iu2Jc$intlStringsmodulejs))), '@react-spectrum/toast');
|
|
58
|
+
let iconLabel = variant && variant !== 'neutral' ? stringFormatter.format(variant) : null;
|
|
59
|
+
let Icon = $7e7a2952509f3a56$export$fde44257752a9f60[variant];
|
|
60
|
+
let isFocusVisible = (0, $iu2Jc$useContext)((0, $e46feef4e4c28a4b$export$9194c0aa0cd7a9ff));
|
|
61
|
+
const handleAction = ()=>{
|
|
62
|
+
if (onAction) onAction();
|
|
63
|
+
if (shouldCloseOnAction) state.close(key);
|
|
64
|
+
};
|
|
65
|
+
return /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
66
|
+
...styleProps,
|
|
67
|
+
...toastProps,
|
|
68
|
+
...(0, $iu2Jc$filterDOMProps)(props.toast.content),
|
|
69
|
+
ref: domRef,
|
|
70
|
+
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast', {
|
|
71
|
+
['spectrum-Toast--' + variant]: variant
|
|
72
|
+
}, styleProps.className, (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toastContainer_cssmodulejs))), 'spectrum-Toast', {
|
|
73
|
+
'focus-ring': props.toast.key === ((_state_visibleToasts_ = state.visibleToasts[0]) === null || _state_visibleToasts_ === void 0 ? void 0 : _state_visibleToasts_.key) && isFocusVisible
|
|
74
|
+
})),
|
|
75
|
+
style: {
|
|
76
|
+
...styleProps.style,
|
|
77
|
+
zIndex: props.toast.priority
|
|
78
|
+
},
|
|
79
|
+
"data-animation": animation,
|
|
80
|
+
onAnimationEnd: ()=>{
|
|
81
|
+
if (animation === 'exiting') state.remove(key);
|
|
82
|
+
}
|
|
83
|
+
}, Icon && /*#__PURE__*/ (0, $iu2Jc$react).createElement(Icon, {
|
|
84
|
+
"aria-label": iconLabel,
|
|
85
|
+
UNSAFE_className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-typeIcon')
|
|
86
|
+
}), /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
87
|
+
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-body')
|
|
88
|
+
}, /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
89
|
+
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-content'),
|
|
90
|
+
...titleProps
|
|
91
|
+
}, children), actionLabel && /*#__PURE__*/ (0, $iu2Jc$react).createElement((0, $iu2Jc$Button), {
|
|
92
|
+
onPress: handleAction,
|
|
93
|
+
UNSAFE_className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Button'),
|
|
94
|
+
variant: "secondary",
|
|
95
|
+
staticColor: "white"
|
|
96
|
+
}, actionLabel)), /*#__PURE__*/ (0, $iu2Jc$react).createElement("div", {
|
|
97
|
+
className: (0, $iu2Jc$classNames)((0, ($parcel$interopDefault($iu2Jc$toast_vars_cssmodulejs))), 'spectrum-Toast-buttons')
|
|
98
|
+
}, /*#__PURE__*/ (0, $iu2Jc$react).createElement((0, $iu2Jc$ClearButton), {
|
|
99
|
+
...closeButtonProps,
|
|
100
|
+
variant: "overBackground"
|
|
101
|
+
}, /*#__PURE__*/ (0, $iu2Jc$react).createElement((0, $iu2Jc$spectrumiconsuiCrossMedium), null))));
|
|
102
|
+
}
|
|
103
|
+
let $7e7a2952509f3a56$export$8d8dc7d5f743331b = /*#__PURE__*/ (0, $iu2Jc$react).forwardRef($7e7a2952509f3a56$var$Toast);
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
export {$7e7a2952509f3a56$export$fde44257752a9f60 as ICONS, $7e7a2952509f3a56$export$8d8dc7d5f743331b as Toast};
|
|
107
|
+
//# sourceMappingURL=Toast.module.js.map
|
|
@@ -0,0 +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;QAoDxB;IAnD3C,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,EACX,GAAG,CAAA,GAAA,eAAO,EAAE,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;QAA4B,GAAG,UAAU;OAAG,WAC9E,6BACC,gCAAC,CAAA,GAAA,aAAK;QACJ,SAAS;QACT,kBAAkB,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,uDAAK,GAAG;QACrC,SAAQ;QACR,aAAY;OACX,6BAIP,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} 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, {useContext} 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 {ToasterContext} from './Toaster';\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 } = 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 = useContext(ToasterContext);\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 {...toastProps}\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': props.toast.key === state.visibleToasts[0]?.key && 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 {Icon &&\n <Icon\n aria-label={iconLabel}\n UNSAFE_className={classNames(styles, 'spectrum-Toast-typeIcon')} />\n }\n <div className={classNames(styles, 'spectrum-Toast-body')}>\n <div className={classNames(styles, 'spectrum-Toast-content')} {...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 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"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
var $6c5bd1047ecc310e$exports = require("./Toast.main.js");
|
|
2
|
+
var $5b9f2c86c1b1395c$exports = require("./Toaster.main.js");
|
|
3
|
+
var $5IVGU$reactariautils = require("@react-aria/utils");
|
|
4
|
+
var $5IVGU$react = require("react");
|
|
5
|
+
var $5IVGU$reactstatelytoast = require("@react-stately/toast");
|
|
6
|
+
var $5IVGU$usesyncexternalstoreshimindexjs = require("use-sync-external-store/shim/index.js");
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function $parcel$interopDefault(a) {
|
|
10
|
+
return a && a.__esModule ? a.default : a;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function $parcel$export(e, n, v, s) {
|
|
14
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
$parcel$export(module.exports, "ToastContainer", () => $56cdf77f3be52eaf$export$f2815235e76a62b9);
|
|
18
|
+
$parcel$export(module.exports, "ToastQueue", () => $56cdf77f3be52eaf$export$f1f8569633bbbec4);
|
|
19
|
+
/*
|
|
20
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
21
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
22
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
23
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
24
|
+
*
|
|
25
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
26
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
27
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
28
|
+
* governing permissions and limitations under the License.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
// There is a single global toast queue instance for the whole app, initialized lazily.
|
|
36
|
+
let $56cdf77f3be52eaf$var$globalToastQueue = null;
|
|
37
|
+
function $56cdf77f3be52eaf$var$getGlobalToastQueue() {
|
|
38
|
+
if (!$56cdf77f3be52eaf$var$globalToastQueue) $56cdf77f3be52eaf$var$globalToastQueue = new (0, $5IVGU$reactstatelytoast.ToastQueue)({
|
|
39
|
+
maxVisibleToasts: Infinity,
|
|
40
|
+
hasExitAnimation: true
|
|
41
|
+
});
|
|
42
|
+
return $56cdf77f3be52eaf$var$globalToastQueue;
|
|
43
|
+
}
|
|
44
|
+
function $56cdf77f3be52eaf$export$320311f0e4ecb3ae() {
|
|
45
|
+
$56cdf77f3be52eaf$var$globalToastQueue = null;
|
|
46
|
+
}
|
|
47
|
+
let $56cdf77f3be52eaf$var$toastProviders = new Set();
|
|
48
|
+
let $56cdf77f3be52eaf$var$subscriptions = new Set();
|
|
49
|
+
function $56cdf77f3be52eaf$var$subscribe(fn) {
|
|
50
|
+
$56cdf77f3be52eaf$var$subscriptions.add(fn);
|
|
51
|
+
return ()=>$56cdf77f3be52eaf$var$subscriptions.delete(fn);
|
|
52
|
+
}
|
|
53
|
+
function $56cdf77f3be52eaf$var$triggerSubscriptions() {
|
|
54
|
+
for (let fn of $56cdf77f3be52eaf$var$subscriptions)fn();
|
|
55
|
+
}
|
|
56
|
+
function $56cdf77f3be52eaf$var$getActiveToastContainer() {
|
|
57
|
+
return $56cdf77f3be52eaf$var$toastProviders.values().next().value;
|
|
58
|
+
}
|
|
59
|
+
function $56cdf77f3be52eaf$var$useActiveToastContainer() {
|
|
60
|
+
return (0, $5IVGU$usesyncexternalstoreshimindexjs.useSyncExternalStore)($56cdf77f3be52eaf$var$subscribe, $56cdf77f3be52eaf$var$getActiveToastContainer, $56cdf77f3be52eaf$var$getActiveToastContainer);
|
|
61
|
+
}
|
|
62
|
+
function $56cdf77f3be52eaf$export$f2815235e76a62b9(props) {
|
|
63
|
+
// Track all toast provider instances in a set.
|
|
64
|
+
// Only the first one will actually render.
|
|
65
|
+
// We use a ref to do this, since it will have a stable identity
|
|
66
|
+
// over the lifetime of the component.
|
|
67
|
+
let ref = (0, $5IVGU$react.useRef)();
|
|
68
|
+
// eslint-disable-next-line arrow-body-style
|
|
69
|
+
(0, $5IVGU$react.useEffect)(()=>{
|
|
70
|
+
$56cdf77f3be52eaf$var$toastProviders.add(ref);
|
|
71
|
+
$56cdf77f3be52eaf$var$triggerSubscriptions();
|
|
72
|
+
return ()=>{
|
|
73
|
+
// When this toast provider unmounts, reset all animations so that
|
|
74
|
+
// when the new toast provider renders, it is seamless.
|
|
75
|
+
for (let toast of $56cdf77f3be52eaf$var$getGlobalToastQueue().visibleToasts)toast.animation = null;
|
|
76
|
+
// Remove this toast provider, and call subscriptions.
|
|
77
|
+
// This will cause all other instances to re-render,
|
|
78
|
+
// and the first one to become the new active toast provider.
|
|
79
|
+
$56cdf77f3be52eaf$var$toastProviders.delete(ref);
|
|
80
|
+
$56cdf77f3be52eaf$var$triggerSubscriptions();
|
|
81
|
+
};
|
|
82
|
+
}, []);
|
|
83
|
+
// Only render if this is the active toast provider instance, and there are visible toasts.
|
|
84
|
+
let activeToastContainer = $56cdf77f3be52eaf$var$useActiveToastContainer();
|
|
85
|
+
let state = (0, $5IVGU$reactstatelytoast.useToastQueue)($56cdf77f3be52eaf$var$getGlobalToastQueue());
|
|
86
|
+
if (ref === activeToastContainer && state.visibleToasts.length > 0) return /*#__PURE__*/ (0, ($parcel$interopDefault($5IVGU$react))).createElement((0, $5b9f2c86c1b1395c$exports.Toaster), {
|
|
87
|
+
state: state,
|
|
88
|
+
...props
|
|
89
|
+
}, state.visibleToasts.map((toast)=>/*#__PURE__*/ (0, ($parcel$interopDefault($5IVGU$react))).createElement((0, $6c5bd1047ecc310e$exports.Toast), {
|
|
90
|
+
key: toast.key,
|
|
91
|
+
toast: toast,
|
|
92
|
+
state: state
|
|
93
|
+
})));
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
function $56cdf77f3be52eaf$var$addToast(children, variant, options = {}) {
|
|
97
|
+
// Dispatch a custom event so that toasts can be intercepted and re-targeted, e.g. when inside an iframe.
|
|
98
|
+
if (typeof CustomEvent !== 'undefined' && typeof window !== 'undefined') {
|
|
99
|
+
let event = new CustomEvent('react-spectrum-toast', {
|
|
100
|
+
cancelable: true,
|
|
101
|
+
bubbles: true,
|
|
102
|
+
detail: {
|
|
103
|
+
children: children,
|
|
104
|
+
variant: variant,
|
|
105
|
+
options: options
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
let shouldContinue = window.dispatchEvent(event);
|
|
109
|
+
if (!shouldContinue) return;
|
|
110
|
+
}
|
|
111
|
+
let value = {
|
|
112
|
+
children: children,
|
|
113
|
+
variant: variant,
|
|
114
|
+
actionLabel: options.actionLabel,
|
|
115
|
+
onAction: options.onAction,
|
|
116
|
+
shouldCloseOnAction: options.shouldCloseOnAction,
|
|
117
|
+
...(0, $5IVGU$reactariautils.filterDOMProps)(options)
|
|
118
|
+
};
|
|
119
|
+
// Minimum time of 5s from https://spectrum.adobe.com/page/toast/#Auto-dismissible
|
|
120
|
+
// Actionable toasts cannot be auto dismissed. That would fail WCAG SC 2.2.1.
|
|
121
|
+
// It is debatable whether non-actionable toasts would also fail.
|
|
122
|
+
let timeout = options.timeout && !options.onAction ? Math.max(options.timeout, 5000) : null;
|
|
123
|
+
let queue = $56cdf77f3be52eaf$var$getGlobalToastQueue();
|
|
124
|
+
let key = queue.add(value, {
|
|
125
|
+
timeout: timeout,
|
|
126
|
+
onClose: options.onClose
|
|
127
|
+
});
|
|
128
|
+
return ()=>queue.close(key);
|
|
129
|
+
}
|
|
130
|
+
const $56cdf77f3be52eaf$export$f1f8569633bbbec4 = {
|
|
131
|
+
/** Queues a neutral toast. */ neutral (children, options = {}) {
|
|
132
|
+
return $56cdf77f3be52eaf$var$addToast(children, 'neutral', options);
|
|
133
|
+
},
|
|
134
|
+
/** Queues a positive toast. */ positive (children, options = {}) {
|
|
135
|
+
return $56cdf77f3be52eaf$var$addToast(children, 'positive', options);
|
|
136
|
+
},
|
|
137
|
+
/** Queues a negative toast. */ negative (children, options = {}) {
|
|
138
|
+
return $56cdf77f3be52eaf$var$addToast(children, 'negative', options);
|
|
139
|
+
},
|
|
140
|
+
/** Queues an informational toast. */ info (children, options = {}) {
|
|
141
|
+
return $56cdf77f3be52eaf$var$addToast(children, 'info', options);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
//# sourceMappingURL=ToastContainer.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAwBD,uFAAuF;AACvF,IAAI,yCAA0D;AAC9D,SAAS;IACP,IAAI,CAAC,wCACH,yCAAmB,IAAI,CAAA,GAAA,mCAAS,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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AAA,oCAAa,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 {DOMProps} from '@react-types/shared';\nimport {filterDOMProps} from '@react-aria/utils';\nimport React, {ReactElement, useEffect, useRef} from 'react';\nimport {SpectrumToastValue, Toast} from './Toast';\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();\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 if (ref === activeToastContainer && state.visibleToasts.length > 0) {\n return (\n <Toaster state={state} {...props}>\n {state.visibleToasts.map((toast) => (\n <Toast\n key={toast.key}\n toast={toast}\n state={state} />\n ))}\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"}
|