Skip to content

Commit

Permalink
feat(color-convert): add hsva to hexa
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jul 18, 2021
1 parent 539ab09 commit 55b5e98
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/color-convert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ hexToHsva("#ffffff") //=> { h: 0, s: 0, v: 100, a: 1 }
hsvaToHex({ h: 0, s: 0, v: 100, a: 1 }) // => "#ffffff"
```

#### `hsvaToHexa`

```js
hsvaToHex({ h: 0, s: 0, v: 100, a: 1 }) // => "#ffffff"
```

#### `hsvaToHsla`

```js
Expand Down
1 change: 1 addition & 0 deletions packages/color-convert/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ export const hsvaToRgbaString = (hsva: HsvaColor): string => {
export const rgbaToRgb = ({ r, g, b }: RgbaColor): RgbColor => ({ r, g, b });
export const hslaToHsl = ({ h, s, l }: HslaColor): HslColor => ({ h, s, l });
export const hsvaToHex = (hsva: HsvaColor): string => rgbaToHex(hsvaToRgba(hsva));
export const hsvaToHexa = (hsva: HsvaColor): string => rgbaToHexa(hsvaToRgba(hsva));
export const hsvaToHsv = ({ h, s, v }: HsvaColor): HsvColor => ({ h, s, v });

export const color = (str: string | HsvaColor): ColorResult => {
Expand Down
11 changes: 10 additions & 1 deletion test/convert.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { color, getContrastingColor } from '../packages/color-convert/src';
// HEX
import { hexToHsva, hexToRgba, hsvaToHex } from '../packages/color-convert/src';
import { hexToHsva, hexToRgba, hsvaToHex, hsvaToHexa } from '../packages/color-convert/src';
import { equalHex } from '../packages/color-convert/src/utils';
// HSLA
import { hsvaToHsla, hslaToHsva, HsvaColor, HslaColor } from '../packages/color-convert/src';
Expand Down Expand Up @@ -125,6 +125,15 @@ it('Converts HSVA to HEX', () => {
expect(hsvaToHex({ h: 284, s: 93, v: 73, a: 1 })).toBe('#8c0dba');
});

it('Converts HSVA to HEXA', () => {
expect(hsvaToHexa({ h: 0, s: 0, v: 30.19607843137255, a: 0.4875 })).toBe('#4d4d4d7c');
expect(hsvaToHexa({ h: 0, s: 0, v: 100, a: 1 })).toBe('#ffffffff');
expect(hsvaToHexa({ h: 60, s: 100, v: 100, a: 1 })).toBe('#ffff00ff');
expect(hsvaToHexa({ h: 0, s: 100, v: 100, a: 1 })).toBe('#ff0000ff');
expect(hsvaToHexa({ h: 0, s: 0, v: 0, a: 1 })).toBe('#000000ff');
expect(hsvaToHexa({ h: 284, s: 93, v: 73, a: 1 })).toBe('#8c0dbaff');
});

it('Converts HSVA to HSLA', () => {
let test = (input: HsvaColor, output: HslaColor) => expect(hsvaToHsla(input)).toMatchObject(output);
test({ h: 0, s: 0, v: 100, a: 1 }, { h: 0, s: 0, l: 100, a: 1 });
Expand Down

0 comments on commit 55b5e98

Please sign in to comment.