Skip to content

Commit 6f3e5e0

Browse files
hyphapre-commit-ci[bot]egeakman
authored
Make accordion styling as a component (#996)
While working on the accordion styling for session types in [PR #989](#989), it became clear that extracting it into a reusable component would make things easier for the team. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ege Akman <me@egeakman.dev>
1 parent 47b222c commit 6f3e5e0

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
export interface Props {
3+
title: string;
4+
id: string;
5+
}
6+
7+
const { title, id } = Astro.props;
8+
---
9+
10+
<details class="group mb-4">
11+
<summary
12+
aria-expanded="false"
13+
aria-controls={id}
14+
class="cursor-pointer flex justify-between p-2 rounded-md border-t border-b focus:ring-2"
15+
>
16+
<span class="font-semibold">{title}</span>
17+
<span aria-hidden="true" class="group-open:hidden">+</span>
18+
<span aria-hidden="true" class="group-open:block hidden">−</span>
19+
</summary>
20+
21+
<div id={id} class="pl-4">
22+
<slot />
23+
</div>
24+
</details>

src/content/pages/test.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,22 @@ Barking up the right tree
270270

271271
## YouTube
272272
<YouTube id="j5a0jTc9S10" alt="Mood lifter" />
273+
274+
## Accordion
275+
#### What do the dogs say?
276+
277+
<Accordion title="Spanish-speaking dogs" id="spanish">
278+
**Guau guau!**
279+
</Accordion>
280+
281+
<Accordion title="Italian-speaking dogs" id="italian">
282+
*Bau bau!*
283+
</Accordion>
284+
285+
<Accordion title="Japanese-speaking dogs" id="japanese">
286+
ワンワン
287+
</Accordion>
288+
289+
<Accordion title="Finnish-speaking dogs" id="finnish">
290+
***Hau hau!***
291+
</Accordion>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import BenefitsList from "../components/benefits-list/benefits-list.astro";
1212
import BenefitItem from "../components/benefits-list/benefit-item.astro";
1313
import { Note } from "../components/note";
1414
import { SponsorTiers } from "../components/sponsor-tiers";
15+
import Accordion from "../components/accordion/accordion.astro";
1516
1617
export async function getStaticPaths() {
1718
const posts = await getCollection("pages");
@@ -44,6 +45,7 @@ const description = post.data.subtitle;
4445
Note,
4546
SponsorTiers,
4647
hr: Separator,
48+
Accordion
4749
}}
4850
/>
4951
</Prose>

0 commit comments

Comments
 (0)