diff --git a/example/babel-plugin-styled-resolver-expo/package.json b/example/babel-plugin-styled-resolver-expo/package.json
index 9b40740dd..fc9ab0794 100644
--- a/example/babel-plugin-styled-resolver-expo/package.json
+++ b/example/babel-plugin-styled-resolver-expo/package.json
@@ -11,7 +11,7 @@
"build": "bob build"
},
"dependencies": {
- "@gluestack-style/react": "^0.1.31",
+ "@gluestack-style/react": "^0.1.32",
"expo": "~47.0.8",
"expo-status-bar": "~1.4.2",
"find-yarn-workspace-root": "^2.0.0"
@@ -27,10 +27,10 @@
"babel-plugin-relative-path-import": "^2.0.1",
"ts-loader": "~8.2.0",
"typescript": "^4.6.3",
- "@gluestack-style/react": "^0.1.31"
+ "@gluestack-style/react": "^0.1.32"
},
"peerDependencies": {
- "@gluestack-style/react": "^0.1.31",
+ "@gluestack-style/react": "^0.1.32",
"react": "*",
"react-dom": "*",
"react-native": "*",
diff --git a/example/expo-app/package.json b/example/expo-app/package.json
index be9c32693..b667257e4 100644
--- a/example/expo-app/package.json
+++ b/example/expo-app/package.json
@@ -11,7 +11,7 @@
},
"dependencies": {
"@gluestack-style/babel-plugin-styled-resolver": "^0.1.0",
- "@gluestack-style/react": "^0.1.31",
+ "@gluestack-style/react": "^0.1.32",
"expo": "~47.0.12",
"expo-status-bar": "~1.4.2",
"react": "18.1.0",
diff --git a/example/next/package.json b/example/next/package.json
index 459cc5996..d3f59ce23 100644
--- a/example/next/package.json
+++ b/example/next/package.json
@@ -23,7 +23,7 @@
"react-native-vector-icons": "^9.1.0",
"react-native-vector-icons-for-web": "^0.1.7",
"react-native-web-linear-gradient": "^1.1.2",
- "@gluestack-style/react": "^0.1.31",
+ "@gluestack-style/react": "^0.1.32",
"@gluestack-style/babel-plugin-styled-resolver": "^0.1.6"
},
"devDependencies": {
diff --git a/example/storybook/.ondevice/storybook.requires.js b/example/storybook/.ondevice/storybook.requires.js
index c79696d4a..290779a98 100644
--- a/example/storybook/.ondevice/storybook.requires.js
+++ b/example/storybook/.ondevice/storybook.requires.js
@@ -53,7 +53,7 @@ const getStories = () => {
// require('../src/recipes/ButtonStateProps/ButtonStateProps.stories.tsx'),
// require('../src/recipes/ButtonVariant/ButtonVariant.stories.tsx'),
// require('../src/api/ColorModeBasedStyles/ColorMode.stories.tsx'),
- // require('../src/recipes/Descendants/Descendants.stories.tsx'),
+ require('../src/api/DescendantsStyles/ContextBasedStyles.stories.tsx'),
// require('../src/recipes/Icons/Icons.stories.tsx'),
// require('../src/recipes/LinearGradient/LinearGradient.stories.tsx'),
// require('../src/recipes/MediaQuery/MediaQuery.stories.tsx'),
diff --git a/example/storybook/.storybook/main.js b/example/storybook/.storybook/main.js
index 859108a5a..dd8281365 100644
--- a/example/storybook/.storybook/main.js
+++ b/example/storybook/.storybook/main.js
@@ -31,6 +31,8 @@ module.exports = {
include: [
// path.resolve('../../', 'node_modules/@universa11y'),
path.resolve('../../', 'node_modules/@gluestack-ui'),
+ path.resolve('./', 'node_modules/@gluestack-ui'),
+
path.resolve('../../', 'node_modules/@gluestack/design-system'),
path.resolve(
'../../',
diff --git a/example/storybook/package.json b/example/storybook/package.json
index 2bc2222fb..567f35327 100644
--- a/example/storybook/package.json
+++ b/example/storybook/package.json
@@ -20,7 +20,7 @@
},
"dependencies": {
"@gluestack-style/animation-plugin": "^0.1.7",
- "@gluestack-style/react": "^0.1.31",
+ "@gluestack-style/react": "^0.1.32",
"@gluestack/design-system": "latest",
"@legendapp/motion": "^2.2.0",
"@react-native-async-storage/async-storage": "~1.17.3",
@@ -43,7 +43,7 @@
"devDependencies": {
"@babel/core": "^7.19.3",
"@gluestack-style/animation-plugin": "^0.1.7",
- "@gluestack-style/react": "^0.1.31",
+ "@gluestack-style/react": "^0.1.32",
"@storybook/addon-actions": "^6.5.14",
"@storybook/addon-controls": "^6.5.14",
"@storybook/addon-docs": "^6.5.15",
@@ -69,7 +69,7 @@
"typescript": "4.9.4"
},
"peerDependencies": {
- "@gluestack-style/react": "^0.1.31",
+ "@gluestack-style/react": "^0.1.32",
"react": "*",
"react-dom": "*",
"react-native": "*",
diff --git a/example/storybook/src/api/DescendantsStyles/ContextBasedStyles.tsx b/example/storybook/src/api/DescendantsStyles/ContextBasedStyles.tsx
index 3365f1fe2..b636e7dc8 100644
--- a/example/storybook/src/api/DescendantsStyles/ContextBasedStyles.tsx
+++ b/example/storybook/src/api/DescendantsStyles/ContextBasedStyles.tsx
@@ -3,14 +3,15 @@ import React from 'react';
import { Pressable, Text } from 'react-native';
import { AsForwarder, styled } from '@gluestack-style/react';
import { Wrapper } from '../../components/Wrapper';
-import { AddIcon } from '@gluestack/design-system';
+// import { AddIcon } from '@gluestack/design-system';
+import { createIcon } from '@gluestack-ui/icon';
+import { Svg } from 'react-native-svg';
const StyledButton = styled(
Pressable,
{
backgroundColor: '$primary500',
p: '$2',
-
_icon: {
props: {
color: '$blue500',
@@ -23,19 +24,53 @@ const StyledButton = styled(
);
const StyledIcon = styled(
- AsForwarder,
- {},
+ Text,
+ {
+ color: 'red',
+ },
{
ancestorStyle: ['_icon'],
- DEBUG: 'FORWARDER ICON',
+ DEBUG: 'STYLED_ICON',
+ }
+);
+
+const MyText = styled(
+ StyledIcon,
+ {
+ props: {
+ color: '$white',
+ },
+ },
+ {
+ // ancestorStyle: ['_icon'],
+ DEBUG: 'MYTEXT',
}
);
+// const StyledIcon = styled(
+// AsForwarder,
+// {},
+// {
+// ancestorStyle: ['_icon'],
+// DEBUG: 'FORWARDER ICON',
+// }
+// );
+
+// const AddIcon = createIcon({
+// Root: StyledIcon,
+// viewBox: '0 0 24 24',
+// d: 'M13.25 10.75V2H10.75V10.75H2V13.25H10.75V22H13.25V13.25H22V10.75H13.25Z',
+// });
+
+// AddIcon.displayName = 'AddIcon';
export function ContextBasedStyles() {
return (
( function injectComponentAndDescendantStyles( orderedResolved: OrderedSXResolved, styleTagId?: string, - type: 'boot' | 'inline' = 'boot' + type: 'boot' | 'inline' | 'passing' = 'boot' ) { // const componentOrderResolved = getComponentResolved(orderedResolved); // const descendantOrderResolved = getDescendantResolved(orderedResolved); @@ -548,7 +574,7 @@ export function verboseStyled
( // BASE COLOR MODE RESOLUTION - function setColorModeBaseStyleIdsForWeb(styleIds: any, COLOR_MODE: any) { + function setColorModeBaseStyleIds(styleIds: any, COLOR_MODE: any) { if (COLOR_MODE) { if ( styleIds?.baseStyle?.colorMode && @@ -562,10 +588,7 @@ export function verboseStyled
( } } - function setColorModeBaseStyleIdsDescendantForWeb( - styleIds: any, - COLOR_MODE: any - ) { + function setColorModeBaseStyleIdsDescendant(styleIds: any, COLOR_MODE: any) { if (COLOR_MODE) { Object.keys(styleIds).forEach((descendantKey) => { if ( @@ -581,12 +604,41 @@ export function verboseStyled
( } } + function injectSx(sx: any, type: any = 'inline') { + const inlineSxTheme = { + baseStyle: sx, + }; + + resolvePlatformTheme(inlineSxTheme, Platform.OS); + const sxStyledResolved = styledToStyledResolved( + // @ts-ignore + inlineSxTheme, + [], + componentExtendedConfig + ); + + const sxHash = stableHash(sx); + const orderedSXResolved = + styledResolvedToOrderedSXResolved(sxStyledResolved); + + INTERNAL_updateCSSStyleInOrderedResolved( + orderedSXResolved, + sxHash, + false, + 'gs' + ); + + injectComponentAndDescendantStyles(orderedSXResolved, sxHash, type); + + return orderedSXResolved; + } + // END BASE COLOR MODE RESOLUTION const NewComp = ( { as, - ...properties + ...componentProps }: Omit
&
Partial (
componentStyleIds = styleIds.component;
componentDescendantStyleIds = styleIds.descendant;
- setColorModeBaseStyleIdsForWeb(componentStyleIds, COLOR_MODE);
- setColorModeBaseStyleIdsDescendantForWeb(
+ setColorModeBaseStyleIds(componentStyleIds, COLOR_MODE);
+ setColorModeBaseStyleIdsDescendant(
componentDescendantStyleIds,
COLOR_MODE
);
@@ -689,16 +741,18 @@ export function verboseStyled (
const incomingComponentProps = useMemo(() => {
return {
- //@ts-ignore
- // ...theme?.baseStyle?.props,
...applyAncestorPassingProps, // As applyAncestorPassingProps is incoming props for the descendant component
- ...properties,
+ ...componentProps,
};
- }, [properties, applyAncestorPassingProps]);
+ }, [componentProps, applyAncestorPassingProps]);
const { variantProps } = getVariantProps(
- //@ts-ignore
- { ...theme?.baseStyle?.props, ...incomingComponentProps },
+ {
+ //@ts-ignore
+ ...theme?.baseStyle?.props,
+ ...applyAncestorPassingProps,
+ ...componentProps,
+ },
theme
);
@@ -742,6 +796,7 @@ export function verboseStyled (
//
//
//
+
//
// passingProps is specific to current component
const passingProps = React.useMemo(() => {
@@ -759,19 +814,53 @@ export function verboseStyled (
componentStatePassingProps,
]);
+ const { sx: filteredComponentSx, rest: filteredComponentRemainingProps } =
+ convertUtiltiyToSXFromProps(
+ componentProps,
+ componentExtendedConfig,
+ componentStyleConfig
+ );
+
+ const { sx: filteredPassingSx, rest: filteredPassingRemainingProps } =
+ convertUtiltiyToSXFromProps(
+ {
+ ...passingProps,
+ ...applyAncestorPassingProps,
+ },
+ componentExtendedConfig,
+ componentStyleConfig
+ );
+
+ // if (componentStyleConfig.DEBUG === 'MYTEXT') {
+ // console.log(
+ // filteredComponentSx,
+ // filteredPassingSx,
+ // // applyAncestorPassingProps,
+ // // applyAncestorBaseStyleCSSIds,
+ // // applyAncestorVariantStyleCSSIds,
+ // componentProps,
+ // '>>>>>'
+ // );
+ // }
+
+ const remainingComponentProps = {
+ ...filteredPassingRemainingProps,
+ ...filteredComponentRemainingProps,
+ };
+
const mergedWithUtilityPropsAndPassingProps = {
- // ...restProps,
...passingProps,
- ...incomingComponentProps,
+ ...applyAncestorPassingProps,
+ ...componentProps,
};
const {
children,
states,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
- colorMode,
- sx: userSX,
- verboseSx,
+ sx: _sx,
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ verboseSx: _versbosedSx,
...utilityAndPassingProps
}: any = mergedWithUtilityPropsAndPassingProps;
@@ -819,17 +908,8 @@ export function verboseStyled (
});
}
+ // const { sx, remainingComponentProps } = filterSx(mergedSx, mergedVerboseSx);
// TODO: filter for inline props like variant and sizes
- const resolvedSXVerbosed = convertSxToSxVerbosed(userSX);
- const { sxProps: utilityResolvedSX, mergedProps: remainingComponentProps } =
- convertUtilityPropsToSX(
- componentExtendedConfig,
- componentStyleConfig?.descendantStyle,
- utilityAndPassingProps
- );
-
- const resolvedSxVerbose = deepMerge(utilityResolvedSX, resolvedSXVerbosed);
- const sx = deepMerge(resolvedSxVerbose, verboseSx);
const [
applyComponentStateBaseStyleIds,
@@ -864,31 +944,20 @@ export function verboseStyled (
// FOR SX RESOLUTION
- if (Object.keys(sx).length > 0) {
- const inlineSxTheme = {
- baseStyle: sx,
- };
-
- resolvePlatformTheme(inlineSxTheme, Platform.OS);
- const sxStyledResolved = styledToStyledResolved(
- // @ts-ignore
- inlineSxTheme,
- [],
- componentExtendedConfig
- );
-
- const sxHash = stableHash(sx);
- const orderedSXResolved =
- styledResolvedToOrderedSXResolved(sxStyledResolved);
-
- INTERNAL_updateCSSStyleInOrderedResolved(
- orderedSXResolved,
- sxHash,
- false,
- 'gs'
+ if (
+ Object.keys(filteredComponentSx).length > 0 ||
+ Object.keys(filteredPassingSx).length > 0
+ ) {
+ const orderedComponentSXResolved = injectSx(
+ filteredComponentSx,
+ 'inline'
);
- injectComponentAndDescendantStyles(orderedSXResolved, sxHash, 'inline');
+ const orderedPassingSXResolved = injectSx(filteredPassingSx, 'passing');
+ const orderedSXResolved = [
+ ...orderedPassingSXResolved,
+ ...orderedComponentSXResolved,
+ ];
const sxStyleIds = getStyleIds(orderedSXResolved, componentStyleConfig);
@@ -899,14 +968,11 @@ export function verboseStyled (
sxStyleIds.component.compoundVariants =
componentStyleIds.compoundVariants;
- setColorModeBaseStyleIdsForWeb(sxStyleIds.component, COLOR_MODE);
- setColorModeBaseStyleIdsDescendantForWeb(
- sxStyleIds.descendant,
- COLOR_MODE
- );
+ setColorModeBaseStyleIds(sxStyleIds.component, COLOR_MODE);
+ setColorModeBaseStyleIdsDescendant(sxStyleIds.descendant, COLOR_MODE);
- // setColorModeBaseStyleIdsForWeb(sxStyleIds.component, COLOR_MODE);
- // setColorModeBaseStyleIdsForWeb(sxStyleIds.descendant, COLOR_MODE);
+ // setColorModeBaseStyleIds(sxStyleIds.component, COLOR_MODE);
+ // setColorModeBaseStyleIds(sxStyleIds.descendant, COLOR_MODE);
sxComponentStyleIds.current = sxStyleIds.component;
sxDescendantStyleIds.current = sxStyleIds.descendant;
//
@@ -1137,7 +1203,7 @@ export function verboseStyled (
// const remainingComponentPropsWithoutVariants = getRemainingProps
const finalComponentProps = {
- ...passingProps,
+ // ...passingProps,
...resolvedInlineProps,
...resolvedStyleProps,
...remainingComponentProps,
@@ -1145,6 +1211,15 @@ export function verboseStyled (
ref,
};
+ // if (componentStyleConfig.DEBUG === 'MYTEXT') {
+ // console.log(
+ // // finalComponentProps,
+ // passingProps,
+ // componentProps,
+ // 'hello world 22'
+ // );
+ // }
+
const component = !AsComp ? (