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
Add support for dynamic per-class prefix #412
Comments
I see two paths to expose an API for this, not sure yet which one makes more sense. But I think I'm learning towards approach 2. 1.
|
I originally think the prefix function would look like this: const twMerge = createTailwindMerge({
prefix: (className: string): string | undefined => {
// return the prefix, e.g. `tw-`, if the className contains prefix.
// otherwise, return undefined
}
}) Would that be better? This way the function is not removing the prefix. That is still handled by the library. |
Ah yes, that makes sense. Thanks! I'm still worrying about how error-prone this pattern could be. It's not obvious what will happen if the returned prefix isn't in the actual className string. Still needs a bit more thought. 🤔 |
There is only three possible outcomes:
Personally, my preference would be 1 > 3 > 2. 3 is the cleanest. I would do that in most case actually. Failing early is almost always the best option. 1 is pragmatic. It is least intrusive and follows JavaScript behavior. // returns the string untouched when not matched
className.replace(/^prefix-/, '') |
Comes from #405.
The idea is to resolve conflicts across multiple prefixes which aren't necessarily enumerable.
The text was updated successfully, but these errors were encountered: