clr-angular-static-fix
Version:
1. Install Clarity Icons package through npm:
134 lines (108 loc) • 3.25 kB
text/typescript
/*
* Copyright (c) 2016-2018 VMware, Inc. All Rights Reserved.
* This software is released under MIT license.
* The full license information can be found in LICENSE in the root directory of this project.
*/
import { Component, EventEmitter, Input, Optional, Output, SkipSelf, TemplateRef, ViewChild } from '@angular/core';
import { ClrLoadingState } from '../../utils/loading';
import { LoadingListener } from '../../utils/loading/loading-listener';
import { ButtonInGroupService } from '../providers/button-in-group.service';
export class ClrButton implements LoadingListener {
private _enableService: boolean = false;
templateRef: TemplateRef<ClrButton>;
constructor(
public buttonInGroupService: ButtonInGroupService
) {}
private _inMenu: boolean = false;
get inMenu(): boolean {
return this._inMenu;
}
set inMenu(value: boolean) {
value = !!value;
if (this._inMenu !== value) {
this._inMenu = value;
// We check if the service flag is enabled
// and if the service exists because the service is optional
if (this._enableService && this.buttonInGroupService) {
this.buttonInGroupService.updateButtonGroup(this);
}
}
}
private _classNames: string = 'btn';
get classNames(): string {
return this._classNames;
}
set classNames(value: string) {
if (typeof value === 'string') {
const classNames: string[] = value.split(' ');
if (classNames.indexOf('btn') === -1) {
classNames.push('btn');
}
this._classNames = classNames.join(' ');
}
}
private _name: string = null;
get name(): string {
return this._name;
}
set name(value: string) {
if (typeof value === 'string') {
this._name = value;
}
}
private _type: string = null;
get type(): string {
return this._type;
}
set type(value: string) {
if (typeof value === 'string') {
this._type = value;
}
}
private _disabled: any = null;
get disabled(): any {
return this._disabled;
}
set disabled(value: any) {
if (value !== null && value !== false) {
this._disabled = '';
} else {
this._disabled = null;
}
}
public loading: boolean;
loadingStateChange(state: ClrLoadingState): void {
this.loading = state === ClrLoadingState.LOADING;
}
_click: EventEmitter<boolean> = new EventEmitter<boolean>(false);
emitClick(): void {
this._click.emit(true);
}
ngAfterViewInit() {
this._enableService = true;
}
}