Skip to content

Commit

Permalink
Add SVG element props to TS definitions (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcorpet authored and levrik committed Nov 30, 2019
1 parent eabf490 commit a81857d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions scripts/generate-preact.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ declare const ${component.name}: MdiReactIconComponentType;
export default ${component.name};
`, () => `import { FunctionalComponent } from 'preact';
// TODO(pcorpet): Extends SVGProps when it exists in Preact.
export interface MdiReactIconProps {
color?: string;
size?: number | string;
Expand Down
9 changes: 6 additions & 3 deletions scripts/generate-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ export default React.memo ? React.memo(${component.name}) : ${component.name};
declare const ${component.name}: MdiReactIconComponentType;
export default ${component.name};
`, () => `import { ComponentType } from 'react';
`, () => `import { ComponentType, SVGProps } from 'react';
export interface MdiReactIconProps {
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;
className?: string;
// should not have any children
children?: never;
}
Expand Down
3 changes: 3 additions & 0 deletions typings-test-preact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ const render = () => (
<AccessPointNetworkIcon></AccessPointNetworkIcon>
<AccessPointNetworkIcon size={16} />
<AccessPointNetworkIcon color="#fff" size="16" class="some-class" className="some-class" />
<AccessPointNetworkIcon
size={16} style={{display: 'block', margin: 'auto'}}
onClick={() => {}} />
</>
);
3 changes: 3 additions & 0 deletions typings-test-react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ const render = () => (
<AccessPointNetworkIcon></AccessPointNetworkIcon>
<AccessPointNetworkIcon size={16} />
<AccessPointNetworkIcon color="#fff" size="16" className="some-class" />
<AccessPointNetworkIcon
size={16} style={{display: 'block', margin: 'auto'}}
onClick={() => {}} />
</>
);

0 comments on commit a81857d

Please sign in to comment.