1- import { css as emCss } from '@emotion/react'
1+ import { css as emCss , SerializedStyles , Theme } from '@emotion/react'
22import { CSSInterpolation } from '@emotion/serialize'
33import { transform } from '@xstyled/core'
44
@@ -9,15 +9,36 @@ function styleToString(style: any, props: any): any {
99 return style
1010}
1111
12- // @ts -ignore
13- export const css : typeof emCss = (
12+ interface Props {
13+ theme ?: Theme
14+ }
15+
16+ interface CSSInterpolationFn {
17+ ( props : Props ) : CSSInterpolation
18+ }
19+
20+ interface SerializedStylesFn {
21+ ( props : Props ) : SerializedStyles
22+ }
23+
24+ export function css ( fn : CSSInterpolationFn ) : SerializedStylesFn
25+ export function css ( ...args : CSSInterpolation [ ] ) : SerializedStylesFn
26+ export function css (
1427 strings : TemplateStringsArray ,
15- ...rawArgs : Array < CSSInterpolation >
16- ) => {
17- const emCssArgs = emCss ( strings , ...rawArgs )
18- const transformedStyles = transform ( emCssArgs . styles )
19- return ( props : any ) => ( {
20- ...emCssArgs ,
21- styles : styleToString ( transformedStyles , props ) ,
22- } )
28+ ...rawArgs : CSSInterpolation [ ]
29+ ) : SerializedStylesFn
30+ export function css (
31+ strings : TemplateStringsArray | CSSInterpolation | CSSInterpolationFn ,
32+ ...rawArgs : CSSInterpolation [ ]
33+ ) : SerializedStylesFn {
34+ return ( props : Props ) : SerializedStyles => {
35+ const emCssArgs =
36+ typeof strings === 'function'
37+ ? emCss ( strings ( props ) )
38+ : emCss ( strings as TemplateStringsArray , ...rawArgs )
39+ return {
40+ ...emCssArgs ,
41+ styles : styleToString ( transform ( emCssArgs . styles ) , props ) ,
42+ }
43+ }
2344}
0 commit comments