|
1 | 1 | --- |
2 | 2 | import { getCollection } from "astro:content"; |
3 | | -import Button from "@/components/Button.astro"; |
4 | 3 | import Tag from "@/components/Tag.astro"; |
5 | 4 | import LinkList from "@/components/LinkList.astro"; |
6 | 5 | import type { LinkListItem } from "@/components/LinkList.astro"; |
@@ -55,38 +54,54 @@ const linkListItems: LinkListItem[] = posts.map((post) => { |
55 | 54 | --- |
56 | 55 |
|
57 | 56 | <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]"> |
59 | 58 | <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> |
80 | 95 | </div> |
81 | 96 | </header> |
82 | 97 |
|
83 | 98 | <LinkList items={linkListItems} columns={["code", "date", "title"]} variant="grid" gap="normal" /> |
84 | 99 | </Layout> |
85 | 100 |
|
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; |
91 | 106 | } |
92 | | -</script> |
| 107 | +</style> |
0 commit comments