1.0.0 • Published 3 years ago

use-typical v1.0.0

Weekly downloads
24
License
MIT
Repository
github
Last release
3 years ago

Getting Started

Animated typing in ~2.6 kb 🐡 with React Hook.

npm npm dumi License jsdelivr

Live Demo ✨ https://use-typical.vercel.app

📦 Install

yarn add use-typical

Or you can:

npm install use-typical

🚀 Usage

You can create typing animate effects by the react hook useTypical

import React from 'react';
import useTypical from 'use-typical';

export default () => {
  const ref = useTypical({
    steps: ['Hello', 1000, 'Hello world!', 500],
    loop: Infinity,
    speed: 60,
  });

  return <p ref={ref}></p>;
};

To display the blink effects, you can add the classname typingWrapper on the dom.

-<p ref={ref}></p>
+<p ref={ref} className="typingWrapper"></p>

Such as a blink cursor style like this.

.typingWrapper::after {
  content: '|';
  animation: blink 1s infinite step-start;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

📔 API

Hook

const ref = useTypical(options: Options);

Result

ParamsDescriptionType
refThe ref of typical text wraperReact.RefObject<HTMLDocument>

Options

ParamsDescriptionTypeDefault
stepsStep array assign to the typingArray<string, number, Function>-
loopThe number of loop typing animation effect, Infinitynumber1
speedThe speed of typing animation effectnumber60

🔨 Contribute

Install dependencies,

$ npm i

Start the dev server,

$ npm start

Build documentation,

$ npm run docs:build

Build library via father-build,

$ npm run build

License

MIT