All files / components/crud crud-add-button.ts

20% Statements 3/15
0% Branches 0/14
0% Functions 0/2
20% Lines 3/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 561x   1x         1x                                                                                                
import { I18n } from '@zeedhi/core';
import { ICrudAddButton } from './interfaces';
import { CrudButton } from './crud-button';
 
/**
 * Button to be used on Crud Forms
 */
export class CrudAddButton extends CrudButton implements ICrudAddButton {
  /**
   * Button tooltip
   */
  private defaultTooltip: string = 'ADD';
 
  /**
   * Button flat
   */
  private defaultFlat: boolean = true;
 
  /**
   * Button icon
   */
  private defaultIcon: boolean = true;
 
  /**
   * Button icon name
   */
  private defaultIconName: string = 'plus';
 
  /**
   * Button icon color
   */
  private defaultColor: string = '#666';
 
  /**
   * Create new Crud Add Button
   * @param props component properties
   */
  public constructor(props: ICrudAddButton) {
    super({ ...props, clickShortcutKey: props.clickShortcutKey || 'f2' });
    this.flat = props.flat !== undefined ? this.flat : this.defaultFlat;
    this.icon = props.icon !== undefined ? this.icon : this.defaultIcon;
    this.iconName = props.iconName !== undefined ? this.iconName : this.defaultIconName;
    this.color = props.color !== undefined ? this.color : this.defaultColor;
    this.tooltip.label = this.tooltip.label || `${I18n.translate(this.defaultTooltip)} (${props.clickShortcutKey || 'f2'})`;
  }
 
  /**
   * Triggered when the component is clicked.
   * @param event DOM event
   * @param element Element clicked
   */
  public click(event: Event, element: HTMLElement) {
    super.click(event, element);
  }
}