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

react-typist-component

v1.0.6

Published

A react component lets you create typewriter effect.

Downloads

6,788

Readme

React Typist Component

Create typewriter effect by setting up a component's children directly.

Install

npm install react-typist-component
# or
yarn add react-typist-component

Example

import Typist from 'react-typist-component';

const MyComponent = () => {
  return (
    <Typist typingDelay={100} cursor={<span className='cursor'>|</span>}>
      This is a typo
      <br />
      <Typist.Backspace count={5} />
      <Typist.Delay ms={1500} />
      react component
      <Typist.Paste>
        <div>
          use
          <div>deeper div</div>
        </div>
      </Typist.Paste>
    </Typist>
  );
};

API reference

Typist

export type Delay = number | (() => number);
export type Splitter = (str: string) => string[];
export type TypistProps = {
  children: React.ReactNode;
  typingDelay?: Delay;
  backspaceDelay?: Delay;
  loop?: boolean;
  pause?: boolean;
  startDelay?: number;
  finishDelay?: number;
  onTypingDone?: () => void;
  splitter?: Splitter;
  cursor?: string | React.ReactElement;
  disabled?: boolean;
  restartKey?: any;
};

children

The contents that will be rendered with typewriter effect. It accepts nested elements, so you can easily style your contents.

Note that Typist treats the element whose children is null or undefined as a single token. For example:

const Foo = () => {
  return <div>Foo</div>;
};

// The text "Foo" will be displayed after "123" immediately instead of displayed seperately
const App = () => {
  return (
    <Typist>
      123
      <Foo />
    </Typist>
  );
};

typingDelay

Default: 75

The delay after typing a token. If you pass in a function, Typist will call the function after typing a token and use the return value as the delay.

backspaceDelay

Default: typingDelay

The delay after backspacing a token. If you pass in a function, Typist will call the function after backspacing a token and use the return value as the delay.

loop

Default: false

Typist will automatically restart the typing animation if this value is true.

pause

Default: false

Set to true if you want to pause the typing animation.

startDelay

Default: 0

Typist will wait for this delay before starting the typing animation.

finishDelay

Default: 0

Typist will wait for this delay after finishing the typing animation.

onTypingDone

This function will be called when the typing animation finishes. It will be called before waiting for the timeout with finishDelay.

splitter

Default: (str: string) => str.split('')

Typist will use this function to get tokens from strings. It may be useful when you want to split your string in different way. For example, you can use grapheme-splitter to split string if your string contains emoji.

import GraphemeSplitter from 'grapheme-splitter';

const splitter = (str: string) => {
  return new GraphemeSplitter().splitGraphemes(str);
};

const App = () => {
  return (
    <Typist splitter={splitter}>
      😎🗑🥵⚠😀👍✌👨‍👨‍👧‍👦📏💡🚀🎂😓🎈💕😘
      <Typist.Backspace count={16} />
    </Typist>
  );
};

cursor

Will be inserted after the last typed token.

disabled

Default: false

If this value is true, the result will be displayed immediately without typing animation. It can be useful when you want to display the final result if a user has visited the typing animation.

restartKey

Typist will restart the typing animation whenever restartKey changes.

Typist.Backspace

type Props = {
  count: number;
};

count

The number of tokens that will be backspaced.

Typist.Delay

type Props = {
  ms: number;
};

ms

The duration of the delay in milliseconds.

Typist.Paste

type Props = {
  children: React.ReactNode;
};

children

Children inside this component will be pasted without typewriter effect. Do not wrap another Paste inside this component, otherwise Typist will produce weird behavior.