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

Identify Tailwind custom classes #302

Open
ARiyou2000 opened this issue Aug 29, 2023 · 5 comments
Open

Identify Tailwind custom classes #302

ARiyou2000 opened this issue Aug 29, 2023 · 5 comments
Labels
context-v1 Related to tailwind-merge v1

Comments

@ARiyou2000
Copy link

Describe the bug

I have custom border rados in my tailwind.config.js file

const config = {
  theme: {
    extend: {
      borderRadius: {
        card: "1.5625rem",
      }
    }
  }
}

To Reproduce

console.log(cn("rounded-lg", "rounded-xl", "rounded-card"));

result: rounded-xl rounded-card

Expected behavior

result: rounded-card

Environment

It doesn't make any difference but, Next.JS 13

  • tailwind-merge version: 1.14.0 (latest)

Additional context

@romanhrynevych
Copy link

I think that error is in configuration tw-merge, it doesn't take it from tailwind.config.ts file (or other extension), have same error and is going to deep inside it to fix 🙁
Recipe for configuration: https://github.com/dcastil/tailwind-merge/blob/v1.14.0/docs/recipes.md#adding-custom-scale-from-tailwind-config-to-tailwind-merge-config

@dcastil
Copy link
Owner

dcastil commented Aug 29, 2023

Hey @ARiyou2000! 👋

As @romanhrynevych writes, tailwind-merge doesn't have access to the tailwind.config.js file and you need to configure it separately so it knows about the rounded-card class.

Here is an example on how to configure tailwind-merge: https://github.com/dcastil/tailwind-merge/blob/v1.14.0/docs/recipes.md#adding-custom-scale-from-tailwind-config-to-tailwind-merge-config.

And here is the documentation on how the tailwind-merge configuration works: https://github.com/dcastil/tailwind-merge/blob/v1.14.0/docs/configuration.md#usage-with-custom-tailwind-config.

Related: #276, #275, #274, #250, #207

@dcastil
Copy link
Owner

dcastil commented Sep 26, 2023

Note to myself: Mentioned in #315 (comment).

@dcastil dcastil added the context-v1 Related to tailwind-merge v1 label Oct 30, 2023
@silent-tan
Copy link

silent-tan commented Oct 31, 2023

If you have customized the tailwind theme and find it painful to use tw-merge, is there any solution?

// tailwind.config.js
fontSize: {
    "8px": "8px",
    "10px": "10px",
    "12px": "12px",
    "14px": "14px",
    "16px": "16px",
    "18px": "18px",
    "24px": "24px",
  },
...

so that i have to do it for extendTailwindMerge

const twMerge = extendTailwindMerge({
  extend: {
    classGroups: {
      "font-size": [
        {
          text: ["8px", "10px", "12px", "14px", "16px", "18px", "24px"],
        },
      ],
      "text-color": [{ text: ["primary"] }],
    },
  },
});

so image i need to extend spacing,👋🏻

// tailwind.config.js
spacing: {
  "2px": "2px",
  "4px": "4px",
  "6px": "6px",
  "8px": "8px",
  "10px": "10px",
  "12px": "12px",
  "14px": "14px",
  "16px": "16px",
  "18px": "18px",
  "20px": "20px",
  "24px": "24px",
  "28px": "28px",
  "32px": "32px",
  "40px": "40px",
  "54px": "54px",
  "64px": "64px",
},

By default the spacing scale is inherited by the padding, margin, width, height, maxHeight, gap, inset, space, translate, scrollMargin, and scrollPadding core plugins.

@dcastil
Copy link
Owner

dcastil commented Oct 31, 2023

Hey @silent-tan! 👋

The spacing theme scale is supported by tailwind-merge! You can do this and the scale will be applied to all groups that use the spacing scale.

const twMerge = extendTailwindMerge({
    extend: {
        theme: {
            spacing: [(classPart) => /^\d+px$/.test(classPart)]
        }
    }
}) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
context-v1 Related to tailwind-merge v1
Projects
None yet
Development

No branches or pull requests

4 participants