1.0.0 • Published 11 months ago

@element-public/react-chips v1.0.0

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

Chips

Description

Chips are used to represent small blocks of information that the user has entered or selected. They can be one of the types Choice, Filter, or Input

See live demos on storybook

Storybook Chips 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-chips @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

Notable props that are unique for each Chip include chipIdField, chipKeyField, and chipLabelField. Other important props include variant, which details whether the Chip is filled or outlined, scrollable, which determines whether Chips break on a newline in a list, preventChoiceDeselection, which prevents certain Chips from being deselected by a user, and input, which determines whether Chips can be dynamically added and removed.

Usage

Chips are compact elements that allow users to enter information, select a choice, filter content, or trigger an action. Each chip requires a unique key which can be configured with the chipKeyField property. It defaults to looking at the id field in each chip.

For filter and choice chips, two way data binding is accomplished via onUpdateSelectedChips and selectedChips props. For input chips, two way data binding is accomplished via onUpdateChips and chips props. Input chips may be either choice or filter.

Chips can include Leading or Trailing Icons. If no Leading or Trailing Icon is set, a material icon rendering the leadingIconField, or trailingIconField, of each chip is used.

Chips Props

NameTypeDefaultRequiredDescription
chipIdFieldstringempty stringfalseThe property on each chip that represents the id. If one is not provided material will generate an automatic ID.
chipKeyFieldstring'id'falseThe property on each chip that is used as a unique key.
chipLabelFieldstring'label'falseThe property for the label on each chip. The labelRenderer overrides the rendering of the label field
chips[][]trueArray of chips to manager and render.
disabledbooleanfalsefalsePrevent the user from interacting with the chips.
inputbooleanfalsefalseAllows chips to be dynamically added and removed upon trailing icon interaction.
labelRendererReact.ReactNode|functionnullfalseReturns the label to be rendered on each chip. Receives the chipData.
leadingIconFunctionnullfalseLeading icon render function. chip and iconProps is passed into the params. iconProps contains all the props for the icon component. If unused, a material icon rendering the leadingIconField of each chip is used
leadingIconFieldstring'leadingIcon'falseLeading icon property name for each chip. The leading icon property can either be a string corresponding to an icon, or an object containing all the properties for the icon component.
preventChoiceDeselectionbooleanfalsefalsePrevents choice chips from being deselected upon interaction.
scrollablebooleanfalsefalseChips do not break on a newline. The user must scroll horizontally if there is any overflow.
selectedChips[][]falseArray of currently selected chips.
selectionTypestring'default'falseFilter enables selection of multiple chips and will add a check mark to selected chips. Choice allows only one selected chip.Accepted Values: default, choice, filter
trailingIconFunctionnullfalseTrailing icon render function. chip and iconProps is passed into the params. iconProps contains all the props for the icon component. If unused, a material icon rendering the trailingIconField of each chip is used
trailingIconFieldstring'trailingIcon'falseTrailing icon property name for each chip. The trailing icon property can either be a string corresponding to an icon, or an object containing all the properties for the icon component.
variantstring'filled'falseShows chips as filled or outlined.Accepted Values: filled, outlined

Chips Events

NameDefaultRequiredParamsDescription
onInteractionundefinedfalse1. Name: undefined, Type: object, Description: Chip that was interacted withFired when the chip is interacted with (via click/tap or Enter key).
onRemovalundefinedfalse1. Name: undefined, Type: object, Description: Chip that was removedFired when a chip is removed.
onUpdateChipsundefinedfalse1. Name: undefined, Type: array, Description: Array of chipsFired when the chips are removed (input chips only).
onUpdateSelectedChipsundefinedfalseFired when the selected chips are updated (choice and filter chips only).

Chips Breaking Changes

Description
choice (removed): See selectionType=choice
filter (removed): See selectionType=filter

Chip Props

NameTypeDefaultRequiredDescription
chipDataanynulltrueChip data to be rendered. If no label is passed in, chipData will be used. If using an object, use the chipLabelField to set property to be rendered as the label. You may also set leadingIconField and trailingIconField, as well as labelRenderer for additional control.
chipIdFieldstringempty stringfalseThe property on the chip that represents the id. If one is not provided material will generate an automatic ID.
chipLabelFieldstringempty stringtrueThe property on the chip that is the label. The default slot overrides the rendering of the label.
disabledbooleanfalsefalsePrevent the user from interacting with the chip.
idstringundefinedfalseCustom id.
initiallySelectedbooleannulltrueIf the chip is selected on mount.
inputbooleannulltrueAllows chip to be dynamically added and removed upon trailing icon interaction.
labelRendererReact.ReactNode|functionnullfalseReturns the label to be rendered on each chip. Receives the chipData.
leadingIconFunctionnullfalseSlot for leading icon. chip and iconProps is passed into the slots params. iconProps contains all the props for the icon component. If there is no leading icon, a material icon rendering the leadingIconPropName of each chip is used.
leadingIconFieldstringempty stringtrueLeading icon property name for the chip. The leading icon property can either be a string corresponding to an icon, or an object containing all the properties for the icon component.
selectionTypestring'default'falseThe typefilter enables selection of multiple chips and will add a check mark to selected chips. The typechoice allows only one selected chip.Accepted Values: default, choice, filter
trailingIconFunctionnullfalseSlot for trailing icon. chip and iconProps is passed into the slots params. iconProps contains all the props for the icon component. If there is no trailing icon, a material icon rendering the trailingIconPropName of each chip is used.
trailingIconFieldstringempty stringtrueTrailing icon property name for the chip. The trailing icon property can either be a string corresponding to an icon, or an object containing all the properties for the icon component.
variantstring'filled'trueApplies the selected style.Accepted Values: filled, outlined

Chip Render Props

NameTypeDefaultRequiredDescription
labelReact.ReactNodenullfalseThe label to be rendered on each chip. Optionally chipData and chipLabelField may be used instead of label.

Chip Events

NameDefaultRequiredParamsDescription
onClickundefinedfalseCalled when chip is clicked.
onDestroyundefinedfalseFired when the chip is destroyed.
onEnterundefinedfalseCalled when Enter is pressed.
onMountedundefinedfalseFired when the chip is mounted.

Chip Breaking Changes

Description
children (removed): See label.
filled (removed): See variant=filled.
outlined (removed): See variant=outlined.
selected (removed): This is no longer needed.