-
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
Organize doc menu into groups #110
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,63 @@ | ||
import _ from 'lodash'; | ||
import React, {Component} from 'react'; | ||
import stardust, {Menu, MenuItem, Input} from 'stardust'; | ||
import META from 'src/utils/Meta'; | ||
|
||
export default class Sidebar extends Component { | ||
state = {query: ''}; | ||
|
||
handleSearchChange = e => this.setState({query: e.target.value}); | ||
|
||
getComponentsByQuery() { | ||
return _.filter(stardust, component => { | ||
const name = component._meta.name; | ||
const isParent = META.isParent(component); | ||
const isQueryMatch = new RegExp(this.state.query, 'i').test(name); | ||
return isParent && isQueryMatch; | ||
}); | ||
} | ||
|
||
getComponentsByType = type => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method builds a submenu for each section, like: Elements
Only parent elements are included in the menu. For instance, Modal, but not its child components ModalHeader, ModalContent, etc. |
||
const items = _(this.getComponentsByQuery()) | ||
.filter(component => META.isType(component, type)) | ||
.sortBy((component, name) => name) | ||
.map(component => { | ||
const name = component._meta.name; | ||
return <MenuItem key={name} name={name} href={`#${name}`} />; | ||
}) | ||
.value(); | ||
|
||
const subMenu = ( | ||
<div className='item'> | ||
<div className='header'>{_.capitalize(type)}s</div> | ||
<div className='menu'>{items}</div> | ||
</div> | ||
); | ||
|
||
return items && subMenu; | ||
}; | ||
|
||
render() { | ||
const menuItems = Object.keys(stardust) | ||
.sort() | ||
.filter(name => new RegExp(this.state.query, 'i').test(name)) | ||
.map(name => <MenuItem key={name} name={name} href={`#${name}`} />); | ||
const elements = this.getComponentsByType(META.type.element); | ||
const collections = this.getComponentsByType(META.type.collection); | ||
const views = this.getComponentsByType(META.type.view); | ||
const modules = this.getComponentsByType(META.type.module); | ||
|
||
return ( | ||
<Menu className='small inverted secondary vertical pointing fluid'> | ||
<Menu className='inverted secondary vertical fluid' style={{margin: 0}}> | ||
<MenuItem> | ||
<Input | ||
className='small transparent inverted' | ||
className='transparent inverted icon' | ||
icon='search' | ||
placeholder='Search' | ||
iconClass='search link icon' | ||
onChange={this.handleSearchChange} | ||
/> | ||
</MenuItem> | ||
{menuItems} | ||
{elements} | ||
{collections} | ||
{views} | ||
{modules} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Order all the submenus. |
||
</Menu> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ export default class Menu extends Component { | |
const activeItemName = !hasActiveItem && i === 0 | ||
? child.props.name | ||
: this.state.activeItem || this.props.activeItem; | ||
return React.cloneElement(child, { | ||
return child && React.cloneElement(child, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The menu component cannot clone the child if it doesn't exist. When filtering the doc site menu by search we we're getting errors. Now, we skip cloning and updating menu children if the child is falsy. |
||
activeItem: activeItemName, | ||
callbackParent: this.handleClickItem, | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,6 @@ export default class MenuItem extends Component { | |
const classes = classNames( | ||
'sd-menu-item', | ||
this.props.className, | ||
'blue', | ||
'item', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed default color class on menu item, this should be up to the consumer. |
||
{active: isActive} | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ export default class Buttons extends Component { | |
library: META.library.semanticUI, | ||
name: 'Buttons', | ||
type: META.type.element, | ||
parent: 'Button' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Buttons is not a top level component, but a child to the Button component. This prevents it from showing in the menu. |
||
}; | ||
|
||
render() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import _ from 'lodash'; | ||
|
||
/** | ||
* Component meta information. Used to declaratively classify and identify components. | ||
* @type {{}} | ||
|
@@ -28,9 +30,14 @@ const META = { | |
isElement: ({_meta}) => _meta.type === META.type.element, | ||
isView: ({_meta}) => _meta.type === META.type.view, | ||
isModule: ({_meta}) => _meta.type === META.type.module, | ||
isType: ({_meta}, type) => _meta.type === type, | ||
|
||
// parent | ||
isChild: ({_meta}) => !!_meta.parent, | ||
isParent: (component) => ( | ||
// has no 'parent' or 'parent' is self | ||
!_.has(component, '_meta.parent') || _.get(component, '_meta.parent') === component._meta.name | ||
), | ||
isChild: component => !META.isParent(component), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extended META to include helper method for identifying a parent component and a component with a type string. |
||
}; | ||
|
||
export default META; |
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.
Pulled menu item filtering into separate methods.