2024-07-13 14:15:43 +01:00
|
|
|
<script lang="ts">
|
2024-07-18 12:22:29 +01:00
|
|
|
import { tick } from "svelte";
|
|
|
|
|
2024-07-13 14:15:43 +01:00
|
|
|
import { killDialog } from "$lib/dialogs";
|
2024-07-20 16:48:17 +01:00
|
|
|
import type { DialogButton, SmallDialogIcons } from "$lib/types/dialog";
|
2024-07-13 14:15:43 +01:00
|
|
|
|
2024-07-20 15:34:19 +01:00
|
|
|
import Meowbalt from "$components/misc/Meowbalt.svelte";
|
|
|
|
import type { MeowbaltEmotions } from "$lib/types/meowbalt";
|
2024-07-16 09:00:56 +01:00
|
|
|
|
2024-07-20 16:48:17 +01:00
|
|
|
import IconAlertTriangle from "@tabler/icons-svelte/IconAlertTriangle.svelte";
|
|
|
|
|
2024-07-13 14:15:43 +01:00
|
|
|
export let id: string;
|
2024-07-20 16:48:17 +01:00
|
|
|
export let meowbalt: MeowbaltEmotions | undefined;
|
|
|
|
export let icon: SmallDialogIcons | undefined;
|
2024-07-13 14:15:43 +01:00
|
|
|
export let title: string = "";
|
|
|
|
export let bodyText: string = "";
|
|
|
|
export let bodySubText: string = "";
|
|
|
|
export let buttons: DialogButton[];
|
|
|
|
|
|
|
|
let dialogParent: HTMLDialogElement;
|
|
|
|
|
2024-07-16 09:00:56 +01:00
|
|
|
let closing = false;
|
2024-07-18 12:22:29 +01:00
|
|
|
let open = false;
|
2024-07-16 09:00:56 +01:00
|
|
|
|
2024-07-13 14:15:43 +01:00
|
|
|
const close = () => {
|
|
|
|
if (dialogParent) {
|
2024-07-16 09:00:56 +01:00
|
|
|
closing = true;
|
2024-07-18 12:22:29 +01:00
|
|
|
open = false;
|
2024-07-16 09:00:56 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
dialogParent.close();
|
|
|
|
killDialog();
|
2024-07-20 13:49:51 +01:00
|
|
|
}, 150);
|
2024-07-13 14:15:43 +01:00
|
|
|
}
|
2024-07-16 09:00:56 +01:00
|
|
|
};
|
2024-07-13 14:15:43 +01:00
|
|
|
|
|
|
|
$: if (dialogParent) {
|
|
|
|
dialogParent.showModal();
|
2024-07-18 12:22:29 +01:00
|
|
|
tick().then(() => {
|
|
|
|
open = true;
|
2024-07-20 13:49:51 +01:00
|
|
|
});
|
2024-07-13 14:15:43 +01:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2024-07-18 12:22:29 +01:00
|
|
|
<dialog id="dialog-{id}" bind:this={dialogParent} class:closing class:open>
|
2024-07-16 09:00:56 +01:00
|
|
|
<div class="dialog-body small-dialog" class:meowbalt-visible={meowbalt}>
|
2024-07-20 15:34:19 +01:00
|
|
|
{#if meowbalt}
|
2024-07-16 09:00:56 +01:00
|
|
|
<div class="meowbalt-container">
|
2024-07-20 15:34:19 +01:00
|
|
|
<Meowbalt emotion={meowbalt} />
|
2024-07-16 09:00:56 +01:00
|
|
|
</div>
|
2024-07-13 14:15:43 +01:00
|
|
|
{/if}
|
2024-07-16 09:00:56 +01:00
|
|
|
<div class="popup-body">
|
2024-07-20 16:48:17 +01:00
|
|
|
{#if title || icon}
|
|
|
|
<div class="popup-header">
|
|
|
|
{#if icon === "warn-red"}
|
|
|
|
<div class="popup-icon {icon}">
|
|
|
|
<IconAlertTriangle />
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
{#if title}
|
|
|
|
<h2>{title}</h2>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
{/if}
|
2024-07-16 09:00:56 +01:00
|
|
|
{#if bodyText}
|
|
|
|
<div class="body-text" tabindex="-1">{bodyText}</div>
|
|
|
|
{/if}
|
|
|
|
{#if bodySubText}
|
|
|
|
<div class="subtext">{bodySubText}</div>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
<div class="popup-buttons">
|
|
|
|
{#each buttons as button}
|
|
|
|
<button
|
2024-07-20 16:48:17 +01:00
|
|
|
class="button popup-button {button.color}"
|
2024-07-16 09:00:56 +01:00
|
|
|
class:active={button.main}
|
|
|
|
on:click={async () => {
|
2024-07-13 14:15:43 +01:00
|
|
|
await button.action();
|
|
|
|
close();
|
2024-07-16 09:00:56 +01:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{button.text}
|
|
|
|
</button>
|
|
|
|
{/each}
|
|
|
|
</div>
|
2024-07-13 14:15:43 +01:00
|
|
|
</div>
|
2024-07-16 09:00:56 +01:00
|
|
|
|
2024-07-21 08:41:14 +01:00
|
|
|
<div id="dialog-backdrop-close" aria-hidden="true" on:click={() => close()}></div>
|
2024-07-13 14:15:43 +01:00
|
|
|
</dialog>
|
|
|
|
|
|
|
|
<style>
|
2024-07-16 09:00:56 +01:00
|
|
|
dialog {
|
|
|
|
display: flex;
|
2024-07-18 12:22:29 +01:00
|
|
|
flex-direction: column;
|
2024-07-16 09:00:56 +01:00
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
background: none;
|
|
|
|
|
|
|
|
max-height: 100%;
|
|
|
|
max-width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
border: none;
|
|
|
|
pointer-events: all;
|
|
|
|
|
|
|
|
inset-inline-start: unset;
|
|
|
|
inset-inline-end: unset;
|
|
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog:modal {
|
|
|
|
inset-block-start: 0;
|
|
|
|
inset-block-end: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog:modal::backdrop {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2024-07-20 15:34:19 +01:00
|
|
|
.small-dialog,
|
|
|
|
.popup-body {
|
2024-07-16 09:00:56 +01:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
gap: var(--padding);
|
2024-07-20 15:34:19 +01:00
|
|
|
}
|
|
|
|
|
2024-07-20 16:48:17 +01:00
|
|
|
.popup-body {
|
|
|
|
gap: 8px;
|
|
|
|
}
|
|
|
|
|
2024-07-20 15:34:19 +01:00
|
|
|
.small-dialog {
|
|
|
|
--small-dialog-padding: 18px;
|
2024-07-20 16:48:17 +01:00
|
|
|
|
|
|
|
align-items: center;
|
|
|
|
text-align: center;
|
2024-07-16 09:00:56 +01:00
|
|
|
max-width: 340px;
|
2024-07-20 13:49:51 +01:00
|
|
|
width: calc(
|
|
|
|
100% - var(--padding) * 2 - var(--small-dialog-padding) * 2
|
|
|
|
);
|
2024-07-16 09:00:56 +01:00
|
|
|
background: var(--popup-bg);
|
2024-07-20 13:49:51 +01:00
|
|
|
box-shadow:
|
|
|
|
0 0 0 2px var(--popup-stroke) inset,
|
|
|
|
0 0 60px 10px var(--popup-bg);
|
|
|
|
padding: var(--small-dialog-padding);
|
2024-07-16 09:00:56 +01:00
|
|
|
margin: var(--padding);
|
|
|
|
border-radius: 29px;
|
|
|
|
position: relative;
|
|
|
|
will-change: transform;
|
|
|
|
}
|
|
|
|
|
2024-07-18 12:22:29 +01:00
|
|
|
.open .small-dialog {
|
|
|
|
animation: modal-in 0.35s;
|
|
|
|
}
|
|
|
|
|
|
|
|
.closing .small-dialog {
|
|
|
|
animation: modal-out 0.15s;
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
|
2024-07-16 09:00:56 +01:00
|
|
|
.small-dialog.meowbalt-visible {
|
2024-07-20 15:34:19 +01:00
|
|
|
padding-top: calc(var(--padding) * 4);
|
2024-07-16 09:00:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.meowbalt-container {
|
|
|
|
position: absolute;
|
2024-07-20 15:34:19 +01:00
|
|
|
top: -120px;
|
|
|
|
}
|
|
|
|
|
2024-07-20 16:48:17 +01:00
|
|
|
.popup-header h2 {
|
2024-07-20 15:34:19 +01:00
|
|
|
color: var(--secondary);
|
2024-07-20 16:48:17 +01:00
|
|
|
font-size: 19px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.popup-header .popup-icon.warn-red :global(svg) {
|
|
|
|
stroke-width: 1.5px;
|
|
|
|
height: 50px;
|
|
|
|
width: 50px;
|
|
|
|
stroke: var(--red);
|
2024-07-16 09:00:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.body-text {
|
|
|
|
font-size: 14.5px;
|
|
|
|
font-weight: 500;
|
|
|
|
line-height: 1.7;
|
|
|
|
color: var(--gray);
|
2024-07-17 09:50:35 +01:00
|
|
|
user-select: text;
|
|
|
|
-webkit-user-select: text;
|
2024-07-16 09:00:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.body-text:focus-visible {
|
|
|
|
box-shadow: none !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.popup-buttons {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
width: 100%;
|
2024-07-20 13:49:51 +01:00
|
|
|
gap: calc(var(--padding) / 2);
|
2024-07-20 16:48:17 +01:00
|
|
|
overflow: scroll;
|
|
|
|
border-radius: var(--border-radius);
|
2024-07-16 09:00:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.popup-button {
|
|
|
|
width: 100%;
|
|
|
|
height: 40px;
|
|
|
|
}
|
|
|
|
|
2024-07-20 16:48:17 +01:00
|
|
|
.popup-button.red {
|
|
|
|
background-color: var(--red);
|
2024-07-20 16:56:43 +01:00
|
|
|
color: var(--white);
|
2024-07-20 16:48:17 +01:00
|
|
|
}
|
|
|
|
|
2024-07-20 15:34:19 +01:00
|
|
|
.popup-button:not(.active) {
|
|
|
|
background-color: var(--button-elevated);
|
|
|
|
}
|
|
|
|
|
2024-07-20 16:48:17 +01:00
|
|
|
.popup-button:not(.active):active {
|
|
|
|
background-color: var(--button-elevated-hover);
|
|
|
|
}
|
|
|
|
|
2024-07-20 15:34:19 +01:00
|
|
|
.popup-button:not(:focus-visible) {
|
|
|
|
box-shadow: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
@media (hover: hover) {
|
|
|
|
.popup-button:not(.active):hover {
|
|
|
|
background-color: var(--button-elevated-hover);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-21 08:41:14 +01:00
|
|
|
#dialog-backdrop-close {
|
2024-07-18 12:22:29 +01:00
|
|
|
position: inherit;
|
2024-07-16 09:00:56 +01:00
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
z-index: -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@keyframes modal-in {
|
|
|
|
from {
|
|
|
|
transform: scale(0.8);
|
|
|
|
opacity: 0;
|
|
|
|
}
|
2024-07-18 12:22:29 +01:00
|
|
|
30% {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
2024-07-16 09:00:56 +01:00
|
|
|
50% {
|
|
|
|
transform: scale(1.005);
|
|
|
|
}
|
|
|
|
100% {
|
|
|
|
transform: scale(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@keyframes modal-out {
|
|
|
|
from {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
to {
|
|
|
|
opacity: 0;
|
|
|
|
transform: scale(0.9);
|
|
|
|
visibility: hidden;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@media screen and (max-width: 535px) {
|
|
|
|
dialog {
|
2024-07-18 12:22:29 +01:00
|
|
|
justify-content: end;
|
2024-07-16 09:00:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.small-dialog {
|
|
|
|
margin-bottom: calc(var(--padding) + env(safe-area-inset-bottom));
|
|
|
|
box-shadow: 0 0 0 2px var(--popup-stroke) inset;
|
|
|
|
}
|
2024-07-18 12:22:29 +01:00
|
|
|
|
|
|
|
.open .small-dialog {
|
|
|
|
animation: modal-in-mobile 0.4s;
|
|
|
|
}
|
|
|
|
|
|
|
|
@keyframes modal-in-mobile {
|
|
|
|
from {
|
|
|
|
transform: translateY(200px);
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
30% {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
50% {
|
|
|
|
transform: translateY(-5px);
|
|
|
|
}
|
|
|
|
100% {
|
|
|
|
transform: translateY(0px);
|
|
|
|
}
|
|
|
|
}
|
2024-07-13 14:15:43 +01:00
|
|
|
}
|
|
|
|
</style>
|