svgSprite.js 682 B

1234567891011121314151617
  1. module.exports = function (clazz, icons) {
  2. let svgSpriteStr = `<style type="text/css">
  3. ${clazz} {
  4. width: 1em; height: 1em;
  5. vertical-align: -0.15em;
  6. fill: currentColor;
  7. overflow: hidden;
  8. }
  9. </style>
  10. <svg aria-hidden="true" style="position: absolute; width: 0px; height: 0px; overflow: hidden;">{placeholder}</svg>`;
  11. let symbolStr = '';
  12. for (let icon of icons) {
  13. symbolStr += icon.iconContent.replace(/<svg/ig, `<symbol id="${clazz}-${icon.iconName}" class="${clazz}"`)
  14. .replace('</svg>', '</symbol>');
  15. }
  16. return svgSpriteStr.replace('{placeholder}', symbolStr);
  17. };