This repository has been archived by the owner on Jan 24, 2025. It is now read-only.
-
-
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.
feat(docz-theme-default): start logic to create theme feature
- Loading branch information
1 parent
05ac064
commit 900cf2b
Showing
16 changed files
with
230 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"plugins": [ | ||
["module-resolver", { | ||
"alias": { | ||
"playgrodd": "../../packages/playgrood/build/main", | ||
"playgrodd-theme-default": "../../packages/playgrood/build/main/theme/default.js" | ||
} | ||
}] | ||
] | ||
} |
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,42 @@ | ||
import React from 'react' | ||
import { Route } from 'react-router-dom' | ||
import { IComponent } from '../utils/components' | ||
|
||
export interface IAsyncRouteProps { | ||
component: IComponent | ||
} | ||
|
||
export interface IAsyncRouteState { | ||
render(): JSX.Element | null | ||
} | ||
|
||
export class AsyncRoute extends React.Component< | ||
IAsyncRouteProps, | ||
IAsyncRouteState | ||
> { | ||
constructor(props: any, ctx: any) { | ||
super(props, ctx) | ||
|
||
this.state = { | ||
render: () => null, | ||
} | ||
} | ||
|
||
async componentDidMount() { | ||
const { name } = this.props.component | ||
const { importFn } = window.__PLAYGRODD_COMPONENTS__[`${name}`] | ||
const { doc: render } = await importFn | ||
|
||
this.setState({ render }) | ||
} | ||
|
||
render() { | ||
return ( | ||
<Route | ||
exact | ||
path={this.props.component.route} | ||
render={this.state.render} | ||
/> | ||
) | ||
} | ||
} |
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,38 @@ | ||
import * as React from 'react' | ||
import { Router } from 'react-router-dom' | ||
import { createBrowserHistory, History } from 'history' | ||
import createContext from 'create-react-context' | ||
|
||
export const history: History = createBrowserHistory() | ||
export const PlaygroddContext = createContext({}) | ||
|
||
export interface IPlaygroddState { | ||
components: any | ||
} | ||
|
||
export class Playgrodd extends React.Component<{}, IPlaygroddState> { | ||
constructor(props: any) { | ||
super(props) | ||
|
||
this.state = { | ||
components: {}, | ||
} | ||
} | ||
|
||
setComponents = () => | ||
this.setState({ components: window.__PLAYGRODD_COMPONENTS__ }) | ||
|
||
componentDidMount() { | ||
window.addEventListener('load', this.setComponents, false) | ||
} | ||
|
||
render() { | ||
return ( | ||
<Router history={history}> | ||
<PlaygroddContext.Provider value={this.state.components}> | ||
{this.props.children} | ||
</PlaygroddContext.Provider> | ||
</Router> | ||
) | ||
} | ||
} |
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,15 @@ | ||
import * as React from 'react' | ||
|
||
import { IComponents } from '../utils/components' | ||
import { PlaygroddContext } from '../components/Playgrodd' | ||
import { AsyncRoute } from '../components/AsyncRoute' | ||
|
||
export const Preview: React.SFC = () => ( | ||
<PlaygroddContext.Consumer> | ||
{(components: IComponents) => | ||
Object.values(components).map(component => ( | ||
<AsyncRoute key={component.id} component={component} /> | ||
)) | ||
} | ||
</PlaygroddContext.Consumer> | ||
) |
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,2 @@ | ||
export { Preview } from './components/Preview' | ||
export { Playgrodd } from './components/Playgrodd' |
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,19 @@ | ||
import * as React from 'react' | ||
import { Link } from 'react-router-dom' | ||
|
||
import { Playgrodd } from '../components/Playgrodd' | ||
import { Preview } from '../components/Preview' | ||
|
||
export const App = () => ( | ||
<Playgrodd> | ||
<ul> | ||
<li> | ||
<Link to="/src/Alert">Alert</Link> | ||
</li> | ||
<li> | ||
<Link to="/src/Button">Button</Link> | ||
</li> | ||
</ul> | ||
<Preview /> | ||
</Playgrodd> | ||
) |
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 was deleted.
Oops, something went wrong.
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,21 @@ | ||
import { IComponents } from './components' | ||
|
||
const mapImports = (components: IComponents) => | ||
Object.values(components).map( | ||
({ name, filepath }) => | ||
`window.__PLAYGRODD_COMPONENTS__.${name}.importFn = import('${filepath}')` | ||
) | ||
|
||
export const generateMain = (components: IComponents) => | ||
`import 'babel-polyfill' | ||
${mapImports(components).join('\n')} | ||
import * as React from 'react' | ||
import { render } from 'react-dom' | ||
import { App } from 'playgrodd-theme-default' | ||
render( | ||
<App />, | ||
document.querySelector('#root') | ||
)` |
Oops, something went wrong.