-
-
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.
chore(docz-theme-default): refac to use new docz links and preview
- Loading branch information
1 parent
c82f41b
commit b1a84f8
Showing
8 changed files
with
181 additions
and
157 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
124 changes: 124 additions & 0 deletions
124
packages/docz-theme-default/src/modules/Sidebar/Menu.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,124 @@ | ||
import * as React from 'react' | ||
import { rem } from 'polished' | ||
import { SFC } from 'react' | ||
import { Entry, Link } from 'docz' | ||
import { Toggle } from 'react-powerplug' | ||
import { ChevronDown } from 'react-feather' | ||
import styled, { css } from 'react-emotion' | ||
|
||
import * as colors from '../../styles/colors' | ||
|
||
const Wrapper = styled('div')` | ||
display: flex; | ||
flex-direction: column; | ||
` | ||
|
||
export const menuStyle = css` | ||
position: relative; | ||
display: block; | ||
padding: ${rem(20)} ${rem(30)}; | ||
border-bottom: 1px solid ${colors.border}; | ||
background: white; | ||
font-size: 18px; | ||
color: ${colors.steel}; | ||
&:hover, | ||
&:visited { | ||
color: ${colors.steel}; | ||
} | ||
` | ||
|
||
const Toggler = styled('a')` | ||
${menuStyle}; | ||
` | ||
|
||
interface IconProps { | ||
opened: boolean | ||
} | ||
|
||
const Icon = styled<IconProps, 'div'>('div')` | ||
position: absolute; | ||
top: 50%; | ||
right: 20px; | ||
transform: translateY(-50%) rotate(${p => (p.opened ? '-180deg' : '0deg')}); | ||
transform-origin: 50% 50%; | ||
transition: transform 0.3s; | ||
& svg { | ||
stroke: ${colors.steel}; | ||
} | ||
` | ||
|
||
const List = styled('dl')` | ||
margin: 0; | ||
padding: 0; | ||
background: ${colors.snow}; | ||
a { | ||
padding: 10px ${rem(30)}; | ||
display: block; | ||
position: relative; | ||
border-bottom: 1px solid ${colors.border}; | ||
color: ${colors.silver}; | ||
font-size: ${rem(15)}; | ||
} | ||
a:before { | ||
position: absolute; | ||
content: ''; | ||
top: 0; | ||
left: 0; | ||
width: 4px; | ||
height: 100%; | ||
background: ${colors.purple}; | ||
transform: scaleX(0); | ||
transform-origin: 0 50%; | ||
transition: transform 0.3s; | ||
} | ||
a.hover::before, | ||
a.active:before { | ||
transform: scaleX(1); | ||
} | ||
` | ||
|
||
export interface MenuProps { | ||
menu: string | ||
docs: Entry[] | ||
} | ||
|
||
const isActive = (match: any, location: any) => | ||
match && match.url === location.pathname | ||
|
||
export const Menu: SFC<MenuProps> = ({ menu, docs }) => ( | ||
<Toggle initial={false}> | ||
{({ on, toggle }: any) => { | ||
const handleToggle = (ev: React.SyntheticEvent<any>) => { | ||
ev.preventDefault() | ||
toggle() | ||
} | ||
|
||
return ( | ||
<Wrapper> | ||
<Toggler href="#" onClick={handleToggle}> | ||
{menu} | ||
<Icon opened={on}> | ||
<ChevronDown size={15} /> | ||
</Icon> | ||
</Toggler> | ||
{on && ( | ||
<List> | ||
{docs.map(doc => ( | ||
<dt key={doc.id}> | ||
<Link isActive={isActive} to={doc.slug}> | ||
{doc.name} | ||
</Link> | ||
</dt> | ||
))} | ||
</List> | ||
)} | ||
</Wrapper> | ||
) | ||
}} | ||
</Toggle> | ||
) |
88 changes: 31 additions & 57 deletions
88
packages/docz-theme-default/src/modules/Sidebar/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 |
---|---|---|
@@ -1,70 +1,44 @@ | ||
import React, { Fragment, SFC } from 'react' | ||
import { DocObj } from 'docz' | ||
import { Docs } from 'docz' | ||
import React from 'react' | ||
import { Docs, Link as BaseLink, Entry } from 'docz' | ||
import styled from 'react-emotion' | ||
|
||
import * as colors from '../../styles/colors' | ||
import { Link } from './Link' | ||
import { Menu, menuStyle } from './Menu' | ||
|
||
const Sidebar = styled('div')` | ||
padding: 15px 0; | ||
width: 200px; | ||
height: 100vh; | ||
const Wrapper = styled('div')` | ||
width: 320px; | ||
height: 100%; | ||
border-right: 1px solid ${colors.border}; | ||
background: ${colors.snow}; | ||
` | ||
|
||
const List = styled('ul')` | ||
list-style: none; | ||
padding: 0; | ||
margin: 5px 0; | ||
& ~ & { | ||
margin-top: 10px; | ||
} | ||
` | ||
|
||
const Category = styled('li')` | ||
padding: 0 20px; | ||
margin: 20px 0 5px; | ||
font-size: 12px; | ||
font-weight: 600; | ||
text-transform: uppercase; | ||
color: ${colors.steel}; | ||
const Link = styled(BaseLink)` | ||
${menuStyle}; | ||
` | ||
|
||
interface LinksProps { | ||
docs: DocObj[] | ||
} | ||
|
||
const Links: SFC<LinksProps> = ({ docs }) => ( | ||
<Fragment> | ||
{docs.map(doc => ( | ||
<li key={doc.id}> | ||
<Link to={doc.route}>{doc.name}</Link> | ||
</li> | ||
))} | ||
</Fragment> | ||
) | ||
|
||
export const Menu = () => ( | ||
export const Sidebar = () => ( | ||
<Docs> | ||
{({ categories, docs }) => ( | ||
<Sidebar> | ||
<List> | ||
<Links docs={docs.filter(doc => !doc.category)} /> | ||
{categories.map(category => ( | ||
<Fragment key={category}> | ||
<Category>{category}</Category> | ||
<Links | ||
docs={docs.filter( | ||
doc => doc.category && doc.category === category | ||
)} | ||
/> | ||
</Fragment> | ||
{({ docs, menus }) => { | ||
const docsWithoutMenu = docs.filter((doc: Entry) => !doc.menu) | ||
|
||
return ( | ||
<Wrapper> | ||
{docsWithoutMenu.map(doc => ( | ||
<Link key={doc.id} to={doc.slug}> | ||
{doc.name} | ||
</Link> | ||
))} | ||
</List> | ||
</Sidebar> | ||
)} | ||
{menus.map( | ||
menu => | ||
menu && ( | ||
<Menu | ||
key={menu} | ||
menu={menu} | ||
docs={docs.filter(doc => doc.menu && doc.menu === menu)} | ||
/> | ||
) | ||
)} | ||
</Wrapper> | ||
) | ||
}} | ||
</Docs> | ||
) |
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,2 +1,3 @@ | ||
declare module 'react-feather' | ||
declare module 'react-powerplug' | ||
declare module 'react-lightweight-tooltip' |