/
dorf-field.component.ts
53 lines (47 loc) · 2.12 KB
/
dorf-field.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
import { Component } from '@angular/core';
import { DorfConfigService } from '../../dorf-config.service';
import { IDorfCommonCssClasses } from '../../base/dorf-css-classes';
import { IDorfFieldDefinition } from './abstract-dorf-field.definition';
import { DorfFieldMetadata } from './abstract-dorf-field.metadata';
import { AbstractDorfFieldComponent } from './abstract-dorf-field.component';
import { INPUT, RADIO, SELECT, CHECKBOX, DorfField } from './dorf-field';
/**
* Component which switch between all built-in DORF fields.
* There are 4 base fields + additional ones, passed with {@link DorfConfigService}. This component groups all those fields
* in order to speed up HTML template creation. Only one field will be visible at a time.
* It is possible to include custom HTML code between component's tags.
*
* @example
* ```
*
*
* <dorf-field [metadata]="fieldMeta">
* <star-rating *ngIf="fieldMeta.tag === 'star-rating'" [metadata]="fieldMeta"></star-rating>
* </dorf-field>
* ```
*
* @stable
*/
@Component({
selector: 'dorf-field',
template: `
<dorf-input *ngIf="isDorfInput" [metadata]="metadata" [ngClass]="dorfFieldCss"></dorf-input>
<dorf-radio *ngIf="isDorfRadio" [metadata]="metadata" [ngClass]="dorfFieldCss"></dorf-radio>
<dorf-select *ngIf="isDorfSelect" [metadata]="metadata" [ngClass]="dorfFieldCss"></dorf-select>
<dorf-checkbox *ngIf="isDorfCheckbox" [metadata]="metadata" [ngClass]="dorfFieldCss"></dorf-checkbox>
<!-- Fields defined by the user. -->
<ng-content></ng-content>
`
})
export class DorfFieldComponent<T, M extends DorfFieldMetadata<T, IDorfFieldDefinition<T>>> extends AbstractDorfFieldComponent<T, M> {
/** @inheritdoc */
constructor(config: DorfConfigService) {
super(config);
}
get dorfFieldCss() { return this.getCss('dorfField'); }
get isDorfInput() { return this.isDorfTag(INPUT); }
get isDorfRadio() { return this.isDorfTag(RADIO); }
get isDorfSelect() { return this.isDorfTag(SELECT); }
get isDorfCheckbox() { return this.isDorfTag(CHECKBOX); }
protected isDorfTag(tag: string) { return this.metadata.tag === tag; }
}