@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
package/src/Toast.tsx
CHANGED
|
@@ -14,7 +14,8 @@ 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';
|
|
@@ -27,7 +28,7 @@ import {ToasterContext} from './Toaster';
|
|
|
27
28
|
import {useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
28
29
|
import {useToast} from '@react-aria/toast';
|
|
29
30
|
|
|
30
|
-
export interface SpectrumToastValue {
|
|
31
|
+
export interface SpectrumToastValue extends DOMProps {
|
|
31
32
|
children: string,
|
|
32
33
|
variant: 'positive' | 'negative' | 'info' | 'neutral',
|
|
33
34
|
actionLabel?: string,
|
|
@@ -90,6 +91,7 @@ function Toast(props: SpectrumToastProps, ref: DOMRef<HTMLDivElement>) {
|
|
|
90
91
|
<div
|
|
91
92
|
{...styleProps}
|
|
92
93
|
{...toastProps}
|
|
94
|
+
{...filterDOMProps(props.toast.content)}
|
|
93
95
|
ref={domRef}
|
|
94
96
|
className={classNames(styles,
|
|
95
97
|
'spectrum-Toast',
|
package/src/ToastContainer.tsx
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {AriaToastRegionProps} from '@react-aria/toast';
|
|
14
|
+
import {DOMProps} from '@react-types/shared';
|
|
15
|
+
import {filterDOMProps} from '@react-aria/utils';
|
|
14
16
|
import React, {ReactElement, useEffect, useRef} from 'react';
|
|
15
17
|
import {SpectrumToastValue, Toast} from './Toast';
|
|
16
18
|
import {Toaster} from './Toaster';
|
|
@@ -19,7 +21,7 @@ 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
26
|
actionLabel?: string,
|
|
25
27
|
/** Handler that is called when the action button is pressed. */
|
|
@@ -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
|
}
|
|
@@ -143,7 +145,8 @@ function addToast(children: string, variant: SpectrumToastValue['variant'], opti
|
|
|
143
145
|
variant,
|
|
144
146
|
actionLabel: options.actionLabel,
|
|
145
147
|
onAction: options.onAction,
|
|
146
|
-
shouldCloseOnAction: options.shouldCloseOnAction
|
|
148
|
+
shouldCloseOnAction: options.shouldCloseOnAction,
|
|
149
|
+
...filterDOMProps(options)
|
|
147
150
|
};
|
|
148
151
|
|
|
149
152
|
// Minimum time of 5s from https://spectrum.adobe.com/page/toast/#Auto-dismissible
|
|
@@ -151,7 +154,7 @@ function addToast(children: string, variant: SpectrumToastValue['variant'], opti
|
|
|
151
154
|
// It is debatable whether non-actionable toasts would also fail.
|
|
152
155
|
let timeout = options.timeout && !options.onAction ? Math.max(options.timeout, 5000) : null;
|
|
153
156
|
let queue = getGlobalToastQueue();
|
|
154
|
-
let key = queue.add(value, {
|
|
157
|
+
let key = queue.add(value, {timeout, onClose: options.onClose});
|
|
155
158
|
return () => queue.close(key);
|
|
156
159
|
}
|
|
157
160
|
|
|
@@ -175,20 +178,3 @@ const SpectrumToastQueue = {
|
|
|
175
178
|
};
|
|
176
179
|
|
|
177
180
|
export {SpectrumToastQueue as ToastQueue};
|
|
178
|
-
|
|
179
|
-
// https://spectrum.adobe.com/page/toast/#Priority-queue
|
|
180
|
-
// TODO: if a lower priority toast comes in, no way to know until you dismiss the higher priority one.
|
|
181
|
-
const VARIANT_PRIORITY = {
|
|
182
|
-
negative: 10,
|
|
183
|
-
positive: 3,
|
|
184
|
-
info: 2,
|
|
185
|
-
neutral: 1
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
function getPriority(variant: SpectrumToastValue['variant'], options: SpectrumToastOptions) {
|
|
189
|
-
let priority = VARIANT_PRIORITY[variant] || 1;
|
|
190
|
-
if (options.onAction) {
|
|
191
|
-
priority += 4;
|
|
192
|
-
}
|
|
193
|
-
return priority;
|
|
194
|
-
}
|
package/src/Toaster.tsx
CHANGED
|
@@ -19,6 +19,7 @@ import ReactDOM from 'react-dom';
|
|
|
19
19
|
import toastContainerStyles from './toastContainer.css';
|
|
20
20
|
import {ToastState} from '@react-stately/toast';
|
|
21
21
|
import {useFocusRing} from '@react-aria/focus';
|
|
22
|
+
import {useUNSTABLE_PortalContext} from '@react-aria/overlays';
|
|
22
23
|
|
|
23
24
|
interface ToastContainerProps extends AriaToastRegionProps {
|
|
24
25
|
children: ReactNode,
|
|
@@ -36,6 +37,7 @@ export function Toaster(props: ToastContainerProps): ReactElement {
|
|
|
36
37
|
let ref = useRef();
|
|
37
38
|
let {regionProps} = useToastRegion(props, state, ref);
|
|
38
39
|
let {focusProps, isFocusVisible} = useFocusRing();
|
|
40
|
+
let {getContainer} = useUNSTABLE_PortalContext();
|
|
39
41
|
|
|
40
42
|
let contents = (
|
|
41
43
|
<Provider UNSAFE_style={{background: 'transparent'}}>
|
|
@@ -55,5 +57,5 @@ export function Toaster(props: ToastContainerProps): ReactElement {
|
|
|
55
57
|
</Provider>
|
|
56
58
|
);
|
|
57
59
|
|
|
58
|
-
return ReactDOM.createPortal(contents, document.body);
|
|
60
|
+
return ReactDOM.createPortal(contents, getContainer?.() ?? document.body);
|
|
59
61
|
}
|
package/src/toastContainer.css
CHANGED
|
@@ -20,23 +20,23 @@
|
|
|
20
20
|
display: flex;
|
|
21
21
|
pointer-events: none;
|
|
22
22
|
outline: none;
|
|
23
|
+
margin-block-end: 8px;
|
|
23
24
|
|
|
24
25
|
.spectrum-Toast {
|
|
25
|
-
|
|
26
|
-
margin: 16px;
|
|
26
|
+
margin: 8px;
|
|
27
27
|
pointer-events: all;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
&[data-position=top] {
|
|
31
31
|
top: 0;
|
|
32
|
-
flex-direction: column;
|
|
32
|
+
flex-direction: column-reverse;
|
|
33
33
|
--slide-from: translateY(-100%);
|
|
34
34
|
--slide-to: translateY(0);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
&[data-position=bottom] {
|
|
38
38
|
bottom: 0;
|
|
39
|
-
flex-direction: column
|
|
39
|
+
flex-direction: column;
|
|
40
40
|
--slide-from: translateY(100%);
|
|
41
41
|
--slide-to: translateY(0);
|
|
42
42
|
}
|
package/dist/main.css.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAwBA;;;;;;;;;;;;;;;AAkBA;;;;;;;;;AAUA;;;;;;;;;AASA;;;;;;AAOI;;;;AAAA;;;;AAAA;;;;AAAA;;;;AAOJ;;;;;;;;;;AAWE;;;;;;AAoBF;;;;;AAKA;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAIA;EACE;;;;;AC5HF;;;;;;;;AAOE;;;;;;;;;;;;;;AAiBF;;;AAII;;;;;AAQF;;;;AAKE;;;;;AAOJ;;;;;;;;;;AASE;;;;;;AAMA;;;;;;;AAOA;;;;;;;AAOA;;;;;;AAKE;;;;AAAA;;;;AAKF;;;;AAIA;;;;;;AAKE;;;;AAAA;;;;AAMJ;;;;;;AAME;;;;AAIA;;;;AAKF;;;;;;;;;;AAUA","sources":["packages/@adobe/spectrum-css-temp/components/toast/vars.css","packages/@react-spectrum/toast/src/toastContainer.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","/*\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 \"../../../@adobe/spectrum-css-temp/components/commons/focus-ring.css\";\n\n.react-spectrum-ToastContainer {\n position: fixed;\n inset-inline-start: 0;\n inset-inline-end: 0;\n z-index: 100050; /* above modals */\n display: flex;\n pointer-events: none;\n outline: none;\n\n .spectrum-Toast {\n position: absolute;\n margin: 16px;\n pointer-events: all;\n }\n\n &[data-position=top] {\n top: 0;\n flex-direction: column;\n --slide-from: translateY(-100%);\n --slide-to: translateY(0);\n }\n\n &[data-position=bottom] {\n bottom: 0;\n flex-direction: column-reverse;\n --slide-from: translateY(100%);\n --slide-to: translateY(0);\n }\n\n &[data-placement=left] {\n align-items: flex-start;\n --slide-from: translateX(-100%);\n --slide-to: translateX(0);\n\n &:dir(rtl) {\n --slide-from: translateX(100%);\n }\n }\n\n &[data-placement=center] {\n align-items: center;\n }\n\n &[data-placement=right] {\n align-items: flex-end;\n --slide-from: translateX(100%);\n --slide-to: translateX(0);\n\n &:dir(rtl) {\n --slide-from: translateX(-100%);\n }\n }\n}\n\n.spectrum-Toast {\n composes: spectrum-FocusRing;\n --spectrum-focus-ring-border-radius: var(--spectrum-toast-border-radius);\n --spectrum-focus-ring-gap: var(--spectrum-alias-focus-ring-gap);\n --spectrum-focus-ring-size: var(--spectrum-alias-focus-ring-size);\n\n &[data-animation=entering] {\n animation: slide-in 300ms;\n }\n\n &[data-animation=exiting] {\n animation: fade-out 300ms forwards;\n }\n}\n\n@keyframes slide-in {\n from {\n transform: var(--slide-from);\n }\n\n to {\n transform: var(--slide-to);\n }\n}\n\n@keyframes fade-out {\n from {\n opacity: 1;\n }\n\n to {\n opacity: 0;\n }\n}\n"],"names":[],"version":3,"file":"main.css.map"}
|