blob: 2d21b619d65b4ce6dd2862fe7ced4c58845116a8 (
plain)
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
|
import { faChevronDown, faChevronUp } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import React, { useState } from "react";
import BorderedContainer from "./BorderedContainer";
type Props = {
caption: string;
children: React.ReactNode;
};
export default function FoldableBorderedContainerWithCaption({
caption,
children,
}: Props) {
const [isOpen, setIsOpen] = useState(true);
const handleToggle = () => {
setIsOpen((prev) => !prev);
};
return (
<BorderedContainer>
<div className="flex flex-col gap-4">
<div className="flex items-center">
<div className="flex-1 text-center">
<h2 className="text-lg font-semibold">{caption}</h2>
</div>
<div className="flex-shrink-0">
<button
onClick={handleToggle}
className="p-1 bg-gray-50 border-1 border-gray-300 rounded-sm"
>
<FontAwesomeIcon
icon={isOpen ? faChevronUp : faChevronDown}
fixedWidth
className="text-gray-500"
/>
</button>
</div>
</div>
<div className={isOpen ? "" : "hidden"}>{children}</div>
</div>
</BorderedContainer>
);
}
|