mirror of
https://github.com/zhigang1992/nativewind.git
synced 2026-06-16 11:49:47 +08:00
fix: cssProps working in preview mode
This commit is contained in:
@@ -34,27 +34,41 @@ export function withStyledProps<S, T extends string>({
|
|||||||
|
|
||||||
const styledProps: Partial<Record<T, unknown>> = {};
|
const styledProps: Partial<Record<T, unknown>> = {};
|
||||||
|
|
||||||
if (spreadProps.length > 0 || cssProps.length > 0) {
|
for (const prop of cssProps) {
|
||||||
for (const prop of [...spreadProps, ...cssProps]) {
|
const value = componentProps[prop];
|
||||||
const value = componentProps[prop];
|
|
||||||
|
|
||||||
if (typeof value === "string") {
|
if (typeof value === "string") {
|
||||||
if (preview) {
|
if (preview) {
|
||||||
|
styledProps[prop] = undefined;
|
||||||
|
(mainStyles as unknown as Record<string, unknown>)[prop] = tw(value, {
|
||||||
|
flatten: false,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const entries = Object.entries(tw(value, { flatten: true }));
|
||||||
|
if (entries.length > 0) {
|
||||||
styledProps[prop] = undefined;
|
styledProps[prop] = undefined;
|
||||||
mainStyles.push(...tw(value, { flatten: false }));
|
for (const [key, value] of entries) {
|
||||||
} else {
|
styledProps[key as T] = value;
|
||||||
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 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) {
|
if (propsToTransform) {
|
||||||
for (const prop of propsToTransform) {
|
for (const prop of propsToTransform) {
|
||||||
const value = componentProps[prop];
|
const value = componentProps[prop];
|
||||||
@@ -67,7 +81,9 @@ export function withStyledProps<S, T extends string>({
|
|||||||
|
|
||||||
const style = styleProp
|
const style = styleProp
|
||||||
? [mainStyles, styleProp]
|
? [mainStyles, styleProp]
|
||||||
: mainStyles.length > 0
|
: Array.isArray(mainStyles) && mainStyles.length > 0
|
||||||
|
? mainStyles
|
||||||
|
: "$$css" in mainStyles
|
||||||
? mainStyles
|
? mainStyles
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user