1.0.0 • Published 11 months ago

@element-public/react-icon-button v1.0.0

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

IconButton

Description

The icon button wraps the icon and provides button style interactions. Used when a user needs to interact with an icon.

See live demos on storybook

Storybook IconButton 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-button @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

The Icon Button makes an Icon clickable, so a user can interact with it.

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

Similarly to Icon, Icon Button offers use cases with Notification Badges, with and without a counter. Examples of these behaviors are shown under their respective Storybook stories.

The Toggleable story demonstrates an Icon Button that shows whether or not it has been clicked. In this example, the star Icon Button is filled in when clicked, and only outlined when it is unclicked. This behavior could be useful for showing an on/off function.

Icon Button Props

NameTypeDefaultRequiredDescription
activebooleanfalsefalseProgrammatically sets the toggle state of the button when used as a toggle button. If not set, the toggle state will be managed internally.
ariaLabelstringnullfalseAccessibility label for assistive technologies.
ariaLabelledBystringnullfalseId of an element serving as a label for this IconButton instance. Used by assistive technologies.
badgeReact.ReactNodeundefinedfalseThe custom icon button notification badge to be rendered.
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.
densebooleanfalsefalseEnables a smaller IconButton.
disabledbooleanfalsefalseDisables the icon button.
iconstring|React.ReactNodenullfalseFor simple use-cases, this will automatically create the icon object. Does not work with toggle='true'
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
tabIndexnumber0falseTabIndex of the button.
toggleOffAriaLabelstringnullfalseThe aria-label value to be read by a screen-reader when the button is toggled off. Example 'Add to Favorites'. Alternatively, toggleOffAriaLabelledBy may be used instead.
toggleOffAriaLabelledBystringnullfalseThe aria-labelledbyvalue when the button is toggled on. This should be the idof a parent element to be read by a screen reader instead of aria-label.
toggleOnAriaLabelstringnullfalseThe aria-label value to be read by a screen-reader when the button is toggled on. Example 'Remove from Favorites'. Alternatively, toggleOnAriaLabelledBy may be used instead.
toggleOnAriaLabelledBystringnullfalseThe aria-labelledbyvalue when the button is toggled on. This should be the id of a parent element to be read by a screen reader instead of aria-label.
variantstringempty stringfalseVariants 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-primary, filled-secondary, color-primary, color-secondary, color-on-dark, color-on-unknown-blackDeprecated Values: primary-alt, secondary-alt, primary, danger-alt, danger

Icon Button Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseThe content when when using the IconButton normally. Expects an Icon component. For toggle button functionality, use toggleOn and toggleOff instead.
toggleOffReact.ReactNodenullfalseThe content to be rendered when the IconButton is toggled off. Expects an Icon component. The typical use case for a toggle button would be to set an Icon for toggleOn and toggleOff, leaving children blank.
toggleOnReact.ReactNodenullfalseThe content to be rendered when the IconButton is toggled on. Expects an Icon component. The typical use case for a toggle button would be to set an Icon for toggleOn and toggleOff, leaving children blank.

Icon Button Events

NameDefaultRequiredParamsDescription
onClickundefinedfalse1. Name: event, Type: event, Description: The DOM JavaScript event.Fired when the user clicks the IconButton, will return toggle state, if applicable.