Options
All
  • Public
  • Public/Protected
  • All
Menu

react-transition-collapse

Performant animated accordion/collapse react component powered by css transitions and css transform.

npm build
npm travis

Installation

npm install --save react-transition-collapse
yarn add react-transition-collapse

Usage

ReactTransitionCollapse takes these props:

children: Element
duration: number | string // number of milliseconds
expanded: boolean
animationType: 'scale' | 'translate' // which css transform should be applied to animate the transition

Full example

import React, { useState } from 'react'
import ReactTransitionCollapse from 'react-transition-collapse'

export const Expandable = () => {
  const [expanded, setExpanded] = useState(false)
  return (
    <>
      <button onClick={() => setExpanded(expanded => !expanded)}>Expand</button>
      <div>
        <ReactTransitionCollapse expanded={expanded} duration={200}>
          Lorem nostrud velit ullamco dolore exercitation consectetur occaecat enim laboris cillum
          incididunt ullamco ex. Adipisicing eu nulla anim laborum. Exercitation consequat anim
          culpa aute fugiat dolor in aliqua Lorem labore mollit anim id dolore. Sunt ut sunt duis
          commodo irure dolore adipisicing occaecat non nisi sit. Labore consequat amet anim nulla
          ipsum excepteur do duis labore.
        </ReactTransitionCollapse>
      </div>
    </>
  )
}

NPM scripts

  • npm t: Run test suite
  • npm start: Run npm run build in watch mode
  • npm run test:watch: Run test suite in interactive watch mode
  • npm run test:prod: Run linting and generate coverage
  • npm run build: Generate bundles and typings, create docs
  • npm run lint: Lints code
  • npm run commit: Commit using conventional commit style (husky will tell you to use it if you haven't :wink:)

Index

Type aliases

DomEl

DomEl: null | HTMLElement

transitionProps

transitionProps: object

Type declaration

  • Optional animationType?: "scale" | "translate"
  • children: Element
  • Optional duration?: number | string
  • expanded: boolean

Object literals

Const innerBaseStyle

innerBaseStyle: object

height

height: string = "auto"

transformOrigin

transformOrigin: string = "top"

transitionDuration

transitionDuration: string = "0.5s"

transitionProperty

transitionProperty: string = "transform"

transitionTimingFunction

transitionTimingFunction: string = "ease"

Const wrapperBaseStyle

wrapperBaseStyle: object

height

height: string = "0px"

overflow

overflow: string = "hidden"

transitionDuration

transitionDuration: string = "0.5s"

transitionProperty

transitionProperty: string = "height"

transitionTimingFunction

transitionTimingFunction: string = "ease"

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc