Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 1150373

Browse files
committed
feat(docz): add doc page wrapper as component
1 parent 435da9b commit 1150373

File tree

8 files changed

+101
-68
lines changed

8 files changed

+101
-68
lines changed

packages/docz-theme-default/src/components/ui/Container.tsx

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/docz-theme-default/src/components/ui/H1.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import styled from 'react-emotion'
22

33
export const H1 = styled('h1')`
44
position: relative;
5+
display: table;
56
${p => p.theme.styles.h1};
67
78
&:before {
89
position: absolute;
910
content: '';
10-
bottom: 0;
11+
bottom: 5%;
1112
left: 0;
12-
width: 10%;
13+
width: 30%;
1314
height: 3px;
1415
background: ${p => p.theme.colors.primary};
1516
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as React from 'react'
2+
import { PageProps } from 'docz'
3+
import { SFC } from 'react'
4+
import styled from 'react-emotion'
5+
6+
export const Container = styled('div')`
7+
margin: 0 auto;
8+
${p => p.theme.styles.container};
9+
`
10+
11+
const Wrapper = styled('div')`
12+
flex: 1;
13+
height: 100%;
14+
overflow-y: auto;
15+
`
16+
17+
export const Page: SFC<PageProps> = ({ children, ...props }) => (
18+
<Wrapper>
19+
<Container>{children}</Container>
20+
</Wrapper>
21+
)

packages/docz-theme-default/src/components/ui/Tooltip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface TooltipProps {
1010

1111
export const Tooltip: SFC<TooltipProps> = ({ text, children }) => (
1212
<ThemeConfig>
13-
{({ config }) => (
13+
{config => (
1414
<BaseTooltip styles={config.styles.tooltip} content={text}>
1515
{children}
1616
</BaseTooltip>

packages/docz-theme-default/src/components/ui/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
export { Container } from './Container'
21
export { H1 } from './H1'
32
export { H2 } from './H2'
43
export { H3 } from './H3'
54
export { H4 } from './H4'
65
export { H5 } from './H5'
76
export { H6 } from './H6'
87
export { List } from './List'
8+
export { Page } from './Page'
99
export { Pre } from './Pre'
1010
export { Render } from './Render'
1111
export { Table } from './Table'

packages/docz-theme-default/src/index.tsx

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,35 @@
11
import './styles/prism-theme'
22

33
import * as React from 'react'
4-
import styled from 'react-emotion'
54
import { theme, DocPreview, ThemeConfig } from 'docz'
65
import { ThemeProvider } from 'emotion-theming'
76

8-
import * as components from './components/ui'
9-
import { Container } from './components/ui'
10-
import { Sidebar, Main } from './components/shared'
117
import { config } from './config'
12-
13-
const Page = styled('div')`
14-
flex: 1;
15-
height: 100%;
16-
overflow-y: auto;
17-
`
8+
import { Sidebar, Main } from './components/shared'
9+
import * as components from './components/ui'
1810

1911
const Theme = () => (
2012
<ThemeConfig>
21-
{({ config }) => (
13+
{config => (
2214
<ThemeProvider theme={config}>
2315
<Main config={config}>
2416
<Sidebar />
25-
<Page>
26-
<Container>
27-
<DocPreview
28-
components={{
29-
h1: components.H1,
30-
h2: components.H2,
31-
h3: components.H3,
32-
h4: components.H4,
33-
h5: components.H5,
34-
h6: components.H6,
35-
ul: components.List,
36-
table: components.Table,
37-
render: components.Render,
38-
tooltip: components.Tooltip,
39-
pre: components.Pre,
40-
}}
41-
/>
42-
</Container>
43-
</Page>
17+
<DocPreview
18+
components={{
19+
page: components.Page,
20+
render: components.Render,
21+
h1: components.H1,
22+
h2: components.H2,
23+
h3: components.H3,
24+
h4: components.H4,
25+
h5: components.H5,
26+
h6: components.H6,
27+
ul: components.List,
28+
table: components.Table,
29+
pre: components.Pre,
30+
tooltip: components.Tooltip,
31+
}}
32+
/>
4433
</Main>
4534
</ThemeProvider>
4635
)}
Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,67 @@
11
import * as React from 'react'
22
import { SFC } from 'react'
33
import loadable from 'loadable-components'
4-
import { Switch, Route } from 'react-router-dom'
4+
import { Switch, Route, RouteComponentProps } from 'react-router-dom'
55

6-
import { dataContext } from '../theme'
6+
import { RenderComponent } from './Playground'
7+
import { dataContext, Entry } from '../theme'
8+
9+
export type PageProps = RouteComponentProps<any> & {
10+
doc?: Entry
11+
}
712

813
export interface DocPreviewProps {
914
components: {
15+
page?: React.ComponentType<PageProps>
16+
render?: RenderComponent
17+
h1?: React.ComponentType<any>
18+
h2?: React.ComponentType<any>
19+
h3?: React.ComponentType<any>
20+
h4?: React.ComponentType<any>
21+
h5?: React.ComponentType<any>
22+
h6?: React.ComponentType<any>
23+
ul?: React.ComponentType<any>
24+
table?: React.ComponentType<any>
25+
pre?: React.ComponentType<any>
1026
[key: string]: any
1127
}
1228
}
1329

14-
export const DocPreview: SFC<DocPreviewProps> = ({ components }) => (
15-
<dataContext.Consumer>
16-
{({ imports, entries }) => (
17-
<Switch>
18-
{Object.keys(imports).map(path => {
19-
const entry = entries && entries[path]
20-
const asyncComponent = loadable(async () => {
21-
const { default: Component } = await imports[path]()
22-
return props => <Component {...props} components={components} />
23-
})
30+
export const DocPreview: SFC<DocPreviewProps> = ({ components }) => {
31+
const Page = components.page
2432

25-
return (
26-
entry && (
27-
<Route
28-
exact
29-
key={entry.id}
30-
path={entry.route}
31-
component={asyncComponent}
32-
/>
33+
return (
34+
<dataContext.Consumer>
35+
{({ imports, entries }) => (
36+
<Switch>
37+
{Object.keys(imports).map(path => {
38+
const entry = entries && entries[path]
39+
const AsyncComponent = loadable(async () => {
40+
const { default: Component } = await imports[path]()
41+
return props => <Component {...props} components={components} />
42+
})
43+
44+
return (
45+
entry && (
46+
<Route
47+
exact
48+
key={entry.id}
49+
path={entry.route}
50+
render={props =>
51+
Page ? (
52+
<Page {...props} doc={entry}>
53+
<AsyncComponent />
54+
</Page>
55+
) : (
56+
<AsyncComponent {...props} />
57+
)
58+
}
59+
/>
60+
)
3361
)
34-
)
35-
})}
36-
</Switch>
37-
)}
38-
</dataContext.Consumer>
39-
)
62+
})}
63+
</Switch>
64+
)}
65+
</dataContext.Consumer>
66+
)
67+
}

packages/docz/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export { theme, Entry } from './theme'
2-
export { DocPreview } from './components/DocPreview'
2+
export { DocPreview, PageProps } from './components/DocPreview'
33
export { Docs, DocsRenderProps } from './components/Docs'
44
export { Link } from './components/Link'
55
export { Playground, RenderComponent } from './components/Playground'
66
export { PropsTable } from './components/PropsTable'
7-
export { ThemeConfig, ThemeConfigRenderProps } from './components/ThemeConfig'
7+
export { ThemeConfig } from './components/ThemeConfig'

0 commit comments

Comments
 (0)