Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

styled-animate

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

styled-animate

```javascript import withAnimate from 'styled-animate'

  • 0.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Example Usage

import withAnimate from 'styled-animate'

const Foo = styled.div`
  /* some styles here */
`

const AnimatedFoo = withAnimate(Foo, {
  transition: '500ms linear',
  animate: {
    opacity: [0, 1]
  }
})

// then in a render function...
<AnimatedFoo in={this.state.showFoo} />

Using the "animate" key will produce a react-transition-group component that animates opacity from 0 to 1 on mount and from 1 to 0 on unmount, both animations lasting 500ms (parsed from the "transition" key). You may also use seconds as the unit of measure for the transition timing, like transition: 2s ease-in.

API

Using the example above, firstValue and secondValue equal 0 and 1, respectively, and property equals "opacity"

  • animate - animate property from firstValue to secondValue on mount, and from secondValue to firstValue on unmount.
  • animateIn - animate property from firstValue to secondValue on mount
  • animateOut - animate property from secondValue to firstValue on unmount
  • animateSticky - animate property from firstValue to secondValue when in prop is truthy, and from secondValue to firstValue when in prop is falsy. Component stays mounted regardless of the value of the in prop.

For the first three in the list above, the component will mount immediately when the in prop is truthy.

Note that property can be any CSS property, and firstValue and secondValue can be any valid values for that property.

Compatible components

You can use this on any component that forwards on the className prop. The styled components docs explanation applies here:

The styled method works perfectly on all of your own or any third-party components as well, as long as they pass the className prop to their rendered sub-components, which should pass it too, and so on. Ultimately, the className must be passed down the line to an actual DOM node for the styling to take any effect.

Upcoming features

Allow passing an array of properties to animate, and allow passing different values for "entering" and "exiting" phases of animation:

const Example = withAnimation(SomeComponent, {
  transition: 'opacity 1s ease-in-out',
  animate: [
    {
      opacity: [0, 1, 0.5]
    }, {
      'font-size': ['12px', '16px', '14px']
    }
  ]
}

Keywords

FAQs

Package last updated on 08 Mar 2018

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