OLD | NEW |
(Empty) | |
| 1 <!-- |
| 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 |
| 4 // found in the LICENSE file. |
| 5 --> |
| 6 <import src="/sky/framework/sky-element/sky-element.sky" as="SkyElement" /> |
| 7 |
| 8 <sky-element name="sky-button"> |
| 9 <template> |
| 10 <style> |
| 11 :host { |
| 12 display: inline-flex; |
| 13 border-radius: 4px; |
| 14 justify-content: center; |
| 15 align-items: center; |
| 16 border: 1px solid blue; |
| 17 -webkit-user-select: none; |
| 18 margin: 5px; |
| 19 } |
| 20 :host([highlight=true]) { |
| 21 background-color: orange; |
| 22 } |
| 23 </style> |
| 24 <content></content> |
| 25 </template> |
| 26 <script> |
| 27 module.exports = class extends SkyElement { |
| 28 created() { |
| 29 this.tabIndex = 0; // Make focusable. |
| 30 this.setHighlight(false); |
| 31 |
| 32 this.addEventListener("mousedown", function() { |
| 33 this.setHighlight(true); |
| 34 }); |
| 35 this.addEventListener("mouseup", function() { |
| 36 this.setHighlight(false); |
| 37 }); |
| 38 this.addEventListener("mouseout", function() { |
| 39 this.setHighlight(false); |
| 40 }); |
| 41 } |
| 42 setHighlight(newValue) { |
| 43 // Set both a property and an attribute to keep both parents happy. |
| 44 this.setAttribute('highlight', newValue); |
| 45 this.highlight = newValue; |
| 46 } |
| 47 }.register(); |
| 48 </script> |
| 49 </sky-element> |
OLD | NEW |