91 lines
2.3 KiB
TypeScript
91 lines
2.3 KiB
TypeScript
import { ChangeDetectionStrategy, Component, booleanAttribute, input, output } from '@angular/core';
|
|||
|
|
|
||
|
|
/**
|
||
|
|
* Fila de formulario SBO: etiqueta a la izquierda y el control proyectado a la derecha.
|
||
|
|
* `action` pinta la flecha dorada de SAP (campo que enlaza a otro objeto o a una lista).
|
||
|
|
*/
|
||
|
|
@Component({
|
||
|
|
selector: 'sbo-field',
|
||
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||
|
|
template: `
|
||
|
|
<div class="f">
|
||
|
|
<label
|
||
|
|
[attr.for]="for()"
|
||
|
|
[class.req]="required()"
|
||
|
|
[class.ga]="action()"
|
||
|
|
[class.link]="linkable()"
|
||
|
|
(click)="labelClick.emit()"
|
||
|
|
>{{ label() }}</label
|
||
|
|
>
|
||
|
|
<div class="ctl">
|
||
|
|
<ng-content />
|
||
|
|
@if (error()) {
|
||
|
|
<span class="err" role="alert" [id]="for() + '-err'">{{ error() }}</span>
|
||
|
|
}
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
`,
|
||
|
|
styles: `
|
||
|
|
:host {
|
||
|
|
display: block;
|
||
|
|
}
|
||
|
|
.f {
|
||
|
|
display: grid;
|
||
|
|
grid-template-columns: var(--label-w, 165px) minmax(0, 1fr);
|
||
|
|
align-items: start;
|
||
|
|
gap: 8px;
|
||
|
|
min-height: 24px;
|
||
|
|
}
|
||
|
|
label {
|
||
|
|
padding-top: 3px;
|
||
|
|
overflow: hidden;
|
||
|
|
text-overflow: ellipsis;
|
||
|
|
white-space: nowrap;
|
||
|
|
}
|
||
|
|
label.req::after {
|
||
|
|
content: ' *';
|
||
|
|
color: var(--err);
|
||
|
|
}
|
||
|
|
label.ga {
|
||
|
|
position: relative;
|
||
|
|
padding-left: 14px;
|
||
|
|
}
|
||
|
|
label.ga::before {
|
||
|
|
content: '';
|
||
|
|
position: absolute;
|
||
|
|
left: 0;
|
||
|
|
top: 50%;
|
||
|
|
transform: translateY(-50%);
|
||
|
|
border-left: 8px solid var(--gold);
|
||
|
|
border-top: 5px solid transparent;
|
||
|
|
border-bottom: 5px solid transparent;
|
||
|
|
}
|
||
|
|
label.link {
|
||
|
|
cursor: pointer;
|
||
|
|
}
|
||
|
|
label.link:hover {
|
||
|
|
text-decoration: underline;
|
||
|
|
}
|
||
|
|
.ctl {
|
||
|
|
min-width: 0;
|
||
|
|
}
|
||
|
|
.err {
|
||
|
|
display: block;
|
||
|
|
margin-top: 1px;
|
||
|
|
font-size: 11.5px;
|
||
|
|
color: var(--err);
|
||
|
|
}
|
||
|
|
`,
|
||
|
|
})
|
||
|
|
export class SboField {
|
||
|
|
readonly label = input.required<string>();
|
||
|
|
/** `id` del control, para enlazar la etiqueta. */
|
||
|
|
readonly for = input<string>();
|
||
|
|
readonly required = input(false, { transform: booleanAttribute });
|
||
|
|
readonly action = input(false, { transform: booleanAttribute });
|
||
|
|
/** La etiqueta es un enlace (ej. abrir el socio de negocio). */
|
||
|
|
readonly linkable = input(false, { transform: booleanAttribute });
|
||
|
|
readonly error = input<string>();
|
||
|
|
|
||
|
|
readonly labelClick = output<void>();
|
||
|
|
}
|