forked from mattkenney/wildebeest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccordion.tsx
32 lines (28 loc) · 929 Bytes
/
Accordion.tsx
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
import { component$, Slot, useSignal } from '@builder.io/qwik'
type Props = {
title: string
}
export const Accordion = component$<Props>(({ title }) => {
const headerId = useSignal(
`accordion-${title.replace(/\s/g, '_')}-${`${Math.round(Math.random() * 99999)}`.padStart(5, '0')}`
).value
const expanded = useSignal(false)
return (
<div class="bg-wildebeest-600 border border-wildebeest-700 rounded overflow-hidden">
<header id={headerId} class=" bg-wildebeest-700 text-wildebeest-vibrant-400">
<button
class="py-4 px-5 text-start w-full flex items-center"
onClick$={() => (expanded.value = !expanded.value)}
>
<i class={`fa-solid fa-chevron-${expanded.value ? 'down' : 'right'} mr-3 text-xl`}></i>
<span class="font-semibold">{title}</span>
</button>
</header>
{expanded.value && (
<section aria-labelledby={headerId}>
<Slot />
</section>
)}
</div>
)
})