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

@bucky24/react-animate

v0.1.7

Published

Animation library for React apps

Downloads

17

Readme

@bucky24/react-animate

Animation library for React apps

There are probably better animation libraries out there.

@bucky24/react-animate allows for keyframe-based animation over standard css properties.

How To Use

The module currently exports a single hook, useAnimator.

import { useAnimator } from '@bucky24/react-animate';

export default function Component() {
    const animator = useAnimator({ config, autoPlay: true, frameDelay: 100 });
    
    return <div>
        <div {...animator.animate('id of element')}>content</div>
    </div>;

The hook takes three parameters:

| Param | Type | Description | |----|----|----| | config | Object | Must confirm to Config below | | autoPlay | Bool | Indicates if the animation should start playing immediately or not | | frameDelay | Number | The number of MS in between each tick |

It is recommended that you avoid setting the style property directly of any element you're animating over, though adding classes should work fine.

Animator

The Animator from useAnimator exposes the following methods:

animate

In order to actually consume the animator, spread the result of animator.animate('id') over the element. The id should match the ID in the config, and does not need to match the id property set on the element.

| Param | Type | Description | |----|----|----| | id | string | The id of the element in the config to get animation data for | | styles | Object | Optional. Any styles given here will also be applied to the element (overriding anything in the animation) |

moveTo

The moveTo method takes in a frame, and will immediately jump in time to that frame, setting all applicable properties.

playTo

The playTo method takes in a frame, and will play until that frame, then stop playback (unless autoPlay is enabled). If the current frame is already past the frame given, nothing will happen.

Config

The config is the main body of data for the animation system. Note that changing the configuration mid-animation will cause the entire system to reset.

The config is an object of the following format:

{
    <keyframe>: {
        "<id>": {
            "<animation key>": <value>
        }
    }
}

Keyframes should always be numeric, and represent the tick at which the value should be reached.

Style keys

Style keys are any valid css style, prepended with style.. so in order to set the color property, you would set style.color. Note these should be React css properties, so use marginTop, not margin-top.

Rotation

The rotation key will properly handle the rotation of the component, using transform. This is a shortcut key to allow the user to do rotations without building the full transform string.

Tips For Use

Setting a Property Before Use

The animation system will only be able to animate over a property if it was already set. So if you have something like this:

{
    10: {
        "id": {
            "width": 400
        }
    }
}

Then the system will wait 10 tickets, then set the width to 400. If you want to animate, you need to set the initial value like so:

{
    0: {
        "id": {
            "width": 100
        }
    },
    10: {
        "id": {
            "width": 400
        }
    }
}

This will animate the width from 100 to 400 over 10 ticks.