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-radio-button-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 <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); | |
54 } | |
55 </style> | |
56 | |
57 <dom-module id="paper-checkbox"> | |
58 <link rel="import" type="css" href="paper-checkbox.css"> | |
59 | |
60 <template> | |
61 | |
62 <div id="checkboxContainer"> | |
63 <paper-ripple id="ink" class="circle" center checked$="[[checked]]"></pape
r-ripple> | |
64 <div id="checkbox" class$="[[_computeCheckboxClass(checked)]]"> | |
65 <div id="checkmark" class$="[[_computeCheckmarkClass(checked)]]"></div> | |
66 </div> | |
67 </div> | |
68 | |
69 <div id="checkboxLabel" aria-hidden="true"><content></content></div> | |
70 | |
71 </template> | |
72 | |
73 <script> | |
74 Polymer({ | |
75 is: 'paper-checkbox', | |
76 | |
77 behaviors: [ | |
78 Polymer.PaperRadioButtonBehavior | |
79 ], | |
80 | |
81 hostAttributes: { | |
82 role: 'checkbox', | |
83 'aria-checked': false, | |
84 tabindex: 0 | |
85 }, | |
86 | |
87 properties: { | |
88 /** | |
89 * Fired when the checked state changes due to user interaction. | |
90 * | |
91 * @event change | |
92 */ | |
93 | |
94 /** | |
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 } | |
157 } | |
158 }) | |
159 </script> | |
160 | |
161 </dom-module> | |
OLD | NEW |