import { Component, OnInit, Input, Output, EventEmitter, ElementRef, HostBinding } from '@angular/core'; import { CfCoreComponent } from '../core/core.component'; import { SelectModel } from '../../models/select/select.model'; import { SelectStylingModel } from '../../models/select/select-styling.model'; @Component({ selector: 'cf-select', template: "
", styles: [":host { position: relative; z-index: 0; display: inline-flex; } :host.notification-clickable cf-notification:hover { cursor: pointer; } .cf-select-filter-container { padding: 8px 16px; height: 40px; overflow: hidden; } .cf-select-filter-container md-input-container { width: 100%; } [hidden] { display: none !important; } "] }) export class CfSelectComponent extends CfCoreComponent implements OnInit { @HostBinding('class') notifacationClickable = ''; /** *

It is Object which will recive data from SelectModel Class. It is used in cf-select template.

*

Example of SelectModel Class:

*
{
   *  placeholder: 'Select fruit: ',
   *  items: [
   *      { value: 'apl', label: 'Apple' },
   *      { value: 'ban', label: 'Banana' },
   *      { value: 'che', label: 'Cherry' }       
   * ],
   *  itemValue: 'value',
   *  itemLabel: 'label',
   *  selected: 'che',
   *  showFilter: false,
   * }
*

placeholder: string

*

It is Select placeholder text.

*

items: Array

*

It is an Array with items. Each item is an Object with at least two properties to be used in Select template.

*

itemValue: string

* It is name of item property, which will be used as value for md-option. Each item value type of that property can be only logically correct. *

itemLabel: string

* It is name of item property, which will be used as displaying text for md-option and by this property filtering system is working. Each item value type of that property can be only logically correct. Also HTML values are possible. *

selected: any

* It is 'itemValue' of one of the items and that item will be selected. *

showFilter: Boolean

* It show/hide Filter in dropdown list. */ cfSelect: Object = {}; /** * It is value of the Filter input by which whole dropdown list items will be filtered. */ cfFilterBy: string = ''; /** * It is [properties] attribute of cf-select component with json object generated by SelectModel (described in cfSelect above). */ @Input() public properties: SelectModel; @Input() public styling: SelectStylingModel; /** * It is [required] attribute of cf-select component. Means if Select is required. */ @Input() public required: Boolean = false; /** * It is [display] attribute of cf-select component. Means if Select is visible. */ @Input() public display: Boolean = true; /** * It is [disable] attribute of cf-select component. Means if Select is disabled. */ @Input() public disable: Boolean = false; /** * It is (cfOnOpen) attribute of cf-select component. Means what event to call when Select dropdown list was opened. */ @Output() cfOnOpen = new EventEmitter(); /** * It is (cfOnChange) attribute of cf-select component. Means what event to call when value of Select was changed. */ @Output() cfOnChange = new EventEmitter(); /** * It is (cfOnClose) attribute of cf-select component. Means what event to call when Select dropdown list was closed. */ @Output() cfOnClose = new EventEmitter(); /** * It is method which will emit corresponding event when Select dropdown list was opened. */ cfSelectOpened() { this.cfOnOpen.emit(); } /** * It is method which will emit corresponding event when value of Select was changed. */ cfSelectChanged() { this.cfOnChange.emit(); } /** * It is method which will emit corresponding event when Select dropdown list was closed. */ cfSelectClosed() { this.cfOnClose.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); } constructor(public elementRef: ElementRef) { super(elementRef); } /** * It will be generated cfSelect object and rendered inside component template. */ ngOnInit() { if(this.notificationAction.observers.length > 0) this.notifacationClickable = 'notification-clickable'; if(this.properties==null) this.properties = new SelectModel(); if(this.styling==null) this.styling = new SelectStylingModel(); this.cfSelect = this.properties; } }