Skip to content

Repository files navigation

@rc-component/collapse

Ant Design Part of the Ant Design ecosystem.

🪗 A flexible collapse and accordion component for React.

NPM versionnpm downloadsbuild statusCodecovbundle sizedumi

English | 简体中文

Highlights

  • Supports accordion and multi-panel collapse modes.
  • Prefer the items API for declarative panel configuration.
  • Keeps Collapse.Panel for compatibility. It is deprecated and will be removed in v4.
  • Supports custom expand icons, semantic class names, semantic styles, and motion.

Install

npm install @rc-component/collapse

Usage

importCollapsefrom'@rc-component/collapse';import'@rc-component/collapse/assets/index.css';exportdefaultfunctionApp(){return(<CollapsedefaultActiveKey="1"items={[{key: '1',label: 'First panel',children: 'First panel content',},{key: '2',label: 'Second panel',children: 'Second panel content',},]}/>);}

Examples

Run the local dumi site:

npm install
npm start

Then open http://localhost:8000.

API

Collapse

PropertyDescriptionTypeDefault
accordionOnly one panel can be opened at a timebooleanfalse
activeKeyCurrent active panel keyReact.Key | React.Key[]-
classNameAdditional class namestring-
classNamesSemantic class namesPartial<Record<SemanticName, string>>-
collapsibleSpecify whether panel trigger area is collapsibleheader | icon | disabled-
defaultActiveKeyInitial active panel keyReact.Key | React.Key[]-
destroyOnHiddenDestroy inactive panel contentbooleanfalse
expandIconCustom expand icon(props: object) => React.ReactNode-
itemsCollapse items contentItemType[]-
openMotionCustom open motionCSSMotionProps-
prefixClsComponent class name prefixstringrc-collapse
styleInline styleobject-
stylesSemantic stylesPartial<Record<SemanticName, React.CSSProperties>>-
onChangeCallback when active panels change(key: React.Key[]) => void-

ItemType

PropertyDescriptionTypeDefault
keyPanel keyReact.Key-
labelPanel header contentReact.ReactNode-
refPanel DOM refReact.RefObject<HTMLDivElement>-
childrenPanel body contentReact.ReactNode-
classNameAdditional panel class namestring-
classNamesSemantic class namesPartial<Record<SemanticName, string>>-
collapsibleSpecify whether the panel is collapsibleheader | icon | disabled-
destroyOnHiddenDestroy inactive panel contentbooleanfalse
extraExtra content in the panel headerReact.ReactNode-
forceRenderRender panel content before it is openedbooleanfalse
showArrowShow arrow beside headerbooleantrue
styleInline panel styleobject-
stylesSemantic stylesPartial<Record<SemanticName, React.CSSProperties>>-
onItemClickCallback when this panel is clicked(panelKey: React.Key) => void-

Collapse.Panel

Collapse.Panel is deprecated. Use items instead.

Development

npm install
npm start

The dumi site runs at http://localhost:8000 by default.

npm test
npm run tsc
npm run lint
npm run compile
npm run build

Release

npm run prepublishOnly

The release flow is handled by @rc-component/np through the rc-np command after the package build.

License

@rc-component/collapse is released under the MIT license.

About

🪗 A flexible collapse and accordion component for React.

Topics

Resources

Stars

332 stars

Watchers

25 watching

Forks

Releases

Packages

Used by

Contributors

Languages