1.0.3 • Published 6 months ago

react-typewriter-plus v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

React Typewriter Plus

React Typewriter Plus is a React package that creates a typewriter effect, simulating the process of typing a text string letter by letter. It offers customizable options like typing speed, cursor behavior, and looping, making it flexible for various use cases including plain text, Markdown, and HTML content.

Demo

screenshot

Installation

To install React Typewriter Plus, simply use npm.

npm install react-typewriter-plus

Example Usage:

import { Typewriter, useTypewriter } from "react-typewriter-plus";

// If you don't need math support, you can skip importing the CSS file
import "react-typewriter-plus/dist/assets/style.css";

// Component
<Typewriter
  text="welcome to React Typewriter Plus!"
  speed={10}
  loop={true}
  cursor={true}
  cursorBlinkSpeed={500}
/>;

// Hook
const md = `
This is a markdown text with **bold** and _italic_ text.
**Also supports Math formulas**
$a^2 + b^2 = c^2$
$\\sqrt{3x-1}+(1 + x)^2=\\frac{100}{2}$
$\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)$
`;
const typedText = useTypewriter(md, {
  type: "md",
  speed: 10,
  loop: true,
  cursor: true,
  cursorBlinkSpeed: 500,
});

return typedText;

API

Typewriter Props

PropTypeDefault ValueDescription
textstring-The text that will be typed out.
type'text' | 'md' | 'html'textSpecifies the format of the input text. Use 'text' for plain text, 'md' for Markdown, and 'html' for HTML content.
speednumber100The speed at which the text is typed (in milliseconds).
loopbooleanfalseIf true, the typing effect will repeat.
cursorbooleantrueWhether to display the blinking cursor.
cursorBlinkSpeednumber500The speed of the cursor blinking (in milliseconds).
loadingNodeReact.ReactNode"Generating"The loading text or animation displayed while typing is in progress.

useTypewriter Hook

ArgumentTypeDescription
textstringThe text that will be typed out.
optionsPartial<UseTypewriterOptions>Optional configuration for speed, cursor, loop, etc.

Contributing

If you'd like to contribute to React Typewriter Plus, feel free to fork the repository and submit pull requests. We welcome improvements, bug fixes, and additional features!

License

React Typewriter Plus is open-source software licensed under the MIT License.