Skip to content

Commit

Permalink
fix: add "/" to RGBA calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk7034 committed Jan 11, 2024
1 parent eae084e commit 3caefc4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ describe('@mantine/core/to-rgba', () => {
expect(toRgba('rgb(240, 62, 62, 0.8)')).toStrictEqual({ r: 240, g: 62, b: 62, a: 0.8 });
expect(toRgba('rgb(214, 51, 108, 1)')).toStrictEqual({ r: 214, g: 51, b: 108, a: 1 });
expect(toRgba('rgb(112, 72, 232, .2)')).toStrictEqual({ r: 112, g: 72, b: 232, a: 0.2 });
expect(toRgba('rgb(240, 62, 62 / 0.8)')).toStrictEqual({ r: 240, g: 62, b: 62, a: 0.8 });
expect(toRgba('rgb(214, 51, 108 / 1)')).toStrictEqual({ r: 214, g: 51, b: 108, a: 1 });
expect(toRgba('rgb(112, 72, 232 / .2)')).toStrictEqual({ r: 112, g: 72, b: 232, a: 0.2 });
});

it('returns the correct rgba values when given an hsl string', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ function hexToRgba(color: string): RGBA {

function rgbStringToRgba(color: string): RGBA {
const [r, g, b, a] = color
.replace(/[^0-9,.]/g, '')
.split(',')
.replace(/[^0-9,./]/g, '')
.split(/[/,]/)
.map(Number);

return { r, g, b, a: a || 1 };
Expand Down

0 comments on commit 3caefc4

Please sign in to comment.