@react-spectrum/toast 3.0.0-beta.10 → 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.
Files changed (81) hide show
  1. package/dist/Toast.main.js +112 -0
  2. package/dist/Toast.main.js.map +1 -0
  3. package/dist/Toast.mjs +107 -0
  4. package/dist/Toast.module.js +107 -0
  5. package/dist/Toast.module.js.map +1 -0
  6. package/dist/ToastContainer.main.js +146 -0
  7. package/dist/ToastContainer.main.js.map +1 -0
  8. package/dist/ToastContainer.mjs +136 -0
  9. package/dist/ToastContainer.module.js +136 -0
  10. package/dist/ToastContainer.module.js.map +1 -0
  11. package/dist/Toaster.main.js +67 -0
  12. package/dist/Toaster.main.js.map +1 -0
  13. package/dist/Toaster.mjs +61 -0
  14. package/dist/Toaster.module.js +61 -0
  15. package/dist/Toaster.module.js.map +1 -0
  16. package/dist/ar-AE.mjs +1 -1
  17. package/dist/bg-BG.mjs +1 -1
  18. package/dist/cs-CZ.mjs +1 -1
  19. package/dist/da-DK.mjs +1 -1
  20. package/dist/de-DE.mjs +1 -1
  21. package/dist/el-GR.mjs +1 -1
  22. package/dist/en-US.mjs +1 -1
  23. package/dist/es-ES.mjs +1 -1
  24. package/dist/et-EE.mjs +1 -1
  25. package/dist/fi-FI.mjs +1 -1
  26. package/dist/fr-FR.mjs +1 -1
  27. package/dist/he-IL.mjs +1 -1
  28. package/dist/hr-HR.mjs +1 -1
  29. package/dist/hu-HU.mjs +1 -1
  30. package/dist/import.mjs +1 -451
  31. package/dist/intlStrings.main.js +108 -0
  32. package/dist/intlStrings.main.js.map +1 -0
  33. package/dist/intlStrings.mjs +110 -0
  34. package/dist/intlStrings.module.js +110 -0
  35. package/dist/intlStrings.module.js.map +1 -0
  36. package/dist/it-IT.mjs +1 -1
  37. package/dist/ja-JP.mjs +1 -1
  38. package/dist/ko-KR.mjs +1 -1
  39. package/dist/lt-LT.mjs +1 -1
  40. package/dist/lv-LV.mjs +1 -1
  41. package/dist/main.js +3 -449
  42. package/dist/main.js.map +1 -1
  43. package/dist/module.js +1 -451
  44. package/dist/module.js.map +1 -1
  45. package/dist/nb-NO.mjs +1 -1
  46. package/dist/nl-NL.mjs +1 -1
  47. package/dist/pl-PL.mjs +1 -1
  48. package/dist/pt-BR.mjs +1 -1
  49. package/dist/pt-PT.mjs +1 -1
  50. package/dist/ro-RO.mjs +1 -1
  51. package/dist/ru-RU.mjs +1 -1
  52. package/dist/sk-SK.mjs +1 -1
  53. package/dist/sl-SI.mjs +1 -1
  54. package/dist/sr-SP.mjs +1 -1
  55. package/dist/sv-SE.mjs +1 -1
  56. package/dist/{main.css → toastContainer.b596792c.css} +16 -119
  57. package/dist/toastContainer.b596792c.css.map +1 -0
  58. package/dist/toastContainer_css.main.js +34 -0
  59. package/dist/toastContainer_css.main.js.map +1 -0
  60. package/dist/toastContainer_css.mjs +36 -0
  61. package/dist/toastContainer_css.module.js +36 -0
  62. package/dist/toastContainer_css.module.js.map +1 -0
  63. package/dist/toast_vars_css.main.js +38 -0
  64. package/dist/toast_vars_css.main.js.map +1 -0
  65. package/dist/toast_vars_css.mjs +40 -0
  66. package/dist/toast_vars_css.module.js +40 -0
  67. package/dist/toast_vars_css.module.js.map +1 -0
  68. package/dist/tr-TR.mjs +1 -1
  69. package/dist/types.d.ts +2 -1
  70. package/dist/types.d.ts.map +1 -1
  71. package/dist/uk-UA.mjs +1 -1
  72. package/dist/vars.85cde188.css +94 -0
  73. package/dist/vars.85cde188.css.map +1 -0
  74. package/dist/zh-CN.mjs +1 -1
  75. package/dist/zh-TW.mjs +1 -1
  76. package/package.json +13 -12
  77. package/src/Toast.tsx +4 -2
  78. package/src/ToastContainer.tsx +7 -21
  79. package/src/Toaster.tsx +3 -1
  80. package/src/toastContainer.css +4 -4
  81. package/dist/main.css.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-spectrum/toast",
3
- "version": "3.0.0-beta.10",
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,21 +36,22 @@
36
36
  "url": "https://github.com/adobe/react-spectrum"
37
37
  },
38
38
  "dependencies": {
39
- "@react-aria/focus": "^3.16.2",
40
- "@react-aria/i18n": "^3.10.2",
41
- "@react-aria/toast": "3.0.0-beta.10",
42
- "@react-aria/utils": "^3.23.2",
43
- "@react-spectrum/button": "^3.16.2",
44
- "@react-spectrum/utils": "^3.11.5",
45
- "@react-stately/toast": "3.0.0-beta.2",
46
- "@react-types/shared": "^3.22.1",
47
- "@spectrum-icons/ui": "^3.6.5",
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",
48
49
  "@swc/helpers": "^0.5.0",
49
50
  "use-sync-external-store": "^1.2.0"
50
51
  },
51
52
  "devDependencies": {
52
53
  "@adobe/spectrum-css-temp": "3.0.0-alpha.1",
53
- "@react-spectrum/test-utils": "3.0.0-alpha.1",
54
+ "@react-spectrum/test-utils-internal": "3.0.0-alpha.1",
54
55
  "@types/use-sync-external-store": "^0.0.3"
55
56
  },
56
57
  "peerDependencies": {
@@ -61,5 +62,5 @@
61
62
  "publishConfig": {
62
63
  "access": "public"
63
64
  },
64
- "gitHead": "de9f84a22583fc741c29b341d14cd35ef4cca161"
65
+ "gitHead": "f645f29edc1322153fd60af4640cbcab1d992dbd"
65
66
  }
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',
@@ -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: 1,
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, {priority: getPriority(variant, options), timeout, onClose: options.onClose});
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
  }
@@ -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
- position: absolute;
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-reverse;
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"}