UNPKG

5.92 kBJavaScriptView Raw
1import { Component, EventEmitter, Input, Output } from '@angular/core';
2import { ImageTransformationService } from '@vendasta/core/image-transformation';
3var StoreCardComponent = /** @class */ (function () {
4 function StoreCardComponent(imageTransformationService) {
5 this.imageTransformationService = imageTransformationService;
6 this.purchasedClicked = new EventEmitter();
7 this.cardClicked = new EventEmitter();
8 this.descriptionClicked = new EventEmitter();
9 this.bannerClicked = new EventEmitter();
10 }
11 StoreCardComponent.prototype.getBannerColorForName = function () {
12 // determine an icon color for a product with no icon by using the product name
13 var COLOR_CODES = [
14 '#EF5350', '#42A5F5', '#66BB6A', '#FFA726', '#AB47BC', '#FFCA28', '#EC407A', '#26C6DA',
15 '#FF7B57'
16 ];
17 var nameSum = 0;
18 var defaultColor = '#808080';
19 if (!this.item.name) {
20 return defaultColor;
21 }
22 for (var i = 0; i < this.item.name.length; i++) {
23 nameSum += this.item.name[i].charCodeAt(0);
24 }
25 var index = nameSum % COLOR_CODES.length;
26 return COLOR_CODES[index];
27 };
28 StoreCardComponent.prototype.getSrcsetHeaderUrls = function (imageUrl) {
29 return this.imageTransformationService.getSrcSetForImage(imageUrl, [680, 1360, 2720]);
30 };
31 StoreCardComponent.decorators = [
32 { type: Component, args: [{
33 selector: 'va-store-card',
34 template: "\n<mat-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 <mat-card-header>\n <va-icon mat-card-avatar [diameter]=\"40\" [name]=\"item.name\" [iconUrl]=\"item.iconUrl\"></va-icon>\n <mat-card-title>{{item.name}}</mat-card-title>\n <mat-card-subtitle>\n <ng-container *ngIf=\"item.pricing; else formatted\">\n <va-pricing [pricing]=\"item.pricing\"\n [highlightPrice]=\"false\"></va-pricing>\n </ng-container>\n <ng-template #formatted>{{item.formattedPrice}}</ng-template>\n </mat-card-subtitle>\n </mat-card-header>\n <mat-card-content> {{ item.tagline }}\n </mat-card-content>\n </div>\n\n <button *ngIf=\"item.purchased !== undefined\"\n mat-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</mat-card>\n ",
35 styles: [":host { position: relative; } /deep/ .mat-card-header-text { width: 100%; } mat-card.hover-card { overflow: hidden; padding: 0; margin-bottom: 0; } mat-card.hover-card mat-card-title, mat-card.hover-card mat-card-subtitle { margin: 0 80px 0 0; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; } mat-card.hover-card mat-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; color: #212121; 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%; } } mat-card-header { box-sizing: border-box; padding-bottom: 16px; margin: 0; height: 40%; display: flex; align-items: center; } mat-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) { mat-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[mat-button] { padding: 0 8px; min-width: 0; } mat-card-actions { position: relative; padding: 8px !important; margin: 0 !important; text-align: right; border-top: 1px solid #e0e0e0; background-color: #ffffff; color: #212121; } .status { font-size: 14px; } "]
36 },] },
37 ];
38 /** @nocollapse */
39 StoreCardComponent.ctorParameters = function () { return [
40 { type: ImageTransformationService, },
41 ]; };
42 StoreCardComponent.propDecorators = {
43 "item": [{ type: Input },],
44 "purchasedClicked": [{ type: Output },],
45 "cardClicked": [{ type: Output },],
46 "descriptionClicked": [{ type: Output },],
47 "bannerClicked": [{ type: Output },],
48 };
49 return StoreCardComponent;
50}());
51export { StoreCardComponent };