From 794606072e625430322a1180abdb4810afe3d442 Mon Sep 17 00:00:00 2001 From: Katja Lutz Date: Wed, 22 Jun 2022 21:21:52 +0200 Subject: [PATCH] feat: implement Collapsible component --- src/components/Collapsible.tsx | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/components/Collapsible.tsx diff --git a/src/components/Collapsible.tsx b/src/components/Collapsible.tsx new file mode 100644 index 0000000..ed4626a --- /dev/null +++ b/src/components/Collapsible.tsx @@ -0,0 +1,61 @@ +import { FlowComponent, JSX, mergeProps } from "solid-js"; + +const Collapsible: FlowComponent< + { + activeTitleColor?: string; + onChange?: JSX.EventHandler; + value?: boolean; + label: string | JSX.Element; + } & JSX.HTMLAttributes +> = (p) => { + const props = mergeProps({ activeTitleColor: "text-black" }, p); + let inputRef: HTMLInputElement = undefined!; + + return ( +
{ + if (props.value) { + return; + } + + evt.currentTarget.blur(); + inputRef.checked = true; + inputRef.dispatchEvent(new InputEvent("change", { bubbles: true })); + }} + > + { + evt.currentTarget.blur(); + if (props.onChange) { + props.onChange.call(this, evt); + } + }} + /> +
+ {props.label} +
+
+
+ {props.children} +
+
+
+ ); +}; + +export default Collapsible;