mirror of
https://github.com/BradNut/svelte-library
synced 2025-09-08 17:40:21 +00:00
55 lines
1,018 B
Svelte
55 lines
1,018 B
Svelte
<script>
|
|
import { fly, fade } from 'svelte/transition';
|
|
import Portal from './Portal.svelte';
|
|
import { clickOutside } from './clickOutside';
|
|
|
|
export let isModalOpen = false;
|
|
export let background = true;
|
|
|
|
function closeModal() {
|
|
isModalOpen = false;
|
|
}
|
|
</script>
|
|
|
|
{#if isModalOpen}
|
|
<Portal>
|
|
<div
|
|
use:clickOutside
|
|
on:click-outside={closeModal}
|
|
class="modal-wrapper"
|
|
transition:fly={{ opacity: 0, y: 100 }}
|
|
>
|
|
<button class="close-btn" on:click={closeModal} aria-label="Close Modal Box">Close</button>
|
|
<slot />
|
|
</div>
|
|
{#if background}
|
|
<div on:click={closeModal} transition:fade class="background" />
|
|
{/if}
|
|
</Portal>
|
|
{/if}
|
|
|
|
<style>
|
|
.modal-wrapper {
|
|
position: fixed;
|
|
inset: 100px 0 0;
|
|
min-width: 320px;
|
|
max-width: 530px;
|
|
margin: 0 auto;
|
|
width: 100%;
|
|
z-index: 101;
|
|
}
|
|
.background {
|
|
background: black;
|
|
opacity: 0.8;
|
|
cursor: pointer;
|
|
inset: 0;
|
|
position: fixed;
|
|
z-index: 100;
|
|
}
|
|
|
|
.close-btn {
|
|
position: absolute;
|
|
top: -10px;
|
|
right: -10px;
|
|
}
|
|
</style>
|