Config to exclude all classes which includes the -ds-
string from the merging logic
#493
-
TL;DR: Want to know how to config in order to not process any classes which includes the Hi 👋 We are working with a big DS which exports the theme tokens from Figma and they are dynamically fetched and generated during build time. Currently, it has been hard to map and list all the prefixes like For now, we are migrating to use So my question is: How can we extend the config in order to ignore all custom classes which includes We have tried a few approaches:
const customTwMerge = extendTailwindMerge({
extend: {
classGroups: {
'*': [(value: string) => !value.includes('ds-')]
}
}
})
const customTwMerge = extendTailwindMerge({
override: {
classValidator: (classGroup: string, classValue: string) => {
if (classValue.includes('ds-')) {
return false
}
return true
}
}
})
const customTwMerge = extendTailwindMerge({
experimentalParseClassName: ({ className, parseClassName }) => {
if (className.includes('-ds-')) {
return {
baseClassName: className,
modifiers: [],
hasImportantModifier: false,
maybePostfixModifierPosition: undefined
}
}
return parseClassName(className)
}
}) Any tips on how we can achieve that until we figure the config to properly resolve the conflicts? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Actually, I think I made it work with the following piece for now. Not sure if optional but it seems to work: const customTwMerge = extendTailwindMerge({
/**
Modifies how tailwind-merge internally compares classes for conflicts by prepending 'ignore-' to any class containing '-ds-' in its name.
This ensures design system classes are grouped together during conflict resolution without affecting the actual className applied to the DOM.
Example: `text-ds-badge-neutral` becomes `ignore-text-ds-badge-neutral` internally, but the original className is still applied to the component.
**/
experimentalParseClassName({ className, parseClassName }) {
if (className.includes('-ds-')) {
return {
...parseClassName(className),
baseClassName: `ignore-${className}`,
};
}
return parseClassName(className);
},
}); Will leave the discussion option is case a better idea appears, otherwise, you can close it 😄 |
Beta Was this translation helpful? Give feedback.
-
Hey @fabriciopirini! 👋 Thanks for your patience! I'd also say that |
Beta Was this translation helpful? Give feedback.
Hey @fabriciopirini! 👋
Thanks for your patience! I'd also say that
experimentalParseClassName
is the best mechanism for that. Also modifying the beginning of the base class is smart since that will make sure that the class won't match against anything. Maybe I should add a property to the return value ofexperimentalParseClassName
to explicitly opt out of merging, likeisIgnored
or so. 🤔