forked from monero-project/monero-site
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccordion.astro
More file actions
47 lines (42 loc) · 1.04 KB
/
Copy pathAccordion.astro
File metadata and controls
47 lines (42 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
---
import AccordionItem from "./AccordionItem.astro";
import { stableId } from "@/utils/stableId";
export interface AccordionItemType {
title: string;
content: string;
}
export interface Props {
items?: AccordionItemType[];
multiExpand?: boolean;
variant?: "default" | "card";
}
const { items, multiExpand = false, variant = "default" } = Astro.props;
const titles = items?.map((i) => i.title) ?? [];
if (titles.some((t) => !t.trim())) {
throw new Error("<Accordion> item has an empty title.");
}
const accordionId = `${variant}-${titles.length ? stableId(titles) : "slot"}`;
const accordionName = multiExpand ? undefined : `accordion-${accordionId}`;
---
<div class:list={["accordion", `accordion--${variant}`]}>
{
items ? (
items.map((item) => (
<AccordionItem
title={item.title}
content={item.content}
variant={variant}
name={accordionName}
/>
))
) : (
<slot />
)
}
</div>
<style>
.accordion {
display: flex;
flex-direction: column;
}
</style>