Giter Site home page Giter Site logo

didof / tailwindcss-color-shades Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 113 KB

TailwindCSS plugin to generate shades of any given colors.

JavaScript 34.82% HTML 3.98% CSS 61.20%
tailwind color-palette color-palette-generator tailwind-css tailwind-plugin

tailwindcss-color-shades's Introduction

Color Shades Plugin for Tailwind CSS

The issue

When in tailwind.config.js you extend the color palette the shades related to each added color will not be automatically generated. It is up to you to use some online generator get the variants and manually copy and paste them into your configuration.

The plugin

This plugin aims to automate the generation of shades. Once you activate it you just need to add a shades object configuration in the theme. The syntax is the same as you're used to for extending the color palette.

const colorShades = require('tailwindcss-color-shades');

module.exports = {
    content: ["./src/**/*.html"],
    theme: {
        shades: {
            ferrari: '#ed1c24'
        }
    },
    plugins: [
        colorShades()
    ],
};

That's all you need to start using classes sich as bg-ferrari-200 and text-ferrari-800 without any other effort!

The official extension Tailwind CSS IntelliSense will detect and suggest all of them!

The plugin will generate for each input color all combinations between one of the property identifiers, the color name and all the levels.

`${propertyIdentifier}-${colorName}-${level}`

The property identifiers are bg, text, border, border-t, border-r, border-b, border-l, outline, ring, ring-offset, shadow, accent, caret, fill, stroke.

The levels are 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, DEFAULT.

Options

It is possible to configure the plugin behaviour via some options.

Prefix

In some cases you might want to keep it explicit that the class in use is generated by this plugin. The prefix option comes to your aid.

By default (null) no prefix is used.

module.exports = {
    ...
    plugins: [
        colorShades({
            prefix: 's',
        })
    ],
};

The above example results in all generated classes being prefixed with 's' (e.g. s-bg-ferrari-700).

Levels

The option levels gets as value a list of levels. The plugin will generate combinations only of those indicated. Any value not recognized will be ignored.

By default all levels are used.

The level relative to 500 and DEFAULT are always produced.

module.exports = {
    ...
    plugins: [
        colorShades({
            levels: [100, 500, 700]
        })
    ],
};

In the above example you can use shadow-ferrari-100 but not shadow-ferrari-300.

A note

The plugin registers the generated classes via the addUtilities function. This implies that should the input color name match one that is part of tailwindcss's default color palette, the generated css will have two rules. An example follows.

const colorShades = require('tailwindcss-color-shades');

module.exports = {
    content: ["./src/*.html"],
    theme: {
        shades: {
            red: '#ff0000' // red already exists in require('tailwindcss/colors')
        }
    },
    plugins: [
        colorShades()
    ],
};

Ensure to use it in HTML to prevent purging.

<div class="bg-red">42</div>

The extension Tailwind CSS IntelliSense will notify you that two rules exists for bg-red.

VS Code autocompletion showing two rules for bg-red class

But in the style.css produced by tailwindcss you can observe that the default one and the generated one are merged together.

.bg-red {
  --tw-bg-opacity: 1;                                       /* default */
  background-color: rgb(255 0 0 / var(--tw-bg-opacity));    /* default */
  background-color: #ff0000;                                /* generated */
}

Since the generated ones are added via addUtilities they are positioned after.Since how CSS works, that means they take precedence over any pre-existing homonyms.

In general, it is suggested not to clash names ๐Ÿ™‚

tailwindcss-color-shades's People

Contributors

didof avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

tailwindcss-color-shades's Issues

Publish on NPM?

Can you make this package available on NPM? I'd like to use it via Skypack

Much thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.