A Tailwind CSS plugin that generates accessible, stylish button components using chroma-js. This plugin ensures all buttons meet WCAG 2.1 contrast requirements, supports all basic Tailwind CSS colors, allows for custom colors, and includes styling for all button states using classes and pseudo-classes.
Install the plugin via npm:
npm install tailwind-colorscheme-plugin
pnpm install tailwind-colorscheme-plugin
// tailwind.config.js
module.exports = {
theme: {
// Your existing theme configuration
},
plugins: [
require('tailwind-colorscheme-plugin')({
customColors: {
customBlue: '#1e40af',
customGreen: '#10b981',
// Add more custom colors as needed
},
}),
],
};
<button class="btn-blue">Blue Button</button>
<button class="btn-red">Red Button</button>
<button class="btn-green">Green Button</button>
<button class="btn-customBlue">Custom Blue Button</button>
The plugin includes styling for various button states using pseudo-classes:
&:hover
adjusts the background color for hover effects.&:active
modifies the background color when the button is active.&:focus
adds an outline to improve accessibility and user experience.The plugin uses chroma-js to calculate color contrast ratios, ensuring that all buttons meet or exceed WCAG 2.1 guidelines. This is crucial for creating accessible web applications that are usable by everyone.
You can extend the default color palette by providing custom colors in the plugin options:
require('tailwind-colorscheme-plugin')({
customColors: {
// Define your custom colors here
customPurple: '#6b21a8',
customOrange: '#ea580c',
},
});
These colors can then be used just like the default colors:
<button class="btn-customPurple">Custom Purple Button</button>
<button class="btn-customOrange">Custom Orange Button</button>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Tailwind Button Plugin Example</title>
<link href="path/to/your/output.css" rel="stylesheet">
</head>
<body>
<button class="btn-blue">Blue Button</button>
<button class="btn-red">Red Button</button>
<button class="btn-green">Green Button</button>
<button class="btn-customBlue">Custom Blue Button</button>
<button class="btn-customPurple">Custom Purple Button</button>
</body>
</html>
Contributions are welcome! If you have suggestions or find any issues, please open an issue or submit a pull request on the GitHub repository.
This project is licensed under the MIT License. See the LICENSE file for details.