UNPKG

6.61 kBJavaScriptView Raw
1var __extends = (this && this.__extends) || (function () {
2 var extendStatics = Object.setPrototypeOf ||
3 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
4 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
5 return function (d, b) {
6 extendStatics(d, b);
7 function __() { this.constructor = d; }
8 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
9 };
10})();
11import { Directive, ElementRef, HostBinding, Input, Renderer } from '@angular/core';
12import { isTrueProperty } from '../../util/util';
13import { Config } from '../../config/config';
14import { Ion } from '../ion';
15/**
16 * @name Icon
17 * @description
18 * Icons can be used on their own, or inside of a number of Ionic components.
19 * For a full list of available icons, check out the
20 * [Ionicons docs](../../../../ionicons).
21 *
22 * One feature of Ionicons in Ionic is when icon names are set, the actual icon
23 * which is rendered can change slightly depending on the mode the app is
24 * running from. For example, by setting the icon name of `alarm`, on iOS the
25 * icon will automatically apply `ios-alarm`, and on Material Design it will
26 * automatically apply `md-alarm`. This allows the developer to write the
27 * markup once while Ionic applies the appropriate icon based on the mode.
28 *
29 * @usage
30 * ```html
31 * <!-- automatically uses the correct "star" icon depending on the mode -->
32 * <ion-icon name="star"></ion-icon>
33 *
34 * <!-- explicity set the icon for each mode -->
35 * <ion-icon ios="ios-home" md="md-home"></ion-icon>
36 *
37 * <!-- always use the same icon, no matter what the mode -->
38 * <ion-icon name="ios-clock"></ion-icon>
39 * <ion-icon name="logo-twitter"></ion-icon>
40 * ```
41 *
42 * @demo /docs/demos/src/icon/
43 * @see {@link /docs/components#icons Icon Component Docs}
44 *
45 */
46var Icon = (function (_super) {
47 __extends(Icon, _super);
48 function Icon(config, elementRef, renderer) {
49 var _this = _super.call(this, config, elementRef, renderer, 'icon') || this;
50 /** @hidden */
51 _this._isActive = true;
52 /** @hidden */
53 _this._name = '';
54 /** @hidden */
55 _this._ios = '';
56 /** @hidden */
57 _this._md = '';
58 /** @hidden */
59 _this._css = '';
60 /**
61 * @hidden
62 */
63 _this._hidden = false;
64 _this._iconMode = config.get('iconMode');
65 return _this;
66 }
67 /**
68 * @hidden
69 */
70 Icon.prototype.ngOnDestroy = function () {
71 if (this._css) {
72 this.setElementClass(this._css, false);
73 }
74 };
75 Object.defineProperty(Icon.prototype, "name", {
76 /**
77 * @input {string} Specifies which icon to use. The appropriate icon will be used based on the mode.
78 * For more information, see [Ionicons](/docs/ionicons/).
79 */
80 get: function () {
81 return this._name;
82 },
83 set: function (val) {
84 if (!(/^md-|^ios-|^logo-/.test(val))) {
85 // this does not have one of the defaults
86 // so lets auto add in the mode prefix for them
87 this._name = this._iconMode + '-' + val;
88 }
89 else {
90 this._name = val;
91 }
92 this.update();
93 },
94 enumerable: true,
95 configurable: true
96 });
97 Object.defineProperty(Icon.prototype, "ios", {
98 /**
99 * @input {string} Specifies which icon to use on `ios` mode.
100 */
101 get: function () {
102 return this._ios;
103 },
104 set: function (val) {
105 this._ios = val;
106 this.update();
107 },
108 enumerable: true,
109 configurable: true
110 });
111 Object.defineProperty(Icon.prototype, "md", {
112 /**
113 * @input {string} Specifies which icon to use on `md` mode.
114 */
115 get: function () {
116 return this._md;
117 },
118 set: function (val) {
119 this._md = val;
120 this.update();
121 },
122 enumerable: true,
123 configurable: true
124 });
125 Object.defineProperty(Icon.prototype, "isActive", {
126 /**
127 * @input {boolean} If true, the icon is styled with an "active" appearance.
128 * An active icon is filled in, and an inactive icon is the outline of the icon.
129 * The `isActive` property is largely used by the tabbar. Only affects `ios` icons.
130 */
131 get: function () {
132 return this._isActive;
133 },
134 set: function (val) {
135 this._isActive = isTrueProperty(val);
136 this.update();
137 },
138 enumerable: true,
139 configurable: true
140 });
141 /**
142 * @hidden
143 */
144 Icon.prototype.update = function () {
145 var iconName;
146 if (this._ios && this._iconMode === 'ios') {
147 iconName = this._ios;
148 }
149 else if (this._md && this._iconMode === 'md') {
150 iconName = this._md;
151 }
152 else {
153 iconName = this._name;
154 }
155 var hidden = this._hidden = (iconName === null);
156 if (hidden) {
157 return;
158 }
159 var iconMode = iconName.split('-', 2)[0];
160 if (iconMode === 'ios' &&
161 !this._isActive &&
162 iconName.indexOf('logo-') < 0 &&
163 iconName.indexOf('-outline') < 0) {
164 iconName += '-outline';
165 }
166 var css = 'ion-' + iconName;
167 if (this._css === css) {
168 return;
169 }
170 if (this._css) {
171 this.setElementClass(this._css, false);
172 }
173 this._css = css;
174 this.setElementClass(css, true);
175 var label = iconName
176 .replace('ios-', '')
177 .replace('md-', '')
178 .replace('-', ' ');
179 this.setElementAttribute('aria-label', label);
180 };
181 Icon.decorators = [
182 { type: Directive, args: [{
183 selector: 'ion-icon',
184 host: {
185 'role': 'img'
186 }
187 },] },
188 ];
189 /** @nocollapse */
190 Icon.ctorParameters = function () { return [
191 { type: Config, },
192 { type: ElementRef, },
193 { type: Renderer, },
194 ]; };
195 Icon.propDecorators = {
196 'name': [{ type: Input },],
197 'ios': [{ type: Input },],
198 'md': [{ type: Input },],
199 'isActive': [{ type: Input },],
200 '_hidden': [{ type: HostBinding, args: ['class.hide',] },],
201 };
202 return Icon;
203}(Ion));
204export { Icon };
205//# sourceMappingURL=icon.js.map
\No newline at end of file