2021-07-05 06:23:23 -04:00
|
|
|
import { ChevronDown } from "@styled-icons/boxicons-regular";
|
|
|
|
|
2021-07-04 10:53:06 -04:00
|
|
|
import { State, store } from "../../redux";
|
|
|
|
import { Action } from "../../redux/reducers";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
import Details from "../ui/Details";
|
|
|
|
|
2021-07-04 10:53:06 -04:00
|
|
|
import { Children } from "../../types/Preact";
|
|
|
|
|
|
|
|
interface Props {
|
2021-07-05 06:25:20 -04:00
|
|
|
id: string;
|
|
|
|
defaultValue: boolean;
|
2021-07-04 10:53:06 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
sticky?: boolean;
|
|
|
|
large?: boolean;
|
2021-07-04 10:53:06 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
summary: Children;
|
|
|
|
children: Children;
|
2021-07-04 10:53:06 -04:00
|
|
|
}
|
|
|
|
|
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) {
|
2021-07-05 06:25:20 -04:00
|
|
|
const state: State = store.getState();
|
|
|
|
|
|
|
|
function setState(state: boolean) {
|
|
|
|
if (state === defaultValue) {
|
|
|
|
store.dispatch({
|
|
|
|
type: "SECTION_TOGGLE_UNSET",
|
|
|
|
id,
|
|
|
|
} as Action);
|
|
|
|
} else {
|
|
|
|
store.dispatch({
|
|
|
|
type: "SECTION_TOGGLE_SET",
|
|
|
|
id,
|
|
|
|
state,
|
|
|
|
} as Action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Details
|
|
|
|
open={state.sectionToggle[id] ?? defaultValue}
|
|
|
|
onToggle={(e) => setState(e.currentTarget.open)}
|
|
|
|
{...detailsProps}>
|
|
|
|
<summary>
|
|
|
|
<div class="padding">
|
|
|
|
<ChevronDown size={20} />
|
|
|
|
{summary}
|
|
|
|
</div>
|
|
|
|
</summary>
|
|
|
|
{children}
|
|
|
|
</Details>
|
|
|
|
);
|
2021-07-04 10:53:06 -04:00
|
|
|
}
|