import React from "react"; import { observer } from "mobx-react"; export const Checkbox = observer( class Checkbox extends React.Component<{ state: boolean | undefined; label?: string; onChange: (value: boolean) => void; readOnly: boolean; switchStyle?: boolean; }> { inputRef = React.createRef(); updateIndeterminate() { if (this.inputRef.current) { this.inputRef.current.indeterminate = this.props.state == undefined; } } componentDidMount() { this.updateIndeterminate(); } componentDidUpdate() { this.updateIndeterminate(); } render() { const innerInput = ( this.props.onChange(event.target.checked) } disabled={this.props.readOnly} /> ); const input = this.props.switchStyle ? (
 {innerInput}
) : ( innerInput ); if (this.props.label === undefined) { return input; } return (
); } } );