Skip to content

Commit 73ba7f2

Browse files
authored
Merge pull request #14 from pr1mer-tech/react-patch
React support
2 parents 37fab97 + b2eafc7 commit 73ba7f2

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@
3535
"gulp-uglify-es": "^1.0.1",
3636
"gulp4-run-sequence": "^1.0.0",
3737
"vinyl-source-stream": "^2.0.0"
38+
},
39+
"dependencies": {
40+
"react": "^16.13.1"
3841
}
3942
}

react.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import LunarIcon from "./src/react-component";
2+
3+
export default LunarIcon

src/icon.js

+17
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,21 @@ module.exports = class Icon {
7373
toString() {
7474
return this.toSVG().toString()
7575
}
76+
77+
/**
78+
* Generate an icon's SVG
79+
* @param {object} attr Attributes to add to SVG
80+
* @return {String} HTML string of SVG
81+
*/
82+
toSVGString(attr) {
83+
attr = Object.assign({}, this.attr, attr)
84+
if (attr.class) attr.class += ' lunar-icons'
85+
else attr.class = 'lunar-icons'
86+
87+
let attributes = ''
88+
for (let a in attr) attributes += `${a}="${attr[a]}" `
89+
90+
let str = `<svg ${attributes}>${this.path}</svg>`
91+
return str
92+
}
7693
}

src/react-component.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const icon = require('./icon.js');
2+
import React from 'react'
3+
4+
export default function LunarIcon(props) {
5+
return React.createElement("lunar-icon", { className: "lunar-icons", dangerouslySetInnerHTML: { __html: new icon(props.icon).toSVGString({
6+
style: "width: 100%; height: 100%"
7+
}) }, style: { width: "1em", minWidth: "1em", height: "1em", minHeight: "1em" } })
8+
}

0 commit comments

Comments
 (0)