All files / src/components/zd-menu menu-button.ts

100% Statements 13/13
100% Branches 2/2
100% Functions 2/2
100% Lines 12/12

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 5393x 93x             93x       5x         5x         5x         5x                               4x 4x 3x 3x 2x          
import { Metadata } from '@zeedhi/core';
import { Button } from '../zd-button/button';
import { IMenuButton } from './interfaces';
import { Menu } from './menu';
 
/**
 * Base class for MenuButton component.
 */
export class MenuButton extends Button implements IMenuButton {
	/**
	 * Makes the background transparent (equal to text prop in Vuetify).
	 */
	public flat = true;
 
	/**
	 * Designates the button as icon, round and flat.
	 */
	public icon = true;
 
	/**
	 * Designates the button icon, that will be rendered before the label.
	 */
	public iconName = 'menu';
 
	/**
	 * Name of the menu component controlled by this button.
	 */
	public menuName = '';
 
	/* istanbul ignore next */
	/**
	 * Creates a new Menu Button.
	 * @param props Menu Button properties
	 */
	constructor(props: IMenuButton) {
		super(props);
		this.flat = this.getInitValue('flat', props.flat, this.flat);
		this.icon = this.getInitValue('icon', props.icon, this.icon);
		this.iconName = this.getInitValue('iconName', props.iconName, this.iconName);
		this.menuName = this.getInitValue('menuName', props.menuName, this.menuName);
	}
 
	public onCreated(): void {
		super.onCreated();
		this.events.click = () => {
			if (this.menuName) {
				const menu: Menu = Metadata.getInstance(this.menuName);
				if (menu) menu.toggleMenu();
			}
		};
	}
}