Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
35 changes: 6 additions & 29 deletions generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ const axios = require('axios')
const iconURL = 'https://fonts.google.com/metadata/icons'

function setup() {
// Create components folder
fs.mkdirSync(path.join(__dirname, 'src', 'components'))

// Create types file
fs.writeFileSync(
path.join(__dirname, 'src', 'components', 'types.ts'),
path.join(__dirname, 'src', 'types.ts'),
'import React from "react" \nexport type IconProps = React.SVGProps<SVGSVGElement>'
)
}
Expand Down Expand Up @@ -45,7 +42,7 @@ function componentTemplate(name, svg) {
component += "import { IconProps } from './types'\n\n"
component += `const ${name}: React.FC<IconProps> = (props) => (`
component += svg + ')\n\n'
component += `export { ${name} }`
component += `export { ${name} as default }`

return component
}
Expand All @@ -61,34 +58,12 @@ function generateComponent(icon) {
const svg = await getSVGFile(c.name, c.version)

fs.writeFileSync(
path.join(__dirname, 'src', 'components', `${name}.tsx`),
path.join(__dirname, 'src', `${name}.tsx`),
componentTemplate(name, svg)
)
})
}

/**
* Generate index tsx file for easy import
*
* @param icons - Array of icons
*/
function generateIndex(icons) {
let imports = ''
let exports = 'export {\n'

icons.forEach((icon) => {
const name = formatName(icon.name)
imports += `import { ${name} } from './components/${name}'\n`
exports += ` ${name},\n`
})
exports += '}'

fs.writeFileSync(
path.join(__dirname, 'src', 'index.ts'),
imports + '\n' + exports
)
}

