revite/src/components/common/CollapsibleSection.tsx

46 lines
1,018 B
TypeScript
Raw Normal View History

2021-07-05 06:23:23 -04:00
import { ChevronDown } from "@styled-icons/boxicons-regular";
import { useApplicationState } from "../../mobx/State";
2021-07-05 06:23:23 -04:00
import Details from "../ui/Details";
import { Children } from "../../types/Preact";
interface Props {
2021-07-05 06:25:20 -04:00
id: string;
defaultValue: boolean;
2021-07-05 06:25:20 -04:00
sticky?: boolean;
large?: boolean;
2021-07-05 06:25:20 -04:00
summary: Children;
children: Children;
}
2021-07-05 06:23:23 -04:00
export default function CollapsibleSection({
2021-07-05 06:25:20 -04:00
id,
defaultValue,
summary,
children,
...detailsProps
2021-07-05 06:23:23 -04:00
}: Props) {
const layout = useApplicationState().layout;
2021-07-05 06:25:20 -04:00
return (
<Details
open={layout.getSectionState(id, defaultValue)}
onToggle={(e) =>
layout.setSectionState(id, e.currentTarget.open, defaultValue)
}
2021-07-05 06:25:20 -04:00
{...detailsProps}>
<summary>
<div class="padding">
<ChevronDown size={20} />
{summary}
</div>
</summary>
{children}
</Details>
);
}