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

120 lines
2.2 KiB
Svelte
Raw Normal View History

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-15 11:04:36 +00:00
function keydown(event) {
if (event.key === 'Escape') {
show = false;
}
}
2023-01-10 16:28:27 +00:00
</script>
2023-01-15 11:04:36 +00:00
<svelte:window on:keydown={keydown} />
2023-01-10 16:28:27 +00:00
{#if show}
2023-01-15 11:02:17 +00:00
<div class="modal outer" on:mousedown|self={() => show = false} transition:fade>
2023-01-10 16:28:27 +00:00
<div class="inner" 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-15 15:49:08 +00:00
<button class="btn close" on:click={() => show = false} title="close">
<Icon name="x" />
</button>
</header>
{/if}
2023-01-15 11:02:17 +00:00
<div class="slot content" class:padded={contentPadding}> <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
cursor: pointer;
}
2023-01-16 15:56:16 +00:00
:global(#app.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-width: 80vw;
max-height: 80vh;
background-color: #fff;
margin-left: auto;
margin-right: auto;
margin-bottom: auto;
width: 100%;
border-radius: 10px;
2023-01-15 11:02:17 +00:00
overflow: hidden;
2023-01-10 16:28:27 +00:00
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 {
border-bottom: 1px solid #ccc;
display: flex;
align-items: center;
padding: 1rem;
}
header .title {
font-size: 1.5rem;
}
.close {
margin-left: auto;
}
.content {
overflow-y: auto;
max-height: 100%;
}
2023-01-15 11:02:17 +00:00
.content.padded {
padding: 1rem;
}
2023-01-10 16:28:27 +00:00
footer {
padding: 1rem;
border-top: 1px solid #ccc;
}
@media (max-width: 600px) {
.outer {
padding: 0;
}
.inner {
max-width: 100%;
max-height: 100%;
width: 100%;
margin-top: auto;
margin-bottom: 0;
}
}
</style>