Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. import Component from './Component'
  2. import Button from './Button'
  3. import TextInput from './TextInput'
  4.  
  5. export default class TextFieldButton extends Component {
  6. readonly element: HTMLDivElement
  7. private textField: TextInput
  8. private button: Button
  9.  
  10. public onInput: (text: string) => void = (text) => {
  11. throw new Error('The handler for the input element on a TextFieldButton has not been defined.')
  12. }
  13. public onChange: (text: string) => void = (text) => {
  14. throw new Error('The handler for the change element on a TextFieldButton has not been defined.')
  15. }
  16.  
  17. constructor () {
  18. super()
  19. // defines the wrapper
  20. this.element = document.createElement('div')
  21. this.element.className = 'text-field-button'
  22. // defines and setup the text field
  23. this.textField = new TextInput()
  24. this.textField.placeholder = 'Enter a text here...'
  25. this.textField.onInput = (text) => {
  26. this.onInput(text)
  27. }
  28. this.textField.onChange = (text) => {}
  29. // defines and setup the button
  30. this.button = new Button('Submit')
  31. this.button.onClick = () => {
  32. this.onChange(this.textField.value)
  33. }
  34. }
  35.  
  36. get placeholder (): string {
  37. return this.textField.placeholder
  38. }
  39. set placeholder (text: string) {
  40. this.textField.placeholder = text
  41. }
  42.  
  43. get value (): string {
  44. return this.textField.value
  45. }
  46. set value (value: string) {
  47. this.textField.value = value
  48. }
  49.  
  50. // overloads the Component render method
  51. render (parent: HTMLElement) {
  52. // resets the wrapper
  53. this.element.innerHTML = ''
  54. // attach the two others components
  55. this.textField.render(this.element)
  56. this.button.render(this.element)
  57. // then render the wrapper in its parent
  58. super.render(parent)
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement