Skip to content

Commit

Permalink
[react] Support transpiled library for globalCss and keyframes (#155
Browse files Browse the repository at this point in the history
)
  • Loading branch information
siriwatknp authored Jun 21, 2024
1 parent cd97713 commit 659ed43
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 22 deletions.
17 changes: 6 additions & 11 deletions packages/pigment-css-react/src/processors/globalCss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,13 @@ export class GlobalCssProcessor extends BaseProcessor {
}

private handleCall([, callArg]: CallParam, values: ValueCache) {
let styleObj: CSSInterpolation;
if (callArg.kind === ValueType.LAZY) {
styleObj = values.get(callArg.ex.name) as CSSInterpolation;
} else if (callArg.kind === ValueType.FUNCTION) {
if (callArg.kind === ValueType.LAZY || callArg.kind === ValueType.FUNCTION) {
const value = values.get(callArg.ex.name);
const { themeArgs } = this.options as IOptions;
const value = values.get(callArg.ex.name) as (
args: Record<string, unknown> | undefined,
) => CSSInterpolation;
styleObj = value(themeArgs);
}
if (styleObj) {
this.generateArtifacts(styleObj);
const styleObj: CSSInterpolation = typeof value === 'function' ? value(themeArgs) : value;
if (styleObj) {
this.generateArtifacts(styleObj);
}
}
}

Expand Down
17 changes: 6 additions & 11 deletions packages/pigment-css-react/src/processors/keyframes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,13 @@ export class KeyframesProcessor extends BaseProcessor {
}

private handleCall([, callArg]: CallParam, values: ValueCache) {
let styleObj: CSSInterpolation;
if (callArg.kind === ValueType.LAZY) {
styleObj = values.get(callArg.ex.name) as CSSInterpolation;
} else if (callArg.kind === ValueType.FUNCTION) {
if (callArg.kind === ValueType.LAZY || callArg.kind === ValueType.FUNCTION) {
const value = values.get(callArg.ex.name);
const { themeArgs } = this.options as IOptions;
const value = values.get(callArg.ex.name) as (
args: Record<string, unknown> | undefined,
) => CSSInterpolation;
styleObj = value(themeArgs);
}
if (styleObj) {
this.generateArtifacts(styleObj);
const styleObj: CSSInterpolation = typeof value === 'function' ? value(themeArgs) : value;
if (styleObj) {
this.generateArtifacts(styleObj);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@ let inputGlobalStyles = globalCss(({ theme }) => ({
if (typeof inputGlobalStyles === 'function') {
inputGlobalStyles = inputGlobalStyles();
}

// simulate CssBaseline transpiled by Next.js
export const styles = (theme) => ({
html: {
color: theme.palette.primary.main,
},
});
const GlobalStyles = globalCss((_c = ({ theme }) => styles(theme)));
var _c;
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
color: red;
}
}
html {
color: red;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ let inputGlobalStyles = null;
if (typeof inputGlobalStyles === 'function') {
inputGlobalStyles = inputGlobalStyles();
}

// simulate CssBaseline transpiled by Next.js
export const styles = (theme) => ({
html: {
color: theme.palette.primary.main,
},
});
const GlobalStyles = null;
var _c;
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,18 @@ const gradientKeyframe2 = keyframes`
background: ${({ theme }) => theme.palette.secondary.main};
}
`;

// simulate CssBaseline transpiled by Next.js
export const styles = (theme) => ({
'0%': {
background: theme.palette.primary.main,
},
'50%': {
background: green,
},
'100%': {
background: theme.palette.secondary.main,
},
});
const gradientKeyframe3 = keyframes((_c = ({ theme }) => styles(theme)));
var _c;
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@
background: blue;
}
}
@keyframes g9lh2y5 {
0% {
background: red;
}
50% {
background: green;
}
100% {
background: blue;
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
const green = 'green';
const gradientKeyframe = 'gpsum18';
const gradientKeyframe2 = 'g1t1dgxp';

// simulate CssBaseline transpiled by Next.js
export const styles = (theme) => ({
'0%': {
background: theme.palette.primary.main,
},
'50%': {
background: green,
},
'100%': {
background: theme.palette.secondary.main,
},
});
const gradientKeyframe3 = 'g9lh2y5';
var _c;

0 comments on commit 659ed43

Please sign in to comment.