/**
* Get SVG data form google static fonts api
*
Expand All @@ -105,6 +80,9 @@ async function getSVGFile(icon, version) {
.replace('height="24"', '')
.replace('width="24"', '{...props}')
.replace(/class/g, 'className')
.replace(/enable-background/g, 'enableBackground')
.replace(/clip-rule/g, 'clipRule')
.replace(/fill-rule/g, 'fillRule')
}

/**
Expand All @@ -124,5 +102,4 @@ async function getSVGFile(icon, version) {

// Generate icon components and Index
await generateComponent(icons.icons)
await generateIndex(icons.icons)
})()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@aboutbits/react-material-icons",
"version": "0.1.8",
"description": "Material design icon components for React",
"main": "dist/index.js",
"main": "dist/",
"scripts": {
"build": "tsc",
"generate": "rm -rf src/* && node generator.js",
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Second, you can use the icons in you React application like this:

```jsx
import React from 'react'
import IconCached from '@aboutbits/react-material-icons/dist/IconCached'

const MyCommponent = () => {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Icon360.tsx → src/Icon360.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const Icon360: React.FC<IconProps> = (props) => (
</svg>
)

export { Icon360 }
export { Icon360 as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const Icon3dRotation: React.FC<IconProps> = (props) => (
</svg>
)

export { Icon3dRotation }
export { Icon3dRotation as default }
2 changes: 1 addition & 1 deletion src/components/Icon4k.tsx → src/Icon4k.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const Icon4k: React.FC<IconProps> = (props) => (
</svg>
)

export { Icon4k }
export { Icon4k as default }
4 changes: 2 additions & 2 deletions src/components/Icon5g.tsx → src/Icon5g.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IconProps } from './types'
const Icon5g: React.FC<IconProps> = (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
enable-background="new 0 0 24 24"
enableBackground="new 0 0 24 24"
viewBox="0 0 24 24"
{...props}
>
Expand All @@ -20,4 +20,4 @@ const Icon5g: React.FC<IconProps> = (props) => (
</svg>
)

export { Icon5g }
export { Icon5g as default }
4 changes: 2 additions & 2 deletions src/components/Icon6FtApart.tsx → src/Icon6FtApart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IconProps } from './types'
const Icon6FtApart: React.FC<IconProps> = (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
enable-background="new 0 0 24 24"
enableBackground="new 0 0 24 24"
viewBox="0 0 24 24"
{...props}
>
Expand All @@ -13,4 +13,4 @@ const Icon6FtApart: React.FC<IconProps> = (props) => (
</svg>
)

export { Icon6FtApart }
export { Icon6FtApart as default }
2 changes: 1 addition & 1 deletion src/components/IconAcUnit.tsx → src/IconAcUnit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAcUnit: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAcUnit }
export { IconAcUnit as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAccessAlarm: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAccessAlarm }
export { IconAccessAlarm as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAccessAlarms: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAccessAlarms }
export { IconAccessAlarms as default }
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ const IconAccessTime: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAccessTime }
export { IconAccessTime as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAccessibility: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAccessibility }
export { IconAccessibility as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAccessibilityNew: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAccessibilityNew }
export { IconAccessibilityNew as default }
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ const IconAccessible: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAccessible }
export { IconAccessible as default }
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ const IconAccessibleForward: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAccessibleForward }
export { IconAccessibleForward as default }
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IconProps } from './types'
const IconAccountBalance: React.FC<IconProps> = (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
enable-background="new 0 0 24 24"
enableBackground="new 0 0 24 24"
viewBox="0 0 24 24"
{...props}
>
Expand All @@ -23,4 +23,4 @@ const IconAccountBalance: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAccountBalance }
export { IconAccountBalance as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAccountBalanceWallet: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAccountBalanceWallet }
export { IconAccountBalanceWallet as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAccountBox: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAccountBox }
export { IconAccountBox as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAccountCircle: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAccountCircle }
export { IconAccountCircle as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAccountTree: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAccountTree }
export { IconAccountTree as default }
2 changes: 1 addition & 1 deletion src/components/IconAdUnits.tsx → src/IconAdUnits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAdUnits: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAdUnits }
export { IconAdUnits as default }
2 changes: 1 addition & 1 deletion src/components/IconAdb.tsx → src/IconAdb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAdb: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAdb }
export { IconAdb as default }
2 changes: 1 addition & 1 deletion src/components/IconAdd.tsx → src/IconAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAdd: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAdd }
export { IconAdd as default }
4 changes: 2 additions & 2 deletions src/components/IconAddAPhoto.tsx → src/IconAddAPhoto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IconProps } from './types'
const IconAddAPhoto: React.FC<IconProps> = (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
enable-background="new 0 0 24 24"
enableBackground="new 0 0 24 24"
viewBox="0 0 24 24"
{...props}
>
Expand All @@ -13,4 +13,4 @@ const IconAddAPhoto: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddAPhoto }
export { IconAddAPhoto as default }
2 changes: 1 addition & 1 deletion src/components/IconAddAlarm.tsx → src/IconAddAlarm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAddAlarm: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddAlarm }
export { IconAddAlarm as default }
2 changes: 1 addition & 1 deletion src/components/IconAddAlert.tsx → src/IconAddAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAddAlert: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddAlert }
export { IconAddAlert as default }
2 changes: 1 addition & 1 deletion src/components/IconAddBox.tsx → src/IconAddBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAddBox: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddBox }
export { IconAddBox as default }
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IconProps } from './types'
const IconAddBusiness: React.FC<IconProps> = (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
enable-background="new 0 0 24 24"
enableBackground="new 0 0 24 24"
viewBox="0 0 24 24"
{...props}
>
Expand All @@ -21,4 +21,4 @@ const IconAddBusiness: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddBusiness }
export { IconAddBusiness as default }
2 changes: 1 addition & 1 deletion src/components/IconAddCircle.tsx → src/IconAddCircle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAddCircle: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddCircle }
export { IconAddCircle as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAddCircleOutline: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddCircleOutline }
export { IconAddCircleOutline as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAddComment: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddComment }
export { IconAddComment as default }
2 changes: 1 addition & 1 deletion src/components/IconAddIcCall.tsx → src/IconAddIcCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAddIcCall: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddIcCall }
export { IconAddIcCall as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAddLocation: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddLocation }
export { IconAddLocation as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAddLocationAlt: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddLocationAlt }
export { IconAddLocationAlt as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAddPhotoAlternate: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddPhotoAlternate }
export { IconAddPhotoAlternate as default }
4 changes: 2 additions & 2 deletions src/components/IconAddRoad.tsx → src/IconAddRoad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IconProps } from './types'
const IconAddRoad: React.FC<IconProps> = (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
enable-background="new 0 0 24 24"
enableBackground="new 0 0 24 24"
viewBox="0 0 24 24"
{...props}
>
Expand All @@ -24,4 +24,4 @@ const IconAddRoad: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddRoad }
export { IconAddRoad as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAddShoppingCart: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddShoppingCart }
export { IconAddShoppingCart as default }
4 changes: 2 additions & 2 deletions src/components/IconAddTask.tsx → src/IconAddTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IconProps } from './types'
const IconAddTask: React.FC<IconProps> = (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
enable-background="new 0 0 24 24"
enableBackground="new 0 0 24 24"
viewBox="0 0 24 24"
{...props}
>
Expand All @@ -13,4 +13,4 @@ const IconAddTask: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddTask }
export { IconAddTask as default }
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ const IconAddToHomeScreen: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddToHomeScreen }
export { IconAddToHomeScreen as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAddToPhotos: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddToPhotos }
export { IconAddToPhotos as default }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAddToQueue: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddToQueue }
export { IconAddToQueue as default }
2 changes: 1 addition & 1 deletion src/components/IconAddchart.tsx → src/IconAddchart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const IconAddchart: React.FC<IconProps> = (props) => (
</svg>
)

export { IconAddchart }
export { IconAddchart as default }
Loading