-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ef569a
commit cde6511
Showing
53 changed files
with
1,484 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
import React from 'react' | ||
import { Link, Router, Routes } from 'docz' | ||
import { Link, Router, Routes, useDataServer } from 'docz' | ||
import { hot } from 'react-hot-loader' | ||
import Theme from '<%- theme %>' | ||
|
||
import { imports } from './imports' | ||
import database from './db.json' | ||
<% if (wrapper) {%>import Wrapper from '<%- wrapper %>'<%}%> | ||
|
||
const Root = () => ( | ||
<Theme | ||
<% if (wrapper) {%>wrapper={Wrapper}<%}%> | ||
<% if (websocketUrl) {%>websocketUrl="<%- websocketUrl %>"<%}%> | ||
db={database} | ||
linkComponent={Link} | ||
> | ||
<Router> | ||
<Routes imports={imports} /> | ||
</Router> | ||
</Theme> | ||
) | ||
const Root = () => { | ||
<% if (websocketUrl) {%>useDataServer('<%- websocketUrl %>')<%}%> | ||
return ( | ||
<Theme | ||
<% if (wrapper) {%>wrapper={Wrapper}<%}%> | ||
linkComponent={Link} | ||
db={database} | ||
> | ||
<Router> | ||
<Routes imports={imports} /> | ||
</Router> | ||
</Theme> | ||
) | ||
} | ||
|
||
export default hot(module)(Root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
core/docz-theme-default/src/components/ui/AsyncPlayground.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as React from 'react' | ||
|
||
const Playground = React.lazy(() => import('./Playground')) | ||
export const AsyncPlayground: React.SFC<any> = props => ( | ||
<React.Suspense fallback={null}> | ||
<Playground {...props} /> | ||
</React.Suspense> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
core/docz-theme-default/src/components/ui/CodeMirror/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import * as React from 'react' | ||
import { SFC } from 'react' | ||
import { useConfig } from 'docz' | ||
import { Controlled as BaseCodeMirror } from 'react-codemirror2' | ||
import PerfectScrollbar from 'react-perfect-scrollbar' | ||
import styled from 'styled-components' | ||
|
||
import { get } from '@utils/theme' | ||
import { mq } from '@styles/responsive' | ||
|
||
import { ScrollbarStyles } from './ps-scrollbar' | ||
import * as themes from './themes' | ||
|
||
import 'codemirror/mode/markdown/markdown' | ||
import 'codemirror/mode/javascript/javascript' | ||
import 'codemirror/mode/jsx/jsx' | ||
import 'codemirror/mode/css/css' | ||
import 'codemirror/addon/edit/matchbrackets' | ||
import 'codemirror/addon/edit/closetag' | ||
import 'codemirror/addon/fold/xml-fold' | ||
|
||
const Scrollbar = styled(PerfectScrollbar)` | ||
overflow: auto; | ||
position: relative; | ||
max-height: ${p => 25 * p.linesToScroll}px; | ||
.ps__rail-y { | ||
z-index: 9; | ||
opacity: 0.4; | ||
} | ||
` | ||
|
||
const preStyles = get('styles.pre') | ||
const EditorStyled = styled(BaseCodeMirror)` | ||
${themes.dark}; | ||
${themes.light}; | ||
position: relative; | ||
flex: 1; | ||
font-size: 16px; | ||
${p => mq(preStyles(p))}; | ||
.CodeMirror { | ||
max-width: 100%; | ||
height: 100%; | ||
} | ||
.CodeMirror pre { | ||
${p => mq(preStyles(p))}; | ||
} | ||
.CodeMirror-gutters { | ||
left: 1px !important; | ||
} | ||
.CodeMirror-lines { | ||
padding: 10px 0; | ||
box-sizing: content-box; | ||
} | ||
.CodeMirror-line { | ||
padding: 0 10px; | ||
} | ||
.CodeMirror-linenumber { | ||
padding: 0 7px 0 5px; | ||
} | ||
` | ||
|
||
const scrollbarOpts = { | ||
wheelSpeed: 2, | ||
wheelPropagation: true, | ||
minScrollbarLength: 20, | ||
suppressScrollX: true, | ||
} | ||
|
||
const CodeMirror: SFC<any> = props => { | ||
const { themeConfig } = useConfig() | ||
const linesToScroll = themeConfig.linesToScrollEditor || 14 | ||
return ( | ||
<React.Fragment> | ||
<ScrollbarStyles /> | ||
<Scrollbar option={scrollbarOpts} linesToScroll={linesToScroll}> | ||
<EditorStyled {...props} /> | ||
</Scrollbar> | ||
</React.Fragment> | ||
) | ||
} | ||
|
||
export default CodeMirror |
97 changes: 97 additions & 0 deletions
97
core/docz-theme-default/src/components/ui/CodeMirror/ps-scrollbar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { createGlobalStyle } from 'styled-components' | ||
|
||
export const ScrollbarStyles = createGlobalStyle` | ||
/* | ||
* Container style | ||
*/ | ||
.ps { | ||
overflow: hidden !important; | ||
overflow-anchor: none; | ||
-ms-overflow-style: none; | ||
touch-action: auto; | ||
-ms-touch-action: auto; | ||
} | ||
/* | ||
* Scrollbar rail styles | ||
*/ | ||
.ps__rail-x { | ||
display: none; | ||
opacity: 0; | ||
transition: background-color 0.2s linear, opacity 0.2s linear; | ||
-webkit-transition: background-color 0.2s linear, opacity 0.2s linear; | ||
height: 15px; | ||
/* there must be 'bottom' or 'top' for ps__rail-x */ | ||
bottom: 0px; | ||
/* please don't change 'position' */ | ||
position: absolute; | ||
} | ||
.ps__rail-y { | ||
display: none; | ||
opacity: 0; | ||
transition: background-color 0.2s linear, opacity 0.2s linear; | ||
-webkit-transition: background-color 0.2s linear, opacity 0.2s linear; | ||
width: 15px; | ||
/* there must be 'right' or 'left' for ps__rail-y */ | ||
right: 0; | ||
/* please don't change 'position' */ | ||
position: absolute; | ||
} | ||
.ps--active-x > .ps__rail-x, | ||
.ps--active-y > .ps__rail-y { | ||
display: block; | ||
background-color: transparent; | ||
} | ||
/* | ||
* Scrollbar thumb styles | ||
*/ | ||
.ps__thumb-x { | ||
background-color: #aaa; | ||
border-radius: 4px; | ||
transition: background-color 0.2s linear, height 0.2s ease-in-out; | ||
-webkit-transition: background-color 0.2s linear, | ||
height 0.2s ease-in-out; | ||
height: 6px; | ||
/* there must be 'bottom' for ps__thumb-x */ | ||
bottom: 2px; | ||
/* please don't change 'position' */ | ||
position: absolute; | ||
} | ||
.ps__thumb-y { | ||
background-color: #aaa; | ||
border-radius: 4px; | ||
transition: background-color 0.2s linear, width 0.2s ease-in-out; | ||
-webkit-transition: background-color 0.2s linear, width 0.2s ease-in-out; | ||
width: 6px; | ||
/* there must be 'right' for ps__thumb-y */ | ||
right: 2px; | ||
/* please don't change 'position' */ | ||
position: absolute; | ||
} | ||
.ps__rail-x:hover > .ps__thumb-x, | ||
.ps__rail-x:focus > .ps__thumb-x, | ||
.ps__rail-x.ps--clicking .ps__thumb-x { | ||
background-color: #999; | ||
height: 11px; | ||
} | ||
.ps__rail-y:hover > .ps__thumb-y, | ||
.ps__rail-y:focus > .ps__thumb-y, | ||
.ps__rail-y.ps--clicking .ps__thumb-y { | ||
background-color: #999; | ||
width: 11px; | ||
} | ||
/* MS supports */ | ||
@supports (-ms-overflow-style: none) { | ||
.ps { | ||
overflow: auto !important; | ||
} | ||
} | ||
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { | ||
.ps { | ||
overflow: auto !important; | ||
} | ||
} | ||
.scrollbar-container { | ||
position: relative; | ||
height: 100%; | ||
} | ||
` |
Oops, something went wrong.