Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@react-md/icon

mlaursen13.5kMIT5.1.6TypeScript support: included

This package is for including icons within react-md. There is included support for both font icons and SVG icons. There is also a helper component for applying spacing between icons and text.

react-md, material design, react, icon, font icon, svg icon, component, components

readme

@react-md/icon

Create icons using a font-icon library like material-icons or font-awesome or plain old accessible SVG icons. There are also a few additional helpers to creating animating rotating icons and separating text from an icon.

Installation

npm install --save @react-md/icon

It is also recommended to install the other packages if you have not done so:

npm install --save @react-md/theme @react-md/typography

Pre-made material icons

If you would like to have access to all material icons as existing components instead of having to manually remember the correct children to provide or the correct path, you can install the @react-md/material-icons package. This will include all material icons as font and SVGs.

Documentation

You should check out the full documentation for live examples and more customization information, but an example usage is shown below.

Usage

Even though the FontIcon and SVGIcon components are the "main" exports for this package, they are more utility components and probably won't be used much once you set up your own icon system. The real exports are going to be the TextIconSpacing and IconRotator components.

The TextIconSpacing component is used to add spacing between an icon and some "text" where the text can be any renderable element. The IconRotator is used to animate an icon rotation such as expander or collapse icons.

import { render } from "react-dom";
import { FontIcon, TextIconSpacing } from "@react-md/icon";
import { Typography } from "@react-md/typography";

// the Typography component is optional, it'll just add better typography
// than normal text.
const App = () => (
  <>
    // creates an icon spaced before the "Go Home" text
    <TextIconSpacing icon={<FontIcon>home</FontIcon>}>
      <Typography>Go Home</Typography>
    </TextIconSpacing>
    // creates an icon spaced after the "Go Home" text
    <TextIconSpacing icon={<FontIcon>home</FontIcon>} iconAfter>
      <Typography>Go Home</Typography>
    </TextIconSpacing>
    // it can also be combined
    <TextIconSpacing icon={<FontIcon>arrow_back</FontIcon>}>
      <TextIconSpacing icon={<FontIcon>home</FontIcon>} iconAfter>
        <Typography>Go Home</Typography>
      </TextIconSpacing>
    </TextIconSpacing>
  </>
);

render(<App />, document.getElementById("root"));

This package's icon component usage is really only helpful when generating icon components through an external script or using font icons. However, here are a few examples of using the FontIcon and SVGIcon components:

import { render } from "react-dom";
import { FontIcon, SVGIcon } from "@react-md/icon";

// When using font icons, you'll need to make sure they icon fonts have been
// correctly included in your app. Check out the documentation site for more
// info

const App = () => (
  <>
    <FontIcon>home</FontIcon>
    <FontIcon iconClassName="fa fa-github" aria-label="Github" />
    <SVGIcon title="Face">
      <path d="M9 11.75c-.69 0-1.25.56-1.25 1.25s.56 1.25 1.25 1.25 1.25-.56 1.25-1.25-.56-1.25-1.25-1.25zm6 0c-.69 0-1.25.56-1.25 1.25s.56 1.25 1.25 1.25 1.25-.56 1.25-1.25-.56-1.25-1.25-1.25zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8 0-.29.02-.58.05-.86 2.36-1.05 4.23-2.98 5.21-5.37C11.07 8.33 14.05 10 17.42 10c.78 0 1.53-.09 2.25-.26.21.71.33 1.47.33 2.26 0 4.41-3.59 8-8 8z" />
    </SVGIcon>
  </>
);

render(<App />, document.getElementById("root"));

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

5.1.6 (2023-12-11)

Note: Version bump only for package @react-md/icon

5.1.3 (2022-05-07)

Documentation

  • fix typos throughout codebase (725d1a2)

Other Internal Changes

  • typos: fix additional typos throughout repo (ef20132)

5.1.2 (2022-04-02)

Note: Version bump only for package @react-md/icon

5.1.0 (2022-03-18)

Other Internal Changes

  • run lint-scripts --fix for consistent-type-imports (42d839d)

5.0.0 (2022-01-31)

Other Internal Changes

  • chore!(icon): Renamed the download icon to upload (2752a98)

4.0.3 (2021-12-31)

Bug Fixes

  • @react-md/icon: FileInput default icon changed from file_download to file_upload (174d1c1), closes #1325

Other Internal Changes

  • Updated all packages' peerDependenciesMeta (60fcd71), closes #1319

4.0.1 (2021-11-27)

Note: Version bump only for package @react-md/icon

4.0.0 (2021-11-24)

Bug Fixes

  • sass: Do not use legacy global functions (6159e16)

Features

  • Update to use new JSX Transform and latest eslint (8111cd3)
  • @react-md/typography: Renamed Text to Typography (30cf056)

Other Internal Changes

  • always skip lib check (229cef1)
  • react-md: Remove prop-types package and usage (2637a6f)
  • stylelint: Updated to use stylelint (22d1598)

Breaking Changes

  • Minimum React version is now 16.14 instead of 16.8
  • @react-md/typography: The Text component has been renamed to Typography to help with auto-imports conflicting with the Text element that exists in lib.d.ts
  • react-md: There will no longer be run-time prop validation with the prop-types package.

3.1.0 (2021-09-10)

Other Internal Changes

  • ran yarn format to include new files (48d3d7f)

3.0.0 (2021-08-13)

Other Internal Changes

  • react-md.dev: updated examples to work with sass instead of node-sass (d8ddf51)

2.9.1 (2021-07-27)

Other Internal Changes

  • install: slighly reduce install size by excluding tests in publish (9d01a44)

2.9.0 (2021-07-18)

Note: Version bump only for package @react-md/icon

2.8.4 (2021-06-10)

