flotilla/src/lib/components/ModalBox.svelte

39 lines
823 B
Svelte
Raw Normal View History

2024-08-08 21:02:46 +00:00
<script context="module" lang="ts">
2024-08-09 23:22:09 +00:00
import {emitter} from "@app/modal"
2024-08-08 21:02:46 +00:00
const modalHeight = tweened(0, {
2024-08-16 17:50:38 +00:00
duration: 700,
easing: quintOut,
})
2024-08-09 23:22:09 +00:00
2024-08-16 17:50:38 +00:00
emitter.on("close", () => modalHeight.set(0))
2024-08-08 21:02:46 +00:00
</script>
<script lang="ts">
2024-08-16 17:50:38 +00:00
import {onMount} from "svelte"
import {quintOut} from "svelte/easing"
import {tweened} from "svelte/motion"
2024-08-08 21:02:46 +00:00
2024-08-16 17:50:38 +00:00
export let component
export let props = {}
2024-08-08 21:02:46 +00:00
let box: HTMLElement
let content: HTMLElement
let naturalHeight = 0
onMount(() => {
naturalHeight = content.clientHeight + 48
2024-08-09 23:22:09 +00:00
modalHeight.set(naturalHeight)
2024-08-08 21:02:46 +00:00
})
</script>
2024-08-16 17:50:38 +00:00
<div
class="modal-box"
bind:this={box}
style={`height: ${$modalHeight}px`}
class:overflow-hidden={$modalHeight !== naturalHeight}>
2024-08-08 21:02:46 +00:00
<div bind:this={content}>
<svelte:component this={component} {...props} />
</div>
</div>