-
-
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): add module declarations for typescript
- Loading branch information
1 parent
f8e0383
commit ae597af
Showing
11 changed files
with
126 additions
and
63 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"external": ["react", "react-dom", "react-router-dom", "history"] | ||
"external": ["react-router-dom", "history"] | ||
} |
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 { SFC, ReactNode, ComponentType } from 'react' | ||
|
||
declare module 'playgrodd' { | ||
export interface Section { | ||
id: string | ||
title?: string | ||
render: () => ReactNode | ||
} | ||
|
||
export interface DocArgs { | ||
name: string | ||
} | ||
|
||
export interface DocConstructorArgs { | ||
name: string | ||
} | ||
|
||
export class Doc { | ||
public id: string | ||
public name: string | ||
public docDescription: string | null | ||
public sections: Section[] | ||
public route: string | ||
|
||
public constructor({ name }: DocConstructorArgs) | ||
|
||
public description(value: string): Doc | ||
public section(...args: any[]): Doc | ||
} | ||
|
||
export interface DocMap { | ||
[key: string]: Doc | ||
} | ||
|
||
export type Docs = Doc[] | ||
|
||
/** | ||
* Components | ||
*/ | ||
|
||
export function createTheme(WrappedComponent: ComponentType): ComponentType | ||
|
||
export interface PreviewProps { | ||
children: (doc: Doc) => ReactNode | ||
} | ||
|
||
export const Preview: SFC<PreviewProps> | ||
|
||
export interface DocsProps { | ||
children: (docs: Doc[]) => ReactNode | ||
} | ||
|
||
export const Docs: SFC<DocsProps> | ||
} |
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,12 @@ | ||
import * as React from 'react' | ||
import { SFC } from 'react' | ||
import { Subscribe } from 'unstated' | ||
import { DocsProps } from 'playgrodd' | ||
|
||
import { DocsContainer } from '../container' | ||
|
||
export const Docs: SFC<DocsProps> = ({ children }) => ( | ||
<Subscribe to={[DocsContainer]}> | ||
{({ state }) => children(Object.values(state.docs))} | ||
</Subscribe> | ||
) |
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,27 @@ | ||
import * as React from 'react' | ||
import { SFC } from 'react' | ||
import { Subscribe } from 'unstated' | ||
import { Route } from 'react-router-dom' | ||
import { PreviewProps, Doc, Docs } from 'playgrodd' | ||
|
||
import { DocumentsContainer } from '../container' | ||
import { IDoc } from '../documents' | ||
import { DocsContainer } from '../container' | ||
|
||
export const Preview: React.SFC = () => ( | ||
<Subscribe to={[DocumentsContainer]}> | ||
export const Preview: SFC<PreviewProps> = ({ children }) => ( | ||
<Subscribe to={[DocsContainer]}> | ||
{({ state }) => { | ||
const documents: IDoc[] = Object.values(state.documents) | ||
return documents.length > 0 && documents.map(doc => doc.getName()) | ||
const docs: Docs = Object.values(state.docs) | ||
|
||
return ( | ||
docs.length > 0 && | ||
docs.map((doc: Doc) => ( | ||
<Route | ||
exact | ||
key={doc.id} | ||
path={doc.route} | ||
render={() => children(doc)} | ||
/> | ||
)) | ||
) | ||
}} | ||
</Subscribe> | ||
) |
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,29 +1,23 @@ | ||
import { Container } from 'unstated' | ||
import { IDoc, IDocMap } from '../documents' | ||
import { Doc, DocMap } from 'playgrodd' | ||
|
||
export interface DocumentState { | ||
documents: IDocMap | undefined | ||
interface DocsState { | ||
docs: DocMap | undefined | ||
} | ||
|
||
export class DocumentsContainer extends Container<DocumentState> { | ||
export class DocsContainer extends Container<DocsState> { | ||
constructor() { | ||
super() | ||
this.state = { | ||
documents: {}, | ||
} | ||
this.state = { docs: {} } | ||
} | ||
|
||
public addDoc(doc: IDoc) { | ||
public addDoc(doc: Doc) { | ||
this.setState({ | ||
documents: Object.assign({}, this.state.documents, { | ||
[`${doc.getName()}`]: doc, | ||
docs: Object.assign({}, this.state.docs, { | ||
[`${doc.name}`]: doc, | ||
}), | ||
}) | ||
} | ||
|
||
public getDocuments(): IDocMap | undefined { | ||
return this.state.documents | ||
} | ||
} | ||
|
||
export const container = new DocumentsContainer() | ||
export const container = new DocsContainer() |
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,3 +1,4 @@ | ||
export { Docs } from './components/Docs' | ||
export { Preview } from './components/Preview' | ||
export { createTheme } from './components/create-theme' | ||
export { doc } from './documents' | ||
export { doc } from './docs' |
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