|
| 1 | +// Import Third-party Dependencies |
| 2 | +import { LitElement, html, css, nothing } from "lit"; |
| 3 | +import { repeat } from "lit/directives/repeat.js"; |
| 4 | +import { when } from "lit/directives/when.js"; |
| 5 | + |
| 6 | +// Import Internal Dependencies |
| 7 | +import { selectVisibleItems } from "./view-model.js"; |
| 8 | +import "../expandable/expandable.js"; |
| 9 | + |
| 10 | +class ItemsList extends LitElement { |
| 11 | + static styles = css` |
| 12 | +.list-item{ |
| 13 | + display: flex; |
| 14 | + flex-wrap: wrap; |
| 15 | + margin-top: 5px; |
| 16 | + margin-bottom: 5px; |
| 17 | + margin-left: -5px; |
| 18 | + flex-direction: column; |
| 19 | + padding: 0; |
| 20 | + list-style: none; |
| 21 | +} |
| 22 | +
|
| 23 | +.line { |
| 24 | + flex-direction: row; |
| 25 | +} |
| 26 | +
|
| 27 | +.line > li { |
| 28 | +flex-basis: 25px; |
| 29 | +justify-content: start; |
| 30 | +} |
| 31 | +
|
| 32 | +.list-item > li { |
| 33 | + padding-left: 10px; |
| 34 | + padding-top: 5px; |
| 35 | + padding-bottom: 5px; |
| 36 | + width: 96%; |
| 37 | + border-radius: 4px; |
| 38 | + font-size: 13px; |
| 39 | + letter-spacing: 0.7px; |
| 40 | + display: flex; |
| 41 | + align-items: center; |
| 42 | + justify-content: center; |
| 43 | + flex-grow: 1; |
| 44 | + color: #CFD8DC; |
| 45 | + margin-left: 5px; |
| 46 | + margin-top: 5px; |
| 47 | + justify-content: flex-start; |
| 48 | +} |
| 49 | +
|
| 50 | +.clickable:hover { |
| 51 | + background: var(--secondary-darker); |
| 52 | + color: #FFF; |
| 53 | + cursor: pointer; |
| 54 | +} |
| 55 | +
|
| 56 | +`; |
| 57 | + |
| 58 | + static properties = { |
| 59 | + items: { type: Array }, |
| 60 | + isClosed: { type: Boolean }, |
| 61 | + itemsToShowLength: { type: Number }, |
| 62 | + onClickItem: { type: Function }, |
| 63 | + variant: { type: String } |
| 64 | + }; |
| 65 | + |
| 66 | + constructor() { |
| 67 | + super(); |
| 68 | + this.items = []; |
| 69 | + this.isClosed = true; |
| 70 | + this.itemsToShowLength = 5; |
| 71 | + this.onClickItem = null; |
| 72 | + this.variant = "column"; |
| 73 | + this.shouldShowEveryItems = false; |
| 74 | + } |
| 75 | + |
| 76 | + render() { |
| 77 | + const hasExpandable = !this.shouldShowEveryItems && this.items.length > this.itemsToShowLength; |
| 78 | + |
| 79 | + return html` |
| 80 | + <ul class="list-item ${this.variant}"> |
| 81 | + ${repeat(selectVisibleItems({ |
| 82 | + items: this.items, |
| 83 | + isClosed: this.isClosed, |
| 84 | + itemsToShowLength: this.itemsToShowLength, |
| 85 | + shouldShowEveryItems: this.shouldShowEveryItems |
| 86 | + }), |
| 87 | + (item) => item, |
| 88 | + (item) => (typeof this.onClickItem === "function" |
| 89 | + ? html`<li class="clickable" @click=${() => { |
| 90 | + this.onClickItem(item); |
| 91 | + }}>${item}</li>` |
| 92 | + : html`<li>${item}</li>`)) |
| 93 | + } |
| 94 | + </ul> |
| 95 | + ${when(hasExpandable, |
| 96 | + () => html`<expandable-span .isClosed=${this.isClosed} .onToggle=${() => { |
| 97 | + this.isClosed = !this.isClosed; |
| 98 | + }}></expandable-span>`, |
| 99 | + () => nothing |
| 100 | + ) |
| 101 | + } |
| 102 | +`; |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +customElements.define("items-list", ItemsList); |
0 commit comments