Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Unified Diff: third_party/polymer/v0_8/components/paper-drawer-panel/paper-drawer-panel.html

Issue 1082403004: Import Polymer 0.8 and several key elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also remove polymer/explainer Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/polymer/v0_8/components/paper-drawer-panel/paper-drawer-panel.html
diff --git a/third_party/polymer/v0_8/components/paper-drawer-panel/paper-drawer-panel.html b/third_party/polymer/v0_8/components/paper-drawer-panel/paper-drawer-panel.html
new file mode 100644
index 0000000000000000000000000000000000000000..d7d930c7ddf11d411d3362273beb1d853f05b7ed
--- /dev/null
+++ b/third_party/polymer/v0_8/components/paper-drawer-panel/paper-drawer-panel.html
@@ -0,0 +1,725 @@
+<!--
+Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
+This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
+The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
+The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
+Code distributed by Google as part of the polymer project is also
+subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
+-->
+
+<link rel="import" href="../polymer/polymer.html">
+<link rel="import" href="../iron-media-query/iron-media-query.html">
+<link rel="import" href="../iron-selector/iron-selector.html">
+
+<!--
+`paper-drawer-panel` contains a drawer panel and a main panel. The drawer
+and the main panel are side-by-side with drawer on the left. When the browser
+window size is smaller than the `responsiveWidth`, `paper-drawer-panel`
+changes to narrow layout. In narrow layout, the drawer will be stacked on top
+of the main panel. The drawer will slide in/out to hide/reveal the main
+panel.
+
+Use the attribute `drawer` to indicate that the element is the drawer panel and
+`main` to indicate that the element is the main panel.
+
+Example:
+
+ <paper-drawer-panel>
+ <div drawer> Drawer panel... </div>
+ <div main> Main panel... </div>
+ </paper-drawer-panel>
+
+The drawer and the main panels are not scrollable. You can set CSS overflow
+property on the elements to make them scrollable or use `paper-header-panel`.
+
+Example:
+
+ <paper-drawer-panel>
+ <paper-header-panel drawer>
+ <paper-toolbar></paper-toolbar>
+ <div> Drawer content... </div>
+ </paper-header-panel>
+ <paper-header-panel main>
+ <paper-toolbar></paper-toolbar>
+ <div> Main content... </div>
+ </paper-header-panel>
+ </paper-drawer-panel>
+
+An element that should toggle the drawer will automatically do so if it's
+given the `paper-drawer-toggle` attribute. Also this element will automatically
+be hidden in wide layout.
+
+Example:
+
+ <paper-drawer-panel>
+ <paper-header-panel drawer>
+ <paper-toolbar>
+ <div>Application</div>
+ </paper-toolbar>
+ <div> Drawer content... </div>
+ </paper-header-panel>
+ <paper-header-panel main>
+ <paper-toolbar>
+ <paper-icon-button icon="menu" paper-drawer-toggle></paper-icon-button>
+ <div>Title</div>
+ </paper-toolbar>
+ <div> Main content... </div>
+ </paper-header-panel>
+ </paper-drawer-panel>
+
+To position the drawer to the right, add `rightDrawer` attribute.
+
+ <paper-drawer-panel rightDrawer>
+ <div drawer> Drawer panel... </div>
+ <div main> Main panel... </div>
+ </paper-drawer-panel>
+
+@group Polymer Elements
+@element paper-drawer-panel
+@homepage github.io
+-->
+
+<dom-module id="paper-drawer-panel">
+
+ <style>
+ :host {
+ display: block;
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ overflow: hidden;
+ }
+
+ iron-selector > #drawer {
+ position: absolute;
+ top: 0;
+ left: 0;
+ height: 100%;
+ will-change: transform;
+ box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ }
+
+ .transition > #drawer {
+ transition: -webkit-transform ease-in-out 0.3s, width ease-in-out 0.3s;
+ transition: transform ease-in-out 0.3s, width ease-in-out 0.3s;
+ }
+
+ /*
+ right-drawer: make drawer on the right side
+ */
+ .right-drawer > #drawer {
+ left: auto;
+ right: 0;
+ }
+
+ paper-drawer-panel #drawer > * {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ }
+
+ iron-selector > #main {
+ position: absolute;
+ top: 0;
+ right: 0;
+ bottom: 0;
+ }
+
+ .transition > #main {
+ transition: left ease-in-out 0.3s, padding ease-in-out 0.3s;
+ }
+
+ .right-drawer > #main {
+ left: 0;
+ }
+
+ .right-drawer.transition > #main {
+ transition: right ease-in-out 0.3s, padding ease-in-out 0.3s;
+ }
+
+ #main > [main] {
+ height: 100%;
+ }
+
+ #scrim {
+ position: absolute;
+ top: 0;
+ right: 0;
+ bottom: 0;
+ left: 0;
+ background-color: rgba(0, 0, 0, 0.3);
+ visibility: hidden;
+ opacity: 0;
+ transition: opacity ease-in-out 0.38s, visibility ease-in-out 0.38s;
+ }
+
+ #edgeSwipeOverlay {
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ left: 0;
+ width: 20px;
+ }
+
+ .right-drawer > #main > #edgeSwipeOverlay {
+ right: 0;
+ left: auto;
+ }
+
+ /*
+ narrow layout
+ */
+ .narrow-layout > #drawer.iron-selected {
+ box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.15);
+ }
+
+ .right-drawer.narrow-layout > #drawer.iron-selected {
+ box-shadow: -2px 2px 4px rgba(0, 0, 0, 0.15);
+ }
+
+ .narrow-layout > #drawer > ::content[select="[drawer]"] > * {
+ border: 0;
+ }
+
+ .narrow-layout > #drawer:not(.iron-selected) {
+ -webkit-transform: translateX(-100%);
+ transform: translateX(-100%);
+ }
+
+ .right-drawer.narrow-layout > #drawer:not(.iron-selected) {
+ left: auto;
+ -webkit-transform: translateX(100%);
+ transform: translateX(100%);
+ }
+
+ .narrow-layout > #main {
+ left: 0 !important;
+ padding: 0;
+ }
+
+ .right-drawer.narrow-layout > #main {
+ left: 0;
+ right: 0;
+ padding: 0;
+ }
+
+ .narrow-layout > #main:not(.iron-selected) > #scrim,
+ .dragging #scrim {
+ visibility: visible;
+ opacity: 1;
+ }
+
+ .narrow-layout > #main > * {
+ margin: 0;
+ min-height: 100%;
+ left: 0;
+ right: 0;
+ box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ }
+
+ iron-selector:not(.narrow-layout) #main ::content [paper-drawer-toggle] {
+ display: none;
+ }
+ </style>
+
+ <template>
+ <iron-media-query
+ on-query-matches-changed="onQueryMatchesChanged"
+ query="[[_computeMediaQuery(forceNarrow, responsiveWidth)]]">
+ </iron-media-query>
+
+ <iron-selector
+ attr-for-selected="id"
+ class$="[[_computeIronSelectorClass(narrow, transition, dragging, rightDrawer)]]"
+ on-iron-activate="onSelect"
+ selected="[[selected]]">
+
+ <div id="main" style$="[[_computeMainStyle(narrow, rightDrawer, drawerWidth)]]">
+ <content select="[main]"></content>
+ <div id="scrim"></div>
+ <div id="edgeSwipeOverlay"
+ hidden$="[[_computeSwipeOverlayHidden(narrow, disableEdgeSwipe)]]">
+ </div>
+ </div>
+
+ <div id="drawer" style$="[[_computeDrawerStyle(drawerWidth)]]">
+ <content select="[drawer]"></content>
+ </div>
+
+ </iron-selector>
+ </template>
+
+</dom-module>
+
+<script>
+
+ (function() {
+
+ 'use strict';
+
+ function classNames(obj) {
+ var classNames = [];
+ for (var key in obj) {
+ if (obj.hasOwnProperty(key) && obj[key]) {
+ classNames.push(key);
+ }
+ }
+
+ return classNames.join(' ');
+ }
+
+ Polymer({
+
+ is: 'paper-drawer-panel',
+
+ /**
+ * Fired when the narrow layout changes.
+ *
+ * @event paper-responsive-change
+ * @param {Object} detail
+ * @param {boolean} detail.narrow true if the panel is in narrow layout.
+ */
+
+ /**
+ * Fired when the selected panel changes.
+ *
+ * Listening for this event is an alternative to observing changes in the `selected` attribute.
+ * This event is fired both when a panel is selected and deselected.
+ * The `isSelected` detail property contains the selection state.
+ *
+ * @event paper-select
+ * @param {Object} detail
+ * @param {boolean} detail.isSelected true for selection and false for deselection
+ * @param {Object} detail.item the panel that the event refers to
+ */
+
+ properties: {
+
+ /**
+ * The panel to be selected when `paper-drawer-panel` changes to narrow
+ * layout.
+ *
+ * @attribute defaultSelected
+ * @type string
+ * @default 'main'
+ */
+ defaultSelected: {
+ type: String,
+ value: 'main'
+ },
+
+ /**
+ * If true, swipe from the edge is disable.
+ *
+ * @attribute disableEdgeSwipe
+ * @type boolean
+ * @default false
+ */
+ disableEdgeSwipe: Boolean,
+
+ /**
+ * If true, swipe to open/close the drawer is disabled.
+ *
+ * @attribute disableSwipe
+ * @type boolean
+ * @default false
+ */
+ disableSwipe: Boolean,
+
+ // Whether the user is dragging the drawer interactively.
+ dragging: {
+ value: false
+ },
+
+ /**
+ * Width of the drawer panel.
+ *
+ * @attribute drawerWidth
+ * @type string
+ * @default '256px'
+ */
+ drawerWidth: {
+ type: String,
+ value: '256px'
+ },
+
+ // How many pixels on the side of the screen are sensitive to edge
+ // swipes and peek.
+ edgeSwipeSensitivity: {
+ value: 30
+ },
+
+ /**
+ * If true, ignore `responsiveWidth` setting and force the narrow layout.
+ *
+ * @attribute forceNarrow
+ * @type boolean
+ * @default false
+ */
+ forceNarrow: {
+ observer: 'forceNarrowChanged',
+ type: Boolean,
+ value: false
+ },
+
+ // Whether the browser has support for the transform CSS property.
+ hasTransform: {
+ value: function() {
+ return 'transform' in this.style;
+ }
+ },
+
+ // Whether the browser has support for the will-change CSS property.
+ hasWillChange: {
+ value: function() {
+ return 'willChange' in this.style;
+ }
+ },
+
+ /**
+ * Returns true if the panel is in narrow layout. This is useful if you
+ * need to show/hide elements based on the layout.
+ *
+ * @attribute narrow
+ * @type boolean
+ * @default false
+ */
+ narrow: {
+ reflectToAttribute: true,
+ type: Boolean,
+ value: false
+ },
+
+ // Whether the drawer is peeking out from the edge.
+ peeking: false,
+
+ /**
+ * Max-width when the panel changes to narrow layout.
+ *
+ * @attribute responsiveWidth
+ * @type string
+ * @default '640px'
+ */
+ responsiveWidth: {
+ type: String,
+ value: '640px'
+ },
+
+ /**
+ * If true, position the drawer to the right.
+ *
+ * @attribute rightDrawer
+ * @type boolean
+ * @default false
+ */
+ rightDrawer: {
+ type: Boolean,
+ value: false
+ },
+
+ /**
+ * The panel that is being selected. `drawer` for the drawer panel and
+ * `main` for the main panel.
+ *
+ * @attribute selected
+ * @type string
+ * @default null
+ */
+ selected: {
+ reflectToAttribute: true,
+ type: String,
+ value: null
+ },
+
+ /**
+ * The attribute on elements that should toggle the drawer on tap, also elements will
+ * automatically be hidden in wide layout.
+ */
+ drawerToggleAttribute: {
+ value: 'paper-drawer-toggle'
+ },
+
+ /**
+ * Whether the transition is enabled.
+ */
+ transition: false,
+
+ /**
+ * Starting X coordinate of a tracking gesture. It is non-null only between trackStart and
+ * trackEnd events.
+ */
+ _startX: {
+ value: null
+ }
+
+ },
+
+ listeners: {
+ click: 'onClick',
+ track: 'onTrack'
+
+ // TODO: Implement tap handlers when taps are supported.
+ //
+ // down: 'downHandler',
+ // up: 'upHandler'
+ },
+
+ _computeIronSelectorClass: function(narrow, transition, dragging, rightDrawer) {
+ return classNames({
+ dragging: dragging,
+ 'narrow-layout': narrow,
+ 'right-drawer': rightDrawer,
+ transition: transition
+ });
+ },
+
+ _computeDrawerStyle: function(drawerWidth) {
+ return 'width:' + drawerWidth + ';';
+ },
+
+ _computeMainStyle: function(narrow, rightDrawer, drawerWidth) {
+ var style = '';
+
+ style += 'left:' + ((narrow || rightDrawer) ? '0' : drawerWidth) + ';'
+
+ if (rightDrawer) {
+ style += 'right:' + (narrow ? '' : drawerWidth) + ';';
+ } else {
+ style += 'right:;'
+ }
+
+ return style;
+ },
+
+ _computeMediaQuery: function(forceNarrow, responsiveWidth) {
+ return forceNarrow ? '' : '(max-width: ' + responsiveWidth + ')';
+ },
+
+ _computeSwipeOverlayHidden: function(narrow, disableEdgeSwipe) {
+ return !narrow || disableEdgeSwipe;
+ },
+
+ onTrack: function(event) {
+ switch (event.detail.state) {
+ case 'end':
+ this.trackEnd(event);
+ break;
+ case 'move':
+ this.trackX(event);
+ break;
+ case 'start':
+ this.trackStart(event);
+ break;
+ }
+ },
+
+ ready: function() {
+ // Avoid transition at the beginning e.g. page loads and enable
+ // transitions only after the element is rendered and ready.
+ this.transition = true;
+ },
+
+ /**
+ * Toggles the panel open and closed.
+ *
+ * @method togglePanel
+ */
+ togglePanel: function() {
+ if (this.isMainSelected()) {
+ this.openDrawer();
+ } else {
+ this.closeDrawer();
+ }
+ },
+
+ /**
+ * Opens the drawer.
+ *
+ * @method openDrawer
+ */
+ openDrawer: function() {
+ this.selected = 'drawer';
+ },
+
+ /**
+ * Closes the drawer.
+ *
+ * @method closeDrawer
+ */
+ closeDrawer: function() {
+ this.selected = 'main';
+ },
+
+ _responsiveChange: function(narrow) {
+ this.narrow = narrow;
+
+ if (this.narrow) {
+ this.selected = this.defaultSelected;
+ }
+
+ this.setAttribute('touch-action', this.swipeAllowed() ? 'pan-y' : '');
+ this.fire('paper-responsive-change', {narrow: this.narrow});
+ },
+
+ onQueryMatchesChanged: function(e) {
+ this._responsiveChange(e.detail.value);
+ },
+
+ forceNarrowChanged: function() {
+ this._responsiveChange(this.forceNarrow);
+ },
+
+ swipeAllowed: function() {
+ return this.narrow && !this.disableSwipe;
+ },
+
+ isMainSelected: function() {
+ return this.selected === 'main';
+ },
+
+ startEdgePeek: function() {
+ this.width = this.$.drawer.offsetWidth;
+ this.moveDrawer(this.translateXForDeltaX(this.rightDrawer ?
+ -this.edgeSwipeSensitivity : this.edgeSwipeSensitivity));
+ this.peeking = true;
+ },
+
+ stopEdgePeek: function() {
+ if (this.peeking) {
+ this.peeking = false;
+ this.moveDrawer(null);
+ }
+ },
+
+ // TODO: Implement tap handlers when taps are supported.
+ //
+ // downHandler: function(e) {
+ // if (!this.dragging && this.isMainSelected() && this.isEdgeTouch(e)) {
+ // this.startEdgePeek();
+ // }
+ // },
+ //
+ // upHandler: function(e) {
+ // this.stopEdgePeek();
+ // },
+
+ onClick: function(e) {
+ var isTargetToggleElement = e.target &&
+ this.drawerToggleAttribute &&
+ e.target.hasAttribute(this.drawerToggleAttribute);
+
+ if (isTargetToggleElement) {
+ this.togglePanel();
+ }
+ },
+
+ isEdgeTouch: function(event) {
+ var x = event.detail.x;
+
+ return !this.disableEdgeSwipe && this.swipeAllowed() &&
+ (this.rightDrawer ?
+ x >= this.offsetWidth - this.edgeSwipeSensitivity :
+ x <= this.edgeSwipeSensitivity);
+ },
+
+ trackStart: function(event) {
+ if (this.swipeAllowed()) {
+ this.dragging = true;
+ this._startX = event.detail.x;
+
+ if (this.isMainSelected()) {
+ this.dragging = this.peeking || this.isEdgeTouch(event);
+ }
+
+ if (this.dragging) {
+ this.width = this.$.drawer.offsetWidth;
+ this.transition = false;
+
+ // TODO: Re-enable when tap gestures are implemented.
+ //
+ // e.preventTap();
+ }
+ }
+ },
+
+ translateXForDeltaX: function(deltaX) {
+ var isMain = this.isMainSelected();
+
+ if (this.rightDrawer) {
+ return Math.max(0, isMain ? this.width + deltaX : deltaX);
+ } else {
+ return Math.min(0, isMain ? deltaX - this.width : deltaX);
+ }
+ },
+
+ trackX: function(event) {
+ var dx = event.detail.x - this._startX;
+
+ if (this.dragging) {
+ if (this.peeking) {
+ if (Math.abs(dx) <= this.edgeSwipeSensitivity) {
+ // Ignore trackx until we move past the edge peek.
+ return;
+ }
+
+ this.peeking = false;
+ }
+
+ this.moveDrawer(this.translateXForDeltaX(dx));
+ }
+ },
+
+ trackEnd: function(event) {
+ if (this.dragging) {
+ var xDirection = (event.detail.x - this._startX) > 0;
+
+ this.dragging = false;
+ this._startX = null;
+ this.transition = true;
+ this.moveDrawer(null);
+
+ if (this.rightDrawer) {
+ this[(xDirection > 0) ? 'closeDrawer' : 'openDrawer']();
+ } else {
+ this[(xDirection > 0) ? 'openDrawer' : 'closeDrawer']();
+ }
+ }
+ },
+
+ transformForTranslateX: function(translateX) {
+ if (translateX === null) {
+ return '';
+ }
+
+ return this.hasWillChange ? 'translateX(' + translateX + 'px)' :
+ 'translate3d(' + translateX + 'px, 0, 0)';
+ },
+
+ moveDrawer: function(translateX) {
+ var s = this.$.drawer.style;
+
+ if (this.hasTransform) {
+ s.transform = this.transformForTranslateX(translateX);
+ } else {
+ s.webkitTransform = this.transformForTranslateX(translateX);
+ }
+ },
+
+ onSelect: function(e) {
+ e.preventDefault();
+ this.selected = e.detail.selected;
+ }
+
+ });
+
+ }());
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698