@react-aria/toast 3.0.0-nightly.1954

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/module.js ADDED
@@ -0,0 +1,398 @@
1
+ import {useEffect as $5bA4N$useEffect, useRef as $5bA4N$useRef} from "react";
2
+ import {useLayoutEffect as $5bA4N$useLayoutEffect, useId as $5bA4N$useId, useSlotId as $5bA4N$useSlotId, focusWithoutScrolling as $5bA4N$focusWithoutScrolling, mergeProps as $5bA4N$mergeProps} from "@react-aria/utils";
3
+ import {useLocalizedStringFormatter as $5bA4N$useLocalizedStringFormatter} from "@react-aria/i18n";
4
+ import {useHover as $5bA4N$useHover, useFocusWithin as $5bA4N$useFocusWithin, getInteractionModality as $5bA4N$getInteractionModality} from "@react-aria/interactions";
5
+ import {useLandmark as $5bA4N$useLandmark} from "@react-aria/landmark";
6
+
7
+ function $parcel$interopDefault(a) {
8
+ return a && a.__esModule ? a.default : a;
9
+ }
10
+ /*
11
+ * Copyright 2020 Adobe. All rights reserved.
12
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License. You may obtain a copy
14
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software distributed under
17
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
+ * OF ANY KIND, either express or implied. See the License for the specific language
19
+ * governing permissions and limitations under the License.
20
+ */ /*
21
+ * Copyright 2020 Adobe. All rights reserved.
22
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
23
+ * you may not use this file except in compliance with the License. You may obtain a copy
24
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
25
+ *
26
+ * Unless required by applicable law or agreed to in writing, software distributed under
27
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
28
+ * OF ANY KIND, either express or implied. See the License for the specific language
29
+ * governing permissions and limitations under the License.
30
+ */ var $ebf9e0ddd819695a$exports = {};
31
+ var $ff9177efc58547ad$exports = {};
32
+ $ff9177efc58547ad$exports = {
33
+ "close": `إغلاق`
34
+ };
35
+
36
+
37
+ var $25eb7c0c0c45e544$exports = {};
38
+ $25eb7c0c0c45e544$exports = {
39
+ "close": `Затвори`
40
+ };
41
+
42
+
43
+ var $28feffc3d61a8691$exports = {};
44
+ $28feffc3d61a8691$exports = {
45
+ "close": `Zavřít`
46
+ };
47
+
48
+
49
+ var $390d441203d25ff4$exports = {};
50
+ $390d441203d25ff4$exports = {
51
+ "close": `Luk`
52
+ };
53
+
54
+
55
+ var $7063c2d0f14f979a$exports = {};
56
+ $7063c2d0f14f979a$exports = {
57
+ "close": `Schließen`
58
+ };
59
+
60
+
61
+ var $2dfc1dbb6590af88$exports = {};
62
+ $2dfc1dbb6590af88$exports = {
63
+ "close": `Κλείσιμο`
64
+ };
65
+
66
+
67
+ var $9a12ff1caae5a7a5$exports = {};
68
+ $9a12ff1caae5a7a5$exports = {
69
+ "close": `Close`,
70
+ "notifications": `Notifications`
71
+ };
72
+
73
+
74
+ var $f4095fb5a72adbe6$exports = {};
75
+ $f4095fb5a72adbe6$exports = {
76
+ "close": `Cerrar`
77
+ };
78
+
79
+
80
+ var $75bc5191b9d7826a$exports = {};
81
+ $75bc5191b9d7826a$exports = {
82
+ "close": `Sule`
83
+ };
84
+
85
+
86
+ var $e4b9aef18b0db8dc$exports = {};
87
+ $e4b9aef18b0db8dc$exports = {
88
+ "close": `Sulje`
89
+ };
90
+
91
+
92
+ var $888756784d832bd7$exports = {};
93
+ $888756784d832bd7$exports = {
94
+ "close": `Fermer`
95
+ };
96
+
97
+
98
+ var $6835949b68a1fabf$exports = {};
99
+ $6835949b68a1fabf$exports = {
100
+ "close": `סגור`,
101
+ "notifications": `התראות`
102
+ };
103
+
104
+
105
+ var $87ffcbc0b651e40b$exports = {};
106
+ $87ffcbc0b651e40b$exports = {
107
+ "close": `Zatvori`
108
+ };
109
+
110
+
111
+ var $dc6e3b2813600d69$exports = {};
112
+ $dc6e3b2813600d69$exports = {
113
+ "close": `Bezárás`
114
+ };
115
+
116
+
117
+ var $fe136bcbacfcfa14$exports = {};
118
+ $fe136bcbacfcfa14$exports = {
119
+ "close": `Chiudi`
120
+ };
121
+
122
+
123
+ var $8fb53a929b46df83$exports = {};
124
+ $8fb53a929b46df83$exports = {
125
+ "close": `閉じる`
126
+ };
127
+
128
+
129
+ var $2c38dbfaf041a865$exports = {};
130
+ $2c38dbfaf041a865$exports = {
131
+ "close": `닫기`
132
+ };
133
+
134
+
135
+ var $48f3f33a29908d4c$exports = {};
136
+ $48f3f33a29908d4c$exports = {
137
+ "close": `Uždaryti`
138
+ };
139
+
140
+
141
+ var $9867160d996455a0$exports = {};
142
+ $9867160d996455a0$exports = {
143
+ "close": `Aizvērt`
144
+ };
145
+
146
+
147
+ var $196258ea25c96487$exports = {};
148
+ $196258ea25c96487$exports = {
149
+ "close": `Lukk`
150
+ };
151
+
152
+
153
+ var $949061cb954e8000$exports = {};
154
+ $949061cb954e8000$exports = {
155
+ "close": `Sluiten`
156
+ };
157
+
158
+
159
+ var $8189bed27add1ad3$exports = {};
160
+ $8189bed27add1ad3$exports = {
161
+ "close": `Zamknij`
162
+ };
163
+
164
+
165
+ var $a361756a93b6e28c$exports = {};
166
+ $a361756a93b6e28c$exports = {
167
+ "close": `Fechar`
168
+ };
169
+
170
+
171
+ var $034c7393857c8db0$exports = {};
172
+ $034c7393857c8db0$exports = {
173
+ "close": `Fechar`
174
+ };
175
+
176
+
177
+ var $e33d3b3868478b04$exports = {};
178
+ $e33d3b3868478b04$exports = {
179
+ "close": `Închideţi`
180
+ };
181
+
182
+
183
+ var $9a7dcb914b29cd9f$exports = {};
184
+ $9a7dcb914b29cd9f$exports = {
185
+ "close": `Закрыть`
186
+ };
187
+
188
+
189
+ var $e43d964a0c7f1266$exports = {};
190
+ $e43d964a0c7f1266$exports = {
191
+ "close": `Zatvoriť`
192
+ };
193
+
194
+
195
+ var $0bc56cee3275bcaa$exports = {};
196
+ $0bc56cee3275bcaa$exports = {
197
+ "close": `Zapri`
198
+ };
199
+
200
+
201
+ var $7dbdd7289c10d2ba$exports = {};
202
+ $7dbdd7289c10d2ba$exports = {
203
+ "close": `Zatvori`
204
+ };
205
+
206
+
207
+ var $ccbe6066c10b1e53$exports = {};
208
+ $ccbe6066c10b1e53$exports = {
209
+ "close": `Stäng`
210
+ };
211
+
212
+
213
+ var $9d503476b9d858b7$exports = {};
214
+ $9d503476b9d858b7$exports = {
215
+ "close": `Kapat`
216
+ };
217
+
218
+
219
+ var $32ee419c7b9b7a83$exports = {};
220
+ $32ee419c7b9b7a83$exports = {
221
+ "close": `Закрити`
222
+ };
223
+
224
+
225
+ var $122525af1cb737c7$exports = {};
226
+ $122525af1cb737c7$exports = {
227
+ "close": `关闭`
228
+ };
229
+
230
+
231
+ var $52e8b1b00094e5a3$exports = {};
232
+ $52e8b1b00094e5a3$exports = {
233
+ "close": `關閉`
234
+ };
235
+
236
+
237
+ $ebf9e0ddd819695a$exports = {
238
+ "ar-AE": $ff9177efc58547ad$exports,
239
+ "bg-BG": $25eb7c0c0c45e544$exports,
240
+ "cs-CZ": $28feffc3d61a8691$exports,
241
+ "da-DK": $390d441203d25ff4$exports,
242
+ "de-DE": $7063c2d0f14f979a$exports,
243
+ "el-GR": $2dfc1dbb6590af88$exports,
244
+ "en-US": $9a12ff1caae5a7a5$exports,
245
+ "es-ES": $f4095fb5a72adbe6$exports,
246
+ "et-EE": $75bc5191b9d7826a$exports,
247
+ "fi-FI": $e4b9aef18b0db8dc$exports,
248
+ "fr-FR": $888756784d832bd7$exports,
249
+ "he-IL": $6835949b68a1fabf$exports,
250
+ "hr-HR": $87ffcbc0b651e40b$exports,
251
+ "hu-HU": $dc6e3b2813600d69$exports,
252
+ "it-IT": $fe136bcbacfcfa14$exports,
253
+ "ja-JP": $8fb53a929b46df83$exports,
254
+ "ko-KR": $2c38dbfaf041a865$exports,
255
+ "lt-LT": $48f3f33a29908d4c$exports,
256
+ "lv-LV": $9867160d996455a0$exports,
257
+ "nb-NO": $196258ea25c96487$exports,
258
+ "nl-NL": $949061cb954e8000$exports,
259
+ "pl-PL": $8189bed27add1ad3$exports,
260
+ "pt-BR": $a361756a93b6e28c$exports,
261
+ "pt-PT": $034c7393857c8db0$exports,
262
+ "ro-RO": $e33d3b3868478b04$exports,
263
+ "ru-RU": $9a7dcb914b29cd9f$exports,
264
+ "sk-SK": $e43d964a0c7f1266$exports,
265
+ "sl-SI": $0bc56cee3275bcaa$exports,
266
+ "sr-SP": $7dbdd7289c10d2ba$exports,
267
+ "sv-SE": $ccbe6066c10b1e53$exports,
268
+ "tr-TR": $9d503476b9d858b7$exports,
269
+ "uk-UA": $32ee419c7b9b7a83$exports,
270
+ "zh-CN": $122525af1cb737c7$exports,
271
+ "zh-TW": $52e8b1b00094e5a3$exports
272
+ };
273
+
274
+
275
+
276
+
277
+
278
+ function $d6542812f0669241$export$a407b657d3044108(props, state, ref) {
279
+ let { key: key , timer: timer , timeout: timeout , animation: animation } = props.toast;
280
+ (0, $5bA4N$useEffect)(()=>{
281
+ if (!timer) return;
282
+ timer.reset(timeout);
283
+ return ()=>{
284
+ timer.pause();
285
+ };
286
+ }, [
287
+ timer,
288
+ timeout
289
+ ]);
290
+ // Restore focus to the toast container on unmount.
291
+ // If there are no more toasts, the container will be unmounted
292
+ // and will restore focus to wherever focus was before the user
293
+ // focused the toast region.
294
+ let focusOnUnmount = (0, $5bA4N$useRef)(null);
295
+ (0, $5bA4N$useLayoutEffect)(()=>{
296
+ let container = ref.current.closest("[role=region]");
297
+ return ()=>{
298
+ if (container && container.contains(document.activeElement)) // Focus must be delayed for focus ring to appear, but we can't wait
299
+ // until useEffect cleanup to check if focus was inside the container.
300
+ focusOnUnmount.current = container;
301
+ };
302
+ }, [
303
+ ref
304
+ ]);
305
+ // eslint-disable-next-line
306
+ (0, $5bA4N$useEffect)(()=>{
307
+ return ()=>{
308
+ if (focusOnUnmount.current) focusOnUnmount.current.focus();
309
+ };
310
+ }, [
311
+ ref
312
+ ]);
313
+ let titleId = (0, $5bA4N$useId)();
314
+ let descriptionId = (0, $5bA4N$useSlotId)();
315
+ let stringFormatter = (0, $5bA4N$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($ebf9e0ddd819695a$exports))));
316
+ return {
317
+ toastProps: {
318
+ role: "alert",
319
+ "aria-label": props["aria-label"],
320
+ "aria-labelledby": props["aria-labelledby"] || titleId,
321
+ "aria-describedby": props["aria-describedby"] || descriptionId,
322
+ "aria-details": props["aria-details"],
323
+ // Hide toasts that are animating out so VoiceOver doesn't announce them.
324
+ "aria-hidden": animation === "exiting" ? "true" : undefined
325
+ },
326
+ titleProps: {
327
+ id: titleId
328
+ },
329
+ descriptionProps: {
330
+ id: descriptionId
331
+ },
332
+ closeButtonProps: {
333
+ "aria-label": stringFormatter.format("close"),
334
+ onPress: ()=>state.close(key)
335
+ }
336
+ };
337
+ }
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
347
+ let stringFormatter = (0, $5bA4N$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($ebf9e0ddd819695a$exports))));
348
+ let { landmarkProps: landmarkProps } = (0, $5bA4N$useLandmark)({
349
+ role: "region",
350
+ "aria-label": props["aria-label"] || stringFormatter.format("notifications")
351
+ }, ref);
352
+ let { hoverProps: hoverProps } = (0, $5bA4N$useHover)({
353
+ onHoverStart: state.pauseAll,
354
+ onHoverEnd: state.resumeAll
355
+ });
356
+ let lastFocused = (0, $5bA4N$useRef)(null);
357
+ let { focusWithinProps: focusWithinProps } = (0, $5bA4N$useFocusWithin)({
358
+ onFocusWithin: (e)=>{
359
+ state.pauseAll();
360
+ lastFocused.current = e.relatedTarget;
361
+ },
362
+ onBlurWithin: ()=>{
363
+ state.resumeAll();
364
+ lastFocused.current = null;
365
+ }
366
+ });
367
+ // When the region unmounts, restore focus to the last element that had focus
368
+ // before the user moved focus into the region.
369
+ // TODO: handle when the element has unmounted like FocusScope does?
370
+ // eslint-disable-next-line arrow-body-style
371
+ (0, $5bA4N$useEffect)(()=>{
372
+ return ()=>{
373
+ if (lastFocused.current && document.body.contains(lastFocused.current)) {
374
+ if ((0, $5bA4N$getInteractionModality)() === "pointer") (0, $5bA4N$focusWithoutScrolling)(lastFocused.current);
375
+ else lastFocused.current.focus();
376
+ }
377
+ };
378
+ }, [
379
+ ref
380
+ ]);
381
+ return {
382
+ regionProps: (0, $5bA4N$mergeProps)(landmarkProps, hoverProps, focusWithinProps, {
383
+ tabIndex: -1,
384
+ // Mark the toast region as a "top layer", so that it:
385
+ // - is not aria-hidden when opening an overlay
386
+ // - allows focus even outside a containing focus scope
387
+ // - doesn’t dismiss overlays when clicking on it, even though it is outside
388
+ // @ts-ignore
389
+ "data-react-aria-top-layer": true
390
+ })
391
+ };
392
+ }
393
+
394
+
395
+
396
+
397
+ export {$d6542812f0669241$export$a407b657d3044108 as useToast, $6cc546b19ee7130a$export$b8cbbb20a51697de as useToastRegion};
398
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;;;AEAA,4BAAiB;IAAG,SAAS,CAAC,KAAK,CAAC;AACpC;;ADDA;;AEAA,4BAAiB;IAAG,SAAS,CAAC,OAAO,CAAC;AACtC;;;;ACDA,4BAAiB;IAAG,SAAS,CAAC,MAAM,CAAC;AACrC;;;;ACDA,4BAAiB;IAAG,SAAS,CAAC,GAAG,CAAC;AAClC;;;;ACDA,4BAAiB;IAAG,SAAS,CAAC,SAAS,CAAC;AACxC;;;;ACDA,4BAAiB;IAAG,SAAS,CAAC,QAAQ,CAAC;AACvC;;;;ACDA,4BAAiB;IAAG,SAAS,CAAC,KAAK,CAAC;IAClC,iBAAiB,CAAC,aAAa,CAAC;AAClC;;;;ACFA,4BAAiB;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AI,cAAc,CAAA,GAAA,aAAK,EAAE,IAAI;IAC7B,IAAI,oBAAC,iBAAgB,EAAC,GAAG,CAAA,GAAA,qBAAc,AAAD,EAAE;QACtC,eAAe,CAAC,IAAM;YACpB,MAAM,QAAQ;YACd,YAAY,OAAO,GAAG,EAAE,aAAa;QACvC;QACA,cAAc,IAAM;YAClB,MAAM,SAAS;YACf,YAAY,OAAO,GAAG,IAAI;QAC5B;IACF;IAEA,6EAA6E;IAC7E,+CAA+C;IAC/C,oEAAoE;IACpE,4CAA4C;IAC5C,CAAA,GAAA,gBAAS,AAAD,EAAE,IAAM;QACd,OAAO,IAAM;YACX,IAAI,YAAY,OAAO,IAAI,SAAS,IAAI,CAAC,QAAQ,CAAC,YAAY,OAAO;gBACnE,IAAI,CAAA,GAAA,6BAAqB,QAAQ,WAC/B,CAAA,GAAA,4BAAqB,AAAD,EAAE,YAAY,OAAO;qBAEzC,YAAY,OAAO,CAAC,KAAK;aAE5B;QACH;IACF,GAAG;QAAC;KAAI;IAER,OAAO;QACL,aAAa,CAAA,GAAA,iBAAS,EAAE,eAAe,YAAY,kBAAkB;YACnE,UAAU;YACV,sDAAsD;YACtD,iDAAiD;YACjD,yDAAyD;YACzD,8EAA8E;YAC9E,aAAa;YACb,6BAA6B,IAAI;QACnC;IACF;AACF;","sources":["packages/@react-aria/toast/src/index.ts","packages/@react-aria/toast/src/useToast.ts","packages/@react-aria/toast/intl/*.js","packages/@react-aria/toast/intl/ar-AE.json","packages/@react-aria/toast/intl/bg-BG.json","packages/@react-aria/toast/intl/cs-CZ.json","packages/@react-aria/toast/intl/da-DK.json","packages/@react-aria/toast/intl/de-DE.json","packages/@react-aria/toast/intl/el-GR.json","packages/@react-aria/toast/intl/en-US.json","packages/@react-aria/toast/intl/es-ES.json","packages/@react-aria/toast/intl/et-EE.json","packages/@react-aria/toast/intl/fi-FI.json","packages/@react-aria/toast/intl/fr-FR.json","packages/@react-aria/toast/intl/he-IL.json","packages/@react-aria/toast/intl/hr-HR.json","packages/@react-aria/toast/intl/hu-HU.json","packages/@react-aria/toast/intl/it-IT.json","packages/@react-aria/toast/intl/ja-JP.json","packages/@react-aria/toast/intl/ko-KR.json","packages/@react-aria/toast/intl/lt-LT.json","packages/@react-aria/toast/intl/lv-LV.json","packages/@react-aria/toast/intl/nb-NO.json","packages/@react-aria/toast/intl/nl-NL.json","packages/@react-aria/toast/intl/pl-PL.json","packages/@react-aria/toast/intl/pt-BR.json","packages/@react-aria/toast/intl/pt-PT.json","packages/@react-aria/toast/intl/ro-RO.json","packages/@react-aria/toast/intl/ru-RU.json","packages/@react-aria/toast/intl/sk-SK.json","packages/@react-aria/toast/intl/sl-SI.json","packages/@react-aria/toast/intl/sr-SP.json","packages/@react-aria/toast/intl/sv-SE.json","packages/@react-aria/toast/intl/tr-TR.json","packages/@react-aria/toast/intl/uk-UA.json","packages/@react-aria/toast/intl/zh-CN.json","packages/@react-aria/toast/intl/zh-TW.json","packages/@react-aria/toast/src/useToastRegion.ts"],"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 */\nexport {useToast} from './useToast';\nexport {useToastRegion} from './useToastRegion';\n\nexport type {AriaToastRegionProps, ToastRegionAria} from './useToastRegion';\nexport type {AriaToastProps, ToastAria} from './useToast';\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\nimport {AriaButtonProps} from '@react-types/button';\nimport {AriaLabelingProps, DOMAttributes, FocusableElement} from '@react-types/shared';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {QueuedToast, ToastState} from '@react-stately/toast';\nimport {RefObject, useEffect, useRef} from 'react';\nimport {useId, useLayoutEffect, useSlotId} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaToastProps<T> extends AriaLabelingProps {\n /** The toast object. */\n toast: QueuedToast<T>\n}\n\nexport interface ToastAria {\n /** Props for the toast container element. */\n toastProps: DOMAttributes,\n /** Props for the toast title element. */\n titleProps: DOMAttributes,\n /** Props for the toast description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the toast close button. */\n closeButtonProps: AriaButtonProps\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toast component.\n * Toasts display brief, temporary notifications of actions, errors, or other events in an application.\n */\nexport function useToast<T>(props: AriaToastProps<T>, state: ToastState<T>, ref: RefObject<FocusableElement>): ToastAria {\n let {\n key,\n timer,\n timeout,\n animation\n } = props.toast;\n\n useEffect(() => {\n if (!timer) {\n return;\n }\n\n timer.reset(timeout);\n return () => {\n timer.pause();\n };\n }, [timer, timeout]);\n\n // Restore focus to the toast container on unmount.\n // If there are no more toasts, the container will be unmounted\n // and will restore focus to wherever focus was before the user\n // focused the toast region.\n let focusOnUnmount = useRef(null);\n useLayoutEffect(() => {\n let container = ref.current.closest('[role=region]') as HTMLElement;\n return () => {\n if (container && container.contains(document.activeElement)) {\n // Focus must be delayed for focus ring to appear, but we can't wait\n // until useEffect cleanup to check if focus was inside the container.\n focusOnUnmount.current = container;\n }\n };\n }, [ref]);\n\n // eslint-disable-next-line\n useEffect(() => {\n return () => {\n if (focusOnUnmount.current) {\n focusOnUnmount.current.focus();\n }\n };\n }, [ref]);\n\n let titleId = useId();\n let descriptionId = useSlotId();\n let stringFormatter = useLocalizedStringFormatter(intlMessages);\n\n return {\n toastProps: {\n role: 'alert',\n 'aria-label': props['aria-label'],\n 'aria-labelledby': props['aria-labelledby'] || titleId,\n 'aria-describedby': props['aria-describedby'] || descriptionId,\n 'aria-details': props['aria-details'],\n // Hide toasts that are animating out so VoiceOver doesn't announce them.\n 'aria-hidden': animation === 'exiting' ? 'true' : undefined\n },\n titleProps: {\n id: titleId\n },\n descriptionProps: {\n id: descriptionId\n },\n closeButtonProps: {\n 'aria-label': stringFormatter.format('close'),\n onPress: () => state.close(key)\n }\n };\n}\n","const _temp0 = require(\"./ar-AE.json\");\nconst _temp1 = require(\"./bg-BG.json\");\nconst _temp2 = require(\"./cs-CZ.json\");\nconst _temp3 = require(\"./da-DK.json\");\nconst _temp4 = require(\"./de-DE.json\");\nconst _temp5 = require(\"./el-GR.json\");\nconst _temp6 = require(\"./en-US.json\");\nconst _temp7 = require(\"./es-ES.json\");\nconst _temp8 = require(\"./et-EE.json\");\nconst _temp9 = require(\"./fi-FI.json\");\nconst _temp10 = require(\"./fr-FR.json\");\nconst _temp11 = require(\"./he-IL.json\");\nconst _temp12 = require(\"./hr-HR.json\");\nconst _temp13 = require(\"./hu-HU.json\");\nconst _temp14 = require(\"./it-IT.json\");\nconst _temp15 = require(\"./ja-JP.json\");\nconst _temp16 = require(\"./ko-KR.json\");\nconst _temp17 = require(\"./lt-LT.json\");\nconst _temp18 = require(\"./lv-LV.json\");\nconst _temp19 = require(\"./nb-NO.json\");\nconst _temp20 = require(\"./nl-NL.json\");\nconst _temp21 = require(\"./pl-PL.json\");\nconst _temp22 = require(\"./pt-BR.json\");\nconst _temp23 = require(\"./pt-PT.json\");\nconst _temp24 = require(\"./ro-RO.json\");\nconst _temp25 = require(\"./ru-RU.json\");\nconst _temp26 = require(\"./sk-SK.json\");\nconst _temp27 = require(\"./sl-SI.json\");\nconst _temp28 = require(\"./sr-SP.json\");\nconst _temp29 = require(\"./sv-SE.json\");\nconst _temp30 = require(\"./tr-TR.json\");\nconst _temp31 = require(\"./uk-UA.json\");\nconst _temp32 = require(\"./zh-CN.json\");\nconst _temp33 = require(\"./zh-TW.json\");\nmodule.exports = {\n \"ar-AE\": _temp0,\n \"bg-BG\": _temp1,\n \"cs-CZ\": _temp2,\n \"da-DK\": _temp3,\n \"de-DE\": _temp4,\n \"el-GR\": _temp5,\n \"en-US\": _temp6,\n \"es-ES\": _temp7,\n \"et-EE\": _temp8,\n \"fi-FI\": _temp9,\n \"fr-FR\": _temp10,\n \"he-IL\": _temp11,\n \"hr-HR\": _temp12,\n \"hu-HU\": _temp13,\n \"it-IT\": _temp14,\n \"ja-JP\": _temp15,\n \"ko-KR\": _temp16,\n \"lt-LT\": _temp17,\n \"lv-LV\": _temp18,\n \"nb-NO\": _temp19,\n \"nl-NL\": _temp20,\n \"pl-PL\": _temp21,\n \"pt-BR\": _temp22,\n \"pt-PT\": _temp23,\n \"ro-RO\": _temp24,\n \"ru-RU\": _temp25,\n \"sk-SK\": _temp26,\n \"sl-SI\": _temp27,\n \"sr-SP\": _temp28,\n \"sv-SE\": _temp29,\n \"tr-TR\": _temp30,\n \"uk-UA\": _temp31,\n \"zh-CN\": _temp32,\n \"zh-TW\": _temp33\n}","{\n \"close\": \"إغلاق\"\n}\n","{\n \"close\": \"Затвори\"\n}\n","{\n \"close\": \"Zavřít\"\n}\n","{\n \"close\": \"Luk\"\n}\n","{\n \"close\": \"Schließen\"\n}\n","{\n \"close\": \"Κλείσιμο\"\n}\n","{\n \"close\": \"Close\",\n \"notifications\": \"Notifications\"\n}\n","{\n \"close\": \"Cerrar\"\n}\n","{\n \"close\": \"Sule\"\n}\n","{\n \"close\": \"Sulje\"\n}\n","{\n \"close\": \"Fermer\"\n}\n","{\n \"close\": \"סגור\",\n \"notifications\": \"התראות\"\n}\n","{\n \"close\": \"Zatvori\"\n}\n","{\n \"close\": \"Bezárás\"\n}\n","{\n \"close\": \"Chiudi\"\n}\n","{\n \"close\": \"閉じる\"\n}\n","{\n \"close\": \"닫기\"\n}\n","{\n \"close\": \"Uždaryti\"\n}\n","{\n \"close\": \"Aizvērt\"\n}\n","{\n \"close\": \"Lukk\"\n}\n","{\n \"close\": \"Sluiten\"\n}\n","{\n \"close\": \"Zamknij\"\n}\n","{\n \"close\": \"Fechar\"\n}\n","{\n \"close\": \"Fechar\"\n}\n","{\n \"close\": \"Închideţi\"\n}\n","{\n \"close\": \"Закрыть\"\n}\n","{\n \"close\": \"Zatvoriť\"\n}\n","{\n \"close\": \"Zapri\"\n}\n","{\n \"close\": \"Zatvori\"\n}\n","{\n \"close\": \"Stäng\"\n}\n","{\n \"close\": \"Kapat\"\n}\n","{\n \"close\": \"Закрити\"\n}\n","{\n \"close\": \"关闭\"\n}\n","{\n \"close\": \"關閉\"\n}\n","import {AriaLabelingProps, DOMAttributes} from '@react-types/shared';\nimport {focusWithoutScrolling, mergeProps} from '@react-aria/utils';\nimport {getInteractionModality, useFocusWithin, useHover} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {RefObject, useEffect, useRef} from 'react';\nimport {ToastState} from '@react-stately/toast';\nimport {useLandmark} from '@react-aria/landmark';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaToastRegionProps extends AriaLabelingProps {\n /**\n * An accessibility label for the toast region.\n * @default \"Notifications\"\n */\n 'aria-label'?: string\n}\n\nexport interface ToastRegionAria {\n /** Props for the landmark region element. */\n regionProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toast region containing one or more toasts.\n * Toasts display brief, temporary notifications of actions, errors, or other events in an application.\n */\nexport function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState<T>, ref: RefObject<HTMLElement>): ToastRegionAria {\n let stringFormatter = useLocalizedStringFormatter(intlMessages);\n let {landmarkProps} = useLandmark({\n role: 'region',\n 'aria-label': props['aria-label'] || stringFormatter.format('notifications')\n }, ref);\n\n let {hoverProps} = useHover({\n onHoverStart: state.pauseAll,\n onHoverEnd: state.resumeAll\n });\n\n let lastFocused = useRef(null);\n let {focusWithinProps} = useFocusWithin({\n onFocusWithin: (e) => {\n state.pauseAll();\n lastFocused.current = e.relatedTarget;\n },\n onBlurWithin: () => {\n state.resumeAll();\n lastFocused.current = null;\n }\n });\n\n // When the region unmounts, restore focus to the last element that had focus\n // before the user moved focus into the region.\n // TODO: handle when the element has unmounted like FocusScope does?\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n if (lastFocused.current && document.body.contains(lastFocused.current)) {\n if (getInteractionModality() === 'pointer') {\n focusWithoutScrolling(lastFocused.current);\n } else {\n lastFocused.current.focus();\n }\n }\n };\n }, [ref]);\n\n return {\n regionProps: mergeProps(landmarkProps, hoverProps, focusWithinProps, {\n tabIndex: -1,\n // Mark the toast region as a \"top layer\", so that it:\n // - is not aria-hidden when opening an overlay\n // - allows focus even outside a containing focus scope\n // - doesn’t dismiss overlays when clicking on it, even though it is outside\n // @ts-ignore\n 'data-react-aria-top-layer': true\n })\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,41 @@
1
+ import { AriaButtonProps } from "@react-types/button";
2
+ import { AriaLabelingProps, DOMAttributes, FocusableElement } from "@react-types/shared";
3
+ import { QueuedToast, ToastState } from "@react-stately/toast";
4
+ import { RefObject } from "react";
5
+ export interface AriaToastProps<T> extends AriaLabelingProps {
6
+ /** The toast object. */
7
+ toast: QueuedToast<T>;
8
+ }
9
+ export interface ToastAria {
10
+ /** Props for the toast container element. */
11
+ toastProps: DOMAttributes;
12
+ /** Props for the toast title element. */
13
+ titleProps: DOMAttributes;
14
+ /** Props for the toast description element, if any. */
15
+ descriptionProps: DOMAttributes;
16
+ /** Props for the toast close button. */
17
+ closeButtonProps: AriaButtonProps;
18
+ }
19
+ /**
20
+ * Provides the behavior and accessibility implementation for a toast component.
21
+ * Toasts display brief, temporary notifications of actions, errors, or other events in an application.
22
+ */
23
+ export function useToast<T>(props: AriaToastProps<T>, state: ToastState<T>, ref: RefObject<FocusableElement>): ToastAria;
24
+ export interface AriaToastRegionProps extends AriaLabelingProps {
25
+ /**
26
+ * An accessibility label for the toast region.
27
+ * @default "Notifications"
28
+ */
29
+ 'aria-label'?: string;
30
+ }
31
+ export interface ToastRegionAria {
32
+ /** Props for the landmark region element. */
33
+ regionProps: DOMAttributes;
34
+ }
35
+ /**
36
+ * Provides the behavior and accessibility implementation for a toast region containing one or more toasts.
37
+ * Toasts display brief, temporary notifications of actions, errors, or other events in an application.
38
+ */
39
+ export function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState<T>, ref: RefObject<HTMLElement>): ToastRegionAria;
40
+
41
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAqBA,gCAAgC,CAAC,CAAE,SAAQ,iBAAiB;IAC1D,wBAAwB;IACxB,KAAK,EAAE,YAAY,CAAC,CAAC,CAAA;CACtB;AAED;IACE,6CAA6C;IAC7C,UAAU,EAAE,aAAa,CAAC;IAC1B,yCAAyC;IACzC,UAAU,EAAE,aAAa,CAAC;IAC1B,uDAAuD;IACvD,gBAAgB,EAAE,aAAa,CAAC;IAChC,wCAAwC;IACxC,gBAAgB,EAAE,eAAe,CAAA;CAClC;AAED;;;GAGG;AACH,yBAAyB,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,gBAAgB,CAAC,GAAG,SAAS,CAqEvH;ACpGD,qCAAsC,SAAQ,iBAAiB;IAC7D;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED;IACE,6CAA6C;IAC7C,WAAW,EAAE,aAAa,CAAA;CAC3B;AAED;;;GAGG;AACH,+BAA+B,CAAC,EAAE,KAAK,EAAE,oBAAoB,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,WAAW,CAAC,GAAG,eAAe,CAmDjI","sources":["packages/@react-aria/toast/src/packages/@react-aria/toast/src/useToast.ts","packages/@react-aria/toast/src/packages/@react-aria/toast/src/useToastRegion.ts","packages/@react-aria/toast/src/packages/@react-aria/toast/src/index.ts","packages/@react-aria/toast/src/index.ts"],"sourcesContent":[null,null,null,"/*\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 */\nexport {useToast} from './useToast';\nexport {useToastRegion} from './useToastRegion';\n\nexport type {AriaToastRegionProps, ToastRegionAria} from './useToastRegion';\nexport type {AriaToastProps, ToastAria} from './useToast';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@react-aria/toast",
3
+ "version": "3.0.0-nightly.1954+ff3e690ff",
4
+ "description": "Spectrum UI components in React",
5
+ "license": "Apache-2.0",
6
+ "main": "dist/main.js",
7
+ "module": "dist/module.js",
8
+ "types": "dist/types.d.ts",
9
+ "source": "src/index.ts",
10
+ "files": [
11
+ "dist",
12
+ "src"
13
+ ],
14
+ "sideEffects": false,
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/adobe/react-spectrum"
18
+ },
19
+ "dependencies": {
20
+ "@react-aria/i18n": "3.0.0-nightly.1954+ff3e690ff",
21
+ "@react-aria/interactions": "3.0.0-nightly.1954+ff3e690ff",
22
+ "@react-aria/landmark": "3.0.0-nightly.3654+ff3e690ff",
23
+ "@react-aria/utils": "3.0.0-nightly.1954+ff3e690ff",
24
+ "@react-stately/toast": "3.0.0-nightly.3654+ff3e690ff",
25
+ "@react-types/button": "3.7.1-nightly.3654+ff3e690ff",
26
+ "@react-types/shared": "3.0.0-nightly.1954+ff3e690ff",
27
+ "@swc/helpers": "^0.4.14"
28
+ },
29
+ "peerDependencies": {
30
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "gitHead": "ff3e690fffc6c54367b8057e28a0e5b9211f37b5"
36
+ }
package/src/index.ts ADDED
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ export {useToast} from './useToast';
13
+ export {useToastRegion} from './useToastRegion';
14
+
15
+ export type {AriaToastRegionProps, ToastRegionAria} from './useToastRegion';
16
+ export type {AriaToastProps, ToastAria} from './useToast';
@@ -0,0 +1,111 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import {AriaButtonProps} from '@react-types/button';
14
+ import {AriaLabelingProps, DOMAttributes, FocusableElement} from '@react-types/shared';
15
+ // @ts-ignore
16
+ import intlMessages from '../intl/*.json';
17
+ import {QueuedToast, ToastState} from '@react-stately/toast';
18
+ import {RefObject, useEffect, useRef} from 'react';
19
+ import {useId, useLayoutEffect, useSlotId} from '@react-aria/utils';
20
+ import {useLocalizedStringFormatter} from '@react-aria/i18n';
21
+
22
+ export interface AriaToastProps<T> extends AriaLabelingProps {
23
+ /** The toast object. */
24
+ toast: QueuedToast<T>
25
+ }
26
+
27
+ export interface ToastAria {
28
+ /** Props for the toast container element. */
29
+ toastProps: DOMAttributes,
30
+ /** Props for the toast title element. */
31
+ titleProps: DOMAttributes,
32
+ /** Props for the toast description element, if any. */
33
+ descriptionProps: DOMAttributes,
34
+ /** Props for the toast close button. */
35
+ closeButtonProps: AriaButtonProps
36
+ }
37
+
38
+ /**
39
+ * Provides the behavior and accessibility implementation for a toast component.
40
+ * Toasts display brief, temporary notifications of actions, errors, or other events in an application.
41
+ */
42
+ export function useToast<T>(props: AriaToastProps<T>, state: ToastState<T>, ref: RefObject<FocusableElement>): ToastAria {
43
+ let {
44
+ key,
45
+ timer,
46
+ timeout,
47
+ animation
48
+ } = props.toast;
49
+
50
+ useEffect(() => {
51
+ if (!timer) {
52
+ return;
53
+ }
54
+
55
+ timer.reset(timeout);
56
+ return () => {
57
+ timer.pause();
58
+ };
59
+ }, [timer, timeout]);
60
+
61
+ // Restore focus to the toast container on unmount.
62
+ // If there are no more toasts, the container will be unmounted
63
+ // and will restore focus to wherever focus was before the user
64
+ // focused the toast region.
65
+ let focusOnUnmount = useRef(null);
66
+ useLayoutEffect(() => {
67
+ let container = ref.current.closest('[role=region]') as HTMLElement;
68
+ return () => {
69
+ if (container && container.contains(document.activeElement)) {
70
+ // Focus must be delayed for focus ring to appear, but we can't wait
71
+ // until useEffect cleanup to check if focus was inside the container.
72
+ focusOnUnmount.current = container;
73
+ }
74
+ };
75
+ }, [ref]);
76
+
77
+ // eslint-disable-next-line
78
+ useEffect(() => {
79
+ return () => {
80
+ if (focusOnUnmount.current) {
81
+ focusOnUnmount.current.focus();
82
+ }
83
+ };
84
+ }, [ref]);
85
+
86
+ let titleId = useId();
87
+ let descriptionId = useSlotId();
88
+ let stringFormatter = useLocalizedStringFormatter(intlMessages);
89
+
90
+ return {
91
+ toastProps: {
92
+ role: 'alert',
93
+ 'aria-label': props['aria-label'],
94
+ 'aria-labelledby': props['aria-labelledby'] || titleId,
95
+ 'aria-describedby': props['aria-describedby'] || descriptionId,
96
+ 'aria-details': props['aria-details'],
97
+ // Hide toasts that are animating out so VoiceOver doesn't announce them.
98
+ 'aria-hidden': animation === 'exiting' ? 'true' : undefined
99
+ },
100
+ titleProps: {
101
+ id: titleId
102
+ },
103
+ descriptionProps: {
104
+ id: descriptionId
105
+ },
106
+ closeButtonProps: {
107
+ 'aria-label': stringFormatter.format('close'),
108
+ onPress: () => state.close(key)
109
+ }
110
+ };
111
+ }