@fluentui/react-dialog 9.0.0-beta.7
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 +328 -0
- package/CHANGELOG.md +152 -0
- package/LICENSE +15 -0
- package/README.md +5 -0
- package/Spec.md +518 -0
- package/assets/AlertDialogKeyboardInteraction.png +0 -0
- package/assets/AlertDialogMouseInteraction.png +0 -0
- package/assets/ModalDialogKeyboardInteraction.png +0 -0
- package/assets/ModalDialogMouseInteraction.png +0 -0
- package/assets/NonModalDialogKeyboardInteraction.png +0 -0
- package/assets/NonModalDialogMouseInteraction.png +0 -0
- package/dist/index.d.ts +406 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/Dialog.js +2 -0
- package/lib/Dialog.js.map +1 -0
- package/lib/DialogActions.js +2 -0
- package/lib/DialogActions.js.map +1 -0
- package/lib/DialogBody.js +2 -0
- package/lib/DialogBody.js.map +1 -0
- package/lib/DialogSurface.js +2 -0
- package/lib/DialogSurface.js.map +1 -0
- package/lib/DialogTitle.js +2 -0
- package/lib/DialogTitle.js.map +1 -0
- package/lib/DialogTrigger.js +2 -0
- package/lib/DialogTrigger.js.map +1 -0
- package/lib/components/Dialog/Dialog.js +21 -0
- package/lib/components/Dialog/Dialog.js.map +1 -0
- package/lib/components/Dialog/Dialog.types.js +2 -0
- package/lib/components/Dialog/Dialog.types.js.map +1 -0
- package/lib/components/Dialog/index.js +6 -0
- package/lib/components/Dialog/index.js.map +1 -0
- package/lib/components/Dialog/renderDialog.js +26 -0
- package/lib/components/Dialog/renderDialog.js.map +1 -0
- package/lib/components/Dialog/useDialog.js +197 -0
- package/lib/components/Dialog/useDialog.js.map +1 -0
- package/lib/components/Dialog/useDialogContextValues.js +31 -0
- package/lib/components/Dialog/useDialogContextValues.js.map +1 -0
- package/lib/components/Dialog/useDialogStyles.js +41 -0
- package/lib/components/Dialog/useDialogStyles.js.map +1 -0
- package/lib/components/DialogActions/DialogActions.js +16 -0
- package/lib/components/DialogActions/DialogActions.js.map +1 -0
- package/lib/components/DialogActions/DialogActions.types.js +2 -0
- package/lib/components/DialogActions/DialogActions.types.js.map +1 -0
- package/lib/components/DialogActions/index.js +6 -0
- package/lib/components/DialogActions/index.js.map +1 -0
- package/lib/components/DialogActions/renderDialogActions.js +16 -0
- package/lib/components/DialogActions/renderDialogActions.js.map +1 -0
- package/lib/components/DialogActions/useDialogActions.js +27 -0
- package/lib/components/DialogActions/useDialogActions.js.map +1 -0
- package/lib/components/DialogActions/useDialogActionsStyles.js +51 -0
- package/lib/components/DialogActions/useDialogActionsStyles.js.map +1 -0
- package/lib/components/DialogBody/DialogBody.js +16 -0
- package/lib/components/DialogBody/DialogBody.js.map +1 -0
- package/lib/components/DialogBody/DialogBody.types.js +2 -0
- package/lib/components/DialogBody/DialogBody.types.js.map +1 -0
- package/lib/components/DialogBody/index.js +6 -0
- package/lib/components/DialogBody/index.js.map +1 -0
- package/lib/components/DialogBody/renderDialogBody.js +16 -0
- package/lib/components/DialogBody/renderDialogBody.js.map +1 -0
- package/lib/components/DialogBody/useDialogBody.js +25 -0
- package/lib/components/DialogBody/useDialogBody.js.map +1 -0
- package/lib/components/DialogBody/useDialogBodyStyles.js +42 -0
- package/lib/components/DialogBody/useDialogBodyStyles.js.map +1 -0
- package/lib/components/DialogSurface/DialogSurface.js +18 -0
- package/lib/components/DialogSurface/DialogSurface.js.map +1 -0
- package/lib/components/DialogSurface/DialogSurface.types.js +2 -0
- package/lib/components/DialogSurface/DialogSurface.types.js.map +1 -0
- package/lib/components/DialogSurface/index.js +6 -0
- package/lib/components/DialogSurface/index.js.map +1 -0
- package/lib/components/DialogSurface/renderDialogSurface.js +18 -0
- package/lib/components/DialogSurface/renderDialogSurface.js.map +1 -0
- package/lib/components/DialogSurface/useDialogSurface.js +59 -0
- package/lib/components/DialogSurface/useDialogSurface.js.map +1 -0
- package/lib/components/DialogSurface/useDialogSurfaceContextValues.js +7 -0
- package/lib/components/DialogSurface/useDialogSurfaceContextValues.js.map +1 -0
- package/lib/components/DialogSurface/useDialogSurfaceStyles.js +78 -0
- package/lib/components/DialogSurface/useDialogSurfaceStyles.js.map +1 -0
- package/lib/components/DialogTitle/DialogTitle.js +17 -0
- package/lib/components/DialogTitle/DialogTitle.js.map +1 -0
- package/lib/components/DialogTitle/DialogTitle.types.js +2 -0
- package/lib/components/DialogTitle/DialogTitle.types.js.map +1 -0
- package/lib/components/DialogTitle/index.js +6 -0
- package/lib/components/DialogTitle/index.js.map +1 -0
- package/lib/components/DialogTitle/renderDialogTitle.js +19 -0
- package/lib/components/DialogTitle/renderDialogTitle.js.map +1 -0
- package/lib/components/DialogTitle/useDialogTitle.js +42 -0
- package/lib/components/DialogTitle/useDialogTitle.js.map +1 -0
- package/lib/components/DialogTitle/useDialogTitleStyles.js +109 -0
- package/lib/components/DialogTitle/useDialogTitleStyles.js.map +1 -0
- package/lib/components/DialogTrigger/DialogTrigger.js +20 -0
- package/lib/components/DialogTrigger/DialogTrigger.js.map +1 -0
- package/lib/components/DialogTrigger/DialogTrigger.types.js +2 -0
- package/lib/components/DialogTrigger/DialogTrigger.types.js.map +1 -0
- package/lib/components/DialogTrigger/index.js +5 -0
- package/lib/components/DialogTrigger/index.js.map +1 -0
- package/lib/components/DialogTrigger/renderDialogTrigger.js +7 -0
- package/lib/components/DialogTrigger/renderDialogTrigger.js.map +1 -0
- package/lib/components/DialogTrigger/useDialogTrigger.js +65 -0
- package/lib/components/DialogTrigger/useDialogTrigger.js.map +1 -0
- package/lib/contexts/constants.js +11 -0
- package/lib/contexts/constants.js.map +1 -0
- package/lib/contexts/dialogContext.js +21 -0
- package/lib/contexts/dialogContext.js.map +1 -0
- package/lib/contexts/dialogSurfaceContext.js +10 -0
- package/lib/contexts/dialogSurfaceContext.js.map +1 -0
- package/lib/contexts/index.js +4 -0
- package/lib/contexts/index.js.map +1 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -0
- package/lib/utils/index.js +5 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/isEscapeKeyDown.js +11 -0
- package/lib/utils/isEscapeKeyDown.js.map +1 -0
- package/lib/utils/isTargetDisabled.js +14 -0
- package/lib/utils/isTargetDisabled.js.map +1 -0
- package/lib/utils/localShorthands.js +9 -0
- package/lib/utils/localShorthands.js.map +1 -0
- package/lib/utils/normalizeDefaultPrevented.js +11 -0
- package/lib/utils/normalizeDefaultPrevented.js.map +1 -0
- package/lib-commonjs/Dialog.js +10 -0
- package/lib-commonjs/Dialog.js.map +1 -0
- package/lib-commonjs/DialogActions.js +10 -0
- package/lib-commonjs/DialogActions.js.map +1 -0
- package/lib-commonjs/DialogBody.js +10 -0
- package/lib-commonjs/DialogBody.js.map +1 -0
- package/lib-commonjs/DialogSurface.js +10 -0
- package/lib-commonjs/DialogSurface.js.map +1 -0
- package/lib-commonjs/DialogTitle.js +10 -0
- package/lib-commonjs/DialogTitle.js.map +1 -0
- package/lib-commonjs/DialogTrigger.js +10 -0
- package/lib-commonjs/DialogTrigger.js.map +1 -0
- package/lib-commonjs/components/Dialog/Dialog.js +33 -0
- package/lib-commonjs/components/Dialog/Dialog.js.map +1 -0
- package/lib-commonjs/components/Dialog/Dialog.types.js +6 -0
- package/lib-commonjs/components/Dialog/Dialog.types.js.map +1 -0
- package/lib-commonjs/components/Dialog/index.js +18 -0
- package/lib-commonjs/components/Dialog/index.js.map +1 -0
- package/lib-commonjs/components/Dialog/renderDialog.js +39 -0
- package/lib-commonjs/components/Dialog/renderDialog.js.map +1 -0
- package/lib-commonjs/components/Dialog/useDialog.js +211 -0
- package/lib-commonjs/components/Dialog/useDialog.js.map +1 -0
- package/lib-commonjs/components/Dialog/useDialogContextValues.js +40 -0
- package/lib-commonjs/components/Dialog/useDialogContextValues.js.map +1 -0
- package/lib-commonjs/components/Dialog/useDialogStyles.js +53 -0
- package/lib-commonjs/components/Dialog/useDialogStyles.js.map +1 -0
- package/lib-commonjs/components/DialogActions/DialogActions.js +27 -0
- package/lib-commonjs/components/DialogActions/DialogActions.js.map +1 -0
- package/lib-commonjs/components/DialogActions/DialogActions.types.js +6 -0
- package/lib-commonjs/components/DialogActions/DialogActions.types.js.map +1 -0
- package/lib-commonjs/components/DialogActions/index.js +18 -0
- package/lib-commonjs/components/DialogActions/index.js.map +1 -0
- package/lib-commonjs/components/DialogActions/renderDialogActions.js +27 -0
- package/lib-commonjs/components/DialogActions/renderDialogActions.js.map +1 -0
- package/lib-commonjs/components/DialogActions/useDialogActions.js +37 -0
- package/lib-commonjs/components/DialogActions/useDialogActions.js.map +1 -0
- package/lib-commonjs/components/DialogActions/useDialogActionsStyles.js +63 -0
- package/lib-commonjs/components/DialogActions/useDialogActionsStyles.js.map +1 -0
- package/lib-commonjs/components/DialogBody/DialogBody.js +27 -0
- package/lib-commonjs/components/DialogBody/DialogBody.js.map +1 -0
- package/lib-commonjs/components/DialogBody/DialogBody.types.js +6 -0
- package/lib-commonjs/components/DialogBody/DialogBody.types.js.map +1 -0
- package/lib-commonjs/components/DialogBody/index.js +18 -0
- package/lib-commonjs/components/DialogBody/index.js.map +1 -0
- package/lib-commonjs/components/DialogBody/renderDialogBody.js +27 -0
- package/lib-commonjs/components/DialogBody/renderDialogBody.js.map +1 -0
- package/lib-commonjs/components/DialogBody/useDialogBody.js +36 -0
- package/lib-commonjs/components/DialogBody/useDialogBody.js.map +1 -0
- package/lib-commonjs/components/DialogBody/useDialogBodyStyles.js +55 -0
- package/lib-commonjs/components/DialogBody/useDialogBodyStyles.js.map +1 -0
- package/lib-commonjs/components/DialogSurface/DialogSurface.js +30 -0
- package/lib-commonjs/components/DialogSurface/DialogSurface.js.map +1 -0
- package/lib-commonjs/components/DialogSurface/DialogSurface.types.js +6 -0
- package/lib-commonjs/components/DialogSurface/DialogSurface.types.js.map +1 -0
- package/lib-commonjs/components/DialogSurface/index.js +18 -0
- package/lib-commonjs/components/DialogSurface/index.js.map +1 -0
- package/lib-commonjs/components/DialogSurface/renderDialogSurface.js +30 -0
- package/lib-commonjs/components/DialogSurface/renderDialogSurface.js.map +1 -0
- package/lib-commonjs/components/DialogSurface/useDialogSurface.js +72 -0
- package/lib-commonjs/components/DialogSurface/useDialogSurface.js.map +1 -0
- package/lib-commonjs/components/DialogSurface/useDialogSurfaceContextValues.js +16 -0
- package/lib-commonjs/components/DialogSurface/useDialogSurfaceContextValues.js.map +1 -0
- package/lib-commonjs/components/DialogSurface/useDialogSurfaceStyles.js +90 -0
- package/lib-commonjs/components/DialogSurface/useDialogSurfaceStyles.js.map +1 -0
- package/lib-commonjs/components/DialogTitle/DialogTitle.js +28 -0
- package/lib-commonjs/components/DialogTitle/DialogTitle.js.map +1 -0
- package/lib-commonjs/components/DialogTitle/DialogTitle.types.js +6 -0
- package/lib-commonjs/components/DialogTitle/DialogTitle.types.js.map +1 -0
- package/lib-commonjs/components/DialogTitle/index.js +18 -0
- package/lib-commonjs/components/DialogTitle/index.js.map +1 -0
- package/lib-commonjs/components/DialogTitle/renderDialogTitle.js +31 -0
- package/lib-commonjs/components/DialogTitle/renderDialogTitle.js.map +1 -0
- package/lib-commonjs/components/DialogTitle/useDialogTitle.js +56 -0
- package/lib-commonjs/components/DialogTitle/useDialogTitle.js.map +1 -0
- package/lib-commonjs/components/DialogTitle/useDialogTitleStyles.js +123 -0
- package/lib-commonjs/components/DialogTitle/useDialogTitleStyles.js.map +1 -0
- package/lib-commonjs/components/DialogTrigger/DialogTrigger.js +31 -0
- package/lib-commonjs/components/DialogTrigger/DialogTrigger.js.map +1 -0
- package/lib-commonjs/components/DialogTrigger/DialogTrigger.types.js +6 -0
- package/lib-commonjs/components/DialogTrigger/DialogTrigger.types.js.map +1 -0
- package/lib-commonjs/components/DialogTrigger/index.js +16 -0
- package/lib-commonjs/components/DialogTrigger/index.js.map +1 -0
- package/lib-commonjs/components/DialogTrigger/renderDialogTrigger.js +16 -0
- package/lib-commonjs/components/DialogTrigger/renderDialogTrigger.js.map +1 -0
- package/lib-commonjs/components/DialogTrigger/useDialogTrigger.js +80 -0
- package/lib-commonjs/components/DialogTrigger/useDialogTrigger.js.map +1 -0
- package/lib-commonjs/contexts/constants.js +17 -0
- package/lib-commonjs/contexts/constants.js.map +1 -0
- package/lib-commonjs/contexts/dialogContext.js +32 -0
- package/lib-commonjs/contexts/dialogContext.js.map +1 -0
- package/lib-commonjs/contexts/dialogSurfaceContext.js +21 -0
- package/lib-commonjs/contexts/dialogSurfaceContext.js.map +1 -0
- package/lib-commonjs/contexts/index.js +14 -0
- package/lib-commonjs/contexts/index.js.map +1 -0
- package/lib-commonjs/index.js +193 -0
- package/lib-commonjs/index.js.map +1 -0
- package/lib-commonjs/utils/index.js +16 -0
- package/lib-commonjs/utils/index.js.map +1 -0
- package/lib-commonjs/utils/isEscapeKeyDown.js +22 -0
- package/lib-commonjs/utils/isEscapeKeyDown.js.map +1 -0
- package/lib-commonjs/utils/isTargetDisabled.js +23 -0
- package/lib-commonjs/utils/isTargetDisabled.js.map +1 -0
- package/lib-commonjs/utils/localShorthands.js +18 -0
- package/lib-commonjs/utils/localShorthands.js.map +1 -0
- package/lib-commonjs/utils/normalizeDefaultPrevented.js +20 -0
- package/lib-commonjs/utils/normalizeDefaultPrevented.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const MEDIA_QUERY_BREAKPOINT_SELECTOR = '@media screen and (max-width: 480px)';
|
|
2
|
+
export const SURFACE_PADDING = '24px';
|
|
3
|
+
export const DIALOG_GAP = '8px';
|
|
4
|
+
export const SURFACE_BORDER_RADIUS = '8px';
|
|
5
|
+
export const SURFACE_BORDER_WIDTH = '1px';
|
|
6
|
+
export const ACTIONS_START_GRID_AREA = 'actions-start';
|
|
7
|
+
export const ACTIONS_END_GRID_AREA = 'actions-end';
|
|
8
|
+
export const TITLE_GRID_AREA = 'title';
|
|
9
|
+
export const CLOSE_BUTTON_GRID_AREA = 'close-button';
|
|
10
|
+
export const BODY_GRID_AREA = 'body';
|
|
11
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"../src/","sources":["contexts/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,+BAA+B,GAAG,sCAAsC,CAAC;AACtF,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AACtC,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAC;AAChC,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAC3C,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAE1C,MAAM,CAAC,MAAM,uBAAuB,GAAG,eAAe,CAAC;AACvD,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC;AACnD,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC;AACvC,MAAM,CAAC,MAAM,sBAAsB,GAAG,cAAc,CAAC;AACrD,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC","sourcesContent":["export const MEDIA_QUERY_BREAKPOINT_SELECTOR = '@media screen and (max-width: 480px)';\nexport const SURFACE_PADDING = '24px';\nexport const DIALOG_GAP = '8px';\nexport const SURFACE_BORDER_RADIUS = '8px';\nexport const SURFACE_BORDER_WIDTH = '1px';\n\nexport const ACTIONS_START_GRID_AREA = 'actions-start';\nexport const ACTIONS_END_GRID_AREA = 'actions-end';\nexport const TITLE_GRID_AREA = 'title';\nexport const CLOSE_BUTTON_GRID_AREA = 'close-button';\nexport const BODY_GRID_AREA = 'body';\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createContext, useContextSelector } from '@fluentui/react-context-selector';
|
|
2
|
+
const defaultContextValue = {
|
|
3
|
+
open: false,
|
|
4
|
+
modalType: 'modal',
|
|
5
|
+
triggerRef: {
|
|
6
|
+
current: null
|
|
7
|
+
},
|
|
8
|
+
contentRef: {
|
|
9
|
+
current: null
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
requestOpenChange() {
|
|
13
|
+
/* noop */
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
}; // Contexts should default to undefined
|
|
17
|
+
|
|
18
|
+
export const DialogContext = /*#__PURE__*/createContext(undefined);
|
|
19
|
+
export const DialogProvider = DialogContext.Provider;
|
|
20
|
+
export const useDialogContext_unstable = selector => useContextSelector(DialogContext, (ctx = defaultContextValue) => selector(ctx));
|
|
21
|
+
//# sourceMappingURL=dialogContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["contexts/dialogContext.ts"],"names":[],"mappings":"AAAA,SAAS,aAAT,EAAyC,kBAAzC,QAAmE,kCAAnE;AAsBA,MAAM,mBAAmB,GAAuB;EAC9C,IAAI,EAAE,KADwC;EAE9C,SAAS,EAAE,OAFmC;EAG9C,UAAU,EAAE;IAAE,OAAO,EAAE;EAAX,CAHkC;EAI9C,UAAU,EAAE;IAAE,OAAO,EAAE;EAAX,CAJkC;;EAK9C,iBAAiB,GAAA;IACf;EACD;;AAP6C,CAAhD,C,CAUA;;AACA,OAAO,MAAM,aAAa,gBAA4C,aAAa,CACjF,SADiF,CAA5E;AAIP,OAAO,MAAM,cAAc,GAAG,aAAa,CAAC,QAArC;AACP,OAAO,MAAM,yBAAyB,GAAO,QAAJ,IACvC,kBAAkB,CAAC,aAAD,EAAgB,CAAC,GAAG,GAAG,mBAAP,KAA+B,QAAQ,CAAC,GAAD,CAAvD,CADb","sourcesContent":["import { createContext, ContextSelector, useContextSelector } from '@fluentui/react-context-selector';\nimport type { Context } from '@fluentui/react-context-selector';\nimport type { DialogOpenChangeData, DialogModalType } from '../Dialog';\nimport * as React from 'react';\n\nexport type DialogContextValue = {\n /**\n * Reference to trigger element that opened the Dialog\n * null if Dialog is closed\n */\n triggerRef: React.RefObject<HTMLElement>;\n contentRef: React.RefObject<HTMLElement>;\n modalType: DialogModalType;\n dialogTitleID?: string;\n dialogBodyID?: string;\n open: boolean;\n /**\n * Requests dialog main component to update it's internal open state\n */\n requestOpenChange: (data: DialogOpenChangeData) => void;\n};\n\nconst defaultContextValue: DialogContextValue = {\n open: false,\n modalType: 'modal',\n triggerRef: { current: null },\n contentRef: { current: null },\n requestOpenChange() {\n /* noop */\n },\n};\n\n// Contexts should default to undefined\nexport const DialogContext: Context<DialogContextValue | undefined> = createContext<DialogContextValue | undefined>(\n undefined,\n);\n\nexport const DialogProvider = DialogContext.Provider;\nexport const useDialogContext_unstable = <T>(selector: ContextSelector<DialogContextValue, T>): T =>\n useContextSelector(DialogContext, (ctx = defaultContextValue) => selector(ctx));\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
const defaultContextValue = false;
|
|
3
|
+
export const DialogSurfaceContext = /*#__PURE__*/createContext(undefined);
|
|
4
|
+
export const DialogSurfaceProvider = DialogSurfaceContext.Provider;
|
|
5
|
+
export const useDialogSurfaceContext_unstable = () => {
|
|
6
|
+
var _a;
|
|
7
|
+
|
|
8
|
+
return (_a = useContext(DialogSurfaceContext)) !== null && _a !== void 0 ? _a : defaultContextValue;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=dialogSurfaceContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["contexts/dialogSurfaceContext.ts"],"names":[],"mappings":"AAAA,SAAS,aAAT,EAAwB,UAAxB,QAA0C,OAA1C;AAIA,MAAM,mBAAmB,GAA8B,KAAvD;AAEA,OAAO,MAAM,oBAAoB,gBAAG,aAAa,CAAwC,SAAxC,CAA1C;AAEP,OAAO,MAAM,qBAAqB,GAAG,oBAAoB,CAAC,QAAnD;AAEP,OAAO,MAAM,gCAAgC,GAAG,MAAK;EAAA,IAAA,EAAA;;EAAC,OAAA,CAAA,EAAA,GAAA,UAAU,CAAC,oBAAD,CAAV,MAAgC,IAAhC,IAAgC,EAAA,KAAA,KAAA,CAAhC,GAAgC,EAAhC,GAAoC,mBAApC;AAAuD,CAAtG","sourcesContent":["import { createContext, useContext } from 'react';\n\nexport type DialogSurfaceContextValue = boolean;\n\nconst defaultContextValue: DialogSurfaceContextValue = false;\n\nexport const DialogSurfaceContext = createContext<DialogSurfaceContextValue | undefined>(undefined);\n\nexport const DialogSurfaceProvider = DialogSurfaceContext.Provider;\n\nexport const useDialogSurfaceContext_unstable = () => useContext(DialogSurfaceContext) ?? defaultContextValue;\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["contexts/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC","sourcesContent":["export * from './constants';\nexport * from './dialogContext';\nexport * from './dialogSurfaceContext';\n"]}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Dialog, dialogClassNames, renderDialog_unstable, useDialogStyles_unstable, useDialog_unstable } from './Dialog';
|
|
2
|
+
export { DialogTrigger, useDialogTrigger_unstable, renderDialogTrigger_unstable } from './DialogTrigger';
|
|
3
|
+
export { DialogActions, dialogActionsClassNames, useDialogActions_unstable, useDialogActionsStyles_unstable, renderDialogActions_unstable } from './DialogActions';
|
|
4
|
+
export { DialogBody, dialogBodyClassNames, useDialogBody_unstable, useDialogBodyStyles_unstable, renderDialogBody_unstable } from './DialogBody';
|
|
5
|
+
export { DialogTitle, dialogTitleClassNames, useDialogTitle_unstable, useDialogTitleStyles_unstable, renderDialogTitle_unstable } from './DialogTitle';
|
|
6
|
+
export { DialogSurface, dialogSurfaceClassNames, useDialogSurface_unstable, useDialogSurfaceStyles_unstable, renderDialogSurface_unstable } from './DialogSurface';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,SACE,MADF,EAEE,gBAFF,EAGE,qBAHF,EAIE,wBAJF,EAKE,kBALF,QAMO,UANP;AASA,SAAS,aAAT,EAAwB,yBAAxB,EAAmD,4BAAnD,QAAuF,iBAAvF;AAQA,SACE,aADF,EAEE,uBAFF,EAGE,yBAHF,EAIE,+BAJF,EAKE,4BALF,QAMO,iBANP;AAcA,SACE,UADF,EAEE,oBAFF,EAGE,sBAHF,EAIE,4BAJF,EAKE,yBALF,QAMO,cANP;AASA,SACE,WADF,EAEE,qBAFF,EAGE,uBAHF,EAIE,6BAJF,EAKE,0BALF,QAMO,eANP;AASA,SACE,aADF,EAEE,uBAFF,EAGE,yBAHF,EAIE,+BAJF,EAKE,4BALF,QAMO,iBANP","sourcesContent":["export {\n Dialog,\n dialogClassNames,\n renderDialog_unstable,\n useDialogStyles_unstable,\n useDialog_unstable,\n} from './Dialog';\nexport type { DialogProps, DialogOpenChangeData, DialogOpenChangeEvent, DialogSlots, DialogState } from './Dialog';\n\nexport { DialogTrigger, useDialogTrigger_unstable, renderDialogTrigger_unstable } from './DialogTrigger';\nexport type {\n DialogTriggerProps,\n DialogTriggerChildProps,\n DialogTriggerState,\n DialogTriggerAction,\n} from './DialogTrigger';\n\nexport {\n DialogActions,\n dialogActionsClassNames,\n useDialogActions_unstable,\n useDialogActionsStyles_unstable,\n renderDialogActions_unstable,\n} from './DialogActions';\nexport type {\n DialogActionsProps,\n DialogActionsSlots,\n DialogActionsState,\n DialogActionsPosition,\n} from './DialogActions';\n\nexport {\n DialogBody,\n dialogBodyClassNames,\n useDialogBody_unstable,\n useDialogBodyStyles_unstable,\n renderDialogBody_unstable,\n} from './DialogBody';\nexport type { DialogBodyProps, DialogBodySlots, DialogBodyState } from './DialogBody';\n\nexport {\n DialogTitle,\n dialogTitleClassNames,\n useDialogTitle_unstable,\n useDialogTitleStyles_unstable,\n renderDialogTitle_unstable,\n} from './DialogTitle';\nexport type { DialogTitleProps, DialogTitleSlots, DialogTitleState } from './DialogTitle';\n\nexport {\n DialogSurface,\n dialogSurfaceClassNames,\n useDialogSurface_unstable,\n useDialogSurfaceStyles_unstable,\n renderDialogSurface_unstable,\n} from './DialogSurface';\nexport type { DialogSurfaceProps, DialogSurfaceSlots, DialogSurfaceState } from './DialogSurface';\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC","sourcesContent":["export * from './isEscapeKeyDown';\nexport * from './isTargetDisabled';\nexport * from './localShorthands';\nexport * from './normalizeDefaultPrevented';\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Escape } from '@fluentui/keyboard-keys';
|
|
2
|
+
import { normalizeDefaultPrevented } from './normalizeDefaultPrevented';
|
|
3
|
+
/**
|
|
4
|
+
* Checks if keydown event is a proper Escape key dismiss
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export function isEscapeKeyDismiss(event, type) {
|
|
8
|
+
const isDefaultPrevented = normalizeDefaultPrevented(event);
|
|
9
|
+
return event.key === Escape && type !== 'alert' && !isDefaultPrevented();
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=isEscapeKeyDown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["utils/isEscapeKeyDown.ts"],"names":[],"mappings":"AACA,SAAS,MAAT,QAAuB,yBAAvB;AAEA,SAAS,yBAAT,QAA0C,6BAA1C;AAEA;;AAEG;;AACH,OAAM,SAAU,kBAAV,CAA6B,KAA7B,EAAyE,IAAzE,EAA8F;EAClG,MAAM,kBAAkB,GAAG,yBAAyB,CAAC,KAAD,CAApD;EACA,OAAO,KAAK,CAAC,GAAN,KAAc,MAAd,IAAwB,IAAI,KAAK,OAAjC,IAA4C,CAAC,kBAAkB,EAAtE;AACD","sourcesContent":["import * as React from 'react';\nimport { Escape } from '@fluentui/keyboard-keys';\nimport { DialogModalType } from '../components/Dialog/Dialog.types';\nimport { normalizeDefaultPrevented } from './normalizeDefaultPrevented';\n\n/**\n * Checks if keydown event is a proper Escape key dismiss\n */\nexport function isEscapeKeyDismiss(event: React.KeyboardEvent | KeyboardEvent, type: DialogModalType): boolean {\n const isDefaultPrevented = normalizeDefaultPrevented(event);\n return event.key === Escape && type !== 'alert' && !isDefaultPrevented();\n}\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function isTargetDisabled(event) {
|
|
2
|
+
const isDisabled = el => el.hasAttribute('disabled') || el.hasAttribute('aria-disabled') && el.getAttribute('aria-disabled') === 'true';
|
|
3
|
+
|
|
4
|
+
if (isHTMLElement(event.target) && isDisabled(event.target)) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return isHTMLElement(event.currentTarget) && isDisabled(event.currentTarget);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function isHTMLElement(element) {
|
|
12
|
+
return Boolean(element && typeof element === 'object' && 'hasAttribute' in element && 'getAttribute' in element);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=isTargetDisabled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["utils/isTargetDisabled.ts"],"names":[],"mappings":"AAEA,OAAM,SAAU,gBAAV,CAA2B,KAA3B,EAA8D;EAClE,MAAM,UAAU,GAAI,EAAD,IACjB,EAAE,CAAC,YAAH,CAAgB,UAAhB,KAAgC,EAAE,CAAC,YAAH,CAAgB,eAAhB,KAAoC,EAAE,CAAC,YAAH,CAAgB,eAAhB,MAAqC,MAD3G;;EAEA,IAAI,aAAa,CAAC,KAAK,CAAC,MAAP,CAAb,IAA+B,UAAU,CAAC,KAAK,CAAC,MAAP,CAA7C,EAA4E;IAC1E,OAAO,IAAP;EACD;;EAED,OAAO,aAAa,CAAC,KAAK,CAAC,aAAP,CAAb,IAAsC,UAAU,CAAC,KAAK,CAAC,aAAP,CAAvD;AACD;;AAED,SAAS,aAAT,CAAuB,OAAvB,EAA6C;EAC3C,OAAO,OAAO,CAAC,OAAO,IAAI,OAAO,OAAP,KAAmB,QAA9B,IAA0C,kBAAkB,OAA5D,IAAuE,kBAAkB,OAA1F,CAAd;AACD","sourcesContent":["import * as React from 'react';\n\nexport function isTargetDisabled(event: React.SyntheticEvent | Event) {\n const isDisabled = (el: HTMLElement) =>\n el.hasAttribute('disabled') || (el.hasAttribute('aria-disabled') && el.getAttribute('aria-disabled') === 'true');\n if (isHTMLElement(event.target) && isDisabled(event.target as HTMLElement)) {\n return true;\n }\n\n return isHTMLElement(event.currentTarget) && isDisabled(event.currentTarget);\n}\n\nfunction isHTMLElement(element: object | null): element is HTMLElement {\n return Boolean(element && typeof element === 'object' && 'hasAttribute' in element && 'getAttribute' in element);\n}\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["utils/localShorthands.ts"],"names":[],"mappings":"AAAA,OAAM,SAAU,QAAV,CAAmB,IAAnB,EAA+B;EACnC,OAAO;IACL,YAAY,EAAE,IADT;IAEL,UAAU,EAAE,IAFP;IAGL,eAAe,EAAE,IAHZ;IAIL,aAAa,EAAE;EAJV,CAAP;AAMD","sourcesContent":["export function gridArea(name: string) {\n return {\n gridRowStart: name,\n gridRowEnd: name,\n gridColumnStart: name,\n gridColumnEnd: name,\n };\n}\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* normalizes defaultPrevented to work the same way between synthetic events and regular event
|
|
3
|
+
*/
|
|
4
|
+
export function normalizeDefaultPrevented(event) {
|
|
5
|
+
if (event instanceof Event) {
|
|
6
|
+
return () => event.defaultPrevented;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return event.isDefaultPrevented;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=normalizeDefaultPrevented.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["utils/normalizeDefaultPrevented.ts"],"names":[],"mappings":"AAEA;;AAEG;AACH,OAAM,SAAU,yBAAV,CAAoC,KAApC,EAAuE;EAC3E,IAAI,KAAK,YAAY,KAArB,EAA4B;IAC1B,OAAO,MAAM,KAAK,CAAC,gBAAnB;EACD;;EACD,OAAO,KAAK,CAAC,kBAAb;AACD","sourcesContent":["import * as React from 'react';\n\n/**\n * normalizes defaultPrevented to work the same way between synthetic events and regular event\n */\nexport function normalizeDefaultPrevented(event: React.SyntheticEvent | Event) {\n if (event instanceof Event) {\n return () => event.defaultPrevented;\n }\n return event.isDefaultPrevented;\n}\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["Dialog.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,2BAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './components/Dialog/index';\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["DialogActions.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,kCAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './components/DialogActions/index';\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["DialogBody.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,+BAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './components/DialogBody/index';\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["DialogSurface.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,kCAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './components/DialogSurface/index';\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["DialogTitle.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,gCAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './components/DialogTitle/index';\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["DialogTrigger.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,kCAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './components/DialogTrigger/index';\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Dialog = void 0;
|
|
7
|
+
|
|
8
|
+
const React = /*#__PURE__*/require("react");
|
|
9
|
+
|
|
10
|
+
const useDialog_1 = /*#__PURE__*/require("./useDialog");
|
|
11
|
+
|
|
12
|
+
const renderDialog_1 = /*#__PURE__*/require("./renderDialog");
|
|
13
|
+
|
|
14
|
+
const useDialogStyles_1 = /*#__PURE__*/require("./useDialogStyles");
|
|
15
|
+
|
|
16
|
+
const useDialogContextValues_1 = /*#__PURE__*/require("./useDialogContextValues");
|
|
17
|
+
/**
|
|
18
|
+
* The `Dialog` root level component serves as an interface for interaction with all possible behaviors exposed.
|
|
19
|
+
* It provides context down the hierarchy to `children` compound components to allow functionality.
|
|
20
|
+
* This component expects to receive as children either a `DialogSurface` or a `DialogTrigger`
|
|
21
|
+
* and a `DialogSurface` (or some component that will eventually render one of those compound components)
|
|
22
|
+
* in this specific order
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
exports.Dialog = /*#__PURE__*/React.memo(props => {
|
|
27
|
+
const state = useDialog_1.useDialog_unstable(props);
|
|
28
|
+
const contextValues = useDialogContextValues_1.useDialogContextValues_unstable(state);
|
|
29
|
+
useDialogStyles_1.useDialogStyles_unstable(state);
|
|
30
|
+
return renderDialog_1.renderDialog_unstable(state, contextValues);
|
|
31
|
+
});
|
|
32
|
+
exports.Dialog.displayName = 'Dialog';
|
|
33
|
+
//# sourceMappingURL=Dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/Dialog/Dialog.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,WAAA,gBAAA,OAAA,CAAA,aAAA,CAAA;;AACA,MAAA,cAAA,gBAAA,OAAA,CAAA,gBAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,mBAAA,CAAA;;AAEA,MAAA,wBAAA,gBAAA,OAAA,CAAA,0BAAA,CAAA;AAEA;;;;;;AAMG;;;AACU,OAAA,CAAA,MAAA,gBAAgC,KAAK,CAAC,IAAN,CAAW,KAAK,IAAG;EAC9D,MAAM,KAAK,GAAG,WAAA,CAAA,kBAAA,CAAmB,KAAnB,CAAd;EACA,MAAM,aAAa,GAAG,wBAAA,CAAA,+BAAA,CAAgC,KAAhC,CAAtB;EAEA,iBAAA,CAAA,wBAAA,CAAyB,KAAzB;EACA,OAAO,cAAA,CAAA,qBAAA,CAAsB,KAAtB,EAA6B,aAA7B,CAAP;AACD,CAN4C,CAAhC;AAQb,OAAA,CAAA,MAAA,CAAO,WAAP,GAAqB,QAArB","sourcesContent":["import * as React from 'react';\nimport { useDialog_unstable } from './useDialog';\nimport { renderDialog_unstable } from './renderDialog';\nimport { useDialogStyles_unstable } from './useDialogStyles';\nimport type { DialogProps } from './Dialog.types';\nimport { useDialogContextValues_unstable } from './useDialogContextValues';\n\n/**\n * The `Dialog` root level component serves as an interface for interaction with all possible behaviors exposed.\n * It provides context down the hierarchy to `children` compound components to allow functionality.\n * This component expects to receive as children either a `DialogSurface` or a `DialogTrigger`\n * and a `DialogSurface` (or some component that will eventually render one of those compound components)\n * in this specific order\n */\nexport const Dialog: React.FC<DialogProps> = React.memo(props => {\n const state = useDialog_unstable(props);\n const contextValues = useDialogContextValues_unstable(state);\n\n useDialogStyles_unstable(state);\n return renderDialog_unstable(state, contextValues);\n});\n\nDialog.displayName = 'Dialog';\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":"../src/"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
const tslib_1 = /*#__PURE__*/require("tslib");
|
|
8
|
+
|
|
9
|
+
tslib_1.__exportStar(require("./Dialog"), exports);
|
|
10
|
+
|
|
11
|
+
tslib_1.__exportStar(require("./Dialog.types"), exports);
|
|
12
|
+
|
|
13
|
+
tslib_1.__exportStar(require("./renderDialog"), exports);
|
|
14
|
+
|
|
15
|
+
tslib_1.__exportStar(require("./useDialog"), exports);
|
|
16
|
+
|
|
17
|
+
tslib_1.__exportStar(require("./useDialogStyles"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/Dialog/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,UAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,gBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,gBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,aAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,mBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './Dialog';\nexport * from './Dialog.types';\nexport * from './renderDialog';\nexport * from './useDialog';\nexport * from './useDialogStyles';\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.renderDialog_unstable = void 0;
|
|
7
|
+
|
|
8
|
+
const React = /*#__PURE__*/require("react");
|
|
9
|
+
|
|
10
|
+
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
|
11
|
+
|
|
12
|
+
const react_portal_1 = /*#__PURE__*/require("@fluentui/react-portal");
|
|
13
|
+
|
|
14
|
+
const contexts_1 = /*#__PURE__*/require("../../contexts");
|
|
15
|
+
/**
|
|
16
|
+
* Render the final JSX of Dialog
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const renderDialog_unstable = (state, contextValues) => {
|
|
21
|
+
const {
|
|
22
|
+
content,
|
|
23
|
+
trigger,
|
|
24
|
+
open
|
|
25
|
+
} = state;
|
|
26
|
+
const {
|
|
27
|
+
slots,
|
|
28
|
+
slotProps
|
|
29
|
+
} = react_utilities_1.getSlots(state);
|
|
30
|
+
return React.createElement(contexts_1.DialogProvider, {
|
|
31
|
+
value: contextValues.dialog
|
|
32
|
+
}, React.createElement(contexts_1.DialogSurfaceProvider, {
|
|
33
|
+
value: contextValues.dialogSurface
|
|
34
|
+
}, trigger, open && React.createElement(react_portal_1.Portal, null, slots.overlay && React.createElement(slots.overlay, { ...slotProps.overlay
|
|
35
|
+
}), content)));
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.renderDialog_unstable = renderDialog_unstable;
|
|
39
|
+
//# sourceMappingURL=renderDialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/Dialog/renderDialog.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,MAAA,cAAA,gBAAA,OAAA,CAAA,wBAAA,CAAA;;AACA,MAAA,UAAA,gBAAA,OAAA,CAAA,gBAAA,CAAA;AAGA;;AAEG;;;AACI,MAAM,qBAAqB,GAAG,CAAC,KAAD,EAAqB,aAArB,KAA2D;EAC9F,MAAM;IAAE,OAAF;IAAW,OAAX;IAAoB;EAApB,IAA6B,KAAnC;EACA,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,iBAAA,CAAA,QAAA,CAAsB,KAAtB,CAA7B;EAEA,OACE,KAAA,CAAA,aAAA,CAAC,UAAA,CAAA,cAAD,EAAe;IAAC,KAAK,EAAE,aAAa,CAAC;EAAtB,CAAf,EACE,KAAA,CAAA,aAAA,CAAC,UAAA,CAAA,qBAAD,EAAsB;IAAC,KAAK,EAAE,aAAa,CAAC;EAAtB,CAAtB,EACG,OADH,EAEG,IAAI,IACH,KAAA,CAAA,aAAA,CAAC,cAAA,CAAA,MAAD,EAAO,IAAP,EACG,KAAK,CAAC,OAAN,IAAiB,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,OAAP,EAAc,EAAA,GAAK,SAAS,CAAC;EAAf,CAAd,CADpB,EAEG,OAFH,CAHJ,CADF,CADF;AAaD,CAjBM;;AAAM,OAAA,CAAA,qBAAA,GAAqB,qBAArB","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport { Portal } from '@fluentui/react-portal';\nimport { DialogProvider, DialogSurfaceProvider } from '../../contexts';\nimport type { DialogState, DialogSlots, DialogContextValues } from './Dialog.types';\n\n/**\n * Render the final JSX of Dialog\n */\nexport const renderDialog_unstable = (state: DialogState, contextValues: DialogContextValues) => {\n const { content, trigger, open } = state;\n const { slots, slotProps } = getSlots<DialogSlots>(state);\n\n return (\n <DialogProvider value={contextValues.dialog}>\n <DialogSurfaceProvider value={contextValues.dialogSurface}>\n {trigger}\n {open && (\n <Portal>\n {slots.overlay && <slots.overlay {...slotProps.overlay} />}\n {content}\n </Portal>\n )}\n </DialogSurfaceProvider>\n </DialogProvider>\n );\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useDialog_unstable = void 0;
|
|
7
|
+
|
|
8
|
+
const React = /*#__PURE__*/require("react");
|
|
9
|
+
|
|
10
|
+
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
|
11
|
+
|
|
12
|
+
const react_tabster_1 = /*#__PURE__*/require("@fluentui/react-tabster");
|
|
13
|
+
|
|
14
|
+
const react_shared_contexts_1 = /*#__PURE__*/require("@fluentui/react-shared-contexts");
|
|
15
|
+
|
|
16
|
+
const utils_1 = /*#__PURE__*/require("../../utils");
|
|
17
|
+
/**
|
|
18
|
+
* Create the state required to render Dialog.
|
|
19
|
+
*
|
|
20
|
+
* The returned state can be modified with hooks such as useDialogStyles_unstable,
|
|
21
|
+
* before being passed to renderDialog_unstable.
|
|
22
|
+
*
|
|
23
|
+
* @param props - props from this instance of Dialog
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const useDialog_unstable = props => {
|
|
28
|
+
const {
|
|
29
|
+
children,
|
|
30
|
+
overlay,
|
|
31
|
+
modalType = 'modal',
|
|
32
|
+
onOpenChange
|
|
33
|
+
} = props;
|
|
34
|
+
const [trigger, content] = childrenToTriggerAndContent(children);
|
|
35
|
+
const [open, setOpen] = react_utilities_1.useControllableState({
|
|
36
|
+
state: props.open,
|
|
37
|
+
defaultState: props.defaultOpen,
|
|
38
|
+
initialState: false
|
|
39
|
+
});
|
|
40
|
+
const overlayShorthand = react_utilities_1.resolveShorthand(overlay, {
|
|
41
|
+
required: modalType !== 'non-modal',
|
|
42
|
+
defaultProps: {
|
|
43
|
+
'aria-hidden': 'true'
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const requestOpenChange = react_utilities_1.useEventCallback(data => {
|
|
47
|
+
const isDefaultPrevented = utils_1.normalizeDefaultPrevented(data.event);
|
|
48
|
+
|
|
49
|
+
if (onOpenChange) {
|
|
50
|
+
onOpenChange(data.event, data);
|
|
51
|
+
} // if user prevents default then do not change state value
|
|
52
|
+
// otherwise updates state value and trigger reference to the element that caused the opening
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if (!isDefaultPrevented()) {
|
|
56
|
+
triggerRef.current = !open && data.open ? data.event.currentTarget : null;
|
|
57
|
+
setOpen(data.open);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const {
|
|
61
|
+
contentRef,
|
|
62
|
+
triggerRef
|
|
63
|
+
} = useFocusFirstElement({
|
|
64
|
+
open,
|
|
65
|
+
modalType,
|
|
66
|
+
requestOpenChange
|
|
67
|
+
});
|
|
68
|
+
const handleOverLayClick = react_utilities_1.useEventCallback(event => {
|
|
69
|
+
var _a;
|
|
70
|
+
|
|
71
|
+
(_a = overlayShorthand === null || overlayShorthand === void 0 ? void 0 : overlayShorthand.onClick) === null || _a === void 0 ? void 0 : _a.call(overlayShorthand, event);
|
|
72
|
+
|
|
73
|
+
if (isOverlayClickDismiss(event, modalType)) {
|
|
74
|
+
requestOpenChange({
|
|
75
|
+
event,
|
|
76
|
+
open: false,
|
|
77
|
+
type: 'overlayClick'
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
components: {
|
|
83
|
+
overlay: 'div'
|
|
84
|
+
},
|
|
85
|
+
overlay: overlayShorthand && { ...overlayShorthand,
|
|
86
|
+
onClick: handleOverLayClick
|
|
87
|
+
},
|
|
88
|
+
open,
|
|
89
|
+
modalType,
|
|
90
|
+
content,
|
|
91
|
+
trigger,
|
|
92
|
+
triggerRef,
|
|
93
|
+
contentRef,
|
|
94
|
+
requestOpenChange,
|
|
95
|
+
dialogBodyID: react_utilities_1.useId('dialog-body-'),
|
|
96
|
+
dialogTitleID: react_utilities_1.useId('dialog-title-')
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
exports.useDialog_unstable = useDialog_unstable;
|
|
101
|
+
/**
|
|
102
|
+
* Extracts trigger and content from children
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
function childrenToTriggerAndContent(children) {
|
|
106
|
+
const childrenArray = React.Children.toArray(children);
|
|
107
|
+
|
|
108
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
109
|
+
if (childrenArray.length !== 1 && childrenArray.length !== 2) {
|
|
110
|
+
// eslint-disable-next-line no-console
|
|
111
|
+
console.warn('Dialog must contain at least one child <DialogSurface/>,\n' + 'and at most two children <DialogTrigger/> <DialogSurface/> (in this order)');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
switch (childrenArray.length) {
|
|
116
|
+
// case where there's a trigger followed by content
|
|
117
|
+
case 2:
|
|
118
|
+
return childrenArray;
|
|
119
|
+
// case where there's only content
|
|
120
|
+
|
|
121
|
+
case 1:
|
|
122
|
+
return [undefined, childrenArray[0]];
|
|
123
|
+
// unknown case
|
|
124
|
+
|
|
125
|
+
default:
|
|
126
|
+
return [undefined, undefined];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Checks is click event is a proper Overlay click dismiss
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
function isOverlayClickDismiss(event, type) {
|
|
135
|
+
const isDefaultPrevented = utils_1.normalizeDefaultPrevented(event);
|
|
136
|
+
return type === 'modal' && !isDefaultPrevented();
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Focus first element on content when dialog is opened,
|
|
140
|
+
* in case there's no focusable element, then a eventlistener is added to document
|
|
141
|
+
* to ensure Escape keydown functionality
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
function useFocusFirstElement({
|
|
146
|
+
open,
|
|
147
|
+
requestOpenChange,
|
|
148
|
+
modalType
|
|
149
|
+
}) {
|
|
150
|
+
const {
|
|
151
|
+
findFirstFocusable
|
|
152
|
+
} = react_tabster_1.useFocusFinders();
|
|
153
|
+
const {
|
|
154
|
+
targetDocument
|
|
155
|
+
} = react_shared_contexts_1.useFluent_unstable();
|
|
156
|
+
const contentRef = React.useRef(null);
|
|
157
|
+
const triggerRef = React.useRef(null);
|
|
158
|
+
React.useEffect(() => {
|
|
159
|
+
if (!open) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const element = contentRef.current && findFirstFocusable(contentRef.current);
|
|
164
|
+
|
|
165
|
+
if (element) {
|
|
166
|
+
element.focus(); // NOTE: if it's non-modal global listener to escape is necessary
|
|
167
|
+
|
|
168
|
+
if (modalType !== 'non-modal') {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
173
|
+
// eslint-disable-next-line no-console
|
|
174
|
+
console.warn('A Dialog should have at least one focusable element inside DialogSurface');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (triggerRef.current && targetDocument) {
|
|
179
|
+
const trigger = triggerRef.current; // if the trigger is still the active element, the default behavior is to return focus to document.body,
|
|
180
|
+
// which can be achived by blurring
|
|
181
|
+
|
|
182
|
+
if (targetDocument.activeElement === trigger) {
|
|
183
|
+
trigger.blur();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const listener = event => {
|
|
187
|
+
if (utils_1.isEscapeKeyDismiss(event, modalType)) {
|
|
188
|
+
requestOpenChange({
|
|
189
|
+
event,
|
|
190
|
+
open: false,
|
|
191
|
+
type: 'documentEscapeKeyDown'
|
|
192
|
+
});
|
|
193
|
+
trigger.focus();
|
|
194
|
+
event.stopImmediatePropagation();
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
targetDocument.addEventListener('keydown', listener, {
|
|
199
|
+
passive: false
|
|
200
|
+
});
|
|
201
|
+
return () => {
|
|
202
|
+
targetDocument.removeEventListener('keydown', listener);
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}, [findFirstFocusable, requestOpenChange, open, modalType, targetDocument]);
|
|
206
|
+
return {
|
|
207
|
+
contentRef,
|
|
208
|
+
triggerRef
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=useDialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/Dialog/useDialog.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,MAAA,eAAA,gBAAA,OAAA,CAAA,yBAAA,CAAA;;AACA,MAAA,uBAAA,gBAAA,OAAA,CAAA,iCAAA,CAAA;;AACA,MAAA,OAAA,gBAAA,OAAA,CAAA,aAAA,CAAA;AAIA;;;;;;;AAOG;;;AACI,MAAM,kBAAkB,GAAI,KAAD,IAAoC;EACpE,MAAM;IAAE,QAAF;IAAY,OAAZ;IAAqB,SAAS,GAAG,OAAjC;IAA0C;EAA1C,IAA2D,KAAjE;EAEA,MAAM,CAAC,OAAD,EAAU,OAAV,IAAqB,2BAA2B,CAAC,QAAD,CAAtD;EAEA,MAAM,CAAC,IAAD,EAAO,OAAP,IAAkB,iBAAA,CAAA,oBAAA,CAAqB;IAC3C,KAAK,EAAE,KAAK,CAAC,IAD8B;IAE3C,YAAY,EAAE,KAAK,CAAC,WAFuB;IAG3C,YAAY,EAAE;EAH6B,CAArB,CAAxB;EAMA,MAAM,gBAAgB,GAAG,iBAAA,CAAA,gBAAA,CAAiB,OAAjB,EAA0B;IACjD,QAAQ,EAAE,SAAS,KAAK,WADyB;IAEjD,YAAY,EAAE;MACZ,eAAe;IADH;EAFmC,CAA1B,CAAzB;EAOA,MAAM,iBAAiB,GAAG,iBAAA,CAAA,gBAAA,CAAkB,IAAD,IAA+B;IACxE,MAAM,kBAAkB,GAAG,OAAA,CAAA,yBAAA,CAA0B,IAAI,CAAC,KAA/B,CAA3B;;IAEA,IAAI,YAAJ,EAAkB;MAChB,YAAY,CAAC,IAAI,CAAC,KAAN,EAAa,IAAb,CAAZ;IACD,CALuE,CAOxE;IACA;;;IACA,IAAI,CAAC,kBAAkB,EAAvB,EAA2B;MACxB,UAAyD,CAAC,OAA1D,GACC,CAAC,IAAD,IAAS,IAAI,CAAC,IAAd,GAAsB,IAAI,CAAC,KAAL,CAAW,aAAjC,GAAiE,IADlE;MAED,OAAO,CAAC,IAAI,CAAC,IAAN,CAAP;IACD;EACF,CAdyB,CAA1B;EAgBA,MAAM;IAAE,UAAF;IAAc;EAAd,IAA6B,oBAAoB,CAAC;IACtD,IADsD;IAEtD,SAFsD;IAGtD;EAHsD,CAAD,CAAvD;EAMA,MAAM,kBAAkB,GAAG,iBAAA,CAAA,gBAAA,CAAkB,KAAD,IAA4C;;;IACtF,CAAA,EAAA,GAAA,gBAAgB,KAAA,IAAhB,IAAA,gBAAgB,KAAA,KAAA,CAAhB,GAAgB,KAAA,CAAhB,GAAA,gBAAgB,CAAE,OAAlB,MAAyB,IAAzB,IAAyB,EAAA,KAAA,KAAA,CAAzB,GAAyB,KAAA,CAAzB,GAAyB,EAAA,CAAA,IAAA,CAAzB,gBAAyB,EAAG,KAAH,CAAzB;;IACA,IAAI,qBAAqB,CAAC,KAAD,EAAQ,SAAR,CAAzB,EAA6C;MAC3C,iBAAiB,CAAC;QAAE,KAAF;QAAS,IAAI,EAAE,KAAf;QAAsB,IAAI,EAAE;MAA5B,CAAD,CAAjB;IACD;EACF,CAL0B,CAA3B;EAOA,OAAO;IACL,UAAU,EAAE;MACV,OAAO,EAAE;IADC,CADP;IAIL,OAAO,EAAE,gBAAgB,IAAI,EAC3B,GAAG,gBADwB;MAE3B,OAAO,EAAE;IAFkB,CAJxB;IAQL,IARK;IASL,SATK;IAUL,OAVK;IAWL,OAXK;IAYL,UAZK;IAaL,UAbK;IAcL,iBAdK;IAeL,YAAY,EAAE,iBAAA,CAAA,KAAA,CAAM,cAAN,CAfT;IAgBL,aAAa,EAAE,iBAAA,CAAA,KAAA,CAAM,eAAN;EAhBV,CAAP;AAkBD,CAjEM;;AAAM,OAAA,CAAA,kBAAA,GAAkB,kBAAlB;AAmEb;;AAEG;;AACH,SAAS,2BAAT,CACE,QADF,EAC2B;EAEzB,MAAM,aAAa,GAAG,KAAK,CAAC,QAAN,CAAe,OAAf,CAAuB,QAAvB,CAAtB;;EACA,IAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;IACzC,IAAI,aAAa,CAAC,MAAd,KAAyB,CAAzB,IAA8B,aAAa,CAAC,MAAd,KAAyB,CAA3D,EAA8D;MAC5D;MACA,OAAO,CAAC,IAAR,CACE,+DACE,4EAFJ;IAID;EACF;;EACD,QAAQ,aAAa,CAAC,MAAtB;IACE;IACA,KAAK,CAAL;MACE,OAAO,aAAP;IACF;;IACA,KAAK,CAAL;MACE,OAAO,CAAC,SAAD,EAAY,aAAa,CAAC,CAAD,CAAzB,CAAP;IACF;;IACA;MACE,OAAO,CAAC,SAAD,EAAY,SAAZ,CAAP;EATJ;AAWD;AAED;;AAEG;;;AACH,SAAS,qBAAT,CAA+B,KAA/B,EAAwD,IAAxD,EAA6E;EAC3E,MAAM,kBAAkB,GAAG,OAAA,CAAA,yBAAA,CAA0B,KAA1B,CAA3B;EACA,OAAO,IAAI,KAAK,OAAT,IAAoB,CAAC,kBAAkB,EAA9C;AACD;AAED;;;;AAIG;;;AACH,SAAS,oBAAT,CAA8B;EAC5B,IAD4B;EAE5B,iBAF4B;EAG5B;AAH4B,CAA9B,EAIgE;EAC9D,MAAM;IAAE;EAAF,IAAyB,eAAA,CAAA,eAAA,EAA/B;EACA,MAAM;IAAE;EAAF,IAAqB,uBAAA,CAAA,kBAAA,EAA3B;EACA,MAAM,UAAU,GAAG,KAAK,CAAC,MAAN,CAA0B,IAA1B,CAAnB;EACA,MAAM,UAAU,GAAG,KAAK,CAAC,MAAN,CAA0B,IAA1B,CAAnB;EAEA,KAAK,CAAC,SAAN,CAAgB,MAAK;IACnB,IAAI,CAAC,IAAL,EAAW;MACT;IACD;;IAED,MAAM,OAAO,GAAG,UAAU,CAAC,OAAX,IAAsB,kBAAkB,CAAC,UAAU,CAAC,OAAZ,CAAxD;;IACA,IAAI,OAAJ,EAAa;MACX,OAAO,CAAC,KAAR,GADW,CAEX;;MACA,IAAI,SAAS,KAAK,WAAlB,EAA+B;QAC7B;MACD;IACF,CAND,MAMO;MACL,IAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;QACzC;QACA,OAAO,CAAC,IAAR,CAAa,0EAAb;MACD;IACF;;IAED,IAAI,UAAU,CAAC,OAAX,IAAsB,cAA1B,EAA0C;MACxC,MAAM,OAAO,GAAG,UAAU,CAAC,OAA3B,CADwC,CAExC;MACA;;MACA,IAAI,cAAc,CAAC,aAAf,KAAiC,OAArC,EAA8C;QAC5C,OAAO,CAAC,IAAR;MACD;;MACD,MAAM,QAAQ,GAAI,KAAD,IAAyB;QACxC,IAAI,OAAA,CAAA,kBAAA,CAAmB,KAAnB,EAA0B,SAA1B,CAAJ,EAA0C;UACxC,iBAAiB,CAAC;YAChB,KADgB;YAEhB,IAAI,EAAE,KAFU;YAGhB,IAAI,EAAE;UAHU,CAAD,CAAjB;UAKA,OAAO,CAAC,KAAR;UACA,KAAK,CAAC,wBAAN;QACD;MACF,CAVD;;MAWA,cAAc,CAAC,gBAAf,CAAgC,SAAhC,EAA2C,QAA3C,EAAqD;QAAE,OAAO,EAAE;MAAX,CAArD;MACA,OAAO,MAAK;QACV,cAAc,CAAC,mBAAf,CAAmC,SAAnC,EAA8C,QAA9C;MACD,CAFD;IAGD;EACF,CA1CD,EA0CG,CAAC,kBAAD,EAAqB,iBAArB,EAAwC,IAAxC,EAA8C,SAA9C,EAAyD,cAAzD,CA1CH;EA4CA,OAAO;IAAE,UAAF;IAAc;EAAd,CAAP;AACD","sourcesContent":["import * as React from 'react';\nimport { resolveShorthand, useControllableState, useEventCallback, useId } from '@fluentui/react-utilities';\nimport { useFocusFinders } from '@fluentui/react-tabster';\nimport { useFluent_unstable } from '@fluentui/react-shared-contexts';\nimport { normalizeDefaultPrevented, isEscapeKeyDismiss } from '../../utils';\n\nimport type { DialogProps, DialogState, DialogModalType, DialogOpenChangeData } from './Dialog.types';\n\n/**\n * Create the state required to render Dialog.\n *\n * The returned state can be modified with hooks such as useDialogStyles_unstable,\n * before being passed to renderDialog_unstable.\n *\n * @param props - props from this instance of Dialog\n */\nexport const useDialog_unstable = (props: DialogProps): DialogState => {\n const { children, overlay, modalType = 'modal', onOpenChange } = props;\n\n const [trigger, content] = childrenToTriggerAndContent(children);\n\n const [open, setOpen] = useControllableState({\n state: props.open,\n defaultState: props.defaultOpen,\n initialState: false,\n });\n\n const overlayShorthand = resolveShorthand(overlay, {\n required: modalType !== 'non-modal',\n defaultProps: {\n 'aria-hidden': 'true',\n },\n });\n\n const requestOpenChange = useEventCallback((data: DialogOpenChangeData) => {\n const isDefaultPrevented = normalizeDefaultPrevented(data.event);\n\n if (onOpenChange) {\n onOpenChange(data.event, data);\n }\n\n // if user prevents default then do not change state value\n // otherwise updates state value and trigger reference to the element that caused the opening\n if (!isDefaultPrevented()) {\n (triggerRef as React.MutableRefObject<HTMLElement | null>).current =\n !open && data.open ? (data.event.currentTarget as HTMLElement) : null;\n setOpen(data.open);\n }\n });\n\n const { contentRef, triggerRef } = useFocusFirstElement({\n open,\n modalType,\n requestOpenChange,\n });\n\n const handleOverLayClick = useEventCallback((event: React.MouseEvent<HTMLDivElement>) => {\n overlayShorthand?.onClick?.(event);\n if (isOverlayClickDismiss(event, modalType)) {\n requestOpenChange({ event, open: false, type: 'overlayClick' });\n }\n });\n\n return {\n components: {\n overlay: 'div',\n },\n overlay: overlayShorthand && {\n ...overlayShorthand,\n onClick: handleOverLayClick,\n },\n open,\n modalType,\n content,\n trigger,\n triggerRef,\n contentRef,\n requestOpenChange,\n dialogBodyID: useId('dialog-body-'),\n dialogTitleID: useId('dialog-title-'),\n };\n};\n\n/**\n * Extracts trigger and content from children\n */\nfunction childrenToTriggerAndContent(\n children: React.ReactNode,\n): readonly [trigger: React.ReactNode, content: React.ReactNode] {\n const childrenArray = React.Children.toArray(children) as React.ReactElement[];\n if (process.env.NODE_ENV !== 'production') {\n if (childrenArray.length !== 1 && childrenArray.length !== 2) {\n // eslint-disable-next-line no-console\n console.warn(\n 'Dialog must contain at least one child <DialogSurface/>,\\n' +\n 'and at most two children <DialogTrigger/> <DialogSurface/> (in this order)',\n );\n }\n }\n switch (childrenArray.length) {\n // case where there's a trigger followed by content\n case 2:\n return childrenArray as [trigger: React.ReactNode, content: React.ReactNode];\n // case where there's only content\n case 1:\n return [undefined, childrenArray[0]];\n // unknown case\n default:\n return [undefined, undefined];\n }\n}\n\n/**\n * Checks is click event is a proper Overlay click dismiss\n */\nfunction isOverlayClickDismiss(event: React.MouseEvent, type: DialogModalType): boolean {\n const isDefaultPrevented = normalizeDefaultPrevented(event);\n return type === 'modal' && !isDefaultPrevented();\n}\n\n/**\n * Focus first element on content when dialog is opened,\n * in case there's no focusable element, then a eventlistener is added to document\n * to ensure Escape keydown functionality\n */\nfunction useFocusFirstElement({\n open,\n requestOpenChange,\n modalType,\n}: Pick<DialogState, 'open' | 'requestOpenChange' | 'modalType'>) {\n const { findFirstFocusable } = useFocusFinders();\n const { targetDocument } = useFluent_unstable();\n const contentRef = React.useRef<HTMLElement>(null);\n const triggerRef = React.useRef<HTMLElement>(null);\n\n React.useEffect(() => {\n if (!open) {\n return;\n }\n\n const element = contentRef.current && findFirstFocusable(contentRef.current);\n if (element) {\n element.focus();\n // NOTE: if it's non-modal global listener to escape is necessary\n if (modalType !== 'non-modal') {\n return;\n }\n } else {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn('A Dialog should have at least one focusable element inside DialogSurface');\n }\n }\n\n if (triggerRef.current && targetDocument) {\n const trigger = triggerRef.current;\n // if the trigger is still the active element, the default behavior is to return focus to document.body,\n // which can be achived by blurring\n if (targetDocument.activeElement === trigger) {\n trigger.blur();\n }\n const listener = (event: KeyboardEvent) => {\n if (isEscapeKeyDismiss(event, modalType)) {\n requestOpenChange({\n event,\n open: false,\n type: 'documentEscapeKeyDown',\n });\n trigger.focus();\n event.stopImmediatePropagation();\n }\n };\n targetDocument.addEventListener('keydown', listener, { passive: false });\n return () => {\n targetDocument.removeEventListener('keydown', listener);\n };\n }\n }, [findFirstFocusable, requestOpenChange, open, modalType, targetDocument]);\n\n return { contentRef, triggerRef };\n}\n"],"sourceRoot":"../src/"}
|