Updated the 'Popup' component to be more friendly closed.

This commit is contained in:
Yohan Boujon 2025-04-16 12:57:13 +02:00
parent 1fba9c2620
commit 1d3673cdf7
5 changed files with 81 additions and 14 deletions

View file

@ -1,6 +1,9 @@
<script>
import "$lib/css/popup.css";
import { popupComponent } from "$lib/ts/popup.ts";
import { get } from "svelte/store";
import SvgIcon from "@jamescoyle/svelte-icon";
import { mdiClose } from "@mdi/js";
let component = null;
@ -11,16 +14,52 @@
function close() {
popupComponent.set(null);
}
function onKeyDown(e) {
if (get(popupComponent) != null && e.key === "Escape") {
close();
}
}
</script>
<svelte:window on:keydown|preventDefault={onKeyDown} />
{#if component}
<div
class="on-popup"
role="alertdialog"
tabindex="0"
on:keydown={(e) => {
if (e.key === "Escape") {
close();
}
}}
>
<div class="flex align-center">
<div
class="flex-end popup-close"
role="button"
tabindex="0"
on:click={close}
on:keydown={(e) => {
if (e.key === "Escape") {
close();
}
}}
>
<SvgIcon type="mdi" path={mdiClose} size="35" />
</div>
</div>
<svelte:component this={component.component} {...component.props} />
</div>
<div
class="popup"
role="button"
tabindex="0"
tabindex="-1"
on:click={close}
on:keydown={(e) => e.key === "Escape" && close()}
>
<svelte:component this={component.component} {...component.props} />
</div>
on:keydown={(e) => {
if (e.key === "Escape") {
close();
}
}}
></div>
{/if}

View file

@ -42,6 +42,7 @@ h2 {
--background-light: linear-gradient(180deg, rgba(248, 241, 241, 1) 0%, rgba(15, 11, 17, 0.1) 100%);
--background-dark: linear-gradient(180deg, rgba(248, 241, 241, 1) 0%, rgba(224, 217, 217, 1) 100%);
--background-purple: linear-gradient(to right, #241d25c4 0%, #3d2b47c4 100%);
--shadow: rgba(79, 50, 93, 0.25) 0px 30px 60px -12px, rgba(0, 0, 0, 0.3) 0px 18px 36px -18px;
--shadow-hover: rgba(43, 33, 48, 0.5) 0px 22px 70px 4px;
--shadow-active: #2c1235a0 0px 20px 30px -10px;
@ -50,6 +51,7 @@ h2 {
--z-index-front: 1;
--z-index-navbar: 2;
--z-index-popup: 3;
--z-index-on-popup: 4;
--border-min: 0.5rem;
--border-max: 2rem;

View file

@ -116,11 +116,6 @@
/* Pop-up Hover Card */
.hover-card-popup-container {
width: calc(100% - 12rem);
height: calc(100% - 12rem);
margin: 5rem;
padding: 1rem;
background-image: var(--background-dark);
border-radius: 1rem;
box-shadow: var(--shadow);
width: 100%;
height: 100%;
}

View file

@ -145,7 +145,7 @@ a {
/* Floating */
.floating {
background-image: linear-gradient(to right, #241d25c4 0%, #3d2b47c4 100%);
background-image: var(--background-purple);
box-shadow: rgba(52, 42, 58, 0.25) 0px 50px 100px -20px, rgba(0, 0, 0, 0.3) 0px 30px 60px -30px;
border-bottom-left-radius: 2rem;
border-bottom-right-radius: 2rem;

View file

@ -12,4 +12,35 @@
z-index: var(--z-index-popup);
-webkit-backdrop-filter: var(--popup-blur);
backdrop-filter: var(--popup-blur);
}
}
.on-popup {
width: 80dvw;
height: 80dvh;
position: fixed;
left: 10dvw;
top: 10dvh;
z-index: var(--z-index-on-popup);
padding: 1.2rem;
background-image: var(--background-dark);
border-radius: 1rem;
box-shadow: var(--shadow);
}
.popup-close {
cursor: pointer;
border-radius: 100%;
}
.popup-close svg {
border-radius: 100%;
padding: 0.3rem;
transition: var(--transition);
color: var(--color-text);
}
.popup-close svg:hover {
background-color: var(--color-text);
color: var(--color-background);
box-shadow: var(--shadow-hover);
}