Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit f93e117

Browse files
programmistRobert Messerle
authored and
Robert Messerle
committed
fix(icon): Change iconSize param to viewBoxSize.
Updates code and docs. Also removes redundant function names. Fixes #1679 Closes #3123 BREAKING CHANGE: The API has changed for `md-icon` - `iconSize` has been changed to `viewBoxSize`
1 parent 545582d commit f93e117

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

src/components/icon/iconService.js

+32-24
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
* @param {string} id Icon name/id used to register the icon
7575
* @param {string} url specifies the external location for the data file. Used internally by `$http` to load the
7676
* data or as part of the lookup in `$templateCache` if pre-loading was configured.
77-
* @param {string=} iconSize Number indicating the width and height of the icons in the set. All icons
78-
* in the icon set must be the same size. Default size is 24.
77+
* @param {number=} viewBoxSize Sets the width and height the icon's viewBox.
78+
* It is ignored for icons with an existing viewBox. Default size is 24.
7979
*
8080
* @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
8181
*
@@ -104,8 +104,9 @@
104104
* @param {string} id Icon name/id used to register the iconset
105105
* @param {string} url specifies the external location for the data file. Used internally by `$http` to load the
106106
* data or as part of the lookup in `$templateCache` if pre-loading was configured.
107-
* @param {string=} iconSize Number indicating the width and height of the icons in the set. All icons
108-
* in the icon set must be the same size. Default size is 24.
107+
* @param {number=} viewBoxSize Sets the width and height of the viewBox of all icons in the set.
108+
* It is ignored for icons with an existing viewBox. All icons in the icon set should be the same size.
109+
* Default value is 24.
109110
*
110111
* @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
111112
*
@@ -133,8 +134,9 @@
133134
*
134135
* @param {string} url specifies the external location for the data file. Used internally by `$http` to load the
135136
* data or as part of the lookup in `$templateCache` if pre-loading was configured.
136-
* @param {string=} iconSize Number indicating the width and height of the icons in the set. All icons
137-
* in the icon set must be the same size. Default size is 24.
137+
* @param {number=} viewBoxSize Sets the width and height of the viewBox of all icons in the set.
138+
* It is ignored for icons with an existing viewBox. All icons in the icon set should be the same size.
139+
* Default value is 24.
138140
*
139141
* @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
140142
*
@@ -184,15 +186,14 @@
184186

185187
/**
186188
* @ngdoc method
187-
* @name $mdIconProvider#defaultIconSize
189+
* @name $mdIconProvider#defaultViewBoxSize
188190
*
189191
* @description
190192
* While `<md-icon />` markup can also be style with sizing CSS, this method configures
191193
* the default width **and** height used for all icons; unless overridden by specific CSS.
192194
* The default sizing is (24px, 24px).
193-
*
194-
* @param {string} iconSize Number indicating the width and height of the icons in the set. All icons
195-
* in the icon set must be the same size. Default size is 24.
195+
* @param {number=} viewBoxSize Sets the width and height of the viewBox for an icon or an icon set.
196+
* All icons in a set should be the same size. The default value is 24.
196197
*
197198
* @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
198199
*
@@ -203,43 +204,50 @@
203204
* // Configure URLs for icons specified by [set:]id.
204205
*
205206
* $mdIconProvider
206-
* .defaultIconSize(36) // Register a default icon size (width == height)
207+
* .defaultViewBoxSize(36) // Register a default icon size (width == height)
207208
* });
208209
* </hljs>
209210
*
210211
*/
211212

212213
var config = {
213-
defaultIconSize: 24,
214+
defaultViewBoxSize: 24,
214215
defaultFontSet: 'material-icons',
215216
fontSets : [ ]
216217
};
217218

218219
function MdIconProvider() { }
219220

220221
MdIconProvider.prototype = {
221-
222-
icon : function icon(id, url, iconSize) {
222+
icon : function (id, url, viewBoxSize) {
223223
if ( id.indexOf(':') == -1 ) id = '$default:' + id;
224224

225-
config[id] = new ConfigurationItem(url, iconSize );
225+
config[id] = new ConfigurationItem(url, viewBoxSize );
226226
return this;
227227
},
228-
iconSet : function iconSet(id, url, iconSize) {
229-
config[id] = new ConfigurationItem(url, iconSize );
228+
229+
iconSet : function (id, url, viewBoxSize) {
230+
config[id] = new ConfigurationItem(url, viewBoxSize );
230231
return this;
231232
},
232-
defaultIconSet : function defaultIconSet(url, iconSize) {
233+
234+
defaultIconSet : function (url, viewBoxSize) {
233235
var setName = '$default';
234236

235237
if ( !config[setName] ) {
236-
config[setName] = new ConfigurationItem(url, iconSize );
238+
config[setName] = new ConfigurationItem(url, viewBoxSize );
237239
}
238240

239-
config[setName].iconSize = iconSize || config.defaultIconSize;
241+
config[setName].viewBoxSize = viewBoxSize || config.defaultViewBoxSize;
242+
240243
return this;
241244
},
242245

246+
defaultViewBoxSize : function (viewBoxSize) {
247+
config.defaultViewBoxSize = viewBoxSize;
248+
return this;
249+
},
250+
243251
/**
244252
* Register an alias name associated with a font-icon library style ;
245253
*/
@@ -312,9 +320,9 @@
312320
* Configuration item stored in the Icon registry; used for lookups
313321
* to load if not already cached in the `loaded` cache
314322
*/
315-
function ConfigurationItem(url, iconSize) {
323+
function ConfigurationItem(url, viewBoxSize) {
316324
this.url = url;
317-
this.iconSize = iconSize || config.defaultIconSize;
325+
this.viewBoxSize = viewBoxSize || config.defaultViewBoxSize;
318326
}
319327

320328
/**
@@ -512,13 +520,13 @@
512520
* loaded iconCache store.
513521
*/
514522
function prepareAndStyle() {
515-
var iconSize = this.config ? this.config.iconSize : config.defaultIconSize;
523+
var viewBoxSize = this.config ? this.config.viewBoxSize : config.defaultViewBoxSize;
516524
angular.forEach({
517525
'fit' : '',
518526
'height': '100%',
519527
'width' : '100%',
520528
'preserveAspectRatio': 'xMidYMid meet',
521-
'viewBox' : this.element.getAttribute('viewBox') || ('0 0 ' + iconSize + ' ' + iconSize)
529+
'viewBox' : this.element.getAttribute('viewBox') || ('0 0 ' + viewBoxSize + ' ' + viewBoxSize)
522530
}, function(val, attr) {
523531
this.element.setAttribute(attr, val);
524532
}, this);

0 commit comments

Comments
 (0)