OLD | NEW |
1 <!-- | 1 <!-- |
2 // Copyright 2015 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/framework/sky-element.sky" /> | 6 <import src="/sky/framework/sky-element.sky" /> |
7 | 7 |
8 <sky-element attributes="ticker:string"> | 8 <sky-element attributes="ticker:string"> |
9 <template> | 9 <template> |
10 <style> | 10 <style> |
| 11 :host { |
| 12 height: 50px; |
| 13 display: flex; |
| 14 width: 100%; |
| 15 border: 1px solid black; |
| 16 } |
| 17 #ticker { |
| 18 padding: 10px; |
| 19 flex-grow: 1; |
| 20 } |
| 21 #change { |
| 22 padding: 10px; |
| 23 border-radius: 5px; |
| 24 min-width: 60px; |
| 25 text-align: right; |
| 26 } |
| 27 .positive { |
| 28 background-color: green; |
| 29 } |
| 30 .negative { |
| 31 background-color: red; |
| 32 } |
11 </style> | 33 </style> |
12 <div id="ticker" /> | 34 <div id="ticker" /> |
| 35 <div id="change" /> |
13 </template> | 36 </template> |
14 <script> | 37 <script> |
15 import "dart:sky"; | 38 import "dart:sky"; |
16 | 39 |
17 @Tagname('stock') | 40 @Tagname('stock') |
18 class Stock extends SkyElement { | 41 class Stock extends SkyElement { |
19 Element _ticker; | 42 var model; // model.Stock |
20 | 43 |
21 void shadowRootReady() { | 44 void shadowRootReady() { |
22 _ticker = shadowRoot.getElementById('ticker'); | 45 Element ticker = shadowRoot.getElementById('ticker'); |
23 _ticker.textContent = ticker; | 46 ticker.textContent = model.symbol; |
| 47 |
| 48 Element change = shadowRoot.getElementById('change'); |
| 49 change.textContent = "${model.percentChange.toStringAsFixed(2)}%"; |
| 50 change.classList.add((model.percentChange < 0) ? 'negative' : 'positive'); |
24 } | 51 } |
25 } | 52 } |
26 | 53 |
27 _init(script) => register(script, Stock); | 54 _init(script) => register(script, Stock); |
28 </script> | 55 </script> |
29 </sky-element> | 56 </sky-element> |
OLD | NEW |