@engie-group/fluid-design-system-angular
Version:
Fluid Design System Angular
111 lines (94 loc) • 2.54 kB
text/typescript
import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, ViewEncapsulation } from '@angular/core';
import { IconComponent } from '../icon/icon.component';
import { ButtonEmphasis, ButtonSize, buttonSizeToCSS, ButtonVariant } from './button.model';
import { SpinnerComponent } from '../spinner/spinner.component';
export class ButtonComponent {
/**
* @ignore
*/
private readonly buttonClassName = 'nj-btn';
/**
* Type of the button. Some values may be submit, reset...
*/
type = 'button';
/**
* Whether button is disabled or not
*/
isDisabled?: boolean;
/**
* Whether button is loading or not
*/
isLoading?: boolean;
/**
* Tab index, allows you to customize keyboard navigation
*/
tabIndex?: number;
/**
* Button emphasis
*/
emphasis: ButtonEmphasis = 'bold';
/**
* Button variant theme
*/
variant: ButtonVariant = 'primary';
/**
* Button size
*/
size?: ButtonSize;
/**
* Whether button has custom icon
*/
hasCustomIcon = false;
/**
* Button material icon
*/
icon?: string;
/**
* Text alternative for assistive technologies
* @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label
*/
ariaLabel?: string;
/**
* Button click output. Emits a MouseEvent
*/
buttonClick = new EventEmitter<MouseEvent>();
/**
* @ignore
*/
getButtonEmphasisClass(): string {
if (!this.emphasis || this.emphasis === 'bold') {
return '';
}
return `${this.buttonClassName}--${this.emphasis}`;
}
/**
* @ignore
*/
getButtonVariantClass(): string {
if (!this.variant || this.variant === 'primary') {
return '';
}
return `${this.buttonClassName}--${this.variant}`;
}
protected getButtonSizeClass(): string {
if (!this.size || this.size === 'medium' || this.size === 'normal') {
return '';
}
return `${this.buttonClassName}--${buttonSizeToCSS(this.size)}`;
}
/**
* @ignore
*/
getButtonIsLoadingClass(): string {
return this.isLoading ? `${this.buttonClassName}--is-loading` : '';
}
}