2023-09-23 20:24:43 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-09-23 20:43:57 +08:00
|
|
|
const actionClassName =
|
|
|
|
'sticky bottom-0 z-50 flex items-center justify-end bg-base-100 bg-opacity-80 p-4 backdrop-blur'
|
2023-09-23 20:24:43 +08:00
|
|
|
|
|
|
|
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()}>
|
2023-09-23 20:43:57 +08:00
|
|
|
<div class={twMerge(actionClassName, 'top-0 justify-between')}>
|
2023-09-23 20:24:43 +08:00
|
|
|
<div class="flex items-center gap-4 text-xl font-bold">
|
|
|
|
{props.icon}
|
2023-09-23 20:43:57 +08:00
|
|
|
|
2023-09-23 20:24:43 +08:00
|
|
|
<span>{props.title}</span>
|
|
|
|
</div>
|
2023-09-23 20:43:57 +08:00
|
|
|
|
2023-09-23 20:24:43 +08:00
|
|
|
<Button
|
|
|
|
class="btn-circle btn-sm"
|
2023-09-23 20:43:57 +08:00
|
|
|
onClick={() => dialogRef?.close()}
|
2023-09-23 20:24:43 +08:00
|
|
|
icon={<IconX size={20} />}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2023-09-23 20:43:57 +08:00
|
|
|
<div class="p-4">{children(() => props.children)()}</div>
|
2023-09-23 20:24:43 +08:00
|
|
|
|
|
|
|
<Show when={props.action}>
|
2023-09-23 20:43:57 +08:00
|
|
|
<div class={actionClassName}>
|
2023-09-23 20:24:43 +08:00
|
|
|
<div class="flex justify-end gap-2">{props.action}</div>
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<form method="dialog" class="modal-backdrop">
|
|
|
|
<button />
|
|
|
|
</form>
|
|
|
|
</dialog>
|
|
|
|
)
|
|
|
|
}
|