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

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

Issue 946813005: Port Sky widgets demo to Dart (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « sky/framework/sky-button.sky ('k') | sky/framework/sky-element.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!-- 1 <!--
2 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Copyright 2015 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-button.sky" as="SkyButton" /> 6 <import src="sky-button.sky" />
7 <import src="sky-element.sky" />
7 8
8 <sky-element 9 <sky-element attributes="checked:boolean, highlight:boolean">
9 name="sky-checkbox"
10 attributes="checked:boolean"
11 on-click="handleClick">
12 <template> 10 <template>
13 <style> 11 <style>
14 :host { 12 :host {
15 display: flex; 13 display: flex;
16 justify-content: center; 14 justify-content: center;
17 align-items: center; 15 align-items: center;
18 -webkit-user-select: none; 16 -webkit-user-select: none;
19 cursor: pointer; 17 cursor: pointer;
20 width: 30px; 18 width: 30px;
21 height: 30px; 19 height: 30px;
(...skipping 18 matching lines...) Expand all
40 width: 10px; 38 width: 10px;
41 height: 20px; 39 height: 20px;
42 border-style: solid; 40 border-style: solid;
43 border-top: none; 41 border-top: none;
44 border-left: none; 42 border-left: none;
45 border-right-width: 2px; 43 border-right-width: 2px;
46 border-bottom-width: 2px; 44 border-bottom-width: 2px;
47 border-color: #0f9d58; 45 border-color: #0f9d58;
48 } 46 }
49 </style> 47 </style>
50 <div id="container" class="{{ containerStyle }}"> 48 <div id="container">
51 <div id="check" class="{{ checkStyle }}" /> 49 <div id="check" />
52 </div> 50 </div>
53 </template> 51 </template>
54 <script> 52 <script>
55 module.exports = class extends SkyButton { 53 import "dart:sky";
56 created() {
57 super.created();
58 54
59 this.containerStyle = ''; 55 @Tagname('sky-checkbox')
60 this.checkStyle = ''; 56 class SkyCheckbox extends SkyButton {
57 Element _container;
58 Element _check;
59
60 SkyCheckbox() {
61 addEventListener('click', _handleClick);
61 } 62 }
62 checkedChanged(oldValue, newValue) { 63
63 this.checkStyle = newValue ? 'checked' : ''; 64 static String _checkClassForValue(bool value) => value ? 'checked' : '';
65 static String _containerClassForValue(bool value) => value ? 'highlight' : '';
66
67 void shadowRootReady() {
68 _container = shadowRoot.getElementById('container');
69 _container.setAttribute('class', _containerClassForValue(highlight));
70 _check = shadowRoot.getElementById('check');
71 _check.setAttribute('class', _checkClassForValue(checked));
64 } 72 }
65 highlightChanged(oldValue, newValue) { 73
66 this.containerStyle = newValue ? 'highlight' : ''; 74 void checkedChanged(bool oldValue, bool newValue) {
75 if (_check != null)
76 _check.setAttribute('class', _checkClassForValue(newValue));
67 } 77 }
68 handleClick() { 78
69 this.checked = !this.checked; 79 void highlightChanged(bool oldValue, bool newValue) {
80 if (_container != null)
81 _container.setAttribute('class', _containerClassForValue(newValue));
70 } 82 }
71 }.register(); 83
84 void _handleClick(_) {
85 checked = !checked;
86 }
87 }
88
89 _init(script) => register(script, SkyCheckbox);
72 </script> 90 </script>
73 </sky-element> 91 </sky-element>
OLDNEW
« no previous file with comments | « sky/framework/sky-button.sky ('k') | sky/framework/sky-element.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698