npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mdi/react

v1.6.1

Published

React Dist for Material Design Icons

Downloads

351,503

Readme

React - Material Design Icons

Material Design Icons can be used in React with a custom component or with the one provided in this module.

View the Demo

npm install @mdi/react

Usage

The example below uses the @mdi/js package which contains all the MDI icon's path data.

import React, { Component } from 'react';
import Icon from '@mdi/react';
import { mdiAccount } from '@mdi/js';

class App extends Component {
  render() {
    return (
      <Icon path={mdiAccount}
        size={1}
        horizontal
        vertical
        rotate={90}
        color="red"/>
    );
  }
} 

Stack Usage

To layer <Icons/> nest them inside of the <Stack/> component.

import React, { Component } from 'react';
import Icon, { Stack } from '@mdi/react';
import { mdiAccount, mdiBlockHelper } from '@mdi/js';

class App extends Component {
  render() {
    return (
      <Stack color="#444">
        <Icon path={mdiAccount}/>
        <Icon path={mdiBlockHelper}
          color="red"/>
      </Stack>
    );
  }
} 

Props

Icon <Icon/>

| Prop | PropTypes | Default | Details | |-------------|----------------|----------|---------| | title | string, null | null | A11y <title>{title}</title> | | description | string, null | null | A11y <desc>{desc}</desc> | | path | string | required | SVG path data. Usually from @mdi/js | | size | number, string | null | {size * 1.5}rem, 1em, 48px | | horizontal | bool | false | Flip Horizontal | | vertical | bool | false | Flip Vertical | | rotate | number | 0 | degrees 0 to 360 | | color | string | null | rgb() / rgba() / #000 | | spin | bool, number | false | true = 2s, -2 counterclockwise, {spin}s |

Note: Additional props will be applied to the <svg> element.

Stack <Stack/>

All props below will override the nested <Icon/>'s default prop values.

| Prop | PropTypes | Default | Details | |-------------|----------------------|----------|---------| | title | string, null | null | A11y <title>{title}</title> | | description | string, null | null | A11y <desc>{desc}</desc> | | size | number, string, null | null | {size * 1.5}rem | | horizontal | bool, null | null | Flip Horizontal | | vertical | bool, null | null | Flip Vertical | | rotate | number, null | null | degrees 0 to 360 | | color | string, null | null | rgb() / rgba() / #000 | | spin | bool, number, null | null | true = 2s, -2 counterclockwise, {spin}s |

Note: Additional props on <Stack> will apply to the <svg> element. Only in a <Stack> will addional props to the <Icon> component apply to the nested <path> elements.

Styling

Applying a className attribute is usually the easiest solution. The example below demonstrates using SCSS to style the icons.

In most cases it may be a good idea to set a base size. Assuming a 16px base font-size in most themes applying 1.5rem will make the icon a 24px.

svg {
  width: 1.5rem;
}

For more specific styling apply classes. To make selection of layers easier use the nth-child selector.

// For <Icon className="custom-class" />
svg.custom-class {
  path {
    fill: blue;
  }
}
// For <Stack className="custom-class">
svg.custom-class {
  // First layer (behind)
  path:nth-child(1) {
    fill: blue;
  }
  // Second layer (infront)
  path:nth-child(2) {
    fill: red;
  }
}

Accessibility

Making icons accessible can be done through the title prop. If for some rare reason more information is required a description field can also be used.

By leaving off the title prop an icon is assumed to be presentation only. These will be ignored by screen readers. This is ideal for icon buttons or areas where text next to the icon suffices.

<p><Icon path={mdiAccount} /> User Profile</p>
<p><Icon path={mdiAccount} title="User Profile" /></p>
<button aria-label="User Profile"><Icon path={mdiAccount} /></button>

Development

To develop clone the repo and run npm install.

  • src/Icon.tsx - Icon Component
    • tests/Icon.spec.tsx - Unit tests
  • src/Stack.tsx - Stack Component
    • tests/Stack.spec.tsx - Unit tests

Commands:

  • npm run start - Watch for file changes
  • npm run build - Build Icon.js
  • npm run test - Run unit tests

Note: This project is setup to use the Mocha Sidebar extension which makes it easier to view the tests.

Related Packages

NPM @MDI Organization