-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
43 lines (41 loc) · 932 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module.exports = desvg
/**
* @name desvg
* @summary Generate component using passed svg-loader output.
*
* @description
* Generate component using passed svg-loader output.
*
* @param {Function} h
* The helper function (e.g. `React.createElement` or Preact's `h`).
*
* @param {Object} svg
* The svg-loader output.
*
* @returns {Object}
* The generated component.
*
* @example
* import { createElement } from 'react'
* import svgContent from './icon.svg'
* import desvg from 'desvg'
*
* // Basic usage
* const Icon = desvg(createElement, svgContent)
* <Icon fill='currentColor' />
* //=> <svg fill='currentColor' ...>...</svg>
*/
function desvg (h, svg) {
var content = svg.content
var attributes = svg.attributes
return function (props) {
return h(
'svg',
Object.assign(
{ dangerouslySetInnerHTML: { __html: content } },
attributes,
props
)
)
}
}