Add ability to pass twMerge config for 'cn' helper function #313
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds the ability to customize the
cn
helper function with tailwind-merge configuration, allowing users to extend or override the default behavior for custom design systems and utility classes.Motivation
When building design systems with custom Tailwind utility classes, the default
cn
helper doesn't know how to properly merge custom class groups. This leads to both classes being kept instead of the later one overriding the earlier one. By exposing tailwind-merge's configuration options, users can now define their own class groups and conflict resolution rules.Changes
New
createCn
FunctionAdded a new
createCn
function that accepts a tailwind-merge configuration object and returns a customizedcn
function:Supported Configuration Options
Users can now configure:
_
instead of:
)See tailwind-merge documentation for all available options.
Backward Compatibility
The existing
cn
function remains unchanged and continues to work exactly as before. This is a purely additive change with no breaking changes.Testing
Documentation
docs/cn-helper.mdx
with detailed usage guideExample Use Cases
Design System with Custom Colors:
Custom Prefix:
Closes the issue requesting this functionality.
Original prompt
Fixes #303
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.