-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug report: Plugin-added colors not displaying in intellisense pop-up/context window #544
Comments
Can confirm the same issue with a custom buttons plugin I built:
Notice in this screenshot, the built in text-primary decorator shows up, but no decorator for the the usage of The color does show up when rendered, so it's just the decorator that's not picking up the additional styles from the plugin. |
@ripvannwinkler Having some way to preview the styles for a custom class would be cool too, though I think that may deserve its own separate feature request, as custom classes do not currently support color previews (to my knowledge). When color-specific classes like {
theme: {
extend: {
colors: {
aqua: {
50: '#eefdf8',
100: '#cffbeb',
200: '#a0f5da',
300: '#66e9c6',
400: '#31d4ad',
500: '#12b995',
600: '#0a9579',
700: '#0b7763',
800: '#0d5f50',
900: '#0e4e43',
}
}
}
}
} When these colors are added manually to This is essentially what my plugin, tailwind-lerp-colors does. It adds new colors to the Tailwind config at The difference I see in your example is that your classes are not utilities but rather composite classes that combine a number of styles, so they're not actual Tailwind color-specific colors, so Intellisense doesn't by nature show any color previews for them BUT your classes should still appear in the intellisense pop-up window as an available class-name to select. |
@brandonmcconnell yes, the classes still show up in intellisense and they do work. Thanks. |
I can't reproduce this using a simple custom plugin that adds colors to the config: // tailwind.config.js
const plugin = require("tailwindcss/plugin");
module.exports = {
content: [],
theme: {
extend: {},
},
plugins: [
plugin(function () {}, {
theme: {
extend: {
colors: {
flamingo: "#eb34c3",
},
},
},
}),
],
}; My gut is the source of your problem is specific to your implementation, and the fact that you are relying on mutating module level variables inside your plugin function. Tailwind runs your configuration extensions first and that's what I'm guessing IntelliSense is seeing, and at the time that runs, I think what you're really after here is being able to access the current const plugin = require('tailwindcss/plugin')
module.exports = {
content: [],
theme: {
extend: {},
},
plugins: [
plugin(() => {}, {
theme: {
extend: {
colors: ({ theme }) => {
return somethingThatUsesTheme;
}
}
}
})
],
} I'd try refactoring to use that approach, the way your plugin is authored right now isn't really how we intended for the plugin API to be used. |
@adamwathan Thanks for the insightful response! I really appreciate it. That makes a ton of sense. I can certainly refactor my code to include all my logic within that final function. Would that still support the user-defined options object using |
It should yep! |
@adamwathan Okay, that got me about halfway there! That refactoring did cause the Intellisense to start working, but pulling from Is there a way in which, using the theme syntax you recommended, I can also reference any colors defined within |
I've refactored my code to use your suggestion, @adamwathan, but it appears if I reference
Version 1.1.0 of my plugin, before making your suggested change, does actually work with Tailwind. It just doesn't play nicely with the Tailwind CSS Intellisense plugin. The change—when using Can you please inspect my source to see what else might need to be done to work around the The source can be found here: |
I don't think you're doing anything wrong honestly, we probably just need to do some work to make what you want to do properly possible. Ideally you want to be just reading The more I understand what you're trying to do the more I'm convinced the plugin system just doesn't really support that use case well if at all. Not your fault, valid thing to want to do for sure but it's just not going to really work, and I can't say I can justify investing a ton of resources into it or anything for you since we have our own priorities. I think the best way to make it truly work would be to get users to pass the colors in to your plugin through the options, so you have direct access to the colors they want to use at the right phase in your plugin's lifecycle. // tailwind.config.js
module.exports = {
theme: {
// Don't define any colors here
},
plugins: [
require('tailwind-lerp-colors')({
// Pass them here instead
colors: ...
}),
],
} Or instead of even writing a plugin just give people a tool for generating the colors that returns a color object: // tailwind.config.js
const lerp = require('tailwindcss-lerp-colors')
const colors = require('tailwindcss/colors')
module.exports = {
theme: {
colors: lerp(colors)
},
plugins: [],
} |
Thanks for looking into that some more, @adamwathan. I did consider using Going back to my original v1.1.0 implementation, the plugin actually fully worked in Tailwind, and all colors were interpolated as expected. The only issue was that Tailwind CSS Intellisense. I'm wondering if there might be some small change possible that would simply expose all classes Tailwind CSS generates to the Intellisense plugin, even if they are not generated in the way traditionally expected. In my mind, if Tailwind CSS accepts it, shouldn't Tailwind CSS Intellisense? Thanks again! |
Yeah Tailwind accepts it but just by chance, not by design. To me the way it's implemented currently is the sort of thing we could unintentionally break in the future without considering it a breaking change. So I don't plan to invest any time into it unfortunately — maybe it's something @bradlc thinks actually should work and it's just some tiny change he has to make then sure, but otherwise I think it's just one of those "sorry that it doesn't work but we didn't intend for it to work and not interested in working on it" situations. Sorry man 🙁 |
@adamwathan No worries. I can certainly understand that. I'll keep using my accidentally functional v1.1.0 for now, and then if the functional notation is patched to work without causing those |
@adamwathan The main issue here appears to be the Or somehow spread the colors returned into a separate object in such a way that the Tailwind config does not see it as a change needing to trigger a global update to itself. I think the first idea above would make the most sense, to prevent any plugins from triggering updates to themselves, to avoid infinite loops. |
Hey @brandonmcconnell. I'm happy to take a look at your original version ( |
Hey @bradlc, thanks for looking into this for me! I really appreciate it! I came across a more significant issue with my current approach this week which would actually require a Tailwind change. If I use addUtilities(
{
'select:is(.claris-select, .claris-multiselect) option:checked': {
'@apply !bg-[image:linear-gradient(var(--color-brand-100),var(--color-brand-100))] !text-gray-750':
{},
},
},
['responsive']
); …I get this error letting me know that the class doesn't exist and that if it's a custom class, I'll need to define it in a
I'm not sure if that would be a straightforward change or not to get the classes listed in It certainly wouldn't be my preferred solution, as it wouldn't constitute as a true Tailwind plugin, but if it works, it works. Let me know what you think. Thanks! 🙏🏼 |
Also, the reason it probably isn't working with your setup is that my plugin is looking at I also need to include an additional property to determine whether to include legacy color names or not to silence the related warnings (e.g. If you think there's a chance Tailwind could make a change to account for dynamically generated classes within Thanks again! |
Hey @brandonmcconnell. @RobinMalfait figured out why I was struggling to get the plugin ( Regarding your other approaches, after discussing with the team I think that Adam's original assessment is accurate: "sorry that it doesn't work but we didn't intend for it to work and not interested in working on it" – sorry about that. For what it's worth I personally think that Adam's suggestion of a function that generates a color object makes the most sense: // tailwind.config.js
const lerp = require('tailwindcss-lerp-colors')
const colors = require('tailwindcss/colors')
module.exports = {
theme: {
colors: lerp(colors)
},
plugins: [],
} Sorry this isn't the result you were hoping for but I hope you can land on a solution that you're happy with 🙏 |
@bradlc @RobinMalfait @adamwathan Thanks for looking into that for me! I followed Adam's suggestion and refactored
I would love to see Tailwind grow to a place where this sort of added functionality is possible to achieve using Tailwind's built-in plugin infrastructure, though I understand there's not a real need for that at this point, especially alongside everything else Tailwind is currently working on. For now, this solution works great, so thank you for the suggestion! Please let me know if you have any other input or suggestions on how I could build this to further scale with Tailwind. Cheers, and thanks again 🌮🥂 |
What version of Tailwind CSS IntelliSense are you using?
v0.8.3
What version of Tailwind CSS are you using?
v3.0.24
What package manager are you using?
npm
andrush
(same result with both)What operating system are you using?
macOS Monterey v12.3.1 (21E258)
Reproduction steps
tailwind-lerp-colors
into a project usingnpm install tailwind-lerp-colors
. (related repo)require('tailwind-lerp-colors')
file (using defaults w/o invoking should be fine to reproduce the error).bg-red-350
) and you should see that the newly added interpolated colors do not show up in the intellisense pop-up/context window. However, if you save, these new colors do work as all other colors do and can be used with Tailwind JIT.Describe your issue
I built a Tailwind plugin that interpolates between colors from the Tailwind config using the interval and color-space of the user's choice (among other user-definable options). The plugin works, and these new colors do work as all other colors do and can be used with Tailwind JIT, but the new colors do not display in the Tailwind CSS Intellisense pop-up/context window.
The text was updated successfully, but these errors were encountered: