| Output, | Output, | ||||
| } from '@angular/core'; | } from '@angular/core'; | ||||
| import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; | ||||
| import {debounceTime, Subject} from 'rxjs'; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-slider-range', | selector: 'app-slider-range', | ||||
| @Input() max: number = 300; | @Input() max: number = 300; | ||||
| @Input() icon: string = ''; | @Input() icon: string = ''; | ||||
| @Output() valueChange = new EventEmitter<number>(); | @Output() valueChange = new EventEmitter<number>(); | ||||
| @Input() disable: boolean = false; | |||||
| onChange = (value: number) => {}; | onChange = (value: number) => {}; | ||||
| onTouched = () => {}; | onTouched = () => {}; | ||||
| private valueChangeSubject = new Subject<number>(); | |||||
| constructor() {} | |||||
| constructor() { | |||||
| this.valueChangeSubject.pipe(debounceTime(500)).subscribe(value => { | |||||
| this.valueChange.emit(value); | |||||
| }); | |||||
| } | |||||
| writeValue(value: number): void { | writeValue(value: number): void { | ||||
| this.value = value; | this.value = value; | ||||
| this.value = event.target.value; | this.value = event.target.value; | ||||
| this.onChange(this.value); | this.onChange(this.value); | ||||
| this.onTouched(); | this.onTouched(); | ||||
| this.valueChange.emit(this.value); | |||||
| this.valueChangeSubject.next(this.value); | |||||
| } | } | ||||
| onSliderChangeBackground() { | onSliderChangeBackground() { | ||||
| this.value += 10; | this.value += 10; | ||||
| this.onChange(this.value); | this.onChange(this.value); | ||||
| this.onTouched(); | this.onTouched(); | ||||
| this.valueChange.emit(this.value); | |||||
| this.valueChangeSubject.next(this.value); | |||||
| } | } | ||||
| } | } | ||||
| this.value -= 10; | this.value -= 10; | ||||
| this.onChange(this.value); | this.onChange(this.value); | ||||
| this.onTouched(); | this.onTouched(); | ||||
| this.valueChange.emit(this.value); | |||||
| this.valueChangeSubject.next(this.value); | |||||
| } | } | ||||
| } | } | ||||
| } | } |