@fluentui/react-dialog 9.0.0-beta.7 → 9.0.0-beta.8
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 +154 -5
- package/CHANGELOG.md +34 -6
- package/Spec.md +44 -25
- package/dist/index.d.ts +59 -59
- package/lib/components/Dialog/Dialog.js +0 -2
- package/lib/components/Dialog/Dialog.js.map +1 -1
- package/lib/components/Dialog/Dialog.types.js.map +1 -1
- package/lib/components/Dialog/index.js +0 -1
- package/lib/components/Dialog/index.js.map +1 -1
- package/lib/components/Dialog/renderDialog.js +2 -10
- package/lib/components/Dialog/renderDialog.js.map +1 -1
- package/lib/components/Dialog/useDialog.js +19 -129
- package/lib/components/Dialog/useDialog.js.map +1 -1
- package/lib/components/Dialog/useDialogContextValues.js +4 -4
- package/lib/components/Dialog/useDialogContextValues.js.map +1 -1
- package/lib/components/DialogActions/useDialogActionsStyles.js +3 -5
- package/lib/components/DialogActions/useDialogActionsStyles.js.map +1 -1
- package/lib/components/DialogBody/useDialogBodyStyles.js +5 -5
- package/lib/components/DialogBody/useDialogBodyStyles.js.map +1 -1
- package/lib/components/DialogSurface/DialogSurface.types.js.map +1 -1
- package/lib/components/DialogSurface/renderDialogSurface.js +4 -2
- package/lib/components/DialogSurface/renderDialogSurface.js.map +1 -1
- package/lib/components/DialogSurface/useDialogSurface.js +120 -21
- package/lib/components/DialogSurface/useDialogSurface.js.map +1 -1
- package/lib/components/DialogSurface/useDialogSurfaceStyles.js +56 -7
- package/lib/components/DialogSurface/useDialogSurfaceStyles.js.map +1 -1
- package/lib/components/DialogTitle/DialogTitle.js +2 -3
- package/lib/components/DialogTitle/DialogTitle.js.map +1 -1
- package/lib/components/DialogTitle/DialogTitle.types.js.map +1 -1
- package/lib/components/DialogTitle/renderDialogTitle.js +2 -5
- package/lib/components/DialogTitle/renderDialogTitle.js.map +1 -1
- package/lib/components/DialogTitle/useDialogTitle.js +15 -9
- package/lib/components/DialogTitle/useDialogTitle.js.map +1 -1
- package/lib/components/DialogTitle/useDialogTitleStyles.js +61 -54
- package/lib/components/DialogTitle/useDialogTitleStyles.js.map +1 -1
- package/lib/components/DialogTrigger/DialogTrigger.types.js.map +1 -1
- package/lib/components/DialogTrigger/useDialogTrigger.js +3 -22
- package/lib/components/DialogTrigger/useDialogTrigger.js.map +1 -1
- package/lib/contexts/constants.js +1 -1
- package/lib/contexts/constants.js.map +1 -1
- package/lib/contexts/dialogContext.js +2 -4
- package/lib/contexts/dialogContext.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/utils/index.js +4 -3
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/isEscapeKeyDown.js +5 -4
- package/lib/utils/isEscapeKeyDown.js.map +1 -1
- package/lib/utils/isHTMLDialogElement.js +4 -0
- package/lib/utils/isHTMLDialogElement.js.map +1 -0
- package/lib/utils/useControlNativeDialogOpenState.js +20 -0
- package/lib/utils/useControlNativeDialogOpenState.js.map +1 -0
- package/lib/utils/useDisableBodyScroll.js +60 -0
- package/lib/utils/useDisableBodyScroll.js.map +1 -0
- package/lib/utils/useFocusFirstElement.js +41 -0
- package/lib/utils/useFocusFirstElement.js.map +1 -0
- package/lib-commonjs/components/Dialog/Dialog.js +0 -3
- package/lib-commonjs/components/Dialog/Dialog.js.map +1 -1
- package/lib-commonjs/components/Dialog/index.js +0 -2
- package/lib-commonjs/components/Dialog/index.js.map +1 -1
- package/lib-commonjs/components/Dialog/renderDialog.js +2 -12
- package/lib-commonjs/components/Dialog/renderDialog.js.map +1 -1
- package/lib-commonjs/components/Dialog/useDialog.js +18 -128
- package/lib-commonjs/components/Dialog/useDialog.js.map +1 -1
- package/lib-commonjs/components/Dialog/useDialogContextValues.js +4 -4
- package/lib-commonjs/components/Dialog/useDialogContextValues.js.map +1 -1
- package/lib-commonjs/components/DialogActions/useDialogActionsStyles.js +3 -6
- package/lib-commonjs/components/DialogActions/useDialogActionsStyles.js.map +1 -1
- package/lib-commonjs/components/DialogBody/useDialogBodyStyles.js +4 -5
- package/lib-commonjs/components/DialogBody/useDialogBodyStyles.js.map +1 -1
- package/lib-commonjs/components/DialogSurface/renderDialogSurface.js +5 -2
- package/lib-commonjs/components/DialogSurface/renderDialogSurface.js.map +1 -1
- package/lib-commonjs/components/DialogSurface/useDialogSurface.js +120 -21
- package/lib-commonjs/components/DialogSurface/useDialogSurface.js.map +1 -1
- package/lib-commonjs/components/DialogSurface/useDialogSurfaceStyles.js +56 -6
- package/lib-commonjs/components/DialogSurface/useDialogSurfaceStyles.js.map +1 -1
- package/lib-commonjs/components/DialogTitle/DialogTitle.js +2 -3
- package/lib-commonjs/components/DialogTitle/DialogTitle.js.map +1 -1
- package/lib-commonjs/components/DialogTitle/renderDialogTitle.js +2 -6
- package/lib-commonjs/components/DialogTitle/renderDialogTitle.js.map +1 -1
- package/lib-commonjs/components/DialogTitle/useDialogTitle.js +18 -10
- package/lib-commonjs/components/DialogTitle/useDialogTitle.js.map +1 -1
- package/lib-commonjs/components/DialogTitle/useDialogTitleStyles.js +62 -56
- package/lib-commonjs/components/DialogTitle/useDialogTitleStyles.js.map +1 -1
- package/lib-commonjs/components/DialogTrigger/useDialogTrigger.js +4 -24
- package/lib-commonjs/components/DialogTrigger/useDialogTrigger.js.map +1 -1
- package/lib-commonjs/contexts/constants.js +2 -2
- package/lib-commonjs/contexts/constants.js.map +1 -1
- package/lib-commonjs/contexts/dialogContext.js +2 -4
- package/lib-commonjs/contexts/dialogContext.js.map +1 -1
- package/lib-commonjs/index.js +1 -13
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/index.js +5 -3
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/isEscapeKeyDown.js +5 -4
- package/lib-commonjs/utils/isEscapeKeyDown.js.map +1 -1
- package/lib-commonjs/utils/isHTMLDialogElement.js +13 -0
- package/lib-commonjs/utils/isHTMLDialogElement.js.map +1 -0
- package/lib-commonjs/utils/useControlNativeDialogOpenState.js +31 -0
- package/lib-commonjs/utils/useControlNativeDialogOpenState.js.map +1 -0
- package/lib-commonjs/utils/useDisableBodyScroll.js +73 -0
- package/lib-commonjs/utils/useDisableBodyScroll.js.map +1 -0
- package/lib-commonjs/utils/useFocusFirstElement.js +54 -0
- package/lib-commonjs/utils/useFocusFirstElement.js.map +1 -0
- package/package.json +13 -13
- package/dist/tsdoc-metadata.json +0 -11
- package/lib/components/Dialog/useDialogStyles.js +0 -41
- package/lib/components/Dialog/useDialogStyles.js.map +0 -1
- package/lib/utils/isTargetDisabled.js +0 -14
- package/lib/utils/isTargetDisabled.js.map +0 -1
- package/lib/utils/localShorthands.js +0 -9
- package/lib/utils/localShorthands.js.map +0 -1
- package/lib/utils/normalizeDefaultPrevented.js +0 -11
- package/lib/utils/normalizeDefaultPrevented.js.map +0 -1
- package/lib-commonjs/components/Dialog/useDialogStyles.js +0 -53
- package/lib-commonjs/components/Dialog/useDialogStyles.js.map +0 -1
- package/lib-commonjs/utils/isTargetDisabled.js +0 -23
- package/lib-commonjs/utils/isTargetDisabled.js.map +0 -1
- package/lib-commonjs/utils/localShorthands.js +0 -18
- package/lib-commonjs/utils/localShorthands.js.map +0 -1
- package/lib-commonjs/utils/normalizeDefaultPrevented.js +0 -20
- package/lib-commonjs/utils/normalizeDefaultPrevented.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Dialog/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Dialog/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC","sourcesContent":["export * from './Dialog';\nexport * from './Dialog.types';\nexport * from './renderDialog';\nexport * from './useDialog';\n"]}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { getSlots } from '@fluentui/react-utilities';
|
|
3
|
-
import { Portal } from '@fluentui/react-portal';
|
|
4
2
|
import { DialogProvider, DialogSurfaceProvider } from '../../contexts';
|
|
5
3
|
/**
|
|
6
4
|
* Render the final JSX of Dialog
|
|
@@ -9,18 +7,12 @@ import { DialogProvider, DialogSurfaceProvider } from '../../contexts';
|
|
|
9
7
|
export const renderDialog_unstable = (state, contextValues) => {
|
|
10
8
|
const {
|
|
11
9
|
content,
|
|
12
|
-
trigger
|
|
13
|
-
open
|
|
10
|
+
trigger
|
|
14
11
|
} = state;
|
|
15
|
-
const {
|
|
16
|
-
slots,
|
|
17
|
-
slotProps
|
|
18
|
-
} = getSlots(state);
|
|
19
12
|
return /*#__PURE__*/React.createElement(DialogProvider, {
|
|
20
13
|
value: contextValues.dialog
|
|
21
14
|
}, /*#__PURE__*/React.createElement(DialogSurfaceProvider, {
|
|
22
15
|
value: contextValues.dialogSurface
|
|
23
|
-
}, trigger,
|
|
24
|
-
}), content)));
|
|
16
|
+
}, trigger, content));
|
|
25
17
|
};
|
|
26
18
|
//# sourceMappingURL=renderDialog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/Dialog/renderDialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,
|
|
1
|
+
{"version":3,"sources":["components/Dialog/renderDialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,cAAT,EAAyB,qBAAzB,QAAsD,gBAAtD;AAGA;;AAEG;;AACH,OAAO,MAAM,qBAAqB,GAAG,CAAC,KAAD,EAAqB,aAArB,KAA2D;EAC9F,MAAM;IAAE,OAAF;IAAW;EAAX,IAAuB,KAA7B;EAEA,oBACE,KAAA,CAAA,aAAA,CAAC,cAAD,EAAe;IAAC,KAAK,EAAE,aAAa,CAAC;EAAtB,CAAf,eACE,KAAA,CAAA,aAAA,CAAC,qBAAD,EAAsB;IAAC,KAAK,EAAE,aAAa,CAAC;EAAtB,CAAtB,EACG,OADH,EAEG,OAFH,CADF,CADF;AAQD,CAXM","sourcesContent":["import * as React from 'react';\nimport { DialogProvider, DialogSurfaceProvider } from '../../contexts';\nimport type { DialogState, 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 } = state;\n\n return (\n <DialogProvider value={contextValues.dialog}>\n <DialogSurfaceProvider value={contextValues.dialogSurface}>\n {trigger}\n {content}\n </DialogSurfaceProvider>\n </DialogProvider>\n );\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { useControllableState, useEventCallback, useId, useIsomorphicLayoutEffect, useMergedRefs } from '@fluentui/react-utilities';
|
|
3
|
+
import { useHasParentContext } from '@fluentui/react-context-selector';
|
|
4
|
+
import { useControlNativeDialogOpenState, useDisableBodyScroll, useFocusFirstElement } from '../../utils';
|
|
5
|
+
import { DialogContext } from '../../contexts';
|
|
6
6
|
/**
|
|
7
7
|
* Create the state required to render Dialog.
|
|
8
8
|
*
|
|
@@ -15,7 +15,6 @@ import { normalizeDefaultPrevented, isEscapeKeyDismiss } from '../../utils';
|
|
|
15
15
|
export const useDialog_unstable = props => {
|
|
16
16
|
const {
|
|
17
17
|
children,
|
|
18
|
-
overlay,
|
|
19
18
|
modalType = 'modal',
|
|
20
19
|
onOpenChange
|
|
21
20
|
} = props;
|
|
@@ -25,63 +24,36 @@ export const useDialog_unstable = props => {
|
|
|
25
24
|
defaultState: props.defaultOpen,
|
|
26
25
|
initialState: false
|
|
27
26
|
});
|
|
28
|
-
const overlayShorthand = resolveShorthand(overlay, {
|
|
29
|
-
required: modalType !== 'non-modal',
|
|
30
|
-
defaultProps: {
|
|
31
|
-
'aria-hidden': 'true'
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
27
|
const requestOpenChange = useEventCallback(data => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (onOpenChange) {
|
|
38
|
-
onOpenChange(data.event, data);
|
|
39
|
-
} // if user prevents default then do not change state value
|
|
28
|
+
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(data.event, data); // if user prevents default then do not change state value
|
|
40
29
|
// otherwise updates state value and trigger reference to the element that caused the opening
|
|
41
30
|
|
|
42
|
-
|
|
43
|
-
if (!isDefaultPrevented()) {
|
|
44
|
-
triggerRef.current = !open && data.open ? data.event.currentTarget : null;
|
|
31
|
+
if (!data.event.isDefaultPrevented()) {
|
|
45
32
|
setOpen(data.open);
|
|
46
33
|
}
|
|
47
34
|
});
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
const handleOverLayClick = useEventCallback(event => {
|
|
57
|
-
var _a;
|
|
58
|
-
|
|
59
|
-
(_a = overlayShorthand === null || overlayShorthand === void 0 ? void 0 : overlayShorthand.onClick) === null || _a === void 0 ? void 0 : _a.call(overlayShorthand, event);
|
|
60
|
-
|
|
61
|
-
if (isOverlayClickDismiss(event, modalType)) {
|
|
62
|
-
requestOpenChange({
|
|
63
|
-
event,
|
|
64
|
-
open: false,
|
|
65
|
-
type: 'overlayClick'
|
|
66
|
-
});
|
|
35
|
+
const focusRef = useFocusFirstElement(open, modalType);
|
|
36
|
+
const nativeControlRef = useControlNativeDialogOpenState(open, modalType);
|
|
37
|
+
const disableBodyScroll = useDisableBodyScroll();
|
|
38
|
+
const isBodyScrollLocked = Boolean(open && modalType !== 'non-modal');
|
|
39
|
+
useIsomorphicLayoutEffect(() => {
|
|
40
|
+
if (isBodyScrollLocked) {
|
|
41
|
+
return disableBodyScroll();
|
|
67
42
|
}
|
|
68
|
-
});
|
|
43
|
+
}, [disableBodyScroll, isBodyScrollLocked]);
|
|
69
44
|
return {
|
|
70
45
|
components: {
|
|
71
|
-
|
|
72
|
-
},
|
|
73
|
-
overlay: overlayShorthand && { ...overlayShorthand,
|
|
74
|
-
onClick: handleOverLayClick
|
|
46
|
+
backdrop: 'div'
|
|
75
47
|
},
|
|
76
48
|
open,
|
|
77
49
|
modalType,
|
|
78
|
-
content,
|
|
50
|
+
content: open ? content : null,
|
|
79
51
|
trigger,
|
|
80
|
-
triggerRef,
|
|
81
|
-
contentRef,
|
|
82
52
|
requestOpenChange,
|
|
83
53
|
dialogBodyID: useId('dialog-body-'),
|
|
84
|
-
dialogTitleID: useId('dialog-title-')
|
|
54
|
+
dialogTitleID: useId('dialog-title-'),
|
|
55
|
+
isNestedDialog: useHasParentContext(DialogContext),
|
|
56
|
+
dialogRef: useMergedRefs(focusRef, nativeControlRef)
|
|
85
57
|
};
|
|
86
58
|
};
|
|
87
59
|
/**
|
|
@@ -112,86 +84,4 @@ function childrenToTriggerAndContent(children) {
|
|
|
112
84
|
return [undefined, undefined];
|
|
113
85
|
}
|
|
114
86
|
}
|
|
115
|
-
/**
|
|
116
|
-
* Checks is click event is a proper Overlay click dismiss
|
|
117
|
-
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
function isOverlayClickDismiss(event, type) {
|
|
121
|
-
const isDefaultPrevented = normalizeDefaultPrevented(event);
|
|
122
|
-
return type === 'modal' && !isDefaultPrevented();
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Focus first element on content when dialog is opened,
|
|
126
|
-
* in case there's no focusable element, then a eventlistener is added to document
|
|
127
|
-
* to ensure Escape keydown functionality
|
|
128
|
-
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
function useFocusFirstElement({
|
|
132
|
-
open,
|
|
133
|
-
requestOpenChange,
|
|
134
|
-
modalType
|
|
135
|
-
}) {
|
|
136
|
-
const {
|
|
137
|
-
findFirstFocusable
|
|
138
|
-
} = useFocusFinders();
|
|
139
|
-
const {
|
|
140
|
-
targetDocument
|
|
141
|
-
} = useFluent_unstable();
|
|
142
|
-
const contentRef = React.useRef(null);
|
|
143
|
-
const triggerRef = React.useRef(null);
|
|
144
|
-
React.useEffect(() => {
|
|
145
|
-
if (!open) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const element = contentRef.current && findFirstFocusable(contentRef.current);
|
|
150
|
-
|
|
151
|
-
if (element) {
|
|
152
|
-
element.focus(); // NOTE: if it's non-modal global listener to escape is necessary
|
|
153
|
-
|
|
154
|
-
if (modalType !== 'non-modal') {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
} else {
|
|
158
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
159
|
-
// eslint-disable-next-line no-console
|
|
160
|
-
console.warn('A Dialog should have at least one focusable element inside DialogSurface');
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (triggerRef.current && targetDocument) {
|
|
165
|
-
const trigger = triggerRef.current; // if the trigger is still the active element, the default behavior is to return focus to document.body,
|
|
166
|
-
// which can be achived by blurring
|
|
167
|
-
|
|
168
|
-
if (targetDocument.activeElement === trigger) {
|
|
169
|
-
trigger.blur();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const listener = event => {
|
|
173
|
-
if (isEscapeKeyDismiss(event, modalType)) {
|
|
174
|
-
requestOpenChange({
|
|
175
|
-
event,
|
|
176
|
-
open: false,
|
|
177
|
-
type: 'documentEscapeKeyDown'
|
|
178
|
-
});
|
|
179
|
-
trigger.focus();
|
|
180
|
-
event.stopImmediatePropagation();
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
targetDocument.addEventListener('keydown', listener, {
|
|
185
|
-
passive: false
|
|
186
|
-
});
|
|
187
|
-
return () => {
|
|
188
|
-
targetDocument.removeEventListener('keydown', listener);
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
}, [findFirstFocusable, requestOpenChange, open, modalType, targetDocument]);
|
|
192
|
-
return {
|
|
193
|
-
contentRef,
|
|
194
|
-
triggerRef
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
87
|
//# sourceMappingURL=useDialog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/Dialog/useDialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,
|
|
1
|
+
{"version":3,"sources":["components/Dialog/useDialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SACE,oBADF,EAEE,gBAFF,EAGE,KAHF,EAIE,yBAJF,EAKE,aALF,QAMO,2BANP;AAOA,SAAS,mBAAT,QAAoC,kCAApC;AACA,SAAS,+BAAT,EAA0C,oBAA1C,EAAgE,oBAAhE,QAA4F,aAA5F;AACA,SAAS,aAAT,QAA8B,gBAA9B;AAIA;;;;;;;AAOG;;AACH,OAAO,MAAM,kBAAkB,GAAI,KAAD,IAAoC;EACpE,MAAM;IAAE,QAAF;IAAY,SAAS,GAAG,OAAxB;IAAiC;EAAjC,IAAkD,KAAxD;EAEA,MAAM,CAAC,OAAD,EAAU,OAAV,IAAqB,2BAA2B,CAAC,QAAD,CAAtD;EAEA,MAAM,CAAC,IAAD,EAAO,OAAP,IAAkB,oBAAoB,CAAC;IAC3C,KAAK,EAAE,KAAK,CAAC,IAD8B;IAE3C,YAAY,EAAE,KAAK,CAAC,WAFuB;IAG3C,YAAY,EAAE;EAH6B,CAAD,CAA5C;EAMA,MAAM,iBAAiB,GAAG,gBAAgB,CAAE,IAAD,IAA+B;IACxE,YAAY,KAAA,IAAZ,IAAA,YAAY,KAAA,KAAA,CAAZ,GAAY,KAAA,CAAZ,GAAA,YAAY,CAAG,IAAI,CAAC,KAAR,EAAe,IAAf,CAAZ,CADwE,CAGxE;IACA;;IACA,IAAI,CAAC,IAAI,CAAC,KAAL,CAAW,kBAAX,EAAL,EAAsC;MACpC,OAAO,CAAC,IAAI,CAAC,IAAN,CAAP;IACD;EACF,CARyC,CAA1C;EAUA,MAAM,QAAQ,GAAG,oBAAoB,CAAC,IAAD,EAAO,SAAP,CAArC;EACA,MAAM,gBAAgB,GAAG,+BAA+B,CAAC,IAAD,EAAO,SAAP,CAAxD;EACA,MAAM,iBAAiB,GAAG,oBAAoB,EAA9C;EACA,MAAM,kBAAkB,GAAG,OAAO,CAAC,IAAI,IAAI,SAAS,KAAK,WAAvB,CAAlC;EAEA,yBAAyB,CAAC,MAAK;IAC7B,IAAI,kBAAJ,EAAwB;MACtB,OAAO,iBAAiB,EAAxB;IACD;EACF,CAJwB,EAItB,CAAC,iBAAD,EAAoB,kBAApB,CAJsB,CAAzB;EAMA,OAAO;IACL,UAAU,EAAE;MACV,QAAQ,EAAE;IADA,CADP;IAIL,IAJK;IAKL,SALK;IAML,OAAO,EAAE,IAAI,GAAG,OAAH,GAAa,IANrB;IAOL,OAPK;IAQL,iBARK;IASL,YAAY,EAAE,KAAK,CAAC,cAAD,CATd;IAUL,aAAa,EAAE,KAAK,CAAC,eAAD,CAVf;IAWL,cAAc,EAAE,mBAAmB,CAAC,aAAD,CAX9B;IAYL,SAAS,EAAE,aAAa,CAAC,QAAD,EAAW,gBAAX;EAZnB,CAAP;AAcD,CA9CM;AAgDP;;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","sourcesContent":["import * as React from 'react';\nimport {\n useControllableState,\n useEventCallback,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport { useHasParentContext } from '@fluentui/react-context-selector';\nimport { useControlNativeDialogOpenState, useDisableBodyScroll, useFocusFirstElement } from '../../utils';\nimport { DialogContext } from '../../contexts';\n\nimport type { DialogOpenChangeData, DialogProps, DialogState } 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, 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 requestOpenChange = useEventCallback((data: DialogOpenChangeData) => {\n onOpenChange?.(data.event, data);\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 (!data.event.isDefaultPrevented()) {\n setOpen(data.open);\n }\n });\n\n const focusRef = useFocusFirstElement(open, modalType);\n const nativeControlRef = useControlNativeDialogOpenState(open, modalType);\n const disableBodyScroll = useDisableBodyScroll();\n const isBodyScrollLocked = Boolean(open && modalType !== 'non-modal');\n\n useIsomorphicLayoutEffect(() => {\n if (isBodyScrollLocked) {\n return disableBodyScroll();\n }\n }, [disableBodyScroll, isBodyScrollLocked]);\n\n return {\n components: {\n backdrop: 'div',\n },\n open,\n modalType,\n content: open ? content : null,\n trigger,\n requestOpenChange,\n dialogBodyID: useId('dialog-body-'),\n dialogTitleID: useId('dialog-title-'),\n isNestedDialog: useHasParentContext(DialogContext),\n dialogRef: useMergedRefs(focusRef, nativeControlRef),\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"],"sourceRoot":"../src/"}
|
|
@@ -2,10 +2,10 @@ export function useDialogContextValues_unstable(state) {
|
|
|
2
2
|
const {
|
|
3
3
|
modalType,
|
|
4
4
|
open,
|
|
5
|
-
triggerRef,
|
|
6
|
-
contentRef,
|
|
7
5
|
dialogBodyID,
|
|
6
|
+
dialogRef,
|
|
8
7
|
dialogTitleID,
|
|
8
|
+
isNestedDialog,
|
|
9
9
|
requestOpenChange
|
|
10
10
|
} = state;
|
|
11
11
|
/**
|
|
@@ -16,10 +16,10 @@ export function useDialogContextValues_unstable(state) {
|
|
|
16
16
|
const dialog = {
|
|
17
17
|
open,
|
|
18
18
|
modalType,
|
|
19
|
-
|
|
20
|
-
contentRef,
|
|
19
|
+
dialogRef,
|
|
21
20
|
dialogBodyID,
|
|
22
21
|
dialogTitleID,
|
|
22
|
+
isNestedDialog,
|
|
23
23
|
requestOpenChange
|
|
24
24
|
};
|
|
25
25
|
const dialogSurface = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/Dialog/useDialogContextValues.ts"],"names":[],"mappings":"AAGA,OAAM,SAAU,+BAAV,CAA0C,KAA1C,EAA4D;EAChE,MAAM;IAAE,SAAF;IAAa,IAAb;IAAmB,
|
|
1
|
+
{"version":3,"sources":["components/Dialog/useDialogContextValues.ts"],"names":[],"mappings":"AAGA,OAAM,SAAU,+BAAV,CAA0C,KAA1C,EAA4D;EAChE,MAAM;IAAE,SAAF;IAAa,IAAb;IAAmB,YAAnB;IAAiC,SAAjC;IAA4C,aAA5C;IAA2D,cAA3D;IAA2E;EAA3E,IAAiG,KAAvG;EAEA;;;AAGG;;EACH,MAAM,MAAM,GAAuB;IACjC,IADiC;IAEjC,SAFiC;IAGjC,SAHiC;IAIjC,YAJiC;IAKjC,aALiC;IAMjC,cANiC;IAOjC;EAPiC,CAAnC;EAUA,MAAM,aAAa,GAA8B,KAAjD;EAEA,OAAO;IAAE,MAAF;IAAU;EAAV,CAAP;AACD","sourcesContent":["import type { DialogContextValue, DialogSurfaceContextValue } from '../../contexts';\nimport type { DialogContextValues, DialogState } from './Dialog.types';\n\nexport function useDialogContextValues_unstable(state: DialogState): DialogContextValues {\n const { modalType, open, dialogBodyID, dialogRef, dialogTitleID, isNestedDialog, requestOpenChange } = state;\n\n /**\n * This context is created with \"@fluentui/react-context-selector\",\n * there is no sense to memoize it\n */\n const dialog: DialogContextValue = {\n open,\n modalType,\n dialogRef,\n dialogBodyID,\n dialogTitleID,\n isNestedDialog,\n requestOpenChange,\n };\n\n const dialogSurface: DialogSurfaceContextValue = false;\n\n return { dialog, dialogSurface };\n}\n"],"sourceRoot":"../src/"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { __styles, mergeClasses, shorthands } from '@griffel/react';
|
|
2
2
|
import { DIALOG_GAP, ACTIONS_END_GRID_AREA, ACTIONS_START_GRID_AREA, MEDIA_QUERY_BREAKPOINT_SELECTOR } from '../../contexts/constants';
|
|
3
|
-
import * as localShorthands from '../../utils/localShorthands';
|
|
4
3
|
export const dialogActionsClassNames = {
|
|
5
4
|
root: 'fui-DialogActions'
|
|
6
5
|
};
|
|
@@ -12,26 +11,25 @@ const useStyles = /*#__PURE__*/__styles({
|
|
|
12
11
|
"mc9l5x": "f22iagw",
|
|
13
12
|
"i8kkvl": "f4px1ci",
|
|
14
13
|
"Belr9w4": "fn67r4l",
|
|
15
|
-
"Bnr8eeb": "f12ep7o",
|
|
16
14
|
"Bmdcpmo": "f6glcwc",
|
|
17
15
|
"th9wkt": "f1e3st1r"
|
|
18
16
|
},
|
|
19
17
|
"gridPositionEnd": {
|
|
20
18
|
"Bdqf98w": "f1a7i8kp",
|
|
21
19
|
"Ijaq50": "f11u0jfc",
|
|
22
|
-
"nk6f5a": "f23awfp",
|
|
23
20
|
"Br312pm": "f1d6tb1o",
|
|
21
|
+
"nk6f5a": "f23awfp",
|
|
24
22
|
"Bw0ie65": "fiappcv"
|
|
25
23
|
},
|
|
26
24
|
"gridPositionStart": {
|
|
27
25
|
"Bdqf98w": "fsxvdwy",
|
|
28
26
|
"Ijaq50": "f1vnb230",
|
|
29
|
-
"nk6f5a": "f13d374e",
|
|
30
27
|
"Br312pm": "f14781pt",
|
|
28
|
+
"nk6f5a": "f13d374e",
|
|
31
29
|
"Bw0ie65": "f1fjo411"
|
|
32
30
|
}
|
|
33
31
|
}, {
|
|
34
|
-
"d": [".f3052tw{height:-webkit-fit-content;height:-moz-fit-content;height:fit-content;}", ".f1ewtqcl{box-sizing:border-box;}", ".f22iagw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", ".f4px1ci{-webkit-column-gap:8px;column-gap:8px;}", ".fn67r4l{row-gap:8px;}", ".
|
|
32
|
+
"d": [".f3052tw{height:-webkit-fit-content;height:-moz-fit-content;height:fit-content;}", ".f1ewtqcl{box-sizing:border-box;}", ".f22iagw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", ".f4px1ci{-webkit-column-gap:8px;column-gap:8px;}", ".fn67r4l{row-gap:8px;}", ".f1a7i8kp{justify-self:end;}", ".f11u0jfc{grid-row-start:actions-end;}", ".f1d6tb1o{grid-column-start:actions-end;}", ".f23awfp{grid-row-end:actions-end;}", ".fiappcv{grid-column-end:actions-end;}", ".fsxvdwy{justify-self:start;}", ".f1vnb230{grid-row-start:actions-start;}", ".f14781pt{grid-column-start:actions-start;}", ".f13d374e{grid-row-end:actions-start;}", ".f1fjo411{grid-column-end:actions-start;}"],
|
|
35
33
|
"m": [["@media screen and (max-width: 480px){.f6glcwc{-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}}", {
|
|
36
34
|
"m": "screen and (max-width: 480px)"
|
|
37
35
|
}], ["@media screen and (max-width: 480px){.f1e3st1r{justify-self:stretch;}}", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/DialogActions/useDialogActionsStyles.ts"],"names":[],"mappings":"AAAA,mBAAqB,YAArB,EAAmC,UAAnC,QAAqD,gBAArD;AAGA,SACE,UADF,EAEE,qBAFF,EAGE,uBAHF,EAIE,+BAJF,QAKO,0BALP;
|
|
1
|
+
{"version":3,"sources":["components/DialogActions/useDialogActionsStyles.ts"],"names":[],"mappings":"AAAA,mBAAqB,YAArB,EAAmC,UAAnC,QAAqD,gBAArD;AAGA,SACE,UADF,EAEE,qBAFF,EAGE,uBAHF,EAIE,+BAJF,QAKO,0BALP;AAOA,OAAO,MAAM,uBAAuB,GAAuC;EACzE,IAAI,EAAE;AADmE,CAApE;;AAIP,MAAM,SAAS,gBAAG;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;AAAA;EAAA;EAAA;IAAA;EAAA;IAAA;EAAA;AAAA,EAAlB;AAqBA;;AAEG;;;AACH,OAAO,MAAM,+BAA+B,GAAI,KAAD,IAAkD;EAC/F,MAAM,MAAM,GAAG,SAAS,EAAxB;EACA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,YAAY,CACjC,uBAAuB,CAAC,IADS,EAEjC,MAAM,CAAC,IAF0B,EAGjC,KAAK,CAAC,QAAN,KAAmB,OAAnB,IAA8B,MAAM,CAAC,iBAHJ,EAIjC,KAAK,CAAC,QAAN,KAAmB,KAAnB,IAA4B,MAAM,CAAC,eAJF,EAKjC,KAAK,CAAC,IAAN,CAAW,SALsB,CAAnC;EAOA,OAAO,KAAP;AACD,CAVM","sourcesContent":["import { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport type { DialogActionsSlots, DialogActionsState } from './DialogActions.types';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\nimport {\n DIALOG_GAP,\n ACTIONS_END_GRID_AREA,\n ACTIONS_START_GRID_AREA,\n MEDIA_QUERY_BREAKPOINT_SELECTOR,\n} from '../../contexts/constants';\n\nexport const dialogActionsClassNames: SlotClassNames<DialogActionsSlots> = {\n root: 'fui-DialogActions',\n};\n\nconst useStyles = makeStyles({\n root: {\n height: 'fit-content',\n boxSizing: 'border-box',\n display: 'flex',\n ...shorthands.gap(DIALOG_GAP),\n [MEDIA_QUERY_BREAKPOINT_SELECTOR]: {\n flexDirection: 'column',\n justifySelf: 'stretch',\n },\n },\n gridPositionEnd: {\n justifySelf: 'end',\n ...shorthands.gridArea(ACTIONS_END_GRID_AREA),\n },\n gridPositionStart: {\n justifySelf: 'start',\n ...shorthands.gridArea(ACTIONS_START_GRID_AREA),\n },\n});\n\n/**\n * Apply styling to the DialogActions slots based on the state\n */\nexport const useDialogActionsStyles_unstable = (state: DialogActionsState): DialogActionsState => {\n const styles = useStyles();\n state.root.className = mergeClasses(\n dialogActionsClassNames.root,\n styles.root,\n state.position === 'start' && styles.gridPositionStart,\n state.position === 'end' && styles.gridPositionEnd,\n state.root.className,\n );\n return state;\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { __styles, mergeClasses } from '@griffel/react';
|
|
1
|
+
import { __styles, mergeClasses, shorthands } from '@griffel/react';
|
|
2
2
|
import { typographyStyles } from '@fluentui/react-theme';
|
|
3
|
-
import * as localShorthands from '../../utils/localShorthands';
|
|
4
3
|
import { BODY_GRID_AREA } from '../../contexts/constants';
|
|
5
4
|
export const dialogBodyClassNames = {
|
|
6
5
|
root: 'fui-DialogBody'
|
|
@@ -12,12 +11,13 @@ export const dialogBodyClassNames = {
|
|
|
12
11
|
const useStyles = /*#__PURE__*/__styles({
|
|
13
12
|
"root": {
|
|
14
13
|
"a9b677": "fly5x3f",
|
|
15
|
-
"Bqenvij": "
|
|
14
|
+
"Bqenvij": "f1l02sjl",
|
|
15
|
+
"Bmxbyg5": "f5zp4f",
|
|
16
16
|
"sshi5w": "f1nxs5xn",
|
|
17
17
|
"B7ck84d": "f1ewtqcl",
|
|
18
18
|
"Ijaq50": "f6owso0",
|
|
19
|
-
"nk6f5a": "foucsne",
|
|
20
19
|
"Br312pm": "fupswjn",
|
|
20
|
+
"nk6f5a": "foucsne",
|
|
21
21
|
"Bw0ie65": "f1ka72gx",
|
|
22
22
|
"Bahqtrf": "fk6fouc",
|
|
23
23
|
"Be2twd7": "fkhj508",
|
|
@@ -25,7 +25,7 @@ const useStyles = /*#__PURE__*/__styles({
|
|
|
25
25
|
"Bg96gwp": "f1i3iumi"
|
|
26
26
|
}
|
|
27
27
|
}, {
|
|
28
|
-
"d": [".fly5x3f{width:100%;}", ".
|
|
28
|
+
"d": [".fly5x3f{width:100%;}", ".f1l02sjl{height:100%;}", ".f5zp4f{overflow-y:auto;}", ".f1nxs5xn{min-height:32px;}", ".f1ewtqcl{box-sizing:border-box;}", ".f6owso0{grid-row-start:body;}", ".fupswjn{grid-column-start:body;}", ".foucsne{grid-row-end:body;}", ".f1ka72gx{grid-column-end:body;}", ".fk6fouc{font-family:var(--fontFamilyBase);}", ".fkhj508{font-size:var(--fontSizeBase300);}", ".figsok6{font-weight:var(--fontWeightRegular);}", ".f1i3iumi{line-height:var(--lineHeightBase300);}"]
|
|
29
29
|
});
|
|
30
30
|
/**
|
|
31
31
|
* Apply styling to the DialogBody slots based on the state
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/DialogBody/useDialogBodyStyles.ts"],"names":[],"mappings":"AAAA,mBAAqB,YAArB,
|
|
1
|
+
{"version":3,"sources":["components/DialogBody/useDialogBodyStyles.ts"],"names":[],"mappings":"AAAA,mBAAqB,YAArB,EAAmC,UAAnC,QAAqD,gBAArD;AAGA,SAAS,gBAAT,QAAiC,uBAAjC;AACA,SAAS,cAAT,QAA+B,0BAA/B;AAEA,OAAO,MAAM,oBAAoB,GAAoC;EACnE,IAAI,EAAE;AAD6D,CAA9D;AAIP;;AAEG;;AACH,MAAM,SAAS,gBAAG;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;AAAA;EAAA;AAAA,EAAlB;AAYA;;AAEG;;;AACH,OAAO,MAAM,4BAA4B,GAAI,KAAD,IAA4C;EACtF,MAAM,MAAM,GAAG,SAAS,EAAxB;EACA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,YAAY,CAAC,oBAAoB,CAAC,IAAtB,EAA4B,MAAM,CAAC,IAAnC,EAAyC,KAAK,CAAC,IAAN,CAAW,SAApD,CAAnC,CAFsF,CAItF;EACA;;EAEA,OAAO,KAAP;AACD,CARM","sourcesContent":["import { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport type { DialogBodySlots, DialogBodyState } from './DialogBody.types';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\nimport { typographyStyles } from '@fluentui/react-theme';\nimport { BODY_GRID_AREA } from '../../contexts/constants';\n\nexport const dialogBodyClassNames: SlotClassNames<DialogBodySlots> = {\n root: 'fui-DialogBody',\n};\n\n/**\n * Styles for the root slot\n */\nconst useStyles = makeStyles({\n root: {\n width: '100%',\n height: '100%',\n overflowY: 'auto',\n minHeight: '32px',\n boxSizing: 'border-box',\n ...shorthands.gridArea(BODY_GRID_AREA),\n ...typographyStyles.body1,\n },\n});\n\n/**\n * Apply styling to the DialogBody slots based on the state\n */\nexport const useDialogBodyStyles_unstable = (state: DialogBodyState): DialogBodyState => {\n const styles = useStyles();\n state.root.className = mergeClasses(dialogBodyClassNames.root, styles.root, state.root.className);\n\n // TODO Add class names to slots, for example:\n // state.mySlot.className = mergeClasses(styles.mySlot, state.mySlot.className);\n\n return state;\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DialogSurface.types.js","sourceRoot":"../src/","sources":["components/DialogSurface/DialogSurface.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport { DialogSurfaceContextValue } from '../../contexts';\n\nexport type DialogSurfaceSlots = {\n root: Slot<'
|
|
1
|
+
{"version":3,"file":"DialogSurface.types.js","sourceRoot":"../src/","sources":["components/DialogSurface/DialogSurface.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport { DialogSurfaceContextValue } from '../../contexts';\n\nexport type DialogSurfaceSlots = {\n /**\n * Dimmed background of dialog.\n * The default backdrop is rendered as a `<div>` with styling.\n * This slot expects a `<div>` element which will replace the default backdrop.\n * The backdrop should have `aria-hidden=\"true\"`.\n *\n * By default if `DialogSurface` is `<dialog>` element the backdrop is ignored,\n * since native `<dialog>` element supports [::backdrop](https://developer.mozilla.org/en-US/docs/Web/CSS/::backdrop)\n */\n backdrop?: Slot<'div'>;\n root: NonNullable<Slot<'dialog', 'div'>>;\n};\n\n/** @internal */\nexport type DialogSurfaceElement = HTMLDialogElement | HTMLDivElement;\n\n/** @internal */\nexport type DialogSurfaceElementIntersection = HTMLDialogElement & HTMLDivElement;\n\n/**\n * DialogSurface Props\n *\n * Omits basic types from native `dialog` (`open`, `onCancel` and `onClose`)\n * to ensure `onOpenChange`, `open` and `defaultOpen` from `Dialog` is used instead\n */\nexport type DialogSurfaceProps = Omit<ComponentProps<DialogSurfaceSlots>, 'open' | 'onCancel' | 'onClose'>;\n\nexport type DialogSurfaceContextValues = {\n dialogSurface: DialogSurfaceContextValue;\n};\n\n/**\n * State used in rendering DialogSurface\n */\nexport type DialogSurfaceState = ComponentState<DialogSurfaceSlots>;\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { getSlots } from '@fluentui/react-utilities';
|
|
3
3
|
import { DialogSurfaceProvider } from '../../contexts';
|
|
4
|
+
import { Portal } from '@fluentui/react-portal';
|
|
4
5
|
/**
|
|
5
6
|
* Render the final JSX of DialogSurface
|
|
6
7
|
*/
|
|
@@ -10,9 +11,10 @@ export const renderDialogSurface_unstable = (state, contextValues) => {
|
|
|
10
11
|
slots,
|
|
11
12
|
slotProps
|
|
12
13
|
} = getSlots(state);
|
|
13
|
-
return /*#__PURE__*/React.createElement(
|
|
14
|
+
return /*#__PURE__*/React.createElement(Portal, null, slots.backdrop && /*#__PURE__*/React.createElement(slots.backdrop, { ...slotProps.backdrop
|
|
15
|
+
}), /*#__PURE__*/React.createElement(DialogSurfaceProvider, {
|
|
14
16
|
value: contextValues.dialogSurface
|
|
15
17
|
}, /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
|
|
16
|
-
}));
|
|
18
|
+
})));
|
|
17
19
|
};
|
|
18
20
|
//# sourceMappingURL=renderDialogSurface.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/DialogSurface/renderDialogSurface.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAEA,SAAS,qBAAT,QAAsC,gBAAtC;AAEA;;AAEG;;AACH,OAAO,MAAM,4BAA4B,GAAG,CAAC,KAAD,EAA4B,aAA5B,KAAyE;EACnH,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,QAAQ,CAAqB,KAArB,CAArC;EAEA,oBACE,KAAA,CAAA,aAAA,CAAC,qBAAD,EAAsB;IAAC,KAAK,EAAE,aAAa,CAAC;EAAtB,CAAtB,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,CADF,CADF;
|
|
1
|
+
{"version":3,"sources":["components/DialogSurface/renderDialogSurface.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAEA,SAAS,qBAAT,QAAsC,gBAAtC;AACA,SAAS,MAAT,QAAuB,wBAAvB;AAEA;;AAEG;;AACH,OAAO,MAAM,4BAA4B,GAAG,CAAC,KAAD,EAA4B,aAA5B,KAAyE;EACnH,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,QAAQ,CAAqB,KAArB,CAArC;EAEA,oBACE,KAAA,CAAA,aAAA,CAAC,MAAD,EAAO,IAAP,EACG,KAAK,CAAC,QAAN,iBAAkB,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,QAAP,EAAe,EAAA,GAAK,SAAS,CAAC;EAAf,CAAf,CADrB,eAEE,KAAA,CAAA,aAAA,CAAC,qBAAD,EAAsB;IAAC,KAAK,EAAE,aAAa,CAAC;EAAtB,CAAtB,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,CADF,CAFF,CADF;AAQD,CAXM","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { DialogSurfaceState, DialogSurfaceSlots, DialogSurfaceContextValues } from './DialogSurface.types';\nimport { DialogSurfaceProvider } from '../../contexts';\nimport { Portal } from '@fluentui/react-portal';\n\n/**\n * Render the final JSX of DialogSurface\n */\nexport const renderDialogSurface_unstable = (state: DialogSurfaceState, contextValues: DialogSurfaceContextValues) => {\n const { slots, slotProps } = getSlots<DialogSurfaceSlots>(state);\n\n return (\n <Portal>\n {slots.backdrop && <slots.backdrop {...slotProps.backdrop} />}\n <DialogSurfaceProvider value={contextValues.dialogSurface}>\n <slots.root {...slotProps.root} />\n </DialogSurfaceProvider>\n </Portal>\n );\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getNativeElementProps, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';
|
|
2
|
-
import { useModalAttributes } from '@fluentui/react-tabster';
|
|
1
|
+
import { getNativeElementProps, resolveShorthand, useEventCallback, useMergedRefs, isResolvedShorthand } from '@fluentui/react-utilities';
|
|
3
2
|
import { useDialogContext_unstable } from '../../contexts';
|
|
4
3
|
import { isEscapeKeyDismiss } from '../../utils';
|
|
4
|
+
import { useModalAttributes } from '@fluentui/react-tabster';
|
|
5
5
|
/**
|
|
6
6
|
* Create the state required to render DialogSurface.
|
|
7
7
|
*
|
|
@@ -13,20 +13,98 @@ import { isEscapeKeyDismiss } from '../../utils';
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
export const useDialogSurface_unstable = (props, ref) => {
|
|
16
|
-
const modalType = useDialogContext_unstable(ctx => ctx.modalType);
|
|
17
16
|
const {
|
|
18
|
-
|
|
17
|
+
backdrop,
|
|
18
|
+
as
|
|
19
19
|
} = props;
|
|
20
|
-
const
|
|
20
|
+
const isNativeDialog = as === 'dialog' || as === undefined;
|
|
21
|
+
const modalType = useDialogContext_unstable(ctx => ctx.modalType);
|
|
22
|
+
const dialogRef = useDialogContext_unstable(ctx => ctx.dialogRef);
|
|
23
|
+
const open = useDialogContext_unstable(ctx => ctx.open);
|
|
24
|
+
const requestOpenChange = useDialogContext_unstable(ctx => ctx.requestOpenChange);
|
|
21
25
|
const dialogTitleID = useDialogContext_unstable(ctx => ctx.dialogTitleID);
|
|
22
26
|
const dialogBodyID = useDialogContext_unstable(ctx => ctx.dialogBodyID);
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
const handleNativeClick = useEventCallback(event => {
|
|
28
|
+
var _a;
|
|
29
|
+
|
|
30
|
+
(_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
31
|
+
|
|
32
|
+
if (modalType === 'alert' || event.target !== event.currentTarget) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const {
|
|
37
|
+
clientX,
|
|
38
|
+
clientY
|
|
39
|
+
} = event;
|
|
40
|
+
const {
|
|
41
|
+
top,
|
|
42
|
+
left,
|
|
43
|
+
width,
|
|
44
|
+
height
|
|
45
|
+
} = event.currentTarget.getBoundingClientRect();
|
|
46
|
+
const isBackdropClick = top > clientY || clientY > top + height || left > clientX || clientX > left + width;
|
|
47
|
+
|
|
48
|
+
if (isBackdropClick) {
|
|
49
|
+
requestOpenChange({
|
|
50
|
+
event,
|
|
51
|
+
open: false,
|
|
52
|
+
type: 'backdropClick'
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
const handleNativeCancel = useEventCallback(event => {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
|
|
59
|
+
(_b = (_a = props).onCancel) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
60
|
+
|
|
61
|
+
if (event.currentTarget !== event.target) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (modalType !== 'alert') {
|
|
66
|
+
requestOpenChange({
|
|
67
|
+
event,
|
|
68
|
+
open: false,
|
|
69
|
+
type: 'dialogCancel'
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
});
|
|
75
|
+
const handleNativeClose = useEventCallback(event => {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
|
|
78
|
+
(_b = (_a = props).onClose) === null || _b === void 0 ? void 0 : _b.call(_a, event); // Ensure dialog remains open if force closed by close event
|
|
79
|
+
|
|
80
|
+
if (event.currentTarget.open !== open) {
|
|
81
|
+
if (open) {
|
|
82
|
+
if (modalType === 'non-modal') {
|
|
83
|
+
event.currentTarget.show();
|
|
84
|
+
} else {
|
|
85
|
+
event.currentTarget.showModal();
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
event.currentTarget.close();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const handledBackdropClick = useEventCallback(event => {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
|
|
95
|
+
if (isResolvedShorthand(props.backdrop)) {
|
|
96
|
+
(_b = (_a = props.backdrop).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (modalType === 'modal' && !event.isDefaultPrevented()) {
|
|
100
|
+
requestOpenChange({
|
|
101
|
+
event,
|
|
102
|
+
open: false,
|
|
103
|
+
type: 'backdropClick'
|
|
104
|
+
});
|
|
105
|
+
}
|
|
28
106
|
});
|
|
29
|
-
const
|
|
107
|
+
const handleKeyDown = useEventCallback(event => {
|
|
30
108
|
var _a;
|
|
31
109
|
|
|
32
110
|
(_a = props.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
@@ -36,23 +114,44 @@ export const useDialogSurface_unstable = (props, ref) => {
|
|
|
36
114
|
event,
|
|
37
115
|
open: false,
|
|
38
116
|
type: 'escapeKeyDown'
|
|
39
|
-
});
|
|
40
|
-
|
|
117
|
+
}); // stop propagation to avoid conflicting with other elements that listen for `Escape`
|
|
118
|
+
// e,g: nested Dialog, Popover, Menu and Tooltip
|
|
119
|
+
|
|
120
|
+
event.stopPropagation();
|
|
41
121
|
}
|
|
42
122
|
});
|
|
123
|
+
const {
|
|
124
|
+
modalAttributes
|
|
125
|
+
} = useModalAttributes({
|
|
126
|
+
trapFocus: modalType !== 'non-modal'
|
|
127
|
+
});
|
|
43
128
|
return {
|
|
44
129
|
components: {
|
|
45
|
-
|
|
130
|
+
backdrop: 'div',
|
|
131
|
+
root: 'dialog'
|
|
46
132
|
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
133
|
+
backdrop: resolveShorthand(backdrop, {
|
|
134
|
+
required: !isNativeDialog && open && modalType !== 'non-modal',
|
|
135
|
+
defaultProps: {
|
|
136
|
+
'aria-hidden': 'true',
|
|
137
|
+
onClick: handledBackdropClick
|
|
138
|
+
}
|
|
139
|
+
}),
|
|
140
|
+
root: getNativeElementProps(as !== null && as !== void 0 ? as : 'dialog', { ...(isNativeDialog ? {
|
|
141
|
+
role: modalType === 'alert' ? 'alertdialog' : undefined,
|
|
142
|
+
onClose: handleNativeClose,
|
|
143
|
+
onClick: handleNativeClick,
|
|
144
|
+
onCancel: handleNativeCancel
|
|
145
|
+
} : {
|
|
146
|
+
'aria-modal': modalType !== 'non-modal',
|
|
147
|
+
role: modalType === 'alert' ? 'alertdialog' : 'dialog'
|
|
148
|
+
}),
|
|
53
149
|
...props,
|
|
54
150
|
...modalAttributes,
|
|
55
|
-
onKeyDown:
|
|
151
|
+
onKeyDown: handleKeyDown,
|
|
152
|
+
'aria-describedby': dialogBodyID,
|
|
153
|
+
'aria-labelledby': props['aria-label'] ? undefined : dialogTitleID,
|
|
154
|
+
ref: useMergedRefs(ref, dialogRef)
|
|
56
155
|
})
|
|
57
156
|
};
|
|
58
157
|
};
|