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

Side by Side Diff: third_party/polymer/v0_8/components/paper-checkbox/paper-checkbox.html

Issue 1082403004: Import Polymer 0.8 and several key elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also remove polymer/explainer Created 5 years, 7 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-ripple/paper-ripple.html">
13 <link rel="import" href="../paper-styles/default-theme.html">
14
15 <!--
16 `paper-checkbox` is a button that can be either checked or unchecked. User
17 can tap the checkbox to check or uncheck it. Usually you use checkboxes
18 to allow user to select multiple options from a set. If you have a single
19 ON/OFF option, avoid using a single checkbox and use `paper-toggle-button`
20 instead.
21
22 Example:
23
24 <paper-checkbox>label</paper-checkbox>
25
26 <paper-checkbox checked> label</paper-checkbox>
27
28 Styling a checkbox:
29
30 <style is="x-style">
31 * {
32 /* Unhecked state colors. */
33 --paper-checkbox-unchecked-color: #5a5a5a;
34 --paper-checkbox-unchecked-ink-color: #5a5a5a;
35
36 /* Checked state colors. */
37 --paper-checkbox-checked-color: #009688;
38 --paper-checkbox-checked-ink-color: #009688;
39 }
40 </style>
41
42 @group Paper Elements
43 @class paper-checkbox
44 -->
45
46 /* TODO: This needs to use core-focusable when it's ready. */
47 <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">
59
60 <template>
61
62 <div id="checkboxContainer">
63 <paper-ripple id="ink" class="circle" recenters checked$="[[checked]]"></p aper-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 </dom-module>
73
74 <script>
75 Polymer({
76 is: 'paper-checkbox',
77
78 // The custom properties shim is currently an opt-in feature.
79 enableCustomStyleProperties: true,
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 * @attribute checked
104 * @type boolean
105 * @default false
106 */
107 checked: {
108 type: Boolean,
109 value: false,
110 reflectToAttribute: true,
111 observer: '_checkedChanged'
112 },
113
114 /**
115 * If true, the user cannot interact with this element.
116 *
117 * @attribute disabled
118 * @type boolean
119 * @default false
120 */
121 disabled: {
122 type: Boolean
123 }
124 },
125
126 listeners: {
127 keydown: '_onKeyDown',
128 mousedown: '_onMouseDown'
129 },
130
131 ready: function() {
132 if (this.$.checkboxLabel.textContent == '') {
133 this.$.checkboxLabel.hidden = true;
134 } else {
135 this.setAttribute('aria-label', this.$.checkboxLabel.textContent);
136 }
137 },
138
139 _computeCheckboxClass: function(checked) {
140 if (checked) {
141 return 'checked';
142 }
143 },
144
145 _computeCheckmarkClass: function(checked) {
146 if (!checked) {
147 return 'hidden';
148 }
149 },
150
151 _onKeyDown: function(e) {
152 // Enter key.
153 if (e.keyCode === 13) {
154 this._onMouseDown();
155 e.preventDefault();
156 }
157 },
158
159 _onMouseDown: function() {
160 if (this.disabled) {
161 return;
162 }
163
164 var old = this.checked;
165 this.checked = !this.checked;
166
167 if (this.checked !== old) {
168 this.fire('iron-change');
169 }
170 },
171
172 _checkedChanged: function() {
173 this.setAttribute('aria-checked', this.checked ? 'true' : 'false');
174 this.fire('iron-change');
175 }
176 })
177 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698