mirror of
https://github.com/zhigang1992/docz.git
synced 2026-03-27 02:34:14 +08:00
chore(docz-theme-default): improve theme
This commit is contained in:
@@ -2,8 +2,6 @@ import React, { Fragment } from 'react'
|
||||
import styled from 'react-emotion'
|
||||
import t from 'prop-types'
|
||||
|
||||
import Button from './Button'
|
||||
|
||||
const kinds = {
|
||||
info: '#5352ED',
|
||||
positive: '#2ED573',
|
||||
@@ -11,7 +9,7 @@ const kinds = {
|
||||
warning: '#FFA502',
|
||||
}
|
||||
|
||||
const Alert = styled('div')`
|
||||
const AlertStyled = styled('div')`
|
||||
padding: 15px 20px;
|
||||
background: white;
|
||||
border-radius: 3px;
|
||||
@@ -19,8 +17,14 @@ const Alert = styled('div')`
|
||||
background: ${({ kind = 'info' }) => kinds[kind]};
|
||||
`
|
||||
|
||||
const Alert = props => <AlertStyled {...props} />
|
||||
|
||||
Alert.propTypes = {
|
||||
color: t.oneOf(['info', 'positive', 'negative', 'warning']),
|
||||
}
|
||||
|
||||
Alert.defaultProps = {
|
||||
color: 'info',
|
||||
}
|
||||
|
||||
export default Alert
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { doc, Playground } from 'docz'
|
||||
import { doc, Playground, PropsTable } from 'docz'
|
||||
import Alert from './Alert'
|
||||
|
||||
export const meta = doc('Alert')
|
||||
@@ -6,6 +6,8 @@ export const meta = doc('Alert')
|
||||
|
||||
# Alert
|
||||
|
||||
<PropsTable of={Alert} />
|
||||
|
||||
## Basic usage
|
||||
|
||||
<Playground>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"react-dom": "^16.3.2",
|
||||
"react-emotion": "^9.1.2",
|
||||
"react-feather": "^1.1.0",
|
||||
"react-powerplug": "^0.1.5",
|
||||
"react-lightweight-tooltip": "^1.0.0",
|
||||
"react-router-dom": "^4.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
9
packages/docz-theme-default/src/components/Container.tsx
Normal file
9
packages/docz-theme-default/src/components/Container.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { rem } from 'polished'
|
||||
import styled from 'react-emotion'
|
||||
|
||||
export const Container = styled('div')`
|
||||
width: ${rem(960)};
|
||||
max-width: ${rem(960)};
|
||||
padding: ${rem(50)} ${rem(50)} ${rem(100)} ${rem(50)};
|
||||
margin: 0 auto;
|
||||
`
|
||||
@@ -1,57 +0,0 @@
|
||||
import React, { SFC } from 'react'
|
||||
import { rem } from 'polished'
|
||||
import { DocObj } from 'docz'
|
||||
import styled from 'react-emotion'
|
||||
|
||||
import * as colors from '../styles/colors'
|
||||
import { Render } from './Render'
|
||||
import { Table } from './Table'
|
||||
|
||||
const Container = styled('div')`
|
||||
width: ${rem(960)};
|
||||
max-width: ${rem(960)};
|
||||
padding: ${rem(50)} ${rem(50)} ${rem(100)} ${rem(50)};
|
||||
margin: 0 auto;
|
||||
`
|
||||
|
||||
const Title = styled('h1')`
|
||||
position: relative;
|
||||
font-size: ${rem(48)};
|
||||
font-weight: 200;
|
||||
margin: ${rem(50)} 0 ${rem(40)};
|
||||
|
||||
&:before {
|
||||
position: absolute;
|
||||
content: '';
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 10%;
|
||||
height: 3px;
|
||||
background: ${colors.purple};
|
||||
}
|
||||
`
|
||||
|
||||
const Subtitle = styled('h2')`
|
||||
margin: ${rem(50)} 0 ${rem(20)};
|
||||
font-size: ${rem(28)};
|
||||
font-weight: 200;
|
||||
`
|
||||
|
||||
const H3 = styled('h3')`
|
||||
margin: ${rem(30)} 0 ${rem(20)};
|
||||
font-weight: 600;
|
||||
`
|
||||
|
||||
export const Doc: SFC<DocObj> = ({ id, component: Component }) => (
|
||||
<Container key={id}>
|
||||
<Component
|
||||
components={{
|
||||
h1: Title,
|
||||
h2: Subtitle,
|
||||
h3: H3,
|
||||
table: Table,
|
||||
Render,
|
||||
}}
|
||||
/>
|
||||
</Container>
|
||||
)
|
||||
21
packages/docz-theme-default/src/components/H1.tsx
Normal file
21
packages/docz-theme-default/src/components/H1.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import { rem } from 'polished'
|
||||
import styled from 'react-emotion'
|
||||
|
||||
import * as colors from '../styles/colors'
|
||||
|
||||
export const H1 = styled('h1')`
|
||||
position: relative;
|
||||
font-size: ${rem(48)};
|
||||
font-weight: 200;
|
||||
margin: ${rem(50)} 0 ${rem(40)};
|
||||
|
||||
&:before {
|
||||
position: absolute;
|
||||
content: '';
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 10%;
|
||||
height: 3px;
|
||||
background: ${colors.purple};
|
||||
}
|
||||
`
|
||||
8
packages/docz-theme-default/src/components/H2.tsx
Normal file
8
packages/docz-theme-default/src/components/H2.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
import { rem } from 'polished'
|
||||
import styled from 'react-emotion'
|
||||
|
||||
export const H2 = styled('h2')`
|
||||
margin: ${rem(50)} 0 ${rem(20)};
|
||||
font-size: ${rem(28)};
|
||||
font-weight: 200;
|
||||
`
|
||||
7
packages/docz-theme-default/src/components/H3.tsx
Normal file
7
packages/docz-theme-default/src/components/H3.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import { rem } from 'polished'
|
||||
import styled from 'react-emotion'
|
||||
|
||||
export const H3 = styled('h3')`
|
||||
margin: ${rem(30)} 0 ${rem(20)};
|
||||
font-weight: 600;
|
||||
`
|
||||
@@ -1,6 +0,0 @@
|
||||
import styled from 'react-emotion'
|
||||
|
||||
export const Main = styled('div')`
|
||||
display: flex;
|
||||
height: 100vh;
|
||||
`
|
||||
@@ -1,29 +0,0 @@
|
||||
import React from 'react'
|
||||
import { Route } from 'react-router-dom'
|
||||
import { Docs } from 'docz'
|
||||
import styled from 'react-emotion'
|
||||
|
||||
import { Doc } from './Doc'
|
||||
|
||||
const Wrapper = styled('div')`
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow-y: auto;
|
||||
`
|
||||
|
||||
export const View = () => (
|
||||
<Wrapper>
|
||||
<Docs>
|
||||
{({ docs }) =>
|
||||
docs.map(doc => (
|
||||
<Route
|
||||
exact
|
||||
key={doc.id}
|
||||
path={doc.route}
|
||||
render={() => <Doc {...doc} />}
|
||||
/>
|
||||
))
|
||||
}
|
||||
</Docs>
|
||||
</Wrapper>
|
||||
)
|
||||
7
packages/docz-theme-default/src/components/index.tsx
Normal file
7
packages/docz-theme-default/src/components/index.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
export { Container } from './Container'
|
||||
export { H1 } from './H1'
|
||||
export { H2 } from './H2'
|
||||
export { H3 } from './H3'
|
||||
export { Render } from './Render'
|
||||
export { Table } from './Table'
|
||||
export { Tooltip } from './Tooltip'
|
||||
@@ -2,19 +2,34 @@ import './styles'
|
||||
import './styles/prism-theme'
|
||||
|
||||
import * as React from 'react'
|
||||
import styled from 'react-emotion'
|
||||
|
||||
import { BrowserRouter } from 'react-router-dom'
|
||||
import { theme } from 'docz'
|
||||
import { theme, Docs } from 'docz'
|
||||
|
||||
import { Main } from './components/Main'
|
||||
import { Menu } from './components/Menu'
|
||||
import { View } from './components/View'
|
||||
import { Menu } from './modules/Sidebar'
|
||||
import { Doc } from './modules/Doc'
|
||||
|
||||
export const Main = styled('div')`
|
||||
display: flex;
|
||||
height: 100vh;
|
||||
`
|
||||
|
||||
const View = styled('div')`
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow-y: auto;
|
||||
`
|
||||
|
||||
export const Theme = theme(() => (
|
||||
<BrowserRouter>
|
||||
<Main>
|
||||
<Menu />
|
||||
<View />
|
||||
<View>
|
||||
<Docs>
|
||||
{({ docs }) => docs.map(doc => <Doc key={doc.id} {...doc} />)}
|
||||
</Docs>
|
||||
</View>
|
||||
</Main>
|
||||
</BrowserRouter>
|
||||
))
|
||||
|
||||
28
packages/docz-theme-default/src/modules/Doc/index.tsx
Normal file
28
packages/docz-theme-default/src/modules/Doc/index.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import * as React from 'react'
|
||||
import { SFC } from 'react'
|
||||
import { Route } from 'react-router-dom'
|
||||
import { DocObj } from 'docz'
|
||||
|
||||
import * as components from '../../components'
|
||||
import { Container } from '../../components'
|
||||
|
||||
export const Doc: SFC<DocObj> = ({ id, route, component: Component }) => (
|
||||
<Route
|
||||
exact
|
||||
path={route}
|
||||
render={() => (
|
||||
<Container>
|
||||
<Component
|
||||
components={{
|
||||
h1: components.H1,
|
||||
h2: components.H2,
|
||||
h3: components.H3,
|
||||
table: components.Table,
|
||||
render: components.Render,
|
||||
tooltip: components.Tooltip,
|
||||
}}
|
||||
/>
|
||||
</Container>
|
||||
)}
|
||||
/>
|
||||
)
|
||||
@@ -3,7 +3,7 @@ import { NavLink as BaseLink, LinkProps, match } from 'react-router-dom'
|
||||
import { Location } from 'history'
|
||||
import styled from 'react-emotion'
|
||||
|
||||
import * as colors from '../styles/colors'
|
||||
import * as colors from '../../styles/colors'
|
||||
|
||||
const LinkStyled = styled(BaseLink)`
|
||||
position: relative;
|
||||
@@ -3,7 +3,7 @@ import { DocObj } from 'docz'
|
||||
import { Docs } from 'docz'
|
||||
import styled from 'react-emotion'
|
||||
|
||||
import * as colors from '../styles/colors'
|
||||
import * as colors from '../../styles/colors'
|
||||
import { Link } from './Link'
|
||||
|
||||
const Sidebar = styled('div')`
|
||||
2
packages/docz-theme-default/src/types.d.ts
vendored
2
packages/docz-theme-default/src/types.d.ts
vendored
@@ -1,2 +1,2 @@
|
||||
declare module 'react-powerplug'
|
||||
declare module 'react-feather'
|
||||
declare module 'react-lightweight-tooltip'
|
||||
|
||||
@@ -22,7 +22,7 @@ const DefaultRender: RenderComponent = ({ component, code }) => (
|
||||
)
|
||||
|
||||
export const Playground: SFC<PlaygroundProps> = ({
|
||||
components: { Render = DefaultRender },
|
||||
components: { render: Render = DefaultRender },
|
||||
children,
|
||||
__code,
|
||||
}) => (
|
||||
|
||||
Reference in New Issue
Block a user