Note: Version bump only for package @react-md/icon

2.8.3 (2021-05-18)

Documentation

  • react-md.dev: updated tsdoc to work with typedoc (cf54c35)

2.8.2 (2021-04-23)

Note: Version bump only for package @react-md/icon

2.8.0 (2021-04-22)

Other Internal Changes

  • tsconfig: separate tsconfig by package instead of a single root (b278230)

2.7.1 (2021-03-23)

Other Internal Changes

  • ts: stopped using FC type (c5daa47)

2.7.0 (2021-02-28)

Documentation

  • tsdoc: fixed remaining tsdoc syntax warnings (946f4dd)
  • tsdoc: fixed some tsdoc annotations and styling (0449b86)
  • tsdoc: updated @since annotations (c62027e)

Other Internal Changes

  • updated test coverage to not include conditional component PropTypes (24e5df1)

2.6.0 (2021-02-13)

Note: Version bump only for package @react-md/icon

2.5.5 (2021-01-30)

Note: Version bump only for package @react-md/icon

2.5.4 (2021-01-27)

Note: Version bump only for package @react-md/icon

2.5.0 (2020-12-15)

Features

2.4.2 (2020-10-23)

Note: Version bump only for package @react-md/icon

2.4.1 (2020-10-17)

Note: Version bump only for package @react-md/icon

2.4.0 (2020-10-17)

Features

2.3.1 (2020-09-15)

Note: Version bump only for package @react-md/icon

2.3.0 (2020-09-10)

Note: Version bump only for package @react-md/icon

2.2.2 (2020-09-02)

Note: Version bump only for package @react-md/icon

2.2.1 (2020-09-02)

Note: Version bump only for package @react-md/icon

2.1.2 (2020-08-01)

Note: Version bump only for package @react-md/icon

2.1.1 (2020-07-21)

Note: Version bump only for package @react-md/icon

2.1.0 (2020-07-12)

Bug Fixes

  • Booleans in dist/scssVariables (f6d43a3)

2.0.2 (2020-06-30)

Bug Fixes

  • LICENSE: Removed the time range from license since it was incorrect (50c9021)
  • Added sideEffects field to package.json (31820b9)
  • sideEffects formatting (78a7b6b)

v2.0.1

No changes.

v2.0.0

New Behavior and Features

  • all refs are now forwarded to the DOM elements
  • new theme API that allows for customizing the size and color of icons a lot easier with exported mixins
  • built-in support for right-to-left languages when spacing text with icons
  • added an IconRotator component to be able to animate a rotation for an icon

    This is a new component implementation for the .md-collapser/getCollapserStyles that existed in v1 but wasn't really documented

  • the TextIconSpacing component now requires a parent element with display: flex to work since it renders as a <Fragment> instead of a <div>
  • the spacing is now handled with margin instead of padding with the TextIconSpacing component
  • the icon is now placed before the children instead of after by default for the TextIconSpacing component
  • added a new forceIconWrap prop to the TextIconSpacing component to help with custom components that don't accept a className prop being cloned in for the spacing styles
  • added additional props to the TextIconSpacing for additional customization for the spacing behavior
  • simplified svg style precedence to be easier to override (.rmd-icon--svg instead of svg.md-icon)
  • changing the size for font icons and svg icons is now the same since they use css variables

Breaking Changes

  • all icons were updated to have aria-hidden="true" by default.
  • all icons no longer support applying theme colors with the primary, secondary, disabled, error, and inherit props and requires custom css instead
  • the IconSeparator has been renamed to TextIconSpacing and now renders the children as the label and requires an icon prop (the reverse of v1)
  • the SVGIcon no longer has the titleAttr, title, and desc props since they aren't actually helpful with accessibility out of the box since aria-label/aria-labelledby is preferred
  • the SVGIcon changed the default role from "img" to "presentation"

New SCSS Variables, Functions, and Mixins

  • $rmd-icon-material-icons-font: false !default - boolean if you are using the material-icons font icon library and automatically fix the dense spec
  • $rmd-icon-use-font-icons: true !default - boolean if you want to include the styles for font icons. You can maybe save a few bytes by disabling this variable if you only use svg icons
  • $rmd-icon-use-svg-icons: true !default - boolean if you want to include the styles for svg icons. You can maybe save a few bytes by disabling this variable if you only use font icons
  • @function rmd-icon-theme - gets one of the icon's theme values
  • @function rmd-icon-theme-var - gets one of the icon's theme values as a css variable
  • @mixin rmd-icon-theme - applies one of the icon's theme values as a css property
  • @mixin rmd-icon-theme-update-var - updates one of the icon's theme css variables
  • @mixin rmd-icon-text-spacing - a mixin that allows you to separate two elements

Renamed SCSS Variables, Functions, and Mixins

  • renamed $md-font-icon-include-dense to $rmd-icon-include-dense
  • renamed $md-font-icon-size to $rmd-icon-size and changed the default value from 24px to $1.5rem
  • renamed $md-font-icon-dense-size to $rmd-icon-dense-size and changed the default value from 20px to 1.25rem
  • renamed $md-font-icon-separator-padding to $rmd-icon-spacing-with-text and changed the default value from 16px to 0.5rem
  • renamed @mixin react-md-icons-dense to rmd-icon-dense-theme

Removed SCSS Variables Placeholders, and Mixins

  • removed $md-font-icon-include-separators since it is always included by default
  • removed $md-font-icon-include-dense-material-icons since it is no longer required
  • removed $md-font-icon-light-theme-disabled-color and $md-font-icon-dark-theme-disabled-color since they are no longer required
  • removed @mixin react-md-theme-icons since it is no longer required
  • removed @mixin react-md-icons-media since it is no longer required