Skip to content

Commit 1d03ea8

Browse files
authored
Feature/add version to sidebar (#395)
* feat(sidebar): add version in desktop sidebar * feat(sidebar): update bottom margin * Update sidebar.jsx remove unused var * fix(sidebar): fix index pages missing from section and fix layout
1 parent c8d2eed commit 1d03ea8

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

components/sidebar-item/sidebar-item-style.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
margin: 0.5em 0 1em;
3535
}
3636

37+
&__version {
38+
margin-bottom: 10px;
39+
}
40+
3741
&__anchor {
3842
margin:0.25em 0;
3943

components/sidebar-mobile/sidebar-mobile-style.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@
6363
text-transform: uppercase;
6464
color: getColor(mine-shaft);
6565
margin: 1em 16px 0.25em;
66+
67+
&--block {
68+
display: block;
69+
}
70+
71+
&:active,
72+
&--active {
73+
color: getColor(malibu);
74+
}
6675
}
6776

6877
.sidebar-mobile__page {

components/sidebar-mobile/sidebar-mobile.jsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,29 @@ export default class SidebarMobile extends React.Component {
5858
* @return {array} - Markup containing sections and links
5959
*/
6060
_getSections() {
61-
return this.props.sections.map(section => (
62-
<div key={ section.url }>
63-
<h3 className='sidebar-mobile__section'>{ section.title }</h3>
64-
{ this._getPages(section.pages) }
65-
</div>
66-
));
61+
let pathname = '';
62+
63+
if (typeof window !== 'undefined') {
64+
pathname = window.location.pathname;
65+
}
66+
67+
return this.props.sections.map(section => {
68+
let active = pathname === section.url || pathname.includes(`/${section.url}`),
69+
absoluteUrl = `/${section.url}`;
70+
return (
71+
<div key={ absoluteUrl }>
72+
<Link
73+
className={ `sidebar-mobile__section sidebar-mobile__section--block ${active ? 'sidebar-mobile__section--active' : ''}` }
74+
key={ absoluteUrl }
75+
to={ absoluteUrl }
76+
onClick={ this._close.bind(this) }>
77+
<h3>{ section.title }</h3>
78+
</Link>
79+
80+
{ this._getPages(section.pages) }
81+
</div>
82+
);
83+
});
6784
}
6885

6986
/**

components/sidebar/sidebar.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ export default props => {
88
return (
99
<nav className="sidebar">
1010
<div className="sidebar__inner">
11+
<h3 className="sidebar-item__version">Version 2.1</h3>
1112
<SidebarItem
1213
url={ `/${sectionName}` }
1314
title="Introduction"
1415
currentPage= { currentPage }
1516
/>
16-
1717
{
1818
pages.map(({ url, title, anchors }, i) =>
1919
<SidebarItem

0 commit comments

Comments
 (0)