Giter Site home page Giter Site logo

adrianmcli / react-reveal-text Goto Github PK

View Code? Open in Web Editor NEW
186.0 3.0 14.0 1.91 MB

✨ A small react library for animating the revealing of text.

Home Page: https://adrianmcli.github.io/react-reveal-text/

JavaScript 98.78% CSS 1.22%
react reactjs transition javascript style effect animation text-animation

react-reveal-text's Introduction

React Reveal Text

npm dependencies travis bithound license

A small react library for animating the revealing of text.

gif animation

The demo page was built with React Storybook.

Features 🎉

  • Simple – Just plain ol' CSS transition animations.
  • Zero dependencies – Keeping it light and lit up!
  • Flexible – Choose your own easing function and timing.
  • Customizable – Customize and theme like a regular div.
  • Dynamic – Intelligent generation of random transition delay numbers.

Getting Started

  1. Install:
npm install --save react-reveal-text
  1. Use:
<ReactRevealText>WELCOME!</ReactRevealText>

API

Interactive docs with live-editable props here.

This component has many props that you can manipulate; below is a list of all of them.

Note that the component only re-renders when the show property has been changed.

Basic Properties

  • text (string)
    You can set the text either by passing in text as children or by using the text property.

  • show (boolean)
    This prop allows you to control what state the component is in. It allows you to hide or reveal the text.

  • className (string)
    This prop allows you to set the className for the div surrounding the text.

  • style (object)
    This prop allows you to pass in styles for the div surrounding the text.

Transition Properties

Each letter has its own randomly generated delay before its transition begins.

  • transitionTime (integer) [default: 1300]
    The time it takes for each letter's transition.

  • timingFunction (string) [default: 'linear']
    The CSS transition-timing-function property. On this page, you are given a dropdown selection, but in practice (and in the sandbox), you can enter in any valid string.

  • delayMin (integer) [default: 200]
    The minimum allowable delay before the transition for a letter is to begin.

  • delayMax (integer) [default: 1200]
    The maximum allowable delay before the transition for a letter is to begin.

  • threshold (float) [default: 0.2]
    The difference between the random numbers generated for each letter compared to the previous letter. Setting this higher will force the delays to be very different between each letter, spreading out the effect. Setting this lower will allow delays to be similar between letters, sometimes creating a chunking effect.

Contributing

This project was built using my two other tools: React Build Lib and React Build Dist. These tools are still very early in development, so if you are building these libraries, you may encounter some bugs. PRs and issues are welcomed and encouraged! Should probably add some testing too.

react-reveal-text's People

Contributors

adrianmcli avatar

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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-reveal-text's Issues

Height is collapsed until render

Hey there @adrianmcli ! First off, awesome job on this little library. I'm loving it!

I did have one question that I'm hoping you can shed some light on:

  1. I'm using the CharacterReveal in a Gatsby-powered site.
  2. The animation (canPlay) is triggered via state, which is subsequently set through a useEffect after a short delay.

However, I'm noticing on my production server that there is a small "jump" where before the reveal element is built there is nothing visible, collapsing my page height briefly until react-reveal-text renders to the page:

jump-reveal

Here's a live version for you to preview as well: https://the-fold-web.netlify.app/

And here's my code for the react-reveal-text component:

<CharacterReveal
  animateOpacity
  canPlay={isRevealed}
  characterOffsetDelay={60} // ms
  characterWordSpacing={'.25em'}
  copy={[
    'A collection of',
    'cutting edge homes',
    'in the heart of Shaw'
  ]}
  direction={'bottom'}
  duration={600} // ms
  ease={
    'cubic-bezier(0.5848375451263538,-0.003374999999999906,0.16606498194945848,1.012625)'
  }
  offset={'1em'}
  multilineMasking
  multilineOffsetDelay={350} // ms
/>

Let me know what you think, happy to provide more info if needed ✌️

Animations not properly applied when updating text

Heya!

First off! Awesome job with this component!

Is there a way to fix this issue however: whenever I fade out the text, updating the components children (or text), and reveal the text again, it seems like if the new word is longer than the previous, the animations are not being applied

Here is an image of it looks like:

screen shot 2018-02-01 at 14 00 44

And here is the code:

`
import React, {
Component
} from 'react'

import ReactDOM from 'react-dom'

import View from '../view/index.js'

import {
projectCopy
} from './projectCopy.js'

import {
TweenLite
} from 'gsap'

import ReactRevealText from 'react-reveal-text'

export default class Projects extends View {

constructor(props) {

    super(props)

    this.initProjectCopy()

    this.state = {

        index: 0,

        isInteracting: false,

        revealCopy: true,

    }

}

componentDidMount() {

    this.initEvents()

}

componentWillUnmount() {

    this.removeEvents()

}

initProjectCopy() {

    this.projectCopy = projectCopy

}

initEvents() {

    window.addEventListener('mousewheel', this.loadProject.bind(this))

}

removeEvents() {

    window.removeEventListener('mousehwheel', this.loadProject.bind(this))

}

loadProject(e) {

    if (this.state.isInteracting === false) {

        this.setState(() => {
            
            return {isInteracting: true}
        
        })

        TweenLite.to(this, 3.0, {

            onStart: () => {

                this.setState({revealCopy: false})

            },

            onUpdate: () => {

                e.preventDefault()

            },

            onComplete: () => {

                this.setState({title: ' '})

                if (e.deltaY > 0) {

                    this.setState((prevState) => {

                        return {index: prevState.index += (this.state.index < this.projectCopy.length - 1) ? 1 : 0}

                    })

                } else {

                    this.setState((prevState) => {

                        return {index: prevState.index - (this.state.index > 0) ? 1 : 0}

                    })

                }

                this.refs['titleContainer'].props = {text: this.projectCopy[this.state.index].title}

                this.setState({revealCopy: true})

                this.setState({isInteracting: false})

            }

        })

    }

}

render() {
    
    return(

        <div className = "Project" ref = "projectContainer">

            <ReactRevealText className = "Title" ref = "titleContainer" show = {this.state.revealCopy} text = {this.projectCopy[this.state.index].title}/>
            
            <ReactRevealText className = "Description" ref = "descContainer" show = {this.state.revealCopy} text = {this.projectCopy[this.state.index].description}/>
            
            <ReactRevealText className = "Tech" ref = "techContainer" show = {this.state.revealCopy} text = {this.projectCopy[this.state.index].tech}/>

        </div>

    )

}

}

`

Improve README

See here for an example of a good, comprehensive, and well-designed README: https://github.com/clauderic/react-infinite-calendar

GitHub Short Description

  • A short informative sentence for link previews
  • Use an emoji in the description to get people's attention
  • Add a link to a demo page

README.md

  • Have a nice logo
  • Have an awesome image/animated gif
  • Title of your project in plain Capitalized English
  • Short description and link to demo page
Badges from Shields.io
  • NPM version
  • Build status (Travis/Circle CI)
  • Dependencies
  • Code quality (Bithound or similar)
  • Code coverage
  • License
Features
  • Use an emoji
  • Have at least 4 or 5 features
  • Keep the focus on simplicity, lightness (e.g. zero-dependency), and ease-of-use
Other Sections
  • Getting Started or Installation + Usage
  • API
  • Contributing guidelines

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.