Skip to content

Commit 84023d9

Browse files
committed
use shadow dom for settings
1 parent 24995c7 commit 84023d9

File tree

7 files changed

+43
-41
lines changed

7 files changed

+43
-41
lines changed

components/pw-nav.html

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
<patchwork-nav>
2+
<template shadowrootmode="open">
3+
<slot></slot>
4+
</template>
25
<nav class="Grid | Nav" id="nav" popover>
36
<pw-button icon label="Close Menu" classes="{{['Hamburger']}}" popovertarget="nav" popovertargetaction="hide">
47
<ssr-fragment slot="icon"><icon-close /></ssr-fragment>
58
</pw-button>
69
<pw-menu id="nav-menu" menu="{{menu}}" />
7-
<pw-button icon id="settings-button" label="Settings" popovertarget="settings" popovertargetaction="toggle">
10+
<pw-button disabled icon id="settings-button" label="Settings" popovertarget="settings" popovertargetaction="toggle">
811
<ssr-fragment slot="icon"><icon-config /></ssr-fragment>
912
</pw-button>
10-
<div id="settings" class="Nav__settings" popover>
11-
<div class="Button-group jc-end">
12-
<p class="small space-xs mi-end">Theme</p>
13-
<pw-button disabled id="settings-light" label="Light" />
14-
<pw-button disabled id="settings-dark" label="Dark" />
15-
</div>
16-
</div>
1713
</nav>
1814
</patchwork-nav>
1915

16+
<template id="settings-template">
17+
<div id="settings" popover>
18+
<div class="Button-group jc-end">
19+
<p class="small space-xs mi-end">Theme</p>
20+
<pw-button disabled id="settings-light" label="Light" />
21+
<pw-button disabled id="settings-dark" label="Dark" />
22+
</div>
23+
</div>
24+
</template>
25+
2026
<ssr-fragment portal="head">
2127
<script type="module" src="/scripts/patchwork-nav.js?v={{deployHash}}"></script>
2228
</ssr-fragment>

deno.jsonc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
},
77
"imports": {
88
"@dbushell/carriageway": "jsr:@dbushell/carriageway@^1.1.0",
9-
"@dbushell/hyperserve": "jsr:@dbushell/hyperserve@^0.19.0",
10-
"@std/async": "jsr:@std/async@^1.0.7",
9+
"@dbushell/hyperserve": "jsr:@dbushell/hyperserve@^0.20.0",
10+
"@std/async": "jsr:@std/async@^1.0.8",
1111
"@std/fs": "jsr:@std/fs@^1.0.5",
1212
"@std/http": "jsr:@std/http@^1.0.9",
13-
"@std/path": "jsr:@std/path@^1.0.7",
14-
"lightningcss": "npm:lightningcss@^1.27.0"
13+
"@std/path": "jsr:@std/path@^1.0.8",
14+
"lightningcss": "npm:lightningcss@^1.28.1"
1515
}
1616
}

routes/props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const GET = () => {
77
const props = {
88
"header": {
99
"heading": "Patchwork",
10-
"tag": "2.2",
10+
"tag": "2.3",
1111
"menu": [
1212
{
1313
"name": "Home",

static/app.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/css/components/nav.css

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,30 @@
2323
}
2424
}
2525

26-
.Nav__settings {
26+
#settings-button {
27+
anchor-name: --settings;
28+
}
29+
30+
#settings {
31+
position-anchor: --settings;
2732
background: var(--color-bg-2);
2833
border-radius: var(--radius-2);
2934
border: var(--border-size-1) solid var(--color-bg-4);
3035
inset: 0;
3136
margin: auto;
3237
padding: var(--size-2) var(--size-3);
3338

34-
&[style*='--inset'] {
35-
inset: calc(var(--size-3) + (1px * var(--inset-top)))
36-
calc(1px * var(--inset-right)) auto auto;
39+
@supports (inset: anchor(end)) {
40+
margin: 0;
41+
inset: auto;
42+
inset-block-start: calc(anchor(end) + var(--size-3));
43+
inset-inline-end: anchor(end);
3744
}
38-
}
3945

40-
@supports not selector(:popover-open) {
41-
.Nav__settings {
42-
&[style*='--inset'] {
43-
inset-block-start: calc(var(--size-3) + var(--button-height));
44-
inset-inline-end: 0;
46+
@supports not (inset: anchor(end)) {
47+
&::backdrop {
48+
background-color: oklch(0% 0 0 / 0.4);
49+
backdrop-filter: blur(2px);
4550
}
4651
}
4752
}
@@ -57,7 +62,7 @@
5762
}
5863
}
5964

60-
.Nav__settings {
65+
#settings {
6166
display: contents;
6267
}
6368
}
@@ -87,7 +92,7 @@
8792
}
8893

8994
@supports not selector(:popover-open) {
90-
.Nav__settings {
95+
#settings {
9196
&:not(.\:popover-open) {
9297
display: none;
9398
}

static/css/components/tooltip.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
border: var(--border-size-1) solid var(--color-secondary);
55
padding: var(--size-3);
66

7-
@supports (inset: anchor(end)) {
7+
@supports (position-area: end) {
88
margin-inline: 0;
99
margin-block: var(--size-2);
1010
max-inline-size: calc(100% - var(--size-5));
@@ -21,6 +21,7 @@
2121
#tooltip-anchor-1 {
2222
anchor-name: --tooltip1;
2323
}
24+
2425
#tooltip-1 {
2526
position-anchor: --tooltip1;
2627
}

static/scripts/patchwork-nav.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ export class Component extends HTMLElement {
33
#theme = "";
44
#themes = new Set(["light", "dark"]);
55
#navOpen = false;
6-
#settingsTop = 0;
7-
#settingsRight = 0;
86

97
get theme() {
108
return this.#theme;
@@ -47,6 +45,10 @@ export class Component extends HTMLElement {
4745
}
4846

4947
connectedCallback() {
48+
const settings = document.querySelector("#settings-template").content
49+
.cloneNode(true);
50+
this.nav.append(settings);
51+
this.settingsButton.disabled = false;
5052
this.nav.addEventListener("beforetoggle", (ev) => {
5153
this.#navOpen = ev.newState === "open";
5254
});
@@ -61,9 +63,6 @@ export class Component extends HTMLElement {
6163
globalThis.addEventListener("resize", () => {
6264
this.#onResize();
6365
}, { passive: true });
64-
globalThis.addEventListener("scroll", () => {
65-
this.#updateSettings();
66-
}, { passive: true });
6766
this.#onResize();
6867
this.theme = document.documentElement.getAttribute("data-theme") ??
6968
globalThis.localStorage.getItem("theme") ?? "";
@@ -77,7 +76,6 @@ export class Component extends HTMLElement {
7776
}
7877

7978
#onResize() {
80-
this.#updateSettings();
8179
if (this.#navOpen) {
8280
const display = globalThis.getComputedStyle(this.nav).display;
8381
if (display !== "grid") {
@@ -86,14 +84,6 @@ export class Component extends HTMLElement {
8684
}
8785
}
8886

89-
#updateSettings() {
90-
const bounds = this.settingsButton.getBoundingClientRect();
91-
this.#settingsTop = bounds.bottom;
92-
this.#settingsRight = globalThis.innerWidth - bounds.right;
93-
this.settings.style.setProperty("--inset-top", this.#settingsTop);
94-
this.settings.style.setProperty("--inset-right", this.#settingsRight);
95-
}
96-
9787
#updateTheme() {
9888
this.settingsLight.disabled = this.theme === "light";
9989
this.settingsDark.disabled = this.theme === "dark";

0 commit comments

Comments
 (0)