OLD | NEW |
| (Empty) |
1 <!-- | |
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 | |
4 // found in the LICENSE file. | |
5 --> | |
6 <import src="sky-element.sky" /> | |
7 | |
8 <sky-element attributes="type:string, size:number"> | |
9 <template> | |
10 <img /> | |
11 </template> | |
12 <script> | |
13 import "dart:sky"; | |
14 | |
15 const String kAssetBase = '/sky/assets/material-design-icons'; | |
16 | |
17 @Tagname('sky-icon') | |
18 class SkyIcon extends SkyElement { | |
19 Element _img; | |
20 | |
21 void _setSize(int size) { | |
22 _img.style['height'] = '${size}px'; | |
23 _img.style['width'] = '${size}px'; | |
24 } | |
25 | |
26 void _setSrc(String type, int size) { | |
27 List<String> parts = type.split('/'); | |
28 if (parts.length < 2) | |
29 return; | |
30 String category = parts[0]; | |
31 String subtype = parts[1]; | |
32 _img.src = '${kAssetBase}/${category}/2x_web/ic_${subtype}_${size}dp.png'; | |
33 } | |
34 | |
35 void shadowRootReady() { | |
36 _img = shadowRoot.firstElementChild; | |
37 int size = this.size.floor(); | |
38 _setSize(size); | |
39 _setSrc(type, size); | |
40 } | |
41 | |
42 void typeChanged(String oldValue, String newValue) { | |
43 if (_img != null) | |
44 _setSrc(newValue, size.floor()); | |
45 } | |
46 | |
47 void sizeChanged(double oldValue, double newValue) { | |
48 if (_img != null) { | |
49 _setSize(newValue.floor()); | |
50 _setSrc(type, newValue.floor()); | |
51 } | |
52 } | |
53 } | |
54 | |
55 _init(script) => register(script, SkyIcon); | |
56 </script> | |
57 </sky-element> | |
OLD | NEW |