Skip to content

Commit

Permalink
Show onPageNav on mobile devices (#730)
Browse files Browse the repository at this point in the history
* Draft implementation of ToC (onPageNav) support for mobile devices

* Support onPageNav on tablets

* Improve tablet layout, when no onPageNav

* Add close state for toc icon

* Close onPageNav, when after navigation on mobile devices
  • Loading branch information
SleepWalker authored and yangshun committed Jun 10, 2018
1 parent c8bc00a commit 3ff24c7
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 80 deletions.
30 changes: 25 additions & 5 deletions lib/core/nav/SideNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class SideNav extends React.Component {
{this.getLocalizedCategoryString(this.props.current.category)}
</span>
</h2>
<div className="tocToggler" id="tocToggler">
<i className="icon-toc" />
</div>
</div>
<div className="navGroups">
{this.props.contents.map(this.renderCategory, this)}
Expand All @@ -37,11 +40,28 @@ class SideNav extends React.Component {
<script
dangerouslySetInnerHTML={{
__html: `
var toggler = document.getElementById('navToggler');
var nav = document.getElementById('docsNav');
toggler.onclick = function() {
nav.classList.toggle('docsSliderActive');
};
document.addEventListener('DOMContentLoaded', function() {
createToggler('#navToggler', '#docsNav', 'docsSliderActive');
createToggler('#tocToggler', 'body', 'tocActive');
const headings = document.querySelector('.toc-headings');
headings && headings.addEventListener('click', function(event) {
if (event.target.tagName === 'A') {
document.body.classList.remove('tocActive');
}
}, false);
function createToggler(togglerSelector, targetSelector, className) {
var toggler = document.querySelector(togglerSelector);
var target = document.querySelector(targetSelector);
toggler.onclick = function(event) {
event.preventDefault();
target.classList.toggle(className);
};
}
});
`,
}}
/>
Expand Down
221 changes: 146 additions & 75 deletions lib/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ header h2 {
.mainContainer {
background: #f9f9f9;
flex: 1 1 auto;
max-width: 100%;
font-size: 18px;
}
.mainContainer .wrapper {
Expand Down Expand Up @@ -1214,6 +1215,7 @@ ul#languages li {
overflow-y: auto;
-webkit-overflow-scrolling: touch;
padding-bottom: 50px;
overscroll-behavior: contain;
}

.docsNavContainer nav.toc .navBreadcrumb {
Expand All @@ -1231,27 +1233,11 @@ ul#languages li {
border: 0;
color: #393939;
}
.navBreadcrumb i {
padding: 0 4px;
}
nav.toc {
width: 240px;
}
nav.toc section {
padding: 0;
position: relative;
}
nav.toc:last-child {
padding-bottom: 100px;
}
@media only screen and (max-width: 735px) {
nav.toc {
width: 100%;
}
nav.toc:last-child {
padding-bottom: 0;
}

a.anchor {
top: -144px;
}
Expand Down Expand Up @@ -1309,6 +1295,9 @@ nav.toc .toggleNav .navToggle i::after {
width: 5px;
z-index: 10;
}
.toggleNav h2 i {
padding: 0 4px;
}
nav.toc .toggleNav .navToggle i::after {
border-width: 5px 5px 0;
margin-top: 2px;
Expand All @@ -1322,6 +1311,9 @@ nav.toc .toggleNav .navToggle i::after {
.docsSliderActive nav.toc .toggleNav .navToggle i {
opacity: 0;
}
.docsSliderActive .tocToggler {
visibility: hidden;
}
nav.toc .toggleNav .navGroup {
margin-bottom: 20px;
}
Expand Down Expand Up @@ -1364,7 +1356,8 @@ nav.toc .toggleNav ul li a:focus {
nav.toc .toggleNav ul li a.navItemActive {
color: $primaryColor;
}
.docsSliderActive nav.toc .navBreadcrumb {
.docsSliderActive nav.toc .navBreadcrumb,
.tocActive .navBreadcrumb {
border-bottom: 1px solid #ccc;
margin-bottom: 20px;
position: fixed;
Expand All @@ -1377,43 +1370,73 @@ nav.toc .toggleNav .navBreadcrumb h2 {
line-height: 32px;
margin: 0;
padding: 0;
flex-grow: 1;
}
.docsSliderActive nav.toc section .navGroups {
display: block;
}
.tocToggler {
height: 32px;
padding: 0 10px;
margin-right: -10px;
line-height: 32px;
cursor: pointer;
}
.icon-toc {
box-sizing: border-box;
position: relative;
display: inline-block;
vertical-align: middle;
line-height: normal;
top: -1px;
}
.icon-toc,
.icon-toc::before,
.icon-toc::after {
width: 4px;
height: 4px;
border: 1px solid currentColor;
background-color: currentColor;
border-radius: 50%;
box-sizing: border-box;
}
.icon-toc::before,
.icon-toc::after {
content: "";
position: absolute;
}
.icon-toc::before {
top: -7px;
left: -1px;
}
.icon-toc::after {
top: 5px;
left: -1px;
}
.tocActive .icon-toc {
transform: rotate(45deg);
width: 3px;
height: 16px;
border-radius: 0;
}
.tocActive .icon-toc::before {
top: 50%;
left: 50%;
height: 3px;
width: 16px;
border-radius: 0;
transform: translate(-50%, -50%);
}
.tocActive .icon-toc::after {
content: '';
}

@media only screen and (min-width: 736px) {
nav.toc section .navGroups {
padding: 40px 0 0;
}
.navToggle {
display: none;
}

.docsSliderActive .mainContainer {
display: block;
}

.sideNavVisible .navPusher .mainContainer {
.doc.separateOnPageNav .navPusher .mainContainer {
padding-top: 0;
max-width: 70%;
}

.docsNavContainer {
background: none;
box-sizing: border-box;
height: auto;
margin: 40px 40px 0 0;
overflow-y: auto;
position: relative;
width: 300px;
}

nav.toc section .navGroups {
display: block;
padding-top: 0px;
}

.docMainWrapper {
display: flex;
flex-flow: row nowrap;
Expand All @@ -1427,13 +1450,6 @@ nav.toc .toggleNav .navBreadcrumb h2 {
.docMainWrapper .wrapper {
padding-top: 0;
}

.docsNavContainer nav.toc .navBreadcrumb {
display: none;
}
.navBreadcrumb h2 {
padding: 0 10px;
}
}

.onPageNav {
Expand All @@ -1443,20 +1459,82 @@ nav.toc .toggleNav .navBreadcrumb h2 {
display: none;
}

.onPageNav a {
color: #717171;
}

.onPageNav ul li {
font-size: 12px;
line-height: 17px;
padding-bottom: 9px;
}

.onPageNav ul ul {
padding: 8px 0 0 20px;
}

.onPageNav ul ul li {
padding-bottom: 5px;
}

@media only screen and (min-width: 1024px) {
nav.toc {
width: 240px;
}
nav.toc section .navGroups {
display: block;
padding: 0px;
}
.docsNavContainer {
background: none;
box-sizing: border-box;
height: auto;
margin: 40px 40px 0 0;
overflow-y: auto;
position: relative;
width: 300px;
}
.docsNavContainer nav.toc .navBreadcrumb {
display: none;
}
.navBreadcrumb h2 {
padding: 0 10px;
}
}

@supports ((position: -webkit-sticky) or (position: sticky)) {
@media only screen and (min-width: 1024px) {
@media only screen and (max-width: 735px) {
.tocActive .onPageNav {
display: block;
position: fixed;
top: 148px;
background: #fff;
left: 0;
right: 0;
bottom: 0;
z-index: 10;
padding: 0 20px;
overflow-y: auto;
overscroll-behavior: contain;
}

.tocActive .navToggle,
.tocActive .navBreadcrumb h2 {
visibility: hidden;
}

.tocActive .onPageNav > .toc-headings {
padding: 12px 0;
}
}

@media only screen and (min-width: 736px) {
.separateOnPageNav.doc .wrapper,
.separateOnPageNav .headerWrapper.wrapper {
max-width: 1400px;
}

.doc.separateOnPageNav .docsNavContainer {
flex: 0 0 240px;
margin: 55px 0 0;
}

.doc.separateOnPageNav nav.toc:last-child {
padding-bottom: 0;
.doc.separateOnPageNav nav.toc {
width: auto;
}

Expand All @@ -1478,27 +1556,20 @@ nav.toc .toggleNav .navBreadcrumb h2 {
align-self: flex-start;
}

.onPageNav > ul {
.onPageNav > .toc-headings {
border-left: 1px solid #e0e0e0;
padding: 10px 0 2px 15px;
}

.onPageNav a {
color: #717171;
}

.onPageNav ul li {
font-size: 12px;
line-height: 17px;
padding-bottom: 9px;
}

.onPageNav ul ul {
padding: 8px 0 0 20px;
.tocToggler {
display: none;
}
}

.onPageNav ul ul li {
padding-bottom: 5px;
@media only screen and (min-width: 1024px) {
.doc.separateOnPageNav .docsNavContainer {
flex: 0 0 240px;
margin: 55px 0 0;
}
}
}
Expand Down Expand Up @@ -1862,7 +1933,7 @@ footer .social {
width: 100%;
box-sizing: border-box;
}

/* those make the footer sticky and work even in IE 11 */
.navPusher > :first-child {
flex-grow: 1;
Expand Down

0 comments on commit 3ff24c7

Please sign in to comment.