import BaseUIElement from "../BaseUIElement" import { UIEventSource } from "../../Logic/UIEventSource" import Combine from "./Combine" import Title from "./Title" import Hash from "../../Logic/Web/Hash" export class Accordeon extends Combine { constructor(toggles: Toggleable[]) { for (const el of toggles) { el.isVisible.addCallbackAndRun((isVisible) => toggles.forEach((toggle) => { if (toggle !== el && isVisible) { toggle.isVisible.setData(false) } }) ) } super(toggles) } } export default class Toggleable extends Combine { public readonly isVisible = new UIEventSource(false) constructor( title: Title | Combine | BaseUIElement, content: BaseUIElement, options?: { closeOnClick?: true | boolean height?: "100vh" | string } ) { super([title, content]) content.SetClass("animate-height border-l-4 pl-2 block") title.SetClass("background-subtle rounded-lg") const self = this this.onClick(() => { if (self.isVisible.data) { if (options?.closeOnClick ?? true) { self.isVisible.setData(false) } } else { self.isVisible.setData(true) } }) const contentElement = content.ConstructElement() if (title instanceof Combine) { for (const el of title.getElements()) { if (el instanceof Title) { title = el break } } } if (title instanceof Title) { Hash.hash.addCallbackAndRun((h) => { if (h === (