Giter Club home page Giter Club logo

react-split-text's Introduction

Demo

CI npm bundle size

Documentation

This component lets you split your text, and wrap each line, word or letter with a custom element. The lines and words are correctly split according to how they fit in the layout. The component doesn't change that behavior, it just analyses the text and wrap each line, word and letter in a custom element. This lib is useful when trying to make text animations or special effects with texts.

Features

  • Zero-dependency 1.44 KB minified and gzipped
  • Wrap your letters, words or lines with custom elements
  • Respect and keep your layout integrity
  • Readjust on resize
  • Support dynamic text

Installation

npm i @cyriacbr/react-split-text
# or
yarn add @cyriacbr/react-split-text

Usage

To use this library, simply wrap your text with the SplitText component. The text will automatically be wrapped, by default with span elements, and will be readjusted on resize.

<SplitText>
  Hello World
</SplitText>

Everything else is covered in the documentation.

react-split-text's People

Contributors

cyriacbr 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

Watchers

 avatar  avatar

react-split-text's Issues

NPM package details mismatched?

Just looking on the NPM page for this package and it seems to be missing the pointer to this git repo and the readme doesn't match what's here. Just mentioning in case you didn't notice.

Repeated rerenders on iOS Safari scroll

On iOS Safari with URL bar at the bottom of the screen (>15.0), the window resizes every time the scroll direction changes, as the URL bar is being minimized or expanded.
This triggers a re render of the SplitText component and the animation is triggered every single time.
Is there a way to prevent those undesired rerenders by filtering vertical resize listening events on iOS devices maybe?

Migrate tests to react-testing-library

I tried to make a fork that fixes #23, and it works just fine but the tests are failing because enzyme does not work with react 18 anymore.
Consider migrating to react-testing-library.

Use italics/bold in text

Hey @CyriacBr, I discovered your library recently and it's very good as Splitting is not very optimized for React and SSR use. The thing is tho, I would like to have some italics or text formatting in my string, and as I understand it, that makes it tricky. I tried to play with some kind of Markdown way to make a text italic, but as the Component splits every character, that simply doesn't work…

The desired effect would be something like that:

image

Any lead?

Page.jsx

<SplitText text={RichText.asText(data.intro_headline)} className="title" mode="lines" />

SplitText.jsx

...

    /*
    ** Lines only
    */
    else if (mode === 'lines') {
        const Lines = ({ text, className }) => {
            return (
                <SplitText className={className}
                    LineWrapper={({ lineIndex, children }) => (
                        <div className="ln" style={{ '--ln-i': lineIndex }}>
                            <div className="ln__inner">
                                {children} // my text in italics would go there, but that contains HTML, so…
                            </div>
                        </div>
                    )}
                    WordWrapper={({ children }) => children}
                    LetterWrapper={({ children }) => {}}
                >
                    {text}
                </SplitText>
            )
        }

        return <Lines text={text} />
    }

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.