Skip to content

Commit

Permalink
refactor(theme): ✨ add support for defaultTheme with extend
Browse files Browse the repository at this point in the history
  • Loading branch information
navin-moorthy committed Jul 29, 2021
1 parent 99b0b93 commit c2feed3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/theme/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ export type ExtendableDefaultTheme = PartialDefaultTheme & {

export type RenderlesskitProviderProps = {
children?: React.ReactNode;
theme?: ExtendableDefaultTheme;
theme?: DefaultTheme;
extend?: ExtendableDefaultTheme;
};

export const RenderlesskitProvider = (props: RenderlesskitProviderProps) => {
const { children, theme = defaultTheme } = props;
const { children, theme = defaultTheme, extend } = props;

const finalTheme: DefaultTheme = React.useMemo(
() => mergeExtensions(mergeThemes([theme, cloneDeep(defaultTheme)])),
[theme],
);
let finalTheme = theme;

if (extend) {
finalTheme = mergeExtensions(mergeThemes([extend, cloneDeep(theme)]));
}

return (
<ThemeContext.Provider value={finalTheme}>{children}</ThemeContext.Provider>
Expand Down

0 comments on commit c2feed3

Please sign in to comment.