@fluentui/react-toast 9.0.5 → 9.1.0
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/CHANGELOG.json +87 -3
- package/CHANGELOG.md +31 -4
- package/lib/components/ToastContainer/useToastContainer.js +28 -11
- package/lib/components/ToastContainer/useToastContainer.js.map +1 -1
- package/lib/components/ToastContainer/useToastContainerStyles.styles.js +2 -2
- package/lib/components/ToastContainer/useToastContainerStyles.styles.js.map +1 -1
- package/lib/components/ToastTrigger/useToastTrigger.js +1 -1
- package/lib/components/ToastTrigger/useToastTrigger.js.map +1 -1
- package/lib/components/Toaster/useToastAnnounce.js +47 -0
- package/lib/components/Toaster/useToastAnnounce.js.map +1 -0
- package/lib/components/Toaster/useToaster.js +32 -30
- package/lib/components/Toaster/useToaster.js.map +1 -1
- package/lib/components/Toaster/useToasterFocusManagement.js +85 -0
- package/lib/components/Toaster/useToasterFocusManagement.js.map +1 -0
- package/lib/components/Toaster/useToasterStyles.styles.js +4 -1
- package/lib/components/Toaster/useToasterStyles.styles.js.map +1 -1
- package/lib/state/useToaster.js +24 -6
- package/lib/state/useToaster.js.map +1 -1
- package/lib-commonjs/components/ToastContainer/useToastContainer.js +28 -11
- package/lib-commonjs/components/ToastContainer/useToastContainer.js.map +1 -1
- package/lib-commonjs/components/ToastContainer/useToastContainerStyles.styles.js +3 -3
- package/lib-commonjs/components/ToastContainer/useToastContainerStyles.styles.js.map +1 -1
- package/lib-commonjs/components/ToastTrigger/useToastTrigger.js +1 -1
- package/lib-commonjs/components/ToastTrigger/useToastTrigger.js.map +1 -1
- package/lib-commonjs/components/Toaster/useToastAnnounce.js +50 -0
- package/lib-commonjs/components/Toaster/useToastAnnounce.js.map +1 -0
- package/lib-commonjs/components/Toaster/useToaster.js +31 -29
- package/lib-commonjs/components/Toaster/useToaster.js.map +1 -1
- package/lib-commonjs/components/Toaster/useToasterFocusManagement.js +92 -0
- package/lib-commonjs/components/Toaster/useToasterFocusManagement.js.map +1 -0
- package/lib-commonjs/components/Toaster/useToasterStyles.styles.js +4 -1
- package/lib-commonjs/components/Toaster/useToasterStyles.styles.js.map +1 -1
- package/lib-commonjs/state/useToaster.js +24 -6
- package/lib-commonjs/state/useToaster.js.map +1 -1
- package/package.json +9 -8
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { isHTMLElement } from '@fluentui/react-utilities';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
|
4
|
+
import { ArrowDown, ArrowUp } from '@fluentui/keyboard-keys';
|
|
5
|
+
import { toastContainerClassNames } from '../ToastContainer';
|
|
6
|
+
const noop = ()=>undefined;
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/ export function useToasterFocusManagement_unstable(pauseAllToasts, playAllToasts) {
|
|
10
|
+
const { targetDocument } = useFluent();
|
|
11
|
+
const cleanupListenersRef = React.useRef(noop);
|
|
12
|
+
return React.useCallback((el)=>{
|
|
13
|
+
if (!el || !targetDocument) {
|
|
14
|
+
cleanupListenersRef.current();
|
|
15
|
+
cleanupListenersRef.current = noop;
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const toastContainerWalker = targetDocument.createTreeWalker(el, NodeFilter.SHOW_ELEMENT, {
|
|
19
|
+
acceptNode (node) {
|
|
20
|
+
if (isHTMLElement(node) && node.classList.contains(toastContainerClassNames.root)) {
|
|
21
|
+
return NodeFilter.FILTER_ACCEPT;
|
|
22
|
+
}
|
|
23
|
+
return NodeFilter.FILTER_SKIP;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* FIXME: https://github.com/microsoft/tabster/issues/299
|
|
28
|
+
* Toasts should be arrow navigable and focus should be trapped in a stack of tasts
|
|
29
|
+
* This is a temporary measure, Tabster does not have an API yet to enable mover arrow keys from within grouppers
|
|
30
|
+
* Once tabster fully supports this use case, remove this hook
|
|
31
|
+
*/ const keydownListener = (e)=>{
|
|
32
|
+
const { target , key } = e;
|
|
33
|
+
if (!isHTMLElement(target)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (key === ArrowDown) {
|
|
37
|
+
toastContainerWalker.currentNode = target;
|
|
38
|
+
let nextToastContainer = toastContainerWalker.nextNode();
|
|
39
|
+
if (!nextToastContainer) {
|
|
40
|
+
toastContainerWalker.currentNode = el;
|
|
41
|
+
nextToastContainer = toastContainerWalker.nextNode();
|
|
42
|
+
}
|
|
43
|
+
if (isHTMLElement(nextToastContainer)) {
|
|
44
|
+
nextToastContainer.focus();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (key === ArrowUp) {
|
|
48
|
+
toastContainerWalker.currentNode = target;
|
|
49
|
+
let prevToastContainer = toastContainerWalker.previousNode();
|
|
50
|
+
if (prevToastContainer && prevToastContainer.contains(target)) {
|
|
51
|
+
prevToastContainer = toastContainerWalker.previousNode();
|
|
52
|
+
}
|
|
53
|
+
if (!prevToastContainer) {
|
|
54
|
+
toastContainerWalker.currentNode = el;
|
|
55
|
+
prevToastContainer = toastContainerWalker.lastChild();
|
|
56
|
+
}
|
|
57
|
+
if (isHTMLElement(prevToastContainer)) {
|
|
58
|
+
prevToastContainer.focus();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const focusInListener = (e)=>{
|
|
63
|
+
if (isHTMLElement(e.currentTarget) && !e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)) {
|
|
64
|
+
pauseAllToasts();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const focusOutListener = (e)=>{
|
|
68
|
+
if (isHTMLElement(e.currentTarget) && !e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)) {
|
|
69
|
+
playAllToasts();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
el.addEventListener('keydown', keydownListener);
|
|
73
|
+
el.addEventListener('focusin', focusInListener);
|
|
74
|
+
el.addEventListener('focusout', focusOutListener);
|
|
75
|
+
cleanupListenersRef.current = ()=>{
|
|
76
|
+
el.removeEventListener('keydown', keydownListener);
|
|
77
|
+
el.removeEventListener('focusin', focusInListener);
|
|
78
|
+
el.removeEventListener('focusout', focusOutListener);
|
|
79
|
+
};
|
|
80
|
+
}, [
|
|
81
|
+
targetDocument,
|
|
82
|
+
pauseAllToasts,
|
|
83
|
+
playAllToasts
|
|
84
|
+
]);
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useToasterFocusManagement.ts"],"sourcesContent":["import { isHTMLElement } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { ArrowDown, ArrowUp } from '@fluentui/keyboard-keys';\nimport { toastContainerClassNames } from '../ToastContainer';\n\nconst noop = () => undefined;\n\n/**\n * @internal\n */\nexport function useToasterFocusManagement_unstable(pauseAllToasts: () => void, playAllToasts: () => void) {\n const { targetDocument } = useFluent();\n const cleanupListenersRef = React.useRef<() => void>(noop);\n\n return React.useCallback(\n (el: HTMLDivElement) => {\n if (!el || !targetDocument) {\n cleanupListenersRef.current();\n cleanupListenersRef.current = noop;\n return;\n }\n\n const toastContainerWalker = targetDocument.createTreeWalker(el, NodeFilter.SHOW_ELEMENT, {\n acceptNode(node: Node) {\n if (isHTMLElement(node) && node.classList.contains(toastContainerClassNames.root)) {\n return NodeFilter.FILTER_ACCEPT;\n }\n\n return NodeFilter.FILTER_SKIP;\n },\n });\n\n /**\n * FIXME: https://github.com/microsoft/tabster/issues/299\n * Toasts should be arrow navigable and focus should be trapped in a stack of tasts\n * This is a temporary measure, Tabster does not have an API yet to enable mover arrow keys from within grouppers\n * Once tabster fully supports this use case, remove this hook\n */\n const keydownListener = (e: KeyboardEvent) => {\n const { target, key } = e;\n if (!isHTMLElement(target)) {\n return;\n }\n\n if (key === ArrowDown) {\n toastContainerWalker.currentNode = target;\n let nextToastContainer = toastContainerWalker.nextNode();\n if (!nextToastContainer) {\n toastContainerWalker.currentNode = el;\n nextToastContainer = toastContainerWalker.nextNode();\n }\n\n if (isHTMLElement(nextToastContainer)) {\n nextToastContainer.focus();\n }\n }\n\n if (key === ArrowUp) {\n toastContainerWalker.currentNode = target;\n let prevToastContainer = toastContainerWalker.previousNode();\n if (prevToastContainer && prevToastContainer.contains(target)) {\n prevToastContainer = toastContainerWalker.previousNode();\n }\n\n if (!prevToastContainer) {\n toastContainerWalker.currentNode = el;\n prevToastContainer = toastContainerWalker.lastChild();\n }\n\n if (isHTMLElement(prevToastContainer)) {\n prevToastContainer.focus();\n }\n }\n };\n\n const focusInListener = (e: FocusEvent) => {\n if (\n isHTMLElement(e.currentTarget) &&\n !e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)\n ) {\n pauseAllToasts();\n }\n };\n\n const focusOutListener = (e: FocusEvent) => {\n if (\n isHTMLElement(e.currentTarget) &&\n !e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)\n ) {\n playAllToasts();\n }\n };\n\n el.addEventListener('keydown', keydownListener);\n el.addEventListener('focusin', focusInListener);\n el.addEventListener('focusout', focusOutListener);\n\n cleanupListenersRef.current = () => {\n el.removeEventListener('keydown', keydownListener);\n el.removeEventListener('focusin', focusInListener);\n el.removeEventListener('focusout', focusOutListener);\n };\n },\n [targetDocument, pauseAllToasts, playAllToasts],\n );\n}\n"],"names":["isHTMLElement","React","useFluent_unstable","useFluent","ArrowDown","ArrowUp","toastContainerClassNames","noop","undefined","useToasterFocusManagement_unstable","pauseAllToasts","playAllToasts","targetDocument","cleanupListenersRef","useRef","useCallback","el","current","toastContainerWalker","createTreeWalker","NodeFilter","SHOW_ELEMENT","acceptNode","node","classList","contains","root","FILTER_ACCEPT","FILTER_SKIP","keydownListener","e","target","key","currentNode","nextToastContainer","nextNode","focus","prevToastContainer","previousNode","lastChild","focusInListener","currentTarget","relat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_state_bottomStart, _state_bottomEnd, _state_topStart, _state_topEnd;
|
|
2
1
|
import { __resetStyles, mergeClasses } from '@griffel/react';
|
|
3
2
|
import { TOAST_POSITIONS, getPositionStyles } from '../../state/index';
|
|
4
3
|
export const toasterClassNames = {
|
|
@@ -15,24 +14,28 @@ export const useToasterStyles_unstable = state => {
|
|
|
15
14
|
const rootBaseClassName = useRootBaseClassName();
|
|
16
15
|
const className = mergeClasses(toasterClassNames.root, rootBaseClassName, state.root.className);
|
|
17
16
|
if (state.bottomStart) {
|
|
17
|
+
var _state_bottomStart;
|
|
18
18
|
state.bottomStart.className = className;
|
|
19
19
|
var _style;
|
|
20
20
|
(_style = (_state_bottomStart = state.bottomStart).style) !== null && _style !== void 0 ? _style : _state_bottomStart.style = {};
|
|
21
21
|
Object.assign(state.bottomStart.style, getPositionStyles(TOAST_POSITIONS.bottomStart, state.dir, state.offset));
|
|
22
22
|
}
|
|
23
23
|
if (state.bottomEnd) {
|
|
24
|
+
var _state_bottomEnd;
|
|
24
25
|
state.bottomEnd.className = className;
|
|
25
26
|
var _style1;
|
|
26
27
|
(_style1 = (_state_bottomEnd = state.bottomEnd).style) !== null && _style1 !== void 0 ? _style1 : _state_bottomEnd.style = {};
|
|
27
28
|
Object.assign(state.bottomEnd.style, getPositionStyles(TOAST_POSITIONS.bottomEnd, state.dir, state.offset));
|
|
28
29
|
}
|
|
29
30
|
if (state.topStart) {
|
|
31
|
+
var _state_topStart;
|
|
30
32
|
state.topStart.className = className;
|
|
31
33
|
var _style2;
|
|
32
34
|
(_style2 = (_state_topStart = state.topStart).style) !== null && _style2 !== void 0 ? _style2 : _state_topStart.style = {};
|
|
33
35
|
Object.assign(state.topStart.style, getPositionStyles(TOAST_POSITIONS.topStart, state.dir, state.offset));
|
|
34
36
|
}
|
|
35
37
|
if (state.topEnd) {
|
|
38
|
+
var _state_topEnd;
|
|
36
39
|
state.topEnd.className = className;
|
|
37
40
|
var _style3;
|
|
38
41
|
(_style3 = (_state_topEnd = state.topEnd).style) !== null && _style3 !== void 0 ? _style3 : _state_topEnd.style = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["__resetStyles","mergeClasses","TOAST_POSITIONS","getPositionStyles","toasterClassNames","root","useRootBaseClassName","useToasterStyles_unstable","state","rootBaseClassName","className","bottomStart","_state_bottomStart","_style","style","Object","assign","dir","offset","bottomEnd","_state_bottomEnd","_style1","topStart","_state_topStart","_style2","topEnd","_state_topEnd","_style3"],"sources":["useToasterStyles.styles.js"],"sourcesContent":["import { makeResetStyles, mergeClasses } from '@griffel/react';\nimport { TOAST_POSITIONS, getPositionStyles } from '../../state/index';\nexport const toasterClassNames = {\n root: 'fui-Toaster'\n};\n/**\n * Styles for the root slot\n */ const useRootBaseClassName = makeResetStyles({\n position: 'fixed',\n width: '292px',\n pointerEvents: 'none'\n});\n/**\n * Apply styling to the Toaster slots based on the state\n */ export const useToasterStyles_unstable = (state)=>{\n const rootBaseClassName = useRootBaseClassName();\n const className = mergeClasses(toasterClassNames.root, rootBaseClassName, state.root.className);\n if (state.bottomStart) {\n var _state_bottomStart;\n state.bottomStart.className = className;\n var _style;\n (_style = (_state_bottomStart = state.bottomStart).style) !== null && _style !== void 0 ? _style : _state_bottomStart.style = {};\n Object.assign(state.bottomStart.style, getPositionStyles(TOAST_POSITIONS.bottomStart, state.dir, state.offset));\n }\n if (state.bottomEnd) {\n var _state_bottomEnd;\n state.bottomEnd.className = className;\n var _style1;\n (_style1 = (_state_bottomEnd = state.bottomEnd).style) !== null && _style1 !== void 0 ? _style1 : _state_bottomEnd.style = {};\n Object.assign(state.bottomEnd.style, getPositionStyles(TOAST_POSITIONS.bottomEnd, state.dir, state.offset));\n }\n if (state.topStart) {\n var _state_topStart;\n state.topStart.className = className;\n var _style2;\n (_style2 = (_state_topStart = state.topStart).style) !== null && _style2 !== void 0 ? _style2 : _state_topStart.style = {};\n Object.assign(state.topStart.style, getPositionStyles(TOAST_POSITIONS.topStart, state.dir, state.offset));\n }\n if (state.topEnd) {\n var _state_topEnd;\n state.topEnd.className = className;\n var _style3;\n (_style3 = (_state_topEnd = state.topEnd).style) !== null && _style3 !== void 0 ? _style3 : _state_topEnd.style = {};\n Object.assign(state.topEnd.style, getPositionStyles(TOAST_POSITIONS.topEnd, state.dir, state.offset));\n }\n return state;\n};\n"],"mappings":"AAAA,SAAAA,aAAA,EAA0BC,YAAY,QAAQ,gBAAgB;AAC9D,SAASC,eAAe,EAAEC,iBAAiB,QAAQ,mBAAmB;AACtE,OAAO,MAAMC,iBAAiB,GAAG;EAC7BC,IAAI,EAAE;AACV,CAAC;AACD;AACA;AACA;AAAI,MAAMC,oBAAoB,gBAAGN,aAAA,+EAIhC,CAAC;AACF;AACA;AACA;AAAI,OAAO,MAAMO,yBAAyB,GAAIC,KAAK,IAAG;EAClD,MAAMC,iBAAiB,GAAGH,oBAAoB,CAAC,CAAC;EAChD,MAAMI,SAAS,GAAGT,YAAY,CAACG,iBAAiB,CAACC,IAAI,EAAEI,iBAAiB,EAAED,KAAK,CAACH,IAAI,CAACK,SAAS,CAAC;EAC/F,IAAIF,KAAK,CAACG,WAAW,EAAE;IACnB,IAAIC,kBAAkB;IACtBJ,KAAK,CAACG,WAAW,CAACD,SAAS,GAAGA,SAAS;IACvC,IAAIG,MAAM;IACV,CAACA,MAAM,GAAG,CAACD,kBAAkB,GAAGJ,KAAK,CAACG,WAAW,EAAEG,KAAK,MAAM,IAAI,IAAID,MAAM,KAAK,KAAK,CAAC,GAAGA,MAAM,GAAGD,kBAAkB,CAACE,KAAK,GAAG,CAAC,CAAC;IAChIC,MAAM,CAACC,MAAM,CAACR,KAAK,CAACG,WAAW,CAACG,KAAK,EAAEX,iBAAiB,CAACD,eAAe,CAACS,WAAW,EAAEH,KAAK,CAACS,GAAG,EAAET,KAAK,CAACU,MAAM,CAAC,CAAC;EACnH;EACA,IAAIV,KAAK,CAACW,SAAS,EAAE;IACjB,IAAIC,gBAAgB;IACpB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AAK,CAACiB,MAAM,CAACX,KAAK,EAAEX,iBAAiB,CAACD,eAAe,CAACuB,MAAM,EAAEjB,KAAK,CAACS,GAAG,EAAET,KAAK,CAACU,MAAM,CAAC,CAAC;EACzG;EACA,OAAOV,KAAK;AAChB,CAAC"}
|
package/lib/state/useToaster.js
CHANGED
|
@@ -18,11 +18,6 @@ export function useToaster(options = {}) {
|
|
|
18
18
|
return shortcuts.focus(e);
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
|
-
const tryRestoreFocus = React.useCallback(()=>{
|
|
22
|
-
var _lastActiveElementRef_current;
|
|
23
|
-
(_lastActiveElementRef_current = lastActiveElementRef.current) === null || _lastActiveElementRef_current === void 0 ? void 0 : _lastActiveElementRef_current.focus();
|
|
24
|
-
lastActiveElementRef.current = null;
|
|
25
|
-
}, []);
|
|
26
21
|
const pauseAllToasts = React.useCallback(()=>{
|
|
27
22
|
toaster.visibleToasts.forEach((toastId)=>{
|
|
28
23
|
var _toast_imperativeRef_current;
|
|
@@ -58,6 +53,28 @@ export function useToaster(options = {}) {
|
|
|
58
53
|
}, [
|
|
59
54
|
toaster
|
|
60
55
|
]);
|
|
56
|
+
const tryRestoreFocus = React.useCallback(()=>{
|
|
57
|
+
const mostRecentToast = getMostRecentVisibleToast();
|
|
58
|
+
if (mostRecentToast === null || mostRecentToast === void 0 ? void 0 : mostRecentToast.imperativeRef.current) {
|
|
59
|
+
mostRecentToast.imperativeRef.current.focus();
|
|
60
|
+
} else {
|
|
61
|
+
var _lastActiveElementRef_current;
|
|
62
|
+
(_lastActiveElementRef_current = lastActiveElementRef.current) === null || _lastActiveElementRef_current === void 0 ? void 0 : _lastActiveElementRef_current.focus();
|
|
63
|
+
lastActiveElementRef.current = null;
|
|
64
|
+
}
|
|
65
|
+
}, [
|
|
66
|
+
getMostRecentVisibleToast
|
|
67
|
+
]);
|
|
68
|
+
const closeAllToasts = React.useCallback(()=>{
|
|
69
|
+
toaster.visibleToasts.forEach((toastId)=>{
|
|
70
|
+
const toast = toaster.toasts.get(toastId);
|
|
71
|
+
toast === null || toast === void 0 ? void 0 : toast.close();
|
|
72
|
+
});
|
|
73
|
+
tryRestoreFocus();
|
|
74
|
+
}, [
|
|
75
|
+
toaster,
|
|
76
|
+
tryRestoreFocus
|
|
77
|
+
]);
|
|
61
78
|
React.useEffect(()=>{
|
|
62
79
|
if (!targetDocument) {
|
|
63
80
|
return;
|
|
@@ -157,6 +174,7 @@ export function useToaster(options = {}) {
|
|
|
157
174
|
toastsToRender,
|
|
158
175
|
pauseAllToasts,
|
|
159
176
|
playAllToasts,
|
|
160
|
-
tryRestoreFocus
|
|
177
|
+
tryRestoreFocus,
|
|
178
|
+
closeAllToasts
|
|
161
179
|
};
|
|
162
180
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useToaster.ts"],"sourcesContent":["import * as React from 'react';\nimport { isHTMLElement, useEventCallback, useForceUpdate } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { createToaster } from './vanilla';\nimport type {\n CommonToastDetail,\n ShowToastEventDetail,\n Toast,\n ToastListenerMap,\n ToastPosition,\n ToasterId,\n ToasterOptions,\n} from './types';\nimport { EVENTS } from './constants';\n\nexport function useToaster<TElement extends HTMLElement = HTMLDivElement>(options: Partial<ToasterOptions> = {}) {\n const forceUpdate = useForceUpdate();\n const { toasterId: userToasterId, shortcuts } = options;\n // Currently the toaster options can never be changed at runtime\n const [toaster] = React.useState(() => createToaster(options));\n const { targetDocument } = useFluent();\n\n const lastActiveElementRef = React.useRef<HTMLElement | null>(null);\n\n const isCorrectToaster = useEventCallback((toasterId: ToasterId | undefined) => {\n return toasterId === userToasterId;\n });\n\n const isFocusShortcut = useEventCallback((e: KeyboardEvent) => {\n if (shortcuts?.focus) {\n return shortcuts.focus(e);\n }\n });\n\n const tryRestoreFocus = React.useCallback(() => {\n lastActiveElementRef.current?.focus();\n lastActiveElementRef.current = null;\n }, []);\n\n const pauseAllToasts = React.useCallback(() => {\n toaster.visibleToasts.forEach(toastId => {\n const toast = toaster.toasts.get(toastId);\n toast?.imperativeRef.current?.pause();\n });\n }, [toaster]);\n\n const playAllToasts = React.useCallback(() => {\n toaster.visibleToasts.forEach(toastId => {\n const toast = toaster.toasts.get(toastId);\n toast?.imperativeRef.current?.play();\n });\n }, [toaster]);\n\n const getMostRecentVisibleToast = React.useCallback(() => {\n return Array.from(toaster.visibleToasts).reduce((cur, next) => {\n const toast = toaster.toasts.get(next);\n if (!toast) {\n return cur;\n }\n\n if (!cur) {\n return toast;\n }\n\n if (cur.order < toast?.order) {\n return toast;\n }\n\n return cur;\n }, undefined as Toast | undefined);\n }, [toaster]);\n\n React.useEffect(() => {\n if (!targetDocument) {\n return;\n }\n\n const addToastListener = <TType extends keyof ToastListenerMap>(\n eventType: TType,\n callback: ToastListenerMap[TType],\n ) => {\n const listener: ToastListenerMap[TType] = (e: CustomEvent<CommonToastDetail>) => {\n if (!isCorrectToaster(e.detail.toasterId)) {\n return;\n }\n\n callback(e as CustomEvent<ShowToastEventDetail>);\n forceUpdate();\n };\n\n targetDocument.addEventListener(eventType, listener as () => void);\n return () => targetDocument.removeEventListener(eventType, listener as () => void);\n };\n\n const buildToast: ToastListenerMap[typeof EVENTS.show] = e => {\n toaster.buildToast(e.detail, forceUpdate);\n };\n\n const dismissToast: ToastListenerMap[typeof EVENTS.dismiss] = e => {\n toaster.dismissToast(e.detail.toastId);\n };\n\n const updateToast: ToastListenerMap[typeof EVENTS.update] = e => {\n toaster.updateToast(e.detail);\n };\n\n const dismissAllToasts: ToastListenerMap[typeof EVENTS.dismissAll] = e => {\n toaster.dismissAllToasts();\n };\n\n const pauseToast: ToastListenerMap[typeof EVENTS.pause] = e => {\n const toast = toaster.toasts.get(e.detail.toastId);\n if (toast) {\n toast.imperativeRef.current?.pause();\n }\n };\n\n const playToast: ToastListenerMap[typeof EVENTS.play] = e => {\n const toast = toaster.toasts.get(e.detail.toastId);\n if (toast) {\n toast.imperativeRef.current?.play();\n }\n };\n\n const cleanupBuildListener = addToastListener(EVENTS.show, buildToast);\n const cleanupUpdateListener = addToastListener(EVENTS.update, updateToast);\n const cleanupDismissListener = addToastListener(EVENTS.dismiss, dismissToast);\n const cleanupDismissAllListener = addToastListener(EVENTS.dismissAll, dismissAllToasts);\n const cleanupPauseListener = addToastListener(EVENTS.pause, pauseToast);\n const cleanupPlayListener = addToastListener(EVENTS.play, playToast);\n\n const focusShortcutListener = (e: KeyboardEvent) => {\n if (isFocusShortcut(e)) {\n pauseAllToasts();\n const mostRecentToast = getMostRecentVisibleToast();\n\n if (mostRecentToast) {\n lastActiveElementRef.current = isHTMLElement(targetDocument.activeElement)\n ? targetDocument.activeElement\n : null;\n mostRecentToast.imperativeRef.current?.focus();\n }\n }\n };\n\n targetDocument.addEventListener('keydown', focusShortcutListener);\n\n return () => {\n cleanupBuildListener();\n cleanupDismissAllListener();\n cleanupUpdateListener();\n cleanupDismissListener();\n cleanupPauseListener();\n cleanupPlayListener();\n\n targetDocument.removeEventListener('keydown', focusShortcutListener);\n };\n }, [\n toaster,\n forceUpdate,\n targetDocument,\n isCorrectToaster,\n pauseAllToasts,\n getMostRecentVisibleToast,\n isFocusShortcut,\n ]);\n\n const toastsToRender = (() => {\n if (!toaster) {\n return new Map<ToastPosition, Toast[]>();\n }\n\n const toRender = new Map<ToastPosition, Toast[]>();\n const toasts = Array.from(toaster.toasts.values());\n\n toasts.forEach(toast => {\n const { position } = toast;\n toRender.has(position) || toRender.set(position, []);\n if (position.startsWith('bottom')) {\n toRender.get(position)!.push(toast);\n } else {\n toRender.get(position)!.unshift(toast);\n }\n });\n\n return toRender;\n })();\n\n return {\n isToastVisible: toaster.isToastVisible,\n toastsToRender,\n pauseAllToasts,\n playAllToasts,\n tryRestoreFocus,\n };\n}\n"],"names":["React","isHTMLElement","useEventCallback","useForceUpdate","useFluent_unstable","useFluent","createToaster","EVENTS","useToaster","options","forceUpdate","toasterId","userToasterId","shortcuts","toaster","useState","targetDocument","lastActiveElementRef","useRef","isCorrectToaster","isFocusShortcut","e","focus","tryRestoreFocus","useCallback","current","pauseAllToasts","visibleToasts","forEach","toastId","toast","toasts","get","imperativeRef","pause","playAllToasts","play","getMostRecentVisibleToast","Array","from","reduce","cur","next","order","undefined","useEffect","addToastListener","eventType","callback","listener","detail","addEventListener","removeEventListener","buildToast","dismissToast","updateToast","dismissAllToasts","pauseToast","playToast","cleanupBuildListener","show","cleanupUpdateListener","update","cleanupDismissListener","dismiss","cleanupDismissAllListener","dismissAll","cleanupPauseListener","cleanupPlayListener","focusShortcutListener","mostRecentToast","activeElement","toastsToRender","Map","toRender","values","position","has","set","startsWith","push","unshift","isToastVisible"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,aAAa,EAAEC,gBAAgB,EAAEC,cAAc,QAAQ,4BAA4B;AAC5F,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,aAAa,QAAQ,YAAY;AAU1C,SAASC,MAAM,QAAQ,cAAc;AAErC,OAAO,SAASC,WAA0DC,UAAmC,CAAC,CAAC,EAAE;IAC/G,MAAMC,cAAcP;IACpB,MAAM,EAAEQ,WAAWC,cAAa,EAAEC,UAAS,EAAE,GAAGJ;IAChD,gEAAgE;IAChE,MAAM,CAACK,QAAQ,GAAGd,MAAMe,QAAQ,CAAC,IAAMT,cAAcG;IACrD,MAAM,EAAEO,eAAc,EAAE,GAAGX;IAE3B,MAAMY,uBAAuBjB,MAAMkB,MAAM,CAAqB,IAAI;IAElE,MAAMC,mBAAmBjB,iBAAiB,CAACS,YAAqC;QAC9E,OAAOA,cAAcC;IACvB;IAEA,MAAMQ,kBAAkBlB,iBAAiB,CAACmB,IAAqB;QAC7D,IAAIR,sBAAAA,uBAAAA,KAAAA,IAAAA,UAAWS,KAAK,EAAE;YACpB,OAAOT,UAAUS,KAAK,CAACD;QACzB,CAAC;IACH;IAEA,MAAME,kBAAkBvB,MAAMwB,WAAW,CAAC,IA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AU,EAAE;YACnD,IAAIA,SAASG,UAAU,CAAC,WAAW;gBACjCL,SAAS1C,GAAG,CAAC4C,UAAWI,IAAI,CAAClD;YAC/B,OAAO;gBACL4C,SAAS1C,GAAG,CAAC4C,UAAWK,OAAO,CAACnD;YAClC,CAAC;QACH;QAEA,OAAO4C;IACT,CAAA;IAEA,OAAO;QACLQ,gBAAgBpE,QAAQoE,cAAc;QACtCV;QACA9C;QACAS;QACAZ;IACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"sources":["useToaster.ts"],"sourcesContent":["import * as React from 'react';\nimport { isHTMLElement, useEventCallback, useForceUpdate } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { createToaster } from './vanilla';\nimport type {\n CommonToastDetail,\n ShowToastEventDetail,\n Toast,\n ToastListenerMap,\n ToastPosition,\n ToasterId,\n ToasterOptions,\n} from './types';\nimport { EVENTS } from './constants';\n\nexport function useToaster<TElement extends HTMLElement = HTMLDivElement>(options: Partial<ToasterOptions> = {}) {\n const forceUpdate = useForceUpdate();\n const { toasterId: userToasterId, shortcuts } = options;\n // Currently the toaster options can never be changed at runtime\n const [toaster] = React.useState(() => createToaster(options));\n const { targetDocument } = useFluent();\n\n const lastActiveElementRef = React.useRef<HTMLElement | null>(null);\n\n const isCorrectToaster = useEventCallback((toasterId: ToasterId | undefined) => {\n return toasterId === userToasterId;\n });\n\n const isFocusShortcut = useEventCallback((e: KeyboardEvent) => {\n if (shortcuts?.focus) {\n return shortcuts.focus(e);\n }\n });\n\n const pauseAllToasts = React.useCallback(() => {\n toaster.visibleToasts.forEach(toastId => {\n const toast = toaster.toasts.get(toastId);\n toast?.imperativeRef.current?.pause();\n });\n }, [toaster]);\n\n const playAllToasts = React.useCallback(() => {\n toaster.visibleToasts.forEach(toastId => {\n const toast = toaster.toasts.get(toastId);\n toast?.imperativeRef.current?.play();\n });\n }, [toaster]);\n\n const getMostRecentVisibleToast = React.useCallback(() => {\n return Array.from(toaster.visibleToasts).reduce((cur, next) => {\n const toast = toaster.toasts.get(next);\n if (!toast) {\n return cur;\n }\n\n if (!cur) {\n return toast;\n }\n\n if (cur.order < toast?.order) {\n return toast;\n }\n\n return cur;\n }, undefined as Toast | undefined);\n }, [toaster]);\n\n const tryRestoreFocus = React.useCallback(() => {\n const mostRecentToast = getMostRecentVisibleToast();\n if (mostRecentToast?.imperativeRef.current) {\n mostRecentToast.imperativeRef.current.focus();\n } else {\n lastActiveElementRef.current?.focus();\n lastActiveElementRef.current = null;\n }\n }, [getMostRecentVisibleToast]);\n\n const closeAllToasts = React.useCallback(() => {\n toaster.visibleToasts.forEach(toastId => {\n const toast = toaster.toasts.get(toastId);\n toast?.close();\n });\n\n tryRestoreFocus();\n }, [toaster, tryRestoreFocus]);\n\n React.useEffect(() => {\n if (!targetDocument) {\n return;\n }\n\n const addToastListener = <TType extends keyof ToastListenerMap>(\n eventType: TType,\n callback: ToastListenerMap[TType],\n ) => {\n const listener: ToastListenerMap[TType] = (e: CustomEvent<CommonToastDetail>) => {\n if (!isCorrectToaster(e.detail.toasterId)) {\n return;\n }\n\n callback(e as CustomEvent<ShowToastEventDetail>);\n forceUpdate();\n };\n\n targetDocument.addEventListener(eventType, listener as () => void);\n return () => targetDocument.removeEventListener(eventType, listener as () => void);\n };\n\n const buildToast: ToastListenerMap[typeof EVENTS.show] = e => {\n toaster.buildToast(e.detail, forceUpdate);\n };\n\n const dismissToast: ToastListenerMap[typeof EVENTS.dismiss] = e => {\n toaster.dismissToast(e.detail.toastId);\n };\n\n const updateToast: ToastListenerMap[typeof EVENTS.update] = e => {\n toaster.updateToast(e.detail);\n };\n\n const dismissAllToasts: ToastListenerMap[typeof EVENTS.dismissAll] = e => {\n toaster.dismissAllToasts();\n };\n\n const pauseToast: ToastListenerMap[typeof EVENTS.pause] = e => {\n const toast = toaster.toasts.get(e.detail.toastId);\n if (toast) {\n toast.imperativeRef.current?.pause();\n }\n };\n\n const playToast: ToastListenerMap[typeof EVENTS.play] = e => {\n const toast = toaster.toasts.get(e.detail.toastId);\n if (toast) {\n toast.imperativeRef.current?.play();\n }\n };\n\n const cleanupBuildListener = addToastListener(EVENTS.show, buildToast);\n const cleanupUpdateListener = addToastListener(EVENTS.update, updateToast);\n const cleanupDismissListener = addToastListener(EVENTS.dismiss, dismissToast);\n const cleanupDismissAllListener = addToastListener(EVENTS.dismissAll, dismissAllToasts);\n const cleanupPauseListener = addToastListener(EVENTS.pause, pauseToast);\n const cleanupPlayListener = addToastListener(EVENTS.play, playToast);\n\n const focusShortcutListener = (e: KeyboardEvent) => {\n if (isFocusShortcut(e)) {\n pauseAllToasts();\n const mostRecentToast = getMostRecentVisibleToast();\n\n if (mostRecentToast) {\n lastActiveElementRef.current = isHTMLElement(targetDocument.activeElement)\n ? targetDocument.activeElement\n : null;\n mostRecentToast.imperativeRef.current?.focus();\n }\n }\n };\n\n targetDocument.addEventListener('keydown', focusShortcutListener);\n\n return () => {\n cleanupBuildListener();\n cleanupDismissAllListener();\n cleanupUpdateListener();\n cleanupDismissListener();\n cleanupPauseListener();\n cleanupPlayListener();\n\n targetDocument.removeEventListener('keydown', focusShortcutListener);\n };\n }, [\n toaster,\n forceUpdate,\n targetDocument,\n isCorrectToaster,\n pauseAllToasts,\n getMostRecentVisibleToast,\n isFocusShortcut,\n ]);\n\n const toastsToRender = (() => {\n if (!toaster) {\n return new Map<ToastPosition, Toast[]>();\n }\n\n const toRender = new Map<ToastPosition, Toast[]>();\n const toasts = Array.from(toaster.toasts.values());\n\n toasts.forEach(toast => {\n const { position } = toast;\n toRender.has(position) || toRender.set(position, []);\n if (position.startsWith('bottom')) {\n toRender.get(position)!.push(toast);\n } else {\n toRender.get(position)!.unshift(toast);\n }\n });\n\n return toRender;\n })();\n\n return {\n isToastVisible: toaster.isToastVisible,\n toastsToRender,\n pauseAllToasts,\n playAllToasts,\n tryRestoreFocus,\n closeAllToasts,\n };\n}\n"],"names":["React","isHTMLElement","useEventCallback","useForceUpdate","useFluent_unstable","useFluent","createToaster","EVENTS","useToaster","options","forceUpdate","toasterId","userToasterId","shortcuts","toaster","useState","targetDocument","lastActiveElementRef","useRef","isCorrectToaster","isFocusShortcut","e","focus","pauseAllToasts","useCallback","visibleToasts","forEach","toastId","toast","toasts","get","imperativeRef","current","pause","playAllToasts","play","getMostRecentVisibleToast","Array","from","reduce","cur","next","order","undefined","tryRestoreFocus","mostRecentToast","closeAllToasts","close","useEffect","addToastListener","eventType","callback","listener","detail","addEventListener","removeEventListener","buildToast","dismissToast","updateToast","dismissAllToasts","pauseToast","playToast","cleanupBuildListener","show","cleanupUpdateListener","update","cleanupDismissListener","dismiss","cleanupDismissAllListener","dismissAll","cleanupPauseListener","cleanupPlayListener","focusShortcutListener","activeElement","toastsToRender","Map","toRender","values","position","has","set","startsWith","push","unshift","isToastVisible"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,aAAa,EAAEC,gBAAgB,EAAEC,cAAc,QAAQ,4BAA4B;AAC5F,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,aAAa,QAAQ,YAAY;AAU1C,SAASC,MAAM,QAAQ,cAAc;AAErC,OAAO,SAASC,WAA0DC,UAAmC,CAAC,CAAC,EAAE;IAC/G,MAAMC,cAAcP;IACpB,MAAM,EAAEQ,WAAWC,cAAa,EAAEC,UAAS,EAAE,GAAGJ;IAChD,gEAAgE;IAChE,MAAM,CAACK,QAAQ,GAAGd,MAAMe,QAAQ,CAAC,IAAMT,cAAcG;IACrD,MAAM,EAAEO,eAAc,EAAE,GAAGX;IAE3B,MAAMY,uBAAuBjB,MAAMkB,MAAM,CAAqB,IAAI;IAElE,MAAMC,mBAAmBjB,iBAAiB,CAACS,YAAqC;QAC9E,OAAOA,cAAcC;IACvB;IAEA,MAAMQ,kBAAkBlB,iBAAiB,CAACmB,IAAqB;QAC7D,IAAIR,sBAAAA,uBAAAA,KAAAA,IAAAA,UAAWS,KAAK,EAAE;YACpB,OAAOT,UAAU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,gBAAgB,CAAC,WAAWkB;QAE3C,OAAO,IAAM;YACXV;YACAM;YACAJ;YACAE;YACAI;YACAC;YAEAvD,eAAeuC,mBAAmB,CAAC,WAAWiB;QAChD;IACF,GAAG;QACD1D;QACAJ;QACAM;QACAG;QACAI;QACAa;QACAhB;KACD;IAED,MAAMsD,iBAAiB,AAAC,CAAA,IAAM;QAC5B,IAAI,CAAC5D,SAAS;YACZ,OAAO,IAAI6D;QACb,CAAC;QAED,MAAMC,WAAW,IAAID;QACrB,MAAM9C,SAASQ,MAAMC,IAAI,CAACxB,QAAQe,MAAM,CAACgD,MAAM;QAE/ChD,OAAOH,OAAO,CAACE,CAAAA,QAAS;YACtB,MAAM,EAAEkD,SAAQ,EAAE,GAAGlD;YACrBgD,SAASG,GAAG,CAACD,aAAaF,SAASI,GAAG,CAACF,UAAU,EAAE;YACnD,IAAIA,SAASG,UAAU,CAAC,WAAW;gBACjCL,SAAS9C,GAAG,CAACgD,UAAWI,IAAI,CAACtD;YAC/B,OAAO;gBACLgD,SAAS9C,GAAG,CAACgD,UAAWK,OAAO,CAACvD;YAClC,CAAC;QACH;QAEA,OAAOgD;IACT,CAAA;IAEA,OAAO;QACLQ,gBAAgBtE,QAAQsE,cAAc;QACtCV;QACAnD;QACAW;QACAU;QACAE;IACF;AACF,CAAC"}
|
|
@@ -10,8 +10,9 @@ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildc
|
|
|
10
10
|
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
11
11
|
const _reactUtilities = require("@fluentui/react-utilities");
|
|
12
12
|
const _reactSharedContexts = require("@fluentui/react-shared-contexts");
|
|
13
|
-
const
|
|
13
|
+
const _keyboardKeys = require("@fluentui/keyboard-keys");
|
|
14
14
|
const _reactTabster = require("@fluentui/react-tabster");
|
|
15
|
+
const _timer = require("../Timer/Timer");
|
|
15
16
|
const intentPolitenessMap = {
|
|
16
17
|
success: 'assertive',
|
|
17
18
|
warning: 'assertive',
|
|
@@ -27,6 +28,16 @@ const useToastContainer_unstable = (props, ref)=>{
|
|
|
27
28
|
const [running, setRunning] = _react.useState(false);
|
|
28
29
|
const imperativePauseRef = _react.useRef(false);
|
|
29
30
|
const focusedToastBeforeClose = _react.useRef(false);
|
|
31
|
+
const focusableGroupAttribute = (0, _reactTabster.useFocusableGroup)({
|
|
32
|
+
tabBehavior: 'limited-trap-focus',
|
|
33
|
+
// Users should only use Tab to focus into the toast
|
|
34
|
+
// Escape is already reserved to dismiss all toasts
|
|
35
|
+
ignoreDefaultKeydown: {
|
|
36
|
+
Tab: true,
|
|
37
|
+
Escape: true,
|
|
38
|
+
Enter: true
|
|
39
|
+
}
|
|
40
|
+
});
|
|
30
41
|
const close = (0, _reactUtilities.useEventCallback)(()=>{
|
|
31
42
|
var _toastRef_current;
|
|
32
43
|
const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;
|
|
@@ -58,18 +69,12 @@ const useToastContainer_unstable = (props, ref)=>{
|
|
|
58
69
|
setRunning(true);
|
|
59
70
|
}
|
|
60
71
|
});
|
|
61
|
-
const { findFirstFocusable } = (0, _reactTabster.useFocusFinders)();
|
|
62
72
|
_react.useImperativeHandle(imperativeRef, ()=>({
|
|
63
73
|
focus: ()=>{
|
|
64
74
|
if (!toastRef.current) {
|
|
65
75
|
return;
|
|
66
76
|
}
|
|
67
|
-
|
|
68
|
-
if (firstFocusable) {
|
|
69
|
-
firstFocusable.focus();
|
|
70
|
-
} else {
|
|
71
|
-
toastRef.current.focus();
|
|
72
|
-
}
|
|
77
|
+
toastRef.current.focus();
|
|
73
78
|
},
|
|
74
79
|
play: ()=>{
|
|
75
80
|
imperativePauseRef.current = false;
|
|
@@ -142,12 +147,23 @@ const useToastContainer_unstable = (props, ref)=>{
|
|
|
142
147
|
play();
|
|
143
148
|
userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onMouseEnter = userRootSlot.onMouseEnter) === null || _userRootSlot_onMouseEnter === void 0 ? void 0 : _userRootSlot_onMouseEnter.call(userRootSlot, e);
|
|
144
149
|
});
|
|
150
|
+
const { findFirstFocusable , findLastFocusable } = (0, _reactTabster.useFocusFinders)();
|
|
145
151
|
const onKeyDown = (0, _reactUtilities.useEventCallback)((e)=>{
|
|
146
152
|
var _userRootSlot_onKeyDown;
|
|
147
|
-
if (e.key ===
|
|
153
|
+
if (e.key === _keyboardKeys.Delete) {
|
|
148
154
|
e.preventDefault();
|
|
149
155
|
close();
|
|
150
156
|
}
|
|
157
|
+
if (e.key === _keyboardKeys.Tab && e.currentTarget === e.target) {
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
if (e.shiftKey) {
|
|
160
|
+
var _findLastFocusable;
|
|
161
|
+
(_findLastFocusable = findLastFocusable(e.currentTarget)) === null || _findLastFocusable === void 0 ? void 0 : _findLastFocusable.focus();
|
|
162
|
+
} else {
|
|
163
|
+
var _findFirstFocusable;
|
|
164
|
+
(_findFirstFocusable = findFirstFocusable(e.currentTarget)) === null || _findFirstFocusable === void 0 ? void 0 : _findFirstFocusable.focus();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
151
167
|
userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onKeyDown = userRootSlot.onKeyDown) === null || _userRootSlot_onKeyDown === void 0 ? void 0 : _userRootSlot_onKeyDown.call(userRootSlot, e);
|
|
152
168
|
});
|
|
153
169
|
_react.useEffect(()=>{
|
|
@@ -194,12 +210,13 @@ const useToastContainer_unstable = (props, ref)=>{
|
|
|
194
210
|
root: (0, _reactUtilities.getNativeElementProps)('div', {
|
|
195
211
|
ref: (0, _reactUtilities.useMergedRefs)(ref, toastRef, toastAnimationRef),
|
|
196
212
|
children,
|
|
197
|
-
tabIndex:
|
|
198
|
-
role: '
|
|
213
|
+
tabIndex: 0,
|
|
214
|
+
role: 'listitem',
|
|
199
215
|
'aria-labelledby': titleId,
|
|
200
216
|
'aria-describedby': bodyId,
|
|
201
217
|
...rest,
|
|
202
218
|
...userRootSlot,
|
|
219
|
+
...focusableGroupAttribute,
|
|
203
220
|
onMouseEnter,
|
|
204
221
|
onMouseLeave,
|
|
205
222
|
onKeyDown
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useToastContainer.js"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, useMergedRefs, useEventCallback, resolveShorthand, useId } from '@fluentui/react-utilities';\nimport { useFluent_unstable } from '@fluentui/react-shared-contexts';\nimport { Timer } from '../Timer/Timer';\nimport { useFocusFinders } from '@fluentui/react-tabster';\nconst intentPolitenessMap = {\n success: 'assertive',\n warning: 'assertive',\n error: 'assertive',\n info: 'polite'\n};\n/**\n * Create the state required to render ToastContainer.\n *\n * The returned state can be modified with hooks such as useToastContainerStyles_unstable,\n * before being passed to renderToastContainer_unstable.\n *\n * @param props - props from this instance of ToastContainer\n * @param ref - reference to root HTMLElement of ToastContainer\n */ export const useToastContainer_unstable = (props, ref)=>{\n const { visible , children , close: closeProp , remove , updateId , announce , data , timeout: timerTimeout , politeness: desiredPoliteness , intent ='info' , pauseOnHover , pauseOnWindowBlur , imperativeRef , tryRestoreFocus , ...rest } = props;\n const titleId = useId('toast-title');\n const bodyId = useId('toast-body');\n const toastRef = React.useRef(null);\n const { targetDocument } = useFluent_unstable();\n const [running, setRunning] = React.useState(false);\n const imperativePauseRef = React.useRef(false);\n const focusedToastBeforeClose = React.useRef(false);\n const close = useEventCallback(()=>{\n var _toastRef_current;\n const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;\n if (activeElement && ((_toastRef_current = toastRef.current) === null || _toastRef_current === void 0 ? void 0 : _toastRef_current.contains(activeElement))) {\n focusedToastBeforeClose.current = true;\n }\n closeProp();\n });\n const onStatusChange = useEventCallback((status)=>{\n var _props_onStatusChange;\n return (_props_onStatusChange = props.onStatusChange) === null || _props_onStatusChange === void 0 ? void 0 : _props_onStatusChange.call(props, null, {\n status,\n ...props\n });\n });\n const pause = useEventCallback(()=>setRunning(false));\n const play = useEventCallback(()=>{\n var _toastRef_current;\n if (imperativePauseRef.current) {\n return;\n }\n var _targetDocument_activeElement;\n const containsActive = !!((_toastRef_current = toastRef.current) === null || _toastRef_current === void 0 ? void 0 : _toastRef_current.contains((_targetDocument_activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement) !== null && _targetDocument_activeElement !== void 0 ? _targetDocument_activeElement : null));\n if (timerTimeout < 0) {\n setRunning(true);\n return;\n }\n if (!containsActive) {\n setRunning(true);\n }\n });\n const { findFirstFocusable } = useFocusFinders();\n React.useImperativeHandle(imperativeRef, ()=>({\n focus: ()=>{\n if (!toastRef.current) {\n return;\n }\n const firstFocusable = findFirstFocusable(toastRef.current);\n if (firstFocusable) {\n firstFocusable.focus();\n } else {\n toastRef.current.focus();\n }\n },\n play: ()=>{\n imperativePauseRef.current = false;\n play();\n },\n pause: ()=>{\n imperativePauseRef.current = true;\n pause();\n }\n }));\n React.useEffect(()=>{\n return ()=>onStatusChange('unmounted');\n }, [\n onStatusChange\n ]);\n React.useEffect(()=>{\n if (!targetDocument) {\n return;\n }\n if (pauseOnWindowBlur) {\n var _targetDocument_defaultView, _targetDocument_defaultView1;\n (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.addEventListener('focus', play);\n (_targetDocument_defaultView1 = targetDocument.defaultView) === null || _targetDocument_defaultView1 === void 0 ? void 0 : _targetDocument_defaultView1.addEventListener('blur', pause);\n return ()=>{\n var _targetDocument_defaultView, _targetDocument_defaultView1;\n (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.removeEventListener('focus', play);\n (_targetDocument_defaultView1 = targetDocument.defaultView) === null || _targetDocument_defaultView1 === void 0 ? void 0 : _targetDocument_defaultView1.removeEventListener('blur', pause);\n };\n }\n }, [\n targetDocument,\n pause,\n play,\n pauseOnWindowBlur\n ]);\n // It's impossible to animate to height: auto in CSS, the actual pixel value must be known\n // Get the height of the toast before animation styles have been applied and set a CSS\n // variable with its height. The CSS variable will be used by the styles\n const onTransitionEntering = ()=>{\n if (!toastRef.current) {\n return;\n }\n const element = toastRef.current;\n element.style.setProperty('--fui-toast-height', `${element.scrollHeight}px`);\n };\n // Users never actually use ToastContainer as a JSX but imperatively through useToastContainerController\n const userRootSlot = data.root;\n // Using a ref callback here because addEventListener supports `once`\n const toastAnimationRef = React.useCallback((el)=>{\n if (el && toastRef.current) {\n toastRef.current.addEventListener('animationend', ()=>{\n // start toast once it's fully animated in\n play();\n onStatusChange('visible');\n }, {\n once: true\n });\n }\n }, [\n play,\n onStatusChange\n ]);\n const onMouseEnter = useEventCallback((e)=>{\n var _userRootSlot_onMouseEnter;\n pause();\n userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onMouseEnter = userRootSlot.onMouseEnter) === null || _userRootSlot_onMouseEnter === void 0 ? void 0 : _userRootSlot_onMouseEnter.call(userRootSlot, e);\n });\n const onMouseLeave = useEventCallback((e)=>{\n var _userRootSlot_onMouseEnter;\n play();\n userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onMouseEnter = userRootSlot.onMouseEnter) === null || _userRootSlot_onMouseEnter === void 0 ? void 0 : _userRootSlot_onMouseEnter.call(userRootSlot, e);\n });\n const onKeyDown = useEventCallback((e)=>{\n var _userRootSlot_onKeyDown;\n if (e.key === 'Escape') {\n e.preventDefault();\n close();\n }\n userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onKeyDown = userRootSlot.onKeyDown) === null || _userRootSlot_onKeyDown === void 0 ? void 0 : _userRootSlot_onKeyDown.call(userRootSlot, e);\n });\n React.useEffect(()=>{\n var _toastRef_current;\n if (!visible) {\n return;\n }\n const politeness = desiredPoliteness !== null && desiredPoliteness !== void 0 ? desiredPoliteness : intentPolitenessMap[intent];\n var _toastRef_current_textContent;\n announce((_toastRef_current_textContent = (_toastRef_current = toastRef.current) === null || _toastRef_current === void 0 ? void 0 : _toastRef_current.textContent) !== null && _toastRef_current_textContent !== void 0 ? _toastRef_current_textContent : '', {\n politeness\n });\n }, [\n announce,\n desiredPoliteness,\n toastRef,\n visible,\n updateId,\n intent\n ]);\n React.useEffect(()=>{\n return ()=>{\n if (focusedToastBeforeClose.current) {\n focusedToastBeforeClose.current = false;\n tryRestoreFocus();\n }\n };\n }, [\n tryRestoreFocus\n ]);\n return {\n components: {\n timer: Timer,\n root: 'div'\n },\n timer: resolveShorthand({\n key: updateId,\n onTimeout: close,\n running,\n timeout: timerTimeout !== null && timerTimeout !== void 0 ? timerTimeout : -1\n }, {\n required: true\n }),\n root: getNativeElementProps('div', {\n ref: useMergedRefs(ref, toastRef, toastAnimationRef),\n children,\n tabIndex: -1,\n role: 'group',\n 'aria-labelledby': titleId,\n 'aria-describedby': bodyId,\n ...rest,\n ...userRootSlot,\n onMouseEnter,\n onMouseLeave,\n onKeyDown\n }),\n timerTimeout,\n transitionTimeout: 500,\n running,\n visible,\n remove,\n close,\n onTransitionEntering,\n updateId,\n nodeRef: toastRef,\n intent,\n titleId,\n bodyId\n };\n};\n"],"names":["useToastContainer_unstable","intentPolitenessMap","success","warning","error","info","props","ref","visible","children","close","closeProp","remove","updateId","announce","data","timeout","timerTimeout","politeness","desiredPoliteness","intent","pauseOnHover","pauseOnWindowBlur","imperativeRef","tryRestoreFocus","rest","titleId","useId","bodyId","toastRef","React","useRef","targetDocument","useFluent_unstable","running","setRunning","useState","imperativePauseRef","focusedToastBeforeClose","useEventCallback","_toastRef_current","activeElement","current","contains","onStatusChange","status","_props_onStatusChange","call","pause","play","_targetDocument_activeElement","containsActive","findFirstFocusable","useFocusFinders","useImperativeHandle","focus","firstFocusable","useEffect","_targetDocument_defaultView","_targetDocument_defaultView1","defaultView","addEventListener","removeEventListener","onTransitionEntering","element","style","setProperty","scrollHeight","userRootSlot","root","toastAnimationRef","useCallback","el","once","onMouseEnter","e","_userRootSlot_onMouseEnter","onMouseLeave","onKeyDown","_userRootSlot_onKeyDown","key","preventDefault","_toastRef_current_textContent","textContent","components","timer","Timer","resolveShorthand","onTimeout","required","getNativeElementProps","useMergedRefs","tabIndex","role","transitionTimeout","nodeRef"],"mappings":";;;;+BAmBiBA;;aAAAA;;;6DAnBM;gCACyE;qCAC7D;uBACb;8BACU;AAChC,MAAMC,sBAAsB;IACxBC,SAAS;IACTC,SAAS;IACTC,OAAO;IACPC,MAAM;AACV;AASW,MAAML,6BAA6B,CAACM,OAAOC,MAAM;IACxD,MAAM,EAAEC,QAAO,EAAGC,SAAQ,EAAGC,OAAOC,UAAS,EAAGC,OAAM,EAAGC,SAAQ,EAAGC,SAAQ,EAAGC,KAAI,EAAGC,SAASC,aAAY,EAAGC,YAAYC,kBAAiB,EAAGC,QAAQ,OAAM,EAAGC,aAAY,EAAGC,kBAAiB,EAAGC,cAAa,EAAGC,gBAAe,EAAG,GAAGC,MAAM,GAAGnB;IAChP,MAAMoB,UAAUC,IAAAA,qBAAK,EAAC;IACtB,MAAMC,SAASD,IAAAA,qBAAK,EAAC;IACrB,MAAME,WAAWC,OAAMC,MAAM,CAAC,IAAI;IAClC,MAAM,EAAEC,eAAc,EAAG,GAAGC,IAAAA,uCAAkB;IAC9C,MAAM,CAACC,SAASC,WAAW,GAAGL,OAAMM,QAAQ,CAAC,KAAK;IAClD,MAAMC,qBAAqBP,OAAMC,MAAM,CAAC,KAAK;IAC7C,MAAMO,0BAA0BR,OAAMC,MAAM,CAAC,KAAK;IAClD,MAAMrB,QAAQ6B,IAAAA,gCAAgB,EAAC,IAAI;QAC/B,IAAIC;QACJ,MAAMC,gBAAgBT,mBAAmB,IAAI,IAAIA,mBAAmB,KAAK,IAAI,KAAK,IAAIA,eAAeS,aAAa;QAClH,IAAIA,iBAAkB,CAAA,AAACD,CAAAA,oBAAoBX,SAASa,OAAO,AAAD,MAAO,IAAI,IAAIF,sBAAsB,KAAK,IAAI,KAAK,IAAIA,kBAAkBG,QAAQ,CAACF,cAAc,AAAD,G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;YACfM;YACAG;YACAC;QACJ;QACA7D;QACA6E,mBAAmB;QACnB5D;QACA1B;QACAI;QACAF;QACAqD;QACAlD;QACAkF,SAASlE;QACTT;QACAM;QACAE;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"sources":["useToastContainer.js"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, useMergedRefs, useEventCallback, resolveShorthand, useId } from '@fluentui/react-utilities';\nimport { useFluent_unstable } from '@fluentui/react-shared-contexts';\nimport { Delete, Tab } from '@fluentui/keyboard-keys';\nimport { useFocusableGroup, useFocusFinders } from '@fluentui/react-tabster';\nimport { Timer } from '../Timer/Timer';\nconst intentPolitenessMap = {\n success: 'assertive',\n warning: 'assertive',\n error: 'assertive',\n info: 'polite'\n};\n/**\n * Create the state required to render ToastContainer.\n *\n * The returned state can be modified with hooks such as useToastContainerStyles_unstable,\n * before being passed to renderToastContainer_unstable.\n *\n * @param props - props from this instance of ToastContainer\n * @param ref - reference to root HTMLElement of ToastContainer\n */ export const useToastContainer_unstable = (props, ref)=>{\n const { visible , children , close: closeProp , remove , updateId , announce , data , timeout: timerTimeout , politeness: desiredPoliteness , intent ='info' , pauseOnHover , pauseOnWindowBlur , imperativeRef , tryRestoreFocus , ...rest } = props;\n const titleId = useId('toast-title');\n const bodyId = useId('toast-body');\n const toastRef = React.useRef(null);\n const { targetDocument } = useFluent_unstable();\n const [running, setRunning] = React.useState(false);\n const imperativePauseRef = React.useRef(false);\n const focusedToastBeforeClose = React.useRef(false);\n const focusableGroupAttribute = useFocusableGroup({\n tabBehavior: 'limited-trap-focus',\n // Users should only use Tab to focus into the toast\n // Escape is already reserved to dismiss all toasts\n ignoreDefaultKeydown: {\n Tab: true,\n Escape: true,\n Enter: true\n }\n });\n const close = useEventCallback(()=>{\n var _toastRef_current;\n const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;\n if (activeElement && ((_toastRef_current = toastRef.current) === null || _toastRef_current === void 0 ? void 0 : _toastRef_current.contains(activeElement))) {\n focusedToastBeforeClose.current = true;\n }\n closeProp();\n });\n const onStatusChange = useEventCallback((status)=>{\n var _props_onStatusChange;\n return (_props_onStatusChange = props.onStatusChange) === null || _props_onStatusChange === void 0 ? void 0 : _props_onStatusChange.call(props, null, {\n status,\n ...props\n });\n });\n const pause = useEventCallback(()=>setRunning(false));\n const play = useEventCallback(()=>{\n var _toastRef_current;\n if (imperativePauseRef.current) {\n return;\n }\n var _targetDocument_activeElement;\n const containsActive = !!((_toastRef_current = toastRef.current) === null || _toastRef_current === void 0 ? void 0 : _toastRef_current.contains((_targetDocument_activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement) !== null && _targetDocument_activeElement !== void 0 ? _targetDocument_activeElement : null));\n if (timerTimeout < 0) {\n setRunning(true);\n return;\n }\n if (!containsActive) {\n setRunning(true);\n }\n });\n React.useImperativeHandle(imperativeRef, ()=>({\n focus: ()=>{\n if (!toastRef.current) {\n return;\n }\n toastRef.current.focus();\n },\n play: ()=>{\n imperativePauseRef.current = false;\n play();\n },\n pause: ()=>{\n imperativePauseRef.current = true;\n pause();\n }\n }));\n React.useEffect(()=>{\n return ()=>onStatusChange('unmounted');\n }, [\n onStatusChange\n ]);\n React.useEffect(()=>{\n if (!targetDocument) {\n return;\n }\n if (pauseOnWindowBlur) {\n var _targetDocument_defaultView, _targetDocument_defaultView1;\n (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.addEventListener('focus', play);\n (_targetDocument_defaultView1 = targetDocument.defaultView) === null || _targetDocument_defaultView1 === void 0 ? void 0 : _targetDocument_defaultView1.addEventListener('blur', pause);\n return ()=>{\n var _targetDocument_defaultView, _targetDocument_defaultView1;\n (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.removeEventListener('focus', play);\n (_targetDocument_defaultView1 = targetDocument.defaultView) === null || _targetDocument_defaultView1 === void 0 ? void 0 : _targetDocument_defaultView1.removeEventListener('blur', pause);\n };\n }\n }, [\n targetDocument,\n pause,\n play,\n pauseOnWindowBlur\n ]);\n // It's impossible to animate to height: auto in CSS, the actual pixel value must be known\n // Get the height of the toast before animation styles have been applied and set a CSS\n // variable with its height. The CSS variable will be used by the styles\n const onTransitionEntering = ()=>{\n if (!toastRef.current) {\n return;\n }\n const element = toastRef.current;\n element.style.setProperty('--fui-toast-height', `${element.scrollHeight}px`);\n };\n // Users never actually use ToastContainer as a JSX but imperatively through useToastContainerController\n const userRootSlot = data.root;\n // Using a ref callback here because addEventListener supports `once`\n const toastAnimationRef = React.useCallback((el)=>{\n if (el && toastRef.current) {\n toastRef.current.addEventListener('animationend', ()=>{\n // start toast once it's fully animated in\n play();\n onStatusChange('visible');\n }, {\n once: true\n });\n }\n }, [\n play,\n onStatusChange\n ]);\n const onMouseEnter = useEventCallback((e)=>{\n var _userRootSlot_onMouseEnter;\n pause();\n userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onMouseEnter = userRootSlot.onMouseEnter) === null || _userRootSlot_onMouseEnter === void 0 ? void 0 : _userRootSlot_onMouseEnter.call(userRootSlot, e);\n });\n const onMouseLeave = useEventCallback((e)=>{\n var _userRootSlot_onMouseEnter;\n play();\n userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onMouseEnter = userRootSlot.onMouseEnter) === null || _userRootSlot_onMouseEnter === void 0 ? void 0 : _userRootSlot_onMouseEnter.call(userRootSlot, e);\n });\n const { findFirstFocusable , findLastFocusable } = useFocusFinders();\n const onKeyDown = useEventCallback((e)=>{\n var _userRootSlot_onKeyDown;\n if (e.key === Delete) {\n e.preventDefault();\n close();\n }\n if (e.key === Tab && e.currentTarget === e.target) {\n e.preventDefault();\n if (e.shiftKey) {\n var _findLastFocusable;\n (_findLastFocusable = findLastFocusable(e.currentTarget)) === null || _findLastFocusable === void 0 ? void 0 : _findLastFocusable.focus();\n } else {\n var _findFirstFocusable;\n (_findFirstFocusable = findFirstFocusable(e.currentTarget)) === null || _findFirstFocusable === void 0 ? void 0 : _findFirstFocusable.focus();\n }\n }\n userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onKeyDown = userRootSlot.onKeyDown) === null || _userRootSlot_onKeyDown === void 0 ? void 0 : _userRootSlot_onKeyDown.call(userRootSlot, e);\n });\n React.useEffect(()=>{\n var _toastRef_current;\n if (!visible) {\n return;\n }\n const politeness = desiredPoliteness !== null && desiredPoliteness !== void 0 ? desiredPoliteness : intentPolitenessMap[intent];\n var _toastRef_current_textContent;\n announce((_toastRef_current_textContent = (_toastRef_current = toastRef.current) === null || _toastRef_current === void 0 ? void 0 : _toastRef_current.textContent) !== null && _toastRef_current_textContent !== void 0 ? _toastRef_current_textContent : '', {\n politeness\n });\n }, [\n announce,\n desiredPoliteness,\n toastRef,\n visible,\n updateId,\n intent\n ]);\n React.useEffect(()=>{\n return ()=>{\n if (focusedToastBeforeClose.current) {\n focusedToastBeforeClose.current = false;\n tryRestoreFocus();\n }\n };\n }, [\n tryRestoreFocus\n ]);\n return {\n components: {\n timer: Timer,\n root: 'div'\n },\n timer: resolveShorthand({\n key: updateId,\n onTimeout: close,\n running,\n timeout: timerTimeout !== null && timerTimeout !== void 0 ? timerTimeout : -1\n }, {\n required: true\n }),\n root: getNativeElementProps('div', {\n ref: useMergedRefs(ref, toastRef, toastAnimationRef),\n children,\n tabIndex: 0,\n role: 'listitem',\n 'aria-labelledby': titleId,\n 'aria-describedby': bodyId,\n ...rest,\n ...userRootSlot,\n ...focusableGroupAttribute,\n onMouseEnter,\n onMouseLeave,\n onKeyDown\n }),\n timerTimeout,\n transitionTimeout: 500,\n running,\n visible,\n remove,\n close,\n onTransitionEntering,\n updateId,\n nodeRef: toastRef,\n intent,\n titleId,\n bodyId\n };\n};\n"],"names":["useToastContainer_unstable","intentPolitenessMap","success","warning","error","info","props","ref","visible","children","close","closeProp","remove","updateId","announce","data","timeout","timerTimeout","politeness","desiredPoliteness","intent","pauseOnHover","pauseOnWindowBlur","imperativeRef","tryRestoreFocus","rest","titleId","useId","bodyId","toastRef","React","useRef","targetDocument","useFluent_unstable","running","setRunning","useState","imperativePauseRef","focusedToastBeforeClose","focusableGroupAttribute","useFocusableGroup","tabBehavior","ignoreDefaultKeydown","Tab","Escape","Enter","useEventCallback","_toastRef_current","activeElement","current","contains","onStatusChange","status","_props_onStatusChange","call","pause","play","_targetDocument_activeElement","containsActive","useImperativeHandle","focus","useEffect","_targetDocument_defaultView","_targetDocument_defaultView1","defaultView","addEventListener","removeEventListener","onTransitionEntering","element","style","setProperty","scrollHeight","userRootSlot","root","toastAnimationRef","useCallback","el","once","onMouseEnter","e","_userRootSlot_onMouseEnter","onMouseLeave","findFirstFocusable","findLastFocusable","useFocusFinders","onKeyDown","_userRootSlot_onKeyDown","key","Delete","preventDefault","currentTarget","target","shiftKey","_findLastFocusable","_findFirstFocusable","_toastRef_current_textContent","textContent","components","timer","Timer","resolveShorthand","onTimeout","required","getNativeElementProps","useMergedRefs","tabIndex","role","transitionTimeout","nodeRef"],"mappings":";;;;+BAoBiBA;;aAAAA;;;6DApBM;gCACyE;qCAC7D;8BACP;8BACuB;uBAC7B;AACtB,MAAMC,sBAAsB;IACxBC,SAAS;IACTC,SAAS;IACTC,OAAO;IACPC,MAAM;AACV;AASW,MAAML,6BAA6B,CAACM,OAAOC,MAAM;IACxD,MAAM,EAAEC,QAAO,EAAGC,SAAQ,EAAGC,OAAOC,UAAS,EAAGC,OAAM,EAAGC,SAAQ,EAAGC,SAAQ,EAAGC,KAAI,EAAGC,SAASC,aAAY,EAAGC,YAAYC,kBAAiB,EAAGC,QAAQ,OAAM,EAAGC,aAAY,EAAGC,kBAAiB,EAAGC,cAAa,EAAGC,gBAAe,EAAG,GAAGC,MAAM,GAAGnB;IAChP,MAAMoB,UAAUC,IAAAA,qBAAK,EAAC;IACtB,MAAMC,SAASD,IAAAA,qBAAK,EAAC;IACrB,MAAME,WAAWC,OAAMC,M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QACTT;QACAM;QACAE;IACJ;AACJ"}
|
|
@@ -9,11 +9,11 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
|
|
12
|
+
toastContainerClassNames: ()=>toastContainerClassNames,
|
|
13
13
|
useToastContainerStyles_unstable: ()=>useToastContainerStyles_unstable
|
|
14
14
|
});
|
|
15
15
|
const _react = require("@griffel/react");
|
|
16
|
-
const
|
|
16
|
+
const toastContainerClassNames = {
|
|
17
17
|
root: 'fui-ToastContainer',
|
|
18
18
|
timer: 'fui-ToastContainer__timer'
|
|
19
19
|
};
|
|
@@ -59,6 +59,6 @@ const useRootBaseClassName = /*#__PURE__*/ (0, _react["__resetStyles"])("r1qaza6
|
|
|
59
59
|
const useToastContainerStyles_unstable = (state)=>{
|
|
60
60
|
const rootBaseClassName = useRootBaseClassName();
|
|
61
61
|
const styles = useStyles();
|
|
62
|
-
state.root.className = (0, _react.mergeClasses)(
|
|
62
|
+
state.root.className = (0, _react.mergeClasses)(toastContainerClassNames.root, rootBaseClassName, state.visible ? styles.enter : styles.exit, state.root.className);
|
|
63
63
|
return state;
|
|
64
64
|
}; //# sourceMappingURL=useToastContainerStyles.styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useToastContainerStyles.styles.js"],"sourcesContent":["import { __resetStyles, __styles, mergeClasses, shorthands } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\nimport { createCustomFocusIndicatorStyle } from '@fluentui/react-tabster';\nexport const
|
|
1
|
+
{"version":3,"sources":["useToastContainerStyles.styles.js"],"sourcesContent":["import { __resetStyles, __styles, mergeClasses, shorthands } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\nimport { createCustomFocusIndicatorStyle } from '@fluentui/react-tabster';\nexport const toastContainerClassNames = {\n root: 'fui-ToastContainer',\n timer: 'fui-ToastContainer__timer'\n};\nconst useRootBaseClassName = /*#__PURE__*/__resetStyles(\"r1qaza64\", \"r1e6dlul\", [\".r1qaza64{box-sizing:border-box;margin-top:16px;min-height:44px;pointer-events:all;border-bottom-right-radius:var(--borderRadiusMedium);border-bottom-left-radius:var(--borderRadiusMedium);border-top-right-radius:var(--borderRadiusMedium);border-top-left-radius:var(--borderRadiusMedium);--fui-toast-height:44px;}\", \".r1qaza64[data-fui-focus-visible]{outline-width:var(--strokeWidthThick);outline-style:solid;outline-color:var(--colorStrokeFocus2);}\", \".r1e6dlul{box-sizing:border-box;margin-top:16px;min-height:44px;pointer-events:all;border-bottom-left-radius:var(--borderRadiusMedium);border-bottom-right-radius:var(--borderRadiusMedium);border-top-left-radius:var(--borderRadiusMedium);border-top-right-radius:var(--borderRadiusMedium);--fui-toast-height:44px;}\", \".r1e6dlul[data-fui-focus-visible]{outline-width:var(--strokeWidthThick);outline-style:solid;outline-color:var(--colorStrokeFocus2);}\"]);\n/**\n * Styles for the root slot\n */\nconst useStyles = /*#__PURE__*/__styles({\n enter: {\n vin17d: \"fayl5bc\",\n m1gqa9: \"f17oyct0\",\n Bv12yb3: \"fvv8lvk\"\n },\n exit: {\n vin17d: \"f1tk3cza\",\n m1gqa9: \"f1nx6yy9\",\n Bv12yb3: \"f9wuypy\"\n }\n}, {\n d: [\".fayl5bc{-webkit-animation-duration:200ms,400ms;animation-duration:200ms,400ms;}\", \".f17oyct0{-webkit-animation-delay:0ms,200ms;animation-delay:0ms,200ms;}\", \".fvv8lvk{-webkit-animation-name:f1rp83na,f5j8bii;animation-name:f1rp83na,f5j8bii;}\", \".f1tk3cza{-webkit-animation-duration:400ms,200ms;animation-duration:400ms,200ms;}\", \".f1nx6yy9{-webkit-animation-delay:0ms,400ms;animation-delay:0ms,400ms;}\", \".f9wuypy{-webkit-animation-name:fk0lfw7,f1n32sdh;animation-name:fk0lfw7,f1n32sdh;}\"],\n k: [\"@-webkit-keyframes f1rp83na{from{max-height:0;opacity:0;margin-top:0;}to{margin-top:16px;opacity:0;max-height:var(--fui-toast-height);}}\", \"@keyframes f1rp83na{from{max-height:0;opacity:0;margin-top:0;}to{margin-top:16px;opacity:0;max-height:var(--fui-toast-height);}}\", \"@-webkit-keyframes f5j8bii{from{opacity:0;}to{opacity:1;}}\", \"@keyframes f5j8bii{from{opacity:0;}to{opacity:1;}}\", \"@-webkit-keyframes fk0lfw7{from{opacity:1;}to{opacity:0;}}\", \"@keyframes fk0lfw7{from{opacity:1;}to{opacity:0;}}\", \"@-webkit-keyframes f1n32sdh{from{opacity:0;}to{opacity:0;margin-top:0;max-height:0;}}\", \"@keyframes f1n32sdh{from{opacity:0;}to{opacity:0;margin-top:0;max-height:0;}}\"]\n});\n/**\n * Apply styling to the ToastContainer slots based on the state\n */\nexport const useToastContainerStyles_unstable = state => {\n const rootBaseClassName = useRootBaseClassName();\n const styles = useStyles();\n state.root.className = mergeClasses(toastContainerClassNames.root, rootBaseClassName, state.visible ? styles.enter : styles.exit, state.root.className);\n return state;\n};\n//# sourceMappingURL=useToastContainerStyles.styles.js.map"],"names":["toastContainerClassNames","useToastContainerStyles_unstable","root","timer","useRootBaseClassName","__resetStyles","useStyles","__styles","enter","vin17d","m1gqa9","Bv12yb3","exit","d","k","state","rootBaseClassName","styles","className","mergeClasses","visible"],"mappings":";;;;;;;;;;;IAGaA,wBAAwB,MAAxBA;IA0BAC,gCAAgC,MAAhCA;;uBA7BqD;AAG3D,MAAMD,2BAA2B;IACtCE,MAAM;IACNC,OAAO;AACT;AACA,MAAMC,uBAAuB,WAAW,GAAEC,IAAAA,uBAAa,EAAC,YAAY,YAAY;IAAC;IAA4T;IAAwI;IAA4T;CAAuI;AACx9B;;CAEC,GACD,MAAMC,YAAY,WAAW,GAAEC,IAAAA,kBAAQ,EAAC;IACtCC,OAAO;QACLC,QAAQ;QACRC,QAAQ;QACRC,SAAS;IACX;IACAC,MAAM;QACJH,QAAQ;QACRC,QAAQ;QACRC,SAAS;IACX;AACF,GAAG;IACDE,GAAG;QAAC;QAAoF;QAA2E;QAAsF;QAAqF;QAA2E;KAAqF;IAC9eC,GAAG;QAAC;QAA4I;QAAoI;QAA8D;QAAsD;QAA8D;QAAsD;QAAyF;KAAgF;AACvqB;AAIO,MAAMb,mCAAmCc,CAAAA,QAAS;IACvD,MAAMC,oBAAoBZ;IAC1B,MAAMa,SAASX;IACfS,MAAMb,IAAI,CAACgB,SAAS,GAAGC,IAAAA,mBAAY,EAACnB,yBAAyBE,IAAI,EAAEc,mBAAmBD,MAAMK,OAAO,GAAGH,OAAOT,KAAK,GAAGS,OAAOL,IAAI,EAAEG,MAAMb,IAAI,CAACgB,SAAS;IACtJ,OAAOH;AACT,GACA,0DAA0D"}
|
|
@@ -17,7 +17,7 @@ const useToastTrigger_unstable = (props)=>{
|
|
|
17
17
|
const child = (0, _reactUtilities.getTriggerChild)(children);
|
|
18
18
|
const handleClick = (0, _reactUtilities.useEventCallback)((e)=>{
|
|
19
19
|
var _child_props, _child_props_onClick;
|
|
20
|
-
(_child_props_onClick =
|
|
20
|
+
(_child_props_onClick = _child_props = child === null || child === void 0 ? void 0 : child.props.onClick) === null || _child_props_onClick === void 0 ? void 0 : _child_props_onClick.call(_child_props, e);
|
|
21
21
|
if (!e.isDefaultPrevented()) {
|
|
22
22
|
close();
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useToastTrigger.js"],"sourcesContent":["import * as React from 'react';\nimport { applyTriggerPropsToChildren, getTriggerChild, useEventCallback } from '@fluentui/react-utilities';\nimport { useARIAButtonProps } from '@fluentui/react-aria';\nimport { useToastContainerContext } from '../../contexts/toastContainerContext';\n/**\n * A non-visual component that wraps its child\n * and configures them to be the trigger that will close a `Toast`.\n * This component should only accept one child.\n *\n * This component sole purpose is to avoid opting out of the internal controlled open state of a `Toast`\n * Besides being a trigger that closes a toast through context this component doesn't do much,\n * making it basically unnecessary in cases where the trigger is outside of a toast.\n */ export const useToastTrigger_unstable = (props)=>{\n const { children , disableButtonEnhancement =false } = props;\n const { close } = useToastContainerContext();\n const child = getTriggerChild(children);\n const handleClick = useEventCallback((e)=>{\n var _child_props, _child_props_onClick;\n (_child_props_onClick =
|
|
1
|
+
{"version":3,"sources":["useToastTrigger.js"],"sourcesContent":["import * as React from 'react';\nimport { applyTriggerPropsToChildren, getTriggerChild, useEventCallback } from '@fluentui/react-utilities';\nimport { useARIAButtonProps } from '@fluentui/react-aria';\nimport { useToastContainerContext } from '../../contexts/toastContainerContext';\n/**\n * A non-visual component that wraps its child\n * and configures them to be the trigger that will close a `Toast`.\n * This component should only accept one child.\n *\n * This component sole purpose is to avoid opting out of the internal controlled open state of a `Toast`\n * Besides being a trigger that closes a toast through context this component doesn't do much,\n * making it basically unnecessary in cases where the trigger is outside of a toast.\n */ export const useToastTrigger_unstable = (props)=>{\n const { children , disableButtonEnhancement =false } = props;\n const { close } = useToastContainerContext();\n const child = getTriggerChild(children);\n const handleClick = useEventCallback((e)=>{\n var _child_props, _child_props_onClick;\n (_child_props_onClick = _child_props = child === null || child === void 0 ? void 0 : child.props.onClick) === null || _child_props_onClick === void 0 ? void 0 : _child_props_onClick.call(_child_props, e);\n if (!e.isDefaultPrevented()) {\n close();\n }\n });\n const triggerChildProps = {\n ...child === null || child === void 0 ? void 0 : child.props,\n ref: child === null || child === void 0 ? void 0 : child.ref,\n onClick: handleClick\n };\n const ariaButtonTriggerChildProps = useARIAButtonProps((child === null || child === void 0 ? void 0 : child.type) === 'button' || (child === null || child === void 0 ? void 0 : child.type) === 'a' ? child.type : 'div', {\n ...triggerChildProps,\n type: 'button'\n });\n return {\n children: applyTriggerPropsToChildren(children, disableButtonEnhancement ? triggerChildProps : ariaButtonTriggerChildProps)\n };\n};\n"],"names":["useToastTrigger_unstable","props","children","disableButtonEnhancement","close","useToastContainerContext","child","getTriggerChild","handleClick","useEventCallback","e","_child_props","_child_props_onClick","onClick","call","isDefaultPrevented","triggerChildProps","ref","ariaButtonTriggerChildProps","useARIAButtonProps","type","applyTriggerPropsToChildren"],"mappings":";;;;+BAYiBA;;aAAAA;;;6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.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useToastAnnounce", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>useToastAnnounce
|
|
8
|
+
});
|
|
9
|
+
const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
|
|
10
|
+
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
11
|
+
const _reactUtilities = require("@fluentui/react-utilities");
|
|
12
|
+
function useToastAnnounce(announce) {
|
|
13
|
+
const activeRef = _react.useRef(true);
|
|
14
|
+
const cleanupRef = _react.useRef(()=>undefined);
|
|
15
|
+
const announceToast = _react.useCallback((message, options)=>{
|
|
16
|
+
if (activeRef.current) {
|
|
17
|
+
announce(message, options);
|
|
18
|
+
}
|
|
19
|
+
}, [
|
|
20
|
+
announce
|
|
21
|
+
]);
|
|
22
|
+
const toasterRef = _react.useCallback((el)=>{
|
|
23
|
+
if (!el) {
|
|
24
|
+
cleanupRef.current();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const onFocusIn = (e)=>{
|
|
28
|
+
if ((0, _reactUtilities.isHTMLElement)(e.currentTarget) && e.currentTarget.contains((0, _reactUtilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
activeRef.current = false;
|
|
32
|
+
};
|
|
33
|
+
const onFocusOut = (e)=>{
|
|
34
|
+
if ((0, _reactUtilities.isHTMLElement)(e.currentTarget) && e.currentTarget.contains((0, _reactUtilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
activeRef.current = true;
|
|
38
|
+
};
|
|
39
|
+
el.addEventListener('focusin', onFocusIn);
|
|
40
|
+
el.addEventListener('focusout', onFocusOut);
|
|
41
|
+
cleanupRef.current = ()=>{
|
|
42
|
+
el.removeEventListener('focusin', onFocusIn);
|
|
43
|
+
el.removeEventListener('focusout', onFocusOut);
|
|
44
|
+
};
|
|
45
|
+
}, []);
|
|
46
|
+
return {
|
|
47
|
+
announceToast,
|
|
48
|
+
toasterRef
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useToastAnnounce.js"],"sourcesContent":["import * as React from 'react';\nimport { isHTMLElement } from '@fluentui/react-utilities';\n/**\n * Wraps an aria live announcement function.\n * Aria live announcements can be detrimental once the user is already navigating\n * multiple toasts. Once the user is focused inside the toaster, the announecments should be disabled.\n * @param announce\n * @returns A function to announce a toast and a ref to attach to the toaster element\n */ export function useToastAnnounce(announce) {\n const activeRef = React.useRef(true);\n const cleanupRef = React.useRef(()=>undefined);\n const announceToast = React.useCallback((message, options)=>{\n if (activeRef.current) {\n announce(message, options);\n }\n }, [\n announce\n ]);\n const toasterRef = React.useCallback((el)=>{\n if (!el) {\n cleanupRef.current();\n return;\n }\n const onFocusIn = (e)=>{\n if (isHTMLElement(e.currentTarget) && e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)) {\n return;\n }\n activeRef.current = false;\n };\n const onFocusOut = (e)=>{\n if (isHTMLElement(e.currentTarget) && e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)) {\n return;\n }\n activeRef.current = true;\n };\n el.addEventListener('focusin', onFocusIn);\n el.addEventListener('focusout', onFocusOut);\n cleanupRef.current = ()=>{\n el.removeEventListener('focusin', onFocusIn);\n el.removeEventListener('focusout', onFocusOut);\n };\n }, []);\n return {\n announceToast,\n toasterRef\n };\n}\n"],"names":["useToastAnnounce","announce","activeRef","React","useRef","cleanupRef","undefined","announceToast","useCallback","message","options","current","toasterRef","el","onFocusIn","e","isHTMLElement","currentTarget","contains","relatedTarget","onFocusOut","addEventListener","removeEventListener"],"mappings":";;;;+BAQoBA;;aAAAA;;;6DARG;gCACO;AAOnB,SAASA,iBAAiBC,QAAQ,EAAE;IAC3C,MAAMC,YAAYC,OAAMC,MAAM,CAAC,IAAI;IACnC,MAAMC,aAAaF,OAAMC,MAAM,CAAC,IAAIE;IACpC,MAAMC,gBAAgBJ,OAAMK,WAAW,CAAC,CAACC,SAASC,UAAU;QACxD,IAAIR,UAAUS,OAAO,EAAE;YACnBV,SAASQ,SAASC;QACtB,CAAC;IACL,GAAG;QACCT;KACH;IACD,MAAMW,aAAaT,OAAMK,WAAW,CAAC,CAACK,KAAK;QACvC,IAAI,CAACA,IAAI;YACLR,WAAWM,OAAO;YAClB;QACJ,CAAC;QACD,MAAMG,YAAY,CAACC,IAAI;YACnB,IAAIC,IAAAA,6BAAa,EAACD,EAAEE,aAAa,KAAKF,EAAEE,aAAa,CAACC,QAAQ,CAACF,IAAAA,6BAAa,EAACD,EAAEI,aAAa,IAAIJ,EAAEI,aAAa,GAAG,IAAI,GAAG;gBACrH;YACJ,CAAC;YACDjB,UAAUS,OAAO,GAAG,KAAK;QAC7B;QACA,MAAMS,aAAa,CAACL,IAAI;YACpB,IAAIC,IAAAA,6BAAa,EAACD,EAAEE,aAAa,KAAKF,EAAEE,aAAa,CAACC,QAAQ,CAACF,IAAAA,6BAAa,EAACD,EAAEI,aAAa,IAAIJ,EAAEI,aAAa,GAAG,IAAI,GAAG;gBACrH;YACJ,CAAC;YACDjB,UAAUS,OAAO,GAAG,IAAI;QAC5B;QACAE,GAAGQ,gBAAgB,CAAC,WAAWP;QAC/BD,GAAGQ,gBAAgB,CAAC,YAAYD;QAChCf,WAAWM,OAAO,GAAG,IAAI;YACrBE,GAAGS,mBAAmB,CAAC,WAAWR;YAClCD,GAAGS,mBAAmB,CAAC,YAAYF;QACvC;IACJ,GAAG,EAAE;IACL,OAAO;QACHb;QACAK;IACJ;AACJ"}
|