forked from MetaCubeX/metacubexd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModal.tsx
53 lines (46 loc) · 1.49 KB
/
Modal.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
import { IconX } from '@tabler/icons-solidjs'
import { JSX, ParentComponent, Show, children } from 'solid-js'
import { twMerge } from 'tailwind-merge'
import { Button } from '~/components'
type Props = {
ref?: (el: HTMLDialogElement) => void
icon?: JSX.Element
title?: JSX.Element
action?: JSX.Element
}
const actionClass =
'sticky bottom-0 z-50 flex items-center justify-end bg-base-100 bg-opacity-80 p-6 backdrop-blur'
export const Modal: ParentComponent<Props> = (props) => {
let dialogRef: HTMLDialogElement | undefined
return (
<dialog
ref={(el) => (dialogRef = el) && props.ref?.(el)}
class="modal modal-bottom sm:modal-middle"
>
<div class="modal-box p-0" onContextMenu={(e) => e.preventDefault()}>
<div class={twMerge(actionClass, 'top-0 justify-between')}>
<div class="flex items-center gap-4 text-xl font-bold">
{props.icon}
<span>{props.title}</span>
</div>
<Button
class="btn-circle btn-sm"
onClick={() => {
dialogRef?.close()
}}
icon={<IconX size={20} />}
/>
</div>
<div class="p-6 pt-3">{children(() => props.children)()}</div>
<Show when={props.action}>
<div class={actionClass}>
<div class="flex justify-end gap-2">{props.action}</div>
</div>
</Show>
</div>
<form method="dialog" class="modal-backdrop">
<button />
</form>
</dialog>
)
}