1
1
import * as React from 'react'
2
2
import { SFC , Fragment , Component } from 'react'
3
3
import { renderToStaticMarkup } from 'react-dom/server'
4
- import { RenderComponentProps , ThemeConfig , theme } from 'docz'
4
+ import { RenderComponentProps , ThemeConfig } from 'docz'
5
5
import { LiveProvider , LiveError , LivePreview } from 'react-live'
6
6
import styled , { css } from 'react-emotion'
7
7
import lighten from 'polished/lib/color/lighten'
@@ -71,7 +71,7 @@ const StyledPreview = styled(LivePreview)`
71
71
width: 100%;
72
72
`
73
73
74
- const DummyPlayground = styled ( 'div' ) `
74
+ const Playground = styled ( 'div' ) `
75
75
width: 100%;
76
76
`
77
77
@@ -106,8 +106,7 @@ const Actions = styled('div')`
106
106
: darken ( 0.04 , borderColor ( p ) ) } ;
107
107
border-left: 1px solid ${ themeGet ( 'colors.border' ) } ;
108
108
border-bottom: 1px solid ${ themeGet ( 'colors.border' ) } ;
109
- border-radius: ${ p =>
110
- themeGet ( 'showPlaygroundEditor' ) ( p ) ? '0' : '0 0 0 4px' } ;
109
+ border-radius: ${ p => ( p . withRadius ? '0' : '0 0 0 4px' ) } ;
111
110
`
112
111
113
112
const actionClass = ( p : any ) => css `
@@ -218,7 +217,7 @@ class RenderBase extends Component<RenderProps, RenderState> {
218
217
const showHtml = this . handleShow ( 'html' )
219
218
220
219
return (
221
- < Actions >
220
+ < Actions withRadius = { this . state . showEditor } >
222
221
< Tabs >
223
222
{ showEditor && (
224
223
< >
@@ -313,7 +312,6 @@ class RenderBase extends Component<RenderProps, RenderState> {
313
312
314
313
return (
315
314
< LiveProvider
316
- noInline
317
315
code = { this . state . code }
318
316
scope = { scope }
319
317
transformCode = { this . transformCode }
@@ -327,9 +325,9 @@ class RenderBase extends Component<RenderProps, RenderState> {
327
325
{ ( live : any ) => (
328
326
< PlaygroundWrapper full = { fullscreen } >
329
327
{ live . error && (
330
- < DummyPlayground className = { className } style = { style } >
328
+ < Playground className = { className } style = { style } >
331
329
{ this . props . component }
332
- </ DummyPlayground >
330
+ </ Playground >
333
331
) }
334
332
< StyledPreview className = { className } style = { style } />
335
333
< StyledError />
@@ -411,16 +409,9 @@ class RenderBase extends Component<RenderProps, RenderState> {
411
409
this . setState ( state => ( { key : state . key + 1 } ) )
412
410
}
413
411
414
- private transformCode ( code : string ) : string {
415
- return `
416
- const DoczApp = ({ children }) => (
417
- <React.Fragment>
418
- {children && typeof children === 'function' ? children() : children}
419
- </React.Fragment>
420
- )
421
-
422
- render(<DoczApp>${ code } </DoczApp>)
423
- `
412
+ private transformCode = ( code : string ) => {
413
+ if ( code . startsWith ( '()' ) || code . startsWith ( 'class' ) ) return code
414
+ return `<React.Fragment>${ code } </React.Fragment>`
424
415
}
425
416
426
417
private codesandboxUrl = ( native : boolean ) : string => {
0 commit comments