-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathSidebarSection.tsx
More file actions
72 lines (66 loc) · 1.89 KB
/
SidebarSection.tsx
File metadata and controls
72 lines (66 loc) · 1.89 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"use client";
import React from "react";
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/components/ui/accordion";
import SidebarButton from "./SidebarButton";
interface SidebarSectionProps {
label: string;
data: { label: string; value: string }[];
selected: string[];
updater: (newVal: string[]) => void;
openItem: string | undefined;
setOpenItem: (val: string | undefined) => void;
}
const SidebarSection: React.FC<SidebarSectionProps> = ({
label,
data,
selected,
updater,
openItem,
setOpenItem,
}) => {
return (
<div className="flex w-full flex-col items-baseline justify-between border-b-2 border-[#36266d] px-[10px]">
<Accordion
className="w-full"
type="single"
collapsible
value={openItem}
onValueChange={setOpenItem}
>
<AccordionItem
className="border-none"
value={label} // ✅ IMPORTANT: stable value
>
<AccordionTrigger className="w-full">
<div className="font-play text-sm">{label}</div>
</AccordionTrigger>
<AccordionContent>
<div className="my-2 flex w-full flex-wrap items-center">
{data.map((item) => (
<SidebarButton
key={item.value}
selected={selected.includes(item.value)}
onClick={() => {
const newValues = selected.includes(item.value)
? selected.filter((v) => v !== item.value)
: [...selected, item.value];
updater(newValues);
}}
className="mb-2 mr-2"
>
{item.label}
</SidebarButton>
))}
</div>
</AccordionContent>
</AccordionItem>
</Accordion>
</div>
);
};
export default SidebarSection;