Skip to content

Commit

Permalink
fix(transformHEXRGBAForCSS): allow whitespacing surrounding the hex c…
Browse files Browse the repository at this point in the history
…ode (#150)

* fix(transformHEXRGBAForCSS): allow whitespacing surrounding the hex code

* chore(): add changeset
  • Loading branch information
Jasperrr91 committed Jun 8, 2023
1 parent d5a8b75 commit 21608ff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/olive-cooks-destroy.md
@@ -0,0 +1,5 @@
---
'@tokens-studio/sd-transforms': patch
---

Patches the transformHEXRGBa function to allow for whitespaces surrounding the HEX code. The Tokens Studio plugin automatically adds these whitespaces when working with aliases so this patch removes the need for manually having to remove those whitespaces.
2 changes: 1 addition & 1 deletion src/css/transformHEXRGBa.ts
Expand Up @@ -9,7 +9,7 @@ export function transformHEXRGBaForCSS(value: string | undefined): string | unde
if (value === undefined) {
return value;
}
const match = /rgba\((?<hex>#.+?),\s*?(?<alpha>\d.*?)\)/g.exec(value);
const match = /rgba\(\s*(?<hex>#.+?)\s*,\s*?(?<alpha>\d.*?)\)/g.exec(value);
if (match && match.groups) {
const { hex, alpha } = match.groups;
try {
Expand Down
4 changes: 4 additions & 0 deletions test/spec/css/transformHEXRGBa.spec.ts
Expand Up @@ -9,6 +9,10 @@ describe('transform HEXRGBa', () => {
expect(transformHEXRGBaForCSS('rgba(#ABC123, 0.5)')).to.equal('rgba(171, 193, 35, 0.5)');
});

it("transforms Figma's hex code RGBA to actual RGBA format regardless of whitespacing", () => {
expect(transformHEXRGBaForCSS('rgba( #ABC123 , 0.5)')).to.equal('rgba(171, 193, 35, 0.5)');
});

it('does not transform the color if it doesnt match the regex', () => {
expect(transformHEXRGBaForCSS('foo')).to.equal('foo');
});
Expand Down

0 comments on commit 21608ff

Please sign in to comment.