-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(ComponentSidebar): add sidebar navigation #2070
Merged
Merged
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c9740a2
docs(ComponentDoc): refactor, add sidebar navigation
b73631e
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
0dafcf9
docs(ComponentDoc): refactor, add sidebar navigation
da68908
docs(ComponentDoc): refactor, add sidebar navigation
d2f3d47
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
layershifter 5a483cf
docs(Sidebar): merge changes, cleanups
layershifter 7ecadac
refactor(DocsLayout): make sidebar opt-in
levithomason 411c2bd
fix(ComponentExample): use props.location vs window
levithomason 310c6b1
fix(DocsLayout): use props.location vs window
levithomason a72b89a
feat(ComponentControls): snappier menu hover transition
levithomason 38aef16
feat(ComponentDoc): more whitespace for examples
levithomason c34bd61
fix(scrollToAnchor): stop scrolling when unable to scroll
levithomason 4dfed3b
fix(ComponentExample): toggle isActive on hash change
levithomason fc8e626
feat(ComponentSidebar): allow toggle open
levithomason 3de7577
fix(ComponentExample): no hash only if !code && !html
levithomason 1b1f5b3
fix(ComponentExample): show controls on mouse move
levithomason 206b54c
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
layershifter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
coverage/ | ||
dist/ | ||
docs/app/docgenInfo.json | ||
docs/app/menuInfo.json | ||
docs/build/ | ||
dll/ | ||
node_modules/ |
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,56 +1,115 @@ | ||
import _ from 'lodash' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import React, { Component } from 'react' | ||
import DocumentTitle from 'react-document-title' | ||
import { withRouter } from 'react-router' | ||
import { Grid } from 'semantic-ui-react' | ||
|
||
import { withDocInfo } from 'docs/app/HOC' | ||
import { scrollToAnchor } from 'docs/app/utils' | ||
import ComponentDocHeader from './ComponentDocHeader' | ||
import ComponentDocLinks from './ComponentDocLinks' | ||
import ComponentDocSee from './ComponentDocSee' | ||
import ComponentExamples from './ComponentExamples' | ||
import ComponentProps from './ComponentProps' | ||
import ComponentSidebar from './ComponentSidebar' | ||
|
||
const ComponentDoc = ({ componentGroup, componentName, description, ghLink, path, seeItems, suiLink }) => ( | ||
<DocumentTitle title={`${componentName} | Semantic UI React`}> | ||
<div> | ||
<Grid padded columns='1'> | ||
<Grid.Column> | ||
<ComponentDocHeader componentName={componentName} description={description} /> | ||
<ComponentDocSee items={seeItems} /> | ||
<ComponentDocLinks | ||
componentName={componentName} | ||
ghLink={ghLink} | ||
path={path} | ||
suiLink={suiLink} | ||
/> | ||
<ComponentProps componentGroup={componentGroup} componentName={componentName} /> | ||
</Grid.Column> | ||
</Grid> | ||
|
||
<ComponentExamples componentName={componentName} /> | ||
</div> | ||
</DocumentTitle> | ||
) | ||
|
||
ComponentDoc.propTypes = { | ||
componentGroup: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
description: PropTypes.string, | ||
props: PropTypes.object, | ||
}), | ||
), | ||
componentName: PropTypes.string.isRequired, | ||
description: PropTypes.string, | ||
ghLink: PropTypes.string.isRequired, | ||
path: PropTypes.string.isRequired, | ||
seeItems: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
description: PropTypes.string, | ||
name: PropTypes.string, | ||
type: PropTypes.string, | ||
}), | ||
).isRequired, | ||
suiLink: PropTypes.string, | ||
const topRowStyle = { margin: '1em' } | ||
|
||
class ComponentDoc extends Component { | ||
static childContextTypes = { | ||
onPassed: PropTypes.func, | ||
} | ||
|
||
static propTypes = { | ||
componentGroup: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
description: PropTypes.string, | ||
props: PropTypes.object, | ||
}), | ||
), | ||
componentName: PropTypes.string.isRequired, | ||
description: PropTypes.string, | ||
ghLink: PropTypes.string.isRequired, | ||
history: PropTypes.object.isRequired, | ||
path: PropTypes.string.isRequired, | ||
seeItems: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
description: PropTypes.string, | ||
name: PropTypes.string, | ||
type: PropTypes.string, | ||
}), | ||
).isRequired, | ||
suiLink: PropTypes.string, | ||
} | ||
|
||
state = {} | ||
|
||
getChildContext() { | ||
return { | ||
onPassed: this.handleExamplePassed, | ||
} | ||
} | ||
|
||
componentWillReceiveProps({ componentName: next }) { | ||
const { componentName: current } = this.props | ||
|
||
if (current !== next) this.setState({ activePath: undefined }) | ||
} | ||
|
||
handleExamplePassed = (e, { examplePath }) => this.setState({ activePath: examplePath }) | ||
|
||
handleExamplesRef = examplesRef => this.setState({ examplesRef }) | ||
|
||
handleSidebarItemClick = (e, { path }) => { | ||
const { history } = this.props | ||
const aPath = _.kebabCase(_.last(path.split('/'))) | ||
|
||
history.replace(`${location.pathname}#${aPath}`) | ||
scrollToAnchor() | ||
} | ||
|
||
render() { | ||
const { componentGroup, componentName, description, ghLink, path, seeItems, suiLink } = this.props | ||
const { activePath, examplesRef } = this.state | ||
|
||
return ( | ||
<DocumentTitle title={`${componentName} | Semantic UI React`}> | ||
<Grid> | ||
<Grid.Row columns='equal' style={topRowStyle}> | ||
<Grid.Column> | ||
<ComponentDocHeader componentName={componentName} description={description} /> | ||
<ComponentDocSee items={seeItems} /> | ||
<ComponentDocLinks | ||
componentName={componentName} | ||
ghLink={ghLink} | ||
path={path} | ||
suiLink={suiLink} | ||
/> | ||
<ComponentProps componentGroup={componentGroup} componentName={componentName} /> | ||
</Grid.Column> | ||
<Grid.Column computer={5} largeScreen={4} widescreen={4} /> | ||
</Grid.Row> | ||
|
||
<Grid.Row columns='equal'> | ||
<Grid.Column> | ||
<div ref={this.handleExamplesRef}> | ||
<ComponentExamples componentName={componentName} /> | ||
</div> | ||
</Grid.Column> | ||
<Grid.Column computer={5} largeScreen={4} widescreen={4}> | ||
<ComponentSidebar | ||
activePath={activePath} | ||
componentName={componentName} | ||
examplesRef={examplesRef} | ||
onItemClick={this.handleSidebarItemClick} | ||
/> | ||
</Grid.Column> | ||
</Grid.Row> | ||
</Grid> | ||
</DocumentTitle> | ||
) | ||
} | ||
} | ||
|
||
export default withDocInfo(ComponentDoc) | ||
export default withDocInfo(withRouter(ComponentDoc)) |
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
78 changes: 78 additions & 0 deletions
78
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,78 @@ | ||
import _ from 'lodash' | ||
import PropTypes from 'prop-types' | ||
import React, { Component } from 'react' | ||
import { Accordion, Menu, Sticky } from 'semantic-ui-react' | ||
|
||
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 | ||
|
||
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 ComponentSidebar |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small optimization. Without it, all examples will be rerendered