1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-19 13:27:58 +00:00
rolens/frontend/src/components/modal.svelte

127 lines
2.4 KiB
Svelte
Raw Normal View History

2023-01-19 07:41:09 +00:00
<script context="module">
let numberOfModalsOpen = 0;
</script>
2023-01-10 16:28:27 +00:00
<script>
import { fade, fly } from 'svelte/transition';
import Icon from './icon.svelte';
export let show = false;
export let title = undefined;
export let contentPadding = true;
2023-01-18 19:59:00 +00:00
export let width = '80vw';
2023-01-21 09:27:52 +00:00
export let overflow = true;
2023-01-15 11:04:36 +00:00
2023-01-19 07:41:09 +00:00
const level = numberOfModalsOpen + 1;
let isNew = true;
$: if (show) {
numberOfModalsOpen++;
}
else if (!isNew) {
numberOfModalsOpen--;
}
else {
isNew = false;
}
2023-01-15 11:04:36 +00:00
function keydown(event) {
2023-01-19 07:41:09 +00:00
if ((event.key === 'Escape') && (level === numberOfModalsOpen)) {
event.preventDefault();
2023-01-15 11:04:36 +00:00
show = false;
}
}
2023-01-10 16:28:27 +00:00
</script>
<svelte:window on:keydown={keydown} />
2023-01-15 11:04:36 +00:00
2023-01-10 16:28:27 +00:00
{#if show}
2023-02-16 19:19:04 +00:00
<div class="modal outer" transition:fade>
<div class="inner" style:max-width={width || '80vw'} transition:fly={{ y: -100 }}>
2023-01-15 15:49:08 +00:00
{#if title}
<header>
2023-01-10 16:28:27 +00:00
<div class="title">{title}</div>
2023-01-17 10:04:04 +00:00
<button class="btn close" on:click={() => show = false} title="close" type="button">
2023-01-15 15:49:08 +00:00
<Icon name="x" />
</button>
</header>
{/if}
2023-01-21 09:27:52 +00:00
<div class="slot content" class:padded={contentPadding} class:overflow> <slot /> </div>
2023-01-15 15:49:08 +00:00
{#if $$slots.footer}
<footer> <slot name="footer" /> </footer>
2023-01-10 16:28:27 +00:00
{/if}
</div>
</div>
{/if}
<style>
.outer {
position: fixed;
display: flex;
z-index: 100;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: rgba(0, 0, 0, 0.5);
margin: 0;
2023-01-16 15:56:16 +00:00
padding-top: 50px;
2023-01-10 16:28:27 +00:00
}
2023-01-18 10:26:28 +00:00
:global(#root.platform-darwin) .outer {
2023-01-17 08:07:53 +00:00
margin-top: var(--darwin-titlebar-height);
2023-01-16 15:56:16 +00:00
}
2023-01-10 16:28:27 +00:00
.inner {
max-height: 80vh;
background-color: #fff;
margin-left: auto;
margin-right: auto;
margin-bottom: auto;
width: 100%;
border-radius: 10px;
display: flex;
2023-01-10 19:10:39 +00:00
flex-flow: column;
2023-01-10 16:28:27 +00:00
cursor: auto;
}
.inner > :global(*:first-child) {
margin-top: 0;
}
.inner > :global(*:last-child) {
margin-bottom: 0;
}
header {
display: flex;
align-items: center;
padding: 1rem;
}
header .title {
font-size: 1.5rem;
}
.close {
margin-left: auto;
}
.content {
max-height: 100%;
}
2023-01-21 09:27:52 +00:00
.content.overflow {
overflow-y: auto;
}
2023-01-15 11:02:17 +00:00
.content.padded {
padding: 1rem;
}
header + .content.padded {
border-top: 1px solid #ccc;
}
2023-01-10 16:28:27 +00:00
footer {
padding: 1rem;
border-top: 1px solid #ccc;
}
</style>