import clsx from "clsx"; import { ComponentChildren } from "preact"; import { useContext, useRef, useState } from "preact/hooks"; import Icon from "../react/Icon"; import { ParentComponent } from "../react/react_utils"; import { RightPanelContext } from "./RightPanelContainer"; interface RightPanelWidgetProps { title: string; children: ComponentChildren; buttons?: ComponentChildren; } export default function RightPanelWidget({ title, buttons, children }: RightPanelWidgetProps) { const rightPanelContext = useContext(RightPanelContext); const [ expanded, setExpanded ] = useState(true); const containerRef = useRef(null); const parentComponent = useContext(ParentComponent); if (parentComponent) { parentComponent.initialized = Promise.resolve(); } return (
{ if (containerRef.current) { rightPanelContext.setExpanded(containerRef.current, !expanded); } setExpanded(!expanded); }} />
{title}
{buttons}
{expanded && children}
); }