|
@@ -1,20 +1,16 @@
|
|
|
import { Component, OnInit, Input, forwardRef } from '@angular/core';
|
|
|
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
|
-
|
|
|
-export interface ValueTransformer {
|
|
|
- inputFn: (value: string) => { modifier: string, value: string }
|
|
|
- outputFn: (modifier: string, value: string) => string
|
|
|
-}
|
|
|
+import { ValueTransformer } from './../../interfaces';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-dropdown-modified-input',
|
|
|
templateUrl: 'dropdown-modified-input.component.html',
|
|
|
styles: [],
|
|
|
providers: [
|
|
|
- {
|
|
|
- provide: NG_VALUE_ACCESSOR,
|
|
|
- useExisting: forwardRef(() => DropdownModifiedInputComponent),
|
|
|
- multi: true
|
|
|
+ {
|
|
|
+ provide: NG_VALUE_ACCESSOR,
|
|
|
+ useExisting: forwardRef(() => DropdownModifiedInputComponent),
|
|
|
+ multi: true
|
|
|
}
|
|
|
]
|
|
|
})
|
|
@@ -22,7 +18,7 @@ export class DropdownModifiedInputComponent implements OnInit, ControlValueAcces
|
|
|
|
|
|
|
|
|
@Input()
|
|
|
- meta: StringMap= {};
|
|
|
+ meta: StringMap = {};
|
|
|
|
|
|
modifiers: Array<string>;
|
|
|
transform: ValueTransformer = {
|
|
@@ -32,7 +28,7 @@ export class DropdownModifiedInputComponent implements OnInit, ControlValueAcces
|
|
|
private selectedModifier: string;
|
|
|
private displayedValue: string;
|
|
|
private _controlValue: string;
|
|
|
-
|
|
|
+
|
|
|
private extraClass: string = '';
|
|
|
|
|
|
propagateChange = (_: any) => {};
|
|
@@ -42,7 +38,7 @@ export class DropdownModifiedInputComponent implements OnInit, ControlValueAcces
|
|
|
['modifiers', 'transform', 'placeholder'].map(p => this[p] = this.meta[p] || this[p]);
|
|
|
this.controlValue = this.meta.value;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
get controlValue(): string {
|
|
|
return this._controlValue;;
|
|
|
}
|
|
@@ -53,7 +49,7 @@ export class DropdownModifiedInputComponent implements OnInit, ControlValueAcces
|
|
|
this.displayedValue = value;
|
|
|
this._controlValue = inputValue;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
writeValue(value: string): void {
|
|
|
this.controlValue = value;
|
|
|
}
|