Port Android relocation packer to chromium build
[chromium-blink-merge.git] / third_party / polymer / components / paper-toast / paper-toast.html
blobe1adf39c8d6f8a95bd21c7ea0f8bd9bea12eb326
1 <!--
2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
8 -->
10 <!--
11 `paper-toast` provides lightweight feedback about an operation in a small popup
12 at the base of the screen on mobile and at the lower left on desktop. Toasts are
13 above all other elements on screen, including the FAB.
15 Toasts automatically disappear after a timeout or after user interaction
16 elsewhere on the screen, whichever comes first. Toasts can be swiped off
17 screen. There can be only one on the screen at a time.
19 Example:
21 <paper-toast text="Your draft has been discarded." onclick="discardDraft(el)"></paper-toast>
23 <script>
24 function discardDraft(el) {
25 el.show();
27 </script>
29 An action button can be presented in the toast.
31 Example (using Polymer's data-binding features):
33 <paper-toast id="toast2" text="Connection timed out. Showing limited messages.">
34 <div style="color: blue;" on-tap="{{retry}}">Retry</div>
35 </paper-toast>
37 Positioning toast:
39 A standard toast appears near the lower left of the screen. You can change the
40 position by overriding bottom and left positions.
42 paper-toast {
43 bottom: 40px;
44 left: 10px;
47 To position the toast to the right:
49 paper-toast {
50 right: 10px;
51 left: auto;
54 To make it fit at the bottom of the screen:
56 paper-toast {
57 bottom: 0;
58 left: 0;
59 width: 100%;
62 When the screen size is smaller than the `responsiveWidth` (default to 480px),
63 the toast will automatically fits at the bottom of the screen.
65 @group Paper Elements
66 @element paper-toast
67 @homepage github.io
68 -->
69 <!--
70 Fired when the `paper-toast`'s `opened` property changes.
72 @event core-overlay-open
73 @param {boolean} detail the opened state
74 -->
75 <!--
76 Fired when the `paper-toast` has completely opened.
78 @event core-overlay-open-completed
79 -->
80 <!--
81 Fired when the `paper-toast` has completely closed.
83 @event core-overlay-close-completed
84 -->
85 <link rel="import" href="../core-overlay/core-overlay.html">
86 <link rel="import" href="../core-transition/core-transition-css.html">
87 <link rel="import" href="../core-media-query/core-media-query.html">
89 <polymer-element name="paper-toast" attributes="text duration opened responsiveWidth swipeDisabled autoCloseDisabled" role="status">
91 <template>
93 <link rel="stylesheet" href="paper-toast.css" >
95 <core-overlay id="overlay" autoFocusDisabled autoCloseDisabled="{{autoCloseDisabled}}" opened="{{opened}}" target="{{}}" transition="core-transition-bottom"></core-overlay>
97 <div class="toast-container" horizontal layout>
99 <div class="toast-text" flex>{{text}}</div>
101 <div class="toast-text toast-action" on-tap="{{dismiss}}">
102 <content></content>
103 </div>
105 </div>
107 <core-media-query query="max-width: {{responsiveWidth}}" queryMatches="{{narrowMode}}"></core-media-query>
109 </template>
110 <script>
112 (function() {
114 var currentToast;
116 Polymer('paper-toast', {
119 * The text shows in a toast.
121 * @attribute text
122 * @type string
123 * @default ''
125 text: '',
128 * The duration in milliseconds to show the toast.
130 * @attribute duration
131 * @type number
132 * @default 3000
134 duration: 3000,
137 * Set opened to true to show the toast and to false to hide it.
139 * @attribute opened
140 * @type boolean
141 * @default false
143 opened: false,
146 * Min-width when the toast changes to narrow layout. In narrow layout,
147 * the toast fits at the bottom of the screen when opened.
149 * @attribute responsiveWidth
150 * @type string
151 * @default '480px'
153 responsiveWidth: '480px',
156 * If true, the toast can't be swiped.
158 * @attribute swipeDisabled
159 * @type boolean
160 * @default false
162 swipeDisabled: false,
165 * By default, the toast will close automatically if the user taps
166 * outside it or presses the escape key. Disable this behavior by setting
167 * the `autoCloseDisabled` property to true.
169 * @attribute autoCloseDisabled
170 * @type boolean
171 * @default false
173 autoCloseDisabled: false,
175 narrowMode: false,
177 eventDelegates: {
178 trackstart: 'trackStart',
179 track: 'track',
180 trackend: 'trackEnd',
181 transitionend: 'transitionEnd'
184 narrowModeChanged: function() {
185 this.classList.toggle('fit-bottom', this.narrowMode);
186 if (this.opened) {
187 this.$.overlay.resizeHandler();
191 openedChanged: function() {
192 if (this.opened) {
193 this.dismissJob = this.job(this.dismissJob, this.dismiss, this.duration);
194 } else {
195 this.dismissJob && this.dismissJob.stop();
196 this.dismiss();
200 /**
201 * Toggle the opened state of the toast.
202 * @method toggle
204 toggle: function() {
205 this.opened = !this.opened;
208 /**
209 * Show the toast for the specified duration
210 * @method show
212 show: function() {
213 if (currentToast) {
214 currentToast.dismiss();
216 currentToast = this;
217 this.opened = true;
220 /**
221 * Dismiss the toast and hide it.
222 * @method dismiss
224 dismiss: function() {
225 if (this.dragging) {
226 this.shouldDismiss = true;
227 } else {
228 this.opened = false;
229 if (currentToast === this) {
230 currentToast = null;
235 trackStart: function(e) {
236 if (!this.swipeDisabled) {
237 e.preventTap();
238 this.vertical = e.yDirection;
239 this.w = this.offsetWidth;
240 this.h = this.offsetHeight;
241 this.dragging = true;
242 this.classList.add('dragging');
246 track: function(e) {
247 if (this.dragging) {
248 var s = this.style;
249 if (this.vertical) {
250 var y = e.dy;
251 s.opacity = (this.h - Math.abs(y)) / this.h;
252 s.transform = s.webkitTransform = 'translate3d(0, ' + y + 'px, 0)';
253 } else {
254 var x = e.dx;
255 s.opacity = (this.w - Math.abs(x)) / this.w;
256 s.transform = s.webkitTransform = 'translate3d(' + x + 'px, 0, 0)';
261 trackEnd: function(e) {
262 if (this.dragging) {
263 this.classList.remove('dragging');
264 this.style.opacity = '';
265 this.style.transform = this.style.webkitTransform = '';
266 var cl = this.classList;
267 if (this.vertical) {
268 cl.toggle('fade-out-down', e.yDirection === 1 && e.dy > 0);
269 cl.toggle('fade-out-up', e.yDirection === -1 && e.dy < 0);
270 } else {
271 cl.toggle('fade-out-right', e.xDirection === 1 && e.dx > 0);
272 cl.toggle('fade-out-left', e.xDirection === -1 && e.dx < 0);
274 this.dragging = false;
278 transitionEnd: function() {
279 var cl = this.classList;
280 if (cl.contains('fade-out-right') || cl.contains('fade-out-left') ||
281 cl.contains('fade-out-down') || cl.contains('fade-out-up')) {
282 this.dismiss();
283 cl.remove('fade-out-right', 'fade-out-left',
284 'fade-out-down', 'fade-out-up');
285 } else if (this.shouldDismiss) {
286 this.dismiss();
288 this.shouldDismiss = false;
293 })();
295 </script>
296 </polymer-element>