Newer
Older
iuav-ui / src / components / hero-banner / hero-banner.ts
  1. /**
  2. * @license
  3. * Copyright 2019 Google LLC
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6.  
  7. import {LitElement, html, css, unsafeCSS} from 'lit';
  8. import {customElement, property} from 'lit/decorators.js';
  9. import { breakpoints } from '../../breakpoints';
  10.  
  11. @customElement('iu-hero-banner')
  12.  
  13. export class HeroBanner extends LitElement {
  14. static override styles = css`
  15. :host{
  16. display:block;
  17. margin-bottom: var(--iu-spacing-block-lg);
  18. }
  19. .video{
  20. aspect-ratio: 16/9;
  21. position: relative;
  22. overflow: hidden;
  23. margin-bottom: calc(var(--iu-grid-gutter)*2);
  24. z-index: 20;
  25. }
  26. @media ${unsafeCSS(breakpoints.md)} {
  27. .video{
  28. aspect-ratio: auto;
  29. }
  30. }
  31. @media ${unsafeCSS(breakpoints.lg)} {
  32. .video{
  33. height: calc(var(--iu-hero-banner-height) - var(--iu-grid-gutter));
  34. }
  35. }
  36. .video video{
  37. width: 100%;
  38. height: 100%;
  39. object-fit: cover;
  40. }
  41. h1{
  42. font-weight: 400;
  43. font: var(--iu-f-4);
  44. z-index: 10;
  45. margin-bottom: 0;
  46. margin-top: 0;
  47. width: calc(100% / 12 * 11);
  48. }
  49. @media ${unsafeCSS(breakpoints.md)} {
  50. h1{
  51. font: var(--iu-f-7);
  52. }
  53. }
  54. @media ${unsafeCSS(breakpoints.lg)} {
  55. h1{
  56. font: var(--iu-f-9);
  57. position: sticky;
  58. bottom: var(--iu-grid-gutter);
  59. }
  60. }
  61. `;
  62.  
  63. override connectedCallback() {
  64. super.connectedCallback();
  65. // Attach the scroll listener to the window
  66. window.addEventListener('resize', this.setHeroBannerHeight);
  67. }
  68.  
  69. setHeroBannerHeight = () => {
  70. if (window.matchMedia('(min-width: 62rem)').matches) {
  71. //get banner top offset
  72. const bannerOffsetTop = this.offsetTop
  73. //set banner height
  74. this.style.setProperty('--iu-hero-banner-height', `${window.innerHeight-bannerOffsetTop}px`)
  75. }
  76. }
  77.  
  78. @property() jpg? = '';
  79. @property() webp? = '';
  80. @property() alt? = '';
  81. @property() mp4? = '';
  82. @property() webm? = '';
  83. @property() heading? = '';
  84.  
  85. override firstUpdated(){
  86. requestAnimationFrame(() => {
  87. this.setHeroBannerHeight()
  88. });
  89. }
  90.  
  91. override render() {
  92. return html`
  93. <div>
  94. <iu-container>
  95.  
  96. ${this.jpg && html`
  97. <div class="img">
  98. <picture>
  99. ${this.webp ? html`<source srcset="${this.webp}" type="image/webp">` : ''}
  100. <source srcset="${this.jpg}" type="image/jpg">
  101. <img src="${this.jpg}" alt="${this.alt}">
  102. </picture>
  103. </div>
  104. `}
  105.  
  106. ${(this.webm || this.mp4) && html`
  107. <div class="video">
  108. <video width="1920" height="1080" autoplay muted loop>
  109. ${this.webm ? html`<source src="${this.webm}" type="video/webm">` : ''}
  110. ${this.mp4 ? html`<source src="${this.mp4}" type="video/mp4">` : ''}
  111. Your browser does not support the video tag.
  112. </video>
  113. </div>
  114. `}
  115.  
  116. ${this.heading && html`
  117. <h1>${this.heading}</h1>
  118. `}
  119. </iu-container>
  120. </div>
  121. `;
  122. }
  123.  
  124. }
  125.  
  126. declare global {
  127. interface HTMLElementTagNameMap {
  128. 'iu-hero-banner': HeroBanner;
  129. }
  130. }