RLH-14 - Implement Button component
This commit is contained in:
parent
02b8ce1655
commit
ec27ad7ee2
@ -1,7 +1,7 @@
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-link"
|
||||
[disabled]="buttonDisabled()"
|
||||
class="m-1 {{classes}}"
|
||||
[disabled]="isDisabled()"
|
||||
(click)="button.click()">
|
||||
{{button.text}}
|
||||
{{ button.text }}
|
||||
</button>
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {booleanAttribute, Component, Input, OnInit} from '@angular/core';
|
||||
import {ButtonModel} from "./models/button.model";
|
||||
import {Component, Input, OnInit} from '@angular/core';
|
||||
import {ButtonModel, ButtonType} from "./models/button.model";
|
||||
|
||||
@Component({
|
||||
selector: 'rlh-button',
|
||||
@ -14,12 +14,12 @@ export class ButtonComponent implements OnInit
|
||||
@Input() button: ButtonModel = {
|
||||
text: 'text',
|
||||
disabled: () => false,
|
||||
click: () => {}
|
||||
click: () => {},
|
||||
type: ButtonType.PRIMARY
|
||||
};
|
||||
|
||||
buttonDisabled: () => boolean = () => {
|
||||
isDisabled: () => boolean = () => {
|
||||
return false;
|
||||
// tslint:disable-next-line: semicolon
|
||||
};
|
||||
|
||||
ngOnInit() {
|
||||
@ -28,12 +28,19 @@ export class ButtonComponent implements OnInit
|
||||
: () => false;
|
||||
//
|
||||
setTimeout(() => {
|
||||
this.buttonDisabled = () => {
|
||||
this.isDisabled = () => {
|
||||
return this.button.disabled();
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
get classes(): string {
|
||||
let classes = 'btn';
|
||||
classes += ' ' + (this.button.type ? this.button.type : ButtonType.PRIMARY);
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,5 +1,11 @@
|
||||
export class ButtonModel {
|
||||
text: string = "text";
|
||||
type: ButtonType;
|
||||
disabled: () => boolean;
|
||||
click: () => void;
|
||||
}
|
||||
|
||||
export enum ButtonType {
|
||||
LINK = "btn-link",
|
||||
PRIMARY = "btn-primary",
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user