flotilla/src/lib/components/Dialog.svelte

59 lines
1.7 KiB
Svelte
Raw Normal View History

2024-10-15 22:52:30 +00:00
<script lang="ts">
2026-01-30 22:14:12 +00:00
import type {Component} from "svelte"
2025-11-03 22:43:27 +00:00
import cx from "classnames"
2024-10-17 23:03:50 +00:00
import {noop} from "@welshman/lib"
2024-10-15 22:52:30 +00:00
import {fade, fly} from "@lib/transition"
import Close from "@assets/icons/close.svg?dataurl"
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
import {clearModals} from "@app/util/modal"
2024-10-15 22:52:30 +00:00
2026-01-30 22:14:12 +00:00
type Props = {
2025-02-04 00:37:14 +00:00
onClose?: any
fullscreen?: boolean
2026-01-30 22:14:12 +00:00
children: {
component: Component<any>
props: Record<string, any>
}
2025-02-04 00:37:14 +00:00
}
2024-10-17 22:02:03 +00:00
const {onClose = noop, fullscreen = false, children}: Props = $props()
2025-02-04 00:37:14 +00:00
2025-12-08 17:19:41 +00:00
const wrapperClass = $derived(
cx("absolute inset-0 flex sm:relative pointer-events-none", {
"items-center justify-center": fullscreen,
"items-end sm:w-[520px] sm:items-center": !fullscreen,
}),
)
const innerClass = $derived(
cx(
"relative text-base-content text-base-content flex-grow pointer-events-auto",
2026-01-30 22:14:12 +00:00
"rounded-t-box sm:rounded-box",
2025-12-08 17:19:41 +00:00
{
2026-02-09 17:04:39 +00:00
"bg-alt shadow-m max-h-[90vh] flex flex-col max-w-full pb-sai sm:pb-0": !fullscreen,
2025-12-08 17:19:41 +00:00
},
),
2025-02-04 00:37:14 +00:00
)
2024-10-15 22:52:30 +00:00
</script>
<div class="center fixed inset-0 z-modal">
<button
type="button"
2025-02-03 23:01:42 +00:00
aria-label="Close dialog"
2026-02-02 18:09:14 +00:00
class="absolute inset-0 cursor-pointer bg-black opacity-50 dark:opacity-75"
transition:fade={{duration: 200}}
2025-02-04 00:37:14 +00:00
onclick={onClose}>
2025-02-03 23:01:42 +00:00
</button>
2025-12-08 17:19:41 +00:00
<div class={wrapperClass}>
2026-02-02 18:09:14 +00:00
<div class={innerClass} transition:fly>
<Button
class="absolute -top-4 right-3 btn btn-circle btn-neutral btn-sm"
onclick={clearModals}>
<Icon icon={Close} size={6} />
</Button>
2026-01-30 22:14:12 +00:00
<children.component {...children.props} />
2025-12-08 17:19:41 +00:00
</div>
2024-10-15 22:52:30 +00:00
</div>
</div>