-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathtemplate.js
52 lines (46 loc) · 1.09 KB
/
template.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
44
45
46
47
48
49
50
51
52
const getAttrs = (style) => {
const baseAttrs = {
xmlns: 'http://www.w3.org/2000/svg',
width: 'size',
height: 'size',
viewBox: '0 0 24 24',
}
const fillAttrs = {
fill: 'color',
otherProps: '...otherProps'
}
const strokeAttrs = {
fill: 'none',
stroke: 'color',
strokeWidth: 2,
strokeLinecap: 'round',
strokeLinejoin: 'round',
otherProps: '...otherProps'
}
return Object.assign({}, baseAttrs, style==='fill' ? fillAttrs : strokeAttrs)
}
const getElementCode = (ComponentName, attrs, svgCode) => `
import React from 'react';
import PropTypes from 'prop-types';
const ${ComponentName} = (props) => {
const { color, size, ...otherProps } = props;
return (
<svg ${attrs}>
${svgCode}
</svg>
)
};
${ComponentName}.propTypes = {
color: PropTypes.string,
size: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),
}
${ComponentName}.defaultProps = {
color: 'currentColor',
size: '24',
}
export default ${ComponentName}
`
module.exports = { getAttrs, getElementCode }