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

Sort classes deep inside clsx calls #14

Open
kripod opened this issue Dec 6, 2020 · 5 comments
Open

Sort classes deep inside clsx calls #14

kripod opened this issue Dec 6, 2020 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@kripod
Copy link

kripod commented Dec 6, 2020

#11 was implemented recently and it works like charm for simple cases. However, it doesn't sort class names within arrays and objects passed to clsx (and similar methods). For instance, classes in the following code should be auto-sorted deeply:

clsx(
  "relative focus:z-10 flex justify-between px-6 py-3 hover:bg-neutral-60 space-x-6",
  disabled
    ? "text-neutral-60"
    : [
        variant === "neutral" && {
          "hover:text-neutral-0": true,
          "text-neutral-0 bg-neutral-60": active,
          "text-neutral-20 bg-neutral-80": !active,
        },
        variant === "danger" && "text-danger-40 bg-neutral-80",
      ],
  className,
)

Thank you in for maintaining this wonderful library! 😊

@kripod kripod added the enhancement New feature or request label Dec 6, 2020
@tqwewe
Copy link
Owner

tqwewe commented Dec 6, 2020

You're right! I didn't consider this.. I'll look into implementing this soon!

@kripod
Copy link
Author

kripod commented Dec 6, 2020

Awesome, I love how fast you're delivering improvements 🙌

@jsardev
Copy link

jsardev commented Dec 20, 2020

Yeah, run into this too! I think there was a wrong assumption that we're only talking about JSX attributes. It would be nice to be able to sort any function calls, just like @kripod proposed 😄

@brc-dd
Copy link

brc-dd commented May 17, 2021

Classes inside arrays passed as an argument are also not sorted. An example:

const zz = cx(['flex-col flex']); // flex should come before flex-col
const yy = (<div tw={['flex-col flex']}>Hey There!</div>);

@addemod
Copy link

addemod commented Apr 13, 2023

Another case where the classes isn't sorted is if you use clsx to "structure" the classes, i.e. printing each class on a separate row:

<div
  className={clsx(
    'flex-col',
    'max-w-[768px]',
    'w-full',
    'flex',
    'items-center',
    'py-20',
    'lg:py-60'
  )}
>
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants