-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(ComponentDoc): refactor, add sidebar navigation
- Loading branch information
Alexander Fedyashov
committed
Sep 26, 2017
1 parent
0dafcf9
commit 841249b
Showing
6 changed files
with
177 additions
and
65 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 was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
docs/app/Components/ComponentDoc/ComponentSidebar/ComponentSidebar.js
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,80 @@ | ||
import _ from 'lodash' | ||
import PropTypes from 'prop-types' | ||
import React, { Component } from 'react' | ||
import { Accordion, Menu, Sticky } from 'semantic-ui-react' | ||
|
||
import { pure } from 'docs/app/HOC' | ||
import menuInfo from 'docs/app/menuInfo.json' | ||
import ComponentSideBarSection from './ComponentSidebarSection' | ||
|
||
const sidebarStyle = { | ||
background: '#fff', | ||
boxShadow: '0 2px 2px rgba(0, 0, 0, 0.1)', | ||
paddingLeft: '1em', | ||
paddingBottom: '0.1em', | ||
paddingTop: '0.1em', | ||
} | ||
|
||
class ComponentSidebar extends Component { | ||
static propTypes = { | ||
activePath: PropTypes.string, | ||
componentName: PropTypes.string, | ||
examplesRef: PropTypes.func, | ||
onItemClick: PropTypes.func, | ||
} | ||
|
||
state = {} | ||
|
||
constructor(props) { | ||
super(props) | ||
|
||
this.state = { sections: this.computeSections(props) } | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
this.setState({ sections: this.computeSections(nextProps) }) | ||
} | ||
|
||
computeSections = ({ componentName }) => _.get(menuInfo, componentName) | ||
|
||
handleItemClick = (e, { path }) => _.invoke(this.props, 'onItemClick', e, { path }) | ||
|
||
handleTitleClick = (e, { name }) => { | ||
const { sections } = this.state | ||
const { examples } = _.find(sections, { name }) | ||
const { path } = _.head(examples) | ||
|
||
_.invoke(this.props, 'onItemClick', e, { path }) | ||
} | ||
|
||
render() { | ||
const { activePath, examplesRef } = this.props | ||
const { sections } = this.state | ||
|
||
console.log(activePath, sections) | ||
return ( | ||
<Sticky context={examplesRef} offset={15}> | ||
<Menu | ||
as={Accordion} | ||
fluid | ||
style={sidebarStyle} | ||
text | ||
vertical | ||
> | ||
{_.map(sections, ({ examples, name }) => ( | ||
<ComponentSideBarSection | ||
activePath={activePath} | ||
examples={examples} | ||
key={name} | ||
name={name} | ||
onItemClick={this.handleItemClick} | ||
onTitleClick={this.handleTitleClick} | ||
/> | ||
))} | ||
</Menu> | ||
</Sticky> | ||
) | ||
} | ||
} | ||
|
||
export default pure(ComponentSidebar) |
28 changes: 28 additions & 0 deletions
28
docs/app/Components/ComponentDoc/ComponentSidebar/ComponentSidebarItem.js
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,28 @@ | ||
import _ from 'lodash' | ||
import PropTypes from 'prop-types' | ||
import React, { Component } from 'react' | ||
import { Menu } from 'semantic-ui-react' | ||
|
||
export default class ComponentSidebarItem extends Component { | ||
static propTypes = { | ||
active: PropTypes.bool, | ||
onClick: PropTypes.func, | ||
path: PropTypes.string, | ||
title: PropTypes.string, | ||
} | ||
|
||
handleClick = e => _.invoke(this.props, 'onClick', e, this.props) | ||
|
||
render() { | ||
const { active, path, title } = this.props | ||
|
||
return ( | ||
<Menu.Item | ||
active={active} | ||
content={title} | ||
name={path} | ||
onClick={this.handleClick} | ||
/> | ||
) | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
docs/app/Components/ComponentDoc/ComponentSidebar/ComponentSidebarSection.js
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,48 @@ | ||
import _ from 'lodash' | ||
import PropTypes from 'prop-types' | ||
import React, { Component } from 'react' | ||
import { Accordion, Icon, Menu } from 'semantic-ui-react' | ||
|
||
import { pure } from 'docs/app/HOC' | ||
import ComponentSidebarItem from './ComponentSidebarItem' | ||
|
||
class ComponentSidebarSection extends Component { | ||
static propTypes = { | ||
activePath: PropTypes.string, | ||
examples: PropTypes.object, | ||
name: PropTypes.string, | ||
onItemClick: PropTypes.func, | ||
onTitleClick: PropTypes.func, | ||
} | ||
|
||
handleItemClick = (e, itemProps) => _.invoke(this.props, 'onItemClick', e, itemProps) | ||
|
||
handleTitleClick = e => _.invoke(this.props, 'onTitleClick', e, this.props) | ||
|
||
render() { | ||
const { activePath, examples, name } = this.props | ||
const active = _.find(examples, { path: activePath }) | ||
|
||
return ( | ||
<Menu.Item> | ||
<Accordion.Title active={active} onClick={this.handleTitleClick}> | ||
<b>{name}</b> | ||
<Icon name='dropdown' /> | ||
</Accordion.Title> | ||
<Accordion.Content as={Menu.Menu} active={active}> | ||
{_.map(examples, ({ title, path }) => ( | ||
<ComponentSidebarItem | ||
active={activePath === path} | ||
key={path} | ||
onClick={this.handleItemClick} | ||
path={path} | ||
title={title} | ||
/> | ||
))} | ||
</Accordion.Content> | ||
</Menu.Item> | ||
) | ||
} | ||
} | ||
|
||
export default pure(ComponentSidebarSection) |
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 @@ | ||
export default from './ComponentSidebar' |