Skip to content

Commit b3779eb

Browse files
author
Simon Planinschek
committed
Remove title if not set
1 parent 1828826 commit b3779eb

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

generator.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ const axios = require('axios')
66
const iconURL = 'https://fonts.google.com/metadata/icons'
77

88
function setup() {
9-
let typesFile = "import React from 'react'\n\n"
10-
typesFile +=
11-
'export interface IconProps extends React.SVGProps<SVGSVGElement> {\n'
12-
typesFile += '\ttitle?: string\n'
13-
typesFile += '}\n'
9+
const typesFile = `
10+
import React from 'react'
11+
export interface IconProps extends React.SVGProps<SVGSVGElement> {
12+
title?: string
13+
}
14+
`
1415

1516
// Create types file
1617
fs.writeFileSync(path.join(__dirname, 'src', 'types.ts'), typesFile)
@@ -41,13 +42,16 @@ function formatName(string) {
4142
* @returns {string} - Component
4243
*/
4344
function componentTemplate(name, svg) {
44-
let component = "import React from 'react'\n"
45-
component += "import { IconProps } from './types'\n\n"
46-
component += `const ${name}: React.FC<IconProps> = ({ title = '${name}', ...props }) => (`
47-
component += svg + ')\n\n'
48-
component += `export { ${name} as default }`
49-
50-
return component
45+
return `
46+
import React from 'react'
47+
import { IconProps } from './types'
48+
49+
const ${name}: React.FC<IconProps> = ({ ...props }) => (
50+
${svg}
51+
)
52+
53+
export { ${name} as default }
54+
`
5155
}
5256

5357
/**
@@ -86,7 +90,7 @@ async function getSVGFile(icon, version) {
8690
.replace(/enable-background/g, 'enableBackground')
8791
.replace(/clip-rule/g, 'clipRule')
8892
.replace(/fill-rule/g, 'fillRule')
89-
.replace('>', '><title>{title}</title>')
93+
.replace('>', '>{props.title && <title>{props.title}</title>}')
9094
}
9195

9296
/**

0 commit comments

Comments
 (0)