import m, { ClassComponent, CVnode } from "mithril"; import { ICheckboxField, IPropWidget } from "../interface/widget"; import { IConfig, TIcon, TSubset } from "../interface/config"; import { getConfig } from "../config"; import { wrapperCls } from "../theme"; import { getDisplayLabel } from "../utils"; import { SelectionInner } from "../input/layout/selectionInner"; type TCheckboxWidget = IPropWidget; export class Checkbox implements ClassComponent { protected readonly onIcon: keyof TSubset = "checkIcn"; protected readonly offIcon: keyof TSubset = "uncheckIcn"; public view({ attrs: { field, value } }: CVnode) { const { label, uiClass = {}, config } = field; return m(".pa2", { class: wrapperCls(uiClass), }, m(SelectionInner, { selected: Boolean(value()), label: getDisplayLabel(label, "mh1 truncate"), onIcon: getConfig(this.onIcon, config), offIcon: getConfig(this.offIcon, config), config })); } }