1.4.1 • Published 7 months ago

@zure/tw-style-merge v1.4.1

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

TwStyleMerge

TwStyleMerge is a Tailwind CSS plugin that simplifies the creation of reusable CSS classes directly in the tailwind.config.js file. By defining multiple properties for your classes, this plugin eliminates the need for @apply directives, streamlining your styling process and enhancing maintainability.


🛠️ Features

  • Custom Utility Classes: Define utility classes based on your Tailwind theme.
  • Variable Support: Reference existing styles defined in your tailwind.config.js file.
  • Custom Prefix: Add a unique prefix to your generated classes.

🚀 Installation

You can install the plugin using one of the following methods:

Using npm

npm install @zure/tw-style-merge

Using Yarn

yarn add @zure/tw-style-merge

Using pnpm

pnpm add @zure/tw-style-merge

⚙️ Configuration

Add the plugin to your tailwind.config.js file and define custom styles under the tw-style-merge theme key:

// tailwind.config.js
const twStyleMerge = require('@zure/tw-style-merge');

module.exports = {
  plugins: [
    twStyleMerge()
  ],
  theme: {
    "tw-style-merge": {
      "heading-1": {
        "fontFamily": "Arial",
        "color": "#000000"
      }
    }
  },
};

Note: This configuration works within theme.extend as well.

Plugin Typing in tailwind.config.js

To add typing support, use the following JSDoc Type Annotation:

/** @type {import('@zure/tw-style-merge').TwStyleMerge} */
const twStyleMerge = require('@zure/tw-style-merge');

module.exports = {
  plugins: [
    twStyleMerge()
  ],
  theme: {
    /** @type {import('@zure/tw-style-merge').TwStyleMergeNode} */
    "tw-style-merge": {
      // ...
    }
  },
};

💡 Usage

Once configured, use the generated classes in your HTML:

<h1 class="heading-1">Main heading</h1>

If you're using Tailwind CSS IntelliSense, IntelliSense will detect and suggest the configured classes seamlessly.


🔧 Advanced Options

Adding a Custom Prefix

To prefix your custom classes, configure the plugin as follows:

// tailwind.config.js
module.exports = {
  plugins: [
    twStyleMerge({ prefix: 'my-prefix' })
  ],
};

Usage:

<h1 class="my-prefix-heading-1">Main heading</h1>

Changing the Configuration Node

Customize the default configuration node (tw-style-merge) by specifying a different name:

// tailwind.config.js
module.exports = {
  plugins: [
    twStyleMerge({ node: 'custom-node-name' })
  ],
  theme: {
    "custom-node-name": {
      "heading-1": {
        "fontFamily": "Arial",
        "color": "#000000"
      }
    }
  }
};

📝 Variables Support

Leverage variables to reuse existing properties from your tailwind.config.js file:

// tailwind.config.js
const twStyleMerge = require('@zure/tw-style-merge');

module.exports = {
  plugins: [
    twStyleMerge()
  ],
  theme: {
    colors: {
      primary: {
        dark: "#0000ff"
      }
    },
    "tw-style-merge": {
      "heading-1": {
        "fontFamily": "Arial",
        "color": "$primary.dark"
      }
    }
  }
};

Variable Mapping

The plugin intelligently maps variables to their respective theme sections. For example:

Tailwind themeCSS Property
colorscolor
spacingwidth, height, padding, paddingLeft, paddingRight, paddingTop, paddingBottom, margin, marginLeft, marginRight, marginTop, marginBottom, maxWidth, maxHeight, minWidth, minHeight
gapgap
fontFamilyfontFamily
fontSizefontSize
fontWeightfontWeight
borderRadiusborderRadius
boxShadowboxShadow
opacityopacity
zIndexzIndex
lineHeightlineHeight
letterSpacingletterSpacing
maxWidthmaxWidth
maxHeightmaxHeight
minWidthminWidth
minHeightminHeight
transitionDurationtransitionDuration
textDecorationColortextDecorationColor
textDecorationThicknesstextDecorationThickness
textUnderlineOffsettextUnderlineOffset
backgroundColorbackgroundColor
borderColorborderColor
borderWidthborderWidth
transformOrigintransformOrigin
animationanimation
transitionPropertytransitionProperty
transitionTimingFunctiontransitionTimingFunction
transitionDelaytransitionDelay

🤝 Contributing

Contributions are welcome! Feel free to submit issues or pull requests on GitHub.


📜 License

Licensed under the MIT License.


🌟 Thanks

Built with ❤️ for developers who value clean and reusable styles. Powered by Tailwind CSS.

1.4.1

7 months ago

1.4.0

7 months ago

1.3.7

7 months ago

1.3.6

7 months ago

1.3.5

7 months ago

1.3.4

7 months ago

1.3.3

7 months ago

1.3.2

7 months ago

1.3.1

7 months ago

1.3.0

7 months ago

1.2.3

7 months ago

1.2.2

7 months ago

1.2.1

7 months ago

1.2.0

7 months ago