From 01110d4a5cf1e2f050f183a2815226c25eafb557 Mon Sep 17 00:00:00 2001 From: Pedro Nauck Date: Wed, 14 Nov 2018 19:51:48 -0200 Subject: [PATCH] fix(docz-theme-default): add styles or classname on playground --- .../src/components/ui/Editor/index.tsx | 11 ++- .../src/components/ui/Render/LiveConsumer.tsx | 5 -- .../src/components/ui/Render/index.tsx | 87 ++++++++----------- 3 files changed, 43 insertions(+), 60 deletions(-) delete mode 100644 packages/docz-theme-default/src/components/ui/Render/LiveConsumer.tsx diff --git a/packages/docz-theme-default/src/components/ui/Editor/index.tsx b/packages/docz-theme-default/src/components/ui/Editor/index.tsx index a42f8fce9..e6db3bb93 100644 --- a/packages/docz-theme-default/src/components/ui/Editor/index.tsx +++ b/packages/docz-theme-default/src/components/ui/Editor/index.tsx @@ -63,13 +63,18 @@ const Scrollbar = styled(PerfectScrollbar)` } ` +interface EditorStyledProps { + square: boolean +} + const preStyles = get('styles.pre') const EditorStyled = styled(CodeMirror)` ${themes.dark()}; ${themes.light()}; ${p => p.theme.docz.mq(preStyles(p))}; position: relative; - border-radius: ${get('radii')}; + border-radius: ${(p: EditorStyledProps) => + p.square ? 'none' : get('radii')}; flex: 1; .CodeMirror { @@ -159,6 +164,7 @@ interface EditorProps { onChange?: (code: string) => any language?: string withLastLine?: boolean + square?: boolean } interface EditorState { @@ -187,6 +193,7 @@ export class Editor extends Component { className, editorClassName, language: defaultLanguage, + square, ...props } = this.props @@ -227,7 +234,7 @@ export class Editor extends Component { {config => ( - + )} diff --git a/packages/docz-theme-default/src/components/ui/Render/LiveConsumer.tsx b/packages/docz-theme-default/src/components/ui/Render/LiveConsumer.tsx deleted file mode 100644 index 81f498f29..000000000 --- a/packages/docz-theme-default/src/components/ui/Render/LiveConsumer.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import { withLive } from 'react-live' - -export const LiveConsumer = withLive(({ live, children }) => - children(live) -) 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 f3e7a1d8c..532255427 100644 --- a/packages/docz-theme-default/src/components/ui/Render/index.tsx +++ b/packages/docz-theme-default/src/components/ui/Render/index.tsx @@ -18,7 +18,6 @@ import pretty from 'pretty' import { Handle, HANDLE_SIZE } from './Handle' import { ResizeBar } from './ResizeBar' -import { LiveConsumer } from './LiveConsumer' import { CodeSandboxLogo } from './CodeSandboxLogo' import { ActionButton, ClipboardAction, Editor as PreBase } from '../Editor' @@ -64,15 +63,11 @@ const PlaygroundWrapper = styled('div')` border: 1px solid ${borderColor}; background: ${backgroundColor}; min-height: ${whenFullscreen('198px', 'auto')}; - ${p => p.theme.docz.mq(p.theme.docz.styles.playground)}; ` const StyledPreview = styled(LivePreview)` width: 100%; -` - -const Playground = styled('div')` - width: 100%; + ${p => p.theme.docz.mq(p.theme.docz.styles.playground)}; ` const StyledError = styled(LiveError)` @@ -131,7 +126,7 @@ const Action = styled(ActionButton)` const ActionLink = Action.withComponent('a') -const Clipboard = styled(ClipboardAction)` +const Clipboard = styled(ClipboardAction as any)` ${actionClass}; ` @@ -172,21 +167,6 @@ const parse = (position: number, key: string, defaultValue: any) => { return obj ? getter(obj, key) : defaultValue } -interface JSXProps { - onChange: (code: string) => any -} - -const Jsx: SFC = ({ children, ...props }) => ( -
}
-  >
-    {children}
-  
-) - interface RenderProps extends RenderComponentProps { showEditor?: boolean } @@ -233,14 +213,14 @@ class RenderBase extends Component { {showEditor && ( - <> + JSX HTML - + )} @@ -278,7 +258,11 @@ class RenderBase extends Component { } get html(): string { - return pretty(renderToStaticMarkup(this.props.component)) + try { + return pretty(renderToStaticMarkup(this.props.component)) + } catch (err) { + return 'There was an error while rendering your html' + } } get resizableProps(): Record { @@ -321,7 +305,13 @@ class RenderBase extends Component { public render(): JSX.Element { const { className, style, scope } = this.props - const { fullscreen, showing, key, showEditor } = this.state + const { fullscreen, showing, showEditor } = this.state + + const editorProps = { + square: true, + className: editorClassName, + actions: , + } return ( { {fullscreen ? : null} - - {(live: any) => ( - - {live.error && ( - - {this.props.component} - - )} - - - - )} - + + + + {this.actions} - {showEditor && - (showing === 'jsx' ? ( - this.setState({ code })}> - {this.state.code} - - ) : ( -
}
-                      withLastLine
-                    >
-                      {this.html}
-                    
- ))} + {showing === 'jsx' && ( +
 this.setState({ code })}
+                    readOnly={false}
+                  >
+                    {this.state.code}
+                  
+ )} + {showing === 'html' && ( +
+                    {this.html}
+                  
+ )}