Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #417 from gluestack/fix/passing-resolved-inline-props
Browse files Browse the repository at this point in the history
fix: passing resolved inline props
  • Loading branch information
ankit-tailor authored Sep 13, 2023
2 parents ba7a29d + b545cce commit 5211229
Showing 1 changed file with 69 additions and 42 deletions.
111 changes: 69 additions & 42 deletions packages/react/src/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,57 @@ export function getVariantProps(
};
}

function resolveInlineProps(
componentStyleConfig: any,
componentExtendedConfig: any,
props: any,
CONFIG: any
) {
let resolvedInlineProps = {};
if (
componentStyleConfig.resolveProps &&
Object.keys(componentExtendedConfig).length > 0
) {
componentStyleConfig.resolveProps.forEach((toBeResovledProp: any) => {
if (props[toBeResovledProp]) {
let value = props[toBeResovledProp];
if (
CONFIG.propertyResolver &&
CONFIG.propertyResolver.props &&
CONFIG.propertyResolver.props[toBeResovledProp]
) {
let transformer = CONFIG.propertyResolver.props[toBeResovledProp];
let aliasTokenType = CONFIG.propertyTokenMap[toBeResovledProp];
let token = transformer(
value,
(value1: any, scale = aliasTokenType) =>
resolveStringToken(
value1,
CONFIG,
CONFIG.propertyTokenMap,
toBeResovledProp,
scale
)
);
//@ts-ignore
resolvedInlineProps[toBeResovledProp] = token;
} else {
//@ts-ignore
resolvedInlineProps[toBeResovledProp] =
getResolvedTokenValueFromConfig(
componentExtendedConfig,
props,
toBeResovledProp,
props[toBeResovledProp]
);
}
delete props[toBeResovledProp];
}
});
}
return resolvedInlineProps;
}

const getStyleIdsFromMap = (
CONFIG: any,
ExtendedConfig: any,
Expand Down Expand Up @@ -1253,48 +1304,12 @@ export function verboseStyled<P, Variants, ComCon>(
// 520ms

// Inline prop based style resolution TODO: Diagram insertion
const resolvedInlineProps = {};
if (
componentStyleConfig.resolveProps &&
Object.keys(componentExtendedConfig).length > 0
) {
componentStyleConfig.resolveProps.forEach((toBeResovledProp: any) => {
if (componentPropsWithoutVariants[toBeResovledProp]) {
let value = componentPropsWithoutVariants[toBeResovledProp];
if (
CONFIG.propertyResolver &&
CONFIG.propertyResolver.props &&
CONFIG.propertyResolver.props[toBeResovledProp]
) {
let transformer = CONFIG.propertyResolver.props[toBeResovledProp];
let aliasTokenType = CONFIG.propertyTokenMap[toBeResovledProp];
let token = transformer(
value,
(value1: any, scale = aliasTokenType) =>
resolveStringToken(
value1,
CONFIG,
CONFIG.propertyTokenMap,
toBeResovledProp,
scale
)
);
//@ts-ignore
resolvedInlineProps[toBeResovledProp] = token;
} else {
//@ts-ignore
resolvedInlineProps[toBeResovledProp] =
getResolvedTokenValueFromConfig(
componentExtendedConfig,
componentPropsWithoutVariants,
toBeResovledProp,
componentPropsWithoutVariants[toBeResovledProp]
);
}
delete componentPropsWithoutVariants[toBeResovledProp];
}
});
}
const resolvedInlineProps = resolveInlineProps(
componentStyleConfig,
componentExtendedConfig,
componentPropsWithoutVariants,
CONFIG
);

const passingProps = deepMergeObjects(
applyComponentPassingProps,
Expand All @@ -1319,6 +1334,7 @@ export function verboseStyled<P, Variants, ComCon>(

let containsSX = false;
Object.assign(applyComponentInlineProps, filteredPassingRemainingProps);
Object.assign(applyComponentInlineProps, resolvedInlineProps);
Object.assign(applyComponentInlineProps, filteredComponentRemainingProps);

if (
Expand Down Expand Up @@ -1524,11 +1540,22 @@ export function verboseStyled<P, Variants, ComCon>(

injectAndUpdateSXProps(filteredPassingSx);

const resolvedPassingRemainingProps = resolveInlineProps(
componentStyleConfig,
componentExtendedConfig,
filteredPassingRemainingPropsUpdated,
CONFIG
);

Object.assign(
applyComponentInlineProps,
filteredPassingRemainingPropsUpdated
);

Object.assign(applyComponentInlineProps, resolvedPassingRemainingProps);

Object.assign(applyComponentInlineProps, resolvedInlineProps);

Object.assign(
applyComponentInlineProps,
filteredComponentRemainingProps
Expand Down

0 comments on commit 5211229

Please sign in to comment.