All Projects → tanvesh01 → motion-hooks

tanvesh01 / motion-hooks

Licence: MIT license
A simple Hooks wrapper over Motion One, An animation library, built on the Web Animations API for the smallest filesize and the fastest performance.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to motion-hooks

babel-plugin-rewire-exports
Babel plugin for stubbing [ES6, ES2015] module exports
Stars: ✭ 62 (-33.33%)
Mutual labels:  rollup, esm
vitext
The Next.js like React framework for better User & Developer experience!
Stars: ✭ 376 (+304.3%)
Mutual labels:  rollup, esm
npm-es-modules
Breakdown of 7 different ways to use ES modules with npm today.
Stars: ✭ 67 (-27.96%)
Mutual labels:  rollup, esm
dynamic-motion
Provide additional functionality to Android MotionLayout.
Stars: ✭ 34 (-63.44%)
Mutual labels:  motion
rollup-plugin-inject-process-env
Inject environment variables in process.env with Rollup
Stars: ✭ 48 (-48.39%)
Mutual labels:  rollup
rollit
🌯 Zero config js library bundling using rollup with support for Vue
Stars: ✭ 24 (-74.19%)
Mutual labels:  rollup
tailwind-layouts
Collection of Tailwind Layouts
Stars: ✭ 53 (-43.01%)
Mutual labels:  esm
WebCamCap
Motion capture tool for 2D/3D motion capture with LED markers.
Stars: ✭ 20 (-78.49%)
Mutual labels:  motion
svelte-box
A truffle box for svelte
Stars: ✭ 60 (-35.48%)
Mutual labels:  rollup
rollup-plugin-html
Import HTML files as strings in rollup build
Stars: ✭ 36 (-61.29%)
Mutual labels:  rollup
nativescript-vue-rollup-template
A NativeScript template ready to roll with Vue.js and .vue files.
Stars: ✭ 39 (-58.06%)
Mutual labels:  rollup
piCamBot
Security camera based on a raspberry pi and Telegram, controllable by smartphone
Stars: ✭ 43 (-53.76%)
Mutual labels:  motion
zksync-dapp-checkout
zkCheckout — trustable permissionless DeFi payment gateway. Brand new zkSync dApp w/t all L2 perks: fast&cheap transfers / simple&quick withdrawal
Stars: ✭ 37 (-60.22%)
Mutual labels:  rollup
room-glimpse
Read what your Raspberry Pi sees (picamera + Azure Cognitive / IoT)
Stars: ✭ 15 (-83.87%)
Mutual labels:  motion
vue-motion-one
Animation library for Vue 3 based on Motion One.
Stars: ✭ 152 (+63.44%)
Mutual labels:  motion
fliphub
the easiest app builder
Stars: ✭ 30 (-67.74%)
Mutual labels:  rollup
rollup-plugin-glob-import
A rollup plugin to use glob-star.
Stars: ✭ 18 (-80.65%)
Mutual labels:  rollup
rollup-plugin-generate-package-json
Generate package.json file with packages from your bundle using Rollup
Stars: ✭ 29 (-68.82%)
Mutual labels:  rollup
interpolations
Lightweight Unity library for smoothing movements and value progressions in code (dragging, easing, tweening).
Stars: ✭ 29 (-68.82%)
Mutual labels:  motion
gloss
a powerful style system for building ui kits
Stars: ✭ 16 (-82.8%)
Mutual labels:  motion

motion-hooks

A React Hooks wrapper over Motion One, An animation library, built on the Web Animations API for the smallest filesize and the fastest performance.

npm version npm Twitter Follow

Installation

npm install motion-hooks motion

Your project needs to have [email protected] [email protected] or greater

Hooks

As of now, motion-hooks has 2 hooks that wrap around animate and timeline of motion one respectively

Example usage

Things You could do with useMotionAnimate

Animating List - Link to codesandbox

useMotionAnimate List Example

Animating Counter - Link to codesandbox

useMotionAnimate Counter Example

Things You could do with useMotionTimeline

Animating elements independently - Link to codesandbox

useMotionTimeline Example Usage

useMotionAnimate

Returns all the properties returned by animate and some helper functions and state

Props returned my animate are null initially

You may view this example here on codesandbox.

