import { Component, OnInit, Input, Output, ElementRef, EventEmitter, HostBinding } from '@angular/core'; import { CfCoreComponent } from '../core/core.component'; import { ButtonMenuModel } from '../../models/button-menu/button-menu.model'; import { ButtonMenuStylingModel } from '../../models/button-menu/button-menu-styling.model'; import { ButtonMenuTemplates } from '../../templates/button-menu.template'; /** *

GC ButtonMenu is created based on the ButtonMenuModel class (see /models/button-menu).

*

Example of using the component:

*
 * <cf-button [settings]="button" (onClick)="function() "></cf-button>
 * 
*/ @Component({ selector: 'cf-button-menu', template: " ", styles: [":host { position: relative; z-index: 0; } :host.notification-clickable cf-notification:hover { cursor: pointer; } :host > span { display: flex; flex-direction: row; } .cf-button-menu-main { border-radius: 4px 0 0 4px; } .cf-button-menu-trigger { border-radius: 0 4px 4px 0; padding: 0px; width: 40px; min-width: 40px; position: relative; z-index: 0; } .cf-button-menu-trigger:before { content: ''; display: block; width: 100%; height: 100%; position: absolute; z-index: 1; } .cf-button-menu-main[disabled], .cf-button-menu-trigger[disabled] { background-color: rgba(0, 0, 0, 0.065) !important; color: rgba(0, 0, 0, 0.38) !important; } "] }) export class CfButtonMenuComponent extends CfCoreComponent implements OnInit { @HostBinding('class') notifacationClickable = ''; /** * It is the ButtonMenu object which will recive data from ButtonMenuModel and after will be used in component template. */ cfButtonMenu: ButtonMenuModel; /** *

The type of the needed button.

*

Type can be: mat-button, mat-raised-button.

*/ buttonType: string; /** *

It is cf-button-menu html attribute [settings] with json ButtonMenu object.

*

ButtonMenu is assembly of Button component and Menu component.

*/ @Input() public properties: ButtonMenuModel; @Input() public styling: ButtonMenuStylingModel; /** *

It is cf-button-menu html attribute [disabled] to set disabled status of component. Default is false.

*/ @Input() disabled: boolean = false; /** *

The event will be emitted when the button is clicked (left part of button).

*

Click on right part of the button (with arrow down icon) is just opening dropdown menu.

*/ @Output() onClick = new EventEmitter(); notificationAction: any; constructor(public elementRef: ElementRef) { super(elementRef); } /** *

On initialization:

*

Check to see if any of the angular material button types are needed to be passed to the child button.

*

Types are: md-button, md-raised-button.

*

Then initialize the button element.

*/ ngOnInit() { super.ngOnInit(); if(this.properties==null) this.properties = new ButtonMenuModel(ButtonMenuTemplates.defaultTemplate.property); if(this.styling==null) this.styling = new ButtonMenuStylingModel(ButtonMenuTemplates.defaultTemplate.style); if(this.notificationAction.observers.length>0) this.notifacationClickable = 'notification-clickable'; this.cfButtonMenu = this.properties; } /** *

The method will emit event when the button is clicked

*/ buttonClicked() { this.onClick.emit(); } /** * It is function for creating Notification click events by using Core Component notificationAction event emmiter. * @param notification it is json notification object */ cfNotificationAction(notification) { this.notificationAction.emit(notification); } }