feat: refactor cart item and cart components for improved layout and styling

This commit is contained in:
2026-07-02 08:42:35 -03:00
parent 06d29be056
commit 8471505e6f
4 changed files with 187 additions and 272 deletions

View File

@@ -1,45 +1,47 @@
<article class="cart-item"> <article class="w-100 rounded-0 cart-item">
<div class="cart-item__media"> <div class="position-relative overflow-hidden cart-item-media">
@if (discountPercentage() && discountPercentage()! > 0) { @if (discountPercentage() && discountPercentage()! > 0) {
<span class="cart-item__discount-badge">-{{ discountPercentage() }}%</span> <span class="position-absolute top-0 start-0 z-1 rounded-0 cart-item-discount-badge">-{{ discountPercentage() }}%</span>
} }
@if (imageUrl()) { @if (imageUrl()) {
<img class="cart-item__image" [src]="imageUrl()" [alt]="product()" /> <img class="w-100 h-100 object-fit-cover d-block" [src]="imageUrl()" [alt]="product()" />
} @else { } @else {
<div class="cart-item__image cart-item__image--placeholder" aria-hidden="true"></div> <div class="w-100 h-100 cart-item-placeholder" aria-hidden="true"></div>
} }
</div> </div>
<div class="cart-item__content"> <div class="d-grid min-w-0 cart-item-content">
<div class="cart-item__top-row"> <div class="d-grid align-items-start cart-item-top-row">
<h3 class="cart-item__product">{{ product() }}</h3> <h3 class="m-0 text-uppercase fw-normal cart-item-product">{{ product() }}</h3>
<div class="cart-item__prices"> <div class="text-nowrap cart-item-prices">
@if (formattedOriginalPrice(); as originalPrice) { @if (formattedOriginalPrice(); as originalPrice) {
<span class="cart-item__price cart-item__price--original">{{ originalPrice }}</span> <span class="text-decoration-line-through fw-light cart-item-original-price">{{ originalPrice }}</span>
} }
<span class="cart-item__price cart-item__price--discounted">{{ formattedDiscountedPrice() }}</span> <span class="fw-normal cart-item-discounted-price">{{ formattedDiscountedPrice() }}</span>
</div> </div>
</div> </div>
<div class="cart-item__attributes"> <div class="d-grid cart-item-attributes">
@for (attribute of attributes(); track attribute.label + attribute.value) { @for (attribute of attributes(); track attribute.label + attribute.value) {
<div class="cart-item__attribute"> <div class="cart-item-attribute">
<span class="cart-item__attribute-label">{{ attribute.label }}:</span> <span class="fw-normal cart-item-attribute-label">{{ attribute.label }}: </span>
<span class="cart-item__attribute-value">{{ attribute.value }}</span> <span class="fw-bold">{{ attribute.value }}</span>
</div> </div>
} }
</div> </div>
<div class="cart-item__actions" aria-hidden="true"> <div class="d-flex justify-content-end align-items-center mt-auto cart-item-actions" aria-hidden="true">
<button class="cart-item__quantity-control" type="button">-</button> <button class="border d-inline-flex align-items-center justify-content-center bg-white rounded-0 cart-item-qty-btn" type="button">-</button>
<span class="cart-item__quantity">{{ quantity() }}</span> <span class="border d-inline-flex align-items-center justify-content-center bg-white rounded-0 cart-item-qty-value" >{{ quantity() }}</span>
<button class="cart-item__quantity-control" type="button">+</button> <button class="border d-inline-flex align-items-center justify-content-center bg-white rounded-0 cart-item-qty-btn" type="button">+</button>
<button class="cart-item__remove" type="button"> <button class="border-0 bg-transparent d-inline-flex align-items-center justify-content-center cart-item-remove-btn" type="button">
<i class="fa-solid fa-trash-can"></i> <i class="fa-solid fa-trash"></i>
</button> </button>
</div> </div>
</div> </div>
</article> </article>

View File

