clx

Utility function for working with classNames.

Usage#


The clx function is a utility function for working with classNames. It is built using clsx and tw-merge and is intended to be used with Tailwind CSS.

Code
1import { clx } from "@medusajs/ui"2
3type BoxProps = {4  className?: string5  children: React.ReactNode6  mt: "sm" | "md" | "lg"7}8
9const Box = ({ className, children, mt }: BoxProps) => {10  return (11    <div12      className={clx(13        "flex items-center justify-center",14        {15          "mt-4": mt === "sm",16          "mt-8": mt === "md",17          "mt-12": mt === "lg",18        },19        className20      )}21    >22      {children}23    </div>24  )25}

In the above example the utility is used to apply a base style, a margin top that is dependent on the mt prop and a custom className. The Box component accepts a className prop that is merged with the other classNames, and the underlying usage of tw-merge ensures that all Tailwind CSS classes are merged without style conflicts.

Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break