mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-27 12:54:42 -05:00
34 lines
782 B
TypeScript
34 lines
782 B
TypeScript
import { Box, BoxProps, Flex } from "@chakra-ui/react";
|
|
import { useState } from "react";
|
|
import SubText from "./SubText";
|
|
|
|
interface Props {
|
|
title: string;
|
|
children: React.ReactNode;
|
|
isOpenByDefault?: boolean;
|
|
}
|
|
|
|
const SubTextCollapse: React.FC<Props & BoxProps> = ({
|
|
title,
|
|
children,
|
|
isOpenByDefault = false,
|
|
...props
|
|
}) => {
|
|
const [isOpen, setIsOpen] = useState(isOpenByDefault);
|
|
return (
|
|
<Box {...props}>
|
|
<SubText onClick={() => setIsOpen(!isOpen)} cursor="pointer" mb={2}>
|
|
<Flex userSelect="none">
|
|
<Box w={4} transform="rotate(0deg)">
|
|
{isOpen ? "▼" : "►"}
|
|
</Box>{" "}
|
|
{title}
|
|
</Flex>
|
|
</SubText>
|
|
{isOpen && <>{children}</>}
|
|
</Box>
|
|
);
|
|
};
|
|
|
|
export default SubTextCollapse;
|