Skip to content

Commit

Permalink
feat(docz-theme-default): set max lines before scroll editor (#519)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7bf3803)
  • Loading branch information
pedronauck committed Dec 17, 2018
1 parent 30c358b commit 8d511e5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions packages/docz-theme-default/README.md
Expand Up @@ -68,6 +68,10 @@ const config = {
* Show/hide Playground editor by default
*/
showPlaygroundEditor: true,
/**
* Set the numbers of max lines before scroll editor
*/
linesToScrollEditor: 14
/**
* Customize codemirror theme
*/
Expand Down
18 changes: 13 additions & 5 deletions packages/docz-theme-default/src/components/ui/CodeMirror/index.tsx
@@ -1,5 +1,6 @@
import { jsx } from '@emotion/core'
import { SFC } from 'react'
import { ThemeConfig } from 'docz'
import { Controlled as BaseCodeMirror } from 'react-codemirror2'
import PerfectScrollbar from 'react-perfect-scrollbar'
import styled from '@emotion/styled'
Expand All @@ -20,7 +21,7 @@ import 'codemirror/addon/fold/xml-fold'
const Scrollbar = styled(PerfectScrollbar)<any>`
overflow: auto;
position: relative;
max-height: 360px;
max-height: ${p => 25 * p.linesToScroll}px;
.ps__rail-y {
z-index: 9;
Expand Down Expand Up @@ -70,8 +71,15 @@ const scrollbarOpts = {
}

export const CodeMirror: SFC<any> = props => (
<Scrollbar option={scrollbarOpts}>
{global}
<EditorStyled {...props} />
</Scrollbar>
<ThemeConfig>
{({ themeConfig }) => (
<Scrollbar
option={scrollbarOpts}
linesToScroll={themeConfig.linesToScrollEditor || 14}
>
{global}
<EditorStyled {...props} />
</Scrollbar>
)}
</ThemeConfig>
)
1 change: 1 addition & 0 deletions packages/docz-theme-default/src/config.ts
Expand Up @@ -7,4 +7,5 @@ export const config = {
radii: '2px',
mode: 'light',
showPlaygroundEditor: false,
linesToScrollEditor: 18,
}
5 changes: 2 additions & 3 deletions packages/docz/src/components/Playground.tsx
Expand Up @@ -28,12 +28,11 @@ const BasePlayground: SFC<PlaygroundProps> = ({
__codesandbox,
}) => {
if (!components || !components.render) return null
const props = { className, style, components }

return (
<components.render
className={className}
style={style}
components={components}
{...props}
component={Wrapper ? <Wrapper>{children}</Wrapper> : children}
scope={__scope}
position={__position}
Expand Down

0 comments on commit 8d511e5

Please sign in to comment.