Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
feat(drawer): Improved navigation drawer (#3417)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Drawer variants have new DOM structure, mixins, and JS. MDCPersistentDrawer and MDCTemporaryDrawer components are replaced with a single MDCDrawer component which supports both.
  • Loading branch information
abhiomkar authored Aug 25, 2018
1 parent 108f9ea commit 3aa211d
Show file tree
Hide file tree
Showing 68 changed files with 3,125 additions and 5,124 deletions.
2 changes: 1 addition & 1 deletion closure_externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
* @see http://npmjs.com/focus-trap
*/

goog.provide('mdc.thirdparty.focusTrap')
goog.provide('mdc.thirdparty.focusTrap');

/**
* @typedef {{
Expand Down
207 changes: 207 additions & 0 deletions demos/drawer/dismissible-drawer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
<!DOCTYPE html>
<!--
Copyright 2018 Google Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<html>
<head>
<meta charset="utf-8">
<title>Dismissible Drawer - Material Components Catalog</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="/images/logo_components_color_2x_web_48dp.png">
<link rel="stylesheet" href="/assets/drawer/drawer.css">
<link rel="stylesheet" href="/assets/radio.css">
<script src="/ready.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body class="mdc-typography demo-body">
<aside id="demo-drawer" class="mdc-drawer mdc-drawer--dismissible mdc-drawer--open demo-drawer">
<div class="mdc-drawer__header">
<h3 class="mdc-drawer__title">Mail</h3>
<h6 class="mdc-drawer__subtitle">[email protected]</h6>
</div>
<div class="mdc-drawer__content">
<nav class="mdc-list">
<a class="mdc-list-item mdc-list-item--activated" href="#" aria-selected="true" tabindex="0">
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">inbox</i>
Inbox
</a>
<a class="mdc-list-item" href="#">
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">star</i>
Star
</a>
<a class="mdc-list-item" href="#">
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">send</i>
Sent Mail
</a>
<a class="mdc-list-item" href="#">
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">drafts</i>
Drafts
</a>

<hr class="mdc-list-divider">
<h6 class="mdc-list-group__subheader">Labels</h6>
<a class="mdc-list-item" href="#">
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">bookmark</i>
Family
</a>
<a class="mdc-list-item" href="#">
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">bookmark</i>
Friends
</a>
<a class="mdc-list-item" href="#">
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">bookmark</i>
Work
</a>

<hr class="mdc-list-divider">
<a class="mdc-list-item" href="#">
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">settings</i>
Settings
</a>
<a class="mdc-list-item" href="#">
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">announcement</i>
Help & feedback
</a>
</nav>
</div>
</aside>
<div class="demo-content mdc-drawer-app-content" id="demo-content">
<header class="mdc-top-app-bar demo-top-app-bar" id="app-bar">
<div class="mdc-top-app-bar__row">
<section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-start">
<a href="#" class="demo-menu material-icons mdc-top-app-bar__navigation-icon">menu</a>
<span class="mdc-top-app-bar__title">Dismissible Drawer</span>
</section>
<section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-end" role="toolbar">
<a href="#" class="material-icons mdc-top-app-bar__action-item" aria-label="Download" alt="Download">file_download</a>
</section>
</div>
</header>

<main class="demo-main" id="demo-main">
<div class="mdc-top-app-bar--fixed-adjust"></div>
<h1 class="mdc-typography--headline4">Dismissible Drawer</h1>
<p class="mdc-typography--body1">It sits to the left of this content. Currently active destination: <strong class="demo-selected-destination">Inbox</strong></p>

<div id="demo-radio-buttons">
<div class="mdc-form-field">
<div class="mdc-radio">
<input class="mdc-radio__native-control" type="radio" id="theme-radio-default" name="theme" checked>
<div class="mdc-radio__background">
<div class="mdc-radio__outer-circle"></div>
<div class="mdc-radio__inner-circle"></div>
</div>
</div>
<label for="theme-radio-default">Default</label>
</div>
<div class="mdc-form-field">
<div class="mdc-radio">
<input class="mdc-radio__native-control" type="radio" id="theme-radio-custom" name="theme">
<div class="mdc-radio__background">
<div class="mdc-radio__outer-circle"></div>
<div class="mdc-radio__inner-circle"></div>
</div>
</div>
<label for="theme-radio-custom">Custom Theme</label>
</div>
<div class="mdc-form-field">
<div class="mdc-radio">
<input class="mdc-radio__native-control" type="radio" id="theme-radio-accessible" name="theme">
<div class="mdc-radio__background">
<div class="mdc-radio__outer-circle"></div>
<div class="mdc-radio__inner-circle"></div>
</div>
</div>
<label for="theme-radio-accessible">Accessible Theme</label>
</div>
</div>

<div class="extra-content-wrapper">
<button type="button" class="mdc-button mdc-button--outlined mdc-button--dense demo-toolbar-example-heading__rtl-toggle-button">Toggle RTL</button>
</div>
<div class="extra-content-wrapper">
<button id="toggle-wide" class="mdc-button mdc-button--outlined mdc-button--dense">Toggle extra-wide content</button>
<div id="extra-wide-content" class="mdc-elevation--z2">&nbsp;</div>
</div>
<div class="extra-content-wrapper">
<button id="toggle-tall" class="mdc-button mdc-button--outlined mdc-button--dense">Toggle extra-tall content</button>
<div id="extra-tall-content" class="mdc-elevation--z2">&nbsp;</div>
</div>
</main>
</div>

<script src="/assets/material-components-web.js" async></script>
<script>
demoReady(function() {
var extraWide = document.querySelector('#extra-wide-content');
extraWide.style.display = 'none';
document.querySelector('#toggle-wide').addEventListener('click', function() {
extraWide.style.display = extraWide.style.display ? '' : 'none';
});
var extraTall = document.querySelector('#extra-tall-content');
extraTall.style.display = 'none';
document.querySelector('#toggle-tall').addEventListener('click', function() {
extraTall.style.display = extraTall.style.display ? '' : 'none';
});

var drawerEl = document.getElementById('demo-drawer');
var drawer = new mdc.drawer.MDCDrawer(drawerEl);
var radioEl = document.querySelector('#demo-radio-buttons');
radioEl.addEventListener('change', function(e) {
drawerEl.classList.remove('demo-drawer--custom');
drawerEl.classList.remove('demo-drawer--accessible');

if(e.target.id === 'theme-radio-custom') {
drawerEl.classList.add('demo-drawer--custom');
} else if(e.target.id === 'theme-radio-accessible') {
drawerEl.classList.add('demo-drawer--accessible');
}
});

var rtlToggleBtn = document.querySelector('.demo-toolbar-example-heading__rtl-toggle-button');
rtlToggleBtn.addEventListener('click', function(event) {
document.body.setAttribute('dir', document.body.getAttribute('dir') === 'rtl' ? 'ltr' : 'rtl');
});

var topAppBarEl = document.getElementById('app-bar');
var topAppBar = new mdc.topAppBar.MDCTopAppBar(topAppBarEl);
var mainEl = document.getElementById('demo-main');
topAppBar.setScrollTarget(mainEl);
topAppBar.listen('MDCTopAppBar:nav', function() {
drawer.open = !drawer.open;
});

var listEl = drawerEl.querySelector('.mdc-list');
var selectedDestinationEl = document.querySelector('.demo-selected-destination');
var mainEl = document.querySelector('.demo-main');
listEl.addEventListener('click', function(event) {
selectedDestinationEl.textContent = event.target.lastChild.textContent;
mainEl.querySelector('input').focus();
});
document.body.addEventListener('MDCDrawer:closed', function() {
mainEl.querySelector('input').focus();
});
});
</script>
</body>
</html>
80 changes: 54 additions & 26 deletions demos/drawer/drawer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
// THE SOFTWARE.
//

@import "../../packages/mdc-list/mixins";
@import "../../packages/mdc-form-field/mdc-form-field";
@import "../common";
@import "../../packages/mdc-drawer/mdc-drawer";
@import "../../packages/mdc-drawer/mixins";
@import "../../packages/mdc-drawer/mdc-drawer";
@import "../../packages/mdc-elevation/mdc-elevation";
@import "../../packages/mdc-list/mdc-list";
@import "../../packages/mdc-button/mdc-button";
@import "../../packages/mdc-top-app-bar/mdc-top-app-bar";

.examples {
display: flex;
Expand Down Expand Up @@ -65,36 +65,64 @@
padding: 10px;
}

.demo-drawer--custom {
@include mdc-drawer-fill-color($material-color-teal-900);
@include mdc-drawer-ink-color(#fff);
@include mdc-list-item-graphic-ink-color(#fff);
.demo-form-field {
margin: 16px 0;
}

.demo-drawer-list-item {
@include mdc-list-item-graphic-ink-color(text-icon-on-dark);
@include mdc-list-item-primary-text-ink-color(text-secondary-on-dark);
}
/* Place drawer and content side by side. */
.demo-body {
display: flex;
padding: 0;
margin: 0;
height: 100vh;
}

.demo-drawer-list-item.mdc-list-item--selected {
@include mdc-list-item-graphic-ink-color(text-primary-on-dark);
@include mdc-list-item-primary-text-ink-color(text-primary-on-dark);
}
.demo-content {
flex: auto;
overflow: auto;
background: #fff;
}

.demo-drawer--accessible {
@include mdc-drawer-fill-color-accessible($material-color-indigo-500);
.demo-main {
padding-left: 16px;
padding-right: 16px;
overflow: auto;
height: 100%;
width: 100%;
box-sizing: border-box;
}

.demo-drawer-list-item {
@include mdc-list-item-graphic-ink-color(text-icon-on-dark);
@include mdc-list-item-primary-text-ink-color(text-secondary-on-dark);
}
#extra-wide-content {
width: 200vw;
}

.demo-drawer-list-item.mdc-list-item--selected {
@include mdc-list-item-graphic-ink-color(text-primary-on-dark);
@include mdc-list-item-primary-text-ink-color(text-primary-on-dark);
}
#extra-tall-content {
height: 200vh;
}

.demo-form-field {
margin: 16px 0;
.demo-drawer--custom {
@include mdc-drawer-border-color(lightblue);
@include mdc-drawer-subtitle-ink-color(darkolivegreen);
@include mdc-drawer-surface-fill-color(pink);
@include mdc-drawer-item-icon-ink-color(darkolivegreen);
@include mdc-drawer-title-ink-color(darkolivegreen);
@include mdc-drawer-activated-overlay-color(darkcyan);
@include mdc-drawer-item-text-ink-color(darkolivegreen);
@include mdc-drawer-item-activated-text-ink-color(darkcyan);
@include mdc-drawer-item-activated-icon-ink-color(darkcyan);
}

.demo-drawer--accessible {
@include mdc-drawer-fill-color-accessible(darkcyan);
@include mdc-drawer-activated-overlay-color(pink);
@include mdc-drawer-item-activated-text-ink-color(pink);
@include mdc-drawer-item-activated-icon-ink-color(pink);
}

.demo-top-app-bar {
position: absolute;
}

.demo-selected-destination {
font-weight: 500;
}
43 changes: 16 additions & 27 deletions demos/drawer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,23 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="/images/logo_components_color_2x_web_48dp.png">
<link rel="stylesheet" href="/assets/drawer/drawer.css">
<link rel="stylesheet" href="/assets/radio.css">
<script src="/ready.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

</head>
<body class="mdc-typography demo-body">
<div class="mdc-toolbar mdc-toolbar--fixed">
<div class="mdc-toolbar__row">
<section class="mdc-toolbar__section mdc-toolbar__section--align-start">
<header class="mdc-top-app-bar" id="app-bar">
<div class="mdc-top-app-bar__row">
<section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-start">
<a href="/" class="catalog-back mdc-toolbar__menu-icon"><i class="material-icons">&#xE5C4;</i></a>
<span class="mdc-toolbar__title catalog-title">Drawer</span>
<span class="mdc-top-app-bar__title">Drawer</span>
</section>
</div>
</div>
</header>

<main class="mdc-toolbar-fixed-adjust">
<main>
<div class="mdc-top-app-bar--fixed-adjust"></div>
<div class="intro">
<p>
To best show the functionality of drawers, we put all demos in iframes.
Expand All @@ -60,34 +59,24 @@
<section class="examples">
<div class="example">
<h2 class="drawer-example-heading">
<span>Temporary Drawer</span>
</h2>
<p><a href="./temporary-drawer.html" target="_blank">View in separate window</a></p>
<iframe src="./temporary-drawer.html"></iframe>
</div>

<div class="example">
<h2 class="drawer-example-heading">
<span>Persistent Drawer</span>
<span>Permanent drawer</span>
</h2>
<p><a href="./persistent-drawer.html" target="_blank">View in separate window</a></p>
<iframe src="./persistent-drawer.html"></iframe>
<p><a href="./permanent-drawer.html" target="_blank">View in separate window</a></p>
<iframe src="./permanent-drawer.html"></iframe>
</div>

<div class="example">
<h2 class="drawer-example-heading">
<span>Permanent drawer above toolbar</span>
<span>Dismissible drawer</span>
</h2>
<p><a href="./permanent-drawer-above-toolbar.html" target="_blank">View in separate window</a></p>
<iframe src="./permanent-drawer-above-toolbar.html"></iframe>
<p><a href="./dismissible-drawer.html" target="_blank">View in separate window</a></p>
<iframe src="./dismissible-drawer.html"></iframe>
</div>

<div class="example">
<h2 class="drawer-example-heading">
<span>Permanent drawer below toolbar</span>
<span>Modal drawer</span>
</h2>
<p><a href="./permanent-drawer-below-toolbar.html" target="_blank">View in separate window</a></p>
<iframe src="./permanent-drawer-below-toolbar.html"></iframe>
<p><a href="./modal-drawer.html" target="_blank">View in separate window</a></p>
<iframe src="./modal-drawer.html"></iframe>
</div>
</section>
</main>
Expand Down
Loading

0 comments on commit 3aa211d

Please sign in to comment.