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-hover-animation

v2.1.1

Published

A react wrapper component that detects hover and adds animation from the awesome react-spring.Works both on the web and mobile touch events.

Downloads

236

Readme

react-hover-animation

A react wrapper component that detects hover and adds animation from the awesome react-spring. Works both on the web and mobile touch events.

NPM JavaScript Style Guide

Example:

https://react-hover-animation-example.netlify.com/

Install

npm:

npm install --save react-hover-animation

yarn:

yarn add react-hover-animation

Usage

Basic usage

import React from 'react'
import { AnimationWrapper } from 'react-hover-animation'

const App = () => {
  return (
    <AnimationWrapper>
      <h1>I animate on hover</h1>
    </AnimationWrapper>
  )
}
export default App

Default behavior

The wrapper component comes with a build-in behavior on hover, Animation will play and change the element opacity from 1 to 0.6 and change the element scale from 1 to 0.95. In order to change the default behavior, you can either pass the reset prop to reset these defaults or pass a config object with styles for initial and onHover state.

Optional props

  • style: A style object for the wrapper component - styles will override the hover styles on the config object.
  • config: A config object to declare more styles to change on hover or overrides the default behavior, must provide to each CSS property two values of the same type(initial and onHover).
    • initial: The initial style.
    • onHover: The style on hover.
  • reset: A boolean that will reset the default behavior.
  • animaionConfig: Config for the animation, can be either a regular react-spring-config-object or a string with the name of one of the react-spring-config-presets (default, gentle, wobbly, stiff, slow, molasses).

Usage with props

import React from 'react'
import { AnimationWrapper } from 'react-hover-animation'

const App = () => {
  return (
    <AnimationWrapper
      /* 
      normal react attributes like "className" are allowed 
      */
      className='animation-wrapper'
      /* 
      styles will override the hover styles 
      */
      style={{
        textAlign: 'center',
        borderRadius: '5px',
        padding: '5px',
        backgroundColor: 'lightblue',
      }}
      /* 
      must provide to each css property two values of the same type (initial and onHover)  
      */
      config={{
        color: {
          initial: 'black',
          onHover: 'red',
        },
      }}
      /* 
      resets the default behavior  
      */
      reset={true}
      /* 
      animation config using an object 
      */
      animationConfig={{
        duration: 500,
      }}
      /* 
      animation config using a preset
      */
      /* 
      animationConfig='molasses'
      */
    >
      <h1>I animate on hover</h1>
    </AnimationWrapper>
  )
}
export default App

The useHover hook

If you don't want to render a wrapper div you can also import a custom hook and apply the animation directly on the element. Optional config object can be passed as an argument to the hook with either styles or animation config object.

import React from 'react'
import { useHover } from 'react-hover-animation'

const App = () => {
  /* 
    first call the hook
  */
  const { spring, animated, setHover } = useHover({
    /* 
    optional styles...
    */
    color: {
      initial: 'black',
      onHover: 'red',
    },
    /* 
    animation config using an object 
    */
    animationConfig: {
      duration: 500,
    },
    /* 
    animation config using a preset
    */
    /* 
    animationConfig: 'molasses',
    */
  })
  return (
    /* 
    add 'animated' to the element
    */
    <animated.h1
      /* 
      add spring to the style object
      */
      style={spring}
      /* 
     add these two event handlers
     */
      onPointerOver={() => {
        setHover(true)
      }}
      onPointerOut={() => {
        setHover(false)
      }}
    >
      I animate on hover
    </animated.h1>
  )
}
export default App

License

MIT © lulu70