UNPKG

5.37 kBJavaScriptView Raw
1import { Component, EventEmitter, Input, Output } from '@angular/core';
2var StoreCardComponent = (function () {
3 function StoreCardComponent() {
4 this.purchasedClicked = new EventEmitter();
5 this.cardClicked = new EventEmitter();
6 this.descriptionClicked = new EventEmitter();
7 this.bannerClicked = new EventEmitter();
8 }
9 StoreCardComponent.prototype.getBannerColorForName = function () {
10 // determine an icon color for a product with no icon by using the product name
11 var COLOR_CODES = [
12 '#EF5350', '#42A5F5', '#66BB6A', '#FFA726', '#AB47BC', '#FFCA28', '#EC407A', '#26C6DA',
13 '#FF7B57'
14 ];
15 var nameSum = 0;
16 var defaultColor = '#808080';
17 if (!this.item.name) {
18 return defaultColor;
19 }
20 for (var i = 0; i < this.item.name.length; i++) {
21 nameSum += this.item.name[i].charCodeAt(0);
22 }
23 var index = nameSum % COLOR_CODES.length;
24 return COLOR_CODES[index];
25 };
26 StoreCardComponent.prototype.getSrcsetHeaderUrls = function (imageUrl) {
27 return imageUrl + "=s680 680w, " + imageUrl + "=s1360 1360w, " + imageUrl + "=s2720 2720w";
28 };
29 StoreCardComponent.decorators = [
30 { type: Component, args: [{
31 selector: 'va-store-card',
32 template: "\n<md-card class=\"hover-card\" *ngIf=\"item\" (click)=\"cardClicked.emit(item)\">\n<div class=\"hover-area\">\n <div class=\"product-banner\" (click)=\"bannerClicked.emit(item)\"\n [style.background-color]=\"item.headerImageUrl ? '': getBannerColorForName()\">\n <img *ngIf=\"item.headerImageUrl\" [src]=\"item.headerImageUrl\" [srcset]=\"getSrcsetHeaderUrls(item.headerImageUrl)\">\n </div>\n\n <div class=\"description\" (click)=\"descriptionClicked.emit(item)\">\n <md-card-header>\n <va-icon md-card-avatar [diameter]=\"40\" [name]=\"item.name\" [iconUrl]=\"item.iconUrl\"></va-icon>\n <md-card-title>{{item.name}}</md-card-title>\n <md-card-subtitle>{{item.formattedPrice}}</md-card-subtitle>\n </md-card-header>\n <md-card-content> {{ item.tagline }}\n </md-card-content>\n </div>\n\n <button *ngIf=\"item.purchased !== undefined\"\n md-button color=\"primary\" class=\"enabled-indicator\" (click)=\"purchasedClicked.emit(item)\" [disabled]=\"item.purchased\">\n <i *ngIf=\"!item.purchased\" class=\"material-icons\">add</i>\n <i *ngIf=\"item.purchased\" class=\"material-icons\" style=\"color: #39B74A\">check</i>\n <span>{{(item.purchased) ? 'ENABLED' : 'ENABLE'}}</span>\n </button>\n </div>\n</md-card>\n ",
33 styles: [":host { position: relative; } /deep/ .mat-card-header-text { width: 100%; } md-card.hover-card { overflow: hidden; padding: 0; margin-bottom: 0; } md-card.hover-card md-card-title, md-card.hover-card md-card-subtitle { margin: 0 80px 0 0; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; } md-card.hover-card md-card-subtitle { font-size: 12px; margin-top: 4px; } .hover-area { position: relative; cursor: pointer; } @media screen and (min-width: 480px) { .hover-area { padding-top: 55%; } .hover-area:hover .description { top: 0; } .hover-area:hover .enabled-indicator span { width: 70px; } } .product-banner { max-height: 133px; overflow: hidden; display: flex; width: 100%; height: 100px; align-items: center; justify-content: center; } .product-banner img { max-width: 100%; } @media screen and (min-width: 480px) { .product-banner { max-height: none; position: absolute; height: 60%; top: 0; } } .description { box-sizing: border-box; padding: 10px 16px 0; overflow: hidden; background: #ffffff; transition: 0.3s ease all; } .description:after { content: ''; display: block; width: 100%; height: 40%; position: absolute; bottom: 0; left: 0; background: linear-gradient(rgba(255, 255, 255, 0) 40%, white 70%); } @media screen and (min-width: 480px) { .description { position: absolute; top: 60%; width: 100%; height: 100%; } .description:after { height: 70%; } } md-card-header { box-sizing: border-box; padding-bottom: 16px; margin: 0; height: 40%; display: flex; align-items: center; } md-card-content { min-height: 40px; max-height: 80px; padding: 16px; margin: 0 -16px; border-top: 1px solid #e0e0e0; font-size: 12px; } @media screen and (min-width: 480px) { md-card-content { min-height: 0; max-height: none; } } .enabled-indicator { position: absolute; right: 8px; bottom: 8px; } .enabled-indicator span { display: inline-block; width: 70px; overflow: hidden; transition: 0.3s ease all; } @media screen and (min-width: 480px) { .enabled-indicator span { width: 0; } } button[md-button] { padding: 0 8px; min-width: 0; } md-card-actions { position: relative; padding: 8px !important; margin: 0 !important; text-align: right; border-top: 1px solid #e0e0e0; background-color: #ffffff; } .status { font-size: 14px; } "]
34 },] },
35 ];
36 /** @nocollapse */
37 StoreCardComponent.ctorParameters = function () { return []; };
38 StoreCardComponent.propDecorators = {
39 'item': [{ type: Input },],
40 'purchasedClicked': [{ type: Output },],
41 'cardClicked': [{ type: Output },],
42 'descriptionClicked': [{ type: Output },],
43 'bannerClicked': [{ type: Output },],
44 };
45 return StoreCardComponent;
46}());
47export { StoreCardComponent };