function App() {
    const { play, isFinished, replay } = useMotionAnimate(
        '.listItem',
        { y: -20, opacity: 1 },
        {
            delay: stagger(0.3),
            duration: 0.5,
            easing: [0.22, 0.03, 0.26, 1],
        },
    );

    // Play the animation on mount of the component
    useEffect(() => {
        play();
    }, []);

    return (
        // Replay the animation anytime by calling a function, anywhere
        <div className="App">
            <button disabled={!isFinished} onClick={() => replay()}>
                Replay
            </button>

            <ul className="list">
                <li className="listItem">Item 1</li>
                <li className="listItem">Item 2</li>
                <li className="listItem">Item 3</li>
            </ul>
        </div>
    );
}

Instead of passing strings to select elements, you can also pass a ref 👇

const boxRef = useRef(null);
const { play, isFinished, replay } = useMotionAnimate(
    boxRef,
    { y: -20, scale: 1.2 },
    { duration: 1 },
);

return <div ref={boxRef}>BOX</div>;

API

const { play, replay, reset, isFinished, animateInstance } = useMotionAnimate(
    selector,
    keyframes,
    options,
    events,
);

useMotionAnimate returns:

  • play: plays the animation
  • replay: Resets and plays the animation
  • reset: resets the element to its original styling
  • isFinished: is true when animation has finished playing
  • animateInstance: Animation Controls. Refer to motion one docs for more.

useMotionAnimate accepts:

  • selector - The target element, can be string or a ref

  • keyframes - Element will animate from its current style to those defined in the keyframe. Refer to motion's docs for more.

  • options - Optional parameter. Refer to motion doc's for the values you could pass to this.

  • events - Pass functions of whatever you want to happen when a event like onFinish happens.

    events usage example

    const { play, isFinished, replay } = useMotionAnimate(
        '.listItem',
        { y: -20, opacity: 1 },
        {
            delay: stagger(0.3),
            duration: 0.5,
        },
        {
            onFinish: () => {
                // Whatever you want to do when animation finishes
            },
        },
    );

useMotionTimeline

Create complex sequences of animations across multiple elements.

returns timelineInstance (Animation Controls) that are returned by timeline and some helper functions and state

Props returned my timeline are null initially

You may view this example here on codesandbox.

function App() {
    const gifRef = useRef(null);
    const { play, isFinished, replay } = useMotionTimeline(
        [
            // You can use Refs too!
            [gifRef, { scale: [0, 1.2], opacity: 1 }],
            ['.heading', { y: [50, 0], opacity: [0, 1] }],
            ['.container p', { opacity: 1 }],
        ],
        { duration: 2 },
    );

    useEffect(() => {
        play();
    }, []);

    return (
        <div className="App">
            <button disabled={!isFinished} onClick={() => replay()}>
                Replay
            </button>

            <div className="container">
                <img
                    ref={gifRef}
                    className="gif"
                    src={Image}
                    alt="mind explosion gif"
                />
                <div>
                    <h1 className="heading">Tanvesh</h1>
                    <p>@sarve__tanvesh</p>
                </div>
            </div>
        </div>
    );
}

API

const { play, replay, reset, isFinished, timelineInstance } = useMotionTimeline(
    sequence,
    options,
    events,
);

useMotionTimeline returns:

  • play: plays the animation
  • replay: Resets and plays the animation
  • reset: resets the element to its original styling
  • isFinished: is true when animation has finished playing
  • timelineInstance: Animation Controls. Refer to motion one docs for more.

useMotionTimeline accepts:

  • sequence - sequence is an array, defines animations with the same settings as the animate function. In the arrays, Element can be either a string or a ref. You can refer to sequence docs for more on this.
  • options - Optional parameter. Refer to motion doc's for the values you could pass to this.
  • events - Pass functions of whatever you want to happen when a event like onFinish happens. Exactly same as useMotionAnimate's onFinish.

Local Installation & Contributing

git clone https://github.com/:github-username/motion-hooks.git
cd motion-hooks
npm install # Installs dependencies for motion-hooks
cd examples # React app to test out changes
npm install # Installs dependencies for example app
npm run dev # To run example on localhost:3000

The contributing guidelines along with local setup guide is mentioned in CONTRIBUTING.md

Any Type of feedback is more than welcome! This project is in very early stage and would love to have contributors of any skill/exp level.

You can contact me on my Twitter handle @Sarve___tanvesh

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].