Skip to content

Commit 578963f

Browse files
committed
Merge pull request #110 from TechnologyAdvice/feature/menu-hierarchy
Organize doc menu into groups
2 parents 4031d69 + b210c4a commit 578963f

File tree

5 files changed

+52
-10
lines changed

5 files changed

+52
-10
lines changed

docs/app/Components/Sidebar/Sidebar.js

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,63 @@
1+
import _ from 'lodash';
12
import React, {Component} from 'react';
23
import stardust, {Menu, MenuItem, Input} from 'stardust';
4+
import META from 'src/utils/Meta';
35

46
export default class Sidebar extends Component {
57
state = {query: ''};
68

79
handleSearchChange = e => this.setState({query: e.target.value});
810

11+
getComponentsByQuery() {
12+
return _.filter(stardust, component => {
13+
const name = component._meta.name;
14+
const isParent = META.isParent(component);
15+
const isQueryMatch = new RegExp(this.state.query, 'i').test(name);
16+
return isParent && isQueryMatch;
17+
});
18+
}
19+
20+
getComponentsByType = type => {
21+
const items = _(this.getComponentsByQuery())
22+
.filter(component => META.isType(component, type))
23+
.sortBy((component, name) => name)
24+
.map(component => {
25+
const name = component._meta.name;
26+
return <MenuItem key={name} name={name} href={`#${name}`} />;
27+
})
28+
.value();
29+
30+
const subMenu = (
31+
<div className='item'>
32+
<div className='header'>{_.capitalize(type)}s</div>
33+
<div className='menu'>{items}</div>
34+
</div>
35+
);
36+
37+
return items && subMenu;
38+
};
39+
940
render() {
10-
const menuItems = Object.keys(stardust)
11-
.sort()
12-
.filter(name => new RegExp(this.state.query, 'i').test(name))
13-
.map(name => <MenuItem key={name} name={name} href={`#${name}`} />);
41+
const elements = this.getComponentsByType(META.type.element);
42+
const collections = this.getComponentsByType(META.type.collection);
43+
const views = this.getComponentsByType(META.type.view);
44+
const modules = this.getComponentsByType(META.type.module);
1445

1546
return (
16-
<Menu className='small inverted secondary vertical pointing fluid'>
47+
<Menu className='inverted secondary vertical fluid' style={{margin: 0}}>
1748
<MenuItem>
1849
<Input
19-
className='small transparent inverted'
50+
className='transparent inverted icon'
51+
icon='search'
2052
placeholder='Search'
2153
iconClass='search link icon'
2254
onChange={this.handleSearchChange}
2355
/>
2456
</MenuItem>
25-
{menuItems}
57+
{elements}
58+
{collections}
59+
{views}
60+
{modules}
2661
</Menu>
2762
);
2863
}

src/collections/Menu/Menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default class Menu extends Component {
3434
const activeItemName = !hasActiveItem && i === 0
3535
? child.props.name
3636
: this.state.activeItem || this.props.activeItem;
37-
return React.cloneElement(child, {
37+
return child && React.cloneElement(child, {
3838
activeItem: activeItemName,
3939
callbackParent: this.handleClickItem,
4040
});

src/collections/Menu/MenuItem.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export default class MenuItem extends Component {
3636
const classes = classNames(
3737
'sd-menu-item',
3838
this.props.className,
39-
'blue',
4039
'item',
4140
{active: isActive}
4241
);

src/elements/Button/Buttons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default class Buttons extends Component {
1212
library: META.library.semanticUI,
1313
name: 'Buttons',
1414
type: META.type.element,
15+
parent: 'Button'
1516
};
1617

1718
render() {

src/utils/Meta.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import _ from 'lodash';
2+
13
/**
24
* Component meta information. Used to declaratively classify and identify components.
35
* @type {{}}
@@ -28,9 +30,14 @@ const META = {
2830
isElement: ({_meta}) => _meta.type === META.type.element,
2931
isView: ({_meta}) => _meta.type === META.type.view,
3032
isModule: ({_meta}) => _meta.type === META.type.module,
33+
isType: ({_meta}, type) => _meta.type === type,
3134

3235
// parent
33-
isChild: ({_meta}) => !!_meta.parent,
36+
isParent: (component) => (
37+
// has no 'parent' or 'parent' is self
38+
!_.has(component, '_meta.parent') || _.get(component, '_meta.parent') === component._meta.name
39+
),
40+
isChild: component => !META.isParent(component),
3441
};
3542

3643
export default META;

0 commit comments

Comments
 (0)