Giter Club home page Giter Club logo

tailwindcss-multiple-classes's Introduction

tailwindcss-multiple-classes

Defining several classes at once for one variant


Advantages

  1. options for defining your separator, and brackets
  2. support for nested variants
  3. There is a postCSS plugin to support css files

The problem

  1. With the separator: SPACE. (more precisely in prettier-plugin-tailwindcss)
  2. The problem with auto-completion (is not displayed) (tailwindcss intelliSense)
  3. Strange formatting of user classes - puts all classes at the beginning. But as I realized, this problem is solved tailwindlabs/prettier-plugin-tailwindcss#228

Installation

Installation

Installation depending on the developer

npm install --save-dev tailwindcss-multiple-classes

Creating a function and exporting it:

// transformMultipleClasses.js
import createTransform from 'tailwindcss-multiple-classes';

const transformMultipleClasses = createTransform({ separator: ',', opBracket: '(', clBracket: ')' });

export default transformMultipleClasses;

Adding to the tailwindcss configuration:

//tailwindcss.config.js
import transformMultipleClasses from './src/transformMultipleClasses.js';

const config = {
  content: {
    files: ['./src/**/*.{js,ts,jsx,tsx,mdx}'],
    transform: {
      jsx: (content = '') => transformMultipleClasses(content),
      // You can designate for any file extension
    },
  }

  ...
}

IMPORTANT: This setting is necessary for tailwindcss to understand what classes it needs to generate in a CSS file, but it does not work as a compiler for files. Details: tailwindlabs/tailwindcss#13705 (comment)

Webpack/next.js

  webpack: (config, options) => {
    config.module.rules.push({
      test: /\.jsx/,
      use: path.resolve('./transformMultipleClasses.js'),
    });

    return config;
  },

IMPORTANT: use javascript to support webpack

PostCSS

https://github.com/MrOxMasTer/postcss-tailwindcss-multiple-classes

Demonstration

jsx

Before:

const Main = () => {
	return <main className="flex mm:(bg-red,text-green,hover:(text-3xl))">...</main>;
};

After:

const Main = () => {
	return <main className="flex mm:bg-red mm:text-green mm:hover:text-3xl ">...</main>;
};

css

IMPORTANT: You need to connect the PostCSS plugin

Before:

.class {
	@apply mm:(bg-red,text-green);
}

After:

.class {
	@apply mm:bg-red mm:text-green;
}

tailwindcss-multiple-classes's People

Contributors

mroxmaster avatar

Watchers

 avatar

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.