@lit-roa/custom-footer 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,564 +1,587 @@
1
- import { LitElement, css, html, nothing, type TemplateResult } from 'lit';
2
- import { customElement, property, state } from 'lit/decorators.js';
3
- import {
4
- emitir,
5
- estilosBase,
6
- iconoBrandFacebook,
7
- iconoBrandInstagram,
8
- iconoBrandLinkedin,
9
- iconoBrandPinterest,
10
- iconoBrandTelegram,
11
- iconoBrandTiktok,
12
- iconoBrandWhatsapp,
13
- iconoBrandX,
14
- iconoBrandYoutube,
15
- iconoChevronDown,
16
- iconoClock,
17
- iconoMail,
18
- iconoMapPin,
19
- iconoPhone,
20
- tokens,
21
- } from '@lit-roa/base';
22
-
23
- export interface EnlaceFooter {
24
- texto: string;
25
- /** URL de referencia; viaja en el evento, el componente no navega. */
26
- href?: string;
27
- /** Identificador libre para que el sitio sepa qué hacer (ej. "terminos"). */
28
- id?: string;
29
- }
30
-
31
- export interface GrupoFooter {
32
- titulo: string;
33
- enlaces: EnlaceFooter[];
34
- }
35
-
36
- export type RedSocial =
37
- | 'facebook'
38
- | 'instagram'
39
- | 'tiktok'
40
- | 'whatsapp'
41
- | 'youtube'
42
- | 'x'
43
- | 'linkedin'
44
- | 'pinterest'
45
- | 'telegram';
46
-
47
- export interface RedFooter {
48
- red: RedSocial;
49
- url: string;
50
- /** Texto accesible; por omisión el nombre de la red. */
51
- etiqueta?: string;
52
- }
53
-
54
- export interface ContactoFooter {
55
- direccion?: string;
56
- telefono?: string;
57
- correo?: string;
58
- horario?: string;
59
- }
60
-
61
- export type MetodoPago = 'visa' | 'mastercard' | 'amex' | 'mercado-pago';
62
-
63
- export interface DetalleClicEnlace {
64
- enlace: EnlaceFooter;
65
- /** Título del grupo; `undefined` cuando es el logo. */
66
- grupo?: string;
67
- }
68
-
69
- const iconosRedes: Record<RedSocial, { icono: TemplateResult; nombre: string }> = {
70
- facebook: { icono: iconoBrandFacebook, nombre: 'Facebook' },
71
- instagram: { icono: iconoBrandInstagram, nombre: 'Instagram' },
72
- tiktok: { icono: iconoBrandTiktok, nombre: 'TikTok' },
73
- whatsapp: { icono: iconoBrandWhatsapp, nombre: 'WhatsApp' },
74
- youtube: { icono: iconoBrandYoutube, nombre: 'YouTube' },
75
- x: { icono: iconoBrandX, nombre: 'X' },
76
- linkedin: { icono: iconoBrandLinkedin, nombre: 'LinkedIn' },
77
- pinterest: { icono: iconoBrandPinterest, nombre: 'Pinterest' },
78
- telegram: { icono: iconoBrandTelegram, nombre: 'Telegram' },
79
- };
80
-
81
- // TODO: cambiar por el SVG oficial del kit de marca de Mercado Pago.
82
- const mercadoPagoLogo = new URL('./mercado-pago.svg', import.meta.url).href;
83
- const metodosPago: Record<MetodoPago, { nombre: string; contenido: TemplateResult }> = {
84
- visa: { nombre: 'Visa', contenido: html`VISA` },
85
- mastercard: { nombre: 'Mastercard', contenido: html`<i></i><i></i>` },
86
- amex: { nombre: 'American Express', contenido: html`AMEX` },
87
- 'mercado-pago': { nombre: 'Mercado Pago', contenido: html`<img src=${mercadoPagoLogo}>` },
88
- };
89
-
90
- /** Ancho (px) por debajo del cual el footer pasa a una columna con acordeones. */
91
- const ANCHO_ESTRECHO = 640;
92
-
93
- /**
94
- * Footer genérico y responsive.
95
- *
96
- * Los enlaces no navegan: lanzan `clic-enlace` para que el sitio decida si
97
- * cambia de ruta o abre una modal. Ctrl/Cmd + clic sí abre el `href` en otra
98
- * pestaña. Las redes sociales sí son ligas normales (se abren en otra pestaña).
99
- *
100
- * @fires clic-enlace - Al tocar un enlace o el logo. `detail`: `{ enlace, grupo }`.
101
- * @slot boletin - Franja superior, por ejemplo un formulario de novedades.
102
- * @slot extra - Al final de la columna de contacto, por ejemplo horarios especiales.
103
- * @slot pie - En la barra inferior, junto al ©.
104
- */
105
- @customElement('lr-custom-footer')
106
- export class LrCustomFooter extends LitElement {
107
- static override styles = [
108
- tokens,
109
- estilosBase,
110
- css`
111
- :host {
112
- display: block;
113
- --_f-fondo: var(--lr-footer-fondo, #1c1917);
114
- --_f-fondo-alterno: var(--lr-footer-fondo-alterno, rgb(255 255 255 / 0.04));
115
- --_f-texto: var(--lr-footer-texto, #e7e5e4);
116
- --_f-titulos: var(--lr-footer-titulos, #ffffff);
117
- --_f-texto-suave: var(--lr-footer-texto-suave, #a8a29e);
118
- --_f-borde: var(--lr-footer-borde, #3a3431);
119
- --_f-ancho: var(--lr-footer-ancho-maximo, 1160px);
120
- }
121
- footer {
122
- background: var(--_f-fondo);
123
- color: var(--_f-texto);
124
- font-size: 0.875rem;
125
- }
126
- .cont {
127
- max-width: var(--_f-ancho);
128
- margin: 0 auto;
129
- padding: 3rem 2rem 0;
130
- }
131
- a {
132
- color: inherit;
133
- }
134
- a:focus-visible,
135
- button:focus-visible {
136
- outline: 2px solid var(--_color-primario);
137
- outline-offset: 2px;
138
- border-radius: 4px;
139
- }
140
- svg {
141
- flex: none;
142
- }
143
-
144
- .boletin {
145
- margin-bottom: 2.75rem;
146
- }
147
- .boletin[hidden] {
148
- display: none;
149
- }
150
-
151
- .rejilla {
152
- display: grid;
153
- grid-template-columns: 1.5fr repeat(var(--_grupos, 3), 1fr) 1.3fr;
154
- gap: 2rem;
155
- }
156
-
157
- .logo {
158
- display: inline-flex;
159
- align-items: center;
160
- gap: 0.625rem;
161
- font-size: 1.375rem;
162
- font-weight: 600;
163
- color: var(--_f-titulos);
164
- text-decoration: none;
165
- }
166
- .logo img {
167
- display: block;
168
- max-height: var(--lr-footer-alto-logo, 44px);
169
- max-width: 200px;
170
- object-fit: contain;
171
- }
172
- .descripcion {
173
- color: var(--_f-texto-suave);
174
- line-height: 1.6;
175
- margin: 1rem 0 1.25rem;
176
- max-width: 300px;
177
- }
178
- .redes {
179
- display: flex;
180
- flex-wrap: wrap;
181
- gap: 0.5rem;
182
- margin: 0;
183
- padding: 0;
184
- list-style: none;
185
- }
186
- .redes a {
187
- display: grid;
188
- place-items: center;
189
- width: 38px;
190
- height: 38px;
191
- border-radius: 999px;
192
- border: 1px solid var(--_f-borde);
193
- font-size: 1.25rem;
194
- transition: background 0.15s, border-color 0.15s;
195
- }
196
- .redes a:hover {
197
- background: var(--_color-primario);
198
- border-color: var(--_color-primario);
199
- color: var(--_color-sobre-primario);
200
- }
201
-
202
- .titulo {
203
- margin: 0 0 0.875rem;
204
- font-size: 0.9375rem;
205
- font-weight: 600;
206
- color: var(--_f-titulos);
207
- }
208
- .titulo button {
209
- all: unset;
210
- box-sizing: border-box;
211
- display: flex;
212
- width: 100%;
213
- justify-content: space-between;
214
- align-items: center;
215
- padding: 1rem 0.125rem;
216
- cursor: pointer;
217
- }
218
- .titulo button svg {
219
- color: var(--_f-texto-suave);
220
- font-size: 1.125rem;
221
- transition: transform 0.2s;
222
- }
223
- .titulo button[aria-expanded='true'] svg {
224
- transform: rotate(180deg);
225
- }
226
- .enlaces {
227
- list-style: none;
228
- margin: 0;
229
- padding: 0;
230
- display: grid;
231
- gap: 0.625rem;
232
- }
233
- .enlaces a {
234
- color: var(--_f-texto-suave);
235
- text-decoration: none;
236
- }
237
- .enlaces a:hover {
238
- color: var(--_f-texto);
239
- text-decoration: underline;
240
- text-underline-offset: 3px;
241
- }
242
-
243
- .dato {
244
- display: flex;
245
- gap: 0.625rem;
246
- color: var(--_f-texto-suave);
247
- margin: 0 0 0.75rem;
248
- line-height: 1.45;
249
- font-style: normal;
250
- }
251
- .dato svg {
252
- color: var(--_color-primario);
253
- font-size: 1.125rem;
254
- margin-top: 1px;
255
- }
256
- .dato a {
257
- text-decoration: none;
258
- }
259
- .dato a:hover {
260
- text-decoration: underline;
261
- }
262
-
263
- .pie {
264
- display: flex;
265
- justify-content: space-between;
266
- align-items: center;
267
- flex-wrap: wrap;
268
- gap: 1rem;
269
- border-top: 1px solid var(--_f-borde);
270
- margin-top: 2.75rem;
271
- padding: 1.375rem 0 1.625rem;
272
- color: var(--_f-texto-suave);
273
- font-size: 0.8125rem;
274
- }
275
- .derechos {
276
- display: flex;
277
- flex-wrap: wrap;
278
- gap: 0.5rem 1rem;
279
- align-items: center;
280
- }
281
- .pagos {
282
- display: flex;
283
- gap: 0.375rem;
284
- flex-wrap: wrap;
285
- margin: 0;
286
- padding: 0;
287
- list-style: none;
288
- }
289
- .pago {
290
- height: 26px;
291
- min-width: 44px;
292
- padding: 0 0.5rem;
293
- border-radius: 5px;
294
- background: #fff;
295
- display: inline-flex;
296
- align-items: center;
297
- justify-content: center;
298
- font-weight: 800;
299
- font-size: 0.6875rem;
300
- }
301
- .pago.visa {
302
- color: #1a1f71;
303
- font-style: italic;
304
- font-size: 0.8125rem;
305
- }
306
- .pago.amex {
307
- background: #2e77bc;
308
- color: #fff;
309
- }
310
- .pago.mastercard i {
311
- width: 15px;
312
- height: 15px;
313
- border-radius: 50%;
314
- background: #eb001b;
315
- }
316
- .pago.mastercard i + i {
317
- background: #f79e1b;
318
- margin-left: -6px;
319
- opacity: 0.9;
320
- }
321
- .pago.mercado-pago {
322
- gap: 5px;
323
- padding: 2px;
324
- color: #0a0a6b;
325
- font-weight: 700;
326
- font-size: 8.5px;
327
- line-height: 1;
328
- text-align: left;
329
- min-width: 94px;
330
- }
331
-
332
- /* Celular o contenedor angosto */
333
- .estrecho .cont {
334
- padding: 2rem 1rem 0;
335
- }
336
- .estrecho .boletin {
337
- margin-bottom: 1.75rem;
338
- }
339
- .estrecho .rejilla {
340
- grid-template-columns: 1fr;
341
- gap: 0;
342
- }
343
- .estrecho .marca {
344
- text-align: center;
345
- padding-bottom: 1.5rem;
346
- }
347
- .estrecho .descripcion {
348
- margin: 0.875rem auto 1.125rem;
349
- }
350
- .estrecho .redes {
351
- justify-content: center;
352
- }
353
- .estrecho .grupo {
354
- border-top: 1px solid var(--_f-borde);
355
- }
356
- .estrecho .grupo .titulo {
357
- margin: 0;
358
- }
359
- .estrecho .enlaces {
360
- padding: 0 0.125rem 1rem;
361
- }
362
- .estrecho .enlaces[hidden] {
363
- display: none;
364
- }
365
- .estrecho .contacto {
366
- border-top: 1px solid var(--_f-borde);
367
- padding-top: 1.25rem;
368
- }
369
- .estrecho .pie {
370
- flex-direction: column;
371
- text-align: center;
372
- margin-top: 1.5rem;
373
- }
374
- .estrecho .derechos,
375
- .estrecho .pagos {
376
- justify-content: center;
377
- }
378
- `,
379
- ];
380
-
381
- /** Nombre del negocio: se usa en el © y como texto del logo si no hay imagen. */
382
- @property() nombre = '';
383
-
384
- /** URL de la imagen del logo. */
385
- @property() logo = '';
386
-
387
- @property({ attribute: 'logo-alt' }) logoAlt = '';
388
-
389
- /** `href` que viaja en `clic-enlace` al tocar el logo (con `id: "inicio"`). */
390
- @property({ attribute: 'logo-href' }) logoHref = '/';
391
-
392
- @property() descripcion = '';
393
-
394
- /** Grupos de enlaces. Como atributo, en JSON. */
395
- @property({ type: Array }) grupos: GrupoFooter[] = [];
396
-
397
- /** Redes sociales. Como atributo, en JSON. */
398
- @property({ type: Array }) redes: RedFooter[] = [];
399
-
400
- /** Datos de contacto. Como atributo, en JSON. */
401
- @property({ type: Object }) contacto: ContactoFooter = {};
402
-
403
- /** Logos de pago a mostrar, en orden. Como atributo, en JSON. */
404
- @property({ type: Array, attribute: 'metodos-pago' }) metodosPago: MetodoPago[] = [];
405
-
406
- /** Título de la columna de contacto. */
407
- @property({ attribute: 'titulo-contacto' }) tituloContacto = 'Contacto';
408
-
409
- /** Reemplaza el texto después de "© año". */
410
- @property({ attribute: 'texto-derechos' }) textoDerechos = '';
411
-
412
- @state() private estrecho = false;
413
- @state() private abiertos = new Set<number>();
414
- @state() private conBoletin = false;
415
-
416
- private observador?: ResizeObserver;
417
-
418
- override connectedCallback() {
419
- super.connectedCallback();
420
- this.observador = new ResizeObserver(([entrada]) => {
421
- this.estrecho = entrada.contentRect.width < ANCHO_ESTRECHO;
422
- });
423
- this.observador.observe(this);
424
- }
425
-
426
- override disconnectedCallback() {
427
- super.disconnectedCallback();
428
- this.observador?.disconnect();
429
- }
430
-
431
- override render() {
432
- const { direccion, telefono, correo, horario } = this.contacto;
433
- const conContacto = Boolean(direccion || telefono || correo || horario);
434
- const derechos = this.textoDerechos || `${this.nombre}. Todos los derechos reservados.`;
435
-
436
- return html`
437
- <footer class=${this.estrecho ? 'estrecho' : ''}>
438
- <div class="cont">
439
- <div class="boletin" ?hidden=${!this.conBoletin}>
440
- <slot name="boletin" @slotchange=${this.revisarBoletin}></slot>
441
- </div>
442
-
443
- <div class="rejilla" style="--_grupos: ${this.grupos.length}">
444
- <div class="marca">
445
- ${this.renderLogo()}
446
- ${this.descripcion ? html`<p class="descripcion">${this.descripcion}</p>` : nothing}
447
- ${this.redes.length
448
- ? html`<ul class="redes">
449
- ${this.redes.map((r) => this.renderRed(r))}
450
- </ul>`
451
- : nothing}
452
- </div>
453
-
454
- ${this.grupos.map((g, i) => this.renderGrupo(g, i))}
455
-
456
- <div class="contacto">
457
- ${conContacto ? html`<h2 class="titulo">${this.tituloContacto}</h2>` : nothing}
458
- <address>
459
- ${direccion ? html`<p class="dato">${iconoMapPin}<span>${direccion}</span></p>` : nothing}
460
- ${telefono
461
- ? html`<p class="dato">
462
- ${iconoPhone}<a href="tel:${telefono.replace(/[^\d+]/g, '')}">${telefono}</a>
463
- </p>`
464
- : nothing}
465
- ${correo ? html`<p class="dato">${iconoMail}<a href="mailto:${correo}">${correo}</a></p>` : nothing}
466
- ${horario ? html`<p class="dato">${iconoClock}<span>${horario}</span></p>` : nothing}
467
- </address>
468
- <slot name="extra"></slot>
469
- </div>
470
- </div>
471
-
472
- <div class="pie">
473
- <div class="derechos">
474
- <span>© ${new Date().getFullYear()} ${derechos}</span>
475
- <slot name="pie"></slot>
476
- </div>
477
- ${this.metodosPago.length
478
- ? html`<ul class="pagos" aria-label="Métodos de pago">
479
- ${this.metodosPago.map((m) => this.renderPago(m))}
480
- </ul>`
481
- : nothing}
482
- </div>
483
- </div>
484
- </footer>
485
- `;
486
- }
487
-
488
- private renderLogo() {
489
- if (!this.logo && !this.nombre) return nothing;
490
- const contenido = this.logo
491
- ? html`<img src=${this.logo} alt=${this.logoAlt || this.nombre} />`
492
- : html`<span>${this.nombre}</span>`;
493
- const enlace: EnlaceFooter = { texto: this.nombre, href: this.logoHref, id: 'inicio' };
494
- return html`<a class="logo" href=${this.logoHref} @click=${(e: MouseEvent) => this.clic(e, enlace)}>
495
- ${contenido}
496
- </a>`;
497
- }
498
-
499
- private renderRed({ red, url, etiqueta }: RedFooter) {
500
- const datos = iconosRedes[red];
501
- if (!datos) return nothing;
502
- return html`<li>
503
- <a href=${url} target="_blank" rel="noopener noreferrer" aria-label=${etiqueta || datos.nombre} title=${etiqueta || datos.nombre}>
504
- ${datos.icono}
505
- </a>
506
- </li>`;
507
- }
508
-
509
- private renderGrupo(grupo: GrupoFooter, indice: number) {
510
- const abierto = !this.estrecho || this.abiertos.has(indice);
511
- const idLista = `grupo-${indice}`;
512
- return html`
513
- <nav class="grupo" aria-label=${grupo.titulo}>
514
- <h2 class="titulo">
515
- ${this.estrecho
516
- ? html`<button aria-expanded=${abierto} aria-controls=${idLista} @click=${() => this.alternar(indice)}>
517
- ${grupo.titulo} ${iconoChevronDown}
518
- </button>`
519
- : grupo.titulo}
520
- </h2>
521
- <ul class="enlaces" id=${idLista} ?hidden=${!abierto}>
522
- ${grupo.enlaces.map(
523
- (enlace) => html`<li>
524
- <a href=${enlace.href || '#'} @click=${(e: MouseEvent) => this.clic(e, enlace, grupo.titulo)}>
525
- ${enlace.texto}
526
- </a>
527
- </li>`,
528
- )}
529
- </ul>
530
- </nav>
531
- `;
532
- }
533
-
534
- private renderPago(metodo: MetodoPago) {
535
- const datos = metodosPago[metodo];
536
- if (!datos) return nothing;
537
- return html`<li class="pago ${metodo}" role="img" aria-label=${datos.nombre} title=${datos.nombre}>
538
- ${datos.contenido}
539
- </li>`;
540
- }
541
-
542
- private alternar(indice: number) {
543
- const abiertos = new Set(this.abiertos);
544
- if (!abiertos.delete(indice)) abiertos.add(indice);
545
- this.abiertos = abiertos;
546
- }
547
-
548
- private clic(evento: MouseEvent, enlace: EnlaceFooter, grupo?: string) {
549
- // Ctrl/Cmd/Shift + clic o clic con rueda: que el navegador abra el href.
550
- if (enlace.href && (evento.ctrlKey || evento.metaKey || evento.shiftKey || evento.button !== 0)) return;
551
- evento.preventDefault();
552
- emitir<DetalleClicEnlace>(this, 'clic-enlace', { enlace, grupo });
553
- }
554
-
555
- private revisarBoletin(evento: Event) {
556
- this.conBoletin = (evento.target as HTMLSlotElement).assignedNodes({ flatten: true }).length > 0;
557
- }
558
- }
559
-
560
- declare global {
561
- interface HTMLElementTagNameMap {
562
- 'lr-custom-footer': LrCustomFooter;
563
- }
564
- }
1
+ import { LitElement, css, html, nothing, type TemplateResult } from 'lit';
2
+ import { customElement, property, state } from 'lit/decorators.js';
3
+ import { logoMercadoPago } from './mercado-pago-logo.js';
4
+ import {
5
+ emitir,
6
+ estilosBase,
7
+ iconoBrandFacebook,
8
+ iconoBrandInstagram,
9
+ iconoBrandLinkedin,
10
+ iconoBrandPinterest,
11
+ iconoBrandTelegram,
12
+ iconoBrandTiktok,
13
+ iconoBrandWhatsapp,
14
+ iconoBrandX,
15
+ iconoBrandYoutube,
16
+ iconoChevronDown,
17
+ iconoClock,
18
+ iconoMail,
19
+ iconoMapPin,
20
+ iconoPhone,
21
+ tokens,
22
+ } from '@lit-roa/base';
23
+
24
+ export interface EnlaceFooter {
25
+ texto: string;
26
+ /** URL de referencia; viaja en el evento, el componente no navega. */
27
+ href?: string;
28
+ /** Identificador libre para que el sitio sepa qué hacer (ej. "terminos"). */
29
+ id?: string;
30
+ }
31
+
32
+ export interface GrupoFooter {
33
+ titulo: string;
34
+ enlaces: EnlaceFooter[];
35
+ }
36
+
37
+ export type RedSocial =
38
+ | 'facebook'
39
+ | 'instagram'
40
+ | 'tiktok'
41
+ | 'whatsapp'
42
+ | 'youtube'
43
+ | 'x'
44
+ | 'linkedin'
45
+ | 'pinterest'
46
+ | 'telegram';
47
+
48
+ export interface RedFooter {
49
+ red: RedSocial;
50
+ url: string;
51
+ /** Texto accesible; por omisión el nombre de la red. */
52
+ etiqueta?: string;
53
+ }
54
+
55
+ export interface ContactoFooter {
56
+ direccion?: string;
57
+ telefono?: string;
58
+ correo?: string;
59
+ horario?: string;
60
+ }
61
+
62
+ export type MetodoPago = 'visa' | 'mastercard' | 'amex' | 'mercado-pago';
63
+
64
+ export interface DetalleClicEnlace {
65
+ enlace: EnlaceFooter;
66
+ /** Título del grupo; `undefined` cuando es el logo. */
67
+ grupo?: string;
68
+ }
69
+
70
+ const iconosRedes: Record<RedSocial, { icono: TemplateResult; nombre: string }> = {
71
+ facebook: { icono: iconoBrandFacebook, nombre: 'Facebook' },
72
+ instagram: { icono: iconoBrandInstagram, nombre: 'Instagram' },
73
+ tiktok: { icono: iconoBrandTiktok, nombre: 'TikTok' },
74
+ whatsapp: { icono: iconoBrandWhatsapp, nombre: 'WhatsApp' },
75
+ youtube: { icono: iconoBrandYoutube, nombre: 'YouTube' },
76
+ x: { icono: iconoBrandX, nombre: 'X' },
77
+ linkedin: { icono: iconoBrandLinkedin, nombre: 'LinkedIn' },
78
+ pinterest: { icono: iconoBrandPinterest, nombre: 'Pinterest' },
79
+ telegram: { icono: iconoBrandTelegram, nombre: 'Telegram' },
80
+ };
81
+
82
+ const metodosPago: Record<MetodoPago, { nombre: string; contenido: TemplateResult }> = {
83
+ visa: { nombre: 'Visa', contenido: html`VISA` },
84
+ mastercard: { nombre: 'Mastercard', contenido: html`<i></i><i></i>` },
85
+ amex: { nombre: 'American Express', contenido: html`AMEX` },
86
+ 'mercado-pago': { nombre: 'Mercado Pago', contenido: html`<img src=${logoMercadoPago} alt="" />` },
87
+ };
88
+
89
+ /**
90
+ * Ancho de la ventana (px) desde el cual el footer pasa a una columna con
91
+ * acordeones. Se mide con media query, como el CSS: incluye la barra de
92
+ * desplazamiento (medir el componente la restaba y el cambio llegaba ~15 px tarde).
93
+ */
94
+ const ANCHO_ESTRECHO = 700;
95
+ const CONSULTA_ESTRECHO = `(max-width: ${ANCHO_ESTRECHO}px)`;
96
+
97
+ /**
98
+ * Footer genérico y responsive.
99
+ *
100
+ * Los enlaces no navegan: lanzan `clic-enlace` para que el sitio decida si
101
+ * cambia de ruta o abre una modal. Ctrl/Cmd + clic sí abre el `href` en otra
102
+ * pestaña. Las redes sociales sí son ligas normales (se abren en otra pestaña).
103
+ *
104
+ * @fires clic-enlace - Al tocar un enlace o el logo. `detail`: `{ enlace, grupo }`.
105
+ * @slot boletin - Franja superior, por ejemplo un formulario de novedades.
106
+ * @slot extra - Al final de la columna de contacto, por ejemplo horarios especiales.
107
+ * @slot pie - En la barra inferior, junto al ©.
108
+ */
109
+ @customElement('lr-custom-footer')
110
+ export class LrCustomFooter extends LitElement {
111
+ static override styles = [
112
+ tokens,
113
+ estilosBase,
114
+ css`
115
+ :host {
116
+ display: block;
117
+ --_f-fondo: var(--lr-footer-fondo, #1c1917);
118
+ --_f-fondo-alterno: var(--lr-footer-fondo-alterno, rgb(255 255 255 / 0.04));
119
+ --_f-texto: var(--lr-footer-texto, #e7e5e4);
120
+ --_f-titulos: var(--lr-footer-titulos, #ffffff);
121
+ --_f-texto-suave: var(--lr-footer-texto-suave, #a8a29e);
122
+ --_f-borde: var(--lr-footer-borde, #3a3431);
123
+ --_f-ancho: var(--lr-footer-ancho-maximo, 1160px);
124
+ }
125
+ footer {
126
+ background: var(--_f-fondo);
127
+ color: var(--_f-texto);
128
+ font-size: 0.875rem;
129
+ }
130
+ .cont {
131
+ max-width: var(--_f-ancho);
132
+ margin: 0 auto;
133
+ padding: 3rem 2rem 0;
134
+ }
135
+ a {
136
+ color: inherit;
137
+ }
138
+ a:focus-visible,
139
+ button:focus-visible {
140
+ outline: 2px solid var(--_color-primario);
141
+ outline-offset: 2px;
142
+ border-radius: 4px;
143
+ }
144
+ svg {
145
+ flex: none;
146
+ }
147
+
148
+ .boletin {
149
+ margin-bottom: 2.75rem;
150
+ }
151
+ .boletin[hidden] {
152
+ display: none;
153
+ }
154
+
155
+ .rejilla {
156
+ display: grid;
157
+ /* Contacto con mínimo fijo: un correo largo se parte en vez de ensanchar */
158
+ grid-template-columns: 1.5fr repeat(var(--_grupos, 3), 1fr) minmax(9rem, 1.3fr);
159
+ gap: 2rem;
160
+ }
161
+
162
+ .logo {
163
+ display: inline-flex;
164
+ align-items: center;
165
+ gap: 0.625rem;
166
+ font-size: 1.375rem;
167
+ font-weight: 600;
168
+ color: var(--_f-titulos);
169
+ text-decoration: none;
170
+ }
171
+ .logo img {
172
+ display: block;
173
+ max-height: var(--lr-footer-alto-logo, 44px);
174
+ max-width: 200px;
175
+ object-fit: contain;
176
+ }
177
+ .descripcion {
178
+ color: var(--_f-texto-suave);
179
+ line-height: 1.6;
180
+ margin: 1rem 0 1.25rem;
181
+ max-width: 300px;
182
+ }
183
+ .redes {
184
+ display: flex;
185
+ flex-wrap: wrap;
186
+ gap: 0.5rem;
187
+ margin: 0;
188
+ padding: 0;
189
+ list-style: none;
190
+ }
191
+ .redes a {
192
+ display: grid;
193
+ place-items: center;
194
+ width: 38px;
195
+ height: 38px;
196
+ border-radius: 999px;
197
+ border: 1px solid var(--_f-borde);
198
+ font-size: 1.25rem;
199
+ transition: background 0.15s, border-color 0.15s;
200
+ }
201
+ .redes a:hover {
202
+ background: var(--_color-primario);
203
+ border-color: var(--_color-primario);
204
+ color: var(--_color-sobre-primario);
205
+ }
206
+
207
+ .titulo {
208
+ margin: 0 0 0.875rem;
209
+ font-size: 0.9375rem;
210
+ font-weight: 600;
211
+ color: var(--_f-titulos);
212
+ }
213
+ .titulo button {
214
+ all: unset;
215
+ box-sizing: border-box;
216
+ display: flex;
217
+ width: 100%;
218
+ justify-content: space-between;
219
+ align-items: center;
220
+ padding: 1rem 0.125rem;
221
+ cursor: pointer;
222
+ }
223
+ .titulo button svg {
224
+ color: var(--_f-texto-suave);
225
+ font-size: 1.125rem;
226
+ transition: transform 0.2s;
227
+ }
228
+ .titulo button[aria-expanded='true'] svg {
229
+ transform: rotate(180deg);
230
+ }
231
+ .enlaces {
232
+ list-style: none;
233
+ margin: 0;
234
+ padding: 0;
235
+ display: grid;
236
+ gap: 0.625rem;
237
+ }
238
+ .enlaces a {
239
+ color: var(--_f-texto-suave);
240
+ text-decoration: none;
241
+ }
242
+ .enlaces a:hover {
243
+ color: var(--_f-texto);
244
+ text-decoration: underline;
245
+ text-underline-offset: 3px;
246
+ }
247
+
248
+ .dato {
249
+ display: flex;
250
+ gap: 0.625rem;
251
+ color: var(--_f-texto-suave);
252
+ margin: 0 0 0.75rem;
253
+ line-height: 1.45;
254
+ font-style: normal;
255
+ }
256
+ .dato svg {
257
+ color: var(--_color-primario);
258
+ font-size: 1.125rem;
259
+ margin-top: 1px;
260
+ }
261
+ .dato > span,
262
+ .dato > a {
263
+ min-width: 0;
264
+ /* Correos y direcciones largas parten la línea en vez de desbordar */
265
+ overflow-wrap: anywhere;
266
+ }
267
+ .dato a {
268
+ text-decoration: none;
269
+ }
270
+ .dato a:hover {
271
+ text-decoration: underline;
272
+ }
273
+
274
+ .pie {
275
+ display: flex;
276
+ justify-content: space-between;
277
+ align-items: center;
278
+ flex-wrap: wrap;
279
+ gap: 1rem;
280
+ border-top: 1px solid var(--_f-borde);
281
+ margin-top: 2.75rem;
282
+ padding: 1.375rem 0 1.625rem;
283
+ color: var(--_f-texto-suave);
284
+ font-size: 0.8125rem;
285
+ }
286
+ .derechos {
287
+ display: flex;
288
+ flex-wrap: wrap;
289
+ gap: 0.5rem 1rem;
290
+ align-items: center;
291
+ }
292
+ .pagos {
293
+ display: flex;
294
+ gap: 0.375rem;
295
+ flex-wrap: wrap;
296
+ margin: 0;
297
+ padding: 0;
298
+ list-style: none;
299
+ }
300
+ .pago {
301
+ height: 26px;
302
+ min-width: 44px;
303
+ padding: 0 0.5rem;
304
+ border-radius: 5px;
305
+ background: #fff;
306
+ display: inline-flex;
307
+ align-items: center;
308
+ justify-content: center;
309
+ font-weight: 800;
310
+ font-size: 0.6875rem;
311
+ }
312
+ .pago.visa {
313
+ color: #1a1f71;
314
+ font-style: italic;
315
+ font-size: 0.8125rem;
316
+ }
317
+ .pago.amex {
318
+ background: #2e77bc;
319
+ color: #fff;
320
+ }
321
+ .pago.mastercard i {
322
+ width: 15px;
323
+ height: 15px;
324
+ border-radius: 50%;
325
+ background: #eb001b;
326
+ }
327
+ .pago.mastercard i + i {
328
+ background: #f79e1b;
329
+ margin-left: -6px;
330
+ opacity: 0.9;
331
+ }
332
+ .pago.mercado-pago {
333
+ gap: 5px;
334
+ padding: 2px;
335
+ color: #0a0a6b;
336
+ font-weight: 700;
337
+ font-size: 8.5px;
338
+ line-height: 1;
339
+ text-align: left;
340
+ min-width: 94px;
341
+ }
342
+
343
+ /* Tableta: la marca ocupa su propia fila y deja espacio a las columnas */
344
+ @media (max-width: 960px) {
345
+ .rejilla {
346
+ grid-template-columns: repeat(var(--_grupos, 3), minmax(0, 1fr)) minmax(9rem, 1.3fr);
347
+ }
348
+ .marca {
349
+ grid-column: 1 / -1;
350
+ }
351
+ }
352
+
353
+ /* Celular */
354
+ .estrecho .cont {
355
+ padding: 2rem 1rem 0;
356
+ }
357
+ .estrecho .boletin {
358
+ margin-bottom: 1.75rem;
359
+ }
360
+ .estrecho .rejilla {
361
+ grid-template-columns: minmax(0, 1fr);
362
+ gap: 0;
363
+ }
364
+ .estrecho .marca {
365
+ text-align: center;
366
+ padding-bottom: 1.5rem;
367
+ }
368
+ .estrecho .descripcion {
369
+ margin: 0.875rem auto 1.125rem;
370
+ }
371
+ .estrecho .redes {
372
+ justify-content: center;
373
+ }
374
+ .estrecho .grupo {
375
+ border-top: 1px solid var(--_f-borde);
376
+ }
377
+ .estrecho .grupo .titulo {
378
+ margin: 0;
379
+ }
380
+ .estrecho .enlaces {
381
+ padding: 0 0.125rem 1rem;
382
+ }
383
+ .estrecho .enlaces[hidden] {
384
+ display: none;
385
+ }
386
+ .estrecho .contacto {
387
+ border-top: 1px solid var(--_f-borde);
388
+ padding-top: 1.25rem;
389
+ }
390
+ .estrecho .pie {
391
+ flex-direction: column;
392
+ text-align: center;
393
+ margin-top: 1.5rem;
394
+ }
395
+ .estrecho .derechos,
396
+ .estrecho .pagos {
397
+ justify-content: center;
398
+ }
399
+ `,
400
+ ];
401
+
402
+ /** Nombre del negocio: se usa en el © y como texto del logo si no hay imagen. */
403
+ @property() nombre = '';
404
+
405
+ /** URL de la imagen del logo. */
406
+ @property() logo = '';
407
+
408
+ @property({ attribute: 'logo-alt' }) logoAlt = '';
409
+
410
+ /** `href` que viaja en `clic-enlace` al tocar el logo (con `id: "inicio"`). */
411
+ @property({ attribute: 'logo-href' }) logoHref = '/';
412
+
413
+ @property() descripcion = '';
414
+
415
+ /** Grupos de enlaces. Como atributo, en JSON. */
416
+ @property({ type: Array }) grupos: GrupoFooter[] = [];
417
+
418
+ /** Redes sociales. Como atributo, en JSON. */
419
+ @property({ type: Array }) redes: RedFooter[] = [];
420
+
421
+ /** Datos de contacto. Como atributo, en JSON. */
422
+ @property({ type: Object }) contacto: ContactoFooter = {};
423
+
424
+ /** Logos de pago a mostrar, en orden. Como atributo, en JSON. */
425
+ @property({ type: Array, attribute: 'metodos-pago' }) metodosPago: MetodoPago[] = [];
426
+
427
+ /** Título de la columna de contacto. */
428
+ @property({ attribute: 'titulo-contacto' }) tituloContacto = 'Contacto';
429
+
430
+ /** Reemplaza el texto después de "© año". */
431
+ @property({ attribute: 'texto-derechos' }) textoDerechos = '';
432
+
433
+ @state() private estrecho = false;
434
+ @state() private abiertos = new Set<number>();
435
+ @state() private conBoletin = false;
436
+
437
+ private consulta?: MediaQueryList;
438
+ private alCambiarAncho = () => {
439
+ this.estrecho = this.consulta?.matches ?? false;
440
+ };
441
+
442
+ override connectedCallback() {
443
+ super.connectedCallback();
444
+ this.consulta = window.matchMedia(CONSULTA_ESTRECHO);
445
+ this.consulta.addEventListener('change', this.alCambiarAncho);
446
+ this.alCambiarAncho();
447
+ }
448
+
449
+ override disconnectedCallback() {
450
+ super.disconnectedCallback();
451
+ this.consulta?.removeEventListener('change', this.alCambiarAncho);
452
+ }
453
+
454
+ override render() {
455
+ const { direccion, telefono, correo, horario } = this.contacto;
456
+ const conContacto = Boolean(direccion || telefono || correo || horario);
457
+ const derechos = this.textoDerechos || `${this.nombre}. Todos los derechos reservados.`;
458
+
459
+ return html`
460
+ <footer class=${this.estrecho ? 'estrecho' : ''}>
461
+ <div class="cont">
462
+ <div class="boletin" ?hidden=${!this.conBoletin}>
463
+ <slot name="boletin" @slotchange=${this.revisarBoletin}></slot>
464
+ </div>
465
+
466
+ <div class="rejilla" style="--_grupos: ${this.grupos.length}">
467
+ <div class="marca">
468
+ ${this.renderLogo()}
469
+ ${this.descripcion ? html`<p class="descripcion">${this.descripcion}</p>` : nothing}
470
+ ${this.redes.length
471
+ ? html`<ul class="redes">
472
+ ${this.redes.map((r) => this.renderRed(r))}
473
+ </ul>`
474
+ : nothing}
475
+ </div>
476
+
477
+ ${this.grupos.map((g, i) => this.renderGrupo(g, i))}
478
+
479
+ <div class="contacto">
480
+ ${conContacto ? html`<h2 class="titulo">${this.tituloContacto}</h2>` : nothing}
481
+ <address>
482
+ ${direccion ? html`<p class="dato">${iconoMapPin}<span>${direccion}</span></p>` : nothing}
483
+ ${telefono
484
+ ? html`<p class="dato">
485
+ ${iconoPhone}<a href="tel:${telefono.replace(/[^\d+]/g, '')}">${telefono}</a>
486
+ </p>`
487
+ : nothing}
488
+ ${correo ? html`<p class="dato">${iconoMail}<a href="mailto:${correo}">${correo}</a></p>` : nothing}
489
+ ${horario ? html`<p class="dato">${iconoClock}<span>${horario}</span></p>` : nothing}
490
+ </address>
491
+ <slot name="extra"></slot>
492
+ </div>
493
+ </div>
494
+
495
+ <div class="pie">
496
+ <div class="derechos">
497
+ <span>© ${new Date().getFullYear()} ${derechos}</span>
498
+ <slot name="pie"></slot>
499
+ </div>
500
+ ${this.metodosPago.length
501
+ ? html`<ul class="pagos" aria-label="Métodos de pago">
502
+ ${this.metodosPago.map((m) => this.renderPago(m))}
503
+ </ul>`
504
+ : nothing}
505
+ </div>
506
+ </div>
507
+ </footer>
508
+ `;
509
+ }
510
+
511
+ private renderLogo() {
512
+ if (!this.logo && !this.nombre) return nothing;
513
+ const contenido = this.logo
514
+ ? html`<img src=${this.logo} alt=${this.logoAlt || this.nombre} />`
515
+ : html`<span>${this.nombre}</span>`;
516
+ const enlace: EnlaceFooter = { texto: this.nombre, href: this.logoHref, id: 'inicio' };
517
+ return html`<a class="logo" href=${this.logoHref} @click=${(e: MouseEvent) => this.clic(e, enlace)}>
518
+ ${contenido}
519
+ </a>`;
520
+ }
521
+
522
+ private renderRed({ red, url, etiqueta }: RedFooter) {
523
+ const datos = iconosRedes[red];
524
+ if (!datos) return nothing;
525
+ return html`<li>
526
+ <a href=${url} target="_blank" rel="noopener noreferrer" aria-label=${etiqueta || datos.nombre} title=${etiqueta || datos.nombre}>
527
+ ${datos.icono}
528
+ </a>
529
+ </li>`;
530
+ }
531
+
532
+ private renderGrupo(grupo: GrupoFooter, indice: number) {
533
+ const abierto = !this.estrecho || this.abiertos.has(indice);
534
+ const idLista = `grupo-${indice}`;
535
+ return html`
536
+ <nav class="grupo" aria-label=${grupo.titulo}>
537
+ <h2 class="titulo">
538
+ ${this.estrecho
539
+ ? html`<button aria-expanded=${abierto} aria-controls=${idLista} @click=${() => this.alternar(indice)}>
540
+ ${grupo.titulo} ${iconoChevronDown}
541
+ </button>`
542
+ : grupo.titulo}
543
+ </h2>
544
+ <ul class="enlaces" id=${idLista} ?hidden=${!abierto}>
545
+ ${grupo.enlaces.map(
546
+ (enlace) => html`<li>
547
+ <a href=${enlace.href || '#'} @click=${(e: MouseEvent) => this.clic(e, enlace, grupo.titulo)}>
548
+ ${enlace.texto}
549
+ </a>
550
+ </li>`,
551
+ )}
552
+ </ul>
553
+ </nav>
554
+ `;
555
+ }
556
+
557
+ private renderPago(metodo: MetodoPago) {
558
+ const datos = metodosPago[metodo];
559
+ if (!datos) return nothing;
560
+ return html`<li class="pago ${metodo}" role="img" aria-label=${datos.nombre} title=${datos.nombre}>
561
+ ${datos.contenido}
562
+ </li>`;
563
+ }
564
+
565
+ private alternar(indice: number) {
566
+ const abiertos = new Set(this.abiertos);
567
+ if (!abiertos.delete(indice)) abiertos.add(indice);
568
+ this.abiertos = abiertos;
569
+ }
570
+
571
+ private clic(evento: MouseEvent, enlace: EnlaceFooter, grupo?: string) {
572
+ // Ctrl/Cmd/Shift + clic o clic con rueda: que el navegador abra el href.
573
+ if (enlace.href && (evento.ctrlKey || evento.metaKey || evento.shiftKey || evento.button !== 0)) return;
574
+ evento.preventDefault();
575
+ emitir<DetalleClicEnlace>(this, 'clic-enlace', { enlace, grupo });
576
+ }
577
+
578
+ private revisarBoletin(evento: Event) {
579
+ this.conBoletin = (evento.target as HTMLSlotElement).assignedNodes({ flatten: true }).length > 0;
580
+ }
581
+ }
582
+
583
+ declare global {
584
+ interface HTMLElementTagNameMap {
585
+ 'lr-custom-footer': LrCustomFooter;
586
+ }
587
+ }