open-webui/src/lib/components/common/Modal.svelte

55 lines
1.1 KiB
Svelte
Raw Normal View History

2023-10-08 22:38:42 +00:00
<script lang="ts">
import { onMount } from 'svelte';
import { fade, blur } from 'svelte/transition';
export let show = true;
2024-01-06 04:59:56 +00:00
export let size = 'md';
2023-10-08 22:38:42 +00:00
let mounted = false;
2024-01-06 04:59:56 +00:00
const sizeToWidth = (size) => {
2024-01-18 05:01:30 +00:00
if (size === 'xs') {
return 'w-[16rem]';
} else if (size === 'sm') {
2024-01-06 04:59:56 +00:00
return 'w-[30rem]';
} else {
return 'w-[42rem]';
2024-01-06 04:59:56 +00:00
}
};
2023-10-08 22:38:42 +00:00
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
2024-02-08 01:55:19 +00:00
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"
2023-10-08 22:38:42 +00:00
on:click={() => {
show = false;
}}
>
<div
2024-01-06 04:59:56 +00:00
class="m-auto rounded-xl max-w-full {sizeToWidth(
size
)} mx-2 bg-gray-50 dark:bg-gray-900 shadow-3xl"
2023-10-08 22:38:42 +00:00
transition:fade={{ delay: 100, duration: 200 }}
on:click={(e) => {
e.stopPropagation();
}}
>
<slot />
</div>
</div>
{/if}