Socket
Socket
Sign inDemoInstall

react-animate-height

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-animate-height

Lightweight React component for animating height using CSS transitions.


Version published
Weekly downloads
291K
decreased by-11.62%
Maintainers
1
Weekly downloads
 
Created

What is react-animate-height?

The react-animate-height package is a React component that allows you to animate the height of an element. This can be useful for creating smooth transitions when showing or hiding content, such as expanding or collapsing sections.

What are react-animate-height's main functionalities?

Basic Height Animation

This example demonstrates a basic height animation where the height of a div toggles between 0 and 'auto' when a button is clicked. The animation duration is set to 500 milliseconds.

import React, { useState } from 'react';
import AnimateHeight from 'react-animate-height';

const Example = () => {
  const [height, setHeight] = useState(0);

  return (
    <div>
      <button onClick={() => setHeight(height === 0 ? 'auto' : 0)}>
        Toggle Height
      </button>
      <AnimateHeight
        duration={500}
        height={height} // see props documentation below
      >
        <div>
          This content will expand and collapse with animation.
        </div>
      </AnimateHeight>
    </div>
  );
};

export default Example;

Animating to Specific Height

This example shows how to animate the height of a div to specific values (100px and 200px) when a button is clicked. The animation duration is set to 500 milliseconds.

import React, { useState } from 'react';
import AnimateHeight from 'react-animate-height';

const Example = () => {
  const [height, setHeight] = useState(100);

  return (
    <div>
      <button onClick={() => setHeight(height === 100 ? 200 : 100)}>
        Toggle Height
      </button>
      <AnimateHeight
        duration={500}
        height={height} // see props documentation below
      >
        <div>
          This content will expand and collapse to specific heights with animation.
        </div>
      </AnimateHeight>
    </div>
  );
};

export default Example;

Animating with Easing

This example demonstrates how to use easing functions with the height animation. The easing function 'ease-in-out' is applied to the animation, making the transition smoother.

import React, { useState } from 'react';
import AnimateHeight from 'react-animate-height';

const Example = () => {
  const [height, setHeight] = useState(0);

  return (
    <div>
      <button onClick={() => setHeight(height === 0 ? 'auto' : 0)}>
        Toggle Height
      </button>
      <AnimateHeight
        duration={500}
        height={height} // see props documentation below
        easing="ease-in-out"
      >
        <div>
          This content will expand and collapse with easing animation.
        </div>
      </AnimateHeight>
    </div>
  );
};

export default Example;

Other packages similar to react-animate-height

Keywords

FAQs

Package last updated on 10 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc