/
standard-form-row.component.ts
70 lines (63 loc) · 1.41 KB
/
standard-form-row.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {
Component,
Input,
ElementRef,
OnChanges,
SimpleChanges,
Renderer2,
SimpleChange,
} from '@angular/core';
import { toBoolean, updateHostClass } from '@delon/util';
@Component({
selector: 'standard-form-row',
template: `
<div *ngIf="title" class="label"><span>{{title}}</span></div>
<div class="control"><ng-content></ng-content></div>
`,
preserveWhitespaces: false,
})
export class StandardFormRowComponent implements OnChanges {
@Input() title: string;
/** 是否整行 */
@Input()
get block() {
return this._block;
}
set block(value: any) {
this._block = toBoolean(value);
}
private _block: boolean;
/** 是否最后一行 */
@Input()
get last() {
return this._last;
}
set last(value: any) {
this._last = toBoolean(value);
}
private _last: boolean;
/** 是否网格布局 */
@Input()
get grid() {
return this._grid;
}
set grid(value: any) {
this._grid = toBoolean(value);
}
private _grid: boolean;
constructor(private el: ElementRef, private renderer: Renderer2) {}
setClass() {
const classMap = {
['ad-standard-form-row']: true,
['block']: this.block,
['grid']: this.grid,
['last']: this.last,
};
updateHostClass(this.el.nativeElement, this.renderer, classMap);
}
ngOnChanges(
changes: { [P in keyof this]?: SimpleChange } & SimpleChanges,
): void {
this.setClass();
}
}