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

Side by Side Diff: polymer_1.0.4/bower_components/paper-input/paper-input-container.html

Issue 1205703007: Add polymer 1.0 to npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Renamed folder to 1.0.4 Created 5 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!--
2 @license
3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.g ithub.io/LICENSE.txt
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI BUTORS.txt
7 Code distributed by Google as part of the polymer project is also
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS.txt
9 -->
10
11 <link rel="import" href="../polymer/polymer.html">
12 <link rel="import" href="../paper-styles/paper-styles.html">
13
14 <!--
15 `<paper-input-container>` is a container for a `<label>`, an `<input is="iron-in put">` or
16 `<iron-autogrow-textarea>` and optional add-on elements such as an error message or character
17 counter, used to implement Material Design text fields.
18
19 For example:
20
21 <paper-input-container>
22 <label>Your name</label>
23 <input is="iron-input">
24 </paper-input-container>
25
26 ### Listening for input changes
27
28 By default, it listens for changes on the `bind-value` attribute on its children nodes and perform
29 tasks such as auto-validating and label styling when the `bind-value` changes. Y ou can configure
30 the attribute it listens to with the `attr-for-value` attribute.
31
32 ### Using a custom input element
33
34 You can use a custom input element in a `<paper-input-container>`, for example t o implement a
35 compound input field like a social security number input. The custom input eleme nt should have the
36 `paper-input-input` class, have a `notify:true` value property and optionally im plements
37 `Polymer.IronValidatableBehavior` if it is validatble.
38
39 <paper-input-container attr-for-value="ssn-value">
40 <label>Social security number</label>
41 <ssn-input class="paper-input-input"></ssn-input>
42 </paper-input-container>
43
44 ### Validation
45
46 If the `auto-validate` attribute is set, the input container will validate the i nput and update
47 the container styling when the input value changes.
48
49 ### Add-ons
50
51 Add-ons are child elements of a `<paper-input-container>` with the `add-on` attr ibute and
52 implements the `Polymer.PaperInputAddonBehavior` behavior. They are notified whe n the input value
53 or validity changes, and may implement functionality such as error messages or c haracter counters.
54 They appear at the bottom of the input.
55
56 ### Styling
57
58 The following custom properties and mixins are available for styling:
59
60 Custom property | Description | Default
61 ----------------|-------------|----------
62 `--paper-input-container-color` | Label and underline color when the input is no t focused | `--secondary-text-color`
63 `--paper-input-container-focus-color` | Label and underline color when the input is focused | `--default-primary-color`
64 `--paper-input-container-invalid-color` | Label and underline color when the inp ut is focused | `--google-red-500`
65 `--paper-input-container-input-color` | Input foreground color | `--primary-text -color`
66 `--paper-input-container` | Mixin applied to the container | `{}`
67 `--paper-input-container-label` | Mixin applied to the label | `{}`
68 `--paper-input-container-input` | Mixin applied to the input | `{}`
69
70 This element is `display:block` by default, but you can set the `inline` attribu te to make it
71 `display:inline-block`.
72 -->
73 <dom-module id="paper-input-container">
74
75 <style>
76
77 :host {
78 display: block;
79 padding: 8px 0;
80
81 @apply(--paper-input-container);
82 }
83
84 :host[inline] {
85 display: inline-block;
86 }
87
88 :host([disabled]) {
89 pointer-events: none;
90 opacity: 0.33;
91 }
92
93 .floated-label-placeholder {
94 @apply(--paper-font-caption);
95 }
96
97 .underline {
98 position: relative;
99 }
100
101 .focused-line {
102 height: 2px;
103
104 -webkit-transform-origin: center center;
105 transform-origin: center center;
106 -webkit-transform: scale3d(0,1,1);
107 transform: scale3d(0,1,1);
108
109 background: var(--paper-input-container-focus-color, --default-primary-col or);
110 }
111
112 .underline.is-highlighted .focused-line {
113 -webkit-transform: none;
114 transform: none;
115 -webkit-transition: -webkit-transform 0.25s;
116 transition: transform 0.25s;
117
118 @apply(--paper-transition-easing);
119 }
120
121 .underline.is-invalid .focused-line {
122 background: var(--paper-input-container-invalid-color, --google-red-500);
123
124 -webkit-transform: none;
125 transform: none;
126 -webkit-transition: -webkit-transform 0.25s;
127 transition: transform 0.25s;
128
129 @apply(--paper-transition-easing);
130 }
131
132 .unfocused-line {
133 height: 1px;
134 background: var(--paper-input-container-color, --secondary-text-color);
135 }
136
137 :host([disabled]) .unfocused-line {
138 border-bottom: 1px dashed;
139 border-color: var(--paper-input-container-color, --secondary-text-color);
140 background: transparent;
141 }
142
143 .input-content {
144 position: relative;
145 }
146
147 .input-content ::content label,
148 .input-content ::content .paper-input-label {
149 position: absolute;
150 top: 0;
151 right: 0;
152 left: 0;
153 font: inherit;
154 color: var(--paper-input-container-color, --secondary-text-color);
155
156 @apply(--paper-font-subhead);
157 @apply(--paper-input-container-label);
158 }
159
160 .input-content.label-is-floating ::content label,
161 .input-content.label-is-floating ::content .paper-input-label {
162 -webkit-transform: translate3d(0, -75%, 0) scale(0.75);
163 transform: translate3d(0, -75%, 0) scale(0.75);
164 -webkit-transform-origin: left top;
165 transform-origin: left top;
166 -webkit-transition: -webkit-transform 0.25s;
167 transition: transform 0.25s;
168
169 @apply(--paper-transition-easing);
170 }
171
172 .input-content.label-is-highlighted ::content label,
173 .input-content.label-is-highlighted ::content .paper-input-label {
174 color: var(--paper-input-container-focus-color, --default-primary-color);
175 }
176
177 .input-content.is-invalid ::content label,
178 .input-content.is-invalid ::content .paper-input-label {
179 color: var(--paper-input-container-invalid-color, --google-red-500);
180 }
181
182 .input-content.label-is-hidden ::content label,
183 .input-content.label-is-hidden ::content .paper-input-label {
184 visibility: hidden;
185 }
186
187 .input-content ::content input,
188 .input-content ::content textarea,
189 .input-content ::content iron-autogrow-textarea,
190 .input-content ::content .paper-input-input {
191 position: relative; /* to make a stacking context */
192 outline: none;
193 box-shadow: none;
194 padding: 0;
195 width: 100%;
196 background: transparent;
197 border: none;
198 color: var(--paper-input-container-input-color, --primary-text-color);
199
200 @apply(--paper-font-subhead);
201 @apply(--paper-input-container-input);
202 }
203
204 /* Firefox sets a min-width on the input, which can cause layout issues */
205 .input-content ::content input {
206 min-width: 0;
207 }
208
209 .input-content ::content textarea {
210 resize: none;
211 }
212
213 .add-on-content.is-invalid ::content * {
214 color: var(--paper-input-container-invalid-color, --google-red-500);
215 }
216
217 .add-on-content.is-highlighted ::content * {
218 color: var(--paper-input-container-focus-color, --default-primary-color);
219 }
220
221 </style>
222
223 <template>
224
225 <template is="dom-if" if="[[!noLabelFloat]]">
226 <div class="floated-label-placeholder">&nbsp;</div>
227 </template>
228
229 <div class$="[[_computeInputContentClass(noLabelFloat,alwaysFloatLabel,focus ed,invalid,_inputHasContent)]]">
230 <content select=":not([add-on])"></content>
231 </div>
232
233 <div class$="[[_computeUnderlineClass(focused,invalid)]]">
234 <div class="unfocused-line fit"></div>
235 <div class="focused-line fit"></div>
236 </div>
237
238 <div class$="[[_computeAddOnContentClass(focused,invalid)]]">
239 <content id="addOnContent" select="[add-on]"></content>
240 </div>
241
242 </template>
243
244 </dom-module>
245
246 <script>
247 (function() {
248
249 Polymer({
250
251 is: 'paper-input-container',
252
253 properties: {
254
255 /**
256 * Set to true to disable the floating label. The label disappears when th e input value is
257 * not null.
258 */
259 noLabelFloat: {
260 type: Boolean,
261 value: false
262 },
263
264 /**
265 * Set to true to always float the floating label.
266 */
267 alwaysFloatLabel: {
268 type: Boolean,
269 value: false
270 },
271
272 /**
273 * The attribute to listen for value changes on.
274 */
275 attrForValue: {
276 type: String,
277 value: 'bind-value'
278 },
279
280 /**
281 * Set to true to auto-validate the input value when it changes.
282 */
283 autoValidate: {
284 type: Boolean,
285 value: false
286 },
287
288 /**
289 * True if the input is invalid. This property is set automatically when t he input value
290 * changes if auto-validating, or when the `iron-input-valid` event is hea rd from a child.
291 */
292 invalid: {
293 observer: '_invalidChanged',
294 type: Boolean,
295 value: false
296 },
297
298 /**
299 * True if the input has focus.
300 */
301 focused: {
302 readOnly: true,
303 type: Boolean,
304 value: false
305 },
306
307 _addons: {
308 type: Array
309 // do not set a default value here intentionally - it will be initialize d lazily when a
310 // distributed child is attached, which may occur before configuration f or this element
311 // in polyfill.
312 },
313
314 _inputHasContent: {
315 type: Boolean,
316 value: false
317 },
318
319 _inputSelector: {
320 type: String,
321 value: 'input,textarea,.paper-input-input'
322 },
323
324 _boundOnFocus: {
325 type: Function,
326 value: function() {
327 return this._onFocus.bind(this);
328 }
329 },
330
331 _boundOnBlur: {
332 type: Function,
333 value: function() {
334 return this._onBlur.bind(this);
335 }
336 },
337
338 _boundOnInput: {
339 type: Function,
340 value: function() {
341 return this._onInput.bind(this);
342 }
343 },
344
345 _boundValueChanged: {
346 type: Function,
347 value: function() {
348 return this._onValueChanged.bind(this);
349 }
350 }
351
352 },
353
354 listeners: {
355 'addon-attached': '_onAddonAttached',
356 'iron-input-validate': '_onIronInputValidate'
357 },
358
359 get _valueChangedEvent() {
360 return this.attrForValue + '-changed';
361 },
362
363 get _propertyForValue() {
364 return Polymer.CaseMap.dashToCamelCase(this.attrForValue);
365 },
366
367 get _inputElement() {
368 return Polymer.dom(this).querySelector(this._inputSelector);
369 },
370
371 ready: function() {
372 if (!this._addons) {
373 this._addons = [];
374 }
375 this.addEventListener('focus', this._boundOnFocus, true);
376 this.addEventListener('blur', this._boundOnBlur, true);
377 if (this.attrForValue) {
378 this._inputElement.addEventListener(this._valueChangedEvent, this._bound ValueChanged);
379 } else {
380 this.addEventListener('input', this._onInput);
381 }
382 },
383
384 attached: function() {
385 this._handleValue(this._inputElement);
386 },
387
388 _onAddonAttached: function(event) {
389 if (!this._addons) {
390 this._addons = [];
391 }
392 var target = event.target;
393 if (this._addons.indexOf(target) === -1) {
394 this._addons.push(target);
395 if (this.isAttached) {
396 this._handleValue(this._inputElement);
397 }
398 }
399 },
400
401 _onFocus: function() {
402 this._setFocused(true);
403 },
404
405 _onBlur: function() {
406 this._setFocused(false);
407 },
408
409 _onInput: function(event) {
410 this._handleValue(event.target);
411 },
412
413 _onValueChanged: function(event) {
414 this._handleValue(event.target);
415 },
416
417 _handleValue: function(inputElement) {
418 var value = inputElement[this._propertyForValue] || inputElement.value;
419
420 if (this.autoValidate) {
421 var valid;
422 if (inputElement.validate) {
423 valid = inputElement.validate(value);
424 } else {
425 valid = inputElement.checkValidity();
426 }
427 this.invalid = !valid;
428 }
429
430 // type="number" hack needed because this.value is empty until it's valid
431 if (value || (inputElement.type === 'number' && !inputElement.checkValidit y())) {
432 this._inputHasContent = true;
433 } else {
434 this._inputHasContent = false;
435 }
436
437 this.updateAddons({
438 inputElement: inputElement,
439 value: value,
440 invalid: this.invalid
441 });
442 },
443
444 _onIronInputValidate: function(event) {
445 this.invalid = this._inputElement.invalid;
446 },
447
448 _invalidChanged: function() {
449 if (this._addons) {
450 this.updateAddons({invalid: this.invalid});
451 }
452 },
453
454 /**
455 * Call this to update the state of add-ons.
456 * @param {Object} state Add-on state.
457 */
458 updateAddons: function(state) {
459 for (var addon, index = 0; addon = this._addons[index]; index++) {
460 addon.update(state);
461 }
462 },
463
464 _computeInputContentClass: function(noLabelFloat, alwaysFloatLabel, focused, invalid, _inputHasContent) {
465 var cls = 'input-content';
466 if (!noLabelFloat) {
467 if (alwaysFloatLabel || _inputHasContent) {
468 cls += ' label-is-floating';
469 if (invalid) {
470 cls += ' is-invalid';
471 } else if (focused) {
472 cls += " label-is-highlighted";
473 }
474 }
475 } else {
476 if (_inputHasContent) {
477 cls += ' label-is-hidden';
478 }
479 }
480 return cls;
481 },
482
483 _computeUnderlineClass: function(focused, invalid) {
484 var cls = 'underline';
485 if (invalid) {
486 cls += ' is-invalid';
487 } else if (focused) {
488 cls += ' is-highlighted'
489 }
490 return cls;
491 },
492
493 _computeAddOnContentClass: function(focused, invalid) {
494 var cls = 'add-on-content';
495 if (invalid) {
496 cls += ' is-invalid';
497 } else if (focused) {
498 cls += ' is-highlighted'
499 }
500 return cls;
501 }
502
503 });
504
505 })();
506 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698