-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathDialogContext.tsx
104 lines (101 loc) · 3.43 KB
/
DialogContext.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import type { PortalProps } from '../../utils/index.js';
export type DialogContextProps = {
/**
* Flag whether dialog should be shown.
*
* It is recommended to directly pass the boolean condition to this prop instead of rendering the `Dialog`
* conditionally with `isOpen` hard-coded to `true`. One benefit of this is getting an exit animation.
*
* @default false
*/
isOpen?: boolean;
/**
* Handler that is called when dialog is closed.
*/
onClose?: (event?: React.SyntheticEvent) => void;
/**
* Flag whether dialog is dismissible. If false, you can't close it.
* @default true
*/
isDismissible?: boolean;
/**
* Flag whether dialog should be closed on backdrop press.
* @default false
*/
closeOnExternalClick?: boolean;
/**
* Flag whether dialog should be closed on Escape key press.
* @default true
*/
closeOnEsc?: boolean;
/**
* Prevents focus from leaving the dialog. This is useful when the dialog is modal.
*
* Setting this prop to `true` will also set `setFocus` to `true`.
*
* @default false
*/
trapFocus?: boolean;
/**
* If true, focuses the dialog.
*
* Defaults to `true` if `trapFocus` is set to `true`, otherwise defaults to `false`.
*/
setFocus?: boolean;
/**
* Prevents body from being scrollable. This is useful when the dialog is modal.
* @default false
*/
preventDocumentScroll?: boolean;
/**
* Flag whether dialog is draggable.
*
* If you want to make dialog draggable relatively to the container, you should use set `relativeTo` to `container`.
*
* @default false
*/
isDraggable?: boolean;
/**
* Flag whether dialog is resizable.
* @default false
*/
isResizable?: boolean;
/**
* Whether dialog should be positioned relatively to a container or the viewport.
*
* Using `'container'` will absolutely position this dialog relative to the closest positioned ancestor.
* In other words, you must place the dialog as a child of an element that has `position` set to
* something other than `static`, e.g. `position: relative`.
* @default 'viewport'
*/
relativeTo?: 'container' | 'viewport';
/**
* If true, the dialog will be portaled into a <div> inside the nearest `ThemeProvider`.
* Recommended to set to true when for modal dialogs that use `relativeTo='viewport'`.
*
* Can be set to an object with a `to` property to portal into a specific element.
* If `to`/`to()` === `null`/`undefined`, the default behavior will be used (i.e. as if `portal` is not passed).
*
* Defaults to false if using `Dialog` and true if using `Modal`.
*/
portal?: PortalProps['portal'];
/**
* Dialog root ref. For internal use.
*/
dialogRootRef?: React.RefObject<HTMLDivElement | null>;
/**
* Determines the positioning of Dialog on page.
*/
placement?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
};
export const DialogContext = React.createContext<
DialogContextProps | undefined
>(undefined);
export const useDialogContext = () => {
return React.useContext(DialogContext) || {};
};