import { Component, ContextType } from "preact"; import Checkbox from "preact-material-components/Checkbox"; import { BCtx } from "./BContext.tsx"; type Props = { id?: string; checked: boolean; name?: string; description?: string; set_value?: (v: boolean) => void; }; export default class BCheckbox extends Component { static contextType = BCtx; declare context: ContextType; set_value(value: boolean) { if (this.props.set_value) { this.props.set_value(value); } else if (this.context) { this.context.set_value((v) => { v[this.props.name || ""] = value; return v; }); } } render() { let label = null; if (this.props.description) { label = ; } return (
{ if (ev.target) { const e = ev.target as HTMLInputElement; this.set_value(e.checked); } }} /> {label}
); } }