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

reactjs-typewriter-effect

v1.2.0

Published

A React typewriter component with multiple words and customization options

Downloads

263

Readme

React js Typewriter Effect

A versatile React component that dynamically displays text, simulating a typewriter effect. Users can customize the typing speed, deletion speed, pause duration between words, and the overall looping behavior. The component also supports custom styling for specific portions of text and provides options for many other CSS properties with custom classes.

Features

  • Types out words character by character
  • Deletes words character by character
  • Customizable typing, deleting, and pause intervals
  • Option to loop through words or stop at the end
  • Pauses on hover
  • Supports custom styling for specific portions of text
  • Customizable font name, size, weight, color, and text shadow
  • Customizable cursor style
  • Allows setting custom CSS classes for additional styling
  • Automatically loads custom fonts from Google Fonts when specified

Installation

You can install React jsTypewriter Effect with just one command and you're good to go


# with npm
npm i reactjs-typewriter-effect

# with yarn
yarn add reactjs-typewriter-effect

Word Object Structure

Each object in the words array should have the following structure:

{
  text: string,
  styles: [
    {
      start: number,
      end: number,
      ...cssProperties
    },
    // ... more style objects
  ]
}
  • text: The string to be typed.
  • styles: An array of style objects, each defining a styled section of the text.
  • start: The starting index of the styled section.
  • end: The ending index of the styled section.
  • ...cssProperties: Any valid CSS properties to apply to the styled section.

Usage

Import the component where you want to use it:

import React from "react";
import Typewriter from "reactjs-typewriter-effect";

const ComponentName = () => {
  return (
    <div>
      <h1>Welcome to tutorial of reactjs-typewriter-effect</h1>
      <Typewriter
        words={[
          { text: "Welcome to my portfolio!", styles: [] },
          {
            text: "I'm a full-stack developer",
            styles: [{ start: 6, end: 24, color: "blue", fontWeight: "bold" }],
          },
          {
            text: "Specializing in React and Node.js",
            styles: [
              { start: 16, end: 21, color: "cyan" },
              { start: 26, end: 33, color: "green" },
            ],
          },
        ]}
        typingInterval={150}
        deletingInterval={100}
        pauseTime={200}
        loop={true}
        color="blue"
        cursorStyle="_"
        fontName="Roboto"
        fontSize="24px"
        fontWeight={600}
        textShadow="2px 2px 4px rgba(0,0,0,0.3)"
        lineHeight="1.5"
        customClass="opacity"
      />
    </div>
  );
};

export default ComponentName;

This example will create a typewriter effect that cycles through three phrases, with custom styling applied to specific words or sections.

Props

| Prop | Type | Default | Description | | ------------------ | ---------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | words | Array of Objects | Required | An array of word objects to be typed. Each object should have a text property (string) and a styles property (array of style objects). | | typingInterval | Number | 150 | The interval (in milliseconds) between typing each character. | | deletingInterval | Number | 50 | The interval (in milliseconds) between deleting each character. | | pauseTime | Number | 100 | The time (in milliseconds) to pause after completing a word before starting to delete it. | | loop | Boolean | true | Whether to loop through the words array continuously. | | color | String | 'inherit' | The default text color for the typewriter text. | | cursorStyle | String | '|' | The character or string to use as the cursor. | | fontName | String | undefined | The name of the font to use for the typewriter text. If provided, it will be loaded from Google Fonts. | | fontSize | String | undefined | The font size for the typewriter text. | | fontWeight | String or Number | undefined | The font weight for the typewriter text. | | textShadow | String | undefined | The text shadow CSS property for the typewriter text. | | lineHeight | String or Number | undefined | The line height for the typewriter text. | | customClass | String | undefined | A custom CSS class to apply to the typewriter component. |

Behavior

  • The component will type out each word in the words array.
  • After typing a word, it will pause for the duration specified by pauseTime.
  • It will then delete the word character by character.
  • If loop is true, it will move to the next word and repeat the process.
  • If loop is false, it will stop after typing and deleting the last word, displaying the first word in the array.
  • The animation pauses when the user hovers over the text and resumes when the mouse leaves.

Customization

You can customize the appearance and behavior of the Typewriter component by adjusting the props. Experiment with different values for typingInterval, deletingInterval, pauseTime, fontName, fontSize, fontWeight and many other CSS properties as shown above to achieve the desired effect.