2.0.5 • Published 5 years ago

react-tiny-accordion v2.0.5

Weekly downloads
2,535
License
MIT
Repository
github
Last release
5 years ago

Tiny, super simple accordion for React · npm npm bundle size (minified + gzip)

Fully responsive, no resize event listeners, no dependencies, minimal markup, <80 LOC.

Demo

Codesandbox demo

Codesandbox

Installation

npm install react-tiny-accordion

Usage

import Accordion from 'react-tiny-accordion'

<Accordion className='accordion'>
    <div data-header="Title can be string literals">
        Content 1
    </div>
    <div data-header={<OrComponents />}>
        Content 2
    </div>
</Accordion>

Add some styling

.accordion {
  border-bottom: 1px solid #999;
}

/* Header */
.accordion > div > div:first-of-type {
  border: 1px solid #999;
  border-bottom: 0;
  padding: 1em;
  background-color: #eee;
}

/* Content */
.accordion > div > div:last-of-type {
  border-left: 1px solid #999;
  border-right: 1px solid #999;
}

Protip: Check the Codesandbox demo for a more complete styling example.

Props

PropDescriptionDefault
transitionDurationDuration of expand/collapse transition.500
transitionTimingFunctionSpeed curve of the transition, can be any valid CSS transition timing function.'ease'
openClassNameThe CSS class that should be applied to the currently expanded item.'open'
selectedIndexToggling an item can also be done via props.
onChangeEvent triggered when the user toggle an item, args: index, expanded, selectedIndex.
changeOnClickSet this to false if you only want to expand items via the selectedIndex prop.true
2.0.5

5 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.2

6 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago