2018-04-04 21:46:37 +03:00
|
|
|
import DEFAULT_ATTRS from '../src/default-attrs.json';
|
2018-02-21 03:30:59 +03:00
|
|
|
|
|
|
|
/**
|
2018-04-02 02:25:21 +03:00
|
|
|
* Build an SVG sprite string containing SVG symbols.
|
|
|
|
* @param {Object} icons
|
|
|
|
* @returns {string}
|
2018-02-21 03:30:59 +03:00
|
|
|
*/
|
|
|
|
function buildSpriteString(icons) {
|
|
|
|
const symbols = Object.keys(icons)
|
|
|
|
.map(icon => toSvgSymbol(icon, icons[icon]))
|
|
|
|
.join('');
|
|
|
|
|
2018-04-04 21:46:37 +03:00
|
|
|
return `<svg xmlns="${DEFAULT_ATTRS.xmlns}"><defs>${symbols}</defs></svg>`;
|
2018-02-21 03:30:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-02 02:25:21 +03:00
|
|
|
* Create an SVG symbol string.
|
|
|
|
* @param {string} name - Icon name
|
|
|
|
* @param {string} contents - SVG contents
|
|
|
|
* @returns {string}
|
2018-02-21 03:30:59 +03:00
|
|
|
*/
|
|
|
|
function toSvgSymbol(name, contents) {
|
2018-04-04 21:46:37 +03:00
|
|
|
return `<symbol id="${name}" viewBox="${DEFAULT_ATTRS.viewBox}">${
|
2018-04-02 02:25:21 +03:00
|
|
|
contents
|
|
|
|
}</symbol>`;
|
2018-02-21 03:30:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default buildSpriteString;
|