Skip to content

Add mobile navigation #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ declare global {
declare global {
interface HTMLSiteHeaderElement extends HTMLStencilElement {
'currentSection': string;
'isMenuOpen': boolean;
'onToggleClick': any;
}
var HTMLSiteHeaderElement: {
prototype: HTMLSiteHeaderElement;
Expand All @@ -333,14 +335,17 @@ declare global {
namespace JSXElements {
export interface SiteHeaderAttributes extends HTMLAttributes {
'currentSection'?: string;
'isMenuOpen'?: boolean;
'onToggleClick'?: any;
}
}
}


declare global {
interface HTMLSiteMenuElement extends HTMLStencilElement {

'isOpen': boolean;
'onNavigate': () => void;
}
var HTMLSiteMenuElement: {
prototype: HTMLSiteMenuElement;
Expand All @@ -359,7 +364,8 @@ declare global {
}
namespace JSXElements {
export interface SiteMenuAttributes extends HTMLAttributes {

'isOpen'?: boolean;
'onNavigate'?: () => void;
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions src/components/ionic-docs/ionic-docs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ ionic-docs {
}

site-header,
site-menu,
site-preview-app {
position: sticky;
}
Expand All @@ -59,19 +58,6 @@ site-header {
}
}

site-menu {
grid-area: menu;
top: var(--header-height);
padding: 1.75rem 0 1.75rem 2rem;
height: calc(100vh - 75px);
overflow-y: auto;

@media (max-width: $breakpoint-md) {
/* TODO: sidebar drawer */
display: none;
}
}

site-content {
padding: 1.15rem 2rem 1.75rem;
grid-area: content;
Expand Down
18 changes: 16 additions & 2 deletions src/components/ionic-docs/ionic-docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class IonicDocs {
@Element() el: Element;
@Event() sectionChanged: EventEmitter;
@State() currentSection = 'framework';
@State() isMenuOpen = false;

@Listen('docLoaded')
onDocLoaded({ detail }) {
Expand Down Expand Up @@ -36,6 +37,14 @@ export class IonicDocs {
.join(' ');
}

toggleMenu = () => {
this.isMenuOpen = !this.isMenuOpen;
}

closeMenu = () => {
this.isMenuOpen = false;
}

hostData() {
return {
class: { [`section-${this.currentSection}`]: true },
Expand All @@ -44,8 +53,13 @@ export class IonicDocs {

render() {
return [
<site-header currentSection={ this.currentSection } />,
<site-menu/>,
<site-header
currentSection={this.currentSection}
isMenuOpen={this.isMenuOpen}
onToggleClick={this.toggleMenu}/>,
<site-menu
onNavigate={this.closeMenu}
isOpen={this.isMenuOpen}/>,
<site-content/>,
<site-preview-app/>
];
Expand Down
25 changes: 25 additions & 0 deletions src/components/site-header/site-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,28 @@ site-header {
}
}

.site-nav-toggle {
background-color: transparent;
border: none;
color: inherit;
height: 1rem;
margin-right: 1em;
padding: 0;
width: 1rem;

&:focus {
outline: none;
}

@media (min-width: 700px) {
display: none;
}
}

.site-nav-toggle.is-open {
color: white;
}

.site-nav-toggle > svg {
fill: currentColor;
}
18 changes: 18 additions & 0 deletions src/components/site-header/site-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import * as constants from '../../constants';
})
export class SiteHeader {
@Prop() currentSection: string;
@Prop() onToggleClick = () => {};
@Prop() isMenuOpen: boolean;

renderGithubLink() {
if (this.currentSection === constants.SECTION_FRAMEWORK) {
Expand All @@ -21,6 +23,22 @@ export class SiteHeader {
render() {
return [
<nav>
<button
onClick={this.onToggleClick}
class={{ 'site-nav-toggle': true, 'is-open': this.isMenuOpen }}>
{ this.isMenuOpen ? (
<svg viewBox="0 0 54 54">
<rect transform="rotate(45 27 27)" y="22" width="54" height="10" rx="2"/>
<rect transform="rotate(-45 27 27)" y="22" width="54" height="10" rx="2"/>
</svg>
) : (
<svg viewBox="0 0 54 54">
<rect y="0" width="54" height="10" rx="2"/>
<rect y="22" width="54" height="10" rx="2"/>
<rect y="44" width="54" height="10" rx="2"/>
</svg>
)}
</button>
<a href="/docs" id="site-logo">
<svg viewBox="0 0 433 144">
<title>Ionic Docs</title>
Expand Down
23 changes: 22 additions & 1 deletion src/components/site-menu/site-menu.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
/* @import 'src/styles/variables'; */
@import './version-dropdown';

site-menu {
grid-area: menu;
height: calc(100vh - var(--header-height));
overflow-y: auto;
padding: 1.75rem 0 1.75rem 2rem;
position: sticky;
top: var(--header-height);

@media (max-width: 700px) {
background-color: white;
position: fixed;
right: 100%;
transition: transform 400ms cubic-bezier(0.190,1,0.220,1);
width: 100%;
z-index: 1;

&.is-open {
transform: translateX(100%);
}
}
}

site-menu ul {
list-style: none;
margin: 0;
Expand Down
17 changes: 15 additions & 2 deletions src/components/site-menu/site-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, State } from '@stencil/core';
import { Component, Prop, State } from '@stencil/core';
import VersionDropdown from './version-dropdown';
import menuMap from './site-menu-map';
import { versions } from '../../versions';
Expand All @@ -9,6 +9,8 @@ import { versions } from '../../versions';
})
export class SiteMenu {

@Prop() onNavigate: () => void;
@Prop() isOpen: boolean;
@State() activeItem: string;
@State() version = versions[versions.length - 1];

Expand All @@ -30,7 +32,7 @@ export class SiteMenu {
return (
<li role="none">
<stencil-route-link exact url={url}
onClick={ isTopLevel ? () => this.setActiveItem(text) : null }
onClick={() => this.handleNavigate(text, isTopLevel)}
anchor-title={text}
anchor-role="menuitem">
{text}
Expand Down Expand Up @@ -59,10 +61,21 @@ export class SiteMenu {
);
}

handleNavigate = (text, isTopLevel) => {
if (isTopLevel) this.setActiveItem(text);
this.onNavigate();
}

setActiveItem(text: string) {
this.activeItem = this.activeItem === text ? null : text;
}

hostData() {
return {
'class': { 'is-open': this.isOpen }
};
}

render() {
return [
<VersionDropdown
Expand Down