Skip to content

Commit

Permalink
Use window-controls-overlay (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangasta authored Jun 4, 2024
1 parent 0e2b52d commit 7acf812
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 14 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist/
3 changes: 3 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
],
"start_url": "./index.html",
"display": "fullscreen",
"display_override": [
"window-controls-overlay"
],
"theme_color": "seagreen",
"background_color": "seagreen"
}
68 changes: 55 additions & 13 deletions src/components/Menu/Menu.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script lang="ts">
import { onMount } from "svelte";
import { actions } from "../../stores";
import Modal from "../Modal.svelte";
Expand All @@ -12,19 +14,47 @@
open = action === "open";
e.stopPropagation();
};
let menuEl: Element;
let belowTitlebar = "";
const handleResize = () => {
if (!(navigator as any).windowControlsOverlay?.visible) {

Check warning on line 21 in src/components/Menu/Menu.svelte

View workflow job for this annotation

GitHub Actions / Lint, test, and build

Unexpected any. Specify a different type
return;
}
const menuRect = menuEl.getBoundingClientRect();
const titlebarRect = (
navigator as any

Check warning on line 27 in src/components/Menu/Menu.svelte

View workflow job for this annotation

GitHub Actions / Lint, test, and build

Unexpected any. Specify a different type
).windowControlsOverlay?.getTitlebarAreaRect();
if (
titlebarRect.left > menuRect.left ||
titlebarRect.right < menuRect.right
) {
belowTitlebar = "below-titlebar";
} else {
belowTitlebar = "";
}
};
onMount(handleResize);
</script>

<div class="menu">
<IconButton icon={"Menu"} label={"Menu"} onClick={handleClick("open")} />
{#if $actions.help !== undefined}
<IconButton icon="Help" label="Help" onClick={$actions.help} />
{/if}
{#if $actions.shuffle !== undefined}
<IconButton icon="Shuffle" label="Shuffle" onClick={$actions.shuffle} />
{/if}
{#if $actions.undo !== undefined}
<IconButton icon="Undo" label="Undo" onClick={$actions.undo} />
{/if}
<svelte:window on:resize={handleResize} />
<div class="titlebar">
<div class="window-controls"></div>
<div bind:this={menuEl} class="menu {belowTitlebar}">
<IconButton icon={"Menu"} label={"Menu"} onClick={handleClick("open")} />
{#if $actions.help !== undefined}
<IconButton icon="Help" label="Help" onClick={$actions.help} />
{/if}
{#if $actions.shuffle !== undefined}
<IconButton icon="Shuffle" label="Shuffle" onClick={$actions.shuffle} />
{/if}
{#if $actions.undo !== undefined}
<IconButton icon="Undo" label="Undo" onClick={$actions.undo} />
{/if}
</div>
<div class="window-controls"></div>
</div>

{#if open}
Expand Down Expand Up @@ -71,9 +101,21 @@
{/if}

<style lang="sass">
.menu
.titlebar
app-region: drag
display: flex
margin-bottom: 0.25em
text-align: center
.window-controls
flex: 1
height: env(titlebar-area-height, auto)
.menu
app-region: no-drag
transition: margin-top 125ms
&.below-titlebar
margin-top: env(titlebar-area-height)
.drawer
display: flex
Expand Down
15 changes: 14 additions & 1 deletion src/components/Modal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@
open = false;
setTimeout(() => dispatch("close"), 125);
};
let windowControlsOnLeft =
(navigator as any).windowControlsOverlay?.visible &&

Check warning on line 42 in src/components/Modal.svelte

View workflow job for this annotation

GitHub Actions / Lint, test, and build

Unexpected any. Specify a different type
(navigator as any).windowControlsOverlay?.getTitlebarAreaRect().left > 0;

Check warning on line 43 in src/components/Modal.svelte

View workflow job for this annotation

GitHub Actions / Lint, test, and build

Unexpected any. Specify a different type
</script>

<div class="backdrop" class:open />
<div
class="modal {position}"
class="modal {position} {windowControlsOnLeft
? 'window-controls-on-left'
: ''}"
class:open
role="dialog"
aria-labelledby={titleId}
Expand Down Expand Up @@ -124,6 +130,13 @@
opacity: 1
transform: translateX(0)
&.window-controls-on-left
@media (display-mode: window-controls-overlay)
border-radius: 0 0.25em 0 0
height: calc(102vh - env(titlebar-area-height) - 1rem)
padding: 0 1em 2vh
top: calc(env(titlebar-area-height) + 1rem)
background: white
z-index: 4
Expand Down

0 comments on commit 7acf812

Please sign in to comment.