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
type="button"
class="btn btn-link"
[disabled]="buttonDisabled()"
class="m-1 {{classes}}"
[disabled]="isDisabled()"
(click)="button.click()">
{{ button.text }}
</button>

View File

@ -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;
}

View File

@ -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",
}