import { LitElement, html, css } from "lit" export default class Element extends LitElement { static override properties = { popupIndex: { type: Number }, items: { type: String }, looping: { type: Boolean }, } items: string = "" looping: boolean = false popupIndex: number = -1 private _firstIndex: number = 0 private _offset: number = 0 override connectedCallback() { super.connectedCallback() window.addEventListener("resize", this._initiateContainers) } override disconnectedCallback() { super.disconnectedCallback() window.removeEventListener("resize", this._initiateContainers) } static override get styles() { return css` :host { --item-margin: 8px; --item-offset: 7px; --item-width: 348px; display: flex; flex-direction: row; } .btn-next, .btn-prev { background: none; border: 0; color: #1e313b; cursor: pointer; font-size: 36px; outline: none; background-color: #e2e8f0; aspect-ratio: 1 / 1; width: 40px; max-width: 40px; height: auto; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease-in-out; position: absolute; top: 50%; transform: translateY(-50%); z-index: 1; } .btn-next { right: -20px; } .btn-prev { left: -20px; } .btn-next:hover, .btn-prev:hover { color: #10172a; background-color: #cbd5e1; } .hidden { visibility: hidden; } #contents { display: flex; flex: 1; overflow: hidden; position: relative; } .wrapper { position: relative; display: flex; flex-direction: row; align-items: center; justify-content: center; width: calc(100% - 40px); margin: 0 auto; } article { box-shadow: 0 0 0 1px rgba(63, 63, 68, 0.05), 0 1px 3px 0 rgba(63, 63, 68, 0.15); box-sizing: border-box; flex-shrink: 0; margin: var(--item-margin); /* width + left and right margins */ transform: translateX(calc(-1 * var(--item-offset))); transition: transform 300ms; width: var(--item-width); border-radius: 0.5rem; cursor: zoom-in; } article img { object-fit: cover; width: 100%; height: 100%; border-radius: 0.5rem; } :host([looping]) article { transition: none; } .popup { position: fixed; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; background-color: #00000080; z-index: 99; display: flex; align-items: center; justify-content: center; cursor: zoom-out; } .popup > img { max-width: 1100px; width: 90%; } ` } override render() { const itemsArray = this.items.split(",").map((item) => item.trim()) as string[] return html`