npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-smooth-collapse

v2.1.2

Published

React component for animating showing or hiding an element.

Downloads

106,140

Readme

react-smooth-collapse

Circle CI npm version

This component lets you animate the height of an element to reveal or hide its contents. The animation automatically adjusts to the natural height of the contents.

Example

An example can be tried here:

https://streakyc.github.io/react-smooth-collapse/example/

You can find its code in the example directory. The example may be compiled by running:

yarn
yarn example-build
# or use this to auto-rebuild on changes:
yarn example-watch

Q: Why would I use this when I could set a transition rule for height on an element, and then change the height from "auto" to "0"?

A: You can't animate from "auto". This component has the height set to "auto" while the element is expanded, and when the element is set to collapse, the element's height is set to equal its current height, and then set to "0" so that it animates shrinking correctly.

Q: Couldn't I animate shrinking by setting a transition rule for max-height, setting max-height to a very large value when the element is expanded, and then set max-height to "0" when the element is collapsed?

A: That won't animate with the given duration and won't fully respect your timing function. For example, if you have an element that currently has a height of 100px, a max-height of 10000px, and a transition rule of "max-height 1s linear", then it will take 0.99 seconds before the element appears to start shrinking, and then it will fully shrink in 0.01 seconds. If you use a timing function like "ease" instead of "linear", then the easing will only be apparent while the element finishes shrinking to 0 or begins expanding from 0.

SmoothCollapse

This module exports the SmoothCollapse React component. The children of the component should be the contents you want to show or hide. The component also takes the following props:

  • expanded must be a boolean controlling whether to show the children.
  • onChangeEnd may be a function which will be called whenever a show or hide animation is completed.
  • collapsedHeight is the CSS height that the contents should have when collapsed. Defaults to "0".
  • heightTransition may be a string and is used for customizing the animation. This value is prefixed with "height " and is set as the CSS transition property of the SmoothCollapse element. This property defaults to ".25s ease".
  • allowOverflowWhenOpen is an optional boolean that when true causes the overflow:hidden CSS rule to be removed while the element is open. This behavior is off by default because the CSS rule must be present while animating, and contents that rely on the rule not being present while open may be jarringly effected when the rule is added. You may want this prop turned on if the children contains a dropdown element which is meant to visually escape its container.
  • eagerRender will ensure that all children are always rendered, even if they have never been expanded. This property defaults to false.

Additional props such as className will be passed on to the outer element. Care should be taken if any rules added by the class name conflict with SmoothCollapse's own CSS properties.

If the SmoothCollapse component starts out with expanded set to false, eagerRender is set to false, and collapsedHeight is 0, then the children are not rendered until the first time the component is expanded. After the component has been expanded once, the children stay rendered so that they don't lose their state when they're hidden.

Types

Both TypeScript and Flow type definitions for this module are included! The type definitions won't require any configuration to use.