@fluentui/react-dialog 9.0.0-beta.10
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 +527 -0
- package/CHANGELOG.md +199 -0
- package/LICENSE +15 -0
- package/README.md +5 -0
- package/Spec.md +537 -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 +451 -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/DialogContent.js +2 -0
- package/lib/DialogContent.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 +19 -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 +5 -0
- package/lib/components/Dialog/index.js.map +1 -0
- package/lib/components/Dialog/renderDialog.js +18 -0
- package/lib/components/Dialog/renderDialog.js.map +1 -0
- package/lib/components/Dialog/useDialog.js +87 -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/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 +49 -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 +50 -0
- package/lib/components/DialogBody/useDialogBodyStyles.js.map +1 -0
- package/lib/components/DialogContent/DialogContent.js +16 -0
- package/lib/components/DialogContent/DialogContent.js.map +1 -0
- package/lib/components/DialogContent/DialogContent.types.js +2 -0
- package/lib/components/DialogContent/DialogContent.types.js.map +1 -0
- package/lib/components/DialogContent/index.js +6 -0
- package/lib/components/DialogContent/index.js.map +1 -0
- package/lib/components/DialogContent/renderDialogContent.js +15 -0
- package/lib/components/DialogContent/renderDialogContent.js.map +1 -0
- package/lib/components/DialogContent/useDialogContent.js +28 -0
- package/lib/components/DialogContent/useDialogContent.js.map +1 -0
- package/lib/components/DialogContent/useDialogContentStyles.js +40 -0
- package/lib/components/DialogContent/useDialogContentStyles.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 +20 -0
- package/lib/components/DialogSurface/renderDialogSurface.js.map +1 -0
- package/lib/components/DialogSurface/useDialogSurface.js +158 -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 +95 -0
- package/lib/components/DialogSurface/useDialogSurfaceStyles.js.map +1 -0
- package/lib/components/DialogTitle/DialogTitle.js +16 -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 +16 -0
- package/lib/components/DialogTitle/renderDialogTitle.js.map +1 -0
- package/lib/components/DialogTitle/useDialogTitle.js +48 -0
- package/lib/components/DialogTitle/useDialogTitle.js.map +1 -0
- package/lib/components/DialogTitle/useDialogTitleStyles.js +116 -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 +48 -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 +19 -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 +8 -0
- package/lib/index.js.map +1 -0
- package/lib/utils/index.js +6 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/isEscapeKeyDown.js +12 -0
- package/lib/utils/isEscapeKeyDown.js.map +1 -0
- 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/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/DialogContent.js +10 -0
- package/lib-commonjs/DialogContent.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 +30 -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 +16 -0
- package/lib-commonjs/components/Dialog/index.js.map +1 -0
- package/lib-commonjs/components/Dialog/renderDialog.js +29 -0
- package/lib-commonjs/components/Dialog/renderDialog.js.map +1 -0
- package/lib-commonjs/components/Dialog/useDialog.js +101 -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/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 +60 -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 +35 -0
- package/lib-commonjs/components/DialogBody/useDialogBody.js.map +1 -0
- package/lib-commonjs/components/DialogBody/useDialogBodyStyles.js +61 -0
- package/lib-commonjs/components/DialogBody/useDialogBodyStyles.js.map +1 -0
- package/lib-commonjs/components/DialogContent/DialogContent.js +27 -0
- package/lib-commonjs/components/DialogContent/DialogContent.js.map +1 -0
- package/lib-commonjs/components/DialogContent/DialogContent.types.js +6 -0
- package/lib-commonjs/components/DialogContent/DialogContent.types.js.map +1 -0
- package/lib-commonjs/components/DialogContent/index.js +18 -0
- package/lib-commonjs/components/DialogContent/index.js.map +1 -0
- package/lib-commonjs/components/DialogContent/renderDialogContent.js +26 -0
- package/lib-commonjs/components/DialogContent/renderDialogContent.js.map +1 -0
- package/lib-commonjs/components/DialogContent/useDialogContent.js +39 -0
- package/lib-commonjs/components/DialogContent/useDialogContent.js.map +1 -0
- package/lib-commonjs/components/DialogContent/useDialogContentStyles.js +52 -0
- package/lib-commonjs/components/DialogContent/useDialogContentStyles.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 +33 -0
- package/lib-commonjs/components/DialogSurface/renderDialogSurface.js.map +1 -0
- package/lib-commonjs/components/DialogSurface/useDialogSurface.js +171 -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 +107 -0
- package/lib-commonjs/components/DialogSurface/useDialogSurfaceStyles.js.map +1 -0
- package/lib-commonjs/components/DialogTitle/DialogTitle.js +27 -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 +27 -0
- package/lib-commonjs/components/DialogTitle/renderDialogTitle.js.map +1 -0
- package/lib-commonjs/components/DialogTitle/useDialogTitle.js +64 -0
- package/lib-commonjs/components/DialogTitle/useDialogTitle.js.map +1 -0
- package/lib-commonjs/components/DialogTitle/useDialogTitleStyles.js +129 -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 +62 -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 +30 -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 +214 -0
- package/lib-commonjs/index.js.map +1 -0
- package/lib-commonjs/utils/index.js +18 -0
- package/lib-commonjs/utils/index.js.map +1 -0
- package/lib-commonjs/utils/isEscapeKeyDown.js +23 -0
- package/lib-commonjs/utils/isEscapeKeyDown.js.map +1 -0
- 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 +68 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
|
|
3
|
+
import { ARIAButtonResultProps } from '@fluentui/react-aria';
|
|
4
|
+
import { ARIAButtonType } from '@fluentui/react-aria';
|
|
5
|
+
import type { ComponentProps } from '@fluentui/react-utilities';
|
|
6
|
+
import type { ComponentState } from '@fluentui/react-utilities';
|
|
7
|
+
import type { FluentTriggerComponent } from '@fluentui/react-utilities';
|
|
8
|
+
import type { ForwardRefComponent } from '@fluentui/react-utilities';
|
|
9
|
+
import { JSXElementConstructor } from 'react';
|
|
10
|
+
import * as React_2 from 'react';
|
|
11
|
+
import { ReactElement } from 'react';
|
|
12
|
+
import type { Slot } from '@fluentui/react-utilities';
|
|
13
|
+
import type { SlotClassNames } from '@fluentui/react-utilities';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The `Dialog` root level component serves as an interface for interaction with all possible behaviors exposed.
|
|
17
|
+
* It provides context down the hierarchy to `children` compound components to allow functionality.
|
|
18
|
+
* This component expects to receive as children either a `DialogSurface` or a `DialogTrigger`
|
|
19
|
+
* and a `DialogSurface` (or some component that will eventually render one of those compound components)
|
|
20
|
+
* in this specific order
|
|
21
|
+
*/
|
|
22
|
+
export declare const Dialog: React_2.FC<DialogProps>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* `DialogActions` is a container for the actions of the dialog.
|
|
26
|
+
* Apart from styling, this component does not have other behavior.
|
|
27
|
+
*/
|
|
28
|
+
export declare const DialogActions: ForwardRefComponent<DialogActionsProps>;
|
|
29
|
+
|
|
30
|
+
export declare const dialogActionsClassNames: SlotClassNames<DialogActionsSlots>;
|
|
31
|
+
|
|
32
|
+
export declare type DialogActionsPosition = 'start' | 'end';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* DialogActions Props
|
|
36
|
+
*/
|
|
37
|
+
export declare type DialogActionsProps = ComponentProps<DialogActionsSlots> & {
|
|
38
|
+
/**
|
|
39
|
+
* defines the position on the dialog grid of the actions
|
|
40
|
+
* @default 'end'
|
|
41
|
+
*/
|
|
42
|
+
position?: DialogActionsPosition;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export declare type DialogActionsSlots = {
|
|
46
|
+
root: Slot<'div'>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* State used in rendering DialogActions
|
|
51
|
+
*/
|
|
52
|
+
export declare type DialogActionsState = ComponentState<DialogActionsSlots> & {
|
|
53
|
+
position: DialogActionsPosition;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The `DialogBody` is a container where the content of the dialog is rendered.
|
|
58
|
+
* Apart from styling, this component does not have other behavior.
|
|
59
|
+
*/
|
|
60
|
+
export declare const DialogBody: ForwardRefComponent<DialogBodyProps>;
|
|
61
|
+
|
|
62
|
+
export declare const dialogBodyClassNames: SlotClassNames<DialogBodySlots>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* DialogBody Props
|
|
66
|
+
*/
|
|
67
|
+
export declare type DialogBodyProps = ComponentProps<DialogBodySlots> & {};
|
|
68
|
+
|
|
69
|
+
export declare type DialogBodySlots = {
|
|
70
|
+
root: Slot<'div'>;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* State used in rendering DialogBody
|
|
75
|
+
*/
|
|
76
|
+
export declare type DialogBodyState = ComponentState<DialogBodySlots>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The `DialogContent` is a container where the content of the dialog is rendered.
|
|
80
|
+
* Apart from styling, this component does not have other behavior.
|
|
81
|
+
*/
|
|
82
|
+
export declare const DialogContent: ForwardRefComponent<DialogContentProps>;
|
|
83
|
+
|
|
84
|
+
export declare const dialogContentClassNames: SlotClassNames<DialogContentSlots>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* DialogContent Props
|
|
88
|
+
*/
|
|
89
|
+
export declare type DialogContentProps = ComponentProps<DialogContentSlots>;
|
|
90
|
+
|
|
91
|
+
export declare type DialogContentSlots = {
|
|
92
|
+
root: Slot<'div'>;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* State used in rendering DialogContent
|
|
97
|
+
*/
|
|
98
|
+
export declare type DialogContentState = ComponentState<DialogContentSlots>;
|
|
99
|
+
|
|
100
|
+
declare type DialogContextValue = {
|
|
101
|
+
open: boolean;
|
|
102
|
+
dialogContentId?: string;
|
|
103
|
+
dialogTitleId?: string;
|
|
104
|
+
isNestedDialog: boolean;
|
|
105
|
+
dialogRef: React_2.Ref<DialogSurfaceElement>;
|
|
106
|
+
modalType: DialogModalType;
|
|
107
|
+
/**
|
|
108
|
+
* Requests dialog main component to update it's internal open state
|
|
109
|
+
*/
|
|
110
|
+
requestOpenChange: (data: DialogOpenChangeData) => void;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
declare type DialogContextValues = {
|
|
114
|
+
dialog: DialogContextValue;
|
|
115
|
+
/**
|
|
116
|
+
* dialogSurface context is provided by Dialog as false
|
|
117
|
+
* to ensure components inside Dialog but outside DialogSurface will consume this as false
|
|
118
|
+
*/
|
|
119
|
+
dialogSurface: DialogSurfaceContextValue;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
declare type DialogModalType = 'modal' | 'non-modal' | 'alert';
|
|
123
|
+
|
|
124
|
+
export declare type DialogOpenChangeData = {
|
|
125
|
+
/**
|
|
126
|
+
* triggered when Escape key is pressed in a native `dialog`
|
|
127
|
+
*/
|
|
128
|
+
type: 'dialogCancel';
|
|
129
|
+
open: boolean;
|
|
130
|
+
event: React_2.SyntheticEvent<DialogSurfaceElement>;
|
|
131
|
+
} | {
|
|
132
|
+
type: 'escapeKeyDown';
|
|
133
|
+
open: boolean;
|
|
134
|
+
event: React_2.KeyboardEvent<DialogSurfaceElement>;
|
|
135
|
+
} | {
|
|
136
|
+
type: 'backdropClick';
|
|
137
|
+
open: boolean;
|
|
138
|
+
event: React_2.MouseEvent<DialogSurfaceElement>;
|
|
139
|
+
} | {
|
|
140
|
+
type: 'triggerClick';
|
|
141
|
+
open: boolean;
|
|
142
|
+
event: React_2.MouseEvent<DialogSurfaceElement>;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export declare type DialogOpenChangeEvent = DialogOpenChangeData['event'];
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Callback fired when the component changes value from open state.
|
|
149
|
+
*
|
|
150
|
+
* @param event - a React's Synthetic event or a KeyboardEvent in case of `documentEscapeKeyDown`
|
|
151
|
+
* @param data - A data object with relevant information, such as open value and type
|
|
152
|
+
*/
|
|
153
|
+
export declare type DialogOpenChangeEventHandler = (event: DialogOpenChangeEvent, data: DialogOpenChangeData) => void;
|
|
154
|
+
|
|
155
|
+
export declare type DialogProps = ComponentProps<Partial<DialogSlots>> & {
|
|
156
|
+
/**
|
|
157
|
+
* Dialog variations.
|
|
158
|
+
*
|
|
159
|
+
* `modal`: When this type of dialog is open, the rest of the page is dimmed out and cannot be interacted with.
|
|
160
|
+
* The tab sequence is kept within the dialog and moving the focus outside
|
|
161
|
+
* the dialog will imply closing it. This is the default type of the component.
|
|
162
|
+
*
|
|
163
|
+
* `non-modal`: When a non-modal dialog is open, the rest of the page is not dimmed out
|
|
164
|
+
* and users can interact with the rest of the page.
|
|
165
|
+
* This also implies that the tab focus can move outside the dialog when it reaches the last focusable element.
|
|
166
|
+
*
|
|
167
|
+
* `alert`: is a special type of modal dialogs that interrupts the user's workflow
|
|
168
|
+
* to communicate an important message or ask for a decision.
|
|
169
|
+
* Unlike a typical modal dialog, the user must take an action through the options given to dismiss the dialog,
|
|
170
|
+
* and it cannot be dismissed through the dimmed background or escape key.
|
|
171
|
+
*
|
|
172
|
+
* @default modal
|
|
173
|
+
*/
|
|
174
|
+
modalType?: DialogModalType;
|
|
175
|
+
/**
|
|
176
|
+
* Controls the open state of the dialog
|
|
177
|
+
* @default false
|
|
178
|
+
*/
|
|
179
|
+
open?: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Default value for the uncontrolled open state of the dialog.
|
|
182
|
+
* @default false
|
|
183
|
+
*/
|
|
184
|
+
defaultOpen?: boolean;
|
|
185
|
+
onOpenChange?: DialogOpenChangeEventHandler;
|
|
186
|
+
/**
|
|
187
|
+
* Can contain two children including {@link DialogTrigger} and {@link DialogSurface}.
|
|
188
|
+
* Alternatively can only contain {@link DialogSurface} if using trigger outside dialog, or controlling state.
|
|
189
|
+
*/
|
|
190
|
+
children: [JSX.Element, JSX.Element] | JSX.Element;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export declare type DialogSlots = {};
|
|
194
|
+
|
|
195
|
+
export declare type DialogState = ComponentState<DialogSlots> & DialogContextValue & {
|
|
196
|
+
content: React_2.ReactNode;
|
|
197
|
+
trigger: React_2.ReactNode;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* DialogSurface component represents the visual part of a `Dialog` as a whole,
|
|
202
|
+
* it contains everything that should be visible.
|
|
203
|
+
*/
|
|
204
|
+
export declare const DialogSurface: ForwardRefComponent<DialogSurfaceProps>;
|
|
205
|
+
|
|
206
|
+
export declare const dialogSurfaceClassNames: SlotClassNames<DialogSurfaceSlots>;
|
|
207
|
+
|
|
208
|
+
declare type DialogSurfaceContextValue = boolean;
|
|
209
|
+
|
|
210
|
+
declare type DialogSurfaceContextValues = {
|
|
211
|
+
dialogSurface: DialogSurfaceContextValue;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Union between all possible semantic element that represent a DialogSurface
|
|
216
|
+
*/
|
|
217
|
+
export declare type DialogSurfaceElement = HTMLDialogElement | HTMLDivElement;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* DialogSurface Props
|
|
221
|
+
*
|
|
222
|
+
* Omits basic types from native `dialog` (`open`, `onCancel` and `onClose`)
|
|
223
|
+
* to ensure `onOpenChange`, `open` and `defaultOpen` from `Dialog` is used instead
|
|
224
|
+
*/
|
|
225
|
+
export declare type DialogSurfaceProps = Omit<ComponentProps<DialogSurfaceSlots>, 'open' | 'onCancel' | 'onClose'>;
|
|
226
|
+
|
|
227
|
+
export declare type DialogSurfaceSlots = {
|
|
228
|
+
/**
|
|
229
|
+
* Dimmed background of dialog.
|
|
230
|
+
* The default backdrop is rendered as a `<div>` with styling.
|
|
231
|
+
* This slot expects a `<div>` element which will replace the default backdrop.
|
|
232
|
+
* The backdrop should have `aria-hidden="true"`.
|
|
233
|
+
*
|
|
234
|
+
* By default if `DialogSurface` is `<dialog>` element the backdrop is ignored,
|
|
235
|
+
* since native `<dialog>` element supports [::backdrop](https://developer.mozilla.org/en-US/docs/Web/CSS/::backdrop)
|
|
236
|
+
*/
|
|
237
|
+
backdrop?: Slot<'div'>;
|
|
238
|
+
root: NonNullable<Slot<'dialog', 'div'>>;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* State used in rendering DialogSurface
|
|
243
|
+
*/
|
|
244
|
+
export declare type DialogSurfaceState = ComponentState<DialogSurfaceSlots>;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* The `DialogTitle` component expects to have a title/header
|
|
248
|
+
* and when `Dialog` is `non-modal` a close (X icon) button is provided through `action` slot by default.
|
|
249
|
+
*/
|
|
250
|
+
export declare const DialogTitle: ForwardRefComponent<DialogTitleProps>;
|
|
251
|
+
|
|
252
|
+
export declare const dialogTitleClassNames: SlotClassNames<DialogTitleSlots>;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* DialogTitle Props
|
|
256
|
+
*/
|
|
257
|
+
export declare type DialogTitleProps = ComponentProps<DialogTitleSlots> & {};
|
|
258
|
+
|
|
259
|
+
export declare type DialogTitleSlots = {
|
|
260
|
+
/**
|
|
261
|
+
* By default this is a div, but can be a heading.
|
|
262
|
+
*/
|
|
263
|
+
root: Slot<'div', 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'>;
|
|
264
|
+
/**
|
|
265
|
+
* By default a Dialog with modalType='non-modal' will have a close button action
|
|
266
|
+
*/
|
|
267
|
+
action?: Slot<'div'>;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* State used in rendering DialogTitle
|
|
272
|
+
*/
|
|
273
|
+
export declare type DialogTitleState = ComponentState<DialogTitleSlots>;
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* A non-visual component that wraps its child
|
|
277
|
+
* and configures them to be the trigger that will open or close a `Dialog`.
|
|
278
|
+
* This component should only accept one child.
|
|
279
|
+
*
|
|
280
|
+
* In case the trigger is used outside `Dialog` component
|
|
281
|
+
* it'll still provide basic ARIA related attributes
|
|
282
|
+
* to it's wrapped child, but it won't be able to alter the dialog `open` state anymore,
|
|
283
|
+
* in that case the user must provide a `controlled state`
|
|
284
|
+
*/
|
|
285
|
+
export declare const DialogTrigger: React_2.FC<DialogTriggerProps> & FluentTriggerComponent;
|
|
286
|
+
|
|
287
|
+
export declare type DialogTriggerAction = 'open' | 'close';
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Props that are passed to the child of the DialogTrigger when cloned to ensure correct behaviour for the Dialog
|
|
291
|
+
*/
|
|
292
|
+
export declare type DialogTriggerChildProps<Type extends ARIAButtonType = ARIAButtonType, Props = {}> = ARIAButtonResultProps<Type, Props & {
|
|
293
|
+
ref: React_2.Ref<unknown>;
|
|
294
|
+
'aria-haspopup'?: 'dialog';
|
|
295
|
+
}>;
|
|
296
|
+
|
|
297
|
+
export declare type DialogTriggerProps = {
|
|
298
|
+
/**
|
|
299
|
+
* Explicitly declare if the trigger is responsible for opening or
|
|
300
|
+
* closing a Dialog visibility state.
|
|
301
|
+
* @default 'open' // if it's outside DialogSurface
|
|
302
|
+
* @default 'close' // if it's inside DialogSurface
|
|
303
|
+
*/
|
|
304
|
+
action?: DialogTriggerAction;
|
|
305
|
+
/**
|
|
306
|
+
* Explicitly require single child or render function
|
|
307
|
+
* to inject properties
|
|
308
|
+
*/
|
|
309
|
+
children: React_2.ReactElement | ((props: DialogTriggerChildProps) => React_2.ReactElement | null);
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
export declare type DialogTriggerState = {
|
|
313
|
+
children: React_2.ReactElement | null;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Render the final JSX of Dialog
|
|
318
|
+
*/
|
|
319
|
+
export declare const renderDialog_unstable: (state: DialogState, contextValues: DialogContextValues) => JSX.Element;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Render the final JSX of DialogActions
|
|
323
|
+
*/
|
|
324
|
+
export declare const renderDialogActions_unstable: (state: DialogActionsState) => JSX.Element;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Render the final JSX of DialogBody
|
|
328
|
+
*/
|
|
329
|
+
export declare const renderDialogBody_unstable: (state: DialogBodyState) => JSX.Element;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Render the final JSX of DialogContent
|
|
333
|
+
*/
|
|
334
|
+
export declare const renderDialogContent_unstable: (state: DialogContentState) => JSX.Element;
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Render the final JSX of DialogSurface
|
|
338
|
+
*/
|
|
339
|
+
export declare const renderDialogSurface_unstable: (state: DialogSurfaceState, contextValues: DialogSurfaceContextValues) => JSX.Element;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Render the final JSX of DialogTitle
|
|
343
|
+
*/
|
|
344
|
+
export declare const renderDialogTitle_unstable: (state: DialogTitleState) => JSX.Element;
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Render the final JSX of MenuTrigger
|
|
348
|
+
*
|
|
349
|
+
* Only renders children
|
|
350
|
+
*/
|
|
351
|
+
export declare const renderDialogTrigger_unstable: (state: DialogTriggerState) => ReactElement<any, string | JSXElementConstructor<any>> | null;
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Create the state required to render Dialog.
|
|
355
|
+
*
|
|
356
|
+
* The returned state can be modified with hooks such as useDialogStyles_unstable,
|
|
357
|
+
* before being passed to renderDialog_unstable.
|
|
358
|
+
*
|
|
359
|
+
* @param props - props from this instance of Dialog
|
|
360
|
+
*/
|
|
361
|
+
export declare const useDialog_unstable: (props: DialogProps) => DialogState;
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Create the state required to render DialogActions.
|
|
365
|
+
*
|
|
366
|
+
* The returned state can be modified with hooks such as useDialogActionsStyles_unstable,
|
|
367
|
+
* before being passed to renderDialogActions_unstable.
|
|
368
|
+
*
|
|
369
|
+
* @param props - props from this instance of DialogActions
|
|
370
|
+
* @param ref - reference to root HTMLElement of DialogActions
|
|
371
|
+
*/
|
|
372
|
+
export declare const useDialogActions_unstable: (props: DialogActionsProps, ref: React_2.Ref<HTMLElement>) => DialogActionsState;
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Apply styling to the DialogActions slots based on the state
|
|
376
|
+
*/
|
|
377
|
+
export declare const useDialogActionsStyles_unstable: (state: DialogActionsState) => DialogActionsState;
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Create the state required to render DialogBody.
|
|
381
|
+
*
|
|
382
|
+
* The returned state can be modified with hooks such as useDialogBodyStyles_unstable,
|
|
383
|
+
* before being passed to renderDialogBody_unstable.
|
|
384
|
+
*
|
|
385
|
+
* @param props - props from this instance of DialogBody
|
|
386
|
+
* @param ref - reference to root HTMLElement of DialogBody
|
|
387
|
+
*/
|
|
388
|
+
export declare const useDialogBody_unstable: (props: DialogBodyProps, ref: React_2.Ref<HTMLElement>) => DialogBodyState;
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Apply styling to the DialogBody slots based on the state
|
|
392
|
+
*/
|
|
393
|
+
export declare const useDialogBodyStyles_unstable: (state: DialogBodyState) => DialogBodyState;
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Create the state required to render DialogBody.
|
|
397
|
+
*
|
|
398
|
+
* The returned state can be modified with hooks such as useDialogBodyStyles_unstable,
|
|
399
|
+
* before being passed to renderDialogBody_unstable.
|
|
400
|
+
*
|
|
401
|
+
* @param props - props from this instance of DialogBody
|
|
402
|
+
* @param ref - reference to root HTMLElement of DialogBody
|
|
403
|
+
*/
|
|
404
|
+
export declare const useDialogContent_unstable: (props: DialogContentProps, ref: React_2.Ref<HTMLElement>) => DialogContentState;
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Apply styling to the DialogContent slots based on the state
|
|
408
|
+
*/
|
|
409
|
+
export declare const useDialogContentStyles_unstable: (state: DialogContentState) => DialogContentState;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Create the state required to render DialogSurface.
|
|
413
|
+
*
|
|
414
|
+
* The returned state can be modified with hooks such as useDialogSurfaceStyles_unstable,
|
|
415
|
+
* before being passed to renderDialogSurface_unstable.
|
|
416
|
+
*
|
|
417
|
+
* @param props - props from this instance of DialogSurface
|
|
418
|
+
* @param ref - reference to root HTMLElement of DialogSurface
|
|
419
|
+
*/
|
|
420
|
+
export declare const useDialogSurface_unstable: (props: DialogSurfaceProps, ref: React_2.Ref<DialogSurfaceElement>) => DialogSurfaceState;
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Apply styling to the DialogSurface slots based on the state
|
|
424
|
+
*/
|
|
425
|
+
export declare const useDialogSurfaceStyles_unstable: (state: DialogSurfaceState) => DialogSurfaceState;
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Create the state required to render DialogTitle.
|
|
429
|
+
*
|
|
430
|
+
* The returned state can be modified with hooks such as useDialogTitleStyles_unstable,
|
|
431
|
+
* before being passed to renderDialogTitle_unstable.
|
|
432
|
+
*
|
|
433
|
+
* @param props - props from this instance of DialogTitle
|
|
434
|
+
* @param ref - reference to root HTMLElement of DialogTitle
|
|
435
|
+
*/
|
|
436
|
+
export declare const useDialogTitle_unstable: (props: DialogTitleProps, ref: React_2.Ref<HTMLElement>) => DialogTitleState;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Apply styling to the DialogTitle slots based on the state
|
|
440
|
+
*/
|
|
441
|
+
export declare const useDialogTitleStyles_unstable: (state: DialogTitleState) => DialogTitleState;
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Create the state required to render DialogTrigger.
|
|
445
|
+
* Clones the only child component and adds necessary event handling behaviours to open a popup Dialog
|
|
446
|
+
*
|
|
447
|
+
* @param props - props from this instance of DialogTrigger
|
|
448
|
+
*/
|
|
449
|
+
export declare const useDialogTrigger_unstable: (props: DialogTriggerProps) => DialogTriggerState;
|
|
450
|
+
|
|
451
|
+
export { }
|
package/lib/Dialog.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dialog.js","sourceRoot":"../src/","sources":["packages/react-components/react-dialog/src/Dialog.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC","sourcesContent":["export * from './components/Dialog/index';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DialogActions.js","sourceRoot":"../src/","sources":["packages/react-components/react-dialog/src/DialogActions.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC","sourcesContent":["export * from './components/DialogActions/index';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DialogBody.js","sourceRoot":"../src/","sources":["packages/react-components/react-dialog/src/DialogBody.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC","sourcesContent":["export * from './components/DialogBody/index';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DialogContent.js","sourceRoot":"../src/","sources":["packages/react-components/react-dialog/src/DialogContent.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC","sourcesContent":["export * from './components/DialogContent/index';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DialogSurface.js","sourceRoot":"../src/","sources":["packages/react-components/react-dialog/src/DialogSurface.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC","sourcesContent":["export * from './components/DialogSurface/index';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DialogTitle.js","sourceRoot":"../src/","sources":["packages/react-components/react-dialog/src/DialogTitle.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC","sourcesContent":["export * from './components/DialogTitle/index';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DialogTrigger.js","sourceRoot":"../src/","sources":["packages/react-components/react-dialog/src/DialogTrigger.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC","sourcesContent":["export * from './components/DialogTrigger/index';\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useDialog_unstable } from './useDialog';
|
|
3
|
+
import { renderDialog_unstable } from './renderDialog';
|
|
4
|
+
import { useDialogContextValues_unstable } from './useDialogContextValues';
|
|
5
|
+
/**
|
|
6
|
+
* The `Dialog` root level component serves as an interface for interaction with all possible behaviors exposed.
|
|
7
|
+
* It provides context down the hierarchy to `children` compound components to allow functionality.
|
|
8
|
+
* This component expects to receive as children either a `DialogSurface` or a `DialogTrigger`
|
|
9
|
+
* and a `DialogSurface` (or some component that will eventually render one of those compound components)
|
|
10
|
+
* in this specific order
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const Dialog = /*#__PURE__*/React.memo(props => {
|
|
14
|
+
const state = useDialog_unstable(props);
|
|
15
|
+
const contextValues = useDialogContextValues_unstable(state);
|
|
16
|
+
return renderDialog_unstable(state, contextValues);
|
|
17
|
+
});
|
|
18
|
+
Dialog.displayName = 'Dialog';
|
|
19
|
+
//# sourceMappingURL=Dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["packages/react-components/react-dialog/src/components/Dialog/Dialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,kBAAT,QAAmC,aAAnC;AACA,SAAS,qBAAT,QAAsC,gBAAtC;AAEA,SAAS,+BAAT,QAAgD,0BAAhD;AAEA;;;;;;AAMG;;AACH,OAAO,MAAM,MAAM,gBAA0B,KAAK,CAAC,IAAN,CAAW,KAAK,IAAG;EAC9D,MAAM,KAAK,GAAG,kBAAkB,CAAC,KAAD,CAAhC;EACA,MAAM,aAAa,GAAG,+BAA+B,CAAC,KAAD,CAArD;EAEA,OAAO,qBAAqB,CAAC,KAAD,EAAQ,aAAR,CAA5B;AACD,CAL4C,CAAtC;AAOP,MAAM,CAAC,WAAP,GAAqB,QAArB","sourcesContent":["import * as React from 'react';\nimport { useDialog_unstable } from './useDialog';\nimport { renderDialog_unstable } from './renderDialog';\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 return renderDialog_unstable(state, contextValues);\n});\n\nDialog.displayName = 'Dialog';\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dialog.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts"],"names":[],"mappings":"","sourcesContent":["import type * as React from 'react';\nimport type { ComponentProps, ComponentState } from '@fluentui/react-utilities';\nimport type { DialogContextValue, DialogSurfaceContextValue } from '../../contexts';\nimport type { DialogSurfaceElement } from '../DialogSurface/DialogSurface.types';\n\nexport type DialogSlots = {};\n\nexport type DialogOpenChangeEvent = DialogOpenChangeData['event'];\n\nexport type DialogOpenChangeData =\n | {\n /**\n * triggered when Escape key is pressed in a native `dialog`\n */\n type: 'dialogCancel';\n open: boolean;\n event: React.SyntheticEvent<DialogSurfaceElement>;\n }\n | {\n type: 'escapeKeyDown';\n open: boolean;\n event: React.KeyboardEvent<DialogSurfaceElement>;\n }\n | {\n type: 'backdropClick';\n open: boolean;\n event: React.MouseEvent<DialogSurfaceElement>;\n }\n | {\n type: 'triggerClick';\n open: boolean;\n event: React.MouseEvent<DialogSurfaceElement>;\n };\n\nexport type DialogModalType = 'modal' | 'non-modal' | 'alert';\n\n/**\n * Callback fired when the component changes value from open state.\n *\n * @param event - a React's Synthetic event or a KeyboardEvent in case of `documentEscapeKeyDown`\n * @param data - A data object with relevant information, such as open value and type\n */\nexport type DialogOpenChangeEventHandler = (event: DialogOpenChangeEvent, data: DialogOpenChangeData) => void;\n\nexport type DialogContextValues = {\n dialog: DialogContextValue;\n /**\n * dialogSurface context is provided by Dialog as false\n * to ensure components inside Dialog but outside DialogSurface will consume this as false\n */\n dialogSurface: DialogSurfaceContextValue;\n};\n\nexport type DialogProps = ComponentProps<Partial<DialogSlots>> & {\n /**\n * Dialog variations.\n *\n * `modal`: When this type of dialog is open, the rest of the page is dimmed out and cannot be interacted with.\n * The tab sequence is kept within the dialog and moving the focus outside\n * the dialog will imply closing it. This is the default type of the component.\n *\n * `non-modal`: When a non-modal dialog is open, the rest of the page is not dimmed out\n * and users can interact with the rest of the page.\n * This also implies that the tab focus can move outside the dialog when it reaches the last focusable element.\n *\n * `alert`: is a special type of modal dialogs that interrupts the user's workflow\n * to communicate an important message or ask for a decision.\n * Unlike a typical modal dialog, the user must take an action through the options given to dismiss the dialog,\n * and it cannot be dismissed through the dimmed background or escape key.\n *\n * @default modal\n */\n modalType?: DialogModalType;\n /**\n * Controls the open state of the dialog\n * @default false\n */\n open?: boolean;\n /**\n * Default value for the uncontrolled open state of the dialog.\n * @default false\n */\n defaultOpen?: boolean;\n onOpenChange?: DialogOpenChangeEventHandler;\n /**\n * Can contain two children including {@link DialogTrigger} and {@link DialogSurface}.\n * Alternatively can only contain {@link DialogSurface} if using trigger outside dialog, or controlling state.\n */\n children: [JSX.Element, JSX.Element] | JSX.Element;\n};\n\nexport type DialogState = ComponentState<DialogSlots> &\n DialogContextValue & {\n content: React.ReactNode;\n trigger: React.ReactNode;\n };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["packages/react-components/react-dialog/src/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"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { DialogProvider, DialogSurfaceProvider } from '../../contexts';
|
|
3
|
+
/**
|
|
4
|
+
* Render the final JSX of Dialog
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const renderDialog_unstable = (state, contextValues) => {
|
|
8
|
+
const {
|
|
9
|
+
content,
|
|
10
|
+
trigger
|
|
11
|
+
} = state;
|
|
12
|
+
return /*#__PURE__*/React.createElement(DialogProvider, {
|
|
13
|
+
value: contextValues.dialog
|
|
14
|
+
}, /*#__PURE__*/React.createElement(DialogSurfaceProvider, {
|
|
15
|
+
value: contextValues.dialogSurface
|
|
16
|
+
}, trigger, content));
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=renderDialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["packages/react-components/react-dialog/src/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/"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
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
|
+
/**
|
|
7
|
+
* Create the state required to render Dialog.
|
|
8
|
+
*
|
|
9
|
+
* The returned state can be modified with hooks such as useDialogStyles_unstable,
|
|
10
|
+
* before being passed to renderDialog_unstable.
|
|
11
|
+
*
|
|
12
|
+
* @param props - props from this instance of Dialog
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const useDialog_unstable = props => {
|
|
16
|
+
const {
|
|
17
|
+
children,
|
|
18
|
+
modalType = 'modal',
|
|
19
|
+
onOpenChange
|
|
20
|
+
} = props;
|
|
21
|
+
const [trigger, content] = childrenToTriggerAndContent(children);
|
|
22
|
+
const [open, setOpen] = useControllableState({
|
|
23
|
+
state: props.open,
|
|
24
|
+
defaultState: props.defaultOpen,
|
|
25
|
+
initialState: false
|
|
26
|
+
});
|
|
27
|
+
const requestOpenChange = useEventCallback(data => {
|
|
28
|
+
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(data.event, data); // if user prevents default then do not change state value
|
|
29
|
+
// otherwise updates state value and trigger reference to the element that caused the opening
|
|
30
|
+
|
|
31
|
+
if (!data.event.isDefaultPrevented()) {
|
|
32
|
+
setOpen(data.open);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
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();
|
|
42
|
+
}
|
|
43
|
+
}, [disableBodyScroll, isBodyScrollLocked]);
|
|
44
|
+
return {
|
|
45
|
+
components: {
|
|
46
|
+
backdrop: 'div'
|
|
47
|
+
},
|
|
48
|
+
open,
|
|
49
|
+
modalType,
|
|
50
|
+
content: open ? content : null,
|
|
51
|
+
trigger,
|
|
52
|
+
requestOpenChange,
|
|
53
|
+
dialogContentId: useId('dialog-content-'),
|
|
54
|
+
dialogTitleId: useId('dialog-title-'),
|
|
55
|
+
isNestedDialog: useHasParentContext(DialogContext),
|
|
56
|
+
dialogRef: useMergedRefs(focusRef, nativeControlRef)
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Extracts trigger and content from children
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
function childrenToTriggerAndContent(children) {
|
|
64
|
+
const childrenArray = React.Children.toArray(children);
|
|
65
|
+
|
|
66
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
67
|
+
if (childrenArray.length !== 1 && childrenArray.length !== 2) {
|
|
68
|
+
// eslint-disable-next-line no-console
|
|
69
|
+
console.warn('Dialog must contain at least one child <DialogSurface/>,\n' + 'and at most two children <DialogTrigger/> <DialogSurface/> (in this order)');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
switch (childrenArray.length) {
|
|
74
|
+
// case where there's a trigger followed by content
|
|
75
|
+
case 2:
|
|
76
|
+
return childrenArray;
|
|
77
|
+
// case where there's only content
|
|
78
|
+
|
|
79
|
+
case 1:
|
|
80
|
+
return [undefined, childrenArray[0]];
|
|
81
|
+
// unknown case
|
|
82
|
+
|
|
83
|
+
default:
|
|
84
|
+
return [undefined, undefined];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=useDialog.js.map
|