Files
classroomio/src/lib/components/Modal/index.svelte
T

70 lines
1.6 KiB
Svelte
Raw Normal View History

2021-07-17 22:29:12 +03:00
<script>
2021-07-22 08:04:48 +03:00
import { afterUpdate } from 'svelte';
2021-07-17 22:29:12 +03:00
import CloseButton from '../Buttons/Close/index.svelte';
2021-08-18 19:47:02 +03:00
export let open = false;
export let onClose = () => {};
export let modalHeading = '';
export let width = '';
2021-08-26 13:35:56 +03:00
export let maxWidth = '';
2021-08-18 19:47:02 +03:00
export let containerClass = '';
2023-06-17 19:11:29 +00:00
export let size = '';
2021-07-22 08:04:48 +03:00
afterUpdate(() => {
if (open) {
2023-07-15 19:45:04 +00:00
if (!document) return;
2021-07-22 08:04:48 +03:00
document.getElementsByTagName('body')[0].style.overflow = 'hidden';
} else {
2023-07-15 19:45:04 +00:00
if (!document) return;
2021-07-22 08:04:48 +03:00
document.getElementsByTagName('body')[0].style.overflow = 'auto';
}
});
2021-07-17 22:29:12 +03:00
</script>
{#if open}
<div
class="dialog fixed overflow-x-hidden overflow-y-auto inset-0 flex justify-center items-center z-50 bg-gray-100 bg-opacity-50"
2021-12-30 22:30:30 +02:00
on:click={onClose}
role="presentation"
2021-07-17 22:29:12 +03:00
>
<div aria-hidden="true" class="backdrop" />
<div
2023-06-17 19:11:29 +00:00
class="{maxWidth || 'container'} {size === 'sm'
? 'small'
: ''} bg-white dark:bg-gray-800 mx-auto {width} shadow-lg p-5 pt-2 rounded-md"
2021-12-30 22:30:30 +02:00
on:click={(e) => e.stopPropagation()}
role="presentation"
2021-08-18 19:47:02 +03:00
>
2021-07-17 22:29:12 +03:00
<div class="flex items-center justify-between mb-4">
<h3 class="dark:text-white text-xl m-0">
2021-07-17 22:29:12 +03:00
{modalHeading}
</h3>
<div class="rounded-full">
<CloseButton onClick={onClose} contained={true} size="small" />
</div>
2021-07-17 22:29:12 +03:00
</div>
2023-06-17 19:11:29 +00:00
<div class="body p-1 h-4/5 overflow-y-auto {containerClass}">
2021-07-22 08:04:48 +03:00
<slot />
</div>
</div>
</div>
2021-07-17 22:29:12 +03:00
{/if}
<style>
.dialog {
background-color: rgba(0, 0, 0, 0.5);
}
2021-08-18 19:47:02 +03:00
.container {
max-width: 1000px;
}
2021-07-22 08:04:48 +03:00
.body {
max-height: 60vh;
}
2023-06-17 19:11:29 +00:00
.small {
max-width: 388px;
}
2021-07-17 22:29:12 +03:00
</style>