Илья Таратухин / @darkilfa
@Component({
selector: 'custom-input'
})
class CustomInput {
@Input() value: String;
@Input() label: String;
@Output() change: EventEmitter<any>;
@Input() size: String; // s, m, l, xl
@Input() type: String; // light, invisible
@Input() fieldType: String; // email, password
@Input() isReadonly: bool;
@Input() isAutocomplete: bool;
@Output() focus: EventEmitter<any>;
@Output() blur: EventEmitter<any>;
focus(): void {}
...
}
// custom input template
<input class="input-text"
ref-input
[type]="type"
[disabled]="isDisabled"
[placeholder]="placeholderText"
[readonly]="isReadonly"
[autocomplete]="autocomplete"
(input)="onChange($event)"
(focus)="onFocus($event)"
(blur)="onBlur($event)"/>
<label *ngIf="isLabelNotEmpty"
(click)="focus()">
{{ label }}
</label>
@Component({
selector: 'input[custom-input]'
})
class CustomInput {
@Input() size: String; // s, m, l, xl
@Input() skin: String; // light, invisible
}
// Usage in template
<input-meta [label]="labelText">
<input custom-input
[type]="'password'"
[size]="'m'" [skin]="'light'"/>
<input-meta/>
Don't wrap native elements
<tooltip
[trigger]="'click'"
[position]="'right'"
[target]="buttonRef">
Tooltip content
</tooltip>
class Tooltip {
@Input() trigger: String;
@Input() position: String;
@Input() target: Element;
}
class Tooltip {
@Input() trigger: String;
@Input() position: String;
@Input() target: Element;
open(): void {}
close(): void {}
@Output() onOpen: EventEmitter<any>;
@Output() onClose: EventEmitter<any>;
}
class Tooltip {
@Input() position: String;
@Input() target: Element;
}
<tooltip *ngIf="isOpened"
[target]="target"
[position]="'top'">
Tooltip content
</tooltip>
<task-list
[tasks]="tasksModel"
[taskTemplate]="TaskComponent">
</task-list>
<task-list [tasks]="tasksModel">
<task
*ngFor="let item of tasksModel.items"
[model]="item">
</task>
</task-list>
@Component({
selector: 'task-list',
template: '<ng-content></ng-content>'
})
class TaskList implements AfterContentInit {
@Input() tasks: TasksModel;
@ContentChildren(Task) tasks: QueryList<Task>;
ngAfterContentInit() {
// contentChildren is set
}
}
<task-list
[tasks]="tasksModel"
[taskTemplate]="taskTemplate">
</task-list>
<ng-template ref-taskTemplate
let-item>
<task [model]="item">
</ng-template>
// Task list template
<ng-container
*ngTemplateOutlet=
"taskTemplate; context: taskItem">
</ng-container>
- Follow me: @darkilfa
-
: @wriketeam