@@ -1,40 +1,32 @@
:host { :host {
display: block; display: block;
--item-media-width: 64px;
--item-media-height: 72px;
}
@media (max-width: 420px) {
:host {
--item-media-width: 56px;
--item-media-height: 64px;
}
} }
.cart-item { .cart-item {
display: grid; display: grid;
grid-template-columns: 64px minmax(0, 1fr); grid-template-columns: var(--item-media-width) minmax(0, 1fr);
gap: 0.75rem; gap: 0.75rem;
padding: 10px 12px; padding: 10px 12px;
border-radius: 0;
background-color: #f5f5f5; background-color: #f5f5f5;
}
&__media { .cart-item-media {
position: relative; width: var(--item-media-width);
width: 64px; height: var(--item-media-height);
height: 72px;
overflow: hidden;
border-radius: 6px 0 0 6px; border-radius: 6px 0 0 6px;
background-color: #d9d9d9; background-color: #d9d9d9;
} }
&__image { .cart-item-discount-badge {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
&__image--placeholder {
background: linear-gradient(135deg, #d2d2d2, #ececec);
}
&__discount-badge {
position: absolute;
top: 0;
left: 0;
z-index: 1;
padding: 2px 5px; padding: 2px 5px;
border-bottom-right-radius: 4px; border-bottom-right-radius: 4px;
background-color: #6173ff; background-color: #6173ff;
@@ -44,117 +36,81 @@
line-height: 1; line-height: 1;
} }
&__content { .cart-item-placeholder {
display: grid; background: linear-gradient(135deg, #d2d2d2, #ececec);
gap: 0.5rem;
min-width: 0;
} }
&__top-row { .cart-item-content {
display: grid; gap: 0.5rem;
}
.cart-item-top-row {
grid-template-columns: minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr) auto;
gap: 0.75rem; gap: 0.75rem;
align-items: start;
} }
&__product { .cart-item-product {
margin: 0;
color: #666666; color: #666666;
font-size: 12px; font-size: 12px;
font-weight: 325;
line-height: 1.25; line-height: 1.25;
text-transform: uppercase; font-weight: 325;
} }
&__prices { .cart-item-prices {
display: grid; display: grid;
justify-items: end; justify-items: end;
white-space: nowrap;
line-height: 1.1; line-height: 1.1;
} }
&__price { .cart-item-original-price {
color: #a0a0a0; color: #a0a0a0;
}
&__price--original {
font-size: 10px; font-size: 10px;
font-weight: 325; font-weight: 325;
text-decoration: line-through;
} }
&__price--discounted { .cart-item-discounted-price {
color: #a0a0a0;
font-size: 13px; font-size: 13px;
font-weight: 425; font-weight: 425;
} }
&__attributes { .cart-item-attributes {
display: grid;
gap: 0.125rem; gap: 0.125rem;
} }
&__attribute { .cart-item-attribute {
color: #666666; color: #666666;
font-size: 11px; font-size: 11px;
line-height: 1.2; line-height: 1.2;
} }
&__attribute-label { .cart-item-attribute-label {
font-weight: 325; font-weight: 325;
} }
&__attribute-value { .cart-item-actions {
font-weight: 700;
}
&__actions {
display: flex;
justify-content: flex-end;
align-items: center;
gap: 0.125rem; gap: 0.125rem;
margin-top: auto;
} }
&__quantity-control, .cart-item-qty-btn,
&__quantity { .cart-item-qty-value {
display: inline-flex;
align-items: center;
justify-content: center;
width: 18px; width: 18px;
height: 18px; height: 18px;
border: 1px solid #cfcfcf; border-color: #cfcfcf !important;
background-color: #ffffff;
color: #666666; color: #666666;
font-size: 10px; font-size: 10px;
line-height: 1; line-height: 1;
} }
&__quantity-control { .cart-item-qty-btn {
padding: 0; padding: 0;
} }
&__remove { .cart-item-remove-btn {
display: inline-flex;
align-items: center;
justify-content: center;
width: 18px; width: 18px;
height: 18px; height: 18px;
margin-left: 0.35rem; margin-left: 0.35rem;
padding: 0; padding: 0;
border: 0;
background: transparent;
color: #b3b3b3; color: #b3b3b3;
font-size: 12px; font-size: 12px;
} }
}
@media (max-width: 420px) {
.cart-item {
grid-template-columns: 56px minmax(0, 1fr);
&__media {
width: 56px;
height: 64px;
}
}
}

View File

@@ -1,15 +1,15 @@
<section class="cart" [style.background-color]="backgroundColor()"> <section class="d-flex flex-column h-100 overflow-hidden text-secondary" [style.background-color]="backgroundColor()">
<header class="cart__header"> <header class="d-flex align-items-center justify-content-between bg-transparent cart-header">
<h2 class="cart__title">{{ title() }}</h2> <h2 class="m-0 text-uppercase fw-bold cart-title">{{ title() }}</h2>
@if (showClose()) { @if (showClose()) {
<button class="cart__close" type="button" aria-label="Cerrar carrito" (click)="closed.emit()"> <button class="btn btn-link p-0 border-0 d-inline-flex align-items-center justify-content-center cart-close-btn" type="button" aria-label="Cerrar carrito" (click)="closed.emit()">
<i class="fa-solid fa-xmark"></i> <i class="fa-solid fa-xmark"></i>
</button> </button>
} }
</header> </header>
<div class="cart__items"> <div class="d-grid gap-2 flex-grow-1 overflow-y-auto cart-items-container">
@for (item of items(); track item.product + item.discountedPrice) { @for (item of items(); track item.product + item.discountedPrice) {
<app-cart-item <app-cart-item
[imageUrl]="item.imageUrl" [imageUrl]="item.imageUrl"
@@ -23,20 +23,22 @@
} }
</div> </div>
<footer class="cart__summary"> <footer class="d-grid gap-1 bg-transparent cart-footer">
<div class="cart__summary-row"> <div class="d-flex align-items-baseline justify-content-between gap-3">
<span class="cart__summary-label">Subtotal:</span> <span class="cart-summary-text-muted">Subtotal:</span>
<span class="cart__summary-value">{{ formattedSubtotal() }}</span> <span class="cart-summary-text-muted-bold">{{ formattedSubtotal() }}</span>
</div> </div>
<div class="cart__summary-row"> <div class="d-flex align-items-baseline justify-content-between gap-3">
<span class="cart__summary-label">Descuento:</span> <span class="cart-summary-text-muted">Descuento:</span>
<span class="cart__summary-value">{{ formattedDiscount() }}</span> <span class="cart-summary-text-muted-bold">{{ formattedDiscount() }}</span>
</div> </div>
<div class="cart__summary-row cart__summary-row--total"> <div class="d-flex align-items-baseline justify-content-between gap-3 mt-1">
<span class="cart__summary-label">TOTAL:</span> <span class="cart-total-text">TOTAL:</span>
<span class="cart__summary-value">{{ formattedTotal() }}</span> <span class="cart-total-text">{{ formattedTotal() }}</span>
</div> </div>
</footer> </footer>
</section> </section>

View File

@@ -5,102 +5,57 @@
height: 100%; height: 100%;
} }
.cart { .cart-header {
display: grid;
grid-template-rows: auto minmax(0, 1fr) auto;
width: 100%;
height: 100%;
color: #666666;
border-radius: 0;
overflow: hidden;
&__header,
&__summary {
background-color: inherit;
}
&__header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 8px 0 24px; padding: 12px 8px 0 24px;
} }
&__title { .cart-title {
margin: 0;
color: #a0a0a0; color: #a0a0a0;
font-size: 13px; font-size: 13px;
font-weight: 700;
letter-spacing: 0.04em; letter-spacing: 0.04em;
} }
&__close { .cart-close-btn {
display: inline-flex;
align-items: center;
justify-content: center;
width: 24px; width: 24px;
height: 24px; height: 24px;
padding: 0;
border: 0;
background: transparent;
color: #a0a0a0;
font-size: 14px; font-size: 14px;
color: #a0a0a0;
} }
&__items { .cart-items-container {
display: grid;
gap: 8px;
min-height: 0; min-height: 0;
padding: 0 0 0 24px; padding: 0 0 0 24px;
overflow-y: auto;
scrollbar-color: #d5d5d5 transparent; scrollbar-color: #d5d5d5 transparent;
scrollbar-width: thin; scrollbar-width: thin;
}
&__items::-webkit-scrollbar { &::-webkit-scrollbar {
width: 6px; width: 6px;
} }
&__items::-webkit-scrollbar-thumb { &::-webkit-scrollbar-thumb {
border-radius: 999px; border-radius: 999px;
background-color: #d5d5d5; background-color: #d5d5d5;
} }
}
&__summary { .cart-footer {
display: grid;
gap: 0.35rem;
padding: 8px 22px 14px 24px; padding: 8px 22px 14px 24px;
} }
&__summary-row { .cart-summary-text-muted {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 1rem;
}
&__summary-label,
&__summary-value {
color: #a0a0a0; color: #a0a0a0;
font-size: 13px; font-size: 13px;
}
&__summary-label {
font-weight: 325; font-weight: 325;
} }
&__summary-value { .cart-summary-text-muted-bold {
color: #a0a0a0;
font-size: 13px;
font-weight: 700; font-weight: 700;
} }
&__summary-row--total { .cart-total-text {
margin-top: 0.2rem;
}
&__summary-row--total .cart__summary-label,
&__summary-row--total .cart__summary-value {
color: #666666; color: #666666;
font-size: 15px; font-size: 15px;
font-weight: 700; font-weight: 700;
} }
}