Skip to content

Conversation

@barvian
Copy link
Contributor

@barvian barvian commented Aug 26, 2023

Hello Tailwind team! I didn't ask first about this one because it's so tiny; I hope that's OK!

I'm in the process of writing a fluid type utility and encountered an unusual situation where I wanted to know from within the utility if it was being used with a screen variant, so I could change some values accordingly. I figured it would make most sense to pass the variants through to matchUtilities/matchComponents in the extra object that already holds modifiers. I can't think of any negative side effects, because the variants still get applied. For simplicity, I'm only passing through the variant names for now but I could potentially expand it to perhaps show selectors as well (similar to context.getVariants()). Any thoughts?

Thanks!

@adamwathan
Copy link
Member

Hey! Can you share more details about why you'd actually need this? It feels strange to me to change what a utility does based on the variant being used, like if bg-black made something black but hover:bg-black made something green for instance.

@barvian
Copy link
Contributor Author

barvian commented Aug 26, 2023

@adamwathan Thanks for the response! I agree that it's definitely a weird use case and maybe there's a better way to handle it. I'm writing a fluid utility to generate clamp() expressions i.e. fluid-py-4/8, that would generate a clamp() expression that interpolates between 1rem at some default small screen and 2rem at some default large screen. I figured it'd be nice, though, to be able to put that in a a media query like sm:max-lg:fluid-py-4/8 and have the clamp use those breakpoints instead of the default ones. I hope that explanation made sense!

@barvian
Copy link
Contributor Author

barvian commented Aug 26, 2023

@adamwathan Upon thinking about this more, I think you're right that this could make utilities too unpredictable, which seems not worth this one use case so I can think of another way 🙂. Thanks for the response!

@barvian barvian closed this Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants