Created
March 17, 2017 12:16
-
-
Save tomdye/62f90795ed70c52e4eaf614a4271962c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { WidgetBase } from '@dojo/widget-core/WidgetBase'; | |
| import { WidgetProperties } from '@dojo/widget-core/interfaces'; | |
| import { v } from '@dojo/widget-core/d'; | |
| export interface LinkDetails { | |
| label: string; | |
| href: string; | |
| } | |
| export interface HeaderProperties extends WidgetProperties { | |
| title: string; | |
| links?: LinkDetails[]; | |
| showHeaderLinks?: boolean; | |
| } | |
| export default class Header extends WidgetBase<HeaderProperties> { | |
| render() { | |
| const { | |
| title, | |
| links = [], | |
| showHeaderLinks = false | |
| } = this.properties; | |
| const linkVNodes = links.map(({ href, label }) => v('a', { classes: { 'mdl-navigation__link': true }, href }, [ label ])); | |
| return v('div', { classes: { 'mdl-layout': true, 'mdl-js-layout': true, 'mdl-layout--fixed-header': true } }, [ | |
| v('header', { classes: { 'mdl-layout__header': true } }, [ | |
| v('div', { classes: { 'mdl-layout__header-row': true } }, [ | |
| // Title | |
| v('span', { classes: { 'mdl-layout-title': true } }, [ title ]), | |
| // Add spacer, to align navigation to the right | |
| v('div', { classes: { 'mdl-layout-spacer': true } }), | |
| // Navigation. We hide it in small screens. | |
| links.length && showHeaderLinks ? | |
| v('nav', { classes: { 'mdl-navigation': true, 'mdl-layout--large-screen-only': true } }, linkVNodes) : null | |
| ]), | |
| ]), | |
| links.length ? v('div', { classes: { 'mdl-layout__drawer': true } }, [ | |
| v('span', { classes: { 'mdl-layout-title': true } }, [ title ]), | |
| links.length ? v('nav', { classes: { 'mdl-navigation': true } }, linkVNodes) : null | |
| ]): null, | |
| v('main', { classes: { 'mdl-layout__content': true } }, [ | |
| v('div', { classes: { 'page-content': true } }, this.children ) | |
| ]), | |
| ]); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment