Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Add support for a custom ThemeProvider component #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/ThemesProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Theme } from "./types/Theme";
export interface ThemesProviderProps {
themes: List<Theme>;
cb?: (theme: Theme) => void;
CustomThemeProvider?: React.ComponentType<{ theme: Theme }>;
}

interface ThemesProviderState {
Expand All @@ -21,10 +22,10 @@ interface ThemesProviderHandler {

type BaseComponentProps = ThemesProviderProps & ThemesProviderState & ThemesProviderHandler;

const BaseComponent: React.SFC<BaseComponentProps> = ({ theme, children }) => (
<ThemeProvider theme={theme}>
const BaseComponent: React.SFC<BaseComponentProps> = ({ theme, children, CustomThemeProvider = ThemeProvider }) => (
<CustomThemeProvider theme={theme}>
{children}
</ThemeProvider>
</CustomThemeProvider>
);

export const ThemesProvider = compose<BaseComponentProps, ThemesProviderProps>(
Expand Down
4 changes: 2 additions & 2 deletions src/withThemesProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { ThemesProvider } from "./ThemesProvider";

import { Theme } from "./types/Theme";

export const withThemesProvider = (themes: Theme[], cb?: (theme: Theme) => void) => (story): JSX.Element => {
return <ThemesProvider themes={List(themes)} cb={cb}>{story()}</ThemesProvider>;
export const withThemesProvider = (themes: Theme[], cb?: (theme: Theme) => void, CustomThemeProvider?: React.ComponentType<{ theme: Theme }>) => (story): JSX.Element => {
return <ThemesProvider themes={List(themes)} cb={cb} CustomThemeProvider={CustomThemeProvider}>{story()}</ThemesProvider>;
};