@react-spectrum/toast 3.0.0-beta.1 → 3.0.0-beta.11
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/ar-AE.main.js +8 -0
- package/dist/ar-AE.main.js.map +1 -0
- package/dist/ar-AE.mjs +10 -0
- package/dist/ar-AE.module.js +10 -0
- package/dist/ar-AE.module.js.map +1 -0
- package/dist/bg-BG.main.js +8 -0
- package/dist/bg-BG.main.js.map +1 -0
- package/dist/bg-BG.mjs +10 -0
- package/dist/bg-BG.module.js +10 -0
- package/dist/bg-BG.module.js.map +1 -0
- package/dist/cs-CZ.main.js +8 -0
- package/dist/cs-CZ.main.js.map +1 -0
- package/dist/cs-CZ.mjs +10 -0
- package/dist/cs-CZ.module.js +10 -0
- package/dist/cs-CZ.module.js.map +1 -0
- package/dist/da-DK.main.js +8 -0
- package/dist/da-DK.main.js.map +1 -0
- package/dist/da-DK.mjs +10 -0
- package/dist/da-DK.module.js +10 -0
- package/dist/da-DK.module.js.map +1 -0
- package/dist/de-DE.main.js +8 -0
- package/dist/de-DE.main.js.map +1 -0
- package/dist/de-DE.mjs +10 -0
- package/dist/de-DE.module.js +10 -0
- package/dist/de-DE.module.js.map +1 -0
- package/dist/el-GR.main.js +8 -0
- package/dist/el-GR.main.js.map +1 -0
- package/dist/el-GR.mjs +10 -0
- package/dist/el-GR.module.js +10 -0
- package/dist/el-GR.module.js.map +1 -0
- package/dist/en-US.main.js +8 -0
- package/dist/en-US.main.js.map +1 -0
- package/dist/en-US.mjs +10 -0
- package/dist/en-US.module.js +10 -0
- package/dist/en-US.module.js.map +1 -0
- package/dist/es-ES.main.js +8 -0
- package/dist/es-ES.main.js.map +1 -0
- package/dist/es-ES.mjs +10 -0
- package/dist/es-ES.module.js +10 -0
- package/dist/es-ES.module.js.map +1 -0
- package/dist/et-EE.main.js +8 -0
- package/dist/et-EE.main.js.map +1 -0
- package/dist/et-EE.mjs +10 -0
- package/dist/et-EE.module.js +10 -0
- package/dist/et-EE.module.js.map +1 -0
- package/dist/fi-FI.main.js +8 -0
- package/dist/fi-FI.main.js.map +1 -0
- package/dist/fi-FI.mjs +10 -0
- package/dist/fi-FI.module.js +10 -0
- package/dist/fi-FI.module.js.map +1 -0
- package/dist/fr-FR.main.js +8 -0
- package/dist/fr-FR.main.js.map +1 -0
- package/dist/fr-FR.mjs +10 -0
- package/dist/fr-FR.module.js +10 -0
- package/dist/fr-FR.module.js.map +1 -0
- package/dist/he-IL.main.js +8 -0
- package/dist/he-IL.main.js.map +1 -0
- package/dist/he-IL.mjs +10 -0
- package/dist/he-IL.module.js +10 -0
- package/dist/he-IL.module.js.map +1 -0
- package/dist/hr-HR.main.js +8 -0
- package/dist/hr-HR.main.js.map +1 -0
- package/dist/hr-HR.mjs +10 -0
- package/dist/hr-HR.module.js +10 -0
- package/dist/hr-HR.module.js.map +1 -0
- package/dist/hu-HU.main.js +8 -0
- package/dist/hu-HU.main.js.map +1 -0
- package/dist/hu-HU.mjs +10 -0
- package/dist/hu-HU.module.js +10 -0
- package/dist/hu-HU.module.js.map +1 -0
- package/dist/import.mjs +1 -630
- 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/it-IT.main.js +8 -0
- package/dist/it-IT.main.js.map +1 -0
- package/dist/it-IT.mjs +10 -0
- package/dist/it-IT.module.js +10 -0
- package/dist/it-IT.module.js.map +1 -0
- package/dist/ja-JP.main.js +8 -0
- package/dist/ja-JP.main.js.map +1 -0
- package/dist/ja-JP.mjs +10 -0
- package/dist/ja-JP.module.js +10 -0
- package/dist/ja-JP.module.js.map +1 -0
- package/dist/ko-KR.main.js +8 -0
- package/dist/ko-KR.main.js.map +1 -0
- package/dist/ko-KR.mjs +10 -0
- package/dist/ko-KR.module.js +10 -0
- package/dist/ko-KR.module.js.map +1 -0
- package/dist/lt-LT.main.js +8 -0
- package/dist/lt-LT.main.js.map +1 -0
- package/dist/lt-LT.mjs +10 -0
- package/dist/lt-LT.module.js +10 -0
- package/dist/lt-LT.module.js.map +1 -0
- package/dist/lv-LV.main.js +8 -0
- package/dist/lv-LV.main.js.map +1 -0
- package/dist/lv-LV.mjs +10 -0
- package/dist/lv-LV.module.js +10 -0
- package/dist/lv-LV.module.js.map +1 -0
- package/dist/main.js +4 -629
- package/dist/main.js.map +1 -1
- package/dist/module.js +1 -630
- package/dist/module.js.map +1 -1
- package/dist/nb-NO.main.js +8 -0
- package/dist/nb-NO.main.js.map +1 -0
- package/dist/nb-NO.mjs +10 -0
- package/dist/nb-NO.module.js +10 -0
- package/dist/nb-NO.module.js.map +1 -0
- package/dist/nl-NL.main.js +8 -0
- package/dist/nl-NL.main.js.map +1 -0
- package/dist/nl-NL.mjs +10 -0
- package/dist/nl-NL.module.js +10 -0
- package/dist/nl-NL.module.js.map +1 -0
- package/dist/pl-PL.main.js +8 -0
- package/dist/pl-PL.main.js.map +1 -0
- package/dist/pl-PL.mjs +10 -0
- package/dist/pl-PL.module.js +10 -0
- package/dist/pl-PL.module.js.map +1 -0
- package/dist/pt-BR.main.js +8 -0
- package/dist/pt-BR.main.js.map +1 -0
- package/dist/pt-BR.mjs +10 -0
- package/dist/pt-BR.module.js +10 -0
- package/dist/pt-BR.module.js.map +1 -0
- package/dist/pt-PT.main.js +8 -0
- package/dist/pt-PT.main.js.map +1 -0
- package/dist/pt-PT.mjs +10 -0
- package/dist/pt-PT.module.js +10 -0
- package/dist/pt-PT.module.js.map +1 -0
- package/dist/ro-RO.main.js +8 -0
- package/dist/ro-RO.main.js.map +1 -0
- package/dist/ro-RO.mjs +10 -0
- package/dist/ro-RO.module.js +10 -0
- package/dist/ro-RO.module.js.map +1 -0
- package/dist/ru-RU.main.js +8 -0
- package/dist/ru-RU.main.js.map +1 -0
- package/dist/ru-RU.mjs +10 -0
- package/dist/ru-RU.module.js +10 -0
- package/dist/ru-RU.module.js.map +1 -0
- package/dist/sk-SK.main.js +8 -0
- package/dist/sk-SK.main.js.map +1 -0
- package/dist/sk-SK.mjs +10 -0
- package/dist/sk-SK.module.js +10 -0
- package/dist/sk-SK.module.js.map +1 -0
- package/dist/sl-SI.main.js +8 -0
- package/dist/sl-SI.main.js.map +1 -0
- package/dist/sl-SI.mjs +10 -0
- package/dist/sl-SI.module.js +10 -0
- package/dist/sl-SI.module.js.map +1 -0
- package/dist/sr-SP.main.js +8 -0
- package/dist/sr-SP.main.js.map +1 -0
- package/dist/sr-SP.mjs +10 -0
- package/dist/sr-SP.module.js +10 -0
- package/dist/sr-SP.module.js.map +1 -0
- package/dist/sv-SE.main.js +8 -0
- package/dist/sv-SE.main.js.map +1 -0
- package/dist/sv-SE.mjs +10 -0
- package/dist/sv-SE.module.js +10 -0
- package/dist/sv-SE.module.js.map +1 -0
- package/dist/toastContainer.b596792c.css +139 -0
- 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/tr-TR.main.js +8 -0
- package/dist/tr-TR.main.js.map +1 -0
- package/dist/tr-TR.mjs +10 -0
- package/dist/tr-TR.module.js +10 -0
- package/dist/tr-TR.module.js.map +1 -0
- package/dist/types.d.ts +8 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/uk-UA.main.js +8 -0
- package/dist/uk-UA.main.js.map +1 -0
- package/dist/uk-UA.mjs +10 -0
- package/dist/uk-UA.module.js +10 -0
- package/dist/uk-UA.module.js.map +1 -0
- package/dist/vars.85cde188.css +94 -0
- package/dist/vars.85cde188.css.map +1 -0
- package/dist/zh-CN.main.js +8 -0
- package/dist/zh-CN.main.js.map +1 -0
- package/dist/zh-CN.mjs +10 -0
- package/dist/zh-CN.module.js +10 -0
- package/dist/zh-CN.module.js.map +1 -0
- package/dist/zh-TW.main.js +8 -0
- package/dist/zh-TW.main.js.map +1 -0
- package/dist/zh-TW.mjs +10 -0
- package/dist/zh-TW.module.js +10 -0
- package/dist/zh-TW.module.js.map +1 -0
- package/package.json +14 -12
- package/src/Toast.tsx +12 -7
- package/src/ToastContainer.tsx +24 -32
- package/src/Toaster.tsx +14 -9
- package/src/toastContainer.css +9 -15
- package/dist/main.css +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAwBA;;;;;;;;;;;;;;;AAkBA;;;;;;;;;AAUA;;;;;;;;;AASA;;;;;;AAOI;;;;AAOJ;;;;;;;;;;AAWE;;;;;;AAoBF;;;;;AAKA;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAIA;EACE","sources":["packages/@adobe/spectrum-css-temp/components/toast/vars.css"],"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\n@import './index.css';\n@import './skin.css';\n"],"names":[],"version":3,"file":"vars.85cde188.css.map"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAAA,iBAAiB;IAAG,QAAQ,CAAC,gBAAE,CAAC;IAC9B,YAAY,CAAC,gBAAE,CAAC;IAChB,YAAY,CAAC,gBAAE,CAAC;AAClB","sources":["packages/@react-spectrum/toast/intl/zh-CN.json"],"sourcesContent":["{\n \"info\": \"信息\",\n \"negative\": \"错误\",\n \"positive\": \"成功\"\n}\n"],"names":[],"version":3,"file":"zh-CN.main.js.map"}
|
package/dist/zh-CN.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var $b1634d37b87f243f$exports = {};
|
|
2
|
+
$b1634d37b87f243f$exports = {
|
|
3
|
+
"info": `\u{4FE1}\u{606F}`,
|
|
4
|
+
"negative": `\u{9519}\u{8BEF}`,
|
|
5
|
+
"positive": `\u{6210}\u{529F}`
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export {$b1634d37b87f243f$exports as default};
|
|
10
|
+
//# sourceMappingURL=zh-CN.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";AAAA,4BAAiB;IAAG,QAAQ,CAAC,gBAAE,CAAC;IAC9B,YAAY,CAAC,gBAAE,CAAC;IAChB,YAAY,CAAC,gBAAE,CAAC;AAClB","sources":["packages/@react-spectrum/toast/intl/zh-CN.json"],"sourcesContent":["{\n \"info\": \"信息\",\n \"negative\": \"错误\",\n \"positive\": \"成功\"\n}\n"],"names":[],"version":3,"file":"zh-CN.module.js.map"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAAA,iBAAiB;IAAG,QAAQ,CAAC,gBAAE,CAAC;IAC9B,YAAY,CAAC,gBAAE,CAAC;IAChB,YAAY,CAAC,gBAAE,CAAC;AAClB","sources":["packages/@react-spectrum/toast/intl/zh-TW.json"],"sourcesContent":["{\n \"info\": \"資訊\",\n \"negative\": \"錯誤\",\n \"positive\": \"成功\"\n}\n"],"names":[],"version":3,"file":"zh-TW.main.js.map"}
|
package/dist/zh-TW.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var $19cbd4230357935e$exports = {};
|
|
2
|
+
$19cbd4230357935e$exports = {
|
|
3
|
+
"info": `\u{8CC7}\u{8A0A}`,
|
|
4
|
+
"negative": `\u{932F}\u{8AA4}`,
|
|
5
|
+
"positive": `\u{6210}\u{529F}`
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export {$19cbd4230357935e$exports as default};
|
|
10
|
+
//# sourceMappingURL=zh-TW.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";AAAA,4BAAiB;IAAG,QAAQ,CAAC,gBAAE,CAAC;IAC9B,YAAY,CAAC,gBAAE,CAAC;IAChB,YAAY,CAAC,gBAAE,CAAC;AAClB","sources":["packages/@react-spectrum/toast/intl/zh-TW.json"],"sourcesContent":["{\n \"info\": \"資訊\",\n \"negative\": \"錯誤\",\n \"positive\": \"成功\"\n}\n"],"names":[],"version":3,"file":"zh-TW.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-spectrum/toast",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.11",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -36,20 +36,22 @@
|
|
|
36
36
|
"url": "https://github.com/adobe/react-spectrum"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@react-aria/focus": "^3.
|
|
40
|
-
"@react-aria/i18n": "^3.
|
|
41
|
-
"@react-aria/
|
|
42
|
-
"@react-
|
|
43
|
-
"@react-
|
|
44
|
-
"@react-
|
|
45
|
-
"@react-
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
39
|
+
"@react-aria/focus": "^3.17.0",
|
|
40
|
+
"@react-aria/i18n": "^3.11.0",
|
|
41
|
+
"@react-aria/overlays": "^3.22.0",
|
|
42
|
+
"@react-aria/toast": "3.0.0-beta.11",
|
|
43
|
+
"@react-aria/utils": "^3.24.0",
|
|
44
|
+
"@react-spectrum/button": "^3.16.3",
|
|
45
|
+
"@react-spectrum/utils": "^3.11.6",
|
|
46
|
+
"@react-stately/toast": "3.0.0-beta.3",
|
|
47
|
+
"@react-types/shared": "^3.23.0",
|
|
48
|
+
"@spectrum-icons/ui": "^3.6.6",
|
|
49
|
+
"@swc/helpers": "^0.5.0",
|
|
48
50
|
"use-sync-external-store": "^1.2.0"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
53
|
"@adobe/spectrum-css-temp": "3.0.0-alpha.1",
|
|
52
|
-
"@react-spectrum/test-utils": "3.0.0-alpha.1",
|
|
54
|
+
"@react-spectrum/test-utils-internal": "3.0.0-alpha.1",
|
|
53
55
|
"@types/use-sync-external-store": "^0.0.3"
|
|
54
56
|
},
|
|
55
57
|
"peerDependencies": {
|
|
@@ -60,5 +62,5 @@
|
|
|
60
62
|
"publishConfig": {
|
|
61
63
|
"access": "public"
|
|
62
64
|
},
|
|
63
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "f645f29edc1322153fd60af4640cbcab1d992dbd"
|
|
64
66
|
}
|
package/src/Toast.tsx
CHANGED
|
@@ -14,22 +14,24 @@ import AlertMedium from '@spectrum-icons/ui/AlertMedium';
|
|
|
14
14
|
import {Button, ClearButton} from '@react-spectrum/button';
|
|
15
15
|
import {classNames, useDOMRef, useStyleProps} from '@react-spectrum/utils';
|
|
16
16
|
import CrossMedium from '@spectrum-icons/ui/CrossMedium';
|
|
17
|
-
import {DOMRef} from '@react-types/shared';
|
|
17
|
+
import {DOMProps, DOMRef} from '@react-types/shared';
|
|
18
|
+
import {filterDOMProps} from '@react-aria/utils';
|
|
18
19
|
import InfoMedium from '@spectrum-icons/ui/InfoMedium';
|
|
19
20
|
// @ts-ignore
|
|
20
21
|
import intlMessages from '../intl/*.json';
|
|
21
22
|
import {QueuedToast, ToastState} from '@react-stately/toast';
|
|
22
|
-
import React, {
|
|
23
|
+
import React, {useContext} from 'react';
|
|
23
24
|
import styles from '@adobe/spectrum-css-temp/components/toast/vars.css';
|
|
24
25
|
import SuccessMedium from '@spectrum-icons/ui/SuccessMedium';
|
|
25
26
|
import toastContainerStyles from './toastContainer.css';
|
|
27
|
+
import {ToasterContext} from './Toaster';
|
|
26
28
|
import {useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
27
29
|
import {useToast} from '@react-aria/toast';
|
|
28
30
|
|
|
29
|
-
export interface SpectrumToastValue {
|
|
30
|
-
children:
|
|
31
|
+
export interface SpectrumToastValue extends DOMProps {
|
|
32
|
+
children: string,
|
|
31
33
|
variant: 'positive' | 'negative' | 'info' | 'neutral',
|
|
32
|
-
actionLabel?:
|
|
34
|
+
actionLabel?: string,
|
|
33
35
|
onAction?: () => void,
|
|
34
36
|
shouldCloseOnAction?: boolean
|
|
35
37
|
}
|
|
@@ -70,9 +72,10 @@ function Toast(props: SpectrumToastProps, ref: DOMRef<HTMLDivElement>) {
|
|
|
70
72
|
} = useToast(props, state, domRef);
|
|
71
73
|
let {styleProps} = useStyleProps(otherProps);
|
|
72
74
|
|
|
73
|
-
let stringFormatter = useLocalizedStringFormatter(intlMessages);
|
|
75
|
+
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/toast');
|
|
74
76
|
let iconLabel = variant && variant !== 'neutral' ? stringFormatter.format(variant) : null;
|
|
75
77
|
let Icon = ICONS[variant];
|
|
78
|
+
let isFocusVisible = useContext(ToasterContext);
|
|
76
79
|
|
|
77
80
|
const handleAction = () => {
|
|
78
81
|
if (onAction) {
|
|
@@ -88,6 +91,7 @@ function Toast(props: SpectrumToastProps, ref: DOMRef<HTMLDivElement>) {
|
|
|
88
91
|
<div
|
|
89
92
|
{...styleProps}
|
|
90
93
|
{...toastProps}
|
|
94
|
+
{...filterDOMProps(props.toast.content)}
|
|
91
95
|
ref={domRef}
|
|
92
96
|
className={classNames(styles,
|
|
93
97
|
'spectrum-Toast',
|
|
@@ -95,7 +99,8 @@ function Toast(props: SpectrumToastProps, ref: DOMRef<HTMLDivElement>) {
|
|
|
95
99
|
styleProps.className,
|
|
96
100
|
classNames(
|
|
97
101
|
toastContainerStyles,
|
|
98
|
-
'spectrum-Toast'
|
|
102
|
+
'spectrum-Toast',
|
|
103
|
+
{'focus-ring': props.toast.key === state.visibleToasts[0]?.key && isFocusVisible}
|
|
99
104
|
)
|
|
100
105
|
)}
|
|
101
106
|
style={{
|
package/src/ToastContainer.tsx
CHANGED
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {AriaToastRegionProps} from '@react-aria/toast';
|
|
14
|
-
import
|
|
14
|
+
import {DOMProps} from '@react-types/shared';
|
|
15
|
+
import {filterDOMProps} from '@react-aria/utils';
|
|
16
|
+
import React, {ReactElement, useEffect, useRef} from 'react';
|
|
15
17
|
import {SpectrumToastValue, Toast} from './Toast';
|
|
16
18
|
import {Toaster} from './Toaster';
|
|
17
19
|
import {ToastOptions, ToastQueue, useToastQueue} from '@react-stately/toast';
|
|
@@ -19,9 +21,9 @@ import {useSyncExternalStore} from 'use-sync-external-store/shim/index.js';
|
|
|
19
21
|
|
|
20
22
|
export interface SpectrumToastContainerProps extends AriaToastRegionProps {}
|
|
21
23
|
|
|
22
|
-
export interface SpectrumToastOptions extends Omit<ToastOptions, 'priority'
|
|
24
|
+
export interface SpectrumToastOptions extends Omit<ToastOptions, 'priority'>, DOMProps {
|
|
23
25
|
/** A label for the action button within the toast. */
|
|
24
|
-
actionLabel?:
|
|
26
|
+
actionLabel?: string,
|
|
25
27
|
/** Handler that is called when the action button is pressed. */
|
|
26
28
|
onAction?: () => void,
|
|
27
29
|
/** Whether the toast should automatically close when an action is performed. */
|
|
@@ -35,7 +37,7 @@ let globalToastQueue: ToastQueue<SpectrumToastValue> | null = null;
|
|
|
35
37
|
function getGlobalToastQueue() {
|
|
36
38
|
if (!globalToastQueue) {
|
|
37
39
|
globalToastQueue = new ToastQueue({
|
|
38
|
-
maxVisibleToasts:
|
|
40
|
+
maxVisibleToasts: Infinity,
|
|
39
41
|
hasExitAnimation: true
|
|
40
42
|
});
|
|
41
43
|
}
|
|
@@ -55,6 +57,12 @@ function subscribe(fn: () => void) {
|
|
|
55
57
|
return () => subscriptions.delete(fn);
|
|
56
58
|
}
|
|
57
59
|
|
|
60
|
+
function triggerSubscriptions() {
|
|
61
|
+
for (let fn of subscriptions) {
|
|
62
|
+
fn();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
58
66
|
function getActiveToastContainer() {
|
|
59
67
|
return toastProviders.values().next().value;
|
|
60
68
|
}
|
|
@@ -73,10 +81,12 @@ export function ToastContainer(props: SpectrumToastContainerProps): ReactElement
|
|
|
73
81
|
// We use a ref to do this, since it will have a stable identity
|
|
74
82
|
// over the lifetime of the component.
|
|
75
83
|
let ref = useRef();
|
|
76
|
-
toastProviders.add(ref);
|
|
77
84
|
|
|
78
85
|
// eslint-disable-next-line arrow-body-style
|
|
79
86
|
useEffect(() => {
|
|
87
|
+
toastProviders.add(ref);
|
|
88
|
+
triggerSubscriptions();
|
|
89
|
+
|
|
80
90
|
return () => {
|
|
81
91
|
// When this toast provider unmounts, reset all animations so that
|
|
82
92
|
// when the new toast provider renders, it is seamless.
|
|
@@ -88,9 +98,7 @@ export function ToastContainer(props: SpectrumToastContainerProps): ReactElement
|
|
|
88
98
|
// This will cause all other instances to re-render,
|
|
89
99
|
// and the first one to become the new active toast provider.
|
|
90
100
|
toastProviders.delete(ref);
|
|
91
|
-
|
|
92
|
-
fn();
|
|
93
|
-
}
|
|
101
|
+
triggerSubscriptions();
|
|
94
102
|
};
|
|
95
103
|
}, []);
|
|
96
104
|
|
|
@@ -113,7 +121,7 @@ export function ToastContainer(props: SpectrumToastContainerProps): ReactElement
|
|
|
113
121
|
return null;
|
|
114
122
|
}
|
|
115
123
|
|
|
116
|
-
function addToast(children:
|
|
124
|
+
function addToast(children: string, variant: SpectrumToastValue['variant'], options: SpectrumToastOptions = {}) {
|
|
117
125
|
// Dispatch a custom event so that toasts can be intercepted and re-targeted, e.g. when inside an iframe.
|
|
118
126
|
if (typeof CustomEvent !== 'undefined' && typeof window !== 'undefined') {
|
|
119
127
|
let event = new CustomEvent('react-spectrum-toast', {
|
|
@@ -137,7 +145,8 @@ function addToast(children: ReactNode, variant: SpectrumToastValue['variant'], o
|
|
|
137
145
|
variant,
|
|
138
146
|
actionLabel: options.actionLabel,
|
|
139
147
|
onAction: options.onAction,
|
|
140
|
-
shouldCloseOnAction: options.shouldCloseOnAction
|
|
148
|
+
shouldCloseOnAction: options.shouldCloseOnAction,
|
|
149
|
+
...filterDOMProps(options)
|
|
141
150
|
};
|
|
142
151
|
|
|
143
152
|
// Minimum time of 5s from https://spectrum.adobe.com/page/toast/#Auto-dismissible
|
|
@@ -145,44 +154,27 @@ function addToast(children: ReactNode, variant: SpectrumToastValue['variant'], o
|
|
|
145
154
|
// It is debatable whether non-actionable toasts would also fail.
|
|
146
155
|
let timeout = options.timeout && !options.onAction ? Math.max(options.timeout, 5000) : null;
|
|
147
156
|
let queue = getGlobalToastQueue();
|
|
148
|
-
let key = queue.add(value, {
|
|
157
|
+
let key = queue.add(value, {timeout, onClose: options.onClose});
|
|
149
158
|
return () => queue.close(key);
|
|
150
159
|
}
|
|
151
160
|
|
|
152
161
|
const SpectrumToastQueue = {
|
|
153
162
|
/** Queues a neutral toast. */
|
|
154
|
-
neutral(children:
|
|
163
|
+
neutral(children: string, options: SpectrumToastOptions = {}): CloseFunction {
|
|
155
164
|
return addToast(children, 'neutral', options);
|
|
156
165
|
},
|
|
157
166
|
/** Queues a positive toast. */
|
|
158
|
-
positive(children:
|
|
167
|
+
positive(children: string, options: SpectrumToastOptions = {}): CloseFunction {
|
|
159
168
|
return addToast(children, 'positive', options);
|
|
160
169
|
},
|
|
161
170
|
/** Queues a negative toast. */
|
|
162
|
-
negative(children:
|
|
171
|
+
negative(children: string, options: SpectrumToastOptions = {}): CloseFunction {
|
|
163
172
|
return addToast(children, 'negative', options);
|
|
164
173
|
},
|
|
165
174
|
/** Queues an informational toast. */
|
|
166
|
-
info(children:
|
|
175
|
+
info(children: string, options: SpectrumToastOptions = {}): CloseFunction {
|
|
167
176
|
return addToast(children, 'info', options);
|
|
168
177
|
}
|
|
169
178
|
};
|
|
170
179
|
|
|
171
180
|
export {SpectrumToastQueue as ToastQueue};
|
|
172
|
-
|
|
173
|
-
// https://spectrum.adobe.com/page/toast/#Priority-queue
|
|
174
|
-
// TODO: if a lower priority toast comes in, no way to know until you dismiss the higher priority one.
|
|
175
|
-
const VARIANT_PRIORITY = {
|
|
176
|
-
negative: 10,
|
|
177
|
-
positive: 3,
|
|
178
|
-
info: 2,
|
|
179
|
-
neutral: 1
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
function getPriority(variant: SpectrumToastValue['variant'], options: SpectrumToastOptions) {
|
|
183
|
-
let priority = VARIANT_PRIORITY[variant] || 1;
|
|
184
|
-
if (options.onAction) {
|
|
185
|
-
priority += 4;
|
|
186
|
-
}
|
|
187
|
-
return priority;
|
|
188
|
-
}
|
package/src/Toaster.tsx
CHANGED
|
@@ -11,46 +11,51 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {AriaToastRegionProps, useToastRegion} from '@react-aria/toast';
|
|
14
|
-
import {classNames
|
|
15
|
-
import {
|
|
14
|
+
import {classNames} from '@react-spectrum/utils';
|
|
15
|
+
import {mergeProps} from '@react-aria/utils';
|
|
16
16
|
import {Provider} from '@react-spectrum/provider';
|
|
17
|
-
import React, {ReactElement, ReactNode, useRef} from 'react';
|
|
17
|
+
import React, {createContext, ReactElement, ReactNode, useRef} from 'react';
|
|
18
18
|
import ReactDOM from 'react-dom';
|
|
19
19
|
import toastContainerStyles from './toastContainer.css';
|
|
20
20
|
import {ToastState} from '@react-stately/toast';
|
|
21
|
+
import {useFocusRing} from '@react-aria/focus';
|
|
22
|
+
import {useUNSTABLE_PortalContext} from '@react-aria/overlays';
|
|
21
23
|
|
|
22
24
|
interface ToastContainerProps extends AriaToastRegionProps {
|
|
23
25
|
children: ReactNode,
|
|
24
26
|
state: ToastState<unknown>
|
|
25
27
|
}
|
|
26
28
|
|
|
29
|
+
export const ToasterContext = createContext(false);
|
|
30
|
+
|
|
27
31
|
export function Toaster(props: ToastContainerProps): ReactElement {
|
|
28
32
|
let {
|
|
29
33
|
children,
|
|
30
34
|
state
|
|
31
35
|
} = props;
|
|
32
|
-
let containerPlacement = useIsMobileDevice() ? 'center' : 'right';
|
|
33
36
|
|
|
34
37
|
let ref = useRef();
|
|
35
38
|
let {regionProps} = useToastRegion(props, state, ref);
|
|
39
|
+
let {focusProps, isFocusVisible} = useFocusRing();
|
|
40
|
+
let {getContainer} = useUNSTABLE_PortalContext();
|
|
36
41
|
|
|
37
42
|
let contents = (
|
|
38
43
|
<Provider UNSAFE_style={{background: 'transparent'}}>
|
|
39
|
-
<
|
|
44
|
+
<ToasterContext.Provider value={isFocusVisible}>
|
|
40
45
|
<div
|
|
41
|
-
{...regionProps}
|
|
46
|
+
{...mergeProps(regionProps, focusProps)}
|
|
42
47
|
ref={ref}
|
|
43
48
|
data-position="bottom"
|
|
44
|
-
data-placement=
|
|
49
|
+
data-placement="center"
|
|
45
50
|
className={classNames(
|
|
46
51
|
toastContainerStyles,
|
|
47
52
|
'react-spectrum-ToastContainer'
|
|
48
53
|
)}>
|
|
49
54
|
{children}
|
|
50
55
|
</div>
|
|
51
|
-
</
|
|
56
|
+
</ToasterContext.Provider>
|
|
52
57
|
</Provider>
|
|
53
58
|
);
|
|
54
59
|
|
|
55
|
-
return ReactDOM.createPortal(contents, document.body);
|
|
60
|
+
return ReactDOM.createPortal(contents, getContainer?.() ?? document.body);
|
|
56
61
|
}
|
package/src/toastContainer.css
CHANGED
|
@@ -20,34 +20,23 @@
|
|
|
20
20
|
display: flex;
|
|
21
21
|
pointer-events: none;
|
|
22
22
|
outline: none;
|
|
23
|
-
|
|
24
|
-
> :first-child {
|
|
25
|
-
@inherit %spectrum-FocusRing-ring;
|
|
26
|
-
--spectrum-focus-ring-border-radius: var(--spectrum-toast-border-radius);
|
|
27
|
-
--spectrum-focus-ring-gap: var(--spectrum-alias-focus-ring-gap);
|
|
28
|
-
--spectrum-focus-ring-size: var(--spectrum-alias-focus-ring-size);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
&:focus-ring > :first-child {
|
|
32
|
-
@inherit %spectrum-FocusRing-active;
|
|
33
|
-
}
|
|
23
|
+
margin-block-end: 8px;
|
|
34
24
|
|
|
35
25
|
.spectrum-Toast {
|
|
36
|
-
|
|
37
|
-
margin: 16px;
|
|
26
|
+
margin: 8px;
|
|
38
27
|
pointer-events: all;
|
|
39
28
|
}
|
|
40
29
|
|
|
41
30
|
&[data-position=top] {
|
|
42
31
|
top: 0;
|
|
43
|
-
flex-direction: column;
|
|
32
|
+
flex-direction: column-reverse;
|
|
44
33
|
--slide-from: translateY(-100%);
|
|
45
34
|
--slide-to: translateY(0);
|
|
46
35
|
}
|
|
47
36
|
|
|
48
37
|
&[data-position=bottom] {
|
|
49
38
|
bottom: 0;
|
|
50
|
-
flex-direction: column
|
|
39
|
+
flex-direction: column;
|
|
51
40
|
--slide-from: translateY(100%);
|
|
52
41
|
--slide-to: translateY(0);
|
|
53
42
|
}
|
|
@@ -78,6 +67,11 @@
|
|
|
78
67
|
}
|
|
79
68
|
|
|
80
69
|
.spectrum-Toast {
|
|
70
|
+
composes: spectrum-FocusRing;
|
|
71
|
+
--spectrum-focus-ring-border-radius: var(--spectrum-toast-border-radius);
|
|
72
|
+
--spectrum-focus-ring-gap: var(--spectrum-alias-focus-ring-gap);
|
|
73
|
+
--spectrum-focus-ring-size: var(--spectrum-alias-focus-ring-size);
|
|
74
|
+
|
|
81
75
|
&[data-animation=entering] {
|
|
82
76
|
animation: slide-in 300ms;
|
|
83
77
|
}
|
package/dist/main.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
[dir=ltr] .spectrum-Toast_11df86{padding-right:var(--spectrum-toast-padding-right,var(--spectrum-global-dimension-size-100))}[dir=rtl] .spectrum-Toast_11df86{padding-left:var(--spectrum-toast-padding-right,var(--spectrum-global-dimension-size-100))}[dir=ltr] .spectrum-Toast_11df86{padding-left:var(--spectrum-toast-padding-left,var(--spectrum-global-dimension-size-200))}[dir=rtl] .spectrum-Toast_11df86{padding-right:var(--spectrum-toast-padding-left,var(--spectrum-global-dimension-size-200))}.spectrum-Toast_11df86{box-sizing:border-box;max-width:500px;border-radius:var(--spectrum-toast-border-radius,var(--spectrum-global-dimension-static-size-50));padding-top:var(--spectrum-toast-padding-y,var(--spectrum-global-dimension-size-100));padding-bottom:var(--spectrum-toast-padding-y,var(--spectrum-global-dimension-size-100));font-size:var(--spectrum-toast-text-size,var(--spectrum-alias-font-size-default));-webkit-font-smoothing:antialiased;flex-direction:row;align-items:stretch;display:inline-flex}[dir=ltr] .spectrum-Toast-typeIcon_11df86{margin-right:var(--spectrum-toast-icon-padding-right,var(--spectrum-global-dimension-size-150))}[dir=rtl] .spectrum-Toast-typeIcon_11df86{margin-left:var(--spectrum-toast-icon-padding-right,var(--spectrum-global-dimension-size-150))}[dir=ltr] .spectrum-Toast-typeIcon_11df86{margin-left:0}[dir=rtl] .spectrum-Toast-typeIcon_11df86{margin-right:0}.spectrum-Toast-typeIcon_11df86{margin-top:var(--spectrum-global-dimension-size-85);margin-bottom:var(--spectrum-global-dimension-size-85);flex-grow:0;flex-shrink:0}[dir=ltr] .spectrum-Toast-content_11df86{padding-left:0}[dir=rtl] .spectrum-Toast-content_11df86{padding-right:0}[dir=ltr] .spectrum-Toast-content_11df86{text-align:left}[dir=rtl] .spectrum-Toast-content_11df86{text-align:right}.spectrum-Toast-content_11df86{box-sizing:border-box;padding-top:var(--spectrum-global-dimension-size-65);padding-bottom:var(--spectrum-global-dimension-size-65);flex:auto}.spectrum-Toast-buttons_11df86{flex:none;align-items:flex-start;display:flex}[dir=ltr] .spectrum-Toast-buttons_11df86 .spectrum-Button_11df86+.spectrum-Button_11df86,[dir=ltr] .spectrum-Toast-buttons_11df86 .spectrum-Button_11df86+.spectrum-ClearButton_11df86,[dir=ltr] .spectrum-Toast-buttons_11df86 .spectrum-ClearButton_11df86+.spectrum-Button_11df86,[dir=ltr] .spectrum-Toast-buttons_11df86 .spectrum-ClearButton_11df86+.spectrum-ClearButton_11df86{margin-left:var(--spectrum-toast-button-gap,var(--spectrum-global-dimension-size-100))}[dir=rtl] .spectrum-Toast-buttons_11df86 .spectrum-Button_11df86+.spectrum-Button_11df86,[dir=rtl] .spectrum-Toast-buttons_11df86 .spectrum-Button_11df86+.spectrum-ClearButton_11df86,[dir=rtl] .spectrum-Toast-buttons_11df86 .spectrum-ClearButton_11df86+.spectrum-Button_11df86,[dir=rtl] .spectrum-Toast-buttons_11df86 .spectrum-ClearButton_11df86+.spectrum-ClearButton_11df86{margin-right:var(--spectrum-toast-button-gap,var(--spectrum-global-dimension-size-100))}[dir=ltr] .spectrum-Toast-body_11df86{padding-right:var(--spectrum-toast-content-padding-right,var(--spectrum-global-dimension-size-200))}[dir=rtl] .spectrum-Toast-body_11df86{padding-left:var(--spectrum-toast-content-padding-right,var(--spectrum-global-dimension-size-200))}.spectrum-Toast-body_11df86{justify-content:flex-end;align-self:center;column-gap:var(--spectrum-toast-content-padding-right,var(--spectrum-global-dimension-size-200));flex-wrap:wrap;flex:auto;display:flex}[dir=ltr] .spectrum-Toast-body_11df86+.spectrum-Toast-buttons_11df86{padding-left:var(--spectrum-toast-padding-right,var(--spectrum-global-dimension-size-100))}[dir=rtl] .spectrum-Toast-body_11df86+.spectrum-Toast-buttons_11df86{padding-right:var(--spectrum-toast-padding-right,var(--spectrum-global-dimension-size-100))}[dir=ltr] .spectrum-Toast-body_11df86+.spectrum-Toast-buttons_11df86{border-left-width:1px}[dir=rtl] .spectrum-Toast-body_11df86+.spectrum-Toast-buttons_11df86{border-right-width:1px}[dir=ltr] .spectrum-Toast-body_11df86+.spectrum-Toast-buttons_11df86{border-left-style:solid}[dir=rtl] .spectrum-Toast-body_11df86+.spectrum-Toast-buttons_11df86{border-right-style:solid}.spectrum-Toast_11df86{background-color:var(--spectrum-alias-neutral-background-color);color:#fff}.spectrum-Toast-content_11df86{color:var(--spectrum-toast-text-color,var(--spectrum-global-color-static-white))}.spectrum-Toast-typeIcon_11df86{color:#fff}[dir=ltr] .spectrum-Toast-buttons_11df86{border-left-color:#fff3}[dir=rtl] .spectrum-Toast-buttons_11df86{border-right-color:#fff3}.spectrum-Toast--negative_11df86{background-color:var(--spectrum-negative-background-color-default)}.spectrum-Toast--info_11df86{background-color:var(--spectrum-informative-background-color-default)}.spectrum-Toast--positive_11df86{background-color:var(--spectrum-positive-background-color-default)}@media (forced-colors:active){.spectrum-Toast_11df86{border:1px solid #0000}}.react-spectrum-ToastContainer_21a698>:first-child{--spectrum-focus-ring-border-radius:var(--spectrum-textfield-border-radius,var(--spectrum-alias-border-radius-regular));--spectrum-focus-ring-gap:var(--spectrum-alias-input-focusring-gap);--spectrum-focus-ring-size:var(--spectrum-alias-input-focusring-size);--spectrum-focus-ring-border-size:0px;--spectrum-focus-ring-color:var(--spectrum-high-contrast-focus-ring-color,var(--spectrum-alias-focus-ring-color,var(--spectrum-alias-focus-color)))}.react-spectrum-ToastContainer_21a698>:first-child:after{border-radius:calc(var(--spectrum-focus-ring-border-radius) + var(--spectrum-focus-ring-gap));content:"";margin:calc(-1*var(--spectrum-focus-ring-border-size));pointer-events:none;transition:box-shadow var(--spectrum-global-animation-duration-100,.13s)ease-out,margin var(--spectrum-global-animation-duration-100,.13s)ease-out;display:block;position:absolute;top:0;bottom:0;left:0;right:0}.react-spectrum-ToastContainer_21a698.focus-ring_21a698>:first-child:after{margin:calc(var(--spectrum-focus-ring-gap)*-1 - var(--spectrum-focus-ring-border-size));box-shadow:0 0 0 var(--spectrum-focus-ring-size)var(--spectrum-focus-ring-color)}[dir=ltr] .react-spectrum-ToastContainer_21a698{left:0}[dir=rtl] .react-spectrum-ToastContainer_21a698,[dir=ltr] .react-spectrum-ToastContainer_21a698{right:0}[dir=rtl] .react-spectrum-ToastContainer_21a698{left:0}.react-spectrum-ToastContainer_21a698{z-index:100050;pointer-events:none;outline:none;display:flex;position:fixed}.react-spectrum-ToastContainer_21a698>:first-child{--spectrum-focus-ring-border-radius:var(--spectrum-toast-border-radius,var(--spectrum-global-dimension-static-size-50));--spectrum-focus-ring-gap:var(--spectrum-alias-focus-ring-gap,var(--spectrum-global-dimension-static-size-25));--spectrum-focus-ring-size:var(--spectrum-alias-focus-ring-size,var(--spectrum-global-dimension-static-size-25))}.react-spectrum-ToastContainer_21a698 .spectrum-Toast_21a698{pointer-events:all;margin:16px;position:absolute}.react-spectrum-ToastContainer_21a698[data-position=top]{--slide-from:translateY(-100%);--slide-to:translateY(0);flex-direction:column;top:0}.react-spectrum-ToastContainer_21a698[data-position=bottom]{--slide-from:translateY(100%);--slide-to:translateY(0);flex-direction:column-reverse;bottom:0}.react-spectrum-ToastContainer_21a698[data-placement=left]{--slide-from:translateX(-100%);--slide-to:translateX(0);align-items:flex-start}[dir=rtl] .react-spectrum-ToastContainer_21a698[data-placement=left]{--slide-from:translateX(100%)}.react-spectrum-ToastContainer_21a698[data-placement=center]{align-items:center}.react-spectrum-ToastContainer_21a698[data-placement=right]{--slide-from:translateX(100%);--slide-to:translateX(0);align-items:flex-end}[dir=rtl] .react-spectrum-ToastContainer_21a698[data-placement=right]{--slide-from:translateX(-100%)}.spectrum-Toast_21a698[data-animation=entering]{animation:.3s slide-in_21a698}.spectrum-Toast_21a698[data-animation=exiting]{animation:.3s forwards fade-out_21a698}@keyframes slide-in_21a698{0%{transform:var(--slide-from)}to{transform:var(--slide-to)}}@keyframes fade-out_21a698{0%{opacity:1}to{opacity:0}}
|