Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix disable mad buttons(#67) #68

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<button mat-raised-button color="warn" [type]="type" [disabled]="disabled" [title]="title">
<button mat-raised-button color="warn" [type]="type" [title]="title" #btn>
<ng-content></ng-content>
</button>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {Component, Input} from '@angular/core';
import {Component, ElementRef, Input, ViewChild} from '@angular/core';
import {MadBasicButton} from '../mad-basic-button';

@Component({
selector: 'mad-danger-button',
templateUrl: './danger-button.component.html',
styleUrls: ['./danger-button.component.css'],
})
export class DangerButtonComponent {
export class DangerButtonComponent extends MadBasicButton {
@Input()
type: string;

Expand All @@ -14,4 +15,12 @@ export class DangerButtonComponent {

@Input()
title: string = '';

@ViewChild('btn', { read: ElementRef, static: true }) button: ElementRef;

constructor() {
super();
super.button = this.button;
super.disabled = this.disabled;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<button (click)="clickEvent()" [disabled]="disabled" [title]="title" [type]="type" color="primary" mat-button>
<button [title]="title" [type]="type" color="primary" #btn mat-button>
<ng-content></ng-content>
</button>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Component, Input} from '@angular/core';

import { Component, ElementRef, Input, ViewChild } from '@angular/core';
import {MadBasicButton} from '../mad-basic-button';
@Component({
selector: 'mad-link-button',
templateUrl: './link-button.component.html',
styleUrls: ['./link-button.component.css'],
})
export class LinkButtonComponent {
export class LinkButtonComponent extends MadBasicButton {
@Input()
type: string;

Expand All @@ -15,6 +15,11 @@ export class LinkButtonComponent {
@Input()
title: string = '';

@Input()
clickEvent: Function;
@ViewChild('btn', { read: ElementRef, static: true }) button: ElementRef;

constructor() {
super();
super.button = this.button;
super.disabled = this.disabled;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<button mat-icon-button color="primary" [type]="type" [disabled]="disabled" [title]="title">
<button mat-icon-button color="primary" [type]="type" [title]="title" #btn>
<ng-content></ng-content>
</button>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {Component, Input} from '@angular/core';
import {Component, ElementRef, Input, ViewChild} from '@angular/core';
import {MadBasicButton} from '../mad-basic-button';

@Component({
selector: 'mad-icon-button',
templateUrl: './icon-button.component.html',
styleUrls: ['./icon-button.component.css'],
})
export class IconButtonComponent {
export class IconButtonComponent extends MadBasicButton {
@Input()
type: string;

Expand All @@ -14,4 +15,12 @@ export class IconButtonComponent {

@Input()
title: string = '';

@ViewChild('btn', { read: ElementRef, static: true }) button: ElementRef;

constructor() {
super();
super.button = this.button;
super.disabled = this.disabled;
}
}
29 changes: 29 additions & 0 deletions projects/material-addons/src/lib/button/mad-basic-button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {ElementRef, HostBinding, SimpleChanges} from '@angular/core';

export class MadBasicButton {
button: ElementRef;
disabled: boolean;

disableClick = (e: Event) => e.stopPropagation();

ngOnChanges(changes: SimpleChanges) {
this.disableButton();
}

disableButton(): void {
if (this.disabled) {
this.button.nativeElement.addEventListener('click', this.disableClick);
} else {
this.button.nativeElement.removeEventListener('click', this.disableClick);
}
}
@HostBinding('style.pointer-events')
get pointerEvent(): string {
return this.disabled ? 'none' : 'auto';
}

@HostBinding('style.opacity')
get opacity(): string {
return this.disabled ? '0.35' : '1';
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<button mat-stroked-button color="primary" [type]="type" [disabled]="disabled" [title]="title">
<button mat-stroked-button color="primary" [type]="type" [title]="title" #btn>
<ng-content></ng-content>
</button>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {Component, Input} from '@angular/core';
import {Component, ElementRef, Input, ViewChild} from '@angular/core';
import {MadBasicButton} from '../mad-basic-button';

@Component({
selector: 'mad-outline-button',
templateUrl: './outline-button.component.html',
styleUrls: ['./outline-button.component.css'],
})
export class OutlineButtonComponent {
export class OutlineButtonComponent extends MadBasicButton {
@Input()
type: string;

Expand All @@ -14,4 +15,12 @@ export class OutlineButtonComponent {

@Input()
title: string = '';

@ViewChild('btn', { read: ElementRef, static: true }) button: ElementRef;

constructor() {
super();
super.button = this.button;
super.disabled = this.disabled;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<button mat-raised-button color="primary" [type]="type" [disabled]="disabled" [title]="title">
<button mat-raised-button color="primary" [type]="type" [title]="title" #btn>
<ng-content></ng-content>
</button>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {Component, Input} from '@angular/core';
import {Component, ElementRef, Input, ViewChild} from '@angular/core';
import {MadBasicButton} from '../mad-basic-button';

@Component({
selector: 'mad-primary-button',
templateUrl: './primary-button.component.html',
styleUrls: ['./primary-button.component.css'],
})
export class PrimaryButtonComponent {
export class PrimaryButtonComponent extends MadBasicButton {
@Input()
type: string;

Expand All @@ -14,4 +15,12 @@ export class PrimaryButtonComponent {

@Input()
title: string = '';

@ViewChild('btn', { read: ElementRef, static: true }) button: ElementRef;

constructor() {
super();
super.button = this.button;
super.disabled = this.disabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h3>
</mad-icon-button>
</div>
</ng-container>
<mad-link-button *ngIf="!(readonly || readonly === '')" [clickEvent]="addEventFunction"
<mad-link-button *ngIf="!(readonly || readonly === '')" (click)="addItem()"
[disabled]="!addPossible || !isAddAllowed()">
{{ addLabel }}
</mad-link-button>