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

tailwindcss-base-buttons

v1.0.1

Published

A base button styling for Tailwind Css

Downloads

324

Readme

Tailwind CSS Base Buttons

This plugin adds a bunch of base button classes in your Tailwindcss components which can be customized based on your theme colors.

Demo & Documentation

Install

  1. Install the plugin:
npm install tailwindcss-base-buttons --save-dev
  1. Add it inside your tailwind.config.js file:
module.exports = {
    // ...
    plugins: [
        require('tailwindcss-base-buttons')()
    ]
}

Documentation

Out of the box, the plugin will generate these classes for styling your buttons.

  • btn-{color} - Colors are the default Tailwind colors. Ex: btn-indigo.
  • btn-{theme} - These classes are theme based colors. Ex: btn-primary. Other options are secondary, danger, default & disabled.
  • btn-outlined-{color|theme} - These are outlined button based on default and theme colors. Ex: btn-outlined-primary or btn-outlined-red.
  • btn-outlined-alt-{color|theme} - Same as outlined button but with solid backround on hover.
  • btn-gradient-{color|theme} -These are gradient buttons based on default and theme colors. Ex: btn-gradient-primary or btn-gradient-pink.
  • btn-{size} - These are button size classes. Ex: btn-xs. Other options are sm,md(default), lg,xl,
  • btn-rounded - These makes rounded buttons

Customization

The appearance of the button can be customized by passing an option object as a first argument of the plugin. Ex:

module.exports = {
    // ...
    plugins: [
        require('tailwindcss-base-buttons')({
            baseClass: '.button',
            borderRadius: '.5rem',
            padding: '.5rem 1rem',
            colors: {
                theme: {
                    primary: {
                        background: red,
                        text: white
                    },
                    secondary: {
                        background: blue,
                        text: black
                    }
                }
            }
        })
    ]
}

The example above will generate classes like .button-* with border-radius .5rem and padding .5rem 1rem. The theme colors generated would be .button-primary & .button-secondary.

You can also add your custom button styles by adding an object or a callback that generates your button style object as a second argument. Ex: using an object. This adds the .btn-sample class

module.exports = {
    // ...
    plugins: [
        require('tailwindcss-base-buttons')({
            baseClass: '.btn'
        },{
            '.btn-sample': {
                color: 'red',
                width: '200px'
            }
        })
    ]
}

Ex: using a callback. By using a callback, you can access the colorConfig and options which contains the default and theme colors and the options. This will add .btn-sample-{color|theme} classes.

    module.exports = {
    // ...
    plugins: [
        require('tailwindcss-base-buttons')({
            baseClass: '.btn'
        },(colorConfig, options) => {

            let additionalStyles = {};

            Object.entries(colorConfig, config => {

                let [key, properties] = config;

                Object.assign(additionalStyles, {
                    [`${options.baseClass}-sample-${key}`]: {
                        backgroundColor: properties['background'],
                        width: '200px'
                    }
                })
            });

            return additionalStyles;
        })
    ]
}