|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright (c) 2019 The Polymer Project Authors. All rights reserved. |
| 4 | + * This code may only be used under the BSD style license found at |
| 5 | + * http://polymer.github.io/LICENSE.txt The complete set of authors may be found |
| 6 | + * at http://polymer.github.io/AUTHORS.txt The complete set of contributors may |
| 7 | + * be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by |
| 8 | + * Google as part of the polymer project is also subject to an additional IP |
| 9 | + * rights grant found at http://polymer.github.io/PATENTS.txt |
| 10 | + */ |
| 11 | + |
| 12 | +import './shack-item.js'; |
| 13 | +import './shack-cart.js'; |
| 14 | + |
| 15 | +import {css, html, LitElement} from 'lit-element'; |
| 16 | + |
| 17 | +class ShackApp extends LitElement { |
| 18 | + static get properties() { |
| 19 | + return { |
| 20 | + page: {type: String}, |
| 21 | + cart: {type: Array}, |
| 22 | + categories: {type: Object}, |
| 23 | + }; |
| 24 | + } |
| 25 | + |
| 26 | + static get styles() { |
| 27 | + return css` |
| 28 | + :host { |
| 29 | + font-family: "Arial", sans-serif; |
| 30 | + display: flex; |
| 31 | + flex-direction: column; |
| 32 | + align-items: center; |
| 33 | + } |
| 34 | +
|
| 35 | + #pageHeader { |
| 36 | + flex-basis: 130px; |
| 37 | + flex-shrink: 0; |
| 38 | + display: flex; |
| 39 | + flex-direction: column; |
| 40 | + align-items: center; |
| 41 | + } |
| 42 | +
|
| 43 | + #logo { |
| 44 | + margin: 26px 0 0 0; |
| 45 | + font-size: 16px; |
| 46 | + letter-spacing: 4px; |
| 47 | + color: #202020; |
| 48 | + } |
| 49 | +
|
| 50 | + shack-cart { |
| 51 | + position: absolute; |
| 52 | + right: 20px; |
| 53 | + top: 20px; |
| 54 | + } |
| 55 | +
|
| 56 | + #categoryNav { |
| 57 | + display: flex; |
| 58 | + justify-content: center; |
| 59 | + margin-top: 46px; |
| 60 | + } |
| 61 | +
|
| 62 | + #categoryNav > a { |
| 63 | + margin: 0 20px; |
| 64 | + text-decoration: none; |
| 65 | + color: #202020; |
| 66 | + font-size: 13px; |
| 67 | + padding-bottom: 9px; |
| 68 | + min-width: 110px; |
| 69 | + text-align: center; |
| 70 | + cursor: pointer; |
| 71 | + } |
| 72 | +
|
| 73 | + #categoryNav > a[active] { |
| 74 | + border-bottom: 2px solid #172c50; |
| 75 | + } |
| 76 | +
|
| 77 | + main { |
| 78 | + display: flex; |
| 79 | + flex-direction: column; |
| 80 | + align-items: center; |
| 81 | + min-width: 500px; |
| 82 | + flex-grow: 1; |
| 83 | + width: 100%; |
| 84 | + } |
| 85 | +
|
| 86 | + #hero { |
| 87 | + width: 100%; |
| 88 | + flex-basis: 320px; |
| 89 | + flex-shrink: 0; |
| 90 | + background-color: #e7e7e7; |
| 91 | + } |
| 92 | +
|
| 93 | + #categoryTitle { |
| 94 | + font-size: 16px; |
| 95 | + font-weight: normal; |
| 96 | + margin: 37px 0 0 0; |
| 97 | + } |
| 98 | +
|
| 99 | + #numItems { |
| 100 | + color: #757575; |
| 101 | + font-size: 13px; |
| 102 | + margin-top: 8px; |
| 103 | + } |
| 104 | +
|
| 105 | + #list { |
| 106 | + max-width: 1000px; |
| 107 | + display: flex; |
| 108 | + flex-direction: row; |
| 109 | + flex-wrap: wrap; |
| 110 | + margin: 0; |
| 111 | + padding: 0; |
| 112 | + } |
| 113 | +
|
| 114 | + shack-item { |
| 115 | + flex-basis: 33%; |
| 116 | + margin-top: 43px; |
| 117 | + } |
| 118 | +
|
| 119 | + shack-item:nth-child(7n+1) { |
| 120 | + --shack-item-placeholder-color: #d1fdb5; |
| 121 | + } |
| 122 | + shack-item:nth-child(7n+2) { |
| 123 | + --shack-item-placeholder-color: #ffe7a6; |
| 124 | + } |
| 125 | + shack-item:nth-child(7n+3) { |
| 126 | + --shack-item-placeholder-color: #ffe4fe; |
| 127 | + } |
| 128 | + shack-item:nth-child(7n+4) { |
| 129 | + --shack-item-placeholder-color: #cfffff; |
| 130 | + } |
| 131 | + shack-item:nth-child(7n+5) { |
| 132 | + --shack-item-placeholder-color: #feff9b; |
| 133 | + } |
| 134 | + shack-item:nth-child(7n+6) { |
| 135 | + --shack-item-placeholder-color: #d0ebff; |
| 136 | + } |
| 137 | + shack-item:nth-child(7n+7) { |
| 138 | + --shack-item-placeholder-color: #ffd9d9; |
| 139 | + } |
| 140 | +
|
| 141 | + #demoNotice { |
| 142 | + background-color: #202020; |
| 143 | + color: white; |
| 144 | + font-size: 12px; |
| 145 | + padding: 12px 24px; |
| 146 | + margin-top: 30px; |
| 147 | + } |
| 148 | + `; |
| 149 | + } |
| 150 | + |
| 151 | + constructor() { |
| 152 | + super(); |
| 153 | + this.cart = []; |
| 154 | + } |
| 155 | + |
| 156 | + render() { |
| 157 | + return html` |
| 158 | + <header id="pageHeader"> |
| 159 | + <h1 id="logo">SHACK</h1> |
| 160 | + <shack-cart .items=${this.cart}></shack-cart> |
| 161 | + <nav id="categoryNav">${this.categoryNav()}</nav> |
| 162 | + </header> |
| 163 | +
|
| 164 | + <main id="categoryList"> |
| 165 | + <div id="hero"></div> |
| 166 | + <h2 id="categoryTitle">${this.categories[this.page].title}</h2> |
| 167 | + <span id="numItems"> |
| 168 | + (${this.categories[this.page].items.length} items) |
| 169 | + </span> |
| 170 | +
|
| 171 | + <div id="list"> |
| 172 | + ${this.categories[this.page].items.map((item) => html` |
| 173 | + <shack-item .title=${item.title} |
| 174 | + .price=${item.price} |
| 175 | + @click=${(e) => this.clickItem(item, e)} |
| 176 | + </shack-item> |
| 177 | + `)} |
| 178 | + </div> |
| 179 | + </main> |
| 180 | +
|
| 181 | + <footer id="footer"> |
| 182 | + <div id="demoNotice">DEMO ONLY</div> |
| 183 | + </footer> |
| 184 | + `; |
| 185 | + } |
| 186 | + |
| 187 | + categoryNav() { |
| 188 | + return Object.keys(this.categories) |
| 189 | + .map( |
| 190 | + (c) => html`<a ?active=${this.page === c} @click=${ |
| 191 | + (e) => |
| 192 | + this.clickCategory(c, e)}>${this.categories[c].title}</a>`); |
| 193 | + } |
| 194 | + |
| 195 | + clickCategory(category, event) { |
| 196 | + event.preventDefault(); |
| 197 | + this.page = category; |
| 198 | + } |
| 199 | + |
| 200 | + clickItem(item, event) { |
| 201 | + event.preventDefault(); |
| 202 | + this.cart = [item.title, ...this.cart]; |
| 203 | + } |
| 204 | +} |
| 205 | + |
| 206 | +customElements.define('shack-app', ShackApp); |
0 commit comments