Reputation: 3725
I am using material-ui@next for my react app. I want to use Icon
component with dynamic images in png
format. I googled this but cannot find anything directly helpful.
Upvotes: 10
Views: 32137
Reputation: 643
You can:
.svg
file in a text editorIn your code:
import * as React from "react";
import { SvgIcon } from "@material-ui/core";
export default function Icon1(props) {
return (
<SvgIcon
{...props}
... // add here the params that are sent to <svg /> tag in your file
/*
mine were something like:
version="1.0"
xmlns="http://www.w3.org/2000/svg"
width="3000.000000pt"
height="1068.000000pt"
viewBox="0 0 3000.000000 1068.000000"
preserveAspectRatio="xMidYMid meet">
*/
>
// The tags inside the <svg />; probably something like <g/> <path/> tags
</SvgIcon>
);
}
Upvotes: 4
Reputation: 472
I ended up using Gimp to accomplish this. Here are the steps I used:
Next you need to make sure that it is scaled correctly to 24x24 pixels. The path's have their own toolbox window. It is usually found right next to the layers and channels windows.
Create a new file and past the new path tag where indicated below by {paste path tag here}
import * as React from 'react';
import createSvgIcon from '@material-ui/icons/utils/createSvgIcon';
export default createSvgIcon(
<React.Fragment>
<path fill='none' d='M0 0h24v24H0z' />
{paste path tag here}
</React.Fragment>,
'NewIcon'
);
Use your icon as follows:
Import as:
import NewIcon from './filename.tsx';
Then use as:
<NewIcon/>
Upvotes: 0
Reputation: 307
You can saveas PNG images to BMP format then convet them to SVG with potrace app.
potrace icon1.bmp -s -o icon1.svg
Now you can use SvgIcon component. open svg file with notepad and copy tags that are in svg tag and put it into SvgIcon:
function Icon1(props) {
return (
<SvgIcon {...props} >
// tags in your svg file
// ex: <path d="M81 1032 c-19 -9 "/>
</SvgIcon>
);
}
Your icon component is ready:
<Icon1 />
Upvotes: 3