1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <script lang="ts">
- import { onMount } from 'svelte';
- import { fade } from 'svelte/transition';
- import { flyAndScale } from '$lib/utils/transitions';
- export let show = true;
- export let size = 'md';
- let mounted = false;
- const sizeToWidth = (size) => {
- if (size === 'xs') {
- return 'w-[16rem]';
- } else if (size === 'sm') {
- return 'w-[30rem]';
- } else {
- return 'w-[44rem]';
- }
- };
- onMount(() => {
- mounted = true;
- });
- $: if (mounted) {
- if (show) {
- document.body.style.overflow = 'hidden';
- } else {
- document.body.style.overflow = 'unset';
- }
- }
- </script>
- {#if show}
- <!-- svelte-ignore a11y-click-events-have-key-events -->
- <!-- svelte-ignore a11y-no-static-element-interactions -->
- <div
- class=" fixed top-0 right-0 left-0 bottom-0 bg-black/60 w-full min-h-screen h-screen flex justify-center z-50 overflow-hidden overscroll-contain"
- in:fade={{ duration: 10 }}
- on:click={() => {
- show = false;
- }}
- >
- <div
- class=" m-auto rounded-2xl max-w-full {sizeToWidth(
- size
- )} mx-2 bg-gray-50 dark:bg-gray-900 shadow-3xl"
- in:flyAndScale
- on:click={(e) => {
- e.stopPropagation();
- }}
- >
- <slot />
- </div>
- </div>
- {/if}
- <style>
- .modal-content {
- animation: scaleUp 0.1s ease-out forwards;
- }
- @keyframes scaleUp {
- from {
- transform: scale(0.985);
- opacity: 0;
- }
- to {
- transform: scale(1);
- opacity: 1;
- }
- }
- </style>
|