2020-11-11 00:00:54 +01:00
|
|
|
<script context="module">
|
|
|
|
// This makes sure new modals always show up on top of older modals. It is
|
|
|
|
// incremented every time a modal is shown
|
|
|
|
let global_index = 10000;
|
|
|
|
</script>
|
|
|
|
<script>
|
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
import { fade } from 'svelte/transition';
|
|
|
|
|
|
|
|
export let title = "";
|
|
|
|
export let width = "800px";
|
|
|
|
export let height = "auto";
|
|
|
|
let visible = false;
|
|
|
|
|
|
|
|
const load_bg = background => {
|
|
|
|
background.style.zIndex = global_index.valueOf();
|
|
|
|
global_index++;
|
|
|
|
}
|
|
|
|
const load_modal = modal => {
|
|
|
|
modal.style.width = width;
|
|
|
|
modal.style.height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
2021-10-26 22:15:01 +02:00
|
|
|
|
|
|
|
export const show = () => { set_visible(true) }
|
|
|
|
export const hide = () => { set_visible(false) }
|
|
|
|
export const toggle = () => { set_visible(!visible) }
|
|
|
|
export const set_visible = vis => {
|
|
|
|
visible = vis
|
|
|
|
dispatch("is_visible", visible)
|
2020-11-11 00:00:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const keydown = e => {
|
2021-11-27 16:42:41 +01:00
|
|
|
if (document.activeElement.type && document.activeElement.type === "text") {
|
|
|
|
return // Prevent shortcuts from interfering with input fields
|
|
|
|
}
|
2020-11-11 00:00:54 +01:00
|
|
|
if (e.key === 'Escape') {
|
2021-10-26 22:15:01 +02:00
|
|
|
set_visible(false);
|
2021-11-27 16:42:41 +01:00
|
|
|
e.preventDefault()
|
2020-11-11 00:00:54 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<svelte:window on:keydown={keydown}/>
|
|
|
|
|
|
|
|
{#if visible}
|
|
|
|
<div class="background" use:load_bg on:click={hide} transition:fade={{duration: 200}}>
|
|
|
|
<div class="window" use:load_modal on:click|stopPropagation role="dialog" aria-modal="true">
|
2022-01-04 15:55:20 +01:00
|
|
|
<div class="header">
|
2020-12-01 23:01:21 +01:00
|
|
|
<slot name="title">
|
|
|
|
<div class="title">{title}</div>
|
2021-08-17 18:24:21 +02:00
|
|
|
<button class="button button_red round" on:click={hide}>
|
2020-12-01 23:01:21 +01:00
|
|
|
<i class="icon">close</i>
|
|
|
|
</button>
|
|
|
|
</slot>
|
2020-11-11 00:00:54 +01:00
|
|
|
</div>
|
|
|
|
<div class="body">
|
|
|
|
<slot></slot>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.background {
|
|
|
|
position: fixed;
|
|
|
|
text-align: center;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
2022-01-18 20:58:57 +01:00
|
|
|
background-color: rgba(0, 0, 0, 0.6);
|
2020-11-11 00:00:54 +01:00
|
|
|
}
|
|
|
|
.window {
|
|
|
|
position: absolute;
|
|
|
|
z-index: inherit;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
background-color: var(--layer_2_color);
|
|
|
|
max-height: 100%;
|
|
|
|
max-width: 100%;
|
|
|
|
margin: 0 auto;
|
|
|
|
top: 20%;
|
|
|
|
left: 50%;
|
|
|
|
transform: translate(-50%, -20%);
|
|
|
|
padding: 0;
|
2022-01-03 14:02:50 +01:00
|
|
|
border-radius: 20px 20px 16px 16px;
|
2021-08-17 18:02:46 +02:00
|
|
|
overflow: hidden;
|
2020-11-11 00:00:54 +01:00
|
|
|
text-align: left;
|
|
|
|
}
|
|
|
|
.header {
|
|
|
|
flex-grow: 0;
|
|
|
|
flex-shrink: 0;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
padding: 1px;
|
2022-01-04 15:55:20 +01:00
|
|
|
background-color: var(--layer_1_color);
|
2022-01-17 17:40:03 +01:00
|
|
|
color: var(--layer_1_text_color);
|
2020-11-11 00:00:54 +01:00
|
|
|
}
|
|
|
|
.title {
|
|
|
|
flex-grow: 1;
|
|
|
|
flex-shrink: 1;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
font-size: 1.2em;
|
|
|
|
white-space: nowrap;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
2020-12-01 23:01:21 +01:00
|
|
|
.button {
|
2020-11-11 00:00:54 +01:00
|
|
|
flex-grow: 0;
|
|
|
|
flex-shrink: 0;
|
|
|
|
}
|
|
|
|
.body {
|
|
|
|
flex-grow: 1;
|
|
|
|
flex-shrink: 1;
|
|
|
|
overflow: auto;
|
|
|
|
}
|
|
|
|
</style>
|