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

Side by Side Diff: sky/framework/sky-checkbox/sky-checkbox.sky

Issue 836923002: Automate reflected properties in SkyElement. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
1 <!-- 1 <!--
2 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Copyright 2014 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 --> 5 -->
6 <import src="/sky/framework/sky-button/sky-button.sky" as="SkyButton" /> 6 <import src="/sky/framework/sky-button/sky-button.sky" as="SkyButton" />
7 7
8 <sky-element name="sky-checkbox"> 8 <sky-element name="sky-checkbox" attributes="checked:boolean">
9 <template> 9 <template>
10 <style> 10 <style>
11 :host { 11 :host {
12 display: flex; 12 display: flex;
13 justify-content: center; 13 justify-content: center;
14 align-items: center; 14 align-items: center;
15 -webkit-user-select: none; 15 -webkit-user-select: none;
16 cursor: pointer; 16 cursor: pointer;
17 width: 30px; 17 width: 30px;
18 height: 30px; 18 height: 30px;
(...skipping 19 matching lines...) Expand all
38 height: 20px; 38 height: 20px;
39 border-style: solid; 39 border-style: solid;
40 border-top: none; 40 border-top: none;
41 border-left: none; 41 border-left: none;
42 border-right-width: 2px; 42 border-right-width: 2px;
43 border-bottom-width: 2px; 43 border-bottom-width: 2px;
44 border-color: #0f9d58; 44 border-color: #0f9d58;
45 } 45 }
46 </style> 46 </style>
47 <div id="container" class="{{ containerStyle }}"> 47 <div id="container" class="{{ containerStyle }}">
48 <div id="check" class="{{ checkStyle }}"></div> 48 <div id="check" class="{{ checkStyle }}" />
49 </div> 49 </div>
50 </template> 50 </template>
51 <script> 51 <script>
52 module.exports = class extends SkyButton { 52 module.exports = class extends SkyButton {
53 created() { 53 created() {
54 super.created(); 54 super.created();
55 55
56 this.containerStyle = ""; 56 this.containerStyle = "";
57 this.checkStyle = ""; 57 this.checkStyle = "";
58 58
59 this.setChecked(this.getAttribute('checked') == 'true');
60
61 this.addEventListener("mouseup", function() { 59 this.addEventListener("mouseup", function() {
62 this.toggleChecked(); 60 this.checked = !this.checked;
63 }); 61 });
64 } 62 }
65 toggleChecked() { 63 checkedChanged(oldValue, newValue) {
66 this.setChecked(!this.checked); 64 this.checkStyle = newValue ? 'checked' : '';
67 } 65 }
68 setChecked(checked) { 66 highlightChanged(oldValue, newValue) {
69 this.checked = checked;
70 this.setAttribute('checked', checked);
71 this.checkStyle = checked ? 'checked' : '';
72 }
73 setHighlight(newValue) {
74 super.setHighlight(newValue);
75 this.containerStyle = newValue ? 'highlight' : ''; 67 this.containerStyle = newValue ? 'highlight' : '';
76 } 68 }
77 shadowRootReady() {
78 // TODO(esprehn): This is needed because the checked and highlight
79 // setters might be called before the shadowRoot is created since that
80 // doesn't happen until attached(). We should figure out a better way to do
81 // this.
82 this.setHighlight(this.highlight);
83 this.setChecked(this.checked);
84 }
85 }.register(); 69 }.register();
86 </script> 70 </script>
87 </sky-element> 71 </sky-element>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698