This repository was archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathCollapsibleList.tsx
More file actions
60 lines (55 loc) · 1.77 KB
/
CollapsibleList.tsx
File metadata and controls
60 lines (55 loc) · 1.77 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
import { ReactElement, useState } from 'react';
import ExpandIcon from '../../icons/ui/ExpandIcon';
export interface CollapsibleListProps {
title: string | ReactElement;
titleExpanded?: ReactElement;
titleFont?: string;
children: ReactElement;
expanded?: boolean;
classNameExpanded?: string;
className?: string;
onChange?: (expanded: boolean) => void;
pinned?: ReactElement;
}
const CollapsibleList = ({ titleFont, ...props }: CollapsibleListProps) => {
const [expanded, setExpanded] = useState(props.expanded || false);
return (
<div
className={`transition-all ${
props.classNameExpanded && expanded
? props.classNameExpanded
: props.className
}`}
>
<div className="flex flex-row">
<div className="w-10/12 my-auto">
<div className="flex flex-row h-8">
<button
onClick={(e) => {
const newExpanded = !expanded;
setExpanded(newExpanded);
props.onChange && props.onChange(newExpanded);
}}
type="button"
style={{ width: 22, height: 22 }}
className={`flex hover:bg-circle-gray-250 border-white border rounded px-1`}
>
<ExpandIcon className="w-3 h-5 mx-auto" expanded={expanded} />
</button>
<h1
className={`mx-2 ${
titleFont ? titleFont : 'font-medium text-base'
} leading-6 tracking-wide`}
>
{props.title}
</h1>
</div>
{expanded && props.titleExpanded}
</div>
{expanded && props.pinned}
</div>
{expanded && <div className="ml-4">{props.children}</div>}
</div>
);
};
export default CollapsibleList;