import { Component, ContextType } from "preact"; import { SettingsCtx } from "./SettingsContext.tsx"; import type { ConfigType } from "../config.ts"; import Checkbox from "preact-material-components/Checkbox.js"; export type SettingsCheckboxProps = { checked: boolean; name: keyof ConfigType; description: string; }; export default class SettingsCheckbox extends Component { static contextType = SettingsCtx; declare context: ContextType; render() { const id = `s-${this.props.name}`; return (
{ if (ev.target && this.context) { const e = ev.target as HTMLInputElement; this.context.set_settings((v) => { if (v) { const t: Record = v; t[this.props.name] = e.checked; if (this.context) { this.context.set_changed((v) => { v.add(this.props.name); return v; }); } return t as ConfigType; } }); } }} />
); } }