summaryrefslogtreecommitdiffstats
path: root/apps/web-shared/src/components/blowout-toolbelt.svelte
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-06-12 14:39:37 +0200
committerivarlovlie <git@ivarlovlie.no>2022-06-12 14:39:37 +0200
commit39735309b2f2831ea8fe94104139fa0e9f6ace56 (patch)
treeec2a281646053dfbfeeaeb8f2a9d1ccaeddccb7c /apps/web-shared/src/components/blowout-toolbelt.svelte
parentba9f3b475dcde1cbf8bff87f9eec9654c17e70a4 (diff)
downloadgreatoffice-39735309b2f2831ea8fe94104139fa0e9f6ace56.tar.xz
greatoffice-39735309b2f2831ea8fe94104139fa0e9f6ace56.zip
refactor: Close blowout toolbelt on escape or click outside of [data-blowout-toolbelt-element]
Diffstat (limited to 'apps/web-shared/src/components/blowout-toolbelt.svelte')
-rw-r--r--apps/web-shared/src/components/blowout-toolbelt.svelte20
1 files changed, 19 insertions, 1 deletions
diff --git a/apps/web-shared/src/components/blowout-toolbelt.svelte b/apps/web-shared/src/components/blowout-toolbelt.svelte
index 2927d70..b83048c 100644
--- a/apps/web-shared/src/components/blowout-toolbelt.svelte
+++ b/apps/web-shared/src/components/blowout-toolbelt.svelte
@@ -1,4 +1,5 @@
<script>
+ import { onMount } from "svelte";
import ThemeSwitcher from "./theme-switcher.svelte";
import ThemeSwitcherIcon from "./theme-switcher-icon.svelte";
import LocaleSwitcher from "./locale-switcher.svelte";
@@ -15,6 +16,19 @@
show: false,
selection: "system"
};
+
+ onMount(() => {
+ document.addEventListener("keydown", (e) => {
+ if (e.code === "Escape") {
+ expanded = false;
+ }
+ });
+ document.addEventListener("click", (e) => {
+ if (e.target.closest("[data-blowout-toolbelt-element]") === null) {
+ expanded = false;
+ }
+ });
+ });
</script>
<style>
.blowout {
@@ -25,21 +39,25 @@
right: 0 !important;
}
</style>
-<aside class="blowout position-fixed bg-light inner-glow shadow-xs padding-xxs bottom-50% right-0 z-index-popover {expanded ? 'expanded' : ''}">
+<aside class="blowout position-fixed bg-light inner-glow shadow-xs padding-xxs bottom-50% right-0 z-index-popover {expanded ? 'expanded' : ''}" data-blowout-toolbelt-element>
<LocaleSwitcher bind:show="{localeSwitcher.show}"
glow="{false}"
+ data-blowout-toolbelt-element
bind:selection="{localeSwitcher.selection}"/>
<ThemeSwitcher bind:show="{themeSwitcher.show}"
glow="{false}"
+ data-blowout-toolbelt-element
bind:selection="{themeSwitcher.selection}"/>
<div class="flex flex-row gap-sm justify-end">
{#if !expanded}
<div class="flex ld-switch-btn"
+ data-blowout-toolbelt-element
on:click={() => expanded = true}>
<ChevronsLeftIcon/>
</div>
{:else}
<div class="flex ld-switch-btn"
+ data-blowout-toolbelt-element
on:click={() => expanded = false}>
<ChevronsRightIcon/>
</div>