flotilla/src/lib/components/ModalBox.svelte

37 lines
884 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, {
duration: 700,
easing: quintOut
})
2024-08-09 23:22:09 +00:00
emitter.on('close', () => modalHeight.set(0))
2024-08-08 21:02:46 +00:00
</script>
<script lang="ts">
import {onMount} from 'svelte'
import {slide} from 'svelte/transition'
import {quintOut} from 'svelte/easing'
import {tweened} from 'svelte/motion'
import {last} from '@welshman/lib'
export let component
2024-08-09 23:22:09 +00:00
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>
<div class="modal-box" bind:this={box} style={`height: ${$modalHeight}px`} class:overflow-hidden={$modalHeight !== naturalHeight}>
<div bind:this={content}>
<svelte:component this={component} {...props} />
</div>
</div>