import { Component , forwardRef , HostBinding , Input , ElementRef , OnInit } from '@angular/core' ; import { NG_VALUE_ACCESSOR , ControlValueAccessor } from '@angular/forms' ; import { UpdateHostClassService } from 'ngx-tethys/core' ; export type InputSize = 'xs' | 'sm' | 'md' | 'lg' | '' ; const noop = ( ) => { } ; @ Component ( { selector : 'thy-select' , templateUrl : './select.component.html' , providers : [ { provide : NG_VALUE_ACCESSOR , useExisting : forwardRef ( ( ) => ThySelectComponent ) , multi : true } , UpdateHostClassService ] } ) export class ThySelectComponent implements ControlValueAccessor , OnInit { _innerValue : any = null ; _disabled = false ; _size : InputSize ; _expandOptions = false ; private onTouchedCallback : ( ) => void = noop ; private onChangeCallback : ( _ : any ) => void = noop ; @ HostBinding ( 'class.thy-select' ) _isSelect = true ; @ Input ( ) set thySize ( value ) { this . _size = value ; } @ Input ( ) name : string ; @ Input ( ) thyAllowClear = false ; writeValue ( obj ) { if ( obj !== this . _innerValue ) { this . _innerValue = obj ; } } registerOnChange ( fn ) { this . onChangeCallback = fn ; } registerOnTouched ( fn ) { this . onTouchedCallback = fn ; } setDisabledState ? ( isDisabled ) { this . _disabled = isDisabled ; } constructor ( private elementRef , private updateHostClassService ) { this . updateHostClassService . initializeElement ( elementRef . nativeElement ) ; } ngModelChange ( ) { this . onChangeCallback ( this . _innerValue ) ; } ngOnInit ( ) { const classes = this . _size ? [ `thy-select-${ this . _size }` ] : [ ] ; this . updateHostClassService . updateClass ( classes ) ; } clearSelectValue ( event ) { event . stopPropagation ( ) ; this . _innerValue = '' ; this . onChangeCallback ( this . _innerValue ) ; } }