1.0.0 • Published 11 months ago

@element-public/react-expansion-panel v1.0.0

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

ExpansionPanel

Description

Expansion panels are containers that can be connected to a larger surface, such as a content block or card, or can live within a list. They contain information and actions that are not essential to exist at the highest level of the user interface of an application. ExpansionPanels require ExpansionTrigger and ExpansionContent sub-component to be used. The ExpansionIcon indicator may optionally be used.

See live demos on storybook

Storybook ExpansionPanel 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-expansion-panel @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

Expansion Panel has been implemented in an unopinionated way that allows you to have greater flexibility in it's use. Nearly any tag or component can be used as an expansion panel.

The Expansion Panel is composed of 4 components:

  • ExpansionPanel
    • The root component within which all related components will be placed
  • ExpansionTrigger
    • This will define the clickable area
  • ExpansionContent
    • The content to be displayed or hidden.
  • ExpansionIcon
    • An optional customizable icon which will indicate the open or closed state for the given ExpansionContent

To enable each pair of ExpansionTrigger and ExpansionContent components to work together you will need to provide an expansionId. This can be any valid string or number.

Expansion Panel Props

NameTypeDefaultRequiredDescription
accordionbooleanfalsefalseOnly one panel will be open at a time

Expansion Panel Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseContent to be rendered. Expected to be ExpansionTrigger or ExpansionContent, though any other valid components or markup may be used.

Expansion Panel Events

NameDefaultRequiredParamsDescription
onContractundefinedfalseFired when a trigger is clicked and the content is contracted. Note, in the case of an accordion, this will only fire for the panel that was clicked. Returns expansionId
onExpandundefinedfalseFired when a trigger is clicked and the content is expanded. Note, in the case of an accordion, this will only fire for the panel that was clicked. Returns expansionId

Expansion Content Props

NameTypeDefaultRequiredDescription
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
defaultOpenbooleanfalsefalseThe content will display in the open (visible) state by default. If the ExpansionPanel is set to accordion, only the first item will be visible if more than one ExpansionContent is marked as open by default.
expansionIdstring|numbernulltrueThe unique id of the expansion panel, this must match the expansionId of the ExpansionTrigger and ExpansionIcon.
maxHeightstringundefinedfalseOptionally override the automatically calculated content height. Must be specified in px.
openbooleanundefinedfalseFor explicit control of the open state.
styleobjectnullfalsePassthrough style object.
tagstring|React.ElementType|React.Component'div'falseThe root content HtmlElement. Expects a block element that can receive a height (spans will not work). If set to null, no HtmlElement will be inserted and the class and style properties will be added to the first child (this is for backwards compatibility.)

Expansion Content Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenulltrueContent to be rendered inside the banner. Accepts any valid markup.

Expansion Content Breaking Changes

Description
ExpansionContent: ExpansionContent now renders a div around the content. The may be overridden with the tag prop.

Expansion Icon Props

NameTypeDefaultRequiredDescription
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
expandedbooleanundefinedfalseFor explicit control of the icon's toggle state.
expansionIdstring|numbernulltrueThe unique id of the expansion panel, this must match the expansionId of the ExpansionTrigger and ExpansionIcon.
lessIconstring|React.ReactNode'expand_less'falseAccepts the name of any valid material icon (see Icon component documentation for a list of valid icons). It will be toggled with moreIcon.
moreIconstring|React.ReactNode'expand_more'falseAccepts the name of any valid material icon (see Icon component documentation for a list of valid icons). It will be toggled with lessIcon.

Expansion Trigger Props

NameTypeDefaultRequiredDescription
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
disabledbooleannullfalsePrevent the trigger from being activated.
expansionIdstring|numbernulltrueThe unique id of the expansion panel, this must match the expansionId of the ExpansionTrigger and ExpansionIcon.
tagstring|React.ElementType|React.Component'div'falseThe trigger container element. If set to null, no HtmlElement will be inserted and the css class will be added to the first child (this is for backwards compatibility.)

Expansion Trigger Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseMost typically a Button, IconButton or similar clickable component.

Expansion Trigger Events

NameDefaultRequiredParamsDescription
onClicknullfalseWill be fired when the trigger is clicked. Returns the expansionId and open state.
onContractnullfalseWill be fired when the content panel is contracted. Returns expansionId and open state.
onExpandnullfalseWill be fired when the content panel is expanded. Returns expansionId and open state.