Skip to content

Commit

Permalink
Fixed auto color output format, fixes #142
Browse files Browse the repository at this point in the history
  • Loading branch information
sconix committed Oct 23, 2018
1 parent 9cce111 commit 7e77785
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/lib/color-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ export class ColorPickerComponent implements OnInit, OnDestroy, AfterViewInit {
this.format = ColorFormats.HEX;
}

if (this.cpOutputFormat === 'auto') {
this.cpOutputFormat = (this.cpAlphaChannel !== 'disabled') ? 'rgba' : 'hex';
}

this.listenerMouseDown = (event: any) => { this.onMouseDown(event); };
this.listenerResize = () => { this.onResize(); };

Expand Down Expand Up @@ -258,7 +254,9 @@ export class ColorPickerComponent implements OnInit, OnDestroy, AfterViewInit {
this.dialogArrowOffset = 0;
}

if (cpOutputFormat === 'hex' && cpAlphaChannel !== 'always' && cpAlphaChannel !== 'forced') {
if (cpOutputFormat === 'hex' &&
cpAlphaChannel !== 'always' && cpAlphaChannel !== 'forced')
{
this.cpAlphaChannel = 'disabled';
}
}
Expand Down Expand Up @@ -692,6 +690,12 @@ export class ColorPickerComponent implements OnInit, OnDestroy, AfterViewInit {
this.hexAlpha = this.rgbaText.a;
}

if (this.cpOutputFormat === 'auto') {
if (this.hsva.a < 1) {
this.format = this.hsva.a < 1 ? ColorFormats.RGBA : ColorFormats.HEX;
}
}

this.hueSliderColor = 'rgb(' + hue.r + ',' + hue.g + ',' + hue.b + ')';
this.alphaSliderColor = 'rgb(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ')';

Expand Down
4 changes: 4 additions & 0 deletions src/lib/color-picker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ export class ColorPickerService {
}

public outputFormat(hsva: Hsva, outputFormat: string, alphaChannel: string | null): string {
if (outputFormat === 'auto') {
outputFormat = hsva.a < 1 ? 'rgba' : 'hex';
}

switch (outputFormat) {
case 'hsla':
const hsla = this.hsva2hsla(hsva);
Expand Down

0 comments on commit 7e77785

Please sign in to comment.