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

fix(icon): Change iconSize param to viewBoxSize. #3123

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions src/components/icon/iconService.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
* @param {string} id Icon name/id used to register the icon
* @param {string} url specifies the external location for the data file. Used internally by `$http` to load the
* data or as part of the lookup in `$templateCache` if pre-loading was configured.
* @param {string=} iconSize Number indicating the width and height of the icons in the set. All icons
* in the icon set must be the same size. Default size is 24.
* @param {number=} viewBoxSize Sets the width and height the icon's viewBox.
* It is ignored for icons with an existing viewBox. Default size is 24.
*
* @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
*
Expand Down Expand Up @@ -101,8 +101,9 @@
* @param {string} id Icon name/id used to register the iconset
* @param {string} url specifies the external location for the data file. Used internally by `$http` to load the
* data or as part of the lookup in `$templateCache` if pre-loading was configured.
* @param {string=} iconSize Number indicating the width and height of the icons in the set. All icons
* in the icon set must be the same size. Default size is 24.
* @param {number=} viewBoxSize Sets the width and height of the viewBox of all icons in the set.
* It is ignored for icons with an existing viewBox. All icons in the icon set should be the same size.
* Default value is 24.
*
* @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
*
Expand Down Expand Up @@ -130,8 +131,9 @@
*
* @param {string} url specifies the external location for the data file. Used internally by `$http` to load the
* data or as part of the lookup in `$templateCache` if pre-loading was configured.
* @param {string=} iconSize Number indicating the width and height of the icons in the set. All icons
* in the icon set must be the same size. Default size is 24.
* @param {number=} viewBoxSize Sets the width and height of the viewBox of all icons in the set.
* It is ignored for icons with an existing viewBox. All icons in the icon set should be the same size.
* Default value is 24.
*
* @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
*
Expand All @@ -149,15 +151,14 @@
*/
/**
* @ngdoc method
* @name $mdIconProvider#defaultIconSize
* @name $mdIconProvider#defaultViewBoxSize
*
* @description
* While `<md-icon />` markup can also be style with sizing CSS, this method configures
* the default width **and** height used for all icons; unless overridden by specific CSS.
* The default sizing is (24px, 24px).
*
* @param {string} iconSize Number indicating the width and height of the icons in the set. All icons
* in the icon set must be the same size. Default size is 24.
* @param {number=} viewBoxSize Sets the width and height of the viewBox for an icon or an icon set.
* All icons in a set should be the same size. The default value is 24.
*
* @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
*
Expand All @@ -168,45 +169,45 @@
* // Configure URLs for icons specified by [set:]id.
*
* $mdIconProvider
* .defaultIconSize(36) // Register a default icon size (width == height)
* .defaultViewBoxSize(36) // Register a default icon size (width == height)
* });
* </hljs>
*
*/

var config = {
defaultIconSize: 24
defaultViewBoxSize: 24
};

function MdIconProvider() { }

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

config[id] = new ConfigurationItem(url, iconSize );
config[id] = new ConfigurationItem(url, viewBoxSize );
return this;
},

iconSet : function iconSet(id, url, iconSize) {
config[id] = new ConfigurationItem(url, iconSize );
iconSet : function (id, url, viewBoxSize) {
config[id] = new ConfigurationItem(url, viewBoxSize );
return this;
},

defaultIconSet : function defaultIconSet(url, iconSize) {
defaultIconSet : function (url, viewBoxSize) {
var setName = '$default';

if ( !config[setName] ) {
config[setName] = new ConfigurationItem(url, iconSize );
config[setName] = new ConfigurationItem(url, viewBoxSize );
}

config[setName].iconSize = iconSize || config.defaultIconSize;
config[setName].viewBoxSize = viewBoxSize || config.defaultViewBoxSize;

return this;
},

defaultIconSize : function defaultIconSize(iconSize) {
config.defaultIconSize = iconSize;
defaultViewBoxSize : function (viewBoxSize) {
config.defaultViewBoxSize = viewBoxSize;
return this;
},

Expand Down Expand Up @@ -257,9 +258,9 @@
* Configuration item stored in the Icon registry; used for lookups
* to load if not already cached in the `loaded` cache
*/
function ConfigurationItem(url, iconSize) {
function ConfigurationItem(url, viewBoxSize) {
this.url = url;
this.iconSize = iconSize || config.defaultIconSize;
this.viewBoxSize = viewBoxSize || config.defaultViewBoxSize;
}

/**
Expand Down Expand Up @@ -434,13 +435,13 @@
* loaded iconCache store.
*/
function prepareAndStyle() {
var iconSize = this.config ? this.config.iconSize : config.defaultIconSize;
var viewBoxSize = this.config ? this.config.viewBoxSize : config.defaultViewBoxSize;
angular.forEach({
'fit' : '',
'height': '100%',
'width' : '100%',
'preserveAspectRatio': 'xMidYMid meet',
'viewBox' : this.element.getAttribute('viewBox') || ('0 0 ' + iconSize + ' ' + iconSize)
'viewBox' : this.element.getAttribute('viewBox') || ('0 0 ' + viewBoxSize + ' ' + viewBoxSize)
}, function(val, attr) {
this.element.setAttribute(attr, val);
}, this);
Expand Down