| OLD | NEW |
| (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-ripple/paper-ripple.html"> |
| 13 <link rel="import" href="../paper-styles/default-theme.html"> |
| 14 <link rel="import" href="../paper-behaviors/paper-inky-focus-behavior.html"> |
| 15 |
| 16 <!-- |
| 17 |
| 18 `paper-checkbox` is a button that can be either checked or unchecked. User |
| 19 can tap the checkbox to check or uncheck it. Usually you use checkboxes |
| 20 to allow user to select multiple options from a set. If you have a single |
| 21 ON/OFF option, avoid using a single checkbox and use `paper-toggle-button` |
| 22 instead. |
| 23 |
| 24 Example: |
| 25 |
| 26 <paper-checkbox>label</paper-checkbox> |
| 27 |
| 28 <paper-checkbox checked> label</paper-checkbox> |
| 29 |
| 30 ### Styling |
| 31 |
| 32 The following custom properties and mixins are available for styling: |
| 33 |
| 34 Custom property | Description | Default |
| 35 ----------------|-------------|---------- |
| 36 `--paper-checkbox-unchecked-color` | Checkbox color when the input is not checke
d | `--primary-text-color` |
| 37 `--paper-checkbox-unchecked-ink-color` | Selected/focus ripple color when the in
put is not checked | `--primary-text-color` |
| 38 `--paper-checkbox-checked-color` | Checkbox color when the input is checked | `-
-default-primary-color` |
| 39 `--paper-checkbox-checked-ink-color` | Selected/focus ripple color when the inpu
t is checked | `--default-primary-color` |
| 40 `--paper-checkbox-label-color` | Label color | `--primary-text-color` |
| 41 |
| 42 @demo demo/index.html |
| 43 --> |
| 44 |
| 45 <dom-module id="paper-checkbox"> |
| 46 <link rel="import" type="css" href="paper-checkbox.css"> |
| 47 |
| 48 <template> |
| 49 |
| 50 <div id="checkboxContainer"> |
| 51 <paper-ripple id="ink" class="circle" center checked$="[[checked]]"></pape
r-ripple> |
| 52 <div id="checkbox" class$="[[_computeCheckboxClass(checked)]]"> |
| 53 <div id="checkmark" class$="[[_computeCheckmarkClass(checked)]]"></div> |
| 54 </div> |
| 55 </div> |
| 56 |
| 57 <div id="checkboxLabel" aria-hidden="true"><content></content></div> |
| 58 |
| 59 </template> |
| 60 |
| 61 <script> |
| 62 Polymer({ |
| 63 is: 'paper-checkbox', |
| 64 |
| 65 behaviors: [ |
| 66 Polymer.PaperInkyFocusBehavior |
| 67 ], |
| 68 |
| 69 hostAttributes: { |
| 70 role: 'checkbox', |
| 71 'aria-checked': false, |
| 72 tabindex: 0 |
| 73 }, |
| 74 |
| 75 properties: { |
| 76 /** |
| 77 * Fired when the checked state changes due to user interaction. |
| 78 * |
| 79 * @event change |
| 80 */ |
| 81 |
| 82 /** |
| 83 * Fired when the checked state changes. |
| 84 * |
| 85 * @event iron-change |
| 86 */ |
| 87 |
| 88 /** |
| 89 * Gets or sets the state, `true` is checked and `false` is unchecked. |
| 90 */ |
| 91 checked: { |
| 92 type: Boolean, |
| 93 value: false, |
| 94 reflectToAttribute: true, |
| 95 notify: true, |
| 96 observer: '_checkedChanged' |
| 97 }, |
| 98 |
| 99 /** |
| 100 * If true, the button toggles the active state with each tap or press |
| 101 * of the spacebar. |
| 102 */ |
| 103 toggles: { |
| 104 type: Boolean, |
| 105 value: true, |
| 106 reflectToAttribute: true |
| 107 } |
| 108 }, |
| 109 |
| 110 ready: function() { |
| 111 if (Polymer.dom(this).textContent == '') { |
| 112 this.$.checkboxLabel.hidden = true; |
| 113 } else { |
| 114 this.setAttribute('aria-label', Polymer.dom(this).textContent); |
| 115 } |
| 116 this._isReady = true; |
| 117 }, |
| 118 |
| 119 // button-behavior hook |
| 120 _buttonStateChanged: function() { |
| 121 if (this.disabled) { |
| 122 return; |
| 123 } |
| 124 if (this._isReady) { |
| 125 this.checked = this.active; |
| 126 } |
| 127 }, |
| 128 |
| 129 _checkedChanged: function(checked) { |
| 130 this.setAttribute('aria-checked', this.checked ? 'true' : 'false'); |
| 131 this.active = this.checked; |
| 132 this.fire('iron-change'); |
| 133 }, |
| 134 |
| 135 _computeCheckboxClass: function(checked) { |
| 136 if (checked) { |
| 137 return 'checked'; |
| 138 } |
| 139 return ''; |
| 140 }, |
| 141 |
| 142 _computeCheckmarkClass: function(checked) { |
| 143 if (!checked) { |
| 144 return 'hidden'; |
| 145 } |
| 146 return ''; |
| 147 } |
| 148 }) |
| 149 </script> |
| 150 |
| 151 </dom-module> |
| OLD | NEW |