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 #418 from gluestack/release/@gluestack-style/react…
Browse files Browse the repository at this point in the history
…@0.2.42

Release/@gluestack style/[email protected]
  • Loading branch information
ankit-tailor authored Sep 13, 2023
2 parents 2f3012e + a87d940 commit 118aba4
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 44 deletions.
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@gluestack-style/react",
"description": "A universal & performant styling library for React Native, Next.js & React",
"version": "0.2.41",
"version": "0.2.42",
"keywords": [
"React Native",
"Next.js",
Expand Down
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
2 changes: 1 addition & 1 deletion packages/react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export type GlobalStyles<AliasTypes, TokenTypes, Variants> = GlobalVariantSx<
AliasTypes,
TokenTypes
>;
compundVariants?: readonly GlobalCompoundVariant<
compoundVariants?: readonly GlobalCompoundVariant<
'variants' extends keyof Variants ? Variants['variants'] : unknown,
AliasTypes,
TokenTypes
Expand Down

0 comments on commit 118aba4

Please sign in to comment.