Am I using custom classes wrong? #16322
Replies: 3 comments 6 replies
-
See https://tailwindcss.com/docs/theme for how to add custom theme configuration in v4. |
Beta Was this translation helpful? Give feedback.
-
Ditto on this. I'm trying to transition v3 tailwind styles to v4 and there's no mention in theming docs on how to define the colors for |
Beta Was this translation helpful? Give feedback.
-
Ok here's a bit of a weird one along the same lines - is there an expected way to port in this type of declaration, or is it so way out of scope that it was ignored: tailwind.config.js: export default {
content: [
"./src/**/*.{html,js,cjs,mjs,ts,scss}",
"./pkg/**/*.templ",
],
theme: {
extend: {
borderRadius: {
...
},
colors: {
sidebar: {
DEFAULT: "var(--sidebar-background)",
foreground: "var(--sidebar-foreground)",
primary: "var(--sidebar-primary)",
"primary-foreground": "var(--sidebar-primary-foreground)",
accent: "var(--sidebar-accent)",
"accent-foreground": "var(--sidebar-accent-foreground)",
border: "var(--sidebar-border)",
ring: "var(--sidebar-ring)",
},
},
},
},
plugins: [],
} This is also using app.scss: @use "tailwindcss";
@config "../../../tailwind.config.js";
@mixin light-styles {
...
--sidebar-background: hsl(0 0% 98%);
--sidebar-foreground: hsl(240 5.3% 26.1%);
}
@mixin dark-styles {
...
--sidebar-background: hsl(240 5.9% 10%);
--sidebar-foreground: hsl(240 4.8% 95.9%);
}
@theme {
...
@include light-styles;
@include theme-overrides;
}
@layer theme {
:where(.light, .light *) {
@include light-styles;
}
:where(.dark, .dark *) {
@include dark-styles;
}
@media (prefers-color-scheme: dark) {
:where(.system, .system *) {
@include dark-styles;
}
}
}
This is all so that on the page we can use the <div class="flex h-full w-full flex-col bg-sidebar" data-sidebar="sidebar">
...
</div> triggering the following generated css class: .bg-sidebar {
background-color:var(--sidebar-background)
} This is hacky and works now, but doesn't feel right, and I feel like depending on (FYI, this is has a golang/static port of |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
So let's say I have a design that uses many different colors of gray, and I can't remember which gray I use for which component, so instead of remembering
text-gray-200/30
, andtext-gray-600/80
, andtext-gray-900/10
, I would go create a custom class such astext-muted-dark
andtext-muted-darker
.To do that, I would go into the tailwind.config.js file and extend the theme, like so: (ignore the arbitrary classes above, below is a real example)
This would then allow me to use classes like
text-primary-dark
ortext-muted-light
. Is this not the correct way to do this? Because since I've upgraded to v4, all of those custom classes are broken, and if I have to update all of them, it's not going to be a fun task.Since I already know the answer to my question (maybe), what is the correct way to do this?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions