Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.

Commit 9d61910

Browse files
committed
fix(emotion): fix css function
1 parent 4d79400 commit 9d61910

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

packages/shared/core/styled-engine/emotion.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,36 @@ export const withTheme = Component => {
2424
return SafeWithTheme
2525
}
2626

27-
const css = (parts, ...args) => props => {
28-
if (!props) {
29-
throw new Error('Wrong usage of `css` function')
30-
}
27+
const css = (parts, ...args) => {
28+
if (
29+
typeof parts === 'function' ||
30+
args.some(arg => typeof arg === 'function')
31+
) {
32+
return props => {
33+
if (!props) {
34+
throw new Error('Wrong usage of `css` function')
35+
}
3136

32-
const transform = arg => {
33-
if (typeof arg === 'function') {
34-
return transform(arg(props))
35-
}
37+
const transform = arg => {
38+
if (typeof arg === 'function') {
39+
return transform(arg(props))
40+
}
3641

37-
if (Array.isArray(arg)) {
38-
return arg.map(transform)
39-
}
42+
if (Array.isArray(arg)) {
43+
return arg.map(transform)
44+
}
4045

41-
return arg
46+
return arg
47+
}
48+
49+
const transformedArgs = transform(args)
50+
const transformedParts =
51+
typeof parts === 'function' ? transform(parts) : parts
52+
return emotionCss(transformedParts, ...transformedArgs)
53+
}
4254
}
4355

44-
const transformedArgs = transform(args)
45-
return emotionCss(parts, ...transformedArgs)
56+
return emotionCss(parts, ...args)
4657
}
4758

4859
function patchStyledComponent(StyledComponent) {

0 commit comments

Comments
 (0)