# react-tiny-collapse

> Create expanding / collapsing sections in React with with css transitions

Latest version **2.0.0** (published 2022-11-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-tiny-collapse
pnpm add react-tiny-collapse
yarn add react-tiny-collapse
bun add react-tiny-collapse
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-11-07 |
| First published | 2018-05-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Asbjørn Hegdahl |
| Maintainers | asbjornh |
| Keywords | react, collapse, accordion, animation, transition |

## Links

- npm: https://www.npmjs.com/package/react-tiny-collapse
- Repository: https://github.com/asbjornh/react-tiny-collapse
- Homepage: https://github.com/asbjornh/react-tiny-collapse#readme
- Issues: https://github.com/asbjornh/react-tiny-collapse/issues
- npm.io page: https://npm.io/package/react-tiny-collapse

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2022-11-07
- 1.2.0 — 2022-06-06
- 1.1.0 — 2021-04-12
- 1.0.0 — 2019-06-12
- 0.4.0 — 2018-11-15
- 0.3.1 — 2018-06-18
- 0.3.0 — 2018-05-28
- 0.2.3 — 2018-05-28
- 0.2.2 — 2018-05-28
- 0.2.1 — 2018-05-21
- 0.2.0 — 2018-05-07
- 0.1.6 — 2018-05-07
- 0.1.5 — 2018-05-07
- 0.1.4 — 2018-05-07
- 0.1.3 — 2018-05-05
- … 3 more at https://npm.io/package/react-tiny-collapse/versions

## README

# react-tiny-collapse

[![npm version](https://img.shields.io/npm/v/react-tiny-collapse.svg?style=flat)](https://www.npmjs.com/package/react-tiny-collapse)
[![build status](https://travis-ci.org/asbjornh/react-tiny-collapse.svg?branch=master)](https://travis-ci.org/asbjornh/react-tiny-collapse)

TinyCollapse is a lightweight component for making animated expand / collapse components. It measures the height and applies it inline so you can add a transition (works when children change too).

### Browser support:

TinyCollapse needs `requestAnimationFrame` in order to do its thing, so make sure to add polyfills if you need to support older browsers (like IE9 and below).

### Why it exists

I really like [react-collapse](https://github.com/nkbt/react-collapse) and I've used it a lot. It does have some drawbacks though, such as being dependent on [react-motion](https://github.com/chenglou/react-motion) and not playing nice with server side rendering (as of v4). I wanted to create a more lightweight, dependency-free alternative.

### Other Tiny libraries

- [react-tiny-transition](https://github.com/asbjornh/react-tiny-transition)
- [react-tiny-crossfade](https://github.com/asbjornh/react-tiny-crossfade)

### Install

```console
npm install --save react-tiny-collapse
```

## API

**animateChildren** : Boolean = `false`
<br/>Animates height when children changes (set to `false` when nesting collapses)

---

**children** : React element
<br/>Stuff you want to expand / collapse (one root node only)

---

**className** : String

---

**component** : String | Function component = `"div"`
<br/>Type of element used for the wrapper node
<br/>If a function component is used it _must_ use `React.forwardRef`

---

**componentProps** : Object
<br/>Additional props passed to the wrapper component
<br/>If `componentProps` includes a `style` property, some individual styles may be overridden by the inline styles set by `react-tiny-collapse`.

---

**duration** : Number = `500`
<br/>Transition duration (milliseconds)

---

**easing** : String = `cubic-bezier(0.3,0,0,1)`
<br/>CSS easing function

---

**forceInitialAnimation** : Boolean = `false`
<br/>Force animation when TinyCollapse mounts open

---

**isOpen** : Boolean = `false`
<br/>Shows or hides the content

---

**onMeasure** : Function
<br/>Called whenever TinyCollapse measures height

```jsx
<TinyCollapse onMeasure={height => doStuff(height)}>
  <div>Stuff</div>
</TinyCollapse>
```

---

**unmountChildren** : Boolean = `false`
<br/>Unmounts children when closed

---

## Example usage:

```jsx
import TinyCollapse from "react-tiny-collapse";

...

<TinyCollapse isOpen={this.state.isOpen}>
  <div>Content</div>
</TinyCollapse>
```

## Nested TinyCollapse

When using nested `TinyCollapse` instances it's a good idea to set `animateChildren` to `false` on the outer one. If you don't, the outer one will measure the wrong height which will result in jaggy animation and clipping of content.

---
_Source: https://npm.io/package/react-tiny-collapse · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
