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.
There is no such specific custom img component avaiable with material-ui. But you can use the simple html img component inside another wrapper components to create custom img component by your own. e.g Also <CardMedia/> component has to be used with in conjunction with <Card/> component.
And add it to the module’s array of imports: Now, you can use the built-in material icons with the <mat-icon> component. If you add the textual name for an icon, it will display the associated icon glyph. For our tutorial, we will be adding the "mood" icon (this resembles the symbol of a face with a smile):
To use our custom unicorn icon with the <mat-icon> component tag, we’ll need to import HttpClientModule. And add it to the module’s array of imports: Now, we can register our custom "unicorn" icon with the MatIconRegistry service provided by Angular Material. And add the injection of the service into the component:
Let’s learn how to use our own SVG icons in Angular Material components. In this tutorial, you will use the <mat-icon> component to use the standard Material Icons font. Then, you will use the <mat-icon> component to support a custom SVG icon. The full working code can be found on this GitHub repo.
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 />
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>
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With