diff options
author | Phil Hughes <me@iamphill.com> | 2017-10-17 07:56:10 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-10-17 07:56:10 +0000 |
commit | 3fa410c831dac1dd1a74a14260ed99a5920218f8 (patch) | |
tree | c120ac264dae1315c575bbf516d3224faf3d07c3 | |
parent | 30083458b9e2a1e9e54ea09aea8c037e76732af4 (diff) | |
parent | 13b299f4ff06a045269937f9e5fce5991bfca2d8 (diff) | |
download | gitlab-ce-3fa410c831dac1dd1a74a14260ed99a5920218f8.tar.gz |
Merge branch 'sprite-icon-class' into 'master'convert-js-modules
Add ability to pass class name to spriteIcon helper
Closes #39079
See merge request gitlab-org/gitlab-ce!14855
-rw-r--r-- | app/assets/javascripts/lib/utils/common_utils.js | 6 | ||||
-rw-r--r-- | spec/javascripts/lib/utils/common_utils_spec.js | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js index 9f05cf16967..07899777a1e 100644 --- a/app/assets/javascripts/lib/utils/common_utils.js +++ b/app/assets/javascripts/lib/utils/common_utils.js @@ -403,7 +403,11 @@ export const setCiStatusFavicon = (pageUrl) => { }); }; -export const spriteIcon = icon => `<svg><use xlink:href="${gon.sprite_icons}#${icon}" /></svg>`; +export const spriteIcon = (icon, className = '') => { + const classAttribute = className.length > 0 ? `class="${className}"` : ''; + + return `<svg ${classAttribute}><use xlink:href="${gon.sprite_icons}#${icon}" /></svg>`; +}; export const imagePath = imgUrl => `${gon.asset_host || ''}${gon.relative_url_root || ''}/assets/${imgUrl}`; diff --git a/spec/javascripts/lib/utils/common_utils_spec.js b/spec/javascripts/lib/utils/common_utils_spec.js index f86f2f260c3..6613b7dee6b 100644 --- a/spec/javascripts/lib/utils/common_utils_spec.js +++ b/spec/javascripts/lib/utils/common_utils_spec.js @@ -474,7 +474,11 @@ describe('common_utils', () => { }); it('should return the svg for a linked icon', () => { - expect(gl.utils.spriteIcon('test')).toEqual('<svg><use xlink:href="icons.svg#test" /></svg>'); + expect(gl.utils.spriteIcon('test')).toEqual('<svg ><use xlink:href="icons.svg#test" /></svg>'); + }); + + it('should set svg className when passed', () => { + expect(gl.utils.spriteIcon('test', 'fa fa-test')).toEqual('<svg class="fa fa-test"><use xlink:href="icons.svg#test" /></svg>'); }); }); }); |