index.html 1.9 KB

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