40 lines
2.2 KiB
TypeScript
40 lines
2.2 KiB
TypeScript
import { Component, input, output, signal } from '@angular/core';
|
|
|
|
// Round "?" button at the top right of a card. Hover or focus shows its text; a click keeps it open until the next click.
|
|
@Component({
|
|
selector: 'app-indicador-ayuda',
|
|
template: `
|
|
<div class="ayuda" (mouseenter)="sobre.set(true)" (mouseleave)="sobre.set(false)" (focusin)="sobre.set(true)" (focusout)="sobre.set(false)">
|
|
<button type="button" class="ayuda-boton" [attr.aria-label]="etiqueta()" [attr.aria-expanded]="visible()"
|
|
[attr.aria-controls]="visible() ? idPanel : null" (click)="alternar()"><span aria-hidden="true">?</span></button>
|
|
@if (visible()) {
|
|
<div class="ayuda-texto" role="tooltip" [id]="idPanel"><ng-content /></div>
|
|
}
|
|
</div>
|
|
`,
|
|
styles: `
|
|
:host { position: absolute; top: .5rem; right: .5rem; z-index: 2; }
|
|
.ayuda { position: relative; }
|
|
.ayuda-boton { display: inline-flex; align-items: center; justify-content: center; width: 1.75rem; height: 1.75rem; padding: 0; border: 0;
|
|
border-radius: 50%; background: transparent; box-shadow: inset 0 0 0 1.5px var(--issste-text-secondary); color: var(--issste-text); font: inherit; font-weight: 800; line-height: 1; cursor: pointer; }
|
|
.ayuda-boton:focus-visible { outline: 2px solid var(--issste-text); outline-offset: 3px; }
|
|
.ayuda-texto { position: absolute; top: calc(100% + .375rem); right: 0; width: min(22rem, 80vw); box-sizing: border-box; padding: var(--issste-space-3) var(--issste-space-4);
|
|
background: var(--issste-surface); color: var(--issste-text); border: 1px solid var(--issste-border); border-inline-start: 3px solid var(--issste-accent);
|
|
border-radius: var(--issste-radius); box-shadow: 0 4px 16px rgb(0 0 0 / .18); font: var(--mat-sys-body-small); line-height: 1.5; text-align: start; overflow-wrap: anywhere; }
|
|
`,
|
|
})
|
|
export class IndicadorAyuda {
|
|
readonly etiqueta = input('Cómo leer');
|
|
readonly opened = output<void>();
|
|
readonly sobre = signal(false);
|
|
readonly fijo = signal(false);
|
|
private static contador = 0;
|
|
readonly idPanel = 'ayuda-' + ++IndicadorAyuda.contador;
|
|
visible() { return this.sobre() || this.fijo(); }
|
|
alternar() {
|
|
const abre = !this.fijo();
|
|
this.fijo.set(abre);
|
|
if (abre) this.opened.emit();
|
|
}
|
|
}
|