Skip to content

Commit 9b0c7bd

Browse files
committed
Merge pull request #137 from bhamodi/master
Implemented state awareness for the sidebar.
2 parents 44e3212 + 0617dae commit 9b0c7bd

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

docs/TODO.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
- [ ] scaffold design patterns/examples area
99
- [ ] mobile side navbar
1010
- [ ] build pipeline for examples, create example component, possibly with code editing
11-
- [ ] add active state to Docs side bar. (currently doesn't show which tab is active/selected)
11+
- [x] add active state to Docs side bar. (currently doesn't show which tab is active/selected)

docs/sass/main.scss

+5
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,12 @@ pre code.hljs {
255255
.sidebar-links {
256256
&--item {
257257
line-height: 1.2em;
258+
margin-top: 1em;
258259
margin-bottom: 1em;
259260
}
261+
&--item-active {
262+
background-color: #E8E4E4;
263+
padding: 1em;
264+
}
260265
}
261266

docs/src/main.js

+15
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,24 @@ addScrollClass("scrolled")
66

77
render(ItemFilterExample, 'item-filter-example')
88

9+
updateSideBar()
10+
911
function render(component, id) {
1012
var el = document.getElementById(id)
1113
if (el) {
1214
React.render(React.createElement(ItemFilterExample), el)
1315
}
1416
}
17+
18+
function updateSideBar() {
19+
var sideBarElements = document.getElementsByClassName('sidebar-links--item')
20+
for (var i in sideBarElements) {
21+
if (sideBarElements[i].firstChild) {
22+
if (window.location.href === sideBarElements[i].firstChild.href) {
23+
sideBarElements[i].className = 'sidebar-links--item-active'
24+
} else {
25+
sideBarElements[i].className = 'sidebar-links--item'
26+
}
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)