Skip to content
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

Feature Request: Enhanced Responsive Classnames Support #101

Open
guinnod opened this issue Jul 3, 2024 · 3 comments
Open

Feature Request: Enhanced Responsive Classnames Support #101

guinnod opened this issue Jul 3, 2024 · 3 comments

Comments

@guinnod
Copy link

guinnod commented Jul 3, 2024

Feature Request: Enhanced Responsive Classnames Support

Description

I am a developer who heavily utilizes clsx along with Tailwind CSS for my projects. The combination of clsx and Tailwind CSS is incredibly useful for managing dynamic class names. However, I have found that writing responsive Tailwind class names can be cumbersome and less readable.

Current Practice

Currently, I write responsive Tailwind class names like this:

className={clsx(
  "bg-[#2A2A2A] rounded-[16px] py-[24px] px-[16px]",
  "sm:px-[54px] sm:py-[40px] sm:rounded-[16px]",   
  "md:px-[70px] md:py-[40px] md:rounded-[26px]", 
)}

This approach works, but it can become difficult to manage and read as the number of responsive breakpoints increases.

Proposed Feature

I propose adding support for a more readable and isolated approach to responsive class names, similar to the following:

className={clsx(
  "bg-[#2A2A2A] rounded-[16px] py-[24px] px-[16px]",
  {"px-[54px] py-[40px] rounded-[16px]": "sm"},   
  {"px-[70px] py-[40px] rounded-[26px]": "md"}, 
)}

or

className={clsx(
  "bg-[#2A2A2A] rounded-[16px] py-[24px] px-[16px]",
  "sm:{px-[54px] py-[40px] rounded-[16px]}",
  "md:{px-[70px] py-[40px] rounded-[26px]}"
)}

Such formats would allow developers to isolate responsive class names and make the code more readable and maintainable.
I recognize that the maintainers have a deep understanding of the library’s architecture and may know of even more efficient ways to integrate this functionality.

Benefits

  • Improved readability and maintainability of responsive class names
  • Easier isolation of responsive styles for better debugging and testing
  • Enhanced developer experience when working with Tailwind CSS and clsx

Thank you for considering this feature request. I believe it would be a valuable addition to clsx, especially for developers who use Tailwind CSS extensively.

Best regards,
Abzal Slamkozha

@mulfyx
Copy link

mulfyx commented Jul 4, 2024

That is beyond the responsibility of the library

@hoangnhan2ka3
Copy link

So maybe this plugin can serve ~90% your needs: https://github.com/Noriller/easy-tailwind

I currently use it like this:

className={cn(
    fonts.Gilroy_Sans.variable,
    fonts.Sf_Mono.variable,
    "relative h-fit !scroll-smooth bg-mega-background",
    e({
        all: "focus:outline-none",
        selection: "bg-zinc-400/40 text-mega-secondary text-shadow-none"
    })
)}

output:

class="__variable_e8f235 __variable_aaef19 relative h-fit !scroll-smooth bg-mega-background all:focus:outline-none selection:bg-zinc-400/40 selection:text-mega-secondary selection:text-shadow-none"

One drawback that u must nested e() inside another fn like clsx, cn if u want to write variables or complex conditions in it, in my case:

fonts.Gilroy_Sans.variable,
fonts.Sf_Mono.variable,

otherwise u just need e(), detail on the plugin's docs.

And if u have time, consider this Noriller/easy-tailwind#4 issue.

@guinnod
Copy link
Author

guinnod commented Jul 6, 2024

So maybe this plugin can serve ~90% your needs: https://github.com/Noriller/easy-tailwind

I currently use it like this:

className={cn(
    fonts.Gilroy_Sans.variable,
    fonts.Sf_Mono.variable,
    "relative h-fit !scroll-smooth bg-mega-background",
    e({
        all: "focus:outline-none",
        selection: "bg-zinc-400/40 text-mega-secondary text-shadow-none"
    })
)}

output:

class="__variable_e8f235 __variable_aaef19 relative h-fit !scroll-smooth bg-mega-background all:focus:outline-none selection:bg-zinc-400/40 selection:text-mega-secondary selection:text-shadow-none"

One drawback that u must nested e() inside another fn like clsx, cn if u want to write variables or complex conditions in it, in my case:

fonts.Gilroy_Sans.variable,
fonts.Sf_Mono.variable,

otherwise u just need e(), detail on the plugin's docs.

And if u have time, consider this Noriller/easy-tailwind#4 issue.

thank you!

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

No branches or pull requests

3 participants