Socket
Book a DemoInstallSign in
Socket

react-conversational-text

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-conversational-text

Text that prints as if typed by a person

latest
Source
npmnpm
Version
1.1.10
Version published
Maintainers
1
Created
Source

A React component that prints messages one character at a time, as if typed by a person.

Demo gif

Installation

npm i react-conversational-text

Usage

Import and use the ConversationalText component, passing in the list of strings you want printed, along with optional props.

import ConversationalText from "react-conversational-text";
import "./App.css";

function App() {
  return (
    <div>
      <ConversationalText
        messages={[
          "This is the first message.",
          "However, this is the second message.",
        ]}
      />
    </div>
  );
}

export default App;

Props

  • messages (string[]): The list of strings you want to be printed.

Each of the following props is optional and can be used to customize the behavior of the ConversationalText component.

  • delayBetweenCharactersMs (number): The delay in milliseconds between each character. Default is 40ms.
  • delayAfterCommaMs (number): Additional delay in milliseconds after a comma is printed. Default is 500ms.
  • delayAfterSentenceMs (number): Additional delay in milliseconds after a sentence-ending punctuation (., !, ?) is printed. Default is 500ms.
  • delayBetweenMessageMs (number): The delay in milliseconds before starting to print the next message. Default is 1000ms.
  • addSpaceBetweenMessages (boolean): If true, adds a space between messages. Default is true.
  • lineBreakBetweenMessages (boolean): If true, adds a line break between messages. Default is false.
  • onMessageComplete (function): A callback function that is called when each input message is completed. The function receives the index of the completed message as a parameter. Example: onMessageComplete={(messageIndex) => { /* handle completion of message */ }}
  • onAllMessagesComplete (function): A callback function that is called when all messages have been completed. This function does not receive any parameters. Example: onAllMessagesComplete={() => { /* handle completion of all messages */ }}
  • style (CSSProperties): Custom CSS styles to apply to the span containing the messages. This is an object that can contain any valid CSS property.

Example Usage

To see an example react app using this package, check out this repository.

Issues and Feature Requests

To report a problem or make a feature request, add a GitHub 'issue' here.

Keywords

react

FAQs

Package last updated on 02 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts