Skip to content

Instantly share code, notes, and snippets.

@vertcitron
Created September 25, 2019 12:20
Show Gist options
  • Save vertcitron/c69eee06b78e6382a018aaf31157a419 to your computer and use it in GitHub Desktop.
Save vertcitron/c69eee06b78e6382a018aaf31157a419 to your computer and use it in GitHub Desktop.
import Component from './Component'
export default class Button extends Component {
readonly element: HTMLButtonElement
public onClick: () => void = () => {
throw new Error('The click handler has not been defined in a Button component.')
}
constructor (text: string) {
super()
this.element = document.createElement('button')
this.element.textContent = text
this.element.addEventListener('click', e => {
e.preventDefault()
e.stopPropagation()
this.onClick()
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment