Guest User

Untitled

a guest
Dec 9th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import { Component } from '@aspect';
  2. import { html } from '@aspect/dom';
  3.  
  4. interface State {
  5. message: string;
  6. open: boolean;
  7. title: string;
  8. }
  9.  
  10. const el: HTMLDivElement = document.querySelector('#dialog');
  11.  
  12. class Dialog extends Component<State> {
  13. public parent: HTMLElement;
  14. constructor(el: HTMLDivElement) {
  15. super({
  16. el,
  17. state: {
  18. message: 'Hello there',
  19. title: 'How are you today?',
  20. open: false
  21. }
  22. });
  23. }
  24.  
  25. declare(): HTMLElement {
  26. return this.state.open ? this.open() : this.closed();
  27. }
  28.  
  29. open(): HTMLElement {
  30. return html(
  31. `<div>
  32. <div class="dialog-title">
  33. <p>${this.state.title}</p>
  34. </div>
  35. <div class="dialog-message">
  36. <p>${this.state.message}</p>
  37. </div>
  38. </div>`
  39. );
  40. }
  41.  
  42. closed(): HTMLElement {
  43. return html(`<div></div>`);
  44. }
  45. }
  46.  
  47. // Create the dialog, and append it to the document's body.
  48. let dialog: Dialog = new Dialog(el);
  49. document.body.appendChild(el);
Add Comment
Please, Sign In to add comment