refacotr custom color entry component

This commit is contained in:
Fabian Jeglinski
2019-05-10 17:47:57 +02:00
parent 8e29b9f139
commit 4ae9653e66
3 changed files with 15 additions and 33 deletions
@@ -1,7 +1,7 @@
<div class="entry"> <div class="entry">
Color: Color:
<div class="color-preview" [ngStyle]="previewStyle"></div> <div class="color-preview" [ngStyle]="previewStyle"></div>
<span *ngIf="isDefaultColor">(Default)</span> <span *ngIf="isDefaultColor">(default color)</span>
<div class="controls"> <div class="controls">
<!-- [(colorPicker)]="selectedColor"--> <!-- [(colorPicker)]="selectedColor"-->
<i class="material-icons" <i class="material-icons"
@@ -11,7 +11,7 @@
} }
.color-preview { .color-preview {
margin-left: .5rem; margin: 0 .5rem 0 .5rem;
height: 2rem; height: 2rem;
width: 2rem; width: 2rem;
border: 2px solid; border: 2px solid;
@@ -14,14 +14,7 @@ import {Config} from "../../misc/Config";
}) })
export class CustomColorEntryComponent implements OnInit{ export class CustomColorEntryComponent implements OnInit{
_colors: any; @Input() colors: any;
@Input() set colors(value: any) {
this._colors = value;
}
get colors(): any {
return this._colors;
}
private _selectedColor: any; private _selectedColor: any;
set selectedColor(value: any) { set selectedColor(value: any) {
@@ -30,45 +23,33 @@ export class CustomColorEntryComponent implements OnInit{
this.colorChangeEmitter.emit(this.colors); this.colorChangeEmitter.emit(this.colors);
} }
get selectedColor(): any { get selectedColor() :any{
return this._selectedColor; return this._selectedColor;
} }
// - default color properties // - default color properties
get defaultStrokeColor(): any {
return this.colors[CustomProperties.DEFAULT_COLOR_STROKE];
}
get defaultStrokeColorAsRgba(): string { get defaultStrokeColorAsRgba(): string {
return Utils.colorArrayToRgba(this.defaultStrokeColor); const color = this.colors[CustomProperties.DEFAULT_COLOR_STROKE];
} return Utils.colorArrayToRgba(color);
get defaultFillColor(): number[] {
return this.colors[CustomProperties.DEFAULT_COLOR_FILL];
} }
get defaultFillColorAsRgba(): string { get defaultFillColorAsRgba(): string {
return Utils.colorArrayToRgba(this.defaultFillColor); const color = this.colors[CustomProperties.DEFAULT_COLOR_FILL];
return Utils.colorArrayToRgba(color);
} }
// - not default color properties // - not default color properties
get strokeColor(): any {
return this.colors[CustomProperties.COLOR_STROKE];
}
get strokeColorAsRgba(): string { get strokeColorAsRgba(): string {
return Utils.colorArrayToRgba(this.strokeColor); const color = this.colors[CustomProperties.COLOR_STROKE];
} return Utils.colorArrayToRgba(color);
get fillColor(): number[] {
return this.colors[CustomProperties.COLOR_FILL];
} }
get fillColorAsRgba(): string { get fillColorAsRgba(): string {
return Utils.colorArrayToRgba(this.fillColor); const color = this.colors[CustomProperties.COLOR_FILL];
return Utils.colorArrayToRgba(color);
} }
@Output('colorChanged') colorChangeEmitter: EventEmitter<any> = new EventEmitter(); @Output('colorChanged') colorChangeEmitter: EventEmitter<any> = new EventEmitter();
/** /**
@@ -95,7 +76,7 @@ export class CustomColorEntryComponent implements OnInit{
'background-color': this.defaultFillColorAsRgba 'background-color': this.defaultFillColorAsRgba
}; };
this.isDefaultColor = true; this.isDefaultColor = true;
if (this.strokeColor) { if (this.selectedColor) {
styles = { styles = {
'border-color': this.strokeColorAsRgba, 'border-color': this.strokeColorAsRgba,
'background-color': this.fillColorAsRgba 'background-color': this.fillColorAsRgba
@@ -118,6 +99,7 @@ export class CustomColorEntryComponent implements OnInit{
resetColor(){ resetColor(){
this.colors[CustomProperties.COLOR_STROKE] = null; this.colors[CustomProperties.COLOR_STROKE] = null;
this.colors[CustomProperties.COLOR_FILL] = null; this.colors[CustomProperties.COLOR_FILL] = null;
this._selectedColor = null;
this.definePreviewStyle(); this.definePreviewStyle();
} }