Skip to content

Commit

Permalink
fix(docz-theme-default): config transform function
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jul 11, 2018
1 parent 5bcbc8c commit fdb3118
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
17 changes: 12 additions & 5 deletions packages/docz-theme-default/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,17 @@ webfont.load({
},
})

const transform = ({ mode, ...config }: any) => ({
...config,
prismTheme: (prismThemes as any)[mode],
colors: (modes as any)[mode],
})
const transform = ({ mode, ...config }: any) => {
const selectedMode: any = (modes as any)[mode]

return {
...config,
prismTheme: (prismThemes as any)[mode],
colors: {
...selectedMode,
...config.colors,
},
}
}

export default theme(config, transform)(Theme)
8 changes: 3 additions & 5 deletions packages/docz/src/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,10 @@ export type TransformFn = (config: ThemeConfig) => ThemeConfig
export type ThemeReturn = (WrappedComponent: CT) => CT<ThemeProps>

export function theme(
initialConfig?: ThemeConfig,
initialConfig: ThemeConfig,
transform?: TransformFn
): ThemeReturn {
return WrappedComponent => {
const cfg = initialConfig || {}
const newConfig = transform ? transform(cfg) : cfg

const Theme: CT<ThemeProps> = ({
wrapper: Wrapper = DefaultWrapper,
entries,
Expand All @@ -84,10 +81,11 @@ export function theme(
hashRouter = false,
}) => {
const Router = hashRouter ? HashRouter : BrowserRouter
const newConfig = merge(initialConfig, config)
const value = {
entries,
imports,
config: merge(newConfig, config),
config: transform ? transform(newConfig) : newConfig,
}

return (
Expand Down

0 comments on commit fdb3118

Please sign in to comment.