Open kachkaev opened 1 year ago
I wrote a simple PostCSS plugin as a workaround:
const fixTailwindCSSProperties: postcss.Plugin = {
postcssPlugin: 'fix-tailwindcss-properties',
Once(root) {
root.walkDecls('background', (decl) => {
// Check if the declaration is a single color value
const isColorValue = /^#[0-9A-F]{3,6}$/i.test(decl.value) || /^[a-z]+$/i.test(decl.value);
if (isColorValue) decl.prop = 'background-color';
});
}
};
Current Behavior
In
css-to-tailwindcss@1.0.4
,background: red
converts to""
, whilebackground-color: red
converts to"bg-[red]"
.Expected Behavior
It’d be great if CSS like
background: red
could be mapped to a tailwind class too. I understand that the value ofbackground
shorthand can also contain image URL and its placement. It ca be hard to parse, but even supporting simple cases would be great. In practice, a lot of CSS I have seen is usingbackground: color
shorthand.Environment
css-to-tailwindcss@1.0.4
PS: Great lib @Jackardios! Thanks for working on it 🙌