Skip to content

Commit 82f83d4

Browse files
committed
Enhance "traffic control" of z-indexes
so layout components play nice to each other when overlaps to each other
1 parent bda15bf commit 82f83d4

File tree

7 files changed

+66
-38
lines changed

7 files changed

+66
-38
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
// this is a component that makes it easy to provide unobtrusive side nav bars
3+
// with builtin visual feedback when sidebar is being treated with more priority
4+
// than the main contents
5+
6+
import LinkToHome from './LinkToHome.astro';
7+
---
8+
9+
<!-- optionally appear from large screen -->
10+
<aside class="absolute top-0 left-0 w-full lt-lg:hidden bg-transparent">
11+
<!-- "invisible" to act as a placeholder while the real one is coming from ./Header.astro -->
12+
<header class="py-2.5 invisible">
13+
<LinkToHome />
14+
</header>
15+
<div class="flex">
16+
<div class="flex-1 flex">
17+
<div class="grow"></div>
18+
<div class="w-48 xl:w-60 relative">
19+
<!-- slot for "left" side -->
20+
<!-- expose group-hover for the slot -->
21+
<!-- prettier-ignore -->
22+
<div
23+
class="w-48 xl:w-60 fixed hover:z-20 group h-full hover:bg-white/80 empty:hidden"
24+
><slot name="left" /></div>
25+
</div>
26+
</div>
27+
<!-- placeholder to represent the main content-->
28+
<div class="w-prose"></div>
29+
<div class="flex-1 flex">
30+
<div class="w-48 xl:w-60 relative">
31+
<!-- slot for "right" side -->
32+
<!-- expose group-hover for the slot -->
33+
<!-- prettier-ignore -->
34+
<div
35+
class="w-48 xl:w-60 fixed hover:z-20 group h-full hover:bg-white/80 empty:hidden"
36+
><slot name="right" /></div>
37+
</div>
38+
<div class="grow"></div>
39+
</div>
40+
</div>
41+
</aside>

src/components/app/LinkToHome.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
---
33

4-
<a href="/" class="flex items-center">
4+
<a href="/" class="flex items-center w-fit p-2 -m-2">
55
<div class="i-bi-0-square text-yellow-500 text-xl"></div>
66
<div class="i-bi-1-square-fill text-yellow-400 text-xl mr-1"></div>
77
<h1 class="text-lg font-medium">Bizarre Binary</h1>

src/components/app/SideNavs.astro

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import LinkToHome from './LinkToHome.astro';
2+
import AuxiliaryFrame from './AuxiliaryFrame.astro';
33
const path = Astro.url.pathname.replace(/\/$/, '');
44
55
const allToys = await Astro.glob('../../pages/toys/*.mdx');
@@ -14,34 +14,20 @@ const pathMatchesUrl = (url: string) => {
1414
};
1515
---
1616

17-
<!-- -z-10 is important to be not blocking interactivity on the main components as this components expands to full screen -->
18-
<aside class="fixed top-0 left-0 h-full w-full flex lt-lg:hidden -z-10">
19-
<div class="flex-1 flex">
20-
<div class="grow"></div>
21-
<!-- main -->
22-
<div class="w-48 xl:w-60 text-gray-500">
23-
<!-- "invisible" to act as a place holder while the real one is coming from ./Header.astro -->
24-
<header class="py-2.5 sticky top-0 w-full invisible">
25-
<LinkToHome />
26-
</header>
27-
<!-- safe list class="text-gray-800" -->
28-
<nav class="px-3">
29-
<h2 class="mt-10 my-2 font-bold text-gray-500">Toys</h2>
30-
<ul class="text-sm">
31-
{
32-
allToys.map((toy) => (
33-
<li class="truncate">
34-
<a href={toy.url} class={toy.url && pathMatchesUrl(toy.url) ? 'text-gray-800' : ''}>
35-
{toy.frontmatter.title}
36-
</a>
37-
</li>
38-
))
39-
}
40-
</ul>
41-
</nav>
42-
</div>
43-
</div>
44-
<!-- place holder to represent the actual content-->
45-
<div class="w-prose"></div>
46-
<div class="flex-1"></div>
47-
</aside>
17+
<AuxiliaryFrame>
18+
<nav slot="left" class="mt-10 px-3">
19+
<h2 class="my-2 font-bold text-gray-500">Toys</h2>
20+
<!-- safe list class="text-gray-800" -->
21+
<ul class="text-sm text-gray-500">
22+
{
23+
allToys.map((toy) => (
24+
<li class="truncate hover:text-gray-700">
25+
<a href={toy.url} class={toy.url && pathMatchesUrl(toy.url) ? 'text-gray-800' : ''}>
26+
{toy.frontmatter.title}
27+
</a>
28+
</li>
29+
))
30+
}
31+
</ul>
32+
</nav>
33+
</AuxiliaryFrame>

src/components/parts/Bits.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Take an integer and represent that as a series of bits
106106

107107
<!-- safelist class="text-lg text-xs py-0.5 [&:nth-child(8n+5)]:border-l-0 hover:outline" -->
108108
<table class="table-auto border-collapse">
109-
<thead class="bg-slate-50">
109+
<thead class="bg-slate-100/50">
110110
<tr class:hidden={hideHeader}>
111111
{#each sups as sup, idx (reverseIdx(idx))}
112112
<th

src/components/parts/Digits.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Take an integer and represent that as a series of numbers with a base
9090
</div>
9191
<!-- safe list class="text-sm even:border-l-0" -->
9292
<table class="table-auto border-collapse" class:text-sm={compact}>
93-
<thead class="bg-slate-50">
93+
<thead class="bg-slate-100/50">
9494
<tr>
9595
{#each sups as sup, idx (reverseIdx(idx))}
9696
<th

src/layouts/Layout.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ const description = titleFromProps ? `${defaultTitle} - ${title}` : title;
3232
<GlobalStyle />
3333
<PWA />
3434
</head>
35-
<body class="m-auto max-w-prose px-2 md:px-0 flex flex-col [min-height:100svh] overflow-x-hidden">
35+
<body class="m-auto max-w-prose px-2 md:px-0 [min-height:100svh]">
3636
<Header sticky={true} />
3737
<SideNavs />
38-
<main>
38+
<!-- apply relative so that main is on top of other fixed components like SideNavs -->
39+
<main class="relative">
3940
<slot />
4041
</main>
4142
<div class="grow"></div>

src/layouts/Post.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const formattedDate = dates.map((date, idx) => `${prefixes[idx]} ${date}`).join(
3636
<Layout title={title}>
3737
<!-- .prose seems to with weird gap without margin so mitigate that with `-my-[n]` -->
3838
<article class="prose -my-3">
39-
<h1 class="text-3xl sm:text-4xl mb-3">{title}</h1>
39+
<h1 class="sticky top-0 z-10 text-3xl sm:text-4xl mb-3">{title}</h1>
4040
{
4141
!toy && (
4242
<small class="text-slate">

0 commit comments

Comments
 (0)