| OLD | NEW |
| 1 <!-- | 1 <!-- |
| 2 @license | 2 @license |
| 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 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 | 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 | 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 | 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 | 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 | 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 9 --> | 9 --> |
| 10 | 10 |
| 11 <link rel="import" href="../polymer/polymer.html"> | 11 <link rel="import" href="../polymer/polymer.html"> |
| 12 <link rel="import" href="../paper-ripple/paper-ripple.html"> | 12 <link rel="import" href="../paper-ripple/paper-ripple.html"> |
| 13 <link rel="import" href="../paper-styles/default-theme.html"> | 13 <link rel="import" href="../paper-styles/default-theme.html"> |
| 14 <link rel="import" href="../paper-behaviors/paper-radio-button-behavior.html"> | 14 <link rel="import" href="../paper-behaviors/paper-radio-button-behavior.html"> |
| 15 | 15 |
| 16 <!-- | 16 <!-- |
| 17 |
| 17 `paper-checkbox` is a button that can be either checked or unchecked. User | 18 `paper-checkbox` is a button that can be either checked or unchecked. User |
| 18 can tap the checkbox to check or uncheck it. Usually you use checkboxes | 19 can tap the checkbox to check or uncheck it. Usually you use checkboxes |
| 19 to allow user to select multiple options from a set. If you have a single | 20 to allow user to select multiple options from a set. If you have a single |
| 20 ON/OFF option, avoid using a single checkbox and use `paper-toggle-button` | 21 ON/OFF option, avoid using a single checkbox and use `paper-toggle-button` |
| 21 instead. | 22 instead. |
| 22 | 23 |
| 23 Example: | 24 Example: |
| 24 | 25 |
| 25 <paper-checkbox>label</paper-checkbox> | 26 <paper-checkbox>label</paper-checkbox> |
| 26 | 27 |
| 27 <paper-checkbox checked> label</paper-checkbox> | 28 <paper-checkbox checked> label</paper-checkbox> |
| 28 | 29 |
| 29 Styling a checkbox: | 30 ### Styling |
| 30 | 31 |
| 31 <style is="x-style"> | 32 The following custom properties and mixins are available for styling: |
| 32 * { | |
| 33 /* Unhecked state colors. */ | |
| 34 --paper-checkbox-unchecked-color: #5a5a5a; | |
| 35 --paper-checkbox-unchecked-ink-color: #5a5a5a; | |
| 36 | 33 |
| 37 /* Checked state colors. */ | 34 Custom property | Description | Default |
| 38 --paper-checkbox-checked-color: #009688; | 35 ----------------|-------------|---------- |
| 39 --paper-checkbox-checked-ink-color: #009688; | 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 <style is="custom-style"> |
| 46 :root { |
| 47 --paper-checkbox-unchecked-color: var(--primary-text-color); |
| 48 --paper-checkbox-unchecked-ink-color: var(--primary-text-color); |
| 49 |
| 50 --paper-checkbox-checked-color: var(--default-primary-color); |
| 51 --paper-checkbox-checked-ink-color: var(--default-primary-color); |
| 52 |
| 53 --paper-checkbox-label-color: var(--primary-text-color); |
| 40 } | 54 } |
| 41 </style> | 55 </style> |
| 42 | 56 |
| 43 @group Paper Elements | |
| 44 @class paper-checkbox | |
| 45 --> | |
| 46 | |
| 47 <dom-module id="paper-checkbox"> | 57 <dom-module id="paper-checkbox"> |
| 48 <style is="x-style"> | |
| 49 * { | |
| 50 --paper-checkbox-unchecked-color: var(--primary-text-color); | |
| 51 --paper-checkbox-unchecked-ink-color: var(--primary-text-color); | |
| 52 | |
| 53 --paper-checkbox-checked-color: var(--default-primary-color); | |
| 54 --paper-checkbox-checked-ink-color: var(--default-primary-color); | |
| 55 } | |
| 56 </style> | |
| 57 | |
| 58 <link rel="import" type="css" href="paper-checkbox.css"> | 58 <link rel="import" type="css" href="paper-checkbox.css"> |
| 59 | 59 |
| 60 <template> | 60 <template> |
| 61 | 61 |
| 62 <div id="checkboxContainer"> | 62 <div id="checkboxContainer"> |
| 63 <paper-ripple id="ink" class="circle" recenters checked$="[[checked]]"></p
aper-ripple> | 63 <paper-ripple id="ink" class="circle" center checked$="[[checked]]"></pape
r-ripple> |
| 64 <div id="checkbox" class$="[[_computeCheckboxClass(checked)]]"> | 64 <div id="checkbox" class$="[[_computeCheckboxClass(checked)]]"> |
| 65 <div id="checkmark" class$="[[_computeCheckmarkClass(checked)]]"></div> | 65 <div id="checkmark" class$="[[_computeCheckmarkClass(checked)]]"></div> |
| 66 </div> | 66 </div> |
| 67 </div> | 67 </div> |
| 68 | 68 |
| 69 <div id="checkboxLabel" aria-hidden="true"><content></content></div> | 69 <div id="checkboxLabel" aria-hidden="true"><content></content></div> |
| 70 | 70 |
| 71 </template> | 71 </template> |
| 72 </dom-module> | |
| 73 | 72 |
| 74 <script> | 73 <script> |
| 75 Polymer({ | 74 Polymer({ |
| 76 is: 'paper-checkbox', | 75 is: 'paper-checkbox', |
| 77 | 76 |
| 78 // The custom properties shim is currently an opt-in feature. | 77 behaviors: [ |
| 79 enableCustomStyleProperties: true, | 78 Polymer.PaperRadioButtonBehavior |
| 79 ], |
| 80 | 80 |
| 81 behaviors: [ | 81 hostAttributes: { |
| 82 Polymer.PaperRadioButtonBehavior | 82 role: 'checkbox', |
| 83 ], | 83 'aria-checked': false, |
| 84 | 84 tabindex: 0 |
| 85 hostAttributes: { | |
| 86 role: 'checkbox', | |
| 87 'aria-checked': false, | |
| 88 tabindex: 0 | |
| 89 }, | |
| 90 | |
| 91 properties: { | |
| 92 /** | |
| 93 * Fired when the checked state changes due to user interaction. | |
| 94 * | |
| 95 * @event change | |
| 96 */ | |
| 97 | |
| 98 /** | |
| 99 * Fired when the checked state changes. | |
| 100 * | |
| 101 * @event iron-change | |
| 102 */ | |
| 103 | |
| 104 /** | |
| 105 * Gets or sets the state, `true` is checked and `false` is unchecked. | |
| 106 * | |
| 107 * @attribute checked | |
| 108 * @type boolean | |
| 109 * @default false | |
| 110 */ | |
| 111 checked: { | |
| 112 type: Boolean, | |
| 113 value: false, | |
| 114 reflectToAttribute: true, | |
| 115 notify: true, | |
| 116 observer: '_checkedChanged' | |
| 117 }, | 85 }, |
| 118 | 86 |
| 119 /** | 87 properties: { |
| 120 * If true, the user cannot interact with this element. | 88 /** |
| 121 * | 89 * Fired when the checked state changes due to user interaction. |
| 122 * @attribute disabled | 90 * |
| 123 * @type boolean | 91 * @event change |
| 124 * @default false | 92 */ |
| 125 */ | 93 |
| 126 disabled: { | 94 /** |
| 127 type: Boolean | 95 * Fired when the checked state changes. |
| 96 * |
| 97 * @event iron-change |
| 98 */ |
| 99 |
| 100 /** |
| 101 * Gets or sets the state, `true` is checked and `false` is unchecked. |
| 102 */ |
| 103 checked: { |
| 104 type: Boolean, |
| 105 value: false, |
| 106 reflectToAttribute: true, |
| 107 notify: true, |
| 108 observer: '_checkedChanged' |
| 109 }, |
| 110 |
| 111 /** |
| 112 * If true, the button toggles the active state with each tap or press |
| 113 * of the spacebar. |
| 114 */ |
| 115 toggles: { |
| 116 type: Boolean, |
| 117 value: true, |
| 118 reflectToAttribute: true |
| 119 } |
| 120 }, |
| 121 |
| 122 ready: function() { |
| 123 if (Polymer.dom(this).textContent == '') { |
| 124 this.$.checkboxLabel.hidden = true; |
| 125 } else { |
| 126 this.setAttribute('aria-label', Polymer.dom(this).textContent); |
| 127 } |
| 128 this._isReady = true; |
| 129 }, |
| 130 |
| 131 // button-behavior hook |
| 132 _buttonStateChanged: function() { |
| 133 if (this.disabled) { |
| 134 return; |
| 135 } |
| 136 if (this._isReady) { |
| 137 this.checked = this.active; |
| 138 } |
| 139 }, |
| 140 |
| 141 _checkedChanged: function(checked) { |
| 142 this.setAttribute('aria-checked', this.checked ? 'true' : 'false'); |
| 143 this.active = this.checked; |
| 144 this.fire('iron-change'); |
| 145 }, |
| 146 |
| 147 _computeCheckboxClass: function(checked) { |
| 148 if (checked) { |
| 149 return 'checked'; |
| 150 } |
| 151 }, |
| 152 |
| 153 _computeCheckmarkClass: function(checked) { |
| 154 if (!checked) { |
| 155 return 'hidden'; |
| 156 } |
| 128 } | 157 } |
| 129 }, | 158 }) |
| 159 </script> |
| 130 | 160 |
| 131 ready: function() { | 161 </dom-module> |
| 132 this.toggles = true; | |
| 133 | |
| 134 if (this.$.checkboxLabel.textContent == '') { | |
| 135 this.$.checkboxLabel.hidden = true; | |
| 136 } else { | |
| 137 this.setAttribute('aria-label', this.$.checkboxLabel.textContent); | |
| 138 } | |
| 139 }, | |
| 140 | |
| 141 // button-behavior hook | |
| 142 _buttonStateChanged: function() { | |
| 143 this.checked = this.active; | |
| 144 }, | |
| 145 | |
| 146 _checkedChanged: function(checked) { | |
| 147 this.setAttribute('aria-checked', this.checked ? 'true' : 'false'); | |
| 148 this.active = this.checked; | |
| 149 this.fire('iron-change'); | |
| 150 }, | |
| 151 | |
| 152 _computeCheckboxClass: function(checked) { | |
| 153 if (checked) { | |
| 154 return 'checked'; | |
| 155 } | |
| 156 }, | |
| 157 | |
| 158 _computeCheckmarkClass: function(checked) { | |
| 159 if (!checked) { | |
| 160 return 'hidden'; | |
| 161 } | |
| 162 } | |
| 163 }) | |
| 164 </script> | |
| OLD | NEW |