Replies: 4 comments 6 replies
-
Hey! Check out the documentation on this here: https://tailwindcss.com/docs/content-configuration#dynamic-class-names |
Beta Was this translation helpful? Give feedback.
-
Hey @adamwathan , I read that article before opening this as an issue. I would think what we're doing here satisfies the constraint of generating a static string. We are using an object with a number of arbitrary color values the client wants for different svg icons which is why we aren't building them in to the theme. They are defined like this as a static object: export const allDocTypes = {
xls: {
type: "application/vnd.ms-excel",
primaryColor: "#01A63E",
secondaryColor: "#E8F6ED"
}
} Our code determines file extension in a computed function then returns a static string to the class attribute on the div like in the example I shared. const getFileClasses = computed(() => (fileName) => {
const extension = fileName.split(".").pop().toLowerCase();
const classes = allDocTypes[extension] || allDocTypes["default"];
return {
primaryColor: `fill-[${classes.primaryColor}]`,
secondaryColor: `bg-[${classes.secondaryColor}]`,
};
}); So the computed function returns Is there a way to have tailwind determine which classes to purge/build post-build/post-component render so all final class names are established before tailwind decides what to purge/build itself? This is Nuxt3/Vue3 that we're working in. |
Beta Was this translation helpful? Give feedback.
-
@wmelton You can achieve that with binding inline styles instead of binding HTML classes, using Objects:
See the docs: https://vuejs.org/guide/essentials/class-and-style.html#binding-to-objects-1 |
Beta Was this translation helpful? Give feedback.
-
Why Tailwind understand this: :class="[`bg-[url('/auth/mask-bg.png')] bg-no-repeat bg-top bg-cover`]" but not understand this: :class="['bg-[url(\'/auth/mask-bg.png\')] bg-no-repeat bg-top bg-cover']" ? |
Beta Was this translation helpful? Give feedback.
-
What version of Tailwind CSS are you using?
For example: v3.4.1
What build tool (or framework if it abstracts the build tool) are you using?
For example: postcss-cli 8.3.1, Next.js 10.0.9, webpack 5.28.0
Nuxt @3.9.0
What version of Node.js are you using?
v20.9.90
What browser are you using?
Chrome
What operating system are you using?
macOS
Reproduction URL
[A Tailwind Play link or public GitHub repo that includes a minimal reproduction of the bug. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn't matter if your real project is private/confidential, since we want a link to a separate, isolated reproduction anyways.
A reproduction is required when filing an issue — any issue opened without a reproduction will be closed and you'll be asked to create a new issue that includes a reproduction. We're a small team and we can't keep up with the volume of issues we receive if we need to reproduce each issue from scratch ourselves.](https://gist.github.com/wmelton/cea356e2d4fd6364afe15f10eb98fe23)
Describe your issue
When generating arbitrary values for a table that loads file names dynamically on the fly, we return a string from a computed function that is a valid arbitrary color tailwind class. However, the class color is never rendered. We suspect it is being purged but there is no effective way to debug this we have discovered. If we manually enter the computed class (eg. fill-[#f4f4f4]) then it works as expected. Using a computed function like this it does not though.
Beta Was this translation helpful? Give feedback.
All reactions