feat: add icon button component and integrate into cart item for improved UI
This commit is contained in:
@@ -41,9 +41,11 @@
|
||||
(increase)="onIncrease()"
|
||||
(decrease)="onDecrease()"
|
||||
/>
|
||||
<button class="border-0 bg-transparent d-inline-flex align-items-center justify-content-center cart-item-remove-btn" type="button" (click)="onRemove()">
|
||||
<i class="fa-solid fa-trash"></i>
|
||||
</button>
|
||||
<app-icon-button
|
||||
variant="trash"
|
||||
class="cart-item-remove-btn"
|
||||
(click)="onRemove()"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
@@ -96,10 +96,5 @@
|
||||
|
||||
|
||||
.cart-item-remove-btn {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
margin-left: 0.35rem;
|
||||
padding: 0;
|
||||
color: #b3b3b3;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ChangeDetectionStrategy, Component, computed, input, output } from '@angular/core';
|
||||
import { QuantitySelectorComponent } from '../quantity-selector/quantity-selector.component';
|
||||
import { IconButtonComponent } from '../icon-button/icon-button.component';
|
||||
|
||||
export interface CartItemAttribute {
|
||||
label: string;
|
||||
@@ -9,7 +10,7 @@ export interface CartItemAttribute {
|
||||
@Component({
|
||||
selector: 'app-cart-item',
|
||||
standalone: true,
|
||||
imports: [QuantitySelectorComponent],
|
||||
imports: [QuantitySelectorComponent, IconButtonComponent],
|
||||
templateUrl: './cart-item.component.html',
|
||||
styleUrl: './cart-item.component.scss',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<button
|
||||
type="button"
|
||||
[disabled]="disabled()"
|
||||
[ngClass]="buttonClasses()"
|
||||
[attr.aria-label]="ariaLabel() || variant()"
|
||||
>
|
||||
<i [ngClass]="iconClass()"></i>
|
||||
</button>
|
||||
@@ -0,0 +1,64 @@
|
||||
:host {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.icon-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: transparent;
|
||||
border: none;
|
||||
padding: 4px;
|
||||
margin: 0;
|
||||
color: #666666;
|
||||
font-size: 20px;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
transition: color 0.15s ease-in-out, transform 0.1s ease-in-out;
|
||||
border-radius: 4px;
|
||||
|
||||
i {
|
||||
display: inline-block;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
// Active state subtle scale down
|
||||
&:active:not(:disabled) {
|
||||
transform: scale(0.92);
|
||||
}
|
||||
|
||||
// Focus ring for accessibility
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--tenant-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
// Disabled state
|
||||
&:disabled {
|
||||
color: #A0A0A0;
|
||||
cursor: not-allowed;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
// Hover/Active/Focus colors (non-disabled)
|
||||
.icon-btn:hover:not(:disabled),
|
||||
.icon-btn:focus-visible:not(:disabled),
|
||||
.icon-btn.hover-preview:not(:disabled),
|
||||
:host(.hover-preview) .icon-btn:not(:disabled) {
|
||||
color: var(--tenant-primary);
|
||||
}
|
||||
|
||||
// Trash is special (uses danger color for hover/active)
|
||||
.icon-btn--trash {
|
||||
&:hover:not(:disabled),
|
||||
&:focus-visible:not(:disabled),
|
||||
&.hover-preview:not(:disabled) {
|
||||
color: var(--tenant-danger);
|
||||
}
|
||||
}
|
||||
|
||||
:host(.hover-preview) .icon-btn--trash:not(:disabled) {
|
||||
color: var(--tenant-danger);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core';
|
||||
import { NgClass } from '@angular/common';
|
||||
|
||||
export type IconButtonVariant =
|
||||
| 'user'
|
||||
| 'trash'
|
||||
| 'angle-right'
|
||||
| 'angle-left'
|
||||
| 'angle-up'
|
||||
| 'angle-down'
|
||||
| 'copy';
|
||||
|
||||
@Component({
|
||||
selector: 'app-icon-button',
|
||||
imports: [NgClass],
|
||||
templateUrl: './icon-button.component.html',
|
||||
styleUrl: './icon-button.component.scss',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class IconButtonComponent {
|
||||
readonly variant = input.required<IconButtonVariant>();
|
||||
readonly disabled = input(false);
|
||||
readonly ariaLabel = input<string>('');
|
||||
|
||||
protected readonly iconClass = computed(() => {
|
||||
const classes: Record<IconButtonVariant, string> = {
|
||||
user: 'fa-regular fa-circle-user',
|
||||
trash: 'fa-solid fa-trash',
|
||||
'angle-right': 'fa-solid fa-angle-right',
|
||||
'angle-left': 'fa-solid fa-angle-left',
|
||||
'angle-up': 'fa-solid fa-angle-up',
|
||||
'angle-down': 'fa-solid fa-angle-down',
|
||||
copy: 'fa-solid fa-copy'
|
||||
};
|
||||
return classes[this.variant()];
|
||||
});
|
||||
|
||||
protected readonly buttonClasses = computed(() => {
|
||||
return ['icon-btn', `icon-btn--${this.variant()}`];
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user