diff --git a/packages/docz-theme-default/src/components/ui/Render/index.tsx b/packages/docz-theme-default/src/components/ui/Render/index.tsx index e75debf84..8ca046d3f 100644 --- a/packages/docz-theme-default/src/components/ui/Render/index.tsx +++ b/packages/docz-theme-default/src/components/ui/Render/index.tsx @@ -11,6 +11,7 @@ import Resizable from 're-resizable' import Maximize from 'react-feather/dist/icons/maximize' import Minimize from 'react-feather/dist/icons/minimize' import Refresh from 'react-feather/dist/icons/refresh-cw' +import Code from 'react-feather/dist/icons/code' import hotkeys from 'hotkeys-js' import getter from 'lodash.get' import pretty from 'pretty' @@ -179,6 +180,7 @@ export interface RenderState { showing: 'jsx' | 'html' code: string key: number + showEditor: boolean } export class Render extends Component { @@ -189,6 +191,7 @@ export class Render extends Component { showing: parse(this.props.position, 'showing', 'jsx'), code: this.props.code, key: 0, + showEditor: true, } public componentDidMount(): void { @@ -202,7 +205,7 @@ export class Render extends Component { } get actions(): JSX.Element { - const { showing, fullscreen } = this.state + const { showing, fullscreen, showEditor } = this.state const { codesandbox } = this.props const showJsx = this.handleShow('jsx') @@ -211,12 +214,16 @@ export class Render extends Component { return ( - - JSX - - - HTML - + {showEditor && ( + <> + + JSX + + + HTML + + + )} @@ -241,6 +248,12 @@ export class Render extends Component { > {fullscreen ? : } + + + ) } @@ -289,7 +302,7 @@ export class Render extends Component { public render(): JSX.Element { const { className, style, scope } = this.props - const { fullscreen, showing, key } = this.state + const { fullscreen, showing, key, showEditor } = this.state return ( { )} {this.actions} - {showing === 'jsx' ? ( - this.setState({ code })}> - {this.state.code} - - ) : ( -
}
-                  withLastLine
-                >
-                  {this.html}
-                
- )} + {showEditor && + (showing === 'jsx' ? ( + this.setState({ code })}> + {this.state.code} + + ) : ( +
}
+                    withLastLine
+                  >
+                    {this.html}
+                  
+ ))} @@ -369,6 +383,10 @@ export class Render extends Component { }) } + private handleShowEditorToggle = () => { + this.setState(prevState => ({ showEditor: !prevState.showEditor })) + } + private handleShow = (showing: 'jsx' | 'html') => () => { this.setState({ showing }) } diff --git a/packages/docz-theme-default/src/types.d.ts b/packages/docz-theme-default/src/types.d.ts index ac4ba3811..d33e37803 100644 --- a/packages/docz-theme-default/src/types.d.ts +++ b/packages/docz-theme-default/src/types.d.ts @@ -26,6 +26,7 @@ declare module 'react-feather/dist/icons/monitor' declare module 'react-feather/dist/icons/maximize' declare module 'react-feather/dist/icons/minimize' declare module 'react-feather/dist/icons/refresh-cw' +declare module 'react-feather/dist/icons/code' declare module 'react-feather/dist/icons/hash' declare module 'react-lightweight-tooltip' declare module 'react-powerplug'