Skip to content

Commit fc8b587

Browse files
committed
feat: 目次コンポーネントを追加
1 parent 4c6f152 commit fc8b587

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

website/src/components/templates/BaseTemplate.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import type { FC, PropsWithChildren } from "hono/jsx";
22
import type { Page } from "../../types/model";
3-
import { SiteNoticeBanner, Footer, Breadcrumbs } from "../ui/common/";
3+
import {
4+
SiteNoticeBanner,
5+
Footer,
6+
Breadcrumbs,
7+
TableOfContents,
8+
} from "../ui/common/";
49

510
export type BaseTemplateProps = PropsWithChildren<{
611
page: Page;
@@ -397,19 +402,7 @@ export const BaseTemplate: FC<BaseTemplateProps> = ({
397402
)}
398403
</main>
399404

400-
{outline.length > 0 && (
401-
<nav id="page-overview">
402-
<strong>目次</strong>
403-
<ul>
404-
{outline.map((item, idx) => (
405-
<li data-assoc={item.id}>
406-
<a href={`#${item.id}`}>{item.name}</a>
407-
<ul></ul>
408-
</li>
409-
))}
410-
</ul>
411-
</nav>
412-
)}
405+
<TableOfContents outline={outline} />
413406
</div>
414407

415408
<Footer />
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { OutlineItem } from "../../../types/model";
2+
3+
export type TableOfContentsProps = {
4+
outline: OutlineItem[];
5+
};
6+
7+
export const TableOfContents = ({ outline }: TableOfContentsProps) => {
8+
if (outline.length === 0) {
9+
return null;
10+
}
11+
12+
return (
13+
<nav
14+
id="page-overview"
15+
class="flex-none w-full md:w-60 lg:w-72 mt-6 mb-8 px-3.5 py-3 border border-neutral-200/60 rounded-md bg-white sticky top-0 h-screen overflow-auto"
16+
>
17+
<strong class="block mb-2 text-xs text-neutral-500 font-semibold tracking-wide">
18+
目次
19+
</strong>
20+
<ol class="space-y-1 text-xs text-neutral-700">
21+
{outline.map((item) => (
22+
<li key={item.id} data-assoc={item.id}>
23+
<a
24+
href={`#${item.id}`}
25+
class="block px-2 py-1 rounded hover:bg-neutral-100 transition-colors"
26+
>
27+
{item.name}
28+
</a>
29+
</li>
30+
))}
31+
</ol>
32+
</nav>
33+
);
34+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { SiteNoticeBanner } from "./SiteNoticeBanner";
22
export { Breadcrumbs, type BreadcrumbsProps } from "./Breadcrumbs";
3+
export { TableOfContents, type TableOfContentsProps } from "./TableOfContents";
34
export { Footer } from "./Footer";

0 commit comments

Comments
 (0)