Created
October 24, 2016 23:01
-
-
Save robdodson/1bf347309b8d9e20a1b88e409108ab4c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default class XCheckbox extends HTMLElement { | |
| constructor() { | |
| this._checked = false; | |
| } | |
| connectedCallback() { | |
| this.addEventListener('click', this._onclick); | |
| } | |
| disconnectedCallback() { | |
| this.removeEventListener('click', this._onclick); | |
| } | |
| _onclick(e) { | |
| this.checked = !this.checked; | |
| this.dispatchEvent(new CustomEvent('checkedchange', { | |
| detail: { checked: this.checked }, bubbles: false | |
| })); | |
| } | |
| set checked(value) { | |
| this._checked = value; | |
| value ? this.setAttribute('checked', '') : this.removeAttribute('checked'); | |
| } | |
| get checked() { | |
| return this._checked; | |
| } | |
| } | |
| window.customElements.define('x-checkbox', XCheckbox); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment