Coder Social home page Coder Social logo

dipeshrai123 / react-ui-animate Goto Github PK

View Code? Open in Web Editor NEW
40.0 2.0 0.0 575 KB

React library for gestures and animation :computer:

Home Page: https://react-ui-animate.js.org/

License: MIT License

JavaScript 0.84% TypeScript 99.16%
animation gesture interaction

react-ui-animate's Introduction

React UI Animate

npm version

React library for gestures and animation

Install

Install with npm:

npm i react-ui-animate

or Install with yarn:

yarn add react-ui-animate

Getting Started

react-ui-animate provides lots of easy to use APIs to create smooth animations and gestures.

import { AnimatedBlock, useAnimatedValue } from "react-ui-animate";

export default function () {
  const opacity = useAnimatedValue(0); // It initializes opacity object with value 0.

  return (
    <div>
      {/* AnimatedBlock component can read useAnimatedValue() */}
      <AnimatedBlock
        style={{
          opacity: opacity.value, // using opacity with value property
          width: 100,
          padding: 20,
          background: "#39F",
        }}
      >
        ANIMATED
      </AnimatedBlock>

      {/* Assigning value to 1 auto animates from initialized value 0 to 1 smoothly */}
      <button onClick={() => (opacity.value = 1)}>Animate Me</button>
    </div>
  );
}

Animates opacity from 0 to 1.

useAnimatedValue()

useAnimatedValue() is very flexible and powerful hook that lets you define animated values. It accepts a value and returns a node with same value on value property. Whenever value property is assigned to another value, it auto animates from one value to another.

const opacity = useAnimatedValue(0); // initialize with 0 opacity

...
style={{
    opacity: opacity.value // access with `.value`
}}
...

...
onClick={() => opacity.value = 1} // Assignment
...

AnimatedBlock

AnimatedBlock is a div component which can accept the animation node from useAnimatedValue() hook.

const width = useAnimatedValue(100);

<AnimatedBlock
  style={{
    width: width.value,
    height: 100,
    backgroundColor: "#39f",
  }}
/>;

interpolate

The interpolate() function allows animated node value to map from input ranges to different output ranges. By default, it will extrapolate the curve beyond the ranges given, but you can also have it clamp the output value.

import { useAnimatedValue, AnimatedBlock, interpolate } from "react-ui-animate";

const width = useAnimatedValue(100);

<AnimatedBlock
  style={{
    width: width.value,
    height: 100,
    backgroundColor: interpolate(width.value, [100, 200], ["red", "blue"]),
  }}
/>;

backgroundColor is interpolated from input range [100, 200] to output range ["red", "blue"]. So, when the width changes from 100 to 200, backgroundColor will change from red to blue.

Documentation

The official documentation are now published at http://react-ui-animate.js.org/

License

MIT

react-ui-animate's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-ui-animate's Issues

Add types to animated value

Issue:

  • In v2, animated value doesn't have type, Instead we use ValueType while assigning the value.

Expected Result:

  • Type should be added for animated value

Create same component for both MountedBlock and TransitionBlock

Issue:
Currently, MountedBlock and TransitionBlock are separate components.

Expected Result:
MountedBlock and TransitionBlock should be merged into one HOC. It lets devs to use same component whatever the use-case. You might want to use the prop to determine whether the component has to be mounted or not. Please make sure to use the prop names more sensible and short

Bug: `useOutsideClick` hook not working as expected

  • Issue replication: While creating a Modal and using the useOutsideClick hook to handle the dismiss on outside click when we click on the open button the modal doesn't appear. It is as soon as we click the open modal button the outside click callback is instantly fired which causes the issue

Work on branch: fix/useOutsideClick from base v2.0.0
Create a PR against it after completing the issue with the solved video output.

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.