New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

google-material-icons

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-material-icons

A google material icon library package for React applications

latest
npmnpm
Version
2.1.5
Version published
Maintainers
3
Created
Source

Google Material Icons

Implementation of the google material icon library for react applications.

Installation

yarn add google-material-icons

or

npm install google-material-icons

How to use

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.

Example

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;

Props

nametypedefault
sizeNumber24
colorStringcurrentColor
strokeWidthNumber2

Custom props

You can also pass custom props that will be added in the svg as attributes.

const App = () => {
  return <Abc fill="red" />;
};

Generic icon component

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;

With Dynamic Imports

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;
NextJS Example

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;

Keywords

Google

FAQs

Package last updated on 21 Dec 2025

Did you know?

Socket

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.

Install

Related posts