65 lines
3.3 KiB
TypeScript
65 lines
3.3 KiB
TypeScript
import { Component, Input } from '@angular/core';
|
|
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
|
import { MatCardModule } from '@angular/material/card';
|
|
|
|
@Component({
|
|
selector: 'app-indicador-kpi-card',
|
|
imports: [MatCardModule, MatProgressBarModule],
|
|
template: `
|
|
<mat-card [attr.aria-busy]="loading">
|
|
<h3>{{ title }}</h3>
|
|
@if (loading) { <mat-progress-bar mode="indeterminate" [attr.aria-label]="'Cargando ' + title" /> }
|
|
@if (value !== null && value !== undefined) {
|
|
<p class="value">{{ value }}@if (unit) { <span>{{ unit }}</span> }</p>
|
|
}
|
|
<div class="kpi-foot">
|
|
@if (temporalReference) {
|
|
<p class="period">@if (labeledPeriod) { <span class="period-label">Periodo:</span> }<span>{{ temporalReference }}</span></p>
|
|
}
|
|
<p class="kpi-state" role="status" [class.visually-hidden]="quietWhenAvailable && state === 'Disponible'">{{ state }}</p>
|
|
@if (informationLine) { <p class="additional-info">{{ informationLine }}</p> }
|
|
</div>
|
|
</mat-card>
|
|
`,
|
|
styles: `
|
|
:host { display: flex; flex-direction: column; height: 100%; min-width: 0; }
|
|
mat-card { box-sizing: border-box; display: flex; flex-direction: column; flex: 1 1 auto; height: auto; min-height: 100%; padding: var(--issste-space-6);
|
|
background: var(--issste-surface); color: var(--issste-text); border: 1px solid var(--issste-border);
|
|
border-radius: var(--issste-radius); box-shadow: none; }
|
|
.kpi-foot { margin-top: auto; }
|
|
.period { display: flex; flex-wrap: wrap; align-items: baseline; gap: .35rem; }
|
|
.period-label { font-weight: 600; }
|
|
h3 { margin: 0; font-family: var(--issste-font-heading); font-size: 1rem; font-weight: 500; line-height: 1.3; }
|
|
h3, p { overflow-wrap: anywhere; }
|
|
p { margin: var(--issste-space-3) 0 0; }
|
|
.kpi-state, .additional-info { color: var(--issste-text-secondary); font: var(--mat-sys-body-medium); }
|
|
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
|
|
clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
|
|
.value { font-size: 1.75rem; font-weight: 500; line-height: 1.2; }
|
|
.value span { margin-inline-start: .3em; }
|
|
// CaMa's cards are as tall as their grid row.
|
|
:host-context(.kpi-section[data-domain='cama']) { display: flex; flex-direction: column; }
|
|
:host-context(.kpi-section[data-domain='cama']) mat-card { flex: 1 1 auto; height: auto; }
|
|
`,
|
|
})
|
|
export class IndicadorKpiCard {
|
|
@Input({ required: true }) title!: string;
|
|
@Input() value?: string | number | null;
|
|
@Input() unit?: string;
|
|
@Input() temporalReference?: string;
|
|
@Input() loading = false;
|
|
@Input() notes: string[] = [];
|
|
@Input() state = 'Pendiente de definición';
|
|
// A card that shows its value needs no "Disponible" line.
|
|
@Input() quietWhenAvailable = false;
|
|
@Input() additionalInfo?: string;
|
|
get labeledPeriod(): boolean {
|
|
const text = this.temporalReference?.trim();
|
|
return !!text && text.split(',').every(part => /^\d{4}-(?:S[12]|0[1-9]|1[0-2])$/.test(part.trim()));
|
|
}
|
|
get informationLine(): string | undefined {
|
|
const lines = [this.additionalInfo, ...this.notes].map(value => value?.trim()).filter((value): value is string => !!value);
|
|
return [...new Set(lines)].join(' ');
|
|
}
|
|
}
|