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

Release/@gluestack style/[email protected]
  • Loading branch information
ankit-tailor authored Oct 30, 2023
2 parents 0f16922 + 07d31d3 commit ecb6ebe
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 11 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": "1.0.8",
"version": "1.0.9-alpha.8",
"keywords": [
"React Native",
"Next.js",
Expand Down
19 changes: 14 additions & 5 deletions packages/react/src/Theme.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { View } from 'react-native';
import * as React from 'react';
import { styled } from './styled';
type Config = any;

export const defaultConfig: { theme?: string } = {
Expand All @@ -8,11 +9,17 @@ export const defaultConfig: { theme?: string } = {

const defaultContextData: Config = defaultConfig;
const ThemeContext = React.createContext<Config>(defaultContextData);
// Can be discussed should we provide flex 1 by default or not.
const StyledView = styled(
View,
{
// flex: 1
},
{ componentName: 'GluestackThemeView' }
);

export const Theme: React.FC<{
children?: React.ReactNode;
name?: any;
}> = ({ name, children }) => {
// @ts-ignore
export const Theme: typeof StyledView = ({ children, name, ...props }) => {
const contextValue = React.useMemo(() => {
return {
theme: name,
Expand All @@ -22,7 +29,9 @@ export const Theme: React.FC<{
return (
<ThemeContext.Provider value={contextValue}>
{/* @ts-ignore */}
<View dataSet={{ 'theme-id': name }}>{children}</View>
<StyledView dataSet={{ 'theme-id': name }} {...props}>
{children}
</StyledView>
</ThemeContext.Provider>
);
};
Expand Down
13 changes: 12 additions & 1 deletion packages/react/src/generateStylePropsFromCSSIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export function generateStylePropsFromCSSIds(
props: any,
styleCSSIds: any,
config: any,
activeTheme: any
activeTheme: any,
componentConfig: any
) {
const propsStyles = Array.isArray(props?.style)
? props?.style
Expand Down Expand Up @@ -178,5 +179,15 @@ export function generateStylePropsFromCSSIds(
// DONOT REMOVE THIS LINE, THIS IS FOR SPECIFIC COMPONENTS LIKE next/link
'data-style': getDataStyle(props, styleCSSIdsString),
});

if (Platform.OS === 'web') {
Object.assign(props, {
dataSet: {
...props?.dataSet,
componentConfig: JSON.stringify(componentConfig),
},
});
}

return props;
}
55 changes: 51 additions & 4 deletions packages/react/src/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -785,10 +785,13 @@ const getStyleIdsFromMap = (
styleIds: any
) => {
let componentExtendedConfig = CONFIG;

if (ExtendedConfig) {
componentExtendedConfig = deepMerge(CONFIG, ExtendedConfig);
componentExtendedConfig = deepMergeObjects(CONFIG, ExtendedConfig);
}

Object.assign(styledSystemProps, componentExtendedConfig?.aliases);

const componentStyleIds = styleIds.component;
const componentDescendantStyleIds = styleIds.descendant;

Expand Down Expand Up @@ -1022,6 +1025,7 @@ export function verboseStyled<P, Variants, ComCon>(
const applySxDescendantStyleCSSIdsAndPropsWithKey = useRef({});

const styledContext = useStyled();

const { theme: activeTheme } = useTheme();

const ancestorStyleContext = useContext(AncestorStyleContext);
Expand All @@ -1041,6 +1045,7 @@ export function verboseStyled<P, Variants, ComCon>(
...styledContext.config,
propertyTokenMap,
};

// for extended components

const EXTENDED_THEME =
Expand Down Expand Up @@ -1107,7 +1112,14 @@ export function verboseStyled<P, Variants, ComCon>(
// @ts-ignore
[nonVerbosedTheme, , , Component] = plugins[
pluginName
]?.inputMiddleWare<P>(nonVerbosedTheme, true, true, Component);
]?.inputMiddleWare<P>(
nonVerbosedTheme,
true,
true,
Component,
componentStyleConfig,
ExtendedConfig
);
}
nonVerbosedTheme = convertStyledToStyledVerbosed(nonVerbosedTheme);
}
Expand Down Expand Up @@ -1893,11 +1905,31 @@ export function verboseStyled<P, Variants, ComCon>(

// Object.assign(resolvedInlineProps, applyComponentInlineProps);

const componentConfig = {
componentName: componentStyleConfig?.componentName,
colorMode: styledContext.colorMode,
...variantProps,
states,
};

//@ts-ignore
if (applyComponentInlineProps?.as || passingProps?.as?.displayName) {
componentConfig.componentName =
//@ts-ignore
applyComponentInlineProps?.as?.displayName ??
passingProps?.as?.displayName;
componentConfig.as =
//@ts-ignore
applyComponentInlineProps?.as?.displayName ??
passingProps?.as?.displayName;
}

const resolvedStyleProps = generateStylePropsFromCSSIds(
applyComponentInlineProps,
styleCSSIds,
CONFIG,
activeTheme
activeTheme,
componentConfig
);

const AsComp: any =
Expand Down Expand Up @@ -1939,6 +1971,7 @@ export function verboseStyled<P, Variants, ComCon>(
plugins?.length > 0
? {
...variantProps,
states: states,
sx: componentProps.sx,
}
: {};
Expand All @@ -1949,7 +1982,9 @@ export function verboseStyled<P, Variants, ComCon>(
component = (
<ComponentWithPlugin
{...resolvedStyleProps}
{...variantProps}
{...propsToBePassedInToPlugin}
states={states}
style={resolvedStyleMemo}
as={AsComp}
ref={ref}
Expand All @@ -1965,7 +2000,19 @@ export function verboseStyled<P, Variants, ComCon>(
);
}
} else {
component = (
//@ts-ignores
component = Component.isStyledComponent ? (
<ComponentWithPlugin
{...resolvedStyleProps}
{...propsToBePassedInToPlugin}
{...variantProps}
states={states}
style={resolvedStyleMemo}
ref={ref}
>
{children}
</ComponentWithPlugin>
) : (
<ComponentWithPlugin
{...resolvedStyleProps}
{...propsToBePassedInToPlugin}
Expand Down

0 comments on commit ecb6ebe

Please sign in to comment.