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 --> 9 10 <!-- 11 `paper-checkbox` is a button that can be either checked or unchecked. User 12 can tap the checkbox to check or uncheck it. Usually you use checkboxes 13 to allow user to select multiple options from a set. If you have a single 14 ON/OFF option, avoid using a single checkbox and use `paper-toggle-button` 15 instead. 16 17 Example: 18 19 <paper-checkbox></paper-checkbox> 20 21 <paper-checkbox checked></paper-checkbox> 22 23 Styling checkbox: 24 25 To change the ink color for checked state: 26 27 paper-checkbox::shadow #ink[checked] { 28 color: #4285f4; 29 } 30 31 To change the checkbox checked color: 32 33 paper-checkbox::shadow #checkbox.checked { 34 border-color: #4285f4; 35 } 36 37 To change the ink color for unchecked state: 38 39 paper-checkbox::shadow #ink { 40 color: #b5b5b5; 41 } 42 43 To change the checbox unchecked color: 44 45 paper-checkbox::shadow #checkbox { 46 border-color: #b5b5b5; 47 } 48 49 @group Paper Elements 50 @element paper-checkbox 51 @extends paper-radio-button 52 @homepage github.io 53 --> 54 55 <link rel="import" href="../paper-radio-button/paper-radio-button.html"> 56 57 <polymer-element name="paper-checkbox" extends="paper-radio-button" role="checkbox"> 58 <template> 59 60 <link rel="stylesheet" href="paper-checkbox.css"> 61 62 <div id="checkboxContainer" class="{{ {labeled: label} | tokenList }}" > 63 64 <paper-ripple id="ink" class="circle recenteringTouch" checked?="{{!checked}}"></paper-ripple> 65 66 <div id="checkbox" on-animationend="{{checkboxAnimationEnd}}" on-webkitAnimationEnd="{{checkboxAnimationEnd}}"></div> 67 68 </div> 69 70 <div id="checkboxLabel" hidden?="{{!label}}">{{label}}<content></content></div> 71 72 </template> 73 <script> 74 75 Polymer('paper-checkbox', { 76 77 /** 78 * Fired when the checked state changes. 79 * 80 * @event change 81 */ 82 83 toggles: true, 84 85 checkedChanged: function() { 86 var cl = this.$.checkbox.classList; 87 cl.toggle('checked', this.checked); 88 cl.toggle('unchecked', !this.checked); 89 cl.toggle('checkmark', !this.checked); 90 cl.toggle('box', this.checked); 91 this.setAttribute('aria-checked', this.checked ? 'true': 'false'); 92 this.fire('change'); 93 }, 94 95 checkboxAnimationEnd: function() { 96 var cl = this.$.checkbox.classList; 97 cl.toggle('checkmark', this.checked && !cl.contains('checkmark')); 98 cl.toggle('box', !this.checked && !cl.contains('box')); 99 } 100 101 }); 102 103 </script> 104 </polymer-element> 105