OLD | NEW |
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"> |
9 <template> | 9 <template> |
10 <style> | 10 <style> |
11 :host { | 11 :host { |
12 display: inline-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 width: 20px; | 16 cursor: pointer; |
| 17 width: 30px; |
| 18 height: 30px; |
| 19 } |
| 20 #container { |
| 21 border: solid 2px; |
| 22 border-color: rgba(90, 90, 90, 0.25); |
| 23 width: 10px; |
| 24 height: 10px; |
| 25 } |
| 26 #container.highlight { |
| 27 border-radius: 10px; |
| 28 background-color: orange; |
| 29 border-color: orange; |
| 30 } |
| 31 #check { |
| 32 top: 0px; |
| 33 left: 0px; |
| 34 } |
| 35 #check.checked { |
| 36 transform: translate(2px, -15px) rotate(45deg); |
| 37 width: 10px; |
17 height: 20px; | 38 height: 20px; |
18 border-radius: 4px; | 39 border-style: solid; |
19 border: 1px solid blue; | 40 border-top: none; |
20 margin: 5px; | 41 border-left: none; |
21 } | 42 border-right-width: 2px; |
22 :host([highlight=true]) { | 43 border-bottom-width: 2px; |
23 background-color: orange; | 44 border-color: #0f9d58; |
24 } | 45 } |
25 </style> | 46 </style> |
26 <template if="{{ checked }}"> | 47 <div id="container" class="{{ containerStyle }}"> |
27 <check>✓</check> | 48 <div id="check" class="{{ checkStyle }}"></div> |
28 </template> | 49 </div> |
29 </template> | 50 </template> |
30 <script> | 51 <script> |
31 module.exports = class extends SkyButton { | 52 module.exports = class extends SkyButton { |
32 created() { | 53 created() { |
33 super.created(); | 54 super.created(); |
| 55 |
| 56 this.containerStyle = ""; |
| 57 this.checkStyle = ""; |
| 58 |
34 this.setChecked(this.getAttribute('checked') == 'true'); | 59 this.setChecked(this.getAttribute('checked') == 'true'); |
35 | 60 |
36 this.addEventListener("mouseup", function() { | 61 this.addEventListener("mouseup", function() { |
37 this.toggleChecked(); | 62 this.toggleChecked(); |
38 }); | 63 }); |
39 } | 64 } |
40 toggleChecked() { | 65 toggleChecked() { |
41 this.setChecked(!this.checked); | 66 this.setChecked(!this.checked); |
42 } | 67 } |
43 setChecked(checked) { | 68 setChecked(checked) { |
44 this.checked = checked; | 69 this.checked = checked; |
45 this.setAttribute('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' : ''; |
| 76 } |
| 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); |
46 } | 84 } |
47 }.register(); | 85 }.register(); |
48 </script> | 86 </script> |
49 </sky-element> | 87 </sky-element> |
OLD | NEW |