Skip to content

Commit

Permalink
Brought back the auto value for the output format
Browse files Browse the repository at this point in the history
  • Loading branch information
sconix committed Sep 3, 2018
1 parent 138b46e commit 11f5c2f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import { ColorPickerModule } from 'ngx-color-picker';
[cpToggle] // Sets the default open / close state of the color picker (false).
[cpDisabled] // Disables opening of the color picker dialog via toggle / events.

[cpOutputFormat] // Output color format: 'hex', 'rgba', 'hsla' ('hex').
[cpOutputFormat] // Output color format: 'auto', 'hex', 'rgba', 'hsla' ('auto').
[cpAlphaChannel] // Alpha in output value: 'enabled', 'disabled', 'always' ('enabled').
[cpFallbackColor] // Is used when the color is not well-formed or is undefined ('#000').

Expand Down
2 changes: 1 addition & 1 deletion example/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ <h4><b>based on angular2-color-picker by Alberto Pujante</b></h4>
<tr>
<td>cpOutputFormat</td>
<td>
<b>'hex'</b>, 'rgba', 'hsla'
<b>'auto'</b>, 'hex', 'rgba', 'hsla'
</td>
</tr>

Expand Down
10 changes: 7 additions & 3 deletions src/lib/color-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ export class ColorPickerComponent implements OnInit, OnDestroy, AfterViewInit {
this.format = 0;
}

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 @@ -241,7 +245,7 @@ export class ColorPickerComponent implements OnInit, OnDestroy, AfterViewInit {
this.dialogArrowOffset = 0;
}

if (cpOutputFormat === 'hex' && cpAlphaChannel !== 'always' && cpAlphaChannel !== 'hex8') {
if (cpOutputFormat === 'hex' && cpAlphaChannel !== 'always') {
this.cpAlphaChannel = 'disabled';
}
}
Expand All @@ -258,7 +262,7 @@ export class ColorPickerComponent implements OnInit, OnDestroy, AfterViewInit {
public setColorFromString(value: string, emit: boolean = true, update: boolean = true): void {
let hsva: Hsva | null;

if (this.cpAlphaChannel === 'always' || this.cpAlphaChannel === 'hex8') {
if (this.cpAlphaChannel === 'always') {
hsva = this.service.stringToHsva(value, true);

if (!hsva && !this.hsva) {
Expand Down Expand Up @@ -590,7 +594,7 @@ export class ColorPickerComponent implements OnInit, OnDestroy, AfterViewInit {

this.rgbaText = new Rgba(rgba.r, rgba.g, rgba.b, Math.round(rgba.a * 100) / 100);

const allowHex8 = this.cpAlphaChannel === 'always' || this.cpAlphaChannel === 'hex8';
const allowHex8 = this.cpAlphaChannel === 'always';

this.hexText = this.service.rgbaToHex(rgba, allowHex8);
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/color-picker.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export class ColorPickerDirective implements OnChanges, OnDestroy {

@Input() cpDisableInput: boolean = false;

@Input() cpOutputFormat: string = 'auto';
@Input() cpAlphaChannel: string = 'enabled';
@Input() cpOutputFormat: string = 'hex';

@Input() cpFallbackColor: string = '#fff';

Expand Down Expand Up @@ -120,7 +120,7 @@ export class ColorPickerDirective implements OnChanges, OnDestroy {
}

this.dialog.setColorFromString(changes.colorPicker.currentValue, false);

if (this.cpUseRootViewContainer && this.cpDialogDisplay !== 'inline') {
this.cmpRef.changeDetectorRef.detectChanges();
}
Expand Down

0 comments on commit 11f5c2f

Please sign in to comment.