Skip to content

Commit cc38748

Browse files
authored
Docs/update nav bar (#886)
* Update navbar with components hierarchy * remove warning * fix hover coloring * verify window exist - fix deploy
1 parent 9dfec66 commit cc38748

File tree

3 files changed

+98
-51
lines changed

3 files changed

+98
-51
lines changed

uilib-docs/src/components/Navbar.js renamed to uilib-docs/src/components/navbar/index.js

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,29 @@ import PropTypes from 'prop-types';
55
import Link from 'gatsby-link';
66
import _ from 'lodash';
77

8-
import './navbar.scss';
9-
import searchIcon from '../images/search.svg';
8+
import './index.scss';
9+
import searchIcon from '../../images/search.svg';
10+
import Item from './item';
1011

1112
class Navbar extends Component {
12-
static propTypes = {
13-
components: PropTypes.array
14-
};
15-
16-
constructor(props) {
17-
super(props);
18-
19-
this.setFilter = this.setFilter.bind(this);
20-
}
21-
2213
state = {
2314
filter: ''
2415
};
2516

26-
setFilter({target: {value}}) {
17+
setFilter = ({target: {value}}) => {
2718
this.setState({filter: value});
28-
}
19+
};
20+
21+
getCurrentPage = () => {
22+
if (typeof window !== 'undefined') {
23+
const path = window.location.href;
24+
return _.chain(path)
25+
.split('/')
26+
.filter(item => !_.isEmpty(item))
27+
.last()
28+
.value();
29+
}
30+
};
2931

3032
getMarkdownPages(data) {
3133
const markdownPages = data.allFile.edges;
@@ -48,35 +50,38 @@ class Navbar extends Component {
4850
}
4951

5052
renderNavbar = data => {
53+
const currentPage = this.getCurrentPage();
5154
const {filter} = this.state;
5255
const markdowns = this.getMarkdownPages(data);
5356
const components = this.getNavbarComponents(data);
5457

5558
const filteredComponents = _.filter(components, component =>
56-
_.includes(_.lowerCase(component.node.displayName), _.lowerCase(filter)));
59+
_.includes(_.lowerCase(component.node.displayName), _.lowerCase(filter))
60+
);
61+
62+
const componentsByGroups = _.groupBy(
63+
filteredComponents,
64+
c => _.split(c.node.displayName, '.')[0]
65+
);
66+
5767
return (
5868
<div className="navbar">
5969
<div className="search">
60-
<img src={searchIcon}/>
61-
<input placeholder="Search..." onChange={this.setFilter}/>
70+
<img src={searchIcon} />
71+
<input placeholder="Search..." onChange={this.setFilter} />
6272
</div>
6373
<ul>
6474
{_.map(markdowns, page => {
65-
return (
66-
<li>
67-
<Link to={page.path}>{page.title}</Link>
68-
</li>
69-
);
75+
return <Item id={page.title} link={page.path} />;
7076
})}
71-
<li className="separator"/>
72-
{_.map(filteredComponents, (component, index) => {
77+
<li className="separator" />
78+
{_.map(componentsByGroups, (components, key) => {
7379
return (
74-
<li key={index}>
75-
<Link key={component.node.displayName} to={`/docs/${component.node.displayName}/`}>
76-
{component.node.displayName}
77-
{/* {component.node.isPublic && <span className="public">public</span>} */}
78-
</Link>
79-
</li>
80+
<Item
81+
id={key}
82+
components={components}
83+
currentPage={currentPage}
84+
></Item>
8085
);
8186
})}
8287
</ul>

uilib-docs/src/components/Navbar.scss renamed to uilib-docs/src/components/navbar/index.scss

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "src/styles/constants";
1+
@import 'src/styles/constants';
22

33
.navbar {
44
position: fixed;
@@ -28,7 +28,6 @@
2828
img {
2929
display: inline;
3030
height: 16px;
31-
// filter: invert(1); // turn to white
3231
}
3332

3433
input {
@@ -52,44 +51,46 @@
5251
list-style-type: none;
5352
padding: 0;
5453
margin: 0;
55-
56-
.list-header {
57-
// background-color: $dark40;
58-
color: $white;
59-
padding: 4px 0;
60-
}
6154
}
6255

6356
li {
6457
position: relative;
6558
border-radius: 10px;
6659
cursor: pointer;
6760
transition: all 0.2s;
68-
margin: 1px 0;
61+
padding: 12px 8px;
62+
margin-bottom: 2px;
6963

70-
&.separator {
71-
height: 1px;
72-
background-color: $white;
73-
width: 100%;
74-
margin: 8px 0;
64+
&:hover > a > .entry {
65+
color: $yellow20;
7566
}
7667

77-
a {
68+
.entry {
7869
color: $white;
7970
font-size: $text50;
80-
font-weight: 500;
81-
padding: 8px;
71+
font-weight: 600;
8272
line-height: 1.4;
8373
width: 100%;
8474
display: inline-block;
8575
text-decoration: none;
86-
margin-bottom: 2px;
87-
}
8876

89-
&:hover {
90-
a {
77+
&.selected {
9178
color: $yellow20;
79+
font-weight: 600;
9280
}
9381
}
82+
83+
.nested {
84+
border-left: 1px solid $white;
85+
margin-top: 10px;
86+
padding-left: 10px;
87+
}
88+
89+
&.separator {
90+
border-bottom: 1px solid $white;
91+
width: 100%;
92+
margin: 8px 0;
93+
padding: 0;
94+
}
9495
}
9596
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import Link from 'gatsby-link';
3+
import _ from 'lodash';
4+
import classnames from 'classnames';
5+
6+
export default ({id, link, components, currentPage}) => {
7+
const hasChildren = _.size(components) > 1;
8+
if (!hasChildren) {
9+
return <ItemEntry id={id} link={link} currentPage={currentPage} />;
10+
} else {
11+
return (
12+
<li key={id}>
13+
<Link key={id} to={`/docs/${id}/`}>
14+
<span class={classnames('entry', {selected: id === currentPage})}>
15+
{id}
16+
</span>
17+
</Link>
18+
19+
<ul class="nested">
20+
{_.map(_.drop(components, 1), c => {
21+
return (
22+
<ItemEntry id={c.node.displayName} currentPage={currentPage} />
23+
);
24+
})}
25+
</ul>
26+
</li>
27+
);
28+
}
29+
};
30+
31+
const ItemEntry = ({id, link, currentPage}) => {
32+
return (
33+
<li key={id}>
34+
<Link key={id} to={link || `/docs/${id}/`}>
35+
<span class={classnames('entry', {selected: id === currentPage})}>
36+
{id}
37+
</span>
38+
</Link>
39+
</li>
40+
);
41+
};

0 commit comments

Comments
 (0)