Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

color picker accepts rgb format #1775

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
})
export class SkyColorpickerTemplateDrivenDemoComponent {
public model: any = {
favoriteColor: '#00f'
favoriteColor: 'rgb(0, 0, 225)'
};

public swatches = [
Expand Down
15 changes: 15 additions & 0 deletions src/modules/colorpicker/colorpicker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,21 @@ describe('Colorpicker Component', () => {
verifyColorpicker(nativeElement, '#fff', '255, 255, 255');
}));

it('should handle RGB initial color', fakeAsync(() => {
fixture.detectChanges();
fixture.destroy();

fixture = TestBed.createComponent(ColorpickerTestComponent);
nativeElement = fixture.nativeElement as HTMLElement;
component = fixture.componentInstance;

component.selectedOutputFormat = 'rgba';
component.selectedColor = 'rgb(0,0,255)';

openColorpicker(nativeElement, fixture);
verifyColorpicker(nativeElement, 'rgba(0,0,255,1)', '0, 0, 255');
}));

it('should output HEX', fakeAsync(() => {
component.selectedOutputFormat = 'hex';
openColorpicker(nativeElement, fixture);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/colorpicker/colorpicker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class SkyColorpickerService {
const hue = hsva.hue;
const saturation = hsva.saturation;
const value = hsva.value;
const alpha = hsva.alpha;
const alpha = hsva.alpha || hsva.alpha === 0 ? hsva.alpha : 1;
const i = Math.floor(hue * 6);
const f = hue * 6 - i;
const p = value * (1 - saturation);
Expand Down