OLD | NEW |
1 <!-- | 1 <!-- |
| 2 @license |
2 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
3 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
5 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
6 Code distributed by Google as part of the polymer project is also | 7 Code distributed by Google as part of the polymer project is also |
7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
8 --> | 9 --> |
| 10 |
| 11 <link rel="import" href="../polymer/polymer.html"> |
| 12 <link rel="import" href="../iron-meta/iron-meta.html"> |
| 13 <link rel="import" href="../iron-flex-layout/iron-flex-layout.html"> |
| 14 |
9 <!-- | 15 <!-- |
10 | 16 |
11 The `iron-icon` element displays an icon. By default an icon renders as a 24px s
quare. | 17 The `iron-icon` element displays an icon. By default an icon renders as a 24px s
quare. |
12 | 18 |
13 Example using src: | 19 Example using src: |
14 | 20 |
15 <iron-icon src="star.png"></iron-icon> | 21 <iron-icon src="star.png"></iron-icon> |
16 | 22 |
17 Example setting size to 32px x 32px: | 23 Example setting size to 32px x 32px: |
18 | 24 |
(...skipping 26 matching lines...) Expand all Loading... |
45 | 51 |
46 Example of using an icon named `cherry` from a custom iconset with the ID `fruit
`: | 52 Example of using an icon named `cherry` from a custom iconset with the ID `fruit
`: |
47 | 53 |
48 <iron-icon icon="fruit:cherry"></iron-icon> | 54 <iron-icon icon="fruit:cherry"></iron-icon> |
49 | 55 |
50 See [iron-iconset](#iron-iconset) and [iron-iconset-svg](#iron-iconset-svg) for
more information about | 56 See [iron-iconset](#iron-iconset) and [iron-iconset-svg](#iron-iconset-svg) for
more information about |
51 how to create a custom iconset. | 57 how to create a custom iconset. |
52 | 58 |
53 See [iron-icons](http://www.polymer-project.org/components/iron-icons/demo.html)
for the default set of icons. | 59 See [iron-icons](http://www.polymer-project.org/components/iron-icons/demo.html)
for the default set of icons. |
54 | 60 |
55 @group Polymer Core Elements | 61 |
| 62 ### Styling |
| 63 |
| 64 The following custom properties are available for styling: |
| 65 |
| 66 Custom property | Description | Default |
| 67 ----------------|-------------|---------- |
| 68 `--iron-icon-width` | Width of the icon | `24px` |
| 69 `--iron-icon-height` | Height of the icon | `24px` |
| 70 |
| 71 @group Iron Elements |
56 @element iron-icon | 72 @element iron-icon |
| 73 @demo demo/index.html |
| 74 @hero hero.svg |
57 @homepage polymer.github.io | 75 @homepage polymer.github.io |
58 --> | 76 --> |
59 | 77 |
60 <link rel="import" href="../polymer/polymer.html"> | 78 <style is="custom-style"> |
61 <link rel="import" href="../iron-meta/iron-meta.html"> | 79 :root { |
62 <link rel="import" href="../iron-flex-layout/iron-flex-layout.html"> | 80 --iron-icon-width: 24px; |
63 | 81 --iron-icon-height: 24px; |
64 <style is="x-style"> | |
65 * { | |
66 --iron-icon-size: 24px; | |
67 } | 82 } |
68 </style> | 83 </style> |
69 | 84 |
70 <dom-module id="iron-icon"> | 85 <dom-module id="iron-icon"> |
71 | 86 |
72 <style> | 87 <style> |
73 :host { | 88 :host { |
74 mixin(--layout-inline --layout-center-center); | 89 @apply(--layout-inline); |
| 90 @apply(--layout-center-center); |
75 position: relative; | 91 position: relative; |
76 | 92 |
77 vertical-align: middle; | 93 vertical-align: middle; |
78 | 94 |
79 fill: currentcolor; | 95 fill: currentcolor; |
80 | 96 |
81 width: var(--iron-icon-size); | 97 width: var(--iron-icon-width); |
82 height: var(--iron-icon-size); | 98 height: var(--iron-icon-height); |
83 } | 99 } |
84 </style> | 100 </style> |
85 | 101 |
86 <template> | 102 <template> |
87 <iron-meta id="meta" type="iconset"></iron-meta> | 103 <iron-meta id="meta" type="iconset"></iron-meta> |
88 </template> | 104 </template> |
89 | 105 |
| 106 <script> |
| 107 |
| 108 Polymer({ |
| 109 |
| 110 is: 'iron-icon', |
| 111 |
| 112 properties: { |
| 113 |
| 114 /** |
| 115 * The name of the icon to use. The name should be of the form: |
| 116 * `iconset_name:icon_name`. |
| 117 */ |
| 118 icon: { |
| 119 type: String, |
| 120 observer: '_iconChanged' |
| 121 }, |
| 122 |
| 123 /** |
| 124 * The name of the theme to used, if one is specified by the |
| 125 * iconset. |
| 126 */ |
| 127 theme: { |
| 128 type: String, |
| 129 observer: '_updateIcon' |
| 130 }, |
| 131 |
| 132 /** |
| 133 * If using iron-icon without an iconset, you can set the src to be |
| 134 * the URL of an individual icon image file. Note that this will take |
| 135 * precedence over a given icon attribute. |
| 136 */ |
| 137 src: { |
| 138 type: String, |
| 139 observer: '_srcChanged' |
| 140 } |
| 141 }, |
| 142 |
| 143 _DEFAULT_ICONSET: 'icons', |
| 144 |
| 145 _iconChanged: function(icon) { |
| 146 var parts = (icon || '').split(':'); |
| 147 this._iconName = parts.pop(); |
| 148 this._iconsetName = parts.pop() || this._DEFAULT_ICONSET; |
| 149 this._updateIcon(); |
| 150 }, |
| 151 |
| 152 _srcChanged: function(src) { |
| 153 this._updateIcon(); |
| 154 }, |
| 155 |
| 156 _usesIconset: function() { |
| 157 return this.icon || !this.src; |
| 158 }, |
| 159 |
| 160 _updateIcon: function() { |
| 161 if (this._usesIconset()) { |
| 162 if (this._iconsetName) { |
| 163 this._iconset = this.$.meta.byKey(this._iconsetName); |
| 164 if (this._iconset) { |
| 165 this._iconset.applyIcon(this, this._iconName, this.theme); |
| 166 } else { |
| 167 this._warn(this._logf('_updateIcon', 'could not find iconset `' |
| 168 + this._iconsetName + '`, did you import the iconset?')); |
| 169 } |
| 170 } |
| 171 } else { |
| 172 if (!this._img) { |
| 173 this._img = document.createElement('img'); |
| 174 this._img.style.width = '100%'; |
| 175 this._img.style.height = '100%'; |
| 176 } |
| 177 this._img.src = this.src; |
| 178 Polymer.dom(this.root).appendChild(this._img); |
| 179 } |
| 180 } |
| 181 |
| 182 }); |
| 183 |
| 184 </script> |
| 185 |
90 </dom-module> | 186 </dom-module> |
91 | 187 |
92 <script> | |
93 | |
94 Polymer({ | |
95 | |
96 is: 'iron-icon', | |
97 | |
98 enableCustomStyleProperties: true, | |
99 | |
100 properties: { | |
101 | |
102 icon: { | |
103 type: String, | |
104 observer: '_iconChanged' | |
105 }, | |
106 | |
107 theme: { | |
108 type: String, | |
109 observer: '_updateIcon' | |
110 }, | |
111 | |
112 src: { | |
113 type: String, | |
114 observer: '_srcChanged' | |
115 } | |
116 | |
117 }, | |
118 | |
119 _DEFAULT_ICONSET: 'icons', | |
120 | |
121 _iconChanged: function(icon) { | |
122 var parts = (icon || '').split(':'); | |
123 this._iconName = parts.pop(); | |
124 this._iconsetName = parts.pop() || this._DEFAULT_ICONSET; | |
125 this._updateIcon(); | |
126 }, | |
127 | |
128 _srcChanged: function(src) { | |
129 this._updateIcon(); | |
130 }, | |
131 | |
132 _usesIconset: function() { | |
133 return this.icon || !this.src; | |
134 }, | |
135 | |
136 _updateIcon: function() { | |
137 if (this._usesIconset()) { | |
138 this._iconset = this.$.meta.byKey(this._iconsetName); | |
139 if (this._iconset) { | |
140 this._iconset.applyIcon(this, this._iconName, this.theme); | |
141 } else { | |
142 console.warn('iron-icon: could not find iconset `' | |
143 + this._iconsetName + '`, did you import the iconset?'); | |
144 } | |
145 } else { | |
146 if (!this._img) { | |
147 this._img = document.createElement('img'); | |
148 this._img.style.width = '100%'; | |
149 this._img.style.height = '100%'; | |
150 } | |
151 this._img.src = this.src; | |
152 Polymer.dom(this.root).appendChild(this._img); | |
153 } | |
154 } | |
155 | |
156 }); | |
157 | |
158 </script> | |
OLD | NEW |