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

tailwind-typewriter

v1.0.1

Published

A plugin for Tailwind CSS that generates typewriter style text animations in pure CSS.

Downloads

1,163

Readme

tailwind-typewriter

A plugin for Tailwind CSS that generates typewriter style text animations in pure CSS (no JavaScript required)

Support

This plugin has been tested with Tailwind CSS v3. Previous releases may also work but are not officially supported.

Demo

Demo

Installation

Install the plugin:

# Using npm
npm install tailwind-typewriter

# Using Yarn
yarn add tailwind-typewriter

Then add the plugin to your tailwind.config.js file:

// tailwind.config.js
module.exports = {
    theme: {
        // ...
    },
    plugins: [
        require('tailwind-typewriter')
        // ...
    ]
};

Usage

The quickest, dirtiest way to get started is to insert a <span> with the type-example utility class somewhere in your markup. This will let you verify that everything is working with a built-in example:

<span class="type-example"></span>

Styling

You can style the animation text with the usual Tailwind utilities:

<span class="type-example text-lg text-rose-500"></span>

🗒️ Note: The blinking caret can only be styled using the configuration options below.

Customizing

The above example is essentially useless on its own. In a real world application, you'll probably want to provide your own text etc 😎. If, for example, you want to create an animation that cycles between names of fruit (with a 3 second delay) - you can do the following:

// tailwind.config.js
module.exports = {
    theme: {
        // ...
    },
    plugins: [
        require('tailwind-typewriter')({
            wordsets: {
                fruit: {
                    words: ['apple', 'banana', 'orange', 'pear', 'strawberry'],
                    delay: 3
                }
            }
        })
    ]
};
<span class="type-fruit"></span>

🗒️ Note: The animation is generated in the ::after pseudo-element so it will be appended to any text inserted inside the <span>. This may or may not be desirable depending on your project.

Multiple Animations

You can create multiple animations in a single project. Each animation is called a 'wordset'. Each wordset has a name, a set of words/phrases, and its own configuration options (see the full API below).

// tailwind.config.js
module.exports = {
    theme: {
        // ...
    },
    plugins: [
        require('tailwind-typewriter')({
            wordsets: {
                fruit: {
                    words: ['apple', 'banana', 'orange', 'pear', 'strawberry'],
                    delay: 3
                },
                vegetables: {
                    words: ['carrot', 'celery', 'corn', 'potato'],
                    pauseBetween: 5
                }
            }
        })
    ]
};

A unique class is generated for each set as type-{wordset}. For example, to reference the Vegetables animation instead of Fruit, you would use the following:

<span class="type-vegetables"></span>

Singular Animations

This plugin was originally designed to create animations that cycled through a set of words. Sometimes however, you may need to create a simple effect for a single word or phrase. You probably also want this animation to output in a forwards direction, stopping after the last character.

To do this, choose your phrase, then set repeat and eraseSpeed to 0:

// tailwind.config.js
module.exports = {
    theme: {
        // ...
    },
    plugins: [
        require('tailwind-typewriter')({
            wordsets: {
                fruit: {
                    words: ['Your clever phrase'],
                    repeat: 0,
                    eraseSpeed: 0
                }
            }
        })
    ]
};

A word about performance

Generally speaking, CSS animations are very performant (certainly compared with JavaScript). However, it is worth noting that every letter in a wordset generates a CSS keyframe. This means that if you have a wordset with a large amount of text, this will have some impact on file size and possibly renderer performance. This wont be a problem in most use cases, but in large projects, discretion is strongly advised.

Configuration

wordsets

Currently, this is the only available top-level property. It serves as a wrapper for each wordset grouping. A wordset in essence, is just an object literal with a unique name for the key that contains the necessary configuration options for each animation:

wordsets: {
    fruit: {
        words: ['apple', 'banana', 'orange'],
        // ..
    },
    vegetables: {
        words: ['carrot', 'celery', 'corn'],
        // ...
    }
}

Options

The following options are also available to each individual wordset.

| Option | Description | Accepts | Default | | :------------- | :------------------------------------------------------------------------- | ----------- | ------------------ | | words | A list of words or phrases for each step of the animation. | Array | Built-in Example | | delay | Delays the start of the animation by n seconds. | Number | 1 | | repeat | Repeat the animation n times. -1 for an infinite loop. | Number | -1 | | writeSpeed | Speed per letter during the write phase (n seconds). | Number | 0.3 | | eraseSpeed | Speed per letter during the erase phase (n seconds). 0 to disable. | Number | 0.1 | | pauseBetween | Pause for n seconds between each word. | Number | 4 | | caretColor | Set the color of the caret. | CSS Color | 'currentColor' | | caretWidth | Specify an alternate width for the caret. | CSS Unit | '1px' | | caretSpacing | Space between the last character and the caret. | CSS Unit | '0.1em' | | blinkSpeed | The frequency at which the caret blinks (n seconds). | Number | 0.8 |