npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@layerframers/react-text-split

v1.0.6

Published

React Text Split ================

Downloads

5

Readme

React Text Split

DO NOT USE. SEE https://www.npmjs.com/package/@squib/react-split

Provides a set of React components to split a text string up for easy CSS styling

Install

Global

Include /dist/ReactTextSplit.js or /dist/ReactTextSplit.min.js in your html

The global variable ReactTextSplit is available for use.

NPM

yarn add @layerframers/react-text-split

  import TextSplit from 'react-text-split';
  import WordTextSplit from 'react-text-split';
  import LetterTextSplit from 'react-text-split';
  import RotateTextSplit from 'react-text-split';

Usage

Each component has 2 props:

text - the text to split/render
classBase - the base for each of the written classes, default 'text-split'

Each component renders in the following format (LetterTextSplit):

  <span aria-label="some text" className="text-split-base"}>
    <span aria-hidden className="text-split-part part-0">s</span>
    <span aria-hidden className="text-split-part part-1">o</span>
    <span aria-hidden className="text-split-part part-2">m</span>
    <span aria-hidden className="text-split-part part-3">e</span>
    <span aria-hidden className="text-split-part part-4 whitespace text-split-whitespace">&nbsp;</span>
    <span aria-hidden className="text-split-part part-5">t</span>
    <span aria-hidden className="text-split-part part-6">e</span>
    <span aria-hidden className="text-split-part part-7">x</span>
    <span aria-hidden className="text-split-part part-8">t</span>
  </span>

This allows per-part styling via css:

    // don't show anything for whitespace characters
    .example-part.whitespace {
      background: none !important;
    }

    // gold background block behind white text
    .text-split-part {
      padding: 10px;
      font-size: 60px;
      display: inline-block;
      background: #ffb500;
      color: #fff;
    }

    // every odd one skew 10 degrees
    .example-part:nth-child(odd) {
      moz-transform: skewY(-10deg);
      -webkit-transform: skewY(-10deg);
      -o-transform: skewY(-10deg);
      -ms-transform: skewY(-10deg);
      transform: skewY(-10deg);
    }

    // every even one skew opposite direction
    // and set orange background with white text
    .example-part:nth-child(even) {
      background: #f15b14;
      color: #fff;
      moz-transform: skewY(10deg);
      -webkit-transform: skewY(10deg);
      -o-transform: skewY(10deg);
      -ms-transform: skewY(10deg);
      transform: skewY(10deg);
    }

This will make a 'folded paper' type effect with the text, and will show gaps where the whitespace is.

Classes

The outer element has an aria-label set to the given text and the class ${classBase}-base

Each split of the text is an element with aria-hidden set and the classes ${classBase}-part and part-${index}. If the element contains only whitespace it also contains the classes ${classBase}-whitespace and whitespace.

All space characters are replaced with &nbsp; to allow full styling of empty tags.

Types

WordTextSplit

Splits around whitespace characters.

e.g. ' some words separated by differing whitespace' => '&nbsp;', 'some', '&nbsp;', 'words', '&nbsp;', 'separated', '&nbsp;&nbsp;', 'by', '&nbsp;&nbsp;', 'differing', '&nbsp;', 'whitespace'

LetterTextSplit

Splits each letter into it's own span

e.g. 'some text' => 's', 'o', 'm', 'e', '&nbsp;', 't', 'e', 'x', 't'

TextSplit

Puts the entire string in a single element, used as a superclass for WordTextSplit and LetterTextSplit and custom components

RotateTextSplit

This is a wrapper around any other kind of TextSplit element that rotates the text shown from an array on a timer (2000ms).

It takes the following props:

values - an array of text values, only 1 string will be shown at a time type - a React component to pass the text and classBase to classBase - passed to the TextSplit element

Example:

<ReactTextSplit.RotateTextSplit text={['some random', 'text strings', 'to rotate']} type={ReactTextSplit.WordTextSplit} />

Will render ['some', ' ', 'random'] then ['text', ' ', 'strings'] and finally ['to', ' ', 'rotate'] before starting again

Customization

You can create your own splits by extending the TextSplit component and overriding the splitText function:

  var Custom = ReactTextSplit.TextSplit;
  Custom.prototype = ReactTextSplit.TextSplit.prototype;
  
  Custom.prototype.splitText = function() {
    return this.props.text.split(/(t)/);
  };

This splits around and keeps the 't' character like this: 'React Text Split Example' => 'Reac', 't', ' ', 'T', 'ex', 't', ' Spli', 't', ' Example'

Example

An example can be found in the examples folder showing each component + a sample overridden component