feat: Add react package (#4)

* chore: Organise

* feat: Add `react` package

* refactor: Remove unneeded char
This commit is contained in:
John Letey
2020-06-13 12:52:10 +01:00
committed by GitHub
parent 6a3378ce5a
commit d652e795d6
338 changed files with 10986 additions and 15748 deletions

View File

@@ -0,0 +1,28 @@
import DEFAULT_ATTRS from '../src/default-attrs.json';
/**
* Build an SVG sprite string containing SVG symbols.
* @param {Object} icons
* @returns {string}
*/
function buildSpriteString(icons) {
const symbols = Object.keys(icons)
.map(icon => toSvgSymbol(icon, icons[icon]))
.join('');
return `<svg xmlns="${DEFAULT_ATTRS.xmlns}"><defs>${symbols}</defs></svg>`;
}
/**
* Create an SVG symbol string.
* @param {string} name - Icon name
* @param {string} contents - SVG contents
* @returns {string}
*/
function toSvgSymbol(name, contents) {
return `<symbol id="${name}" viewBox="${DEFAULT_ATTRS.viewBox}">${
contents
}</symbol>`;
}
export default buildSpriteString;