UNPKG

@obliczeniowo/elementary

Version:
113 lines (108 loc) 5.34 kB
import * as i1 from '@obliczeniowo/elementary/slider'; import { SliderComponent, SliderModule } from '@obliczeniowo/elementary/slider'; import * as i0 from '@angular/core'; import { EventEmitter, Input, Output, ViewChild, Component, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; /** * Jumper component is made to emit jump value avery 100 ms when user press and * hold left mouse button on jumper area. * * Emitted value need to be used to increase/decrease some variable like page of * table or other parameters without care about step or target value * minimum/maximum. Size of emitted value pending on place when user click and * is bigger if your press left mouse button on edge of jumper area and less * when you click closer to center of it. */ class JumperComponent { change; slider; /** * emits jump value multiply by amount, where jump value is number from range -1 to 1 * with step set by default on 0.1 */ jump = new EventEmitter(); /** maximum of jumping step */ amount = 1; /** */ interval = 100; formatter = (value, max, decimalPipe) => { return ''; }; timer; constructor(change) { this.change = change; } changed(value) { this.slider.value = 0; this.stop(); } emit(value) { this.slider.setValue(false); this.start(); } out() { this.stop(); this.slider.value = 0; this.slider.overValue = 0; this.slider.setValue(false); this.change.detectChanges(); } stop() { if (this.timer) { clearInterval(this.timer); this.timer = undefined; } } start() { if (!this.timer && this.slider) { this.timer = setInterval(() => { this.slider.setValue(false); if (this.slider.value) { this.jump.emit(this.slider.value * this.amount); } }, this.interval); } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: JumperComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.0.4", type: JumperComponent, isStandalone: false, selector: "obl-jumper", inputs: { amount: "amount", interval: "interval" }, outputs: { jump: "jump" }, viewQueries: [{ propertyName: "slider", first: true, predicate: SliderComponent, descendants: true }], ngImport: i0, template: "<div>\n <obl-slider\n [min]=\"-1\"\n [max]=\"1\"\n [value]=\"0\"\n [step]=\"0.1\"\n [formatter]=\"formatter\"\n (valueChanged)=\"changed($event)\"\n (mouseDownValue)=\"emit($event)\"\n (out)=\"out()\"\n #slider\n ></obl-slider>\n</div>\n", styles: [":host{display:flex}div{width:200px}\n"], dependencies: [{ kind: "component", type: i1.SliderComponent, selector: "obl-slider", inputs: ["value", "max", "min", "step", "displayValue", "formatter"], outputs: ["valueChanged", "mouseDownValue", "out", "in"] }] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: JumperComponent, decorators: [{ type: Component, args: [{ selector: 'obl-jumper', standalone: false, template: "<div>\n <obl-slider\n [min]=\"-1\"\n [max]=\"1\"\n [value]=\"0\"\n [step]=\"0.1\"\n [formatter]=\"formatter\"\n (valueChanged)=\"changed($event)\"\n (mouseDownValue)=\"emit($event)\"\n (out)=\"out()\"\n #slider\n ></obl-slider>\n</div>\n", styles: [":host{display:flex}div{width:200px}\n"] }] }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }], propDecorators: { slider: [{ type: ViewChild, args: [SliderComponent] }], jump: [{ type: Output }], amount: [{ type: Input }], interval: [{ type: Input }] } }); class JumperModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: JumperModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: JumperModule, declarations: [JumperComponent], imports: [CommonModule, SliderModule], exports: [JumperComponent] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: JumperModule, imports: [CommonModule, SliderModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: JumperModule, decorators: [{ type: NgModule, args: [{ declarations: [ JumperComponent ], imports: [ CommonModule, SliderModule ], exports: [ JumperComponent ] }] }] }); /** * Generated bundle index. Do not edit. */ export { JumperComponent, JumperModule }; //# sourceMappingURL=obliczeniowo-elementary-jumper.mjs.map