1.0.0 • Published 11 months ago

@element-public/react-icon v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Icon

Description

Icons are small representative images that can be combined with other components such as buttons.

See live demos on storybook

Storybook Icon Demos

Install bundle from npm-e

npm i @element-public/react-components @element-public/themes

Optional: install the component individually

npm i @element-public/react-icon @element-public/themes

Open ~/.npmrc in an editor and add the following line to enable the @element-public scope:

@element-public:registry=https://npm.platforms.engineering

Troubleshooting

See below if you have never installed a package from Bayer's npm-enterprise or run into the following error:

npm ERR! code E401
npm ERR! Unable to authenticate, your authentication token seems to be invalid.
npm ERR! To correct this please trying logging in again with:
npm ERR!     npm login

Setup an access token

See the devtools npm-e guide to learn how to create an access token if this is the first time you are using a npm-e package at Bayer or you do not have a line that starts with the following in your ~/.npmrc file:

//npm.platforms.engineering/:_authToken=

Notes

Many options exist for Icon use. First, there is an extensive list of premade and labeled Icons. This list is included under the 'Icon Search' story on Storybook, and is based on the Google Material list, which can be found at the following link:

Icons can be used in several different sizes:

  • xsmall
  • small
  • medium
  • large
  • xlarge

Icons also support a number of color options:

  • filled-danger-alt
  • filled-danger
  • filled-muted
  • filled-primary
  • filled-secondary
  • color-primary
  • color-secondary
  • color-on-dark
  • blue
  • gray
  • green
  • orange
  • purple
  • red
  • teal
  • yellow

Alternatively, custom Icons can be used alone or with other components, similarly to the preexisting options.

Usage

Icons can be used with, or inside of, many other components, such as Badge and Button. Examples and demos of this behavior can be found under components' respective Storybook stories.

Accessibility Considerations

When creating a custom Icon, it is essential to ensure that the image is AA compliant. Refer to the following link, or one of many similar online resources, to check contrasting colors.

Icon Props

NameTypeDefaultRequiredDescription
ariaHiddenbooleannullfalseSets the aria-hidden attribute for the icon. If set to true, the icon will not be read by screen readers. Should be used if icon is purely decorative (such as when used in a button or textfield) or labeled by rendered text using aria-labelledBy or aria-label.
ariaLabelstringnullfalseAccessibility label for assistive technologies.
ariaLabelledBystringnullfalseId of the component being labeled for assistive technologies.
badgePlacementstring'right-start'falseThe placement of the notification badge on the icon to start. It will flip to the opposite side if there is no room.Accepted Values: right-start, left-start
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
iconstring|React.ReactNodenullfalseMostly commonly a string but accepts any valid markup or components. If a custom icon is used styles like color and size will need be handled with custom CSS.
iconSizestring'medium'falseOne of 'xsmall', 'small', 'medium', 'large', and 'xlarge' will change the size of the icon. Defaults to medium.Accepted Values: xsmall, small, medium, large, xlarge
iconTypestring'filled'falseThe icon type to be rendered. Not all icons have every type. To see which icons are available for different types see Material Icons docsAccepted Values: filled, outlined, rounded, two-tone, sharp
pointerbooleanfalsefalseAdd pointer icon style
variantstringempty stringfalseColor variations. Variants prefixed with filled- will add a background color to the icon according to the theme. Variants prefixed with color- will change the color of the icon according to the theme.Accepted Values: filled-danger-alt, filled-danger, filled-muted, filled-primary, filled-secondary, color-primary, color-secondary, color-on-dark, blue, gray, green, orange, purple, red, teal, yellowDeprecated Values: primary-alt, secondary-alt, primary, danger-alt, danger, muted

Icon Deprecated Props

NameTypeDefaultRequiredDeprecatedDescription
sizestringundefinedfalseRenamed, see iconSize instead.One of 'xsmall', 'small', 'medium', 'large', and 'xlarge' will change the size of the icon. Defaults to medium.

Icon Render Props

NameTypeDefaultRequiredDescription
badgeReact.ReactNodeundefinedfalseThe custom icon notification badge to be rendered. The icon notification badge component prevents xsmall and small icon size