Skip to content

Commit a9fb516

Browse files
committed
Make accordion styling as a component
1 parent 1e2ef8f commit a9fb516

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { clsx } from "clsx";
2+
3+
export const Accordion = ({
4+
title,
5+
children,
6+
id,
7+
}: {
8+
title: string;
9+
children: React.ReactNode;
10+
id: string;
11+
}) => {
12+
return (
13+
<details className="group mb-4">
14+
<summary
15+
aria-expanded="false"
16+
aria-controls={id}
17+
className={clsx(
18+
"cursor-pointer flex justify-between p-2 rounded-md border-t border-b focus:ring-2"
19+
)}
20+
>
21+
<span className="font-semibold">{title}</span>
22+
<span aria-hidden="true" className="group-open:hidden">+</span>
23+
<span aria-hidden="true" className="group-open:block hidden"></span>
24+
</summary>
25+
26+
<div id={id} className="pl-4">{children}</div>
27+
</details>
28+
);
29+
};

src/components/accordion/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Accordion } from "./accordion";

src/pages/[...slug].astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import BenefitItem from "../components/benefits-list/benefit-item.astro";
1414
import { ButtonWithTitle } from "../components/button-with-title";
1515
import { Note } from "../components/note";
1616
import { SponsorTiers } from "../components/sponsor-tiers";
17+
import { Accordion } from "../components/accordion";
1718
1819
export async function getStaticPaths() {
1920
const posts = await getCollection("pages");
@@ -48,6 +49,7 @@ const description = post.data.subtitle;
4849
Note,
4950
SponsorTiers,
5051
hr: Separator,
52+
Accordion
5153
}}
5254
/>
5355
</Prose>

0 commit comments

Comments
 (0)