|
| 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 | +import '@polymer/polymer/lib/elements/dom-repeat.js'; |
| 15 | +import {html, PolymerElement} from '@polymer/polymer'; |
| 16 | + |
| 17 | +class ShackApp extends PolymerElement { |
| 18 | + static get properties() { |
| 19 | + return { |
| 20 | + page: {type: String}, |
| 21 | + cart: {type: Array}, |
| 22 | + categories: {type: Object}, |
| 23 | + |
| 24 | + categoryList: { |
| 25 | + computed: 'computeCategoryList(categories)', |
| 26 | + }, |
| 27 | + categoryPageTitle: { |
| 28 | + computed: 'computeCategoryPageTitle(page, categories)', |
| 29 | + }, |
| 30 | + categoryItems: { |
| 31 | + computed: 'computeCategoryItems(page, categories)', |
| 32 | + }, |
| 33 | + categoryNumItems: { |
| 34 | + computed: 'computeCategoryNumItems(page, categories)', |
| 35 | + } |
| 36 | + }; |
| 37 | + } |
| 38 | + |
| 39 | + static get template() { |
| 40 | + return html` |
| 41 | + <style> |
| 42 | + :host { |
| 43 | + font-family: "Arial", sans-serif; |
| 44 | + display: flex; |
| 45 | + flex-direction: column; |
| 46 | + align-items: center; |
| 47 | + } |
| 48 | +
|
| 49 | + #pageHeader { |
| 50 | + flex-basis: 130px; |
| 51 | + flex-shrink: 0; |
| 52 | + display: flex; |
| 53 | + flex-direction: column; |
| 54 | + align-items: center; |
| 55 | + } |
| 56 | +
|
| 57 | + #logo { |
| 58 | + margin: 26px 0 0 0; |
| 59 | + font-size: 16px; |
| 60 | + letter-spacing: 4px; |
| 61 | + color: #202020; |
| 62 | + } |
| 63 | +
|
| 64 | + shack-cart { |
| 65 | + position: absolute; |
| 66 | + right: 20px; |
| 67 | + top: 20px; |
| 68 | + } |
| 69 | +
|
| 70 | + #categoryNav { |
| 71 | + display: flex; |
| 72 | + justify-content: center; |
| 73 | + margin-top: 46px; |
| 74 | + } |
| 75 | +
|
| 76 | + #categoryNav > a { |
| 77 | + margin: 0 20px; |
| 78 | + text-decoration: none; |
| 79 | + color: #202020; |
| 80 | + font-size: 13px; |
| 81 | + padding-bottom: 9px; |
| 82 | + min-width: 110px; |
| 83 | + text-align: center; |
| 84 | + cursor: pointer; |
| 85 | + } |
| 86 | +
|
| 87 | + #categoryNav > a[active] { |
| 88 | + border-bottom: 2px solid #172c50; |
| 89 | + } |
| 90 | +
|
| 91 | + main { |
| 92 | + display: flex; |
| 93 | + flex-direction: column; |
| 94 | + align-items: center; |
| 95 | + min-width: 500px; |
| 96 | + flex-grow: 1; |
| 97 | + width: 100%; |
| 98 | + } |
| 99 | +
|
| 100 | + #hero { |
| 101 | + width: 100%; |
| 102 | + flex-basis: 320px; |
| 103 | + flex-shrink: 0; |
| 104 | + background-color: #e7e7e7; |
| 105 | + } |
| 106 | +
|
| 107 | + #categoryTitle { |
| 108 | + font-size: 16px; |
| 109 | + font-weight: normal; |
| 110 | + margin: 37px 0 0 0; |
| 111 | + } |
| 112 | +
|
| 113 | + #numItems { |
| 114 | + color: #757575; |
| 115 | + font-size: 13px; |
| 116 | + margin-top: 8px; |
| 117 | + } |
| 118 | +
|
| 119 | + #list { |
| 120 | + max-width: 1000px; |
| 121 | + display: flex; |
| 122 | + flex-direction: row; |
| 123 | + flex-wrap: wrap; |
| 124 | + margin: 0; |
| 125 | + padding: 0; |
| 126 | + } |
| 127 | +
|
| 128 | + shack-item { |
| 129 | + flex-basis: 33%; |
| 130 | + margin-top: 43px; |
| 131 | + } |
| 132 | +
|
| 133 | + shack-item:nth-child(7n+1) { |
| 134 | + --shack-item-placeholder-color: #d1fdb5; |
| 135 | + } |
| 136 | + shack-item:nth-child(7n+2) { |
| 137 | + --shack-item-placeholder-color: #ffe7a6; |
| 138 | + } |
| 139 | + shack-item:nth-child(7n+3) { |
| 140 | + --shack-item-placeholder-color: #ffe4fe; |
| 141 | + } |
| 142 | + shack-item:nth-child(7n+4) { |
| 143 | + --shack-item-placeholder-color: #cfffff; |
| 144 | + } |
| 145 | + shack-item:nth-child(7n+5) { |
| 146 | + --shack-item-placeholder-color: #feff9b; |
| 147 | + } |
| 148 | + shack-item:nth-child(7n+6) { |
| 149 | + --shack-item-placeholder-color: #d0ebff; |
| 150 | + } |
| 151 | + shack-item:nth-child(7n+7) { |
| 152 | + --shack-item-placeholder-color: #ffd9d9; |
| 153 | + } |
| 154 | +
|
| 155 | + #demoNotice { |
| 156 | + background-color: #202020; |
| 157 | + color: white; |
| 158 | + font-size: 12px; |
| 159 | + padding: 12px 24px; |
| 160 | + margin-top: 30px; |
| 161 | + } |
| 162 | + </style> |
| 163 | +
|
| 164 | + <header id="pageHeader"> |
| 165 | + <h1 id="logo">SHACK</h1> |
| 166 | + <shack-cart items=[[cart]]></shack-cart> |
| 167 | +
|
| 168 | + <nav id="categoryNav"> |
| 169 | + <dom-repeat items=[[categoryList]]> |
| 170 | + <template> |
| 171 | + <a active$="[[categoryIsActive(page, item.slug)]]" |
| 172 | + on-click="clickCategory"> |
| 173 | + [[item.title]] |
| 174 | + </a> |
| 175 | + </template> |
| 176 | + </dom-repeat> |
| 177 | + </nav> |
| 178 | + </header> |
| 179 | +
|
| 180 | + <main id="categoryList"> |
| 181 | + <div id="hero"></div> |
| 182 | + <h2 id="categoryTitle">[[categoryTitle]]</h2> |
| 183 | + <span id="numItems">([[categoryNumItems]] items)</span> |
| 184 | +
|
| 185 | + <div id="list"> |
| 186 | + <dom-repeat items=[[categoryItems]]> |
| 187 | + <template> |
| 188 | + <shack-item title=[[item.title]] |
| 189 | + price=[[item.price]] |
| 190 | + on-click="clickItem" |
| 191 | + </shack-item> |
| 192 | + </template> |
| 193 | + </dom-repeat> |
| 194 | + </div> |
| 195 | + </main> |
| 196 | +
|
| 197 | + <footer id="footer"> |
| 198 | + <div id="demoNotice">DEMO ONLY</div> |
| 199 | + </footer> |
| 200 | + `; |
| 201 | + } |
| 202 | + |
| 203 | + constructor() { |
| 204 | + super(); |
| 205 | + this.cart = []; |
| 206 | + } |
| 207 | + |
| 208 | + computeCategoryList() { |
| 209 | + return Object.values(this.categories); |
| 210 | + } |
| 211 | + |
| 212 | + computeCategoryPageTitle() { |
| 213 | + return this.categories[this.page].title; |
| 214 | + } |
| 215 | + |
| 216 | + computeCategoryItems() { |
| 217 | + return this.categories[this.page].items; |
| 218 | + } |
| 219 | + |
| 220 | + computeCategoryNumItems() { |
| 221 | + return this.categories[this.page].items.length; |
| 222 | + } |
| 223 | + |
| 224 | + categoryIsActive(category, active) { |
| 225 | + return category === active; |
| 226 | + } |
| 227 | + |
| 228 | + clickCategory(event) { |
| 229 | + event.preventDefault(); |
| 230 | + this.page = event.model.item.slug; |
| 231 | + } |
| 232 | + |
| 233 | + clickItem(event) { |
| 234 | + event.preventDefault(); |
| 235 | + this.cart = [event.model.item.title, ...this.cart]; |
| 236 | + } |
| 237 | +} |
| 238 | + |
| 239 | +customElements.define('shack-app', ShackApp); |
0 commit comments