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
50 lines (45 loc) · 1.09 KB
/
Copy pathAccordion.astro
File metadata and controls
50 lines (45 loc) · 1.09 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
48
49
50
---
import AccordionItem from "./AccordionItem.astro";
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;
if (items?.some((i) => typeof i.title !== "string" || !i.title.trim())) {
throw new Error("<Accordion> item has an empty title.");
}
const accordionId = items?.length
? `${variant}-${[...items.map((i) => i.title).join("")]
.slice(0, 7)
.map((c) => c.codePointAt(0))
.join("-")}`
: `${variant}-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>