UNPKG

@zeix/ui-element

Version:

UIElement - minimal reactive framework based on Web Components

22 lines (18 loc) 564 B
import { UIElement, asBoolean, setProperty, toggleAttribute } from "../../../" export class InputCheckbox extends UIElement<{ checked: boolean }> { static localName = 'input-checkbox' static observedAttributes = ['checked'] init = { checked: asBoolean } connectedCallback() { super.connectedCallback() this.first<HTMLInputElement>('input') .sync(setProperty('checked')) .on('change', (e: Event) => { this.set('checked', (e.target as HTMLInputElement)?.checked) }) this.self.sync(toggleAttribute('checked')) } } InputCheckbox.define()