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

73 lines
1.3 KiB
Svelte
Raw Normal View History

2023-10-08 22:38:42 +00:00
<script lang="ts">
import { onMount } from 'svelte';
2024-02-22 10:54:55 +00:00
import { fade } from 'svelte/transition';
2023-10-08 22:38:42 +00:00
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 {
2024-02-21 21:29:59 +00:00
return 'w-[44rem]';
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-22 14:20:48 +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"
2024-02-23 08:47:54 +00:00
in:fade={{ duration: 10 }}
2024-02-23 09:21:22 +00:00
on:click={() => {
show = false;
}}
2023-10-08 22:38:42 +00:00
>
<div
2024-02-25 21:45:24 +00:00
class=" modal-content m-auto rounded-2xl max-w-full {sizeToWidth(
2024-01-06 04:59:56 +00:00
size
)} mx-2 bg-gray-50 dark:bg-gray-900 shadow-3xl"
2024-02-23 08:47:54 +00:00
in:fade={{ duration: 10 }}
2023-10-08 22:38:42 +00:00
on:click={(e) => {
e.stopPropagation();
}}
>
<slot />
</div>
</div>
{/if}
2024-02-22 14:20:48 +00:00
<style>
.modal-content {
animation: scaleUp 0.1s ease-out forwards;
}
@keyframes scaleUp {
from {
2024-02-23 09:23:06 +00:00
transform: scale(0.985);
2024-02-22 14:20:48 +00:00
opacity: 0;
}
to {
transform: scale(1);
opacity: 1;
}
}
</style>