Blame view

bower_components/paper-toast/paper-toast.html 7.02 KB
a1a3bc73   Luigi Serra   graphs updates
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
  <!--
  @license
  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-a11y-announcer/iron-a11y-announcer.html">
  <link rel="import" href="../iron-overlay-behavior/iron-overlay-behavior.html">
  <link rel="import" href="../paper-styles/typography.html">
  
  <!--
  Material design: [Snackbards & toasts](https://www.google.com/design/spec/components/snackbars-toasts.html)
  
  `paper-toast` provides a subtle notification toast. Only one `paper-toast` will
  be visible on screen.
  
  Use `opened` to show the toast:
  
  Example:
  
      <paper-toast text="Hello world!" opened></paper-toast>
  
  Also `open()` or `show()` can be used to show the toast:
  
  Example:
  
      <paper-button on-click="openToast">Open Toast</paper-button>
      <paper-toast id="toast" text="Hello world!"></paper-toast>
  
      ...
  
      openToast: function() {
        this.$.toast.open();
      }
  
  Set `duration` to 0, a negative number or Infinity to persist the toast on screen:
  
  Example:
  
      <paper-toast text="Terms and conditions" opened duration="0">
        <a href="#">Show more</a>
      </paper-toast>
  
  
  ### Styling
  The following custom properties and mixins are available for styling:
  
  Custom property | Description | Default
  ----------------|-------------|----------
  `--paper-toast-background-color` | The paper-toast background-color | `#323232`
  `--paper-toast-color` | The paper-toast color | `#f1f1f1`
  
  @group Paper Elements
  @element paper-toast
  @demo demo/index.html
  @hero hero.svg
  -->
  
  <dom-module id="paper-toast">
    <template>
      <style>
        :host {
          display: block;
          position: fixed;
          background-color: var(--paper-toast-background-color, #323232);
          color: var(--paper-toast-color, #f1f1f1);
          min-height: 48px;
          min-width: 288px;
          padding: 16px 24px;
          box-sizing: border-box;
          box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
          border-radius: 2px;
          left: 0;
          bottom: 0;
          margin: 12px;
          font-size: 14px;
          cursor: default;
          -webkit-transition: visibility 0.3s, -webkit-transform 0.3s, opacity 0.3s;
          transition: visibility 0.3s, transform 0.3s, opacity 0.3s;
          visibility: hidden;
          opacity: 0;
          -webkit-transform: translateY(100px);
          transform: translateY(100px);
          @apply(--paper-font-common-base);
        }
  
        :host(.capsule) {
          border-radius: 24px;
        }
  
        :host(.fit-bottom) {
          width: 100%;
          min-width: 0;
          border-radius: 0;
          margin: 0;
        }
  
        :host(.paper-toast-open) {
          visibility: visible;
          opacity: 1;
          -webkit-transform: translateY(0px);
          transform: translateY(0px);
        }
      </style>
  
      <span id="label">{{text}}</span>
      <content></content>
    </template>
  
    <script>
      (function() {
        // Keeps track of the toast currently opened.
        var currentToast = null;
  
        Polymer({
          is: 'paper-toast',
  
          behaviors: [
            Polymer.IronOverlayBehavior
          ],
  
          properties: {
            /**
             * The duration in milliseconds to show the toast.
             * Set to `0`, a negative number, or `Infinity`, to disable the
             * toast auto-closing.
             */
            duration: {
              type: Number,
              value: 3000
            },
  
            /**
             * The text to display in the toast.
             */
            text: {
              type: String,
              value: ''
            },
  
            /**
             * Overridden from `IronOverlayBehavior`.
             * Set to false to enable closing of the toast by clicking outside it.
             */
            noCancelOnOutsideClick: {
              type: Boolean,
              value: true
            },
          },
  
          /**
           * Read-only. Deprecated. Use `opened` from `IronOverlayBehavior`.
           * @property visible
           * @deprecated
           */
          get visible() {
            console.warn('`visible` is deprecated, use `opened` instead');
            return this.opened;
          },
  
          /**
           * Read-only. Can auto-close if duration is a positive finite number.
           * @property _canAutoClose
           */
          get _canAutoClose() {
            return this.duration > 0 && this.duration !== Infinity;
          },
  
          created: function() {
            this._autoClose = null;
            Polymer.IronA11yAnnouncer.requestAvailability();
          },
  
          /**
           * Show the toast. Same as `open()` from `IronOverlayBehavior`.
           */
          show: function() {
            this.open();
          },
  
          /**
           * Hide the toast. Same as `close()` from `IronOverlayBehavior`.
           */
          hide: function() {
            this.close();
          },
  
          /**
           * Overridden from `IronOverlayBehavior`.
           * Called when the value of `opened` changes.
           */
          _openedChanged: function() {
            if (this._autoClose !== null) {
              this.cancelAsync(this._autoClose);
              this._autoClose = null;
            }
            if (this.opened) {
              if (currentToast && currentToast !== this) {
                currentToast.close();
              }
              currentToast = this;
              this.fire('iron-announce', {
                text: this.text
              });
              if (this._canAutoClose) {
                this._autoClose = this.async(this.close, this.duration);
              }
            } else if (currentToast === this) {
              currentToast = null;
            }
            Polymer.IronOverlayBehaviorImpl._openedChanged.apply(this, arguments);
          },
  
          /**
           * Overridden from `IronOverlayBehavior`.
           */
          _renderOpened: function() {
            this.classList.add('paper-toast-open');
          },
  
          /**
           * Overridden from `IronOverlayBehavior`.
           */
          _renderClosed: function() {
            this.classList.remove('paper-toast-open');
          },
  
          /**
           * Overridden from `IronOverlayBehavior`.
           * iron-fit-behavior will set the inline style position: static, which
           * causes the toast to be rendered incorrectly when opened by default.
           */
          _onIronResize: function() {
            Polymer.IronOverlayBehaviorImpl._onIronResize.apply(this, arguments);
            if (this.opened) {
              // Make sure there is no inline style for position.
              this.style.position = '';
            }
          }
  
          /**
           * Fired when `paper-toast` is opened.
           *
           * @event 'iron-announce'
           * @param {{text: string}} detail Contains text that will be announced.
           */
        });
      })();
    </script>
  </dom-module>