Skip to content

Commit

Permalink
[core] Fix useTheme import change
Browse files Browse the repository at this point in the history
* Ignore transforming useTheme reference
* Fix the path to generate theme source
  • Loading branch information
brijeshb42 committed Jun 10, 2024
1 parent e672e4b commit 71bd651
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/pigment-css-react/src/processors/useTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export type TemplateCallback = (params: Record<string, unknown> | undefined) =>
export class UseThemeProcessor extends BaseProcessor {
constructor(params: Params, ...args: TailProcessorParams) {
super([params[0]], ...args);
if (params.length === 1) {
throw BaseProcessor.SKIP;
}
validateParams(params, ['callee', ['call']], `Invalid use of ${this.tagSource.imported} tag.`);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { describe } from 'yargs';
import { expect } from 'chai';
import createExtendSxProp from '../../src/createExtendSxProp';

describe('createExtendSxProp', () => {
it('return the new copy of input', () => {
const original = { color: 'red' };
expect(createExtendSxProp()(original)).to.not.equal(original);
expect(createExtendSxProp()(original)).to.equal(original);
expect(createExtendSxProp()(original)).to.deep.equal({ color: 'red' });
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useTheme } from '../zero-styled';
import { useTheme } from '@pigment-css/react';

console.log(useTheme);

export const Fade = React.forwardRef(function Fade(props, ref) {
const theme = useTheme();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import _default from '@pigment-css/react/theme';
import { useTheme } from '@pigment-css/react';
console.log(useTheme);
export const Fade = React.forwardRef(function Fade(props, ref) {
const theme = _default;
return (
Expand Down
5 changes: 4 additions & 1 deletion packages/pigment-css-unplugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ export const plugin = createUnplugin<PigmentOptions, true>((options) => {
if (id.endsWith('styles.css')) {
return theme ? generateTokenCss(theme) : _code;
}
if (id.includes('pigment-css-react/theme')) {
if (
id.includes('pigment-css-react/theme') ||
id === `${process.env.RUNTIME_PACKAGE_NAME}/theme`
) {
return generateThemeSource(theme);
}
return null;
Expand Down

0 comments on commit 71bd651

Please sign in to comment.