-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathDialog.tsx
More file actions
108 lines (97 loc) · 3.59 KB
/
Copy pathDialog.tsx
File metadata and controls
108 lines (97 loc) · 3.59 KB
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
105
106
107
108
import {
FloatingFocusManager,
FloatingOverlay,
FloatingPortal,
useClick,
useDismiss,
useFloating,
useInteractions,
useRole
} from "@floating-ui/react";
import { If } from "@mendix/widget-plugin-component-kit/If";
import classNames from "classnames";
import { createElement, Fragment, ReactElement } from "react";
import LinkDialog, { LinkDialogProps } from "./LinkDialog";
import VideoDialog, { VideoDialogProps } from "./VideoDialog";
import ViewCodeDialog, { ViewCodeDialogProps } from "./ViewCodeDialog";
import ImageDialog, { ImageDialogProps } from "./ImageDialog";
import "./Dialog.scss";
interface BaseDialogProps {
isOpen: boolean;
parentNode?: HTMLElement | null;
onOpenChange?(open: boolean): void;
}
export type ImageDialogBaseProps = {
dialogType?: "image";
config?: ImageDialogProps;
};
export type ViewCodeDialogBaseProps = {
dialogType?: "view-code";
config?: ViewCodeDialogProps;
};
export type LinkDialogBaseProps = {
dialogType?: "link";
config?: LinkDialogProps;
};
export type VideoDialogBaseProps = {
dialogType?: "video";
config?: VideoDialogProps;
};
export type ChildDialogProps =
| LinkDialogBaseProps
| VideoDialogBaseProps
| ViewCodeDialogBaseProps
| ImageDialogBaseProps;
export type DialogProps = BaseDialogProps & ChildDialogProps;
/**
* Dialog components that will be shown on toolbar's button
*/
export default function Dialog(props: DialogProps): ReactElement {
const { isOpen, onOpenChange, dialogType, config } = props;
const { refs, context } = useFloating({
open: isOpen,
onOpenChange
});
const click = useClick(context);
const dismiss = useDismiss(context, {
outsidePressEvent: "mousedown"
});
const role = useRole(context);
const { getFloatingProps } = useInteractions([click, dismiss, role]);
return (
<FloatingPortal id="root">
{isOpen && (
<Fragment>
<FloatingOverlay
lockScroll
className="widget-rich-text-modal-overlay mx-underlay"
></FloatingOverlay>
<FloatingFocusManager context={context}>
<div
className={classNames("Dialog mx-layoutgrid widget-rich-text", {
"form-vertical": config?.formOrientation === "vertical"
})}
ref={refs.setFloating}
aria-labelledby={dialogType}
aria-describedby={dialogType}
{...getFloatingProps()}
>
<If condition={dialogType === "link"}>
<LinkDialog {...(config as LinkDialogProps)}></LinkDialog>
</If>
<If condition={dialogType === "video"}>
<VideoDialog {...(config as VideoDialogProps)}></VideoDialog>
</If>
<If condition={dialogType === "view-code"}>
<ViewCodeDialog {...(config as ViewCodeDialogProps)}></ViewCodeDialog>
</If>
<If condition={dialogType === "image"}>
<ImageDialog {...(config as ImageDialogProps)}></ImageDialog>
</If>
</div>
</FloatingFocusManager>
</Fragment>
)}
</FloatingPortal>
);
}