diff --git a/generate-module.js b/generate-module.js index 6265562..4433138 100755 --- a/generate-module.js +++ b/generate-module.js @@ -42,8 +42,8 @@ const pick = require('lodash.pick') for (const { name, svg } of icons) { const code = `import React from 'react' - import SvgIcon from '@material-ui/core/SvgIcon' - export default (props) => ${svg} + import createIcon from './util/createIcon' + export default createIcon(${svg}) ` // commonjs module syntax @@ -70,6 +70,16 @@ const pick = require('lodash.pick') compact: process.env.NODE_ENV === 'production' }).code) + // createIcon function + fse.mkdirSync(path.join(__dirname, 'package', 'util')) + fse.writeFileSync( + path.join(__dirname, 'package', 'util', 'createIcon.js'), + babel.transform(fse.readFileSync(path.join(__dirname, 'src', 'util', 'createIcon.js')), { + presets: ['es2015', 'react', 'stage-0'], + compact: process.env.NODE_ENV === 'production' + }).code + ) + // copy other files ;[ 'README.md', diff --git a/src/util/createIcon.js b/src/util/createIcon.js new file mode 100644 index 0000000..a1b79df --- /dev/null +++ b/src/util/createIcon.js @@ -0,0 +1,8 @@ +import React from 'react' +import SvgIcon from '@material-ui/core/SvgIcon' + +export default (svg) => { + const Icon = (props) => {svg} + Icon.muiName = 'SvgIcon' + return Icon +} diff --git a/test.js b/test.js index 3cabd0b..9f310d1 100644 --- a/test.js +++ b/test.js @@ -14,6 +14,7 @@ for (const iconName of Object.keys(commonjsIcons)) { test(`icons > ${iconName}`, (t) => { const renderedIcon = renderer.create(React.createElement(commonjsIcons[iconName])).toJSON() t.is(renderedIcon.type, 'svg') + t.is(commonjsIcons[iconName].muiName, 'SvgIcon') }) } test('ES module index file', (t) => {