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

Commit

Permalink
fix: remove extra hoc from plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
ankit-tailor committed Oct 11, 2023
1 parent 00d8b02 commit b3e8c23
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 57 deletions.
30 changes: 15 additions & 15 deletions packages/react/src/createConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ import { Platform } from 'react-native';

/********************* PLUGINS *****************************/

var globalPluginStore: never[] = [];
function setGlobalPluginStore(plugins: any) {
if (plugins) {
// @ts-ignore
globalPluginStore.push(...plugins);
}
return getGlobalPluginStore();
}
function getGlobalPluginStore() {
return globalPluginStore;
}
// var globalPluginStore: never[] = [];
// function setGlobalPluginStore(plugins: any) {
// if (plugins) {
// // @ts-ignore
// globalPluginStore.push(...plugins);
// }
// return getGlobalPluginStore();
// }
// function getGlobalPluginStore() {
// return globalPluginStore;
// }

export function getInstalledPlugins() {
return getGlobalPluginStore();
}
// export function getInstalledPlugins() {
// return getGlobalPluginStore();
// }

/********************* CREATE COMPONENTS *****************************/

Expand Down Expand Up @@ -74,7 +74,7 @@ export const createConfig = <
>
): T => {
if (config.plugins) {
config.plugins = setGlobalPluginStore(config.plugins);
// config.plugins = setGlobalPluginStore(config.plugins);
}
// delete config.plugins;

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ export { createStyle } from './createStyle';
export { INTERNAL_updateCSSStyleInOrderedResolved } from './updateCSSStyleInOrderedResolved';
export {
createConfig,
getInstalledPlugins,
// getInstalledPlugins,
createComponents,
getInstalledComponents,
// getInstalledComponents,
} from './createConfig';
export * from './core';
export * from './hooks';
39 changes: 16 additions & 23 deletions packages/react/src/plugins/font-resolver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useMemo } from 'react';
import type { IStyled, IStyledPlugin } from '../types';
import { useStyled } from '../StyledProvider';
import { propertyTokenMap } from '../propertyTokenMap';
import { deepMerge, deepMergeObjects, setObjectKeyValue } from '../utils';
import { deepMerge, setObjectKeyValue } from '../utils';
import { getVariantProps } from '../styled';

const fontWeights: any = {
Expand Down Expand Up @@ -218,11 +218,11 @@ export class FontResolver implements IStyledPlugin, FontPlugin {
return styledObject;
}

componentMiddleWare({ Component: NewComp, extendedConfig }: any) {
componentMiddleWare({ Component: InputComponent, extendedConfig }: any) {
const styledConfig = this.#fontFamily;
this.#fontFamily = {};

const Comp = React.forwardRef((props: any, ref: any) => {
const OutputComponent = React.forwardRef((props: any, ref: any) => {
const styledContext = useStyled();
const CONFIG = useMemo(
() => ({
Expand All @@ -249,12 +249,9 @@ export class FontResolver implements IStyledPlugin, FontPlugin {
variantProps,
styledConfig
);
let componentStyledObject = deepMergeObjects(
styledConfig,
variantStyledObject
);
let componentStyledObject = deepMerge(styledConfig, variantStyledObject);

delete componentStyledObject.variants;
// delete componentStyledObject.variants;

const { sx, fontWeight, fontFamily, fontStyle, ...rest } = restProps;

Expand All @@ -279,35 +276,31 @@ export class FontResolver implements IStyledPlugin, FontPlugin {
sxPropsWithThemeProps,
false,
false,
NewComp
() => <></>
);

const styles = Array.isArray(rest.style)
? [...rest?.style, resolvedSxProps]
: resolvedSxProps;

return <NewComp {...rest} style={styles} ref={ref} />;
return <InputComponent {...rest} sx={resolvedSxProps} ref={ref} />;
});

//@ts-ignore
Comp.styled = {};
OutputComponent.styled = {};
//@ts-ignore
Comp.styled.config = {};
OutputComponent.styled.config = {};
//@ts-ignore
Comp.styled.config = {
OutputComponent.styled.config = {
...styledConfig?.config,
...NewComp?.styled?.config,
...InputComponent?.styled?.config,
};

//@ts-ignore
Comp.isStyledComponent = NewComp?.isStyledComponent;
OutputComponent.isStyledComponent = InputComponent?.isStyledComponent;
//@ts-ignore
Comp.isComposedComponent = NewComp?.isComposedComponent;
OutputComponent.isComposedComponent = InputComponent?.isComposedComponent;
//@ts-ignore
Comp.isAnimatedComponent = NewComp?.isAnimatedComponent;
OutputComponent.isAnimatedComponent = InputComponent?.isAnimatedComponent;

Comp.displayName = NewComp?.displayName;
OutputComponent.displayName = InputComponent?.displayName;

return Comp;
return OutputComponent;
}
}
37 changes: 20 additions & 17 deletions packages/react/src/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1887,23 +1887,26 @@ export function verboseStyled<P, Variants, ComCon>(

// }

if (plugins) {
for (const pluginName in plugins) {
// @ts-ignore
if (plugins[pluginName]?.componentMiddleWare) {
const ComponentWithPlugin = React.useMemo(() => {
if (plugins) {
for (const pluginName in plugins) {
// @ts-ignore
Component = plugins[pluginName]?.componentMiddleWare({
Component: Component,
theme,
componentStyleConfig,
ExtendedConfig,
});
if (plugins[pluginName]?.componentMiddleWare) {
// @ts-ignore
Component = plugins[pluginName]?.componentMiddleWare({
Component: Component,
theme,
componentStyleConfig,
ExtendedConfig,
});

//@ts-ignore
pluginData = { ...pluginData, ...Component?.styled };
//@ts-ignore
pluginData = { ...pluginData, ...Component?.styled };
}
}
}
}
return Component;
}, []);

let component;

Expand All @@ -1919,15 +1922,15 @@ export function verboseStyled<P, Variants, ComCon>(
//@ts-ignore
if (Component.isStyledComponent) {
component = (
<Component
<ComponentWithPlugin
{...resolvedStyleProps}
{...propsToBePassedInToPlugin}
style={resolvedStyleMemo}
as={AsComp}
ref={ref}
>
{children}
</Component>
</ComponentWithPlugin>
);
} else {
component = (
Expand All @@ -1938,14 +1941,14 @@ export function verboseStyled<P, Variants, ComCon>(
}
} else {
component = (
<Component
<ComponentWithPlugin
{...resolvedStyleProps}
{...propsToBePassedInToPlugin}
style={resolvedStyleMemo}
ref={ref}
>
{children}
</Component>
</ComponentWithPlugin>
);
}

Expand Down

0 comments on commit b3e8c23

Please sign in to comment.