diff --git a/packages/pigment-css-react/src/utils/cssFunctionTransformerPlugin.ts b/packages/pigment-css-react/src/utils/cssFunctionTransformerPlugin.ts index 1a4985c5..59602e77 100644 --- a/packages/pigment-css-react/src/utils/cssFunctionTransformerPlugin.ts +++ b/packages/pigment-css-react/src/utils/cssFunctionTransformerPlugin.ts @@ -54,7 +54,9 @@ const cssFunctionTransformerPlugin = declare((api, pluginOpt } const themeKeyArr = val.split('.').join('-'); path.replaceWith( - t.stringLiteral(`var(--${finalPrefix}${propertyThemeKey}-${themeKeyArr})`), + t.stringLiteral( + `var(--${finalPrefix ? `${finalPrefix}-` : ''}${propertyThemeKey}-${themeKeyArr})`, + ), ); }, }, diff --git a/packages/pigment-css-react/tests/sx/fixtures/sx-shorthand.input.js b/packages/pigment-css-react/tests/sx/fixtures/sx-shorthand.input.js new file mode 100644 index 00000000..a0def372 --- /dev/null +++ b/packages/pigment-css-react/tests/sx/fixtures/sx-shorthand.input.js @@ -0,0 +1,12 @@ +function App(props) { + return ( +
+
+
+ ); +} diff --git a/packages/pigment-css-react/tests/sx/fixtures/sx-shorthand.output.css b/packages/pigment-css-react/tests/sx/fixtures/sx-shorthand.output.css new file mode 100644 index 00000000..b9186b8b --- /dev/null +++ b/packages/pigment-css-react/tests/sx/fixtures/sx-shorthand.output.css @@ -0,0 +1,4 @@ +.d1h14by3 { + color: var(--d1h14by3-0); + margin-bottom: 8px; +} diff --git a/packages/pigment-css-react/tests/sx/fixtures/sx-shorthand.output.js b/packages/pigment-css-react/tests/sx/fixtures/sx-shorthand.output.js new file mode 100644 index 00000000..012cf7e4 --- /dev/null +++ b/packages/pigment-css-react/tests/sx/fixtures/sx-shorthand.output.js @@ -0,0 +1,21 @@ +import { sx as _sx } from '@pigment-css/react'; +function App(props) { + return ( +
+
+
+ ); +} diff --git a/packages/pigment-css-react/tests/sx/sx.test.ts b/packages/pigment-css-react/tests/sx/sx.test.ts index ba4b79c2..b35c23bb 100644 --- a/packages/pigment-css-react/tests/sx/sx.test.ts +++ b/packages/pigment-css-react/tests/sx/sx.test.ts @@ -87,4 +87,32 @@ describe('Pigment CSS - sx prop', () => { expect(output.js).to.equal(fixture.js); expect(output.css).to.equal(fixture.css); }); + + it('sx prop shorthand', async () => { + const { output, fixture } = await runTransformation( + path.join(__dirname, 'fixtures/sx-shorthand.input.js'), + { + themeArgs: { + theme: { + cssVarPrefix: 'mui', + palette: { + grey: { + 50: '#FBFCFE', + }, + }, + vars: { + palette: { + grey: { + 50: 'var(--mui-palette-grey-50)', + }, + }, + }, + }, + }, + }, + ); + + expect(output.js).to.equal(fixture.js); + expect(output.css).to.equal(fixture.css); + }); });