added favorite on product-item

master
Vic 2 years ago
parent 66f1f41307
commit da72a8fd64

@ -112,8 +112,7 @@ img {
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
padding-top: 2%; padding: 5vh;
padding-bottom: 2%;
box-shadow: 0px 2px 1px -1px rgba(0, 0, 0, 0.2),0px 1px 1px 0px rgba(0, 0, 0, 0.14),0px 1px 3px 0px rgba(0, 0, 0, 0.12); box-shadow: 0px 2px 1px -1px rgba(0, 0, 0, 0.2),0px 1px 1px 0px rgba(0, 0, 0, 0.14),0px 1px 3px 0px rgba(0, 0, 0, 0.12);
transition: box-shadow 280ms cubic-bezier(0.4, 0, 0.2, 1); transition: box-shadow 280ms cubic-bezier(0.4, 0, 0.2, 1);

@ -1,4 +1,5 @@
<div class="product-card"> <div class="product-card">
<mat-icon class="favorite" color="warn" *ngIf="product.favorite">favorite</mat-icon>
<div class="card-content"> <div class="card-content">
<div class="card-img-container"> <div class="card-img-container">
<img src={{product.url}} class="card-img" alt="{{product.name}}"> <img src={{product.url}} class="card-img" alt="{{product.name}}">
@ -10,6 +11,7 @@
</div> </div>
<div class="card-buttons"> <div class="card-buttons">
<button mat-raised-button color="primary" routerLink="/product/{{product.id}}">Details</button> <button mat-raised-button color="primary" routerLink="/product/{{product.id}}">Details</button>
<button mat-raised-button color="primary" (click)="marked.emit(product)">Favorite</button>
</div> </div>
</div> </div>
</div> </div>

@ -1,6 +1,19 @@
$small: 600px; $small: 600px;
$medium: 960px; $medium: 960px;
.favorite {
position: absolute;
pointer-events: none;
cursor: not-allowed;
margin-top: 1%;
margin-left: 13%;
@media screen and (max-width: $medium) {
margin-left: 22%;
}
@media screen and (max-width: $small) {
margin-left: 33%;
}
}
.product-card { .product-card {
display: flex; display: flex;
@ -26,8 +39,6 @@ $medium: 960px;
} }
} }
.card-details-container { .card-details-container {
height: max-content; height: max-content;
padding-top: 15%; padding-top: 15%;
@ -63,9 +74,9 @@ $medium: 960px;
padding-bottom: 5%; padding-bottom: 5%;
button { button {
margin: 2%; margin: 2%;
width: 50%; width: 45%;
@media screen and (max-width: $medium) { @media screen and (max-width: $medium) {
width: 65%; width: 50%;
} }
@media screen and (max-width: $small) { @media screen and (max-width: $small) {
width: 80%; width: 80%;

@ -1,4 +1,4 @@
import { Component, OnInit, Input } from '@angular/core'; import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { Product } from 'src/app/models/product'; import { Product } from 'src/app/models/product';
@Component({ @Component({
@ -16,6 +16,9 @@ export class ProductItemComponent implements OnInit {
description: "", description: "",
quantity: 0 quantity: 0
} }
@Output() marked: EventEmitter<Product> = new EventEmitter;
constructor() { } constructor() { }
ngOnInit(): void { ngOnInit(): void {

@ -1,4 +1,4 @@
<div class="product-list-container"> <div class="product-list-container">
<app-product-item *ngFor="let product of products" [product]="product" class="product-item-container"></app-product-item> <app-product-item class="product-item-container" *ngFor="let product of products" [product]="product" (marked)="markAsFavorite(product)" ></app-product-item>
</div> </div>

@ -18,4 +18,9 @@ export class ProductListComponent implements OnInit {
}) })
} }
markAsFavorite(product: any): void {
console.log(`${product.name} has been added to favorites.`);
product.favorite = true
}
} }

@ -4,5 +4,6 @@ export interface Product {
price: number, price: number,
url : string url : string
description: string, description: string,
quantity: number quantity: number,
favorite?: boolean,
} }
Loading…
Cancel
Save