Currently TailwindCSS only offers opacity at the element level, not the attribute level.
This plugin provides granular, or optionally basic control over RGBA/"opacity" at the attribute level to complement your TailwindCSS theme('colors')
.
The optional basic control uses theme('opacity')
values.
Simple option to generate RGBA attributes based solely on theme('colors')
and theme('opacity')
Granular control through config so that your generated file doesn't explode with unused classes
pluginConfig.opacities: number[]
pluginConfig.variants: string[]
pluginConfig.excludedAttributes: string[]
Handles theme('colors')
recursively
RGBA available on all color defining CSS attributes
color
, Prefix: text
backgroundColor
, Prefix: bg
borderColor
, Prefix: border
borderTopColor
, Prefix: border-t
borderRightColor
, Prefix: border-r
borderBottomColor
, Prefix: border-b
borderLeftColor
, Prefix: border-l
stroke
, Prefix: stroke
fill
, Prefix: fill
Unreleased 3.0.0 Color specific control for super granularity.
excludedAttributes
property on config object is optional. View examples below to see potential usage.deepControl
property on config object is optional. View examples below to see potential usage.npm i --save tailwindcss-opacity
.text-blue-100
text
= color attributeblue
= theme('colors')
, { colors: { blue: '#XXXXXX' } }
100
= 0.1 opacity.border-blue-1-450
border
= border-color attribute1-blue
= theme('colors')
, { colors: { blue: { 1: '#XXXXXX' } } }
450
= 0.45 opacity.bg-light-blue-200
bg
= background-color attributelight-blue
= theme('colors')
, { colors: { light: { blue: '#XXXXXX' } } }
200
= 0.2 opacity.text-yellow-850 {
color: rgba(..., 0.85);
}
.border-r-yellow-200 {
background-color: rgba(..., 0.2);
}
.bg-yellow-400 {
background-color: rgba(..., 0.4);
}
.text-red-0-850 {
color: rgba(..., 0.85);
}
.text-red-3-850 {
color: rgba(..., 0.85);
}
.bg-red-4-400 {
background-color: rgba(..., 0.4);
}
.text-green-0-850 {
color: rgba(..., 0.85);
}
.bg-blue-4-650 {
background-color: rgba(..., 0.65);
}
config: {
...
colors: {
[colorKey: string | number]: string
},
opacity?: number[] // Optional for simple generation
...
}
pluginConfig?: { // Alternative config for granular control
opacities?: number[]
variants?: string[]
excludedAttributes?: string[]
}
/**
* Only use theme('colors') and theme('opacity')
*/
{
plugins: [require('tailwindcss-opacity')()]
}
/**
* Config for more granular control
*/
{
plugins: [
require('tailwindcss-opacity')({
opacities: [0.1, 0.2, 0.4, 0.65, 0.85], // Opacities applied to theme('colors')
variants: ['hover', 'active', 'disabled'], // Variants to apply opacities to
excludedAttributes: ['borderColor'], // Exclude borderColor from generation
}),
]
}
1.0.0
Npm Module, Open Source, published2.0.0
Integrate Typescript2.0.0
Add excludable attributes2.0.1
Example generated classNames added to readme2.0.1
Beginning unit testing with Jest and Typescript2.0.2
Completed unit tests for utils.ts2.1.1
Added simple generation based on theme('opacity')
as an option