Giter Site home page Giter Site logo

resap's Introduction

Resap

React hooks for easy GSAP animations, cause why not?

npm install resap

Hooks

*not currently available

Hooks description params return
useDraggable* returns gsap.Draggable object using Draggable.create DraggableVars ref, Draggable[Object]
useEase* creates custom ease easeVars Ease[Object]
useGSAP* returns the basic gsap object to use if you need a method we dont cover none GSAP[Object]
useMotionPath create a motion path using the motionPath plugin motionPathVars MotionPath[Object]
useToggle toggle trigger animation based on react state using gsap 'to', can optionally pass in an array of tweenvars state ,tweenvars / tweenvars[Array] ref
useTween* returns a Tween TweenVars[Object] ref, Tween[Object]
useTweens* returns array refs and tweens for one config num[Number], TweenVars[Object] refs[Array], Tween[Array]
useScrollTrigger* creates a scrolltigger object using new ScrollTrigger.create method ScrollTriggerVars ScrollTrigger[Object]
useScrollTo* creates a scrollTo Object ScrollToVars ScrollTo[Object]
useSet* sets global defaults for tweens TweenVars none
useText creates a text object with TextPlugin TextVars textObject
useTicker* set a callback function to be called every frame of animation callback[Function] none
useTimeline* returns a gsap timeline object TweenVars[Array], Tween[Array] Timeline[Object]
useUtility returns all utils function from gsap none GSAP.utils[Object]

API

- useToggle (toggles GSAP animation from base css styling to stated animation based on state changes)

//import useToggle from resap library

import { useToggle } from 'resap'

// create your state!
const [open, set] = React.useState(false)

// create a handler to change your state
const handleClick = () => {
  set(!open)
}

// set your gsap animation props! (use useRef or useMemo so the object doesn't get recreated on each render!)
const { current: animProps } = React.useRef({
  opacity: 0,
  y: 30,
  duration: 0.2,
  ease: 'power3.out',
})

// call the useToggle hook which returns a ref, passing in your state and the animation props!
const ref = useToggle(open, animProps)

// pass your ref to the object you wish to animate! when your state changes the toggle animation will trigger!
return <div ref={ref} onClick={handleClick} />

// you can also chain multiple tweens for your toggle by giving useToggle an array of objects

const { current: animProps } = React.useRef([
  {
    opacity: 0,
    y: 30,
    duration: 0.2,
    ease: 'power3.out',
  },
  {
    x: 10,
    skewY: 4,
    duration: 0.2,
    ease: 'power3.out',
  },
])

(More hooks to be included!)

resap's People

Contributors

alon-l avatar dependabot[bot] avatar phl3bas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.