[v4] Custom colors not working #16822
Replies: 3 comments
-
|
I have the same issue. Have you found a solution? |
Beta Was this translation helpful? Give feedback.
-
|
make sure your consumer project (the one importing the library) includes its own Tailwind setup with @import "tailwindcss"; at the top level Iet mw know if it work |
Beta Was this translation helpful? Give feedback.
-
|
Hello! This is a common issue when building component libraries with Tailwind CSS v4. The problem occurs because custom colors defined in your library aren't automatically available in consumer applications. Here's the complete solution: 1. Update Your Library's Tailwind Configuration module.exports = {
content: [
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {
colors: {
brand: {
black: 'hsla(0, 0%, 5%, 1)',
grey: 'hsla(0, 1%, 42%, 1)',
'grey-light': 'hsla(220, 23%, 95%, 1)',
white: 'hsla(0, 0%, 100%, 1)',
'black-alpha': 'hsla(0, 0%, 5%, 0.5)',
'white-alpha': 'hsla(0, 0%, 100%, 0.5)',
'blue-alpha': 'hsla(240, 77%, 95%, 0.5)',
primary: {
900: 'hsla(276, 100%, 25%, 1)',
100: 'hsla(275, 70%, 91%, 1)',
},
green: {
900: 'hsla(89, 100%, 26%, 1)',
100: 'hsla(90, 80%, 90%, 1)',
},
orange: {
900: 'hsla(38, 96%, 45%, 1)',
100: 'hsla(38, 90%, 85%, 1)',
},
red: {
900: 'hsla(339, 85%, 47%, 1)',
100: 'hsla(339, 100%, 94%, 1)',
},
blue: {
900: 'hsla(240, 91%, 31%, 1)',
100: 'hsla(240, 77%, 95%, 1)',
}
}
},
fontFamily: {
albert: ['Albert Sans', 'sans-serif'],
},
borderRadius: {
DEFAULT: '0.6rem',
sm: 'calc(0.6rem - 4px)',
md: 'calc(0.6rem - 2px)',
lg: '0.6rem',
xl: 'calc(0.6rem + 4px)',
}
},
},
plugins: [
require('tailwindcss-animate'),
require('tailwind-scrollbar'),
],
}2. Export CSS from Your Library @import 'tailwindcss';
@import 'tailwindcss/utilities' layer(utilities);
@plugin 'tailwindcss-animate';
@plugin 'tailwind-scrollbar';
@layer base {
* {
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground font-albert;
}
}3. Consumer Application Setup @import "your-component-library/main.css";
@import "tailwindcss";4. Build Configuration Update // vite.config.js
build: {
lib: {
},
rollupOptions: {
external: ["react", "react-dom", "tailwindcss"],
output: {
assetFileNames: (assetInfo) => {
if (assetInfo.name === 'style.css') return 'main.css';
return 'assets/[name][extname]';
},
},
},
}5. For State Variants (Hover, Focus) <button class="bg-brand-primary-900 hover:bg-brand-primary-700 focus:bg-brand-primary-800">
Click me
</button>The key is providing a complete Tailwind configuration from your library that consumer applications can extend, rather than relying solely on CSS custom properties. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We are developing an internal component library using Vite's library mode and encountering the following issues:
main.css:
Vite config (in case its needed):
postcss config:
Beta Was this translation helpful? Give feedback.
All reactions