Skip to content

Commit

Permalink
feat: create style context provider
Browse files Browse the repository at this point in the history
  • Loading branch information
eels committed Oct 28, 2021
1 parent 7d340f3 commit f223ebe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/core/ChicStyleProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import StyleContext from '@src/lib/StyleContext';
import { createElement } from 'react';
import type { ChicStyleProviderProps } from '@types';

export default function ChicStyleProvider({ children, styles }: ChicStyleProviderProps) {
return createElement(StyleContext.Provider, { value: styles }, children);
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ChicStyleProvider from '@src/core/ChicStyleProvider';
import chic from '@src/core/chic';
import create from '@src/core/create';
import extractDynamicStyles from '@src/core/extractDynamicStyles';

export { chic, create, extractDynamicStyles };
export { ChicStyleProvider, chic, create, extractDynamicStyles };
18 changes: 17 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import tags from './tags';
import type { ComponentType, ForwardRefExoticComponent, PropsWithoutRef } from 'react';
import type {
ComponentType,
ForwardRefExoticComponent,
FunctionComponentElement,
PropsWithoutRef,
ProviderProps,
ReactNode,
} from 'react';

export type ExtendableObject<T = any> = { [key: string]: T };

Expand Down Expand Up @@ -50,8 +57,17 @@ export type ChicTagWithAttrsInterface = {
};
};

export type ChicStyleProviderProps = {
children: ReactNode;
styles: CSSModule;
};

export type ChicFactory = ChicFunction & ChicAttrsInterface & ChicTagWithAttrsInterface;

export function ChicStyleProvider(
props: ChicStyleProviderProps,
): FunctionComponentElement<ProviderProps<CSSModule>>;

export const chic: ChicDOMComponents;

export function create(styles?: CSSModule): ChicFactory;
Expand Down

0 comments on commit f223ebe

Please sign in to comment.