Skip to content

Commit 9fa5cb6

Browse files
committed
refac: separate components
1 parent a033cb4 commit 9fa5cb6

31 files changed

+156
-159
lines changed

contents/banner.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
type Banner = {
2-
shown: boolean;
3-
kind: "notify" | "error";
4-
long: string;
5-
short: string;
6-
link: string;
7-
linkText?: string;
8-
};
1+
import type { Banner } from "+/schema.ts";
92
const banner: Banner = {
103
shown: true,
114
kind: "notify",

src/components/ActivityPage/Layout.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
import { Picture } from "astro:assets";
3-
import JoinUsCTA from "+/components/JoinUsCTA.astro";
3+
import JoinUsCTA from "+/components/common/JoinUsCTA.astro";
44
import GlobalLayout from "+/layouts/GlobalLayout.astro";
55
import { Focus } from "+/schema";
66
import type { ImageMetadata } from "astro";

src/components/Header.astro

Lines changed: 0 additions & 126 deletions
This file was deleted.

src/components/Header/Banner.astro

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
import type { Banner } from "+/schema.ts";
3+
import { Icon } from "astro-icon/components";
4+
5+
interface Props {
6+
banner: Banner;
7+
}
8+
const { banner } = Astro.props;
9+
---
10+
11+
<div
12+
id="banner"
13+
class:list={[
14+
"flex items-center justify-center gap-4 px-1 py-2",
15+
banner.kind === "error" ? "bg-red-300" : "bg-green-300",
16+
]}
17+
>
18+
<span class="hidden md:inline">{banner.long}</span>
19+
<span aria-hidden class="sm:text-md inline text-center text-sm md:hidden">
20+
{banner.short}
21+
</span>
22+
<a
23+
href={banner.link}
24+
class="md:text-md inline-flex flex-shrink-0 items-center gap-0.5 text-sm hover:underline"
25+
rel={banner.link.startsWith("/") ? undefined : "noreferrer"}
26+
target={banner.link.startsWith("/") ? undefined : "_blank"}
27+
data-astro-prefetch="viewport"
28+
>
29+
{banner.linkText ?? "詳細はこちら"}
30+
<Icon name="feather:arrow-right" />
31+
</a>
32+
</div>

src/components/Header/NavBar.astro

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
import Logo from "+/components/utils/Logo.astro";
3+
import HamburgerButton from "+/islands/svelte/hamburger-button.svelte";
4+
import { Focus } from "+/schema.ts";
5+
6+
type Props = {
7+
links: { href: string; title: string; focus: Focus }[];
8+
focus: Focus;
9+
};
10+
const { links, focus }: Props = Astro.props;
11+
---
12+
13+
<div class="flex h-16 bg-gray-50/70 backdrop-blur-lg">
14+
<a
15+
href="/"
16+
aria-label="Go to top page"
17+
class="flex items-center px-4"
18+
data-astro-prefetch="viewport"
19+
>
20+
<Logo class="w-36 sm:ml-8" variant="default" />
21+
</a>
22+
<div aria-hidden="true" class="flex-1"></div>
23+
<nav class="hidden md:flex">
24+
{
25+
links.map((link) => (
26+
<a
27+
href={link.href}
28+
class:list={[
29+
"navigation-bar flex h-full min-w-24 items-center justify-center px-6 text-center text-sm",
30+
focus === link.focus ? "current" : "",
31+
]}
32+
data-astro-prefetch="viewport"
33+
>
34+
{link.title}
35+
</a>
36+
))
37+
}
38+
</nav>
39+
<div class="md:hidden">
40+
<HamburgerButton {links} />
41+
</div>
42+
</div>
43+
44+
<style>
45+
.navigation-bar {
46+
background: linear-gradient(black 0 0) bottom left/
47+
var(--underline-width, 0%) 0.09rem no-repeat;
48+
text-decoration: none;
49+
}
50+
.navigation-bar.current {
51+
background: linear-gradient(lawngreen 0 0) bottom left/
52+
var(--underline-width, 0%) 0.15rem no-repeat;
53+
}
54+
.navigation-bar:hover {
55+
--underline-width: 100%;
56+
@starting-style {
57+
--underline-width: 0%;
58+
}
59+
}
60+
@media not (prefers-reduced-motion) {
61+
.navigation-bar {
62+
transition: background-size 0.5s;
63+
}
64+
}
65+
</style>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2+
import ActionButton from "+/components/utils/ActionButton.astro";
3+
import Logo from "+/components/utils/Logo.astro";
24
import { Icon } from "astro-icon/components";
3-
import ActionButton from "./ActionButton.astro";
4-
import Logo from "./Logo.astro";
55
---
66

77
<footer class="bg-base-content text-base-200 p-18">

src/components/common/Header.astro

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
import Banner from "+/components/Header/Banner.astro";
3+
import NavBar from "+/components/Header/NavBar.astro";
4+
import { Focus } from "+/schema.ts";
5+
import banner from "+contents/banner.ts";
6+
7+
const links = [
8+
{ title: "プロジェクト", href: "/projects", focus: Focus.projects },
9+
{ title: "記事", href: "/articles", focus: Focus.articles },
10+
{ title: "メンバー", href: "/members", focus: Focus.members },
11+
{ title: "参加", href: "/join", focus: Focus.join },
12+
{ title: "About", href: "/about", focus: Focus.about },
13+
];
14+
15+
interface Props {
16+
focus: Focus;
17+
}
18+
const { focus } = Astro.props;
19+
---
20+
21+
<header class="sticky top-0 z-20 w-full">
22+
{banner.shown && <Banner banner={banner} />}
23+
<NavBar links={links} focus={focus} />
24+
</header>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import ActionButton from "./ActionButton.astro";
2+
import ActionButton from "+/components/utils/ActionButton.astro";
33
interface Props {
44
class?: string;
55
}

0 commit comments

Comments
 (0)