Class Merging
Configure custom class conflict rules, createCn, useCn, and MoraineProvider cnConfig integration.
Moraine includes a built-in class merging utility on top of cn, configured for UnoCSS and Tailwind 4. It resolves conflicting utility classes (e.g. p-2 vs p-4 or bg-primary vs bg-muted) and provides extensions for Moraine’s semantic shadows, z-index, and parametric transform utilities. Class inputs use cn’s ClassValue type; an empty merge returns undefined for DOM bindings.
Merging Classes#
Keep UnoCSS’s automatic class sorting enabled. Sorting orders tokens within a string; cn resolves conflicts across the inputs it receives, with later conflicting classes winning. Put component overrides in a later input or an appropriate override layer. Avoid placing competing values such as p-2 p-4 in the same string because sorting can change which one appears last.
Custom Class Conflict Rules#
If your project adds custom utility classes that conflict with each other (such as custom density or brand utility prefixes), configure how they merge using createCn or MoraineProvider:
Scoping with MoraineProvider#
Pass your cnConfig to MoraineProvider so all nested Moraine components and calls to useCn() inherit your custom conflict rules:
cnConfig Inheritance#
cnConfig prop |
Behavior |
|---|---|
Omitted or undefined |
Inherits parent merger, or uses default Moraine rules at root. |
| Configuration object | Replaces parent merger with Moraine defaults plus supplied extension. |
{} |
Resets to clean Moraine default rules without parent extensions. |