coreui-angular-ex
Version:
CoreUI Components Library for Angular
88 lines (74 loc) • 2.5 kB
text/typescript
import { booleanAttribute, Directive, HostBinding, Input } from '@angular/core';
import { ButtonType, Colors, Shapes } from '../coreui.types';
export class ButtonDirective {
/**
* Toggle the active state for the component. [docs]
* @type boolean
*/
active: string | boolean = false;
/**
* Sets the color context of the component to one of CoreUI’s themed colors. [docs]
* @type Colors
*/
color?: Colors = 'primary';
/**
* Toggle the disabled state for the component.
* @type boolean
*/
disabled: string | boolean = false;
/**
* Select the shape of the component.
* @type { 'rounded' | 'rounded-top' | 'rounded-end' | 'rounded-bottom' | 'rounded-start' | 'rounded-circle' | 'rounded-pill' | 'rounded-0' | 'rounded-1' | 'rounded-2' | 'rounded-3' | string }
*/
shape?: Shapes;
/**
* Size the component small or large.
* @type {'sm' | 'lg'}
*/
size?: 'sm' | 'lg' | '' = '';
/**
* Specifies the type of button. Always specify the type attribute for the `<button>` element.
* Different browsers may use different default types for the `<button>` element.
*/
type: ButtonType = 'button';
/**
* Set the button variant to an outlined button or a ghost button.
* @type {'ghost' | 'outline'}
*/
variant?: 'ghost' | 'outline';
get hostClasses(): any {
return {
btn: true,
[`btn-${this.color}`]: !!this.color && !this.variant,
[`btn-${this.variant}`]: !!this.variant && !this.color,
[`btn-${this.variant}-${this.color}`]: !!this.variant && !!this.color,
[`btn-${this.size}`]: !!this.size,
[`${this.shape}`]: !!this.shape,
disabled: this.disabled,
active: this.active
};
}
get ariaDisabled() {
return this.disabled || null;
};
get isActive(): boolean | null {
return <boolean>this.active || null;
}
get attrDisabled() {
return this.disabled ? '' : null;
};
get tabIndex(): string | null {
return this.disabled ? '-1' : null;
}
}