Files
archtika/web-app/src/lib/components/Modal.svelte

61 lines
1.3 KiB
Svelte
Raw Normal View History

2024-08-02 15:33:18 +02:00
<script lang="ts">
import type { Snippet } from "svelte";
2024-09-13 17:04:04 +02:00
const {
children,
id,
text,
isWider = false
}: { children: Snippet; id: string; text: string; isWider?: boolean } = $props();
2024-08-24 21:53:05 +02:00
2024-08-24 21:57:41 +02:00
const modalId = `${id}-modal`;
2024-08-02 15:33:18 +02:00
</script>
2024-08-24 21:53:05 +02:00
<a href={`#${modalId}`} role="button">{text}</a>
2024-08-02 15:33:18 +02:00
2024-09-13 17:04:04 +02:00
<div id={modalId} class="modal" style="--modal-width: {isWider ? 600 : 300}px">
2024-08-02 15:33:18 +02:00
<div class="modal__content">
{@render children()}
<a href="#!" role="button">Close</a>
</div>
<a href="#!" class="modal__closeoverlay" aria-label="Close modal"></a>
</div>
<style>
.modal {
position: fixed;
inset: 0;
display: none;
}
.modal:target {
display: flex;
flex-direction: column;
align-items: center;
padding: var(--space-s);
2024-08-02 15:33:18 +02:00
}
.modal__closeoverlay {
position: fixed;
inset: 0;
z-index: 10;
background-color: rgba(0, 0, 0, 0.5);
}
.modal__content {
display: flex;
flex-direction: column;
gap: var(--space-s);
padding-inline: var(--space-s);
padding-block: var(--space-m);
2024-08-02 15:33:18 +02:00
background-color: var(--bg-primary);
border-radius: var(--border-radius);
border: var(--border-primary);
2024-09-13 17:04:04 +02:00
inline-size: var(--modal-width);
max-inline-size: 100%;
max-block-size: calc(100vh - var(--space-m));
overflow-y: auto;
2024-08-02 15:33:18 +02:00
z-index: 20;
}
</style>