Skip to content

Commit dfe0ab4

Browse files
authored
Collapse blog tag filters (#289)
1 parent 5838fb5 commit dfe0ab4

1 file changed

Lines changed: 43 additions & 28 deletions

File tree

src/pages/blog/index.astro

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
import { getCollection } from "astro:content";
3-
import Button from "@/components/Button.astro";
43
import Tag from "@/components/Tag.astro";
54
import LinkList from "@/components/LinkList.astro";
65
import type { LinkListItem } from "@/components/LinkList.astro";
@@ -55,38 +54,54 @@ const linkListItems: LinkListItem[] = posts.map((post) => {
5554
---
5655

5756
<Layout title="Blog - Just Be">
58-
<header class="mb-2 flex justify-between">
57+
<header class="relative mb-2 flex flex-wrap items-start gap-[1ch]">
5958
<h1 class="font-bold">~/blog</h1>
60-
<div class="flex flex-wrap items-center gap-2">
61-
{
62-
selectedTag ? (
63-
<>
64-
<Tag
65-
tag={selectedTag}
66-
count={tagCounts.get(selectedTag)}
67-
url="/blog"
68-
class="invert"
69-
id="selected-tag"
70-
description={tagDescriptions.get(selectedTag)}
71-
/>
72-
<Button shortcut="c" label="clear" href="/blog" />
73-
</>
74-
) : (
75-
sortedTags.map(({ tag, count }) => (
76-
<Tag tag={tag} count={count} url="/blog" description={tagDescriptions.get(tag)} />
77-
))
78-
)
79-
}
59+
<div class="tag-filter flex">
60+
<button
61+
type="button"
62+
class="text-fg-2 flex cursor-pointer items-center gap-[0.5ch] border-none bg-transparent p-0 text-sm"
63+
aria-label={selectedTag ? `Filter by tag: ${selectedTag}` : "Filter by tag"}
64+
title="Filter by tag"
65+
>
66+
<div class="i-pixel-tag" aria-hidden="true"></div>
67+
<span>{selectedTag ?? sortedTags.length}</span>
68+
</button>
69+
<div class="tag-list absolute left-0 top-full z-10 hidden pt-1">
70+
<div class="bg-1 flex max-w-full flex-wrap gap-0 p-1">
71+
{
72+
selectedTag && (
73+
<a
74+
href="/blog"
75+
class="text-accent hocus:bg-0 hocus:invert flex items-center border-2 border-fg-0 px-[1ch] font-medium outline-none"
76+
>
77+
clear
78+
</a>
79+
)
80+
}
81+
{
82+
sortedTags.map(({ tag, count }) => (
83+
<Tag
84+
tag={tag}
85+
count={count}
86+
url="/blog"
87+
class={selectedTag === tag ? "invert" : undefined}
88+
id={selectedTag === tag ? "selected-tag" : undefined}
89+
description={tagDescriptions.get(tag)}
90+
/>
91+
))
92+
}
93+
</div>
94+
</div>
8095
</div>
8196
</header>
8297

8398
<LinkList items={linkListItems} columns={["code", "date", "title"]} variant="grid" gap="normal" />
8499
</Layout>
85100

86-
<script>
87-
// Focus selected tag on page load
88-
const selectedTag = document.getElementById("selected-tag");
89-
if (selectedTag) {
90-
selectedTag.focus();
101+
<style>
102+
.tag-filter:hover .tag-list,
103+
.tag-filter:focus-within .tag-list,
104+
.tag-list:hover {
105+
display: block;
91106
}
92-
</script>
107+
</style>

0 commit comments

Comments
 (0)