Giter Club home page Giter Club logo

react-text-transition's Introduction

React-Text-transition

Animate your text changes

text-transition

Edit r03264p26n

Installation

npm install -S react-text-transition

Using the demo

npm run dev

How to use

Example

import React                       from "react";
import TextTransition, { presets } from "react-text-transition";

const TEXTS = [
  "Forest",
  "Building",
  "Tree",
  "Color"
];

const App = () => {
  const [index, setIndex] = React.useState(0);

  React.useEffect(() => {
    const intervalId = setInterval(() =>
      setIndex(index => index + 1),
      3000 // every 3 seconds
    );
    return () => clearTimeout(intervalId);
  }, []);

  return (
    <h1>
      <TextTransition springConfig={presets.wobbly}>
        {TEXTS[index % TEXTS.length]}
      </TextTransition>
    </h1>
  );
};

Props

Prop Type Default Definition
text String REQUIRED The text you want to show.
direction String (enum) 0 Used to determine the direction of the transition "up" or "down" (Must be an all-lowercase string).
inline Boolean false Makes the wrapper inline (will auto resize based on contents).
delay Number 0 Delay the transition of the text (in milliseconds).
springConfig Object { mass: 1, tension: 170, friction: 26 } react-spring's spring configuration.
className String "" Any css classes that you might want to send to the wrapper.
style React.CSSProperties {} Any styles that you might want to send to the wrapper.
children React.ReactNode REQUIRED The react node to be animated

Detailed Props

inline Boolean

Will simply make the wrapper an inline element and animate its width based on currently showing text, this is useful if you want to show some other static text on the same line.

delay Number

The amount of miliseconds to wait before transitioning.

spring Object

react-spring's Spring configuration (Refer to the configs section) react-spring's spring presets are exposed as presets.

  import TextTransition, { presets } from "react-text-transition";

  // in your render method
  <TextTransition springConfig={presets.wobbly}>
    {this.state.text}
  </TextTransition>

There're 4 presets

  • default The default.
  • gentle
  • wobbly
  • stiff
  • slow
  • molasses

className String

Any css classes that you might want to provide to the wrapper.

style React.CSSProperties

Any css styles that you might want to provide to the wrapper.

NOTE

Feel free to ask any questions about using this component. This plugin requires react +16.8

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.