diff --git a/packages/docz-theme-default/src/components/shared/Main/index.tsx b/packages/docz-theme-default/src/components/shared/Main/index.tsx index aba968715..5fc400d20 100644 --- a/packages/docz-theme-default/src/components/shared/Main/index.tsx +++ b/packages/docz-theme-default/src/components/shared/Main/index.tsx @@ -2,6 +2,7 @@ import * as React from 'react' import { Component } from 'react' import { injectGlobal } from 'emotion' import styled from 'react-emotion' +import get from 'lodash.get' const Wrapper = styled('div')` display: flex; @@ -23,20 +24,21 @@ const base = (body: any) => export class Main extends Component { public componentDidUpdate(prevProps: MainProps): void { - const { config } = this.props - const prevBody = prevProps.config.styles.body - const body = config.styles.body + const body = this.getBody(this.props) + const prevBody = this.getBody(prevProps) - if (body && prevBody !== body) { - base(config.styles.body) - } + if (body && prevBody !== body) base(body) } public componentDidMount(): void { - base(this.props.config.styles.body) + base(this.getBody(this.props)) } public render(): React.ReactNode { return {this.props.children} } + + private getBody(props: MainProps): any { + return get(props, 'config.themeConfig.styles.body') + } } diff --git a/packages/docz-theme-default/src/components/shared/Sidebar/Link.tsx b/packages/docz-theme-default/src/components/shared/Sidebar/Link.tsx index 9abf7b839..4efef7228 100644 --- a/packages/docz-theme-default/src/components/shared/Sidebar/Link.tsx +++ b/packages/docz-theme-default/src/components/shared/Sidebar/Link.tsx @@ -41,7 +41,7 @@ const Wrapper = styled('div')` ${(p: WrapperProps) => p.active && activeWrapper(p)}; ` -export const linkStyle = (colors: any) => css` +export const linkStyle = ({ colors }: any) => css` position: relative; display: block; margin: 6px 24px; @@ -156,10 +156,10 @@ export class Link extends Component { return ( - {theme => ( + {config => ( { this.$el = node diff --git a/packages/docz-theme-default/src/components/shared/Sidebar/Menu.tsx b/packages/docz-theme-default/src/components/shared/Sidebar/Menu.tsx index 6821dc355..5cc072efc 100644 --- a/packages/docz-theme-default/src/components/shared/Sidebar/Menu.tsx +++ b/packages/docz-theme-default/src/components/shared/Sidebar/Menu.tsx @@ -22,7 +22,7 @@ const List = styled('dl')` ` export const MenuLink = styled('a')` - ${linkStyle}; + ${p => linkStyle(p.theme.docz)}; ` interface IconProps { diff --git a/packages/docz-theme-default/src/components/ui/Pre.tsx b/packages/docz-theme-default/src/components/ui/Pre.tsx index 8f33cc525..24d02ca85 100644 --- a/packages/docz-theme-default/src/components/ui/Pre.tsx +++ b/packages/docz-theme-default/src/components/ui/Pre.tsx @@ -130,7 +130,7 @@ export class Pre extends Component { language="javascript" showLineNumbers useInlineStyles={false} - lineNumberContainerStyle={linesStyle(config)} + lineNumberContainerStyle={linesStyle(config.themeConfig)} PreTag={Nullable} CodeTag={getCode(children)} > diff --git a/packages/docz-theme-default/src/components/ui/Tooltip.tsx b/packages/docz-theme-default/src/components/ui/Tooltip.tsx index 05b36bb87..ad08a8398 100644 --- a/packages/docz-theme-default/src/components/ui/Tooltip.tsx +++ b/packages/docz-theme-default/src/components/ui/Tooltip.tsx @@ -34,7 +34,7 @@ interface TooltipProps { export const Tooltip: SFC = ({ text, children }) => ( {config => ( - + {children} )} diff --git a/packages/docz-theme-default/src/index.tsx b/packages/docz-theme-default/src/index.tsx index aa8c4259d..c30040ddf 100644 --- a/packages/docz-theme-default/src/index.tsx +++ b/packages/docz-theme-default/src/index.tsx @@ -15,7 +15,7 @@ import * as prismThemes from './styles/prism' const Theme = () => ( {config => ( - + ReactNode + children?: (config: ThemeConfigObj) => ReactNode } export const configSelector = state.createSelector( @@ -18,13 +18,19 @@ export const ThemeConfig: SFC = ({ children }) => { return ( - {({ initialConfig, transform }) => ( + {({ themeConfig: initialThemeConfig, transform }) => ( - {(config: Config) => { - const newConfig = merge(initialConfig, config) - const transformed = transform ? transform(newConfig) : newConfig + {({ themeConfig, ...config }: Config) => { + const newThemeConfig = merge(initialThemeConfig, themeConfig) - return Children.only(children(transformed)) + return Children.only( + children({ + ...config, + themeConfig: transform + ? transform(newThemeConfig) + : newThemeConfig, + }) + ) }} )} diff --git a/packages/docz/src/state.ts b/packages/docz/src/state.ts index f09439342..c72602ab5 100644 --- a/packages/docz/src/state.ts +++ b/packages/docz/src/state.ts @@ -29,10 +29,18 @@ export interface Entry { [key: string]: any } -export interface Config { +export interface ThemeConfig { [key: string]: any } +export interface Config { + title: string + description: string + ordering: string + themeConfig: ThemeConfig + version: string | null +} + export type EntryMap = Record export type ImportMap = Record Promise> export type TransformFn = (config: Config) => Config diff --git a/packages/docz/src/theme.tsx b/packages/docz/src/theme.tsx index 084fc2b14..7d54a0901 100644 --- a/packages/docz/src/theme.tsx +++ b/packages/docz/src/theme.tsx @@ -7,7 +7,7 @@ import createContext from 'create-react-context' import { ErrorBoundary } from './components/ErrorBoundary' import { DataServer } from './components/DataServer' -import { state, Database, Config, ImportMap } from './state' +import { state, Database, ThemeConfig, ImportMap } from './state' declare var BASE_URL: any const DefaultWrapper: SFC = ({ children }) => {children} @@ -22,17 +22,17 @@ export interface ThemeProps { } export type ThemeReturn = (WrappedComponent: CT) => CT -export type TransformFn = (config: Config) => Config +export type TransformFn = (config: ThemeConfig) => ThemeConfig interface ThemeContext { - initialConfig?: Config + themeConfig?: ThemeConfig transform?: TransformFn } export const themeContext = createContext({}) export function theme( - initialConfig: Config, + themeConfig: ThemeConfig, transform?: TransformFn ): ThemeReturn { return WrappedComponent => { @@ -46,7 +46,7 @@ export function theme( return ( - +