diff --git a/src/with-styled-props.ts b/src/with-styled-props.ts index 13c5d98..51e66a3 100644 --- a/src/with-styled-props.ts +++ b/src/with-styled-props.ts @@ -34,27 +34,41 @@ export function withStyledProps({ const styledProps: Partial> = {}; - if (spreadProps.length > 0 || cssProps.length > 0) { - for (const prop of [...spreadProps, ...cssProps]) { - const value = componentProps[prop]; + for (const prop of cssProps) { + const value = componentProps[prop]; - if (typeof value === "string") { - if (preview) { + if (typeof value === "string") { + if (preview) { + styledProps[prop] = undefined; + (mainStyles as unknown as Record)[prop] = tw(value, { + flatten: false, + }); + } else { + const entries = Object.entries(tw(value, { flatten: true })); + if (entries.length > 0) { styledProps[prop] = undefined; - mainStyles.push(...tw(value, { flatten: false })); - } else { - const entries = Object.entries(tw(value, { flatten: true })); - if (entries.length > 0) { - styledProps[prop] = undefined; - for (const [key, value] of entries) { - styledProps[key as T] = value; - } + for (const [key, value] of entries) { + styledProps[key as T] = value; } } } } } + for (const prop of spreadProps) { + const value = componentProps[prop]; + + if (typeof value === "string") { + const entries = Object.entries(tw(value, { flatten: true })); + if (entries.length > 0) { + styledProps[prop] = undefined; + for (const [key, value] of entries) { + styledProps[key as T] = value; + } + } + } + } + if (propsToTransform) { for (const prop of propsToTransform) { const value = componentProps[prop]; @@ -67,7 +81,9 @@ export function withStyledProps({ const style = styleProp ? [mainStyles, styleProp] - : mainStyles.length > 0 + : Array.isArray(mainStyles) && mainStyles.length > 0 + ? mainStyles + : "$$css" in mainStyles ? mainStyles : undefined;