forked from riccardoperra/codeimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDialog.tsx
More file actions
63 lines (60 loc) · 1.92 KB
/
Dialog.tsx
File metadata and controls
63 lines (60 loc) · 1.92 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
import {Motion} from '@motionone/solid';
import {AriaDialogProps, createDialog} from '@solid-aria/dialog';
import {FocusScope} from '@solid-aria/focus';
import {
AriaModalProps,
AriaOverlayProps,
createModal,
createOverlay,
createPreventScroll,
} from '@solid-aria/overlays';
import {JSXElement, ParentProps, Show} from 'solid-js';
import * as styles from './Dialog.css';
import {DialogPanel, DialogPanelProps} from './DialogPanel';
export interface DialogProps
extends AriaDialogProps,
AriaModalProps,
AriaOverlayProps {
title?: string;
// @ts-expect-error Fix vanilla-extract typing
fullScreen?: DialogPanelProps['fullScreen'];
// @ts-expect-error Fix vanilla-extract typing
size: DialogPanelProps['size'];
}
export function Dialog(props: ParentProps<DialogProps>): JSXElement {
let ref: HTMLDivElement | undefined;
const {overlayProps, underlayProps} = createOverlay(props, () => ref);
createPreventScroll();
const {modalProps} = createModal();
const {dialogProps, titleProps} = createDialog(props, () => ref);
return (
<div
class={styles.overlay}
data-full-screen={props.fullScreen}
{...underlayProps}
>
<FocusScope contain restoreFocus autofocus>
<Motion.div
initial={{opacity: 0, scale: 0.95}}
animate={{opacity: 1, scale: 1}}
exit={{opacity: 0, scale: 0.95}}
transition={{duration: 0.2, easing: 'ease-in-out'}}
{...overlayProps}
{...dialogProps}
{...modalProps}
ref={ref}
class={styles.wrapper({fullScreen: !!props.fullScreen})}
>
<DialogPanel fullScreen={props.fullScreen} size={props.size}>
<Show when={props.title}>
<h3 {...titleProps} class={styles.title}>
{props.title}
</h3>
</Show>
{props.children}
</DialogPanel>
</Motion.div>
</FocusScope>
</div>
);
}