
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
google-material-icons
Advanced tools
Implementation of the google material icon library for react applications.
yarn add google-material-icons
or
npm install google-material-icons
It's built with ES modules so it's completely tree-shakable. Each icon can be imported as a react component with two different variant Filled and Outlined.
You can pass additional props to adjust the icon.
import { Abc } from "google-material-icons/filled";
const App = () => {
return <Abc color="red" size={48} />;
};
export default App;
import { Abc } from "google-material-icons/outlined";
const App = () => {
return <Abc color="red" size={48} />;
};
export default App;
| name | type | default |
|---|---|---|
size | Number | 24 |
color | String | currentColor |
strokeWidth | Number | 2 |
You can also pass custom props that will be added in the svg as attributes.
const App = () => {
return <Abc fill="red" />;
};
It is possible to create a generic icon component to load icons.
:warning: The example below is importing all ES modules. This is not recommended when you using a bundler since your application build size will grow substantially.
import { filledIcons } from "google-material-icons";
const Icon = ({ name, color, size }) => {
const GoogleMaterialIcon = filledIcons[name];
return <GoogleMaterialIcon color={color} size={size} />;
};
export default Icon;
Google Material Icons exports a dynamic import map dynamicIconImports. Useful for applications that want to show icons dynamically by icon name. For example when using a content management system with where icon names are stored in a database.
When using client side rendering, it will fetch the icon component when it's needed. This will reduce the initial bundle size.
The keys of the dynamic import map are the Google Material original icon names.
Example with React suspense:
import React, { lazy, Suspense } from "react";
import { GoogleMaterialProps } from "google-material-icons/outlined";
import outlinedDynamicIconImports from "google-material-icons/outlinedDynamicIconImports";
const fallback = <div style={{ background: "#ddd", width: 24, height: 24 }} />;
interface IconProps extends Omit<GoogleMaterialProps, "ref"> {
name: keyof typeof outlinedDynamicIconImports;
}
const Icon = ({ name, ...props }: IconProps) => {
const GoogleMaterialIcon = lazy(outlinedDynamicIconImports[name]);
return (
<Suspense fallback={fallback}>
<GoogleMaterialIcon {...props} />
</Suspense>
);
};
export default Icon;
In NextJS, the dynamic function can be used to dynamically load the icon component.
To make dynamic imports work with NextJS, you need to add google-material-icons to the transpilePackages option in your next.config.js like this:
/** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ["google-material-icons"], // add this
};
module.exports = nextConfig;
You can then start using it:
import dynamic from "next/dynamic";
import { GoogleMaterialProps } from "google-material-icons/filled";
import filledDynamicIconImports from "google-material-icons/filledDynamicIconImports";
interface IconProps extends GoogleMaterialProps {
name: keyof typeof filledDynamicIconImports;
}
const Icon = ({ name, ...props }: IconProps) => {
const GoogleMaterialIcon = dynamic(filledDynamicIconImports[name]);
return <GoogleMaterialIcon {...props} />;
};
export default Icon;
FAQs
A google material icon library package for React applications
We found that google-material-icons demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.