celerichain-ember-uii
Version:
Fleetbase UI provides all the interface components, helpers, services and utilities for building a Fleetbase extension into the Console.
73 lines (61 loc) • 1.65 kB
JavaScript
import Component from '@glimmer/component';
import { computed, action } from '@ember/object';
import { not, equal } from '@ember/object/computed';
export default class ButtonComponent extends Component {
/**
* Determines if the button should be disabled
*
* @var {Boolean}
*/
('args.{isLoading,disabled}') get isDisabled() {
const { isLoading, disabled } = this.args;
return disabled || isLoading;
}
/**
* Determines if the button should be disabled
*
* @var {Boolean}
*/
('args.type', 'secondary') isSecondary;
/**
* Determines if the button should be disabled
*
* @var {Boolean}
*/
('isSecondary') isNotSecondary;
/**
* Determines if icon be displayed
*
* @var {Boolean}
*/
('args.{icon,isLoading}') get showIcon() {
const { icon, isLoading } = this.args;
return icon && !isLoading;
}
/**
* Setup this component
*
* @void
*/
setupComponent() {
const { onInsert } = this.args;
if (typeof onInsert === 'function') {
onInsert();
}
}
/**
* Dispatches the `onClick` event with all arguments.
* If button `this.isDisable` then event is not executed.
*
* @void
*/
onClick() {
const { onClick } = this.args;
if (this.isDisabled) {
return;
}
if (typeof onClick === 'function') {
onClick(...arguments);
}
}
}