Skip to content

Commit dc5327a

Browse files
committed
Add glassmorphism effect to header with theme support
Introduced a JavaScript function to apply a glassmorphism effect to the header, dynamically adjusting styles based on the current theme. CSS for the header's background and border was removed in favor of this JS-driven approach, and a MutationObserver ensures the effect updates on theme changes.
1 parent ccc85bf commit dc5327a

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

src/components/Header.astro

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,37 @@ import Default from '@astrojs/starlight/components/Header.astro';
1919
}
2020
}
2121

22+
function applyGlassmorphism() {
23+
const header = document.querySelector('header.header') as HTMLElement;
24+
if (header) {
25+
const isDark = document.documentElement.dataset.theme !== 'light';
26+
header.style.backdropFilter = 'blur(10px) saturate(180%)';
27+
header.style.setProperty('-webkit-backdrop-filter', 'blur(10px) saturate(180%)');
28+
header.style.background = isDark
29+
? 'rgba(12, 10, 9, 0.7)'
30+
: 'rgba(255, 255, 255, 0.7)';
31+
header.style.borderBottom = isDark
32+
? '1px solid rgba(255, 255, 255, 0.1)'
33+
: '1px solid rgba(0, 0, 0, 0.1)';
34+
}
35+
}
36+
37+
// Watch for theme changes
38+
const observer = new MutationObserver((mutations) => {
39+
mutations.forEach((mutation) => {
40+
if (mutation.attributeName === 'data-theme') {
41+
applyGlassmorphism();
42+
}
43+
});
44+
});
45+
observer.observe(document.documentElement, { attributes: true });
46+
2247
addDashboardLink();
23-
document.addEventListener('astro:page-load', addDashboardLink);
48+
applyGlassmorphism();
49+
document.addEventListener('astro:page-load', () => {
50+
addDashboardLink();
51+
applyGlassmorphism();
52+
});
2453
</script>
2554

2655
<style is:global>

src/styles/custom.css

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -313,31 +313,9 @@ pre[data-bash-prompt] > code {
313313
}
314314

315315
header.header {
316-
/* Fallback for browsers without backdrop-filter */
317-
background: oklch(0.18 0.005 49.25) !important;
318316
border-bottom-color: var(--sl-color-hairline);
319317
}
320318

321-
@supports (backdrop-filter: blur(1px)) {
322-
header.header {
323-
background: oklch(0.147 0.004 49.25 / 70%) !important;
324-
backdrop-filter: blur(10px) saturate(180%);
325-
-webkit-backdrop-filter: blur(10px) saturate(180%);
326-
border-bottom: 1px solid oklch(1 0 0 / 10%);
327-
}
328-
}
329-
330-
[data-theme='light'] header.header {
331-
background: oklch(1 0 0) !important;
332-
}
333-
334-
@supports (backdrop-filter: blur(1px)) {
335-
[data-theme='light'] header.header {
336-
background: oklch(1 0 0 / 70%) !important;
337-
border-bottom: 1px solid oklch(0 0 0 / 10%);
338-
}
339-
}
340-
341319
/* Table styling */
342320
table {
343321
width: 100%;

0 commit comments

Comments
 (0)