index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { LitElement, html } from 'https://cdn.jsdelivr.net/gh/lit/dist@2/all/lit-all.min.js'
  2. class WebApp extends LitElement {
  3. static properties = {
  4. started: { type: Boolean }
  5. }
  6. constructor () {
  7. super()
  8. this.started = false
  9. }
  10. _clickHandler () {
  11. this.started = !this.started
  12. }
  13. _buttonHandler (label) {
  14. return html`<button type="button" @click=${this._clickHandler}>${label}</button>`
  15. }
  16. render () {
  17. if (this.started) {
  18. return html`
  19. <session-started></session-started>
  20. ${this._buttonHandler('Terminar sesión')}
  21. `
  22. }
  23. return html`
  24. <session-closed></session-closed>
  25. ${this._buttonHandler('Iniciar sesión')}
  26. `
  27. }
  28. }
  29. customElements.define('web-app', WebApp)
  30. class SessionClosed extends LitElement {
  31. static properties = {
  32. user: { type: String },
  33. pass: { type: String }
  34. }
  35. constructor () {
  36. super()
  37. this.user = ''
  38. this.pass = ''
  39. }
  40. render () {
  41. return html`
  42. <h2>Inicio de sesión</h2>
  43. <input placeholder="usuario" type="text" value="">
  44. <input placeholder="contraseña" type="password" value="">`
  45. }
  46. }
  47. customElements.define('session-closed', SessionClosed)
  48. class SessionStarted extends LitElement {
  49. static properties = {
  50. message: { type: String }
  51. }
  52. constructor () {
  53. super()
  54. this.message = 'Bienvenido a tu sesión'
  55. }
  56. render () {
  57. return html`<h2>${this.message}</h2>`
  58. }
  59. }
  60. customElements.define('session-started', SessionStarted)