Skip to content

Commit 16fc2a0

Browse files
committed
Add the Material Design Light icons. Update Material Design Icons.
1 parent b97b9be commit 16fc2a0

7 files changed

Lines changed: 104 additions & 30 deletions

File tree

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Material Design Icons for Material-UI
22
[![npm](https://img.shields.io/npm/v/mdi-material-ui/legacy.svg)](https://www.npmjs.com/package/mdi-material-ui)
3-
[![Material Design Icons version](https://img.shields.io/badge/mdi-v3.6.95-blue.svg)](https://github.com/Templarian/MaterialDesign-SVG/)
3+
[![Material Design Icons version](https://img.shields.io/badge/mdi-v3.7.95-blue.svg)](https://github.com/Templarian/MaterialDesign)
4+
[![Material Design Icons version](https://img.shields.io/badge/mdi--light-v0.2.63-blue.svg)](https://github.com/Templarian/MaterialDesignLight)
45

56
This module provides [Material-UI][material-ui] `<SvgIcon />` components for all
67
[Material Design Icons][md-icons]. This is pretty handy if you use React and Material-UI
@@ -22,14 +23,19 @@ npm install mdi-material-ui@legacy --save
2223
Every icon is exported with its original name in PascalCase. So `coffee` becomes `Coffee`,
2324
`cloud-print-outline` is exported as `CloudPrintOutline` and so on.
2425

26+
The Material Design _Light_ icons are included in the `/light` subdirectory.
27+
2528
### With tree-shaking
2629
If your environment supports tree-shaking and you are sure that it works fine in your setup, you can simply import the icons as follows:
2730

2831
```js
2932
import { Coffee, Food } from 'mdi-material-ui'
33+
import { Camera, Settings } from 'mdi-material-ui/light'
3034

3135
<Coffee />
3236
<Food />
37+
<Camera />
38+
<Settings />
3339
```
3440

3541
### Without tree-shaking
@@ -38,21 +44,13 @@ If your environment doesn't support tree-shaking, you should only import the ico
3844
```js
3945
import Coffee from 'mdi-material-ui/Coffee'
4046
import Food from 'mdi-material-ui/Food'
47+
import Camera from 'mdi-material-ui/light/Camera'
48+
import Settings from 'mdi-material-ui/light/Settings'
4149

4250
<Coffee />
4351
<Food />
44-
```
45-
46-
If you think that this is far too verbose (I agree!), consider using [babel-plugin-direct-import](https://github.com/umidbekkarimov/babel-plugin-direct-import). Install it and adjust your `.babelrc` by adding the following snippet to the plugins section:
47-
48-
```js
49-
{
50-
// ...
51-
plugins: [
52-
// ...
53-
["direct-import", ["mdi-material-ui"]]
54-
]
55-
}
52+
<Camera />
53+
<Settings />
5654
```
5755

5856
## License

generate-module.js

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ const pick = require('lodash.pick')
1313
svgPath: path
1414
}))
1515

16+
const lightIcons = Object.entries(require('@mdi/light-js'))
17+
.filter(([name]) => name.indexOf('mdil') === 0)
18+
.map(([name, path]) => ({
19+
name: pascalCase(name.substr(4)), // remove mdil prefix
20+
svgPath: path
21+
}))
22+
1623
fse.removeSync(path.join(__dirname, 'package'))
17-
fse.mkdirpSync(path.join(__dirname, 'package'))
24+
fse.mkdirpSync(path.join(__dirname, 'package', 'light'))
1825

1926
for (const { name, svgPath } of icons) {
2027
const code = `import createIcon from './util/createIcon'
@@ -32,18 +39,39 @@ const pick = require('lodash.pick')
3239
`)
3340
}
3441

35-
// es2015 module syntax
36-
const allExports = icons.map(({ name }) => `export { default as ${name} } from './${name}'`).join('\n')
37-
fse.writeFileSync(path.join(__dirname, 'package', 'index.es.js'), allExports)
42+
for (const { name, svgPath } of lightIcons) {
43+
const code = `import createIcon from '../util/createIcon'
44+
export default createIcon('${svgPath}')
45+
`
46+
47+
// commonjs module syntax
48+
fse.writeFileSync(path.join(__dirname, 'package', 'light', `${name}.js`), babel.transform(code, {
49+
presets: ['es2015', 'react', 'stage-0'],
50+
compact: process.env.NODE_ENV === 'production'
51+
}).code)
52+
53+
// typescript definition
54+
fse.writeFileSync(path.join(__dirname, 'package', 'light', `${name}.d.ts`), `export { default } from '@material-ui/core/SvgIcon'
55+
`)
56+
}
3857

39-
// typescript index definition (looks exactly the same)
40-
fse.writeFileSync(path.join(__dirname, 'package', 'index.d.ts'), allExports)
58+
const generateIndexFiles = (destination, icons) => {
59+
// es2015 module syntax
60+
const allExports = icons.map(({ name }) => `export { default as ${name} } from './${name}'`).join('\n')
61+
fse.writeFileSync(path.join(destination, 'index.es.js'), allExports)
62+
63+
// typescript index definition (looks exactly the same)
64+
fse.writeFileSync(path.join(destination, 'index.d.ts'), allExports)
65+
66+
// commonjs module
67+
fse.writeFileSync(path.join(destination, 'index.js'), babel.transform(allExports, {
68+
plugins: ['transform-es2015-modules-commonjs'],
69+
compact: process.env.NODE_ENV === 'production'
70+
}).code)
71+
}
4172

42-
// commonjs module
43-
fse.writeFileSync(path.join(__dirname, 'package', 'index.js'), babel.transform(allExports, {
44-
plugins: ['transform-es2015-modules-commonjs'],
45-
compact: process.env.NODE_ENV === 'production'
46-
}).code)
73+
generateIndexFiles(path.join(__dirname, 'package'), icons)
74+
generateIndexFiles(path.join(__dirname, 'package', 'light'), lightIcons)
4775

4876
// createIcon function
4977
fse.mkdirSync(path.join(__dirname, 'package', 'util'))
@@ -57,8 +85,10 @@ const pick = require('lodash.pick')
5785

5886
// update readme
5987
const mdiVersion = require(path.join(require.resolve('@mdi/js'), '..', '..', 'package.json')).version
88+
const mdiLightVersion = require(path.join(require.resolve('@mdi/light-js'), '..', '..', 'package.json')).version
6089
let readme = await fse.readFile(path.join(__dirname, 'README.md'), 'utf-8')
6190
readme = readme.replace(/img\.shields\.io\/badge\/mdi-v(.+?)-blue\.svg/g, `img.shields.io/badge/mdi-v${mdiVersion}-blue.svg`)
91+
readme = readme.replace(/img\.shields\.io\/badge\/mdi--light-v(.+?)-blue\.svg/g, `img.shields.io/badge/mdi--light-v${mdiLightVersion}-blue.svg`)
6292
await fse.writeFile(path.join(__dirname, 'README.md'), readme, 'utf-8')
6393

6494
// copy other files

package-lock.json

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
},
2626
"homepage": "https://github.com/TeamWertarbyte/mdi-material-ui#readme",
2727
"devDependencies": {
28-
"@mdi/js": "^3.6.95",
28+
"@mdi/js": "^3.7.95",
29+
"@mdi/light-js": "^0.2.63",
2930
"@storybook/react": "^3.4.11",
3031
"ava": "^0.25.0",
3132
"babel-core": "^6.8.0",

stories/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import lightBaseTheme from 'material-ui/styles/baseThemes/lightBaseTheme'
44
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
55
import getMuiTheme from 'material-ui/styles/getMuiTheme'
66
const icons = require('../package/index')
7+
const lightIcons = require('../package/light/index')
78

89
function themed (children) {
910
return (
@@ -15,7 +16,7 @@ function themed (children) {
1516
)
1617
}
1718

18-
const iconStories = storiesOf('Icons', module)
19+
const iconStories = storiesOf('Material Design Icons', module)
1920
iconStories.add(`all icons (${Object.keys(icons).length.toLocaleString()})`, () => themed(
2021
<div>
2122
{Object.keys(icons).map((icon) => {
@@ -29,3 +30,18 @@ Object.keys(icons).sort().forEach((icon) => {
2930
const Icon = icons[icon]
3031
iconStories.add(icon, () => themed(<Icon />))
3132
})
33+
34+
const lightIconStories = storiesOf('Material Design Icons Light', module)
35+
lightIconStories.add(`all icons (${Object.keys(lightIcons).length.toLocaleString()})`, () => themed(
36+
<div>
37+
{Object.keys(lightIcons).map((icon) => {
38+
const Icon = lightIcons[icon]
39+
return <Icon key={icon} />
40+
})}
41+
</div>
42+
))
43+
44+
Object.keys(lightIcons).sort().forEach((icon) => {
45+
const Icon = lightIcons[icon]
46+
lightIconStories.add(icon, () => themed(<Icon />))
47+
})

test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import renderer from 'react-test-renderer'
44
import fs from 'fs'
55
import { MuiThemeProvider } from 'material-ui/styles';
66
const commonjsIcons = require('./package/index')
7+
const commonjsIconsLight = require('./package/light/index')
78

89
test('the npm package', (t) => {
910
// should set sideEffects to false to allow webpack to optimize re-exports
@@ -22,6 +23,7 @@ for (const iconName of Object.keys(commonjsIcons)) {
2223
t.is(commonjsIcons[iconName].muiName, 'SvgIcon')
2324
})
2425
}
26+
2527
test('ES module index file', (t) => {
2628
const esmReExports = fs.readFileSync('./package/index.es.js', 'utf-8')
2729
.split('\n')
@@ -34,3 +36,24 @@ test('ES module index file', (t) => {
3436
t.truthy(commonjsIcons[match[1]])
3537
}
3638
})
39+
40+
for (const iconName of Object.keys(commonjsIconsLight)) {
41+
test(`light icons > ${iconName}`, (t) => {
42+
const renderedIcon = renderer.create(React.createElement(commonjsIconsLight[iconName])).toJSON()
43+
t.is(renderedIcon.type, 'svg')
44+
t.is(commonjsIconsLight[iconName].muiName, 'SvgIcon')
45+
})
46+
}
47+
48+
test('mdi-light ES module index file', (t) => {
49+
const esmReExports = fs.readFileSync('./package/light/index.es.js', 'utf-8')
50+
.split('\n')
51+
.filter((line) => line.length > 0)
52+
t.is(esmReExports.length, Object.keys(commonjsIconsLight).length)
53+
54+
for (const line of esmReExports) {
55+
const match = line.match(/^export \{ default as (.+?) \} from '\.\/(.+?)'$/)
56+
t.is(match[1], match[2])
57+
t.truthy(commonjsIconsLight[match[1]])
58+
}
59+
})

update.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
2-
npm i --save-dev @mdi/js@latest
2+
npm i --save-dev @mdi/js@latest @mdi/light-js@latest
33
./generate-module.js

0 commit comments

Comments
 (0)