-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4162a1c
commit a9c26e6
Showing
13 changed files
with
166 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import React from 'react' | ||
import { Router, Routes } from 'docz' | ||
import { hot } from 'react-hot-loader' | ||
import Theme from '<%- theme %>' | ||
|
||
import { imports } from './imports' | ||
import database from './db.json' | ||
<% if (wrapper) {%>import Wrapper from '<%- wrapper %>'<%}%> | ||
|
||
const Root = () => ( | ||
<Theme <% if (wrapper) {%>wrapper={Wrapper}<%}%> /> | ||
<Theme <% if (wrapper) {%>wrapper={Wrapper}<%}%> db={database}> | ||
<Router> | ||
<Routes imports={imports} /> | ||
</Router> | ||
</Theme> | ||
) | ||
|
||
export default hot(module)(Root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as React from 'react' | ||
import { SFC } from 'react' | ||
import { HashRouter, BrowserRouter } from 'react-router-dom' | ||
import { StaticRouterProps } from 'react-router' | ||
|
||
import { ScrollToTop } from '../utils/ScrollToTop' | ||
|
||
declare var DOCZ_BASE_URL: string | ||
declare var DOCZ_HASH_ROUTER: boolean | ||
|
||
const BaseRouter: SFC<StaticRouterProps> = (props: any) => | ||
Boolean(DOCZ_HASH_ROUTER) ? ( | ||
<HashRouter {...props} /> | ||
) : ( | ||
<BrowserRouter {...props} /> | ||
) | ||
|
||
export const Router: SFC = ({ children }) => ( | ||
<BaseRouter basename={DOCZ_BASE_URL}> | ||
<ScrollToTop>{children}</ScrollToTop> | ||
</BaseRouter> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as React from 'react' | ||
import { Fragment, SFC } from 'react' | ||
import { Switch, Route } from 'react-router-dom' | ||
import { withMDXComponents } from '@mdx-js/tag/dist/mdx-provider' | ||
import { get } from 'lodash/fp' | ||
|
||
import { state } from '../state' | ||
import { AsyncRoute, loadRoute, Imports } from './AsyncRoute' | ||
import { ComponentsMap } from './DocPreview' | ||
|
||
export interface RoutesProps { | ||
components: ComponentsMap | ||
imports: Imports | ||
} | ||
|
||
export const Routes: SFC = withMDXComponents( | ||
({ components, imports }: RoutesProps) => ( | ||
<Fragment> | ||
{state.get(({ entries }) => { | ||
if (!entries || !components) return null | ||
|
||
const NotFound: any = components.notFound | ||
const Loading: any = components.loading | ||
|
||
return ( | ||
<Switch> | ||
{Object.keys(entries).map(path => { | ||
const entry = get(path, entries) | ||
const props = { path, entries, components } | ||
const component: any = loadRoute(path, imports, Loading) | ||
|
||
component.preload() | ||
return ( | ||
<Route | ||
exact | ||
key={entry.id} | ||
path={entry.route} | ||
render={routeProps => ( | ||
<AsyncRoute | ||
{...routeProps} | ||
{...props} | ||
asyncComponent={component} | ||
/> | ||
)} | ||
/> | ||
) | ||
})} | ||
{NotFound && <Route component={NotFound} />} | ||
</Switch> | ||
) | ||
})} | ||
</Fragment> | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
export { theme } from './theme' | ||
export { Entry, MenuItem } from './state' | ||
export { Docs, DocsRenderProps } from './components/Docs' | ||
export { Link, LinkProps } from './components/Link' | ||
export { Menu, MenuRenderProps } from './components/Menu' | ||
export { Playground } from './components/Playground' | ||
export { PropsTable } from './components/PropsTable' | ||
export { ThemeConfig } from './components/ThemeConfig' | ||
export { | ||
DocPreview, | ||
PageProps, | ||
RenderComponent, | ||
RenderComponentProps, | ||
} from './components/DocPreview' | ||
export { Router } from './components/Router' | ||
export { Routes } from './components/Routes' | ||
export * from './components/DocPreview' | ||
|
||
export { theme } from './theme' | ||
export { Entry, MenuItem } from './state' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.