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

Commit

Permalink
feat(docz): add rawCode for Playground
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jul 22, 2018
1 parent af88d0e commit 70d4735
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/docz/src/components/DocPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ const Identity: SFC<any> = ({ children }) => <Fragment>{children}</Fragment>
const DefaultLoading: SFC = () => <Fragment>Loading</Fragment>

export type RenderComponent = ComponentType<{
component: JSX.Element
code: any
className?: string
style?: any
components: ComponentsMap
component: JSX.Element
code: (components: ComponentsMap) => any
rawCode: string
}>

export const DefaultRender: RenderComponent = ({ component, code }) => (
Expand Down
8 changes: 6 additions & 2 deletions packages/docz/src/components/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { isFn } from './Docs'
import { ComponentsMap } from './DocPreview'

export interface PlaygroundProps {
components: ComponentsMap
className?: string
style?: any
children: any
components: ComponentsMap
__code: (components: ComponentsMap) => any
__rawCode: string
children: any
}

const BasePlayground: SFC<PlaygroundProps> = ({
Expand All @@ -19,13 +20,16 @@ const BasePlayground: SFC<PlaygroundProps> = ({
style,
children,
__code,
__rawCode,
}) => {
return components && components.render ? (
<components.render
className={className}
style={style}
components={components}
component={isFn(children) ? children() : children}
code={__code(components)}
rawCode={__rawCode}
/>
) : null
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rehype-docz/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const addCodeProp = async (node: any) => {

node.value = node.value.replace(
tagOpen,
`<${name} __code={${codeComponent}}`
`<${name} __code={${codeComponent}} __rawCode={\`${child}\`}`
)
}
}
Expand Down

0 comments on commit 70d4735

Please sign in to comment.