RLH-14 - Implement Button component

This commit is contained in:
Bea 2024-11-04 09:31:29 +01:00
parent 02b8ce1655
commit ec27ad7ee2
3 changed files with 22 additions and 9 deletions

View File

@ -1,7 +1,7 @@
<button <button
type="button" type="button"
class="btn btn-link" class="m-1 {{classes}}"
[disabled]="buttonDisabled()" [disabled]="isDisabled()"
(click)="button.click()"> (click)="button.click()">
{{button.text}} {{ button.text }}
</button> </button>

View File

@ -1,5 +1,5 @@
import {booleanAttribute, Component, Input, OnInit} from '@angular/core'; import {Component, Input, OnInit} from '@angular/core';
import {ButtonModel} from "./models/button.model"; import {ButtonModel, ButtonType} from "./models/button.model";
@Component({ @Component({
selector: 'rlh-button', selector: 'rlh-button',
@ -14,12 +14,12 @@ export class ButtonComponent implements OnInit
@Input() button: ButtonModel = { @Input() button: ButtonModel = {
text: 'text', text: 'text',
disabled: () => false, disabled: () => false,
click: () => {} click: () => {},
type: ButtonType.PRIMARY
}; };
buttonDisabled: () => boolean = () => { isDisabled: () => boolean = () => {
return false; return false;
// tslint:disable-next-line: semicolon
}; };
ngOnInit() { ngOnInit() {
@ -28,12 +28,19 @@ export class ButtonComponent implements OnInit
: () => false; : () => false;
// //
setTimeout(() => { setTimeout(() => {
this.buttonDisabled = () => { this.isDisabled = () => {
return this.button.disabled(); return this.button.disabled();
}; };
}); });
} }
get classes(): string {
let classes = 'btn';
classes += ' ' + (this.button.type ? this.button.type : ButtonType.PRIMARY);
return classes;
}

View File

@ -1,5 +1,11 @@
export class ButtonModel { export class ButtonModel {
text: string = "text"; text: string = "text";
type: ButtonType;
disabled: () => boolean; disabled: () => boolean;
click: () => void; click: () => void;
} }
export enum ButtonType {
LINK = "btn-link",
PRIMARY = "btn-primary",
}