samuelweckstrom / react-ascii-text

ASCII text art renderer
7 stars 1 forks source link

React ASCII Text

This library provides a React hook to render or animate ASCII text art using Figlet fonts.

DEMO Try the code out on StackBlitz

Installation

npm install react-ascii-text

Usage

Figlet fonts are included in the package and can be imported. Full list of fonts along with UI to try them out can be found here.

Note that the font names are converted to camelCasing, omitting spaces and hyphens to allow use as ES modules. This is to allow dynamic import of font and bundlers to only include the desired one in your project code.

Font name Import
1Row import { oneRow } from 'react-ascii-text
3-D import { threeD } from 'react-ascii-text'
5 Line Oblique import { fiveLineOblique } from 'react-ascii-text'
Big Money-sw import { bigMoneySw } from 'react-ascii-text'

etc.

Render ASCII text

Passing a single string will render the text in a Figlet font.

import { useAsciiText, alligator } from 'react-ascii-text';

function MyComponent() {
  const asciiTextRef = useAsciiText({
    font: alligator,
    text: "Hello, World!",
  });

  return <pre ref={asciiTextRef}></pre>;
}

Animate ASCII text

Pass an array of strings to animate a transition between them.

import { useAsciiText, alligator } from 'react-ascii-text';

function MyComponent() {
  const asciiTextRef = useAsciiText({
    animationCharacters: "▒░█",
    animationCharacterSpacing: 1,
    animationDelay: 2000,
    animationDirection: "down",
    animationInterval: 100,
    animationLoop: true,
    animationSpeed: 30,
    font: alligator,
    text: ["REACT", "ASCII", "TEXT"],
  });

  return <pre ref={asciiTextRef}></pre>;
}

Parameters

License

MIT