Skip to content

Commit

Permalink
add theme test case
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Apr 29, 2024
1 parent 13d29a2 commit af389a8
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { globalCss } from '@pigment-css/react';

globalCss`
* {
box-sizing: border-box;
}
@font-face {
font-family: 'Patrick Hand SC';
font-style: normal;
font-weight: 400;
color: ${({ theme }) => theme.palette.primary.main};
src: local('Patrick Hand SC'),
local('PatrickHandSC-Regular'),
url(https://fonts.gstatic.com/s/patrickhandsc/v4/OYFWCgfCR-7uHIovjUZXsZ71Uis0Qeb9Gqo8IZV7ckE.woff2)
format('woff2');
unicode-range: U+0100-024f, U+1-1eff,
U+20a0-20ab, U+20ad-20cf, U+2c60-2c7f,
U+A720-A7FF;
}
`;

let inputGlobalStyles = globalCss(({ theme }) => ({
'@keyframes mui-auto-fill': { from: { display: 'block', color: 'transparent' } },
'@keyframes mui-auto-fill-cancel': {
from: { display: 'block', color: theme.palette.primary.main },
},
}));
if (typeof inputGlobalStyles === 'function') {
inputGlobalStyles = inputGlobalStyles();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
* {
box-sizing: border-box;
}
@font-face {
font-family: 'Patrick Hand SC';
font-style: normal;
font-weight: 400;
color: red;
src:
local('Patrick Hand SC'),
local('PatrickHandSC-Regular'),
url(https://fonts.gstatic.com/s/patrickhandsc/v4/OYFWCgfCR-7uHIovjUZXsZ71Uis0Qeb9Gqo8IZV7ckE.woff2)
format('woff2');
unicode-range: U+0100-024f, U+1-1eff, U+20a0-20ab, U+20ad-20cf, U+2c60-2c7f, U+A720-A7FF;
}
@keyframes mui-auto-fill {
from {
display: block;
color: transparent;
}
}
@keyframes mui-auto-fill-cancel {
from {
display: block;
color: red;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
null;
let inputGlobalStyles = null;
if (typeof inputGlobalStyles === 'function') {
inputGlobalStyles = inputGlobalStyles();
}
20 changes: 20 additions & 0 deletions packages/pigment-css-react/tests/globalCss/globalCss.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,24 @@ describe('Pigment CSS - globalCss', () => {
expect(output.js).to.equal(fixture.js);
expect(output.css).to.equal(fixture.css);
});

it('can access theme', async () => {
const { output, fixture } = await runTransformation(
path.join(__dirname, 'fixtures/globalCss-theme.input.js'),
{
themeArgs: {
theme: {
palette: {
primary: {
main: 'red',
},
},
},
},
},
);

expect(output.js).to.equal(fixture.js);
expect(output.css).to.equal(fixture.css);
});
});

0 comments on commit af389a8

Please sign in to comment.