Skip to content

Commit

Permalink
Set muiName property for generated icons. #14
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaik committed Jun 3, 2018
1 parent de18f0b commit 89bdc50
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
14 changes: 12 additions & 2 deletions generate-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => <SvgIcon {...props}>${svg}</SvgIcon>
import createIcon from './util/createIcon'
export default createIcon(<g>${svg}</g>)
`

// commonjs module syntax
Expand All @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions src/util/createIcon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import SvgIcon from '@material-ui/core/SvgIcon'

export default (svg) => {
const Icon = (props) => <SvgIcon {...props}>{svg}</SvgIcon>
Icon.muiName = 'SvgIcon'
return Icon
}
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 89bdc50

Please sign in to comment.