Compare commits
18 Commits
fc04992ebb
...
tenant/sme
| Author | SHA1 | Date | |
|---|---|---|---|
| 3558b6f575 | |||
| f4959e0250 | |||
| ee1420801d | |||
| 4b9343a867 | |||
| 114a986205 | |||
| b320501650 | |||
| 2162ae3963 | |||
| 92cc1c0275 | |||
| ed806abb9f | |||
| 321f2c08cd | |||
| 9ba3b24b7e | |||
| b8b5292200 | |||
| e8602cca13 | |||
| 36fda9f7ea | |||
| 230e5b01ac | |||
| 85f1b820b4 | |||
| 0fffdc5c5a | |||
| 0e6c949513 |
@@ -31,7 +31,13 @@
|
|||||||
|
|
||||||
<div class="immersive-header__actions">
|
<div class="immersive-header__actions">
|
||||||
@if (displaySearchBar()) {
|
@if (displaySearchBar()) {
|
||||||
<form class="immersive-header__search" role="search" (submit)="submitSearch($event)">
|
<form
|
||||||
|
id="immersive-search"
|
||||||
|
class="immersive-header__search"
|
||||||
|
[class.immersive-header__search--open]="isSearchOpen()"
|
||||||
|
role="search"
|
||||||
|
(submit)="submitSearch($event)"
|
||||||
|
>
|
||||||
<label class="visually-hidden" for="immersive-search-input">Buscar productos</label>
|
<label class="visually-hidden" for="immersive-search-input">Buscar productos</label>
|
||||||
<app-input
|
<app-input
|
||||||
id="immersive-search-input"
|
id="immersive-search-input"
|
||||||
@@ -49,15 +55,32 @@
|
|||||||
</form>
|
</form>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@if (!showHero()) {
|
||||||
@if (ticketsMenu(); as menu) {
|
@if (ticketsMenu(); as menu) {
|
||||||
<app-button
|
<app-button
|
||||||
variant="secondary"
|
variant="primary"
|
||||||
hostClass="immersive-header__tickets"
|
hostClass="immersive-header__tickets"
|
||||||
|
data-testid="store-header-tickets"
|
||||||
(click)="ticketsClick.emit()"
|
(click)="ticketsClick.emit()"
|
||||||
>
|
>
|
||||||
{{ menu.label }}
|
{{ menu.label }}
|
||||||
</app-button>
|
</app-button>
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (!showHero() && displaySearchBar()) {
|
||||||
|
<button
|
||||||
|
#searchToggle
|
||||||
|
type="button"
|
||||||
|
class="immersive-header__search-toggle"
|
||||||
|
aria-label="Buscar productos"
|
||||||
|
aria-controls="immersive-search"
|
||||||
|
[attr.aria-expanded]="isSearchOpen()"
|
||||||
|
(click)="toggleSearch()"
|
||||||
|
>
|
||||||
|
<i class="fa-solid fa-magnifying-glass" aria-hidden="true"></i>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
|
||||||
@if (displayCart()) {
|
@if (displayCart()) {
|
||||||
<app-cart-icon
|
<app-cart-icon
|
||||||
@@ -78,13 +101,19 @@
|
|||||||
[ariaExpanded]="isUserDropdownOpen()"
|
[ariaExpanded]="isUserDropdownOpen()"
|
||||||
(clicked)="toggleUserDropdown()"
|
(clicked)="toggleUserDropdown()"
|
||||||
/>
|
/>
|
||||||
@if (isUserDropdownOpen()) {
|
@if (isUserDropdownOpen() && isAuthenticated()) {
|
||||||
<app-user-dropdown
|
<app-user-dropdown
|
||||||
id="immersive-user-dropdown"
|
id="immersive-user-dropdown"
|
||||||
[user]="user()"
|
[user]="user()"
|
||||||
[accountNavigationMenus]="accountNavigationMenus()"
|
[accountNavigationMenus]="accountNavigationMenus()"
|
||||||
(logoutClick)="onLogoutClick()"
|
(logoutClick)="onLogoutClick()"
|
||||||
/>
|
/>
|
||||||
|
} @else if (isUserDropdownOpen()) {
|
||||||
|
<div id="immersive-user-dropdown" class="immersive-header__guest-menu">
|
||||||
|
<button type="button" (click)="isUserDropdownOpen.set(false); loginClick.emit()">
|
||||||
|
Iniciar sesión
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -116,5 +145,7 @@
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<ng-content />
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: minmax(0, 1fr);
|
grid-template-columns: minmax(0, 1fr);
|
||||||
isolation: isolate;
|
isolation: isolate;
|
||||||
min-height: 640px;
|
|
||||||
color: #fff;
|
color: #fff;
|
||||||
background: #f5f5f5;
|
background: #f5f5f5;
|
||||||
}
|
}
|
||||||
@@ -18,7 +17,7 @@
|
|||||||
z-index: 1;
|
z-index: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
padding-top: clamp(1.75rem, 4vw, 2.5rem);
|
padding-top: clamp(1.75rem, 4vw, 2.5rem);
|
||||||
padding-bottom: 0.5rem;
|
padding-bottom: clamp(1rem, 2vw, 1.5rem);
|
||||||
}
|
}
|
||||||
|
|
||||||
.immersive-header__backdrop {
|
.immersive-header__backdrop {
|
||||||
@@ -59,7 +58,10 @@
|
|||||||
|
|
||||||
.immersive-header__nav {
|
.immersive-header__nav {
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 1;
|
// Keep the whole navigation stacking context above the hero copy and carousel.
|
||||||
|
// Otherwise those later siblings can sit on top of the dropdown and capture
|
||||||
|
// pointer events even though the dropdown itself has a high z-index.
|
||||||
|
z-index: 10;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
@@ -102,15 +104,11 @@
|
|||||||
}
|
}
|
||||||
.immersive-header__account {
|
.immersive-header__account {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
// The nav becomes display: contents on mobile, so it cannot provide the
|
||||||
|
// stacking context there. Keep the dropdown trigger above following rows.
|
||||||
|
z-index: 10;
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
.immersive-header__account app-user-dropdown {
|
|
||||||
position: absolute;
|
|
||||||
top: 100%;
|
|
||||||
right: 0;
|
|
||||||
z-index: 20;
|
|
||||||
color: #222;
|
|
||||||
}
|
|
||||||
:host ::ng-deep .immersive-header__actions .icon-btn,
|
:host ::ng-deep .immersive-header__actions .icon-btn,
|
||||||
:host ::ng-deep .immersive-header__actions .cart-icon {
|
:host ::ng-deep .immersive-header__actions .cart-icon {
|
||||||
color: var(--tenant-primary, #ff7006);
|
color: var(--tenant-primary, #ff7006);
|
||||||
@@ -137,11 +135,13 @@
|
|||||||
.immersive-header__title {
|
.immersive-header__title {
|
||||||
margin: -0.15rem 0 0;
|
margin: -0.15rem 0 0;
|
||||||
font-size: 140px;
|
font-size: 140px;
|
||||||
line-height: 1.05;
|
line-height: 0.7;
|
||||||
}
|
}
|
||||||
.immersive-header__description {
|
.immersive-header__description {
|
||||||
margin: 1.15rem 0 0;
|
margin: 30px 0 0;
|
||||||
font-size: clamp(0.75rem, 1.4vw, 0.95rem);
|
font-family: 'Gotham Book', sans-serif;
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 300;
|
||||||
text-shadow: 0 1px 5px rgba(0, 0, 0, 0.6);
|
text-shadow: 0 1px 5px rgba(0, 0, 0, 0.6);
|
||||||
}
|
}
|
||||||
.immersive-header__timer {
|
.immersive-header__timer {
|
||||||
@@ -159,10 +159,86 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.immersive-header--compact {
|
.immersive-header--compact {
|
||||||
min-height: 0;
|
min-height: 115px;
|
||||||
padding-bottom: 1.5rem;
|
|
||||||
color: #666666;
|
color: #666666;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
|
|
||||||
|
.immersive-header__content {
|
||||||
|
padding: 35px 0 36px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__nav {
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
gap: 0.75rem;
|
||||||
|
min-height: 44px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__brand img {
|
||||||
|
width: clamp(92px, 24vw, 145px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__actions {
|
||||||
|
flex: 0 1 auto;
|
||||||
|
gap: 0.375rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__search-toggle {
|
||||||
|
display: none;
|
||||||
|
flex: none;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 32px;
|
||||||
|
height: 44px;
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: transparent;
|
||||||
|
color: #888;
|
||||||
|
font-size: 20px;
|
||||||
|
|
||||||
|
&:focus-visible {
|
||||||
|
outline: 2px solid var(--tenant-primary);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__guest-menu {
|
||||||
|
position: absolute;
|
||||||
|
top: calc(100% + 0.5rem);
|
||||||
|
right: 0;
|
||||||
|
min-width: 180px;
|
||||||
|
padding: 0.5rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #fff;
|
||||||
|
box-shadow: 0 4px 16px #0002;
|
||||||
|
|
||||||
|
button {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.75rem;
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
color: #666;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:host ::ng-deep .immersive-header--compact {
|
||||||
|
.immersive-header__tickets {
|
||||||
|
flex: none;
|
||||||
|
width: auto;
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
min-width: 120px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__account .icon-btn {
|
||||||
|
width: 32px;
|
||||||
|
height: 44px;
|
||||||
|
color: #888;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.immersive-header--compact .immersive-header__backdrop {
|
.immersive-header--compact .immersive-header__backdrop {
|
||||||
display: none;
|
display: none;
|
||||||
@@ -170,7 +246,18 @@
|
|||||||
|
|
||||||
:host ::ng-deep .immersive-header--compact .immersive-header__actions .icon-btn,
|
:host ::ng-deep .immersive-header--compact .immersive-header__actions .icon-btn,
|
||||||
:host ::ng-deep .immersive-header--compact .immersive-header__actions .cart-icon {
|
:host ::ng-deep .immersive-header--compact .immersive-header__actions .cart-icon {
|
||||||
color: #666666;
|
color: #888;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 359.98px) {
|
||||||
|
.immersive-header--compact .immersive-header__nav {
|
||||||
|
padding-inline: 1rem !important;
|
||||||
|
gap: 0.375rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header--compact .immersive-header__actions {
|
||||||
|
gap: 0.125rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 600px) {
|
@media (max-width: 600px) {
|
||||||
@@ -195,3 +282,175 @@
|
|||||||
font-size: clamp(3rem, 12vw, 5rem);
|
font-size: clamp(3rem, 12vw, 5rem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: 767.98px) {
|
||||||
|
.immersive-header--compact {
|
||||||
|
.immersive-header__search {
|
||||||
|
position: absolute;
|
||||||
|
top: calc(100% + 0.5rem);
|
||||||
|
right: 8vw;
|
||||||
|
display: none;
|
||||||
|
width: min(320px, 84vw);
|
||||||
|
padding: 0.75rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #f5f5f5;
|
||||||
|
box-shadow: 0 4px 16px #0002;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__search--open {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__search-error {
|
||||||
|
position: static;
|
||||||
|
display: block;
|
||||||
|
margin-top: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__search-toggle {
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header:not(.immersive-header--compact) {
|
||||||
|
min-height: 0;
|
||||||
|
|
||||||
|
.immersive-header__content {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) auto auto;
|
||||||
|
align-items: center;
|
||||||
|
align-content: start;
|
||||||
|
padding: 1.875rem 0 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep one search form while placing it below the hero copy on mobile.
|
||||||
|
.immersive-header__nav,
|
||||||
|
.immersive-header__actions {
|
||||||
|
display: contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__brand {
|
||||||
|
grid-area: 1 / 1;
|
||||||
|
margin-left: 8vw;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__brand img {
|
||||||
|
width: clamp(105px, 34vw, 145px);
|
||||||
|
}
|
||||||
|
|
||||||
|
app-cart-icon {
|
||||||
|
grid-area: 1 / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__account {
|
||||||
|
grid-area: 1 / 3;
|
||||||
|
margin-right: calc(8vw - 0.75rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__timer {
|
||||||
|
grid-area: 2 / 1 / auto / -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__copy {
|
||||||
|
grid-area: 3 / 1 / auto / -1;
|
||||||
|
margin: 1.25rem 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__eyebrow {
|
||||||
|
font-size: clamp(18px, 5.5vw, 24px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__title {
|
||||||
|
font-size: clamp(40px, 12vw, 56px);
|
||||||
|
line-height: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__description {
|
||||||
|
margin-top: 30px;
|
||||||
|
font-size: clamp(11px, 3vw, 14px);
|
||||||
|
line-height: 1.5;
|
||||||
|
color: #666;
|
||||||
|
text-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__search {
|
||||||
|
grid-area: 4 / 1 / auto / -1;
|
||||||
|
width: 74%;
|
||||||
|
max-width: 28rem;
|
||||||
|
margin: 0.5rem auto 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__search-error {
|
||||||
|
right: auto;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
color: var(--tenant-danger, #dc3545);
|
||||||
|
}
|
||||||
|
|
||||||
|
app-continuous-image-carousel {
|
||||||
|
grid-area: 6 / 1 / auto / -1;
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
--carousel-card-width: 27vw;
|
||||||
|
--carousel-gap: 3.3vw;
|
||||||
|
--carousel-offset: -9vw;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__backdrop-image {
|
||||||
|
object-position: center 42%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__backdrop {
|
||||||
|
// Keep the fade tied to the hero, independent of the content below it.
|
||||||
|
align-self: start;
|
||||||
|
height: 12.5rem;
|
||||||
|
// Fade the entire layer so its dark base cannot leave a subpixel seam.
|
||||||
|
mask-image: linear-gradient(#000 calc(100% - 8px), transparent 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__backdrop::after {
|
||||||
|
background: linear-gradient(
|
||||||
|
180deg,
|
||||||
|
rgba(0, 0, 0, 0.25) 0%,
|
||||||
|
rgba(245, 245, 245, 0.1) 30%,
|
||||||
|
rgba(245, 245, 245, 0.65) 65%,
|
||||||
|
#f5f5f5 98%,
|
||||||
|
#f5f5f5 100%
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:host ::ng-deep .immersive-header:not(.immersive-header--compact) {
|
||||||
|
.immersive-header__search .form-control {
|
||||||
|
min-height: 36px;
|
||||||
|
padding: 0.25rem 2.5rem 0.25rem 0.75rem;
|
||||||
|
border: 1px solid #888;
|
||||||
|
border-radius: 3px;
|
||||||
|
background: transparent;
|
||||||
|
color: #666;
|
||||||
|
font-size: 16px;
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus-visible {
|
||||||
|
outline: 2px solid #666;
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__search .input-search-icon {
|
||||||
|
color: #666;
|
||||||
|
right: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.immersive-header__account .icon-btn {
|
||||||
|
min-width: 44px;
|
||||||
|
min-height: 44px;
|
||||||
|
|
||||||
|
i {
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import {
|
|||||||
input,
|
input,
|
||||||
output,
|
output,
|
||||||
signal,
|
signal,
|
||||||
|
afterRenderEffect,
|
||||||
|
viewChild,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { RouterLink } from '@angular/router';
|
import { RouterLink } from '@angular/router';
|
||||||
import { AuthUser } from '../../../services/auth/auth.interfaces';
|
import { AuthUser } from '../../../services/auth/auth.interfaces';
|
||||||
@@ -59,6 +61,20 @@ export class ImmersiveStoreHeaderComponent {
|
|||||||
protected searchTerm = '';
|
protected searchTerm = '';
|
||||||
protected readonly showSearchError = signal(false);
|
protected readonly showSearchError = signal(false);
|
||||||
protected readonly isUserDropdownOpen = signal(false);
|
protected readonly isUserDropdownOpen = signal(false);
|
||||||
|
protected readonly isSearchOpen = signal(false);
|
||||||
|
private readonly searchInput = viewChild(InputComponent);
|
||||||
|
private readonly searchToggle = viewChild<ElementRef<HTMLButtonElement>>('searchToggle');
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
afterRenderEffect(() => {
|
||||||
|
if (this.isSearchOpen()) this.searchInput()?.focus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected toggleSearch(): void {
|
||||||
|
this.isUserDropdownOpen.set(false);
|
||||||
|
this.isSearchOpen.update((open) => !open);
|
||||||
|
}
|
||||||
protected readonly checkoutRemainingTime = computed(() => {
|
protected readonly checkoutRemainingTime = computed(() => {
|
||||||
const seconds = this.checkoutRemainingSeconds();
|
const seconds = this.checkoutRemainingSeconds();
|
||||||
if (seconds === null) return null;
|
if (seconds === null) return null;
|
||||||
@@ -76,11 +92,13 @@ export class ImmersiveStoreHeaderComponent {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.showSearchError.set(false);
|
this.showSearchError.set(false);
|
||||||
|
this.isSearchOpen.set(false);
|
||||||
this.searchSubmit.emit(term);
|
this.searchSubmit.emit(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected toggleUserDropdown(): void {
|
protected toggleUserDropdown(): void {
|
||||||
if (!this.isAuthenticated()) {
|
this.isSearchOpen.set(false);
|
||||||
|
if (this.showHero() && !this.isAuthenticated()) {
|
||||||
this.loginClick.emit();
|
this.loginClick.emit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -100,11 +118,14 @@ export class ImmersiveStoreHeaderComponent {
|
|||||||
protected onDocumentClick(event: MouseEvent): void {
|
protected onDocumentClick(event: MouseEvent): void {
|
||||||
if (event.target instanceof Node && !this.host.nativeElement.contains(event.target)) {
|
if (event.target instanceof Node && !this.host.nativeElement.contains(event.target)) {
|
||||||
this.isUserDropdownOpen.set(false);
|
this.isUserDropdownOpen.set(false);
|
||||||
|
this.isSearchOpen.set(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('document:keydown.escape')
|
@HostListener('document:keydown.escape')
|
||||||
protected onEscapeKey(): void {
|
protected onEscapeKey(): void {
|
||||||
|
if (this.isSearchOpen()) this.searchToggle()?.nativeElement.focus();
|
||||||
|
this.isSearchOpen.set(false);
|
||||||
this.isUserDropdownOpen.set(false);
|
this.isUserDropdownOpen.set(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,6 @@
|
|||||||
background-size: cover;
|
background-size: cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
.store-layout__header-main {
|
|
||||||
border-bottom: 1px solid var(--border-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.store-layout__categories {
|
.store-layout__categories {
|
||||||
height: 3.5rem;
|
height: 3.5rem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,17 @@
|
|||||||
(loginClick)="loginClick.emit()"
|
(loginClick)="loginClick.emit()"
|
||||||
(logoutClick)="logoutClick.emit()"
|
(logoutClick)="logoutClick.emit()"
|
||||||
(searchSubmit)="searchSubmit.emit($event)"
|
(searchSubmit)="searchSubmit.emit($event)"
|
||||||
|
>
|
||||||
|
@if (showHero() && displayCategories() && categories().length) {
|
||||||
|
<nav class="immersive-categories" aria-label="Categorías">
|
||||||
|
<app-horizontal-carousel
|
||||||
|
[items]="categoryItems()"
|
||||||
|
ariaLabel="Categorías"
|
||||||
|
(itemSelect)="onCategoryItemSelect($event)"
|
||||||
/>
|
/>
|
||||||
|
</nav>
|
||||||
|
}
|
||||||
|
</app-immersive-store-header>
|
||||||
}
|
}
|
||||||
@default {
|
@default {
|
||||||
<ng-container *ngTemplateOutlet="standardHeader" />
|
<ng-container *ngTemplateOutlet="standardHeader" />
|
||||||
@@ -50,19 +60,3 @@
|
|||||||
(categorySelect)="categorySelect.emit($event)"
|
(categorySelect)="categorySelect.emit($event)"
|
||||||
/>
|
/>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
@if (headerType() === 'immersive' && displayCategories() && categories().length) {
|
|
||||||
<nav class="immersive-categories" aria-label="Categorías">
|
|
||||||
<div class="immersive-categories__list">
|
|
||||||
@for (category of categories(); track category.id) {
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="immersive-categories__item"
|
|
||||||
(click)="categorySelect.emit(category)"
|
|
||||||
>
|
|
||||||
{{ category.nombre | uppercase }}
|
|
||||||
</button>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,47 +2,54 @@
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host(.immersive-shell--compact) {
|
app-immersive-store-header {
|
||||||
background-color: #f5f5f5;
|
position: relative;
|
||||||
background-position: center 42%;
|
z-index: 1;
|
||||||
background-size: cover;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:host(.immersive-shell--compact) .immersive-categories {
|
:host(.immersive-shell--compact) {
|
||||||
border-top: 1px solid rgba(255, 255, 255, 0.6);
|
position: relative;
|
||||||
background: transparent;
|
background-color: #f5f5f5;
|
||||||
|
background-image: none !important;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
background-image: var(--compact-header-background);
|
||||||
|
background-position: left top, center 42%;
|
||||||
|
background-size: 100% 100%, cover;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
mask-image: linear-gradient(#000 calc(100% - 12px), transparent calc(100% - 4px));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.immersive-categories {
|
.immersive-categories {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
overflow-x: auto;
|
margin-top: clamp(5rem, 11vw, 9rem);
|
||||||
background: #f5f5f5;
|
padding: 0.375rem 1rem;
|
||||||
}
|
|
||||||
|
|
||||||
.immersive-categories__list {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
gap: clamp(1rem, 3vw, 2.5rem);
|
|
||||||
width: max-content;
|
|
||||||
min-width: 100%;
|
|
||||||
min-height: 3.5rem;
|
|
||||||
padding: 0.75rem 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.immersive-categories__item {
|
|
||||||
flex: none;
|
|
||||||
border: 0;
|
|
||||||
padding: 0;
|
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: #666666;
|
color: #666;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
white-space: nowrap;
|
--horizontal-carousel-gap: 90px;
|
||||||
cursor: pointer;
|
--horizontal-carousel-text-transform: uppercase;
|
||||||
}
|
}
|
||||||
|
|
||||||
.immersive-categories__item:hover,
|
@media (max-width: 767.98px) {
|
||||||
.immersive-categories__item:focus-visible {
|
.immersive-categories {
|
||||||
text-decoration: underline;
|
grid-area: 5 / 1 / auto / -1;
|
||||||
|
min-width: 0;
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
padding: 0 1rem;
|
||||||
|
font-size: clamp(10px, 2.8vw, 12px);
|
||||||
|
--horizontal-carousel-visible-items: 3;
|
||||||
|
--horizontal-carousel-gap: 0.5rem;
|
||||||
|
--horizontal-carousel-item-width: calc((100cqw - 2 * var(--horizontal-carousel-gap)) / 3);
|
||||||
|
--horizontal-carousel-white-space: normal;
|
||||||
|
--horizontal-carousel-snap: x mandatory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,31 @@
|
|||||||
import { NgTemplateOutlet, UpperCasePipe } from '@angular/common';
|
import { NgTemplateOutlet } from '@angular/common';
|
||||||
import { Component, computed, input, output } from '@angular/core';
|
import { Component, computed, input, output } from '@angular/core';
|
||||||
import { AuthUser } from '../../../services/auth/auth.interfaces';
|
import { AuthUser } from '../../../services/auth/auth.interfaces';
|
||||||
import { Category, Menu, WebsiteExtras } from '../../../services/tenant.interface';
|
import { Category, Menu, WebsiteExtras } from '../../../services/tenant.interface';
|
||||||
import { ImmersiveStoreHeaderComponent } from './immersive-store-header.component';
|
import { ImmersiveStoreHeaderComponent } from './immersive-store-header.component';
|
||||||
import { StandardStoreHeaderComponent } from './standard-store-header.component';
|
import { StandardStoreHeaderComponent } from './standard-store-header.component';
|
||||||
|
|
||||||
|
import {
|
||||||
|
HorizontalCarouselComponent,
|
||||||
|
HorizontalCarouselItem,
|
||||||
|
} from '../../../../shared/components/horizontal-carousel/horizontal-carousel.component';
|
||||||
|
|
||||||
export type StoreHeaderType = 'standard' | 'immersive';
|
export type StoreHeaderType = 'standard' | 'immersive';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-store-header',
|
selector: 'app-store-header',
|
||||||
imports: [NgTemplateOutlet, UpperCasePipe, StandardStoreHeaderComponent, ImmersiveStoreHeaderComponent],
|
imports: [
|
||||||
|
NgTemplateOutlet,
|
||||||
|
HorizontalCarouselComponent,
|
||||||
|
StandardStoreHeaderComponent,
|
||||||
|
ImmersiveStoreHeaderComponent,
|
||||||
|
],
|
||||||
templateUrl: './store-header.component.html',
|
templateUrl: './store-header.component.html',
|
||||||
styleUrl: './store-header.component.scss',
|
styleUrl: './store-header.component.scss',
|
||||||
host: {
|
host: {
|
||||||
'[class.immersive-shell--compact]': 'isCompactImmersive()',
|
'[class.immersive-shell--compact]': 'isCompactImmersive()',
|
||||||
'[style.background-image]': 'compactBackground()',
|
'[style.background-image]': 'null',
|
||||||
|
'[style.--compact-header-background]': 'compactBackground()',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
export class StoreHeaderComponent {
|
export class StoreHeaderComponent {
|
||||||
@@ -31,7 +42,7 @@ export class StoreHeaderComponent {
|
|||||||
if (!this.isCompactImmersive()) return null;
|
if (!this.isCompactImmersive()) return null;
|
||||||
|
|
||||||
const gradient =
|
const gradient =
|
||||||
'linear-gradient(180deg, rgba(245, 245, 245, 0.72) 0%, rgba(245, 245, 245, 0.88) 58%, #f5f5f5 100%)';
|
'linear-gradient(180deg, rgba(245, 245, 245, 0.72) 0%, rgba(245, 245, 245, 0.88) 58%, #f5f5f5 calc(100% - 4px), #f5f5f5 100%)';
|
||||||
const image = this.backgroundImageUrl();
|
const image = this.backgroundImageUrl();
|
||||||
return image ? `${gradient}, url(${JSON.stringify(image)})` : gradient;
|
return image ? `${gradient}, url(${JSON.stringify(image)})` : gradient;
|
||||||
});
|
});
|
||||||
@@ -53,4 +64,13 @@ export class StoreHeaderComponent {
|
|||||||
readonly logoutClick = output<void>();
|
readonly logoutClick = output<void>();
|
||||||
readonly searchSubmit = output<string>();
|
readonly searchSubmit = output<string>();
|
||||||
readonly categorySelect = output<Category>();
|
readonly categorySelect = output<Category>();
|
||||||
|
|
||||||
|
protected readonly categoryItems = computed(() =>
|
||||||
|
this.categories().map((category) => ({ value: category.id, label: category.nombre })),
|
||||||
|
);
|
||||||
|
|
||||||
|
protected onCategoryItemSelect(item: HorizontalCarouselItem): void {
|
||||||
|
const category = this.categories().find((candidate) => candidate.id === item.value);
|
||||||
|
if (category) this.categorySelect.emit(category);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,7 @@
|
|||||||
|
|
||||||
@media (max-width: 575.98px) {
|
@media (max-width: 575.98px) {
|
||||||
:host {
|
:host {
|
||||||
right: -0.5rem;
|
right: 0;
|
||||||
|
width: min(18rem, calc(100vw - 1rem));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -305,7 +305,34 @@ describe('StoreLayoutComponent', () => {
|
|||||||
expect(element.querySelector('app-cart-icon')).not.toBeNull();
|
expect(element.querySelector('app-cart-icon')).not.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows immersive categories below the header and navigates on selection', () => {
|
it('keeps tickets in the immersive account dropdown while hiding its root action', () => {
|
||||||
|
const authService = TestBed.inject(AuthService);
|
||||||
|
(authService.isAuthenticated as any).set(true);
|
||||||
|
(authService.user as any).set({
|
||||||
|
id: 1,
|
||||||
|
nombre_apellido: 'Ada Lovelace',
|
||||||
|
email: 'ada@example.com',
|
||||||
|
});
|
||||||
|
tenantState.set({ ...tenant, header_type: 'immersive' });
|
||||||
|
|
||||||
|
const fixture = TestBed.createComponent(StoreLayoutComponent);
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
const element = fixture.nativeElement as HTMLElement;
|
||||||
|
expect(element.querySelector('[data-testid="store-header-tickets"]')).toBeNull();
|
||||||
|
|
||||||
|
element.querySelector<HTMLButtonElement>('app-icon-button[variant="user"] button')?.click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(element.querySelector('[data-testid="user-dropdown-account.tickets"]')).not.toBeNull();
|
||||||
|
|
||||||
|
(fixture.componentInstance as any).isHomeRoute.set(false);
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(element.querySelector('[data-testid="store-header-tickets"]')).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows immersive categories inside the header and navigates on selection', () => {
|
||||||
tenantState.set({
|
tenantState.set({
|
||||||
...tenant,
|
...tenant,
|
||||||
header_type: 'immersive',
|
header_type: 'immersive',
|
||||||
@@ -335,7 +362,7 @@ describe('StoreLayoutComponent', () => {
|
|||||||
|
|
||||||
expect(header).not.toBeNull();
|
expect(header).not.toBeNull();
|
||||||
expect(categories).not.toBeNull();
|
expect(categories).not.toBeNull();
|
||||||
expect(header?.contains(categories)).toBe(false);
|
expect(header?.contains(categories)).toBe(true);
|
||||||
expect(categoryButton?.textContent?.trim()).toBe('MÚSICA');
|
expect(categoryButton?.textContent?.trim()).toBe('MÚSICA');
|
||||||
|
|
||||||
const navigate = vi.spyOn(TestBed.inject(Router), 'navigate');
|
const navigate = vi.spyOn(TestBed.inject(Router), 'navigate');
|
||||||
@@ -708,7 +735,7 @@ describe('StoreLayoutComponent', () => {
|
|||||||
expect(
|
expect(
|
||||||
compiled.querySelector('[data-testid="user-dropdown-account.purchases"]'),
|
compiled.querySelector('[data-testid="user-dropdown-account.purchases"]'),
|
||||||
).not.toBeNull();
|
).not.toBeNull();
|
||||||
expect(compiled.querySelector('[data-testid="user-dropdown-account.tickets"]')).toBeNull();
|
expect(compiled.querySelector('[data-testid="user-dropdown-account.tickets"]')).not.toBeNull();
|
||||||
expect(router.navigate).not.toHaveBeenCalled();
|
expect(router.navigate).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -783,7 +810,7 @@ describe('StoreLayoutComponent', () => {
|
|||||||
|
|
||||||
expect(profileLink?.getAttribute('href')).toBe('/mi-cuenta/datos-personales');
|
expect(profileLink?.getAttribute('href')).toBe('/mi-cuenta/datos-personales');
|
||||||
expect(purchasesLink?.getAttribute('href')).toBe('/mi-cuenta/compras');
|
expect(purchasesLink?.getAttribute('href')).toBe('/mi-cuenta/compras');
|
||||||
expect(ticketsLink).toBeUndefined();
|
expect(ticketsLink?.getAttribute('href')).toBe('/mi-cuenta/tickets');
|
||||||
expect(logoutButton).toBeDefined();
|
expect(logoutButton).toBeDefined();
|
||||||
|
|
||||||
logoutButton!.click();
|
logoutButton!.click();
|
||||||
|
|||||||
@@ -211,10 +211,12 @@ export class StoreLayoutComponent implements OnInit {
|
|||||||
|
|
||||||
const profile = accountMenu.submenues.find((menu) => menu.code === 'account.profile');
|
const profile = accountMenu.submenues.find((menu) => menu.code === 'account.profile');
|
||||||
const purchases = accountMenu.submenues.find((menu) => menu.code === 'account.purchases');
|
const purchases = accountMenu.submenues.find((menu) => menu.code === 'account.purchases');
|
||||||
|
const tickets = accountMenu.submenues.find((menu) => menu.code === 'account.tickets');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
...(profile ? [{ ...accountMenu, route: profile.route }] : []),
|
...(profile ? [{ ...accountMenu, route: profile.route }] : []),
|
||||||
...(purchases ? [purchases] : []),
|
...(purchases ? [purchases] : []),
|
||||||
|
...(tickets ? [tickets] : []),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,13 @@
|
|||||||
(click)="selectImage(idx)"
|
(click)="selectImage(idx)"
|
||||||
[attr.aria-label]="'Select image ' + (idx + 1)"
|
[attr.aria-label]="'Select image ' + (idx + 1)"
|
||||||
>
|
>
|
||||||
<img [src]="image" alt="Product thumbnail" class="w-100 h-100 object-fit-cover" />
|
<img
|
||||||
|
[src]="image"
|
||||||
|
alt="Product thumbnail"
|
||||||
|
loading="lazy"
|
||||||
|
decoding="async"
|
||||||
|
class="w-100 h-100 object-fit-cover"
|
||||||
|
/>
|
||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
@if (event(); as item) {
|
@if (event(); as item) {
|
||||||
<div class="event-detail row gx-sm-4 gx-lg-5">
|
<div class="event-detail">
|
||||||
<aside class="event-detail__sidebar col-12 col-sm-4">
|
<aside class="event-detail__sidebar">
|
||||||
<div class="event-detail__image" [class.event-detail__image--placeholder]="!item.image">
|
<div class="event-detail__image" [class.event-detail__image--placeholder]="!item.image">
|
||||||
@if (item.image) {
|
@if (item.image) {
|
||||||
<img [src]="item.image" [alt]="item.title" />
|
<img [src]="item.image" [alt]="item.title" />
|
||||||
@@ -12,37 +12,9 @@
|
|||||||
@if (item.starts_at) {
|
@if (item.starts_at) {
|
||||||
<app-counter-to [startsAt]="item.starts_at" />
|
<app-counter-to [startsAt]="item.starts_at" />
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (item.description) {
|
|
||||||
<section class="event-detail__description" aria-labelledby="event-description-title">
|
|
||||||
<h2 id="event-description-title">Descripción</h2>
|
|
||||||
<p>{{ item.description }}</p>
|
|
||||||
</section>
|
|
||||||
}
|
|
||||||
|
|
||||||
@if (item.social_media?.length) {
|
|
||||||
<section class="event-detail__social" aria-labelledby="event-social-title">
|
|
||||||
<h2 id="event-social-title">Información</h2>
|
|
||||||
@for (social of item.social_media; track social.code) {
|
|
||||||
<a [href]="social.url" target="_blank" rel="noopener noreferrer">
|
|
||||||
<i [class]="socialIcon(social.code)" aria-hidden="true"></i>
|
|
||||||
<span>{{ socialLabel(social.code) }}</span>
|
|
||||||
</a>
|
|
||||||
}
|
|
||||||
</section>
|
|
||||||
}
|
|
||||||
|
|
||||||
@if (mapLocations().length) {
|
|
||||||
<app-location-map
|
|
||||||
class="event-detail__map"
|
|
||||||
[locations]="mapLocations()"
|
|
||||||
ariaLabel="Ubicación del evento"
|
|
||||||
mapStyle="standard"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<main class="event-detail__main col-12 col-sm-8">
|
<main class="event-detail__main">
|
||||||
<header class="event-detail__header">
|
<header class="event-detail__header">
|
||||||
<h1>{{ item.title }}</h1>
|
<h1>{{ item.title }}</h1>
|
||||||
@if (item.subtitle) { <p class="event-detail__subtitle">{{ item.subtitle }}</p> }
|
@if (item.subtitle) { <p class="event-detail__subtitle">{{ item.subtitle }}</p> }
|
||||||
@@ -105,6 +77,36 @@
|
|||||||
}
|
}
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
<aside class="event-detail__details">
|
||||||
|
@if (item.description) {
|
||||||
|
<section class="event-detail__description" aria-labelledby="event-description-title">
|
||||||
|
<h2 id="event-description-title">Descripción</h2>
|
||||||
|
<p>{{ item.description }}</p>
|
||||||
|
</section>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (item.social_media?.length) {
|
||||||
|
<section class="event-detail__social" aria-labelledby="event-social-title">
|
||||||
|
<h2 id="event-social-title">Información</h2>
|
||||||
|
@for (social of item.social_media; track social.code) {
|
||||||
|
<a [href]="social.url" target="_blank" rel="noopener noreferrer">
|
||||||
|
<i [class]="socialIcon(social.code)" aria-hidden="true"></i>
|
||||||
|
<span>{{ socialLabel(social.code) }}</span>
|
||||||
|
</a>
|
||||||
|
}
|
||||||
|
</section>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (mapLocations().length) {
|
||||||
|
<app-location-map
|
||||||
|
class="event-detail__map"
|
||||||
|
[locations]="mapLocations()"
|
||||||
|
ariaLabel="Ubicación del evento"
|
||||||
|
mapStyle="standard"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</aside>
|
||||||
</div>
|
</div>
|
||||||
} @else if (!loading()) {
|
} @else if (!loading()) {
|
||||||
<p role="alert">No encontramos este evento.</p>
|
<p role="alert">No encontramos este evento.</p>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
:host { display: block; color: #666666; }
|
:host { display: block; color: #666666; }
|
||||||
.event-detail { margin-bottom: 3rem; }
|
.event-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); column-gap: 1.5rem; margin-bottom: 3rem; }
|
||||||
.event-detail__sidebar, .event-detail__main { min-width: 0; }
|
.event-detail__sidebar, .event-detail__main { min-width: 0; }
|
||||||
|
.event-detail__sidebar { grid-column: 1; grid-row: 1; }
|
||||||
|
.event-detail__main { grid-column: 2; grid-row: 1 / span 2; }
|
||||||
|
.event-detail__details { min-width: 0; grid-column: 1; grid-row: 2; }
|
||||||
.event-detail__image { background: #e7e8e9; }
|
.event-detail__image { background: #e7e8e9; }
|
||||||
.event-detail__image--placeholder { aspect-ratio: 1.43; display: grid; place-items: center; }
|
.event-detail__image--placeholder { aspect-ratio: 1.43; display: grid; place-items: center; }
|
||||||
.event-detail__image img { width: 100%; height: auto; display: block; }
|
.event-detail__image img { width: 100%; height: auto; display: block; }
|
||||||
@@ -34,10 +37,40 @@
|
|||||||
.event-detail__buttons { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.6rem; }
|
.event-detail__buttons { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.6rem; }
|
||||||
.event-detail__buttons app-button { min-width: 0; flex: 0 0 36%; }
|
.event-detail__buttons app-button { min-width: 0; flex: 0 0 36%; }
|
||||||
.event-detail__empty { color: #7c8286; font-size: .85rem; }
|
.event-detail__empty { color: #7c8286; font-size: .85rem; }
|
||||||
|
@media (min-width: 992px) {
|
||||||
|
.event-detail { column-gap: 3rem; }
|
||||||
|
}
|
||||||
@media (max-width: 575.98px) {
|
@media (max-width: 575.98px) {
|
||||||
|
.event-detail { grid-template-columns: minmax(0, 1fr); }
|
||||||
|
.event-detail__sidebar, .event-detail__main, .event-detail__details { grid-column: 1; grid-row: auto; }
|
||||||
.event-detail__main { margin-top: 2rem; }
|
.event-detail__main { margin-top: 2rem; }
|
||||||
|
.event-detail__date-select { width: 100%; }
|
||||||
.event-detail__description, .event-detail__social { margin-top: 1.5rem; }
|
.event-detail__description, .event-detail__social { margin-top: 1.5rem; }
|
||||||
.event-detail__header { min-height: 0; margin-bottom: 2rem; }
|
.event-detail__header { min-height: 0; margin-bottom: 2rem; }
|
||||||
.event-detail__buttons { flex-wrap: wrap; }
|
.event-detail__header h1 { font-size: 20px; }
|
||||||
.event-detail__buttons app-button { flex: 1 1 100%; }
|
.event-detail__product-list { gap: 42px; }
|
||||||
|
.event-detail__product {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) 96px 72px;
|
||||||
|
column-gap: 26px;
|
||||||
|
margin-inline: 0;
|
||||||
|
}
|
||||||
|
.event-detail__product > * { width: auto; margin-top: 0; padding-inline: 0; }
|
||||||
|
.event-detail__product h3 { align-self: center; font-size: 13px; }
|
||||||
|
.event-detail__product-action { margin-left: 0 !important; }
|
||||||
|
.event-detail__product-action app-quantity-selector {
|
||||||
|
--quantity-selector-width: 96px;
|
||||||
|
--quantity-selector-height: 32px;
|
||||||
|
--quantity-selector-button-width: 28px;
|
||||||
|
--quantity-selector-button-font-size: 14px;
|
||||||
|
--quantity-selector-value-font-size: 14px;
|
||||||
|
}
|
||||||
|
.event-detail__price { align-self: center; font-size: 14px; }
|
||||||
|
.event-detail__total { margin-top: 44px; padding-top: 25px; font-size: 13px; }
|
||||||
|
.event-detail__total strong { font-size: 20px; }
|
||||||
|
.event-detail__buttons { gap: 10px; margin-top: 44px; }
|
||||||
|
.event-detail__buttons app-button {
|
||||||
|
--app-button-min-height: 50px;
|
||||||
|
flex: 1 1 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,32 @@
|
|||||||
</p>
|
</p>
|
||||||
} @else {
|
} @else {
|
||||||
@for (group of catalog(); track group.id; let first = $first) {
|
@for (group of catalog(); track group.id; let first = $first) {
|
||||||
|
@if (first) {
|
||||||
|
<ng-container
|
||||||
|
[ngTemplateOutlet]="catalogGroup"
|
||||||
|
[ngTemplateOutletContext]="{ $implicit: group, prioritizeFirstImage: true }"
|
||||||
|
/>
|
||||||
|
} @else {
|
||||||
|
@defer (on viewport; prefetch on idle) {
|
||||||
|
<ng-container
|
||||||
|
[ngTemplateOutlet]="catalogGroup"
|
||||||
|
[ngTemplateOutletContext]="{ $implicit: group, prioritizeFirstImage: false }"
|
||||||
|
/>
|
||||||
|
} @placeholder {
|
||||||
|
<section
|
||||||
|
class="store-home__deferred-group-placeholder"
|
||||||
|
[attr.aria-label]="group.title"
|
||||||
|
></section>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
<ng-template
|
||||||
|
#catalogGroup
|
||||||
|
let-group
|
||||||
|
let-prioritizeFirstImage="prioritizeFirstImage"
|
||||||
|
>
|
||||||
<app-store-section [attr.id]="group.code" [title]="group.title">
|
<app-store-section [attr.id]="group.code" [title]="group.title">
|
||||||
<app-product-list
|
<app-product-list
|
||||||
[layout]="group.layout"
|
[layout]="group.layout"
|
||||||
@@ -30,7 +56,7 @@
|
|||||||
[items]="group.items"
|
[items]="group.items"
|
||||||
[loading]="isGroupLoading(group.id)"
|
[loading]="isGroupLoading(group.id)"
|
||||||
[loadImages]="!hasMainCarouselImages() || mainCarouselReady()"
|
[loadImages]="!hasMainCarouselImages() || mainCarouselReady()"
|
||||||
[prioritizeFirstImage]="first && !hasMainCarouselImages()"
|
[prioritizeFirstImage]="prioritizeFirstImage && !hasMainCarouselImages()"
|
||||||
[unavailableVariantIds]="unavailableVariantIds()"
|
[unavailableVariantIds]="unavailableVariantIds()"
|
||||||
[savingProductIds]="savingProductIds()"
|
[savingProductIds]="savingProductIds()"
|
||||||
(buy)="onBuyProduct($event)"
|
(buy)="onBuyProduct($event)"
|
||||||
@@ -38,8 +64,7 @@
|
|||||||
(pageChange)="onPageChange(group.id, $event)"
|
(pageChange)="onPageChange(group.id, $event)"
|
||||||
/>
|
/>
|
||||||
</app-store-section>
|
</app-store-section>
|
||||||
}
|
</ng-template>
|
||||||
}
|
|
||||||
|
|
||||||
@if (additionalInfo(); as content) {
|
@if (additionalInfo(); as content) {
|
||||||
<app-store-section class="store-home__additional-info" title="Información adicional">
|
<app-store-section class="store-home__additional-info" title="Información adicional">
|
||||||
|
|||||||
@@ -15,6 +15,13 @@ app-store-section[id] {
|
|||||||
scroll-margin-top: 8rem;
|
scroll-margin-top: 8rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.store-home__deferred-group-placeholder {
|
||||||
|
display: block;
|
||||||
|
min-height: clamp(24rem, 42vw, 34rem);
|
||||||
|
content-visibility: auto;
|
||||||
|
contain-intrinsic-size: auto 30rem;
|
||||||
|
}
|
||||||
|
|
||||||
:host > .store-home__additional-info:not(:first-child) {
|
:host > .store-home__additional-info:not(:first-child) {
|
||||||
margin-top: clamp(3rem, 6vw, 5rem);
|
margin-top: clamp(3rem, 6vw, 5rem);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
inject,
|
inject,
|
||||||
signal,
|
signal,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
import { NgTemplateOutlet } from '@angular/common';
|
||||||
import { HttpErrorResponse } from '@angular/common/http';
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { finalize, Subscription } from 'rxjs';
|
import { finalize, Subscription } from 'rxjs';
|
||||||
@@ -44,6 +45,7 @@ import {
|
|||||||
ProductListComponent,
|
ProductListComponent,
|
||||||
HeroBannerComponent,
|
HeroBannerComponent,
|
||||||
MainCarouselComponent,
|
MainCarouselComponent,
|
||||||
|
NgTemplateOutlet,
|
||||||
],
|
],
|
||||||
templateUrl: './store-home-page.component.html',
|
templateUrl: './store-home-page.component.html',
|
||||||
styleUrl: './store-home-page.component.scss',
|
styleUrl: './store-home-page.component.scss',
|
||||||
|
|||||||
@@ -4,12 +4,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.btn {
|
.btn {
|
||||||
min-height: 40px;
|
min-height: var(--app-button-min-height, 40px);
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: 767.98px) {
|
||||||
|
.btn {
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.btn-primary,
|
.btn-primary,
|
||||||
.btn-secondary,
|
.btn-secondary,
|
||||||
.btn-danger {
|
.btn-danger {
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
<section class="carousel" role="region" [attr.aria-label]="ariaLabel()">
|
<section class="carousel" role="region" [attr.aria-label]="ariaLabel()">
|
||||||
|
<span
|
||||||
|
#sizeProbe
|
||||||
|
class="carousel__size-probe"
|
||||||
|
aria-hidden="true"
|
||||||
|
[style.width]="itemBasis()"
|
||||||
|
></span>
|
||||||
<div class="carousel__frame" [class.carousel__frame--with-controls]="hasMultipleItems()">
|
<div class="carousel__frame" [class.carousel__frame--with-controls]="hasMultipleItems()">
|
||||||
<div
|
<div
|
||||||
#viewport
|
#viewport
|
||||||
|
|||||||
@@ -4,8 +4,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.carousel {
|
.carousel {
|
||||||
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
|
&__size-probe {
|
||||||
|
position: absolute;
|
||||||
|
height: 0;
|
||||||
|
visibility: hidden;
|
||||||
|
pointer-events: none;
|
||||||
|
contain: strict;
|
||||||
|
}
|
||||||
|
|
||||||
&__frame {
|
&__frame {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: grid;
|
display: grid;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Component, signal, TemplateRef, viewChild } from '@angular/core';
|
import { Component, signal, TemplateRef, viewChild } from '@angular/core';
|
||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
import { CarouselComponent, CarouselItemContext } from './carousel.component';
|
import { CarouselComponent, CarouselItemContext } from './carousel.component';
|
||||||
|
|
||||||
interface TestItem {
|
interface TestItem {
|
||||||
@@ -16,7 +16,7 @@ interface TestItem {
|
|||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
<app-carousel
|
<app-carousel
|
||||||
[items]="items"
|
[items]="items()"
|
||||||
[itemTemplate]="itemTemplate"
|
[itemTemplate]="itemTemplate"
|
||||||
[scrollStep]="120"
|
[scrollStep]="120"
|
||||||
[gap]="16"
|
[gap]="16"
|
||||||
@@ -28,11 +28,11 @@ interface TestItem {
|
|||||||
class TestHostComponent {
|
class TestHostComponent {
|
||||||
readonly circular = signal(false);
|
readonly circular = signal(false);
|
||||||
|
|
||||||
readonly items: TestItem[] = [
|
readonly items = signal<TestItem[]>([
|
||||||
{ id: 1, label: 'Primero' },
|
{ id: 1, label: 'Primero' },
|
||||||
{ id: 2, label: 'Segundo' },
|
{ id: 2, label: 'Segundo' },
|
||||||
{ id: 3, label: 'Tercero' },
|
{ id: 3, label: 'Tercero' },
|
||||||
];
|
]);
|
||||||
|
|
||||||
readonly carousel = viewChild.required(CarouselComponent<TestItem>);
|
readonly carousel = viewChild.required(CarouselComponent<TestItem>);
|
||||||
readonly itemTemplate =
|
readonly itemTemplate =
|
||||||
@@ -41,8 +41,47 @@ class TestHostComponent {
|
|||||||
|
|
||||||
describe('CarouselComponent', () => {
|
describe('CarouselComponent', () => {
|
||||||
let fixture: ComponentFixture<TestHostComponent>;
|
let fixture: ComponentFixture<TestHostComponent>;
|
||||||
|
let frames: Map<number, FrameRequestCallback>;
|
||||||
|
let resize: () => void;
|
||||||
|
let disconnect: ReturnType<typeof vi.fn>;
|
||||||
|
const flushLayout = () => {
|
||||||
|
const pending = [...frames.values()];
|
||||||
|
frames.clear();
|
||||||
|
pending.forEach((callback) => callback(0));
|
||||||
|
fixture.detectChanges();
|
||||||
|
};
|
||||||
|
const setDimensions = (width: number, basis: number) => {
|
||||||
|
const host = fixture.nativeElement.querySelector('app-carousel');
|
||||||
|
Object.defineProperty(host, 'clientWidth', { configurable: true, value: width });
|
||||||
|
const probe = fixture.nativeElement.querySelector('.carousel__size-probe');
|
||||||
|
probe.getBoundingClientRect = () => ({ width: basis }) as DOMRect;
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
frames = new Map();
|
||||||
|
let frameId = 0;
|
||||||
|
vi.stubGlobal(
|
||||||
|
'requestAnimationFrame',
|
||||||
|
vi.fn((callback: FrameRequestCallback) => {
|
||||||
|
frames.set(++frameId, callback);
|
||||||
|
return frameId;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
vi.stubGlobal(
|
||||||
|
'cancelAnimationFrame',
|
||||||
|
vi.fn((id: number) => frames.delete(id)),
|
||||||
|
);
|
||||||
|
disconnect = vi.fn();
|
||||||
|
vi.stubGlobal(
|
||||||
|
'ResizeObserver',
|
||||||
|
class {
|
||||||
|
constructor(callback: () => void) {
|
||||||
|
resize = callback;
|
||||||
|
}
|
||||||
|
observe() {}
|
||||||
|
disconnect = disconnect;
|
||||||
|
},
|
||||||
|
);
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
imports: [TestHostComponent],
|
imports: [TestHostComponent],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
@@ -51,6 +90,75 @@ describe('CarouselComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
fixture.destroy();
|
||||||
|
vi.unstubAllGlobals();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('agrupa las mediciones y no se realimenta al renderizar o navegar', async () => {
|
||||||
|
fixture.componentInstance.circular.set(true);
|
||||||
|
setDimensions(650, 200);
|
||||||
|
fixture.detectChanges();
|
||||||
|
resize();
|
||||||
|
resize();
|
||||||
|
expect(frames.size).toBe(1);
|
||||||
|
flushLayout();
|
||||||
|
await Promise.resolve();
|
||||||
|
expect(frames.size).toBe(0);
|
||||||
|
const carousel = fixture.componentInstance.carousel();
|
||||||
|
expect(carousel['itemsPerPage']()).toBe(2);
|
||||||
|
carousel.next();
|
||||||
|
fixture.detectChanges();
|
||||||
|
const track = fixture.nativeElement.querySelector('.carousel__track');
|
||||||
|
track.dispatchEvent(new TransitionEvent('transitionend', { propertyName: 'transform' }));
|
||||||
|
fixture.detectChanges();
|
||||||
|
await Promise.resolve();
|
||||||
|
resize(); // Same width, even if the new cards have a different height.
|
||||||
|
expect(frames.size).toBe(0);
|
||||||
|
expect(carousel['currentPage']()).toBe(1);
|
||||||
|
expect(carousel['itemWidth']()).toBe(269);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('recalcula al cambiar el ancho y la base responsive de las tarjetas', () => {
|
||||||
|
setDimensions(650, 200);
|
||||||
|
resize();
|
||||||
|
flushLayout();
|
||||||
|
setDimensions(350, 200);
|
||||||
|
resize();
|
||||||
|
flushLayout();
|
||||||
|
expect(fixture.componentInstance.carousel()['itemsPerPage']()).toBe(1);
|
||||||
|
setDimensions(350, 100);
|
||||||
|
resize();
|
||||||
|
flushLayout();
|
||||||
|
expect(fixture.componentInstance.carousel()['itemsPerPage']()).toBe(2);
|
||||||
|
expect(frames.size).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('actualiza productos y admite una lista vacía sin anchos inválidos', () => {
|
||||||
|
setDimensions(650, 200);
|
||||||
|
flushLayout();
|
||||||
|
fixture.componentInstance.items.set([]);
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(frames.size).toBe(1);
|
||||||
|
flushLayout();
|
||||||
|
const carousel = fixture.componentInstance.carousel();
|
||||||
|
expect(carousel['itemWidth']()).toBeNull();
|
||||||
|
expect(carousel['hasOverflow']()).toBe(false);
|
||||||
|
fixture.componentInstance.items.set([{ id: 4, label: 'Nuevo' }]);
|
||||||
|
fixture.detectChanges();
|
||||||
|
flushLayout();
|
||||||
|
expect(carousel['itemWidth']()).toBe(650);
|
||||||
|
expect(fixture.nativeElement.querySelectorAll('article')).toHaveLength(1);
|
||||||
|
expect(frames.size).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('cancela mediciones pendientes y desconecta el observador al destruirse', () => {
|
||||||
|
expect(frames.size).toBe(1);
|
||||||
|
fixture.destroy();
|
||||||
|
expect(frames.size).toBe(0);
|
||||||
|
expect(disconnect).toHaveBeenCalledOnce();
|
||||||
|
});
|
||||||
|
|
||||||
it('renderiza el template provisto para cada elemento', () => {
|
it('renderiza el template provisto para cada elemento', () => {
|
||||||
const articles = fixture.nativeElement.querySelectorAll('article');
|
const articles = fixture.nativeElement.querySelectorAll('article');
|
||||||
|
|
||||||
@@ -59,6 +167,17 @@ describe('CarouselComponent', () => {
|
|||||||
expect(articles[1].getAttribute('data-index')).toBe('1');
|
expect(articles[1].getAttribute('data-index')).toBe('1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('permite inspeccionar las páginas antes de medir el viewport sin generar listas enormes', () => {
|
||||||
|
const carousel = fixture.componentInstance.carousel();
|
||||||
|
fixture.componentInstance.circular.set(true);
|
||||||
|
carousel['itemsPerPage'].set(Number.MAX_SAFE_INTEGER);
|
||||||
|
|
||||||
|
expect(carousel['circularPages']()).toEqual([]);
|
||||||
|
expect(carousel['createPage']('current', 0).items.map((entry) => entry.item.id)).toEqual([
|
||||||
|
1, 2, 3,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it('expone una región accesible y controles con etiquetas', () => {
|
it('expone una región accesible y controles con etiquetas', () => {
|
||||||
const region = fixture.nativeElement.querySelector('[role="region"]');
|
const region = fixture.nativeElement.querySelector('[role="region"]');
|
||||||
const buttons = fixture.nativeElement.querySelectorAll('button');
|
const buttons = fixture.nativeElement.querySelectorAll('button');
|
||||||
@@ -99,7 +218,7 @@ describe('CarouselComponent', () => {
|
|||||||
|
|
||||||
it('usa todo el ancho y distribuye el espacio sobrante entre elementos completos', () => {
|
it('usa todo el ancho y distribuye el espacio sobrante entre elementos completos', () => {
|
||||||
const host = fixture.nativeElement.querySelector('app-carousel') as HTMLElement;
|
const host = fixture.nativeElement.querySelector('app-carousel') as HTMLElement;
|
||||||
const firstItem = fixture.nativeElement.querySelector('.carousel__item') as HTMLElement;
|
const firstItem = fixture.nativeElement.querySelector('.carousel__size-probe') as HTMLElement;
|
||||||
|
|
||||||
Object.defineProperty(host, 'clientWidth', {
|
Object.defineProperty(host, 'clientWidth', {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
@@ -112,7 +231,7 @@ describe('CarouselComponent', () => {
|
|||||||
}) as DOMRect,
|
}) as DOMRect,
|
||||||
);
|
);
|
||||||
|
|
||||||
fixture.componentInstance.carousel().ngAfterViewInit();
|
flushLayout();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const frame = fixture.nativeElement.querySelector('.carousel__frame') as HTMLElement;
|
const frame = fixture.nativeElement.querySelector('.carousel__frame') as HTMLElement;
|
||||||
@@ -128,7 +247,7 @@ describe('CarouselComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const host = fixture.nativeElement.querySelector('app-carousel') as HTMLElement;
|
const host = fixture.nativeElement.querySelector('app-carousel') as HTMLElement;
|
||||||
const firstItem = fixture.nativeElement.querySelector('.carousel__item') as HTMLElement;
|
const firstItem = fixture.nativeElement.querySelector('.carousel__size-probe') as HTMLElement;
|
||||||
|
|
||||||
Object.defineProperty(host, 'clientWidth', {
|
Object.defineProperty(host, 'clientWidth', {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
@@ -141,7 +260,7 @@ describe('CarouselComponent', () => {
|
|||||||
}) as DOMRect,
|
}) as DOMRect,
|
||||||
);
|
);
|
||||||
|
|
||||||
fixture.componentInstance.carousel().ngAfterViewInit();
|
flushLayout();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const pages = fixture.nativeElement.querySelectorAll('.carousel__page');
|
const pages = fixture.nativeElement.querySelectorAll('.carousel__page');
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
AfterViewInit,
|
AfterViewInit,
|
||||||
|
afterRenderEffect,
|
||||||
ChangeDetectionStrategy,
|
ChangeDetectionStrategy,
|
||||||
Component,
|
Component,
|
||||||
DestroyRef,
|
DestroyRef,
|
||||||
@@ -10,6 +11,7 @@ import {
|
|||||||
inject,
|
inject,
|
||||||
input,
|
input,
|
||||||
signal,
|
signal,
|
||||||
|
untracked,
|
||||||
viewChild,
|
viewChild,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { isPlatformBrowser, NgTemplateOutlet } from '@angular/common';
|
import { isPlatformBrowser, NgTemplateOutlet } from '@angular/common';
|
||||||
@@ -45,12 +47,15 @@ export class CarouselComponent<T> implements AfterViewInit {
|
|||||||
private readonly platformId = inject(PLATFORM_ID);
|
private readonly platformId = inject(PLATFORM_ID);
|
||||||
private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);
|
private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);
|
||||||
private readonly viewport = viewChild.required<ElementRef<HTMLElement>>('viewport');
|
private readonly viewport = viewChild.required<ElementRef<HTMLElement>>('viewport');
|
||||||
|
private readonly sizeProbe = viewChild.required<ElementRef<HTMLElement>>('sizeProbe');
|
||||||
|
private layoutFrame: number | null = null;
|
||||||
|
|
||||||
readonly items = input.required<readonly T[]>();
|
readonly items = input.required<readonly T[]>();
|
||||||
readonly itemTemplate = input.required<TemplateRef<CarouselItemContext<T>>>();
|
readonly itemTemplate = input.required<TemplateRef<CarouselItemContext<T>>>();
|
||||||
readonly trackBy = input<CarouselTrackBy<T>>((index) => index);
|
readonly trackBy = input<CarouselTrackBy<T>>((index) => index);
|
||||||
readonly scrollStep = input<number | null>(null);
|
readonly scrollStep = input<number | null>(null);
|
||||||
readonly gap = input(0);
|
readonly gap = input(0);
|
||||||
|
readonly itemBasis = input('16rem');
|
||||||
readonly circular = input(false);
|
readonly circular = input(false);
|
||||||
readonly ariaLabel = input('Carrusel');
|
readonly ariaLabel = input('Carrusel');
|
||||||
readonly previousLabel = input('Mostrar elementos anteriores');
|
readonly previousLabel = input('Mostrar elementos anteriores');
|
||||||
@@ -70,6 +75,10 @@ export class CarouselComponent<T> implements AfterViewInit {
|
|||||||
);
|
);
|
||||||
protected readonly isCircularLayout = computed(() => this.circular() && this.pageCount() > 1);
|
protected readonly isCircularLayout = computed(() => this.circular() && this.pageCount() > 1);
|
||||||
protected readonly circularPages = computed<CarouselPage<T>[]>(() => {
|
protected readonly circularPages = computed<CarouselPage<T>[]>(() => {
|
||||||
|
if (!this.isCircularLayout()) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const pageCount = this.pageCount();
|
const pageCount = this.pageCount();
|
||||||
const currentPage = this.normalizePage(this.currentPage(), pageCount);
|
const currentPage = this.normalizePage(this.currentPage(), pageCount);
|
||||||
|
|
||||||
@@ -86,27 +95,51 @@ export class CarouselComponent<T> implements AfterViewInit {
|
|||||||
() => !this.hasOverflow() || (!this.circular() && !this.canScrollNext()),
|
() => !this.hasOverflow() || (!this.circular() && !this.canScrollNext()),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
afterRenderEffect(() => {
|
||||||
|
this.items();
|
||||||
|
this.gap();
|
||||||
|
this.circular();
|
||||||
|
this.itemBasis();
|
||||||
|
this.itemTemplate();
|
||||||
|
// Layout outputs must never become dependencies of this effect.
|
||||||
|
untracked(() => this.scheduleLayout());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private scheduleLayout(): void {
|
||||||
|
if (this.destroyRef.destroyed || this.layoutFrame !== null) return;
|
||||||
|
this.layoutFrame = requestAnimationFrame(() => {
|
||||||
|
this.layoutFrame = null;
|
||||||
|
this.refreshLayout();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ngAfterViewInit(): void {
|
ngAfterViewInit(): void {
|
||||||
if (!isPlatformBrowser(this.platformId)) {
|
if (!isPlatformBrowser(this.platformId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const viewport = this.viewport().nativeElement;
|
let previousWidth = -1;
|
||||||
this.refreshLayout();
|
let previousBasis = -1;
|
||||||
|
|
||||||
const resizeObserver =
|
const resizeObserver =
|
||||||
typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(() => this.refreshLayout());
|
typeof ResizeObserver === 'undefined'
|
||||||
resizeObserver?.observe(this.host.nativeElement);
|
|
||||||
|
|
||||||
const mutationObserver =
|
|
||||||
typeof MutationObserver === 'undefined'
|
|
||||||
? null
|
? null
|
||||||
: new MutationObserver(() => this.refreshLayout());
|
: new ResizeObserver(() => {
|
||||||
mutationObserver?.observe(viewport, { childList: true, subtree: true });
|
const width = this.host.nativeElement.clientWidth;
|
||||||
|
const basis = this.sizeProbe().nativeElement.getBoundingClientRect().width;
|
||||||
|
// Image loads and page rotation can change height, but not the layout inputs.
|
||||||
|
if (width === previousWidth && basis === previousBasis) return;
|
||||||
|
previousWidth = width;
|
||||||
|
previousBasis = basis;
|
||||||
|
this.scheduleLayout();
|
||||||
|
});
|
||||||
|
resizeObserver?.observe(this.host.nativeElement);
|
||||||
|
resizeObserver?.observe(this.sizeProbe().nativeElement);
|
||||||
|
|
||||||
this.destroyRef.onDestroy(() => {
|
this.destroyRef.onDestroy(() => {
|
||||||
resizeObserver?.disconnect();
|
resizeObserver?.disconnect();
|
||||||
mutationObserver?.disconnect();
|
if (this.layoutFrame !== null) cancelAnimationFrame(this.layoutFrame);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,24 +251,32 @@ export class CarouselComponent<T> implements AfterViewInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private refreshLayout(): void {
|
private refreshLayout(): void {
|
||||||
const viewport = this.viewport().nativeElement;
|
const itemCount = this.items().length;
|
||||||
const firstItem = viewport.querySelector<HTMLElement>('.carousel__item');
|
|
||||||
const availableWidth = this.host.nativeElement.clientWidth;
|
const availableWidth = this.host.nativeElement.clientWidth;
|
||||||
const availableViewportWidth = Math.max(
|
const availableViewportWidth = Math.max(
|
||||||
availableWidth - (this.hasMultipleItems() ? CarouselComponent.CONTROL_SLOT_WIDTH * 2 : 0),
|
availableWidth - (this.hasMultipleItems() ? CarouselComponent.CONTROL_SLOT_WIDTH * 2 : 0),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!firstItem || availableViewportWidth <= 0) {
|
if (itemCount === 0) {
|
||||||
|
this.itemsPerPage.set(1);
|
||||||
|
this.currentPage.set(0);
|
||||||
|
this.transitionDirection.set(0);
|
||||||
|
this.itemWidth.set(null);
|
||||||
|
this.hasOverflow.set(false);
|
||||||
|
this.canScrollPrevious.set(false);
|
||||||
|
this.canScrollNext.set(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (availableViewportWidth <= 0) {
|
||||||
this.itemWidth.set(null);
|
this.itemWidth.set(null);
|
||||||
this.refreshNavigation();
|
this.refreshNavigation();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const assignedWidth = firstItem.style.width;
|
// Measure a stable CSS basis, never a card whose content/width we just changed.
|
||||||
firstItem.style.width = '';
|
const naturalItemWidth = this.sizeProbe().nativeElement.getBoundingClientRect().width;
|
||||||
const naturalItemWidth = firstItem.getBoundingClientRect().width;
|
|
||||||
firstItem.style.width = assignedWidth;
|
|
||||||
|
|
||||||
if (naturalItemWidth <= 0) {
|
if (naturalItemWidth <= 0) {
|
||||||
this.itemWidth.set(null);
|
this.itemWidth.set(null);
|
||||||
@@ -244,9 +285,9 @@ export class CarouselComponent<T> implements AfterViewInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const gap = this.resolvedGap();
|
const gap = this.resolvedGap();
|
||||||
const fittingItems = Math.max(
|
const fittingItems = Math.min(
|
||||||
1,
|
itemCount,
|
||||||
Math.floor((availableViewportWidth + gap) / (naturalItemWidth + gap)),
|
Math.max(1, Math.floor((availableViewportWidth + gap) / (naturalItemWidth + gap))),
|
||||||
);
|
);
|
||||||
const visibleItems = Math.min(fittingItems, this.items().length);
|
const visibleItems = Math.min(fittingItems, this.items().length);
|
||||||
const distributedItemWidth =
|
const distributedItemWidth =
|
||||||
@@ -258,7 +299,12 @@ export class CarouselComponent<T> implements AfterViewInit {
|
|||||||
this.transitionDirection.set(0);
|
this.transitionDirection.set(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.itemWidth.set(distributedItemWidth);
|
if (this.itemWidth() !== distributedItemWidth) this.itemWidth.set(distributedItemWidth);
|
||||||
|
const normalizedPage = this.normalizePage(this.currentPage(), this.pageCount());
|
||||||
|
if (normalizedPage !== this.currentPage()) {
|
||||||
|
this.currentPage.set(normalizedPage);
|
||||||
|
this.transitionDirection.set(0);
|
||||||
|
}
|
||||||
if (this.circular()) {
|
if (this.circular()) {
|
||||||
const hasOverflow = this.items().length > fittingItems;
|
const hasOverflow = this.items().length > fittingItems;
|
||||||
this.hasOverflow.set(hasOverflow);
|
this.hasOverflow.set(hasOverflow);
|
||||||
@@ -270,14 +316,20 @@ export class CarouselComponent<T> implements AfterViewInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private createPage(slot: CarouselPage<T>['slot'], page: number): CarouselPage<T> {
|
private createPage(slot: CarouselPage<T>['slot'], page: number): CarouselPage<T> {
|
||||||
|
const sourceItems = this.items();
|
||||||
|
// Layout has not necessarily been measured when a computed value is inspected.
|
||||||
|
const pageSize = Math.min(this.itemsPerPage(), sourceItems.length);
|
||||||
|
if (pageSize === 0) {
|
||||||
|
return { slot, items: [] };
|
||||||
|
}
|
||||||
const pageCount = this.pageCount();
|
const pageCount = this.pageCount();
|
||||||
const normalizedPage = this.normalizePage(page, pageCount);
|
const normalizedPage = this.normalizePage(page, pageCount);
|
||||||
const start = normalizedPage * this.itemsPerPage();
|
const start = normalizedPage * pageSize;
|
||||||
const items: CarouselPageItem<T>[] = [];
|
const items: CarouselPageItem<T>[] = [];
|
||||||
|
|
||||||
for (let offset = 0; offset < this.itemsPerPage(); offset += 1) {
|
for (let offset = 0; offset < pageSize; offset += 1) {
|
||||||
const index = (start + offset) % this.items().length;
|
const index = (start + offset) % sourceItems.length;
|
||||||
items.push({ item: this.items()[index], index });
|
items.push({ item: sourceItems[index], index });
|
||||||
}
|
}
|
||||||
|
|
||||||
return { slot, items };
|
return { slot, items };
|
||||||
|
|||||||
@@ -14,20 +14,21 @@
|
|||||||
.continuous-carousel__track {
|
.continuous-carousel__track {
|
||||||
display: flex;
|
display: flex;
|
||||||
width: max-content;
|
width: max-content;
|
||||||
|
margin-left: var(--carousel-offset, 0px);
|
||||||
animation: continuous-carousel-scroll var(--duration) linear infinite;
|
animation: continuous-carousel-scroll var(--duration) linear infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
.continuous-carousel__set {
|
.continuous-carousel__set {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex: none;
|
flex: none;
|
||||||
gap: var(--gap);
|
gap: var(--carousel-gap, var(--gap));
|
||||||
padding-right: var(--gap);
|
padding-right: var(--carousel-gap, var(--gap));
|
||||||
}
|
}
|
||||||
|
|
||||||
.continuous-carousel__image {
|
.continuous-carousel__image {
|
||||||
display: block;
|
display: block;
|
||||||
flex: none;
|
flex: none;
|
||||||
width: var(--card-width);
|
width: var(--carousel-card-width, var(--card-width));
|
||||||
aspect-ratio: 1.45;
|
aspect-ratio: 1.45;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
@@ -64,6 +65,7 @@
|
|||||||
}
|
}
|
||||||
.continuous-carousel__track {
|
.continuous-carousel__track {
|
||||||
animation: none;
|
animation: none;
|
||||||
|
margin-left: 0;
|
||||||
}
|
}
|
||||||
.continuous-carousel__set[aria-hidden='true'] {
|
.continuous-carousel__set[aria-hidden='true'] {
|
||||||
display: none;
|
display: none;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
:host { display: block; margin-top: 9px; }
|
:host { display: block; margin-top: 9px; }
|
||||||
.counter-to { min-height: 30px; padding-block: 12px; display: grid; grid-template-columns: repeat(4, 1fr); align-items: center; text-align: center; border: 1px solid #d7d9db; border-radius: 3px; }
|
.counter-to { min-height: 30px; padding-block: 12px; display: grid; grid-template-columns: repeat(4, 1fr); align-items: center; text-align: center; border: 1px solid #a0a0a0; border-radius: 3px; }
|
||||||
.counter-to > div + div { border-left: 1px solid #e6e7e8; }
|
.counter-to > div + div { border-left: 1px solid #e6e7e8; }
|
||||||
.counter-to strong { display: block; color: #666666; font-size: 16px; font-weight: 700; line-height: 1.1; }
|
.counter-to strong { display: block; color: #666666; font-size: 16px; font-weight: 700; line-height: 1.1; }
|
||||||
.counter-to small { display: block; margin-top: 1px; color: #666666; font-size: 11px; font-weight: 400; letter-spacing: .02em; }
|
.counter-to small { display: block; margin-top: 1px; color: #666666; font-size: 11px; font-weight: 400; letter-spacing: .02em; }
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
<div
|
||||||
|
class="carousel"
|
||||||
|
role="group"
|
||||||
|
[attr.aria-label]="ariaLabel()"
|
||||||
|
[class.carousel--looping]="looping()"
|
||||||
|
>
|
||||||
|
@if (showArrows()) {
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="carousel__arrow"
|
||||||
|
aria-label="Ver elementos anteriores"
|
||||||
|
[disabled]="!overflowing()"
|
||||||
|
(click)="move(-1)"
|
||||||
|
>
|
||||||
|
<i class="fa-solid fa-chevron-left" aria-hidden="true"></i>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
<div #viewport class="carousel__viewport" (scroll)="onScroll()" (scrollend)="normalize()">
|
||||||
|
<div class="carousel__track">
|
||||||
|
@for (block of blocks(); track block) {
|
||||||
|
@if (block === 0) {
|
||||||
|
<div #canonical class="carousel__set">
|
||||||
|
@for (item of items(); track item.value) {
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="carousel__item"
|
||||||
|
(click)="itemSelect.emit(item)"
|
||||||
|
(focus)="reveal($event)"
|
||||||
|
>
|
||||||
|
{{ item.label }}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
} @else {
|
||||||
|
<div class="carousel__set" aria-hidden="true">
|
||||||
|
@for (item of items(); track item.value) {
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="carousel__item"
|
||||||
|
tabindex="-1"
|
||||||
|
(mousedown)="$event.preventDefault()"
|
||||||
|
(click)="selectCopy(item)"
|
||||||
|
>
|
||||||
|
{{ item.label }}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@if (showArrows()) {
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="carousel__arrow"
|
||||||
|
aria-label="Ver más elementos"
|
||||||
|
[disabled]="!overflowing()"
|
||||||
|
(click)="move(1)"
|
||||||
|
>
|
||||||
|
<i class="fa-solid fa-chevron-right" aria-hidden="true"></i>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
:host {
|
||||||
|
display: block;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.carousel {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.carousel__viewport {
|
||||||
|
container-type: inline-size;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
overflow-x: auto;
|
||||||
|
scrollbar-width: none;
|
||||||
|
overflow-anchor: none;
|
||||||
|
scroll-snap-type: var(--horizontal-carousel-snap, none);
|
||||||
|
}
|
||||||
|
.carousel__viewport::-webkit-scrollbar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.carousel__track {
|
||||||
|
display: flex;
|
||||||
|
width: max-content;
|
||||||
|
min-width: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.carousel__set {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex: none;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--horizontal-carousel-gap, 1.5rem);
|
||||||
|
}
|
||||||
|
.carousel--looping .carousel__set {
|
||||||
|
padding-right: var(--horizontal-carousel-gap, 1.5rem);
|
||||||
|
}
|
||||||
|
.carousel__item,
|
||||||
|
.carousel__arrow {
|
||||||
|
flex: none;
|
||||||
|
min-height: 44px;
|
||||||
|
border: 0;
|
||||||
|
padding: 0;
|
||||||
|
background: transparent;
|
||||||
|
color: inherit;
|
||||||
|
font: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.carousel__item {
|
||||||
|
width: var(--horizontal-carousel-item-width, auto);
|
||||||
|
white-space: var(--horizontal-carousel-white-space, nowrap);
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
scroll-snap-align: start;
|
||||||
|
text-transform: var(--horizontal-carousel-text-transform, none);
|
||||||
|
}
|
||||||
|
.carousel__arrow {
|
||||||
|
width: 32px;
|
||||||
|
font-size: 10px;
|
||||||
|
}
|
||||||
|
.carousel__arrow:disabled {
|
||||||
|
opacity: 0.35;
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
.carousel__item:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
.carousel__item:focus-visible,
|
||||||
|
.carousel__arrow:focus-visible {
|
||||||
|
outline: 2px solid currentColor;
|
||||||
|
outline-offset: -2px;
|
||||||
|
}
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
|
import { HorizontalCarouselComponent } from './horizontal-carousel.component';
|
||||||
|
|
||||||
|
describe('HorizontalCarouselComponent', () => {
|
||||||
|
let fixture: ComponentFixture<HorizontalCarouselComponent>;
|
||||||
|
let host: HTMLElement;
|
||||||
|
let available: number;
|
||||||
|
let resize: () => void;
|
||||||
|
const disconnect = vi.fn();
|
||||||
|
const items = Array.from({ length: 5 }, (_, index) => ({ value: index, label: `Item ${index}` }));
|
||||||
|
const viewport = () => host.querySelector<HTMLElement>('.carousel__viewport')!;
|
||||||
|
const period = () =>
|
||||||
|
host.querySelector<HTMLElement>('.carousel__set')!.getBoundingClientRect().width;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
available = 320;
|
||||||
|
vi.stubGlobal(
|
||||||
|
'ResizeObserver',
|
||||||
|
class {
|
||||||
|
constructor(callback: () => void) {
|
||||||
|
resize = callback;
|
||||||
|
}
|
||||||
|
observe() {}
|
||||||
|
disconnect = disconnect;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(function (
|
||||||
|
this: HTMLElement,
|
||||||
|
) {
|
||||||
|
return this.classList.contains('carousel__viewport') ? available - 64 : available;
|
||||||
|
});
|
||||||
|
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (
|
||||||
|
this: HTMLElement,
|
||||||
|
) {
|
||||||
|
const index = this.parentElement ? Array.from(this.parentElement.children).indexOf(this) : 0;
|
||||||
|
const left = this.classList.contains('carousel__item') ? index * 124.25 : 0;
|
||||||
|
const width = this.classList.contains('carousel__set')
|
||||||
|
? Math.max(
|
||||||
|
0,
|
||||||
|
this.children.length * 124.25 - (this.closest('.carousel--looping') ? 0 : 24.25),
|
||||||
|
)
|
||||||
|
: 100;
|
||||||
|
return {
|
||||||
|
left,
|
||||||
|
right: left + width,
|
||||||
|
width,
|
||||||
|
top: 0,
|
||||||
|
bottom: 44,
|
||||||
|
height: 44,
|
||||||
|
x: left,
|
||||||
|
y: 0,
|
||||||
|
toJSON() {},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
vi.stubGlobal(
|
||||||
|
'matchMedia',
|
||||||
|
vi.fn(() => ({ matches: true })),
|
||||||
|
);
|
||||||
|
// jsdom has no layout or scrolling implementation.
|
||||||
|
Object.defineProperty(HTMLElement.prototype, 'scrollTo', {
|
||||||
|
configurable: true,
|
||||||
|
value: vi.fn(function (this: HTMLElement, options: ScrollToOptions) {
|
||||||
|
this.scrollLeft = options.left ?? 0;
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
Object.defineProperty(HTMLElement.prototype, 'scrollBy', {
|
||||||
|
configurable: true,
|
||||||
|
value: vi.fn(function (this: HTMLElement, options: ScrollToOptions) {
|
||||||
|
this.scrollLeft += options.left ?? 0;
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
Object.defineProperty(HTMLElement.prototype, 'scrollIntoView', {
|
||||||
|
configurable: true,
|
||||||
|
value: vi.fn(),
|
||||||
|
});
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [HorizontalCarouselComponent],
|
||||||
|
}).compileComponents();
|
||||||
|
fixture = TestBed.createComponent(HorizontalCarouselComponent);
|
||||||
|
fixture.componentRef.setInput('items', items);
|
||||||
|
fixture.componentRef.setInput('ariaLabel', 'Opciones');
|
||||||
|
host = fixture.nativeElement;
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
fixture.destroy();
|
||||||
|
vi.restoreAllMocks();
|
||||||
|
vi.unstubAllGlobals();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('starts in the middle with only one accessible set', () => {
|
||||||
|
expect(host.querySelectorAll('.carousel__set')).toHaveLength(3);
|
||||||
|
expect(host.querySelectorAll('[aria-hidden="true"] .carousel__item')).toHaveLength(10);
|
||||||
|
expect(host.querySelectorAll('.carousel__item:not([tabindex="-1"])')).toHaveLength(5);
|
||||||
|
expect(viewport().scrollLeft).toBe(period());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('wraps both directions preserving the exact fractional offset', () => {
|
||||||
|
const width = period();
|
||||||
|
viewport().scrollLeft = width - 30.5;
|
||||||
|
viewport().dispatchEvent(new Event('scrollend'));
|
||||||
|
expect(viewport().scrollLeft).toBe(2 * width - 30.5);
|
||||||
|
viewport().scrollLeft = 2 * width + 42.5;
|
||||||
|
viewport().dispatchEvent(new Event('scrollend'));
|
||||||
|
expect(viewport().scrollLeft).toBe(width + 42.5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses the idle fallback after a gesture', () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
viewport().scrollLeft = 12;
|
||||||
|
viewport().dispatchEvent(new Event('scroll'));
|
||||||
|
vi.advanceTimersByTime(180);
|
||||||
|
expect(viewport().scrollLeft).toBe(period() + 12);
|
||||||
|
vi.useRealTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('arrows respect reduced motion', () => {
|
||||||
|
host.querySelectorAll<HTMLButtonElement>('.carousel__arrow')[1].click();
|
||||||
|
expect(viewport().scrollBy).toHaveBeenCalledWith({
|
||||||
|
left: (available - 64) * 0.8,
|
||||||
|
behavior: 'instant',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('selects the original value when clicking a copy', () => {
|
||||||
|
const selected = vi.fn();
|
||||||
|
fixture.componentInstance.itemSelect.subscribe(selected);
|
||||||
|
host.querySelector<HTMLButtonElement>('[aria-hidden="true"] .carousel__item')!.click();
|
||||||
|
expect(selected).toHaveBeenCalledWith(items[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('removes copies and arrows when resized to fit, then restores them', async () => {
|
||||||
|
available = 1000;
|
||||||
|
resize();
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
expect(host.querySelectorAll('.carousel__set')).toHaveLength(1);
|
||||||
|
expect(host.querySelectorAll('.carousel__arrow')).toHaveLength(0);
|
||||||
|
available = 320;
|
||||||
|
resize();
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
expect(host.querySelectorAll('.carousel__set')).toHaveLength(3);
|
||||||
|
expect(viewport().scrollLeft).toBe(period());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps arrows with three visible slots and advances one item', async () => {
|
||||||
|
host.style.setProperty('--horizontal-carousel-visible-items', '3');
|
||||||
|
resize();
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
host.querySelectorAll<HTMLElement>('.carousel__set').forEach((set) => {
|
||||||
|
set.style.columnGap = '8px';
|
||||||
|
});
|
||||||
|
host.querySelectorAll<HTMLButtonElement>('.carousel__arrow')[1].click();
|
||||||
|
expect(viewport().scrollBy).toHaveBeenCalledWith({ left: 108, behavior: 'instant' });
|
||||||
|
|
||||||
|
fixture.componentRef.setInput('items', items.slice(0, 3));
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
expect(host.querySelectorAll('.carousel__set')).toHaveLength(1);
|
||||||
|
expect(host.querySelectorAll('.carousel__arrow:disabled')).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('supports noncircular overflow and empty lists', async () => {
|
||||||
|
fixture.componentRef.setInput('circular', false);
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
expect(host.querySelectorAll('.carousel__set')).toHaveLength(1);
|
||||||
|
expect(host.querySelectorAll('.carousel__arrow')).toHaveLength(2);
|
||||||
|
fixture.componentRef.setInput('items', []);
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
expect(host.querySelectorAll('.carousel__arrow')).toHaveLength(0);
|
||||||
|
expect(host.querySelectorAll('.carousel__item')).toHaveLength(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
import {
|
||||||
|
afterNextRender,
|
||||||
|
afterRenderEffect,
|
||||||
|
ChangeDetectionStrategy,
|
||||||
|
Component,
|
||||||
|
computed,
|
||||||
|
DestroyRef,
|
||||||
|
ElementRef,
|
||||||
|
inject,
|
||||||
|
input,
|
||||||
|
output,
|
||||||
|
signal,
|
||||||
|
viewChild,
|
||||||
|
} from '@angular/core';
|
||||||
|
|
||||||
|
export interface HorizontalCarouselItem {
|
||||||
|
/** Unique within the carousel. */
|
||||||
|
value: string | number;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-horizontal-carousel',
|
||||||
|
templateUrl: './horizontal-carousel.component.html',
|
||||||
|
styleUrl: './horizontal-carousel.component.scss',
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
|
})
|
||||||
|
export class HorizontalCarouselComponent {
|
||||||
|
readonly items = input.required<readonly HorizontalCarouselItem[]>();
|
||||||
|
readonly circular = input(true);
|
||||||
|
readonly ariaLabel = input.required<string>();
|
||||||
|
readonly itemSelect = output<HorizontalCarouselItem>();
|
||||||
|
|
||||||
|
protected readonly overflowing = signal(false);
|
||||||
|
protected readonly visibleItems = signal<number | null>(null);
|
||||||
|
protected readonly showArrows = computed(
|
||||||
|
() => this.overflowing() || (this.visibleItems() !== null && this.items().length > 0),
|
||||||
|
);
|
||||||
|
protected readonly looping = computed(() => this.circular() && this.overflowing());
|
||||||
|
protected readonly blocks = computed(() => (this.looping() ? [-1, 0, 1] : [0]));
|
||||||
|
private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);
|
||||||
|
private readonly viewport = viewChild.required<ElementRef<HTMLElement>>('viewport');
|
||||||
|
private readonly canonical = viewChild.required<ElementRef<HTMLElement>>('canonical');
|
||||||
|
private readonly destroyRef = inject(DestroyRef);
|
||||||
|
private settleTimer?: ReturnType<typeof setTimeout>;
|
||||||
|
private observer?: ResizeObserver;
|
||||||
|
private initializedLoop = false;
|
||||||
|
private transferringFocus = false;
|
||||||
|
private lastItems?: readonly HorizontalCarouselItem[];
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
afterRenderEffect(() => {
|
||||||
|
const items = this.items();
|
||||||
|
const looping = this.looping();
|
||||||
|
const set = this.canonical().nativeElement;
|
||||||
|
this.measure();
|
||||||
|
if (this.lastItems !== items || this.initializedLoop !== looping) {
|
||||||
|
this.viewport().nativeElement.scrollLeft = looping ? set.getBoundingClientRect().width : 0;
|
||||||
|
this.lastItems = items;
|
||||||
|
this.initializedLoop = looping;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
afterNextRender(() => {
|
||||||
|
this.observer = new ResizeObserver(() => {
|
||||||
|
this.measure();
|
||||||
|
this.normalize();
|
||||||
|
});
|
||||||
|
this.observer.observe(this.host.nativeElement);
|
||||||
|
this.observer.observe(this.canonical().nativeElement);
|
||||||
|
});
|
||||||
|
this.destroyRef.onDestroy(() => {
|
||||||
|
this.observer?.disconnect();
|
||||||
|
clearTimeout(this.settleTimer);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private measure(): void {
|
||||||
|
const slots = Number(
|
||||||
|
this.host.nativeElement.ownerDocument.defaultView
|
||||||
|
?.getComputedStyle(this.host.nativeElement)
|
||||||
|
.getPropertyValue('--horizontal-carousel-visible-items'),
|
||||||
|
);
|
||||||
|
this.visibleItems.set(slots > 0 ? slots : null);
|
||||||
|
if (slots > 0) {
|
||||||
|
this.overflowing.set(this.items().length > slots);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const set = this.canonical().nativeElement;
|
||||||
|
const children = set.children;
|
||||||
|
const first = children.item(0) as HTMLElement | null;
|
||||||
|
const last = children.item(children.length - 1) as HTMLElement | null;
|
||||||
|
const width =
|
||||||
|
first && last ? last.getBoundingClientRect().right - first.getBoundingClientRect().left : 0;
|
||||||
|
const available = this.host.nativeElement.clientWidth;
|
||||||
|
this.overflowing.set(available > 0 && width > available + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected move(direction: number): void {
|
||||||
|
const viewport = this.viewport().nativeElement;
|
||||||
|
const set = this.canonical().nativeElement;
|
||||||
|
const first = set.children.item(0) as HTMLElement | null;
|
||||||
|
const gap =
|
||||||
|
parseFloat(viewport.ownerDocument.defaultView?.getComputedStyle(set).columnGap ?? '0') || 0;
|
||||||
|
const distance =
|
||||||
|
this.visibleItems() && first
|
||||||
|
? first.getBoundingClientRect().width + gap
|
||||||
|
: viewport.clientWidth * 0.8;
|
||||||
|
const reduceMotion = viewport.ownerDocument.defaultView?.matchMedia(
|
||||||
|
'(prefers-reduced-motion: reduce)',
|
||||||
|
).matches;
|
||||||
|
viewport.scrollBy({
|
||||||
|
left: direction * distance,
|
||||||
|
behavior: reduceMotion ? 'instant' : 'smooth',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onScroll(): void {
|
||||||
|
clearTimeout(this.settleTimer);
|
||||||
|
// Fallback for browsers without scrollend; momentum keeps resetting the timer.
|
||||||
|
this.settleTimer = setTimeout(() => this.normalize(), 180);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected normalize(): void {
|
||||||
|
clearTimeout(this.settleTimer);
|
||||||
|
if (!this.looping()) return;
|
||||||
|
const viewport = this.viewport().nativeElement;
|
||||||
|
const width = this.canonical().nativeElement.getBoundingClientRect().width;
|
||||||
|
if (!width) return;
|
||||||
|
const left = viewport.scrollLeft;
|
||||||
|
if (left < width || left >= 2 * width) {
|
||||||
|
viewport.scrollTo({ left: width + (((left % width) + width) % width), behavior: 'instant' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected reveal(event: FocusEvent): void {
|
||||||
|
// Only the canonical buttons participate in keyboard / screen-reader navigation.
|
||||||
|
if (this.transferringFocus) return;
|
||||||
|
(event.target as HTMLElement).scrollIntoView({
|
||||||
|
block: 'nearest',
|
||||||
|
inline: 'nearest',
|
||||||
|
behavior: 'instant',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected selectCopy(item: HorizontalCarouselItem): void {
|
||||||
|
const index = this.items().findIndex((candidate) => candidate.value === item.value);
|
||||||
|
this.transferringFocus = true;
|
||||||
|
(this.canonical().nativeElement.children.item(index) as HTMLElement | null)?.focus({
|
||||||
|
preventScroll: true,
|
||||||
|
});
|
||||||
|
this.transferringFocus = false;
|
||||||
|
this.itemSelect.emit(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -67,6 +67,9 @@
|
|||||||
[itemTemplate]="productItem"
|
[itemTemplate]="productItem"
|
||||||
[trackBy]="trackProduct"
|
[trackBy]="trackProduct"
|
||||||
[gap]="24"
|
[gap]="24"
|
||||||
|
[itemBasis]="
|
||||||
|
effectiveLayout() === 'row' ? 'clamp(18rem, 70vw, 32rem)' : 'clamp(15rem, 30vw, 18rem)'
|
||||||
|
"
|
||||||
[circular]="true"
|
[circular]="true"
|
||||||
ariaLabel="Productos destacados"
|
ariaLabel="Productos destacados"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -4,16 +4,16 @@
|
|||||||
|
|
||||||
.quantity-selector {
|
.quantity-selector {
|
||||||
border: 1px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
width: 78px;
|
width: var(--quantity-selector-width, 78px);
|
||||||
height: 40px;
|
height: var(--quantity-selector-height, 40px);
|
||||||
min-height: 40px;
|
min-height: var(--quantity-selector-height, 40px);
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
&__button {
|
&__button {
|
||||||
width: 24px;
|
width: var(--quantity-selector-button-width, 24px);
|
||||||
height: 100%;
|
height: 100%;
|
||||||
font-size: 20px;
|
font-size: var(--quantity-selector-button-font-size, 20px);
|
||||||
color: #6f6f6f;
|
color: #6f6f6f;
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
transition:
|
transition:
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&__value {
|
&__value {
|
||||||
font-size: 16px;
|
font-size: var(--quantity-selector-value-font-size, 16px);
|
||||||
color: #6f6f6f;
|
color: #6f6f6f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,11 @@
|
|||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h2.simple-modal__content {
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
.simple-modal__actions {
|
.simple-modal__actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
z-index: 1500;
|
z-index: 1500;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 0.5rem;
|
gap: 0.25rem;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
width: 90vw;
|
width: 90vw;
|
||||||
max-width: 800px;
|
max-width: 800px;
|
||||||
|
|||||||
Reference in New Issue
Block a user