mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-08 20:40:46 +00:00
feat: add modal component
This commit is contained in:
parent
d0112c2bdc
commit
1ce667c981
1 changed files with 49 additions and 0 deletions
49
frontend/src/lib/components/Modal.svelte
Normal file
49
frontend/src/lib/components/Modal.svelte
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
const close = () => dispatch('close');
|
||||||
|
|
||||||
|
let modal: HTMLElement;
|
||||||
|
|
||||||
|
const handleKeydown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:window on:keydown={handleKeydown} />
|
||||||
|
|
||||||
|
<div class="modalBackground" on:keydown on:click={close} />
|
||||||
|
|
||||||
|
<div class="modal" role="dialog" aria-modal="true" bind:this={modal}>
|
||||||
|
<slot name="header" />
|
||||||
|
<hr />
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.modalBackground {
|
||||||
|
@apply fixed;
|
||||||
|
@apply top-0 left-0;
|
||||||
|
@apply h-full w-full;
|
||||||
|
background: rgba(0, 0, 0, 0.3);
|
||||||
|
|
||||||
|
@apply z-20;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal {
|
||||||
|
@apply absolute;
|
||||||
|
@apply left-1/2 top-1/2;
|
||||||
|
@apply w-[calc(100vw - 4em)]
|
||||||
|
@apply p-4;
|
||||||
|
@apply rounded-md;
|
||||||
|
@apply transform:
|
||||||
|
translate(-50%, -50%) overflow-auto;
|
||||||
|
@apply bg-white;
|
||||||
|
|
||||||
|
@apply z-50;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Loading…
Reference in a new issue