-
Notifications
You must be signed in to change notification settings - Fork 23
/
generate-react.js
33 lines (25 loc) · 1.15 KB
/
generate-react.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const generate = require('./generate');
generate('react', component => `import React from 'react';
const ${component.name} = ({ color = 'currentColor', size = 24, children, ...props }) => {
const className = 'mdi-icon ' + (props.className || '');
return (
<svg {...props} className={className} width={size} height={size} fill={color} viewBox="0 0 24 24">
<path d="${component.svgPath}" />
</svg>
);
};
export default React.memo ? React.memo(${component.name}) : ${component.name};
`, component => `import { MdiReactIconComponentType } from './dist/typings';
declare const ${component.name}: MdiReactIconComponentType;
export default ${component.name};
`, () => `import { ComponentType, SVGProps } from 'react';
type AllSVGProps = SVGProps<SVGSVGElement>
type ReservedProps = 'color' | 'size' | 'width' | 'height' | 'fill' | 'viewBox'
export interface MdiReactIconProps extends Pick<AllSVGProps, Exclude<keyof AllSVGProps, ReservedProps>> {
color?: string;
size?: number | string;
// should not have any children
children?: never;
}
export type MdiReactIconComponentType = ComponentType<MdiReactIconProps>;
`).catch(err => console.error(err));