• Stars
    star
    137
  • Rank 260,535 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Dist for Material Design Icons React Component for JS/TypeScript

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

More Repositories

1

MaterialDesign

βœ’7000+ Material Design Icons from the Community
10,905
star
2

WindowsIcons

Windows Phone and Windows RT CC Icons
961
star
3

MaterialDesign-Webfont

@mdi/font Dist for Material Design Icons.
HTML
390
star
4

slack-emoji-pokemon

Slack Pokemon Emojis
JavaScript
375
star
5

ui.bootstrap.contextMenu

AngularJS Bootstrap UI Context Menu
JavaScript
260
star
6

MaterialDesign-SVG

@mdi/svg Dist for Material Design Icons.
JavaScript
251
star
7

MaterialDesign-JS

Dist for Material Design Icons JS/TypeScript
JavaScript
155
star
8

MaterialDesign-Font

Distribution Repo for the TTF font
HTML
145
star
9

MaterialDesign-Site

Site v2.0. This repo contains the site and admin, so little confusing.
TypeScript
36
star
10

ModernIcons

Modern Icons - Iconography for Universal Applications and the Web
31
star
11

Remarkable

Remarkable Template App and Various Themes
HTML
27
star
12

Script

Simple scripting engine for C#.
C#
22
star
13

MaterialDesign-Font-Build

NodeJS Webfont builder tailored for MDI w/ cli support
HTML
22
star
14

MaterialDesign-Angular-Material

@mdi/angular-material Dist for Material Design Icons.
JavaScript
19
star
15

ui.bootstrap.materialPicker

Material Design Color Picker.
JavaScript
13
star
16

lwc-ui

Absolutely minimal UI components LWC.
TypeScript
8
star
17

MaterialDesign-IconJar

@mdi/iconjar distribution for the IconJar format
JavaScript
6
star
18

MaterialDesign-AdobeXD

Material Design Icons distribution for AdobeXD Library.
JavaScript
6
star
19

ui.bootstrap.progressCircle

Circular Progress for AngularJS Bootstrap.
JavaScript
6
star
20

MaterialDesign-Web-Component

MDI Icon web component for use with @mdi/js
HTML
5
star
21

MaterialDesignLight-Webfont

Dist repo for Material Design Icons Light Font
CSS
4
star
22

MaterialDesign-ng

Angular 5 Distribution and Build for MDI Component and Icons.
TypeScript
3
star
23

Savvy

jqLite compatible markup parser for the Savvy syntax.
JavaScript
3
star
24

MaterialDesignLight-SVG

@mdi/light-svg Dist repo for Material Design Icons Light SVG / meta.json
3
star
25

MaterialDesign-Meta

Dist for Material Design Icons meta.json
JavaScript
3
star
26

MaterialDesign-React-Demo

Demo for MaterialDesign-React
JavaScript
2
star
27

MaterialDesign-Webfont-Build

Custom Builds of the Webfont
JavaScript
2
star
28

lwc-demo

Need an example website to show off your Lightning web components? Use this project.
HTML
2
star
29

MaterialDesign-Vue

VueJS/VueTS Component for Material Design Icons
2
star
30

image-to-bmp

Convert image to 1 bit depth BMP
JavaScript
2
star
31

Templarian

Flat file website.
2
star
32

MaterialDesign-Util

Utils for Material Design Icons' Build scripts
JavaScript
2
star
33

MaterialDesignLight-JS

Dist repo for Material Design Icons Light for JavaScript / TypeScript
TypeScript
1
star
34

MaterialDesign-lwc

Material Design Icons Lightning web component
JavaScript
1
star
35

magnetic-tiles

D20 Magnetic 1.25 inch 3D printed tiles
JavaScript
1
star
36

MaterialDesign-Legacy

Legacy Repo Data... before wiping out the main repo
1
star
37

MaterialDesign-Polymer

MDI Polymer Dist
1
star
38

Element

@mdi/element TypeScript Element
TypeScript
1
star
39

ui.bootstrap.dragDrop

Drag and Drop data / files with a few helpful AngularJS directives.
JavaScript
1
star
40

MaterialDesign-Components

Components for the MDI Website
TypeScript
1
star
41

nfc-terminal

Vintage Holotape Computer
JavaScript
1
star
42

Memory-Device

Memory Device
TypeScript
1
star