Skip to content

Commit

Permalink
fix joined cssVarPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed May 6, 2024
1 parent c41289a commit d2c4c7f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ const cssFunctionTransformerPlugin = declare<BabelPluginOptions>((api, pluginOpt
}
const themeKeyArr = val.split('.').join('-');
path.replaceWith(
t.stringLiteral(`var(--${finalPrefix}${propertyThemeKey}-${themeKeyArr})`),
t.stringLiteral(
`var(--${finalPrefix ? `${finalPrefix}-` : ''}${propertyThemeKey}-${themeKeyArr})`,
),
);
},
},
Expand Down
12 changes: 12 additions & 0 deletions packages/pigment-css-react/tests/sx/fixtures/sx-shorthand.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function App(props) {
return (
<main>
<div
sx={{
color: props.tier.title === 'Professional' ? 'grey.50' : undefined,
mb: 1,
}}
/>
</main>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.d1h14by3 {
color: var(--d1h14by3-0);
margin-bottom: 8px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { sx as _sx } from '@pigment-css/react';
function App(props) {
return (
<main>
<div
{..._sx(
{
className: 'd1h14by3',
vars: {
'd1h14by3-0': [
props.tier.title === 'Professional' ? 'var(--muipalette-grey-50)' : undefined,
false,
],
},
},
{},
)}
/>
</main>
);
}
28 changes: 28 additions & 0 deletions packages/pigment-css-react/tests/sx/sx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit d2c4c7f

Please sign in to comment.