Class merging
Components that accept a class prop need to merge it with their own classes so the caller wins: p-4 passed in should replace the component’s p-2, not sit next to it. tailwind-merge does that for Tailwind’s built-in utilities. @nyxwire/tailwind/merge extends it with the Nyxwire utilities.
import { cn } from '@nyxwire/tailwind/merge'
cn('rounded-md bg-panel p-2', props.class)cn('glow-md glow-flux', isAlarm && 'glow-danger')cn('bg-canvas', { 'bg-panel': raised }, [false, 'p-4'])cn(...inputs) accepts strings, numbers, bigints, null, undefined, booleans, nested readonly arrays and objects whose truthy keys are added. Falsy values are dropped, and it needs no clsx. When two classes set the same thing, the later one wins. Every result below was computed by the shipped cn when this page was built:
| Call | Result |
|---|---|
cn('glow-sm glow-flux', 'glow-lg') | 'glow-flux glow-lg' |
cn('shadow-md', 'glow-sm') | 'glow-sm' |
cn('text-glow text-glow-nw-indigo', 'text-glow-matrix') | 'text-glow text-glow-matrix' |
cn('text-sm text-fg', 'text-fg-muted') | 'text-sm text-fg-muted' |
cn('bg-canvas px-4', 'bg-panel') | 'px-4 bg-panel' |
cn('bg-panel backdrop-blur-sm', 'glass') | 'glass' |
cn('glass', 'bg-panel') | 'glass bg-panel' |
cn('grid-bg', 'bg-wire') | 'bg-wire' |
cn('rounded-lg border bg-panel', 'cut') | 'cut' |
cn('border-line', 'wire') | 'wire' |
cn('text-fg bg-clip-padding', 'text-wire') | 'text-wire' |
cn('rounded-md shadow-sm', 'rounded-xl shadow-lg') | 'rounded-xl shadow-lg' |
cn('font-sans', 'font-display') | 'font-display' |
cn('animate-fade-in', 'animate-glow-pulse') | 'animate-glow-pulse' |
cn('ease-standard', 'ease-back') | 'ease-back' |
What the configuration teaches tailwind-merge:
- Glow sizes (
glow-sm,glow-md,glow-lg,wire-glow) share the box-shadow group, so they replace each other and anyshadow-*. - Glow colors have a group of their own, shared by
glow-*andtext-glow-*: the last color wins, and a size never removes a color. text-glowbelongs to the text-shadow group.bg-wirebelongs to the background-image group, so it replaces another gradient and can sit next to a background color.grid-bgpaints its own background image and size, so it conflicts withbg-wire,cut,wireandtext-wire.cutreplaces an earlier radius, border width or background color: its shape and fill come from--nw-cutand--nw-fill.wirereplaces an earlier border color.glassreplaces an earlierbg-*color orbackdrop-blur-*. A color written after it still applies.text-wirereplaces an earlier text color, background image or background clip.scanlinesandglitchhave groups of their own and never remove anything.- The type scale, radius, easings and animations extend Tailwind’s scales:
text-2xs,rounded-xs,ease-backandanimate-glow-pulsemerge like their built-in neighbors.
A later override of one part of a composite, such as bg-panel after glass, keeps the other parts intact.
twMergeConfig
Section titled “twMergeConfig”To use the configuration with your own tailwind-merge instance, pass it to extendTailwindMerge:
import { extendTailwindMerge } from 'tailwind-merge'import { twMergeConfig } from '@nyxwire/tailwind/merge'
export const merge = extendTailwindMerge(twMergeConfig)twMergeConfig is typed as TwMergeConfig. The module also exports the ClassValue, ClassDictionary and NyxwireClassGroupIds types.
Recipes with tailwind-variants
Section titled “Recipes with tailwind-variants”tailwind-variants builds class lists from variants. Create its tv with createTV from the tailwind-variants/config entry point, so every recipe merges with the Nyxwire configuration:
import { createTV } from 'tailwind-variants/config'import { twMergeConfig } from '@nyxwire/tailwind/merge'
export const tv = createTV({ twMergeConfig })import { tv } from './tv'
export const signal = tv({ base: 'inline-flex items-center gap-1 rounded-md px-2 py-0.5 font-mono text-xs', variants: { intent: { primary: 'bg-primary-soft text-primary', danger: 'bg-danger-soft text-danger', }, glowing: { true: 'glow-sm' }, }, compoundVariants: [{ intent: 'danger', glowing: true, class: 'glow-danger' }], defaultVariants: { intent: 'primary' },})The same recipe, rendered when this page was built. In the last row the caller’s rounded-full replaces the base rounded-md:
| Call | Rendered | Classes |
|---|---|---|
signal() | uplink | inline-flex items-center gap-1 rounded-md px-2 py-0.5 font-mono text-xs bg-primary-soft text-primary |
signal({ glowing: true }) | uplink | inline-flex items-center gap-1 rounded-md px-2 py-0.5 font-mono text-xs bg-primary-soft text-primary glow-sm |
signal({ intent: 'danger', glowing: true }) | uplink | inline-flex items-center gap-1 rounded-md px-2 py-0.5 font-mono text-xs bg-danger-soft text-danger glow-sm glow-danger |
signal({ intent: 'danger', class: 'rounded-full' }) | uplink | inline-flex items-center gap-1 px-2 py-0.5 font-mono text-xs bg-danger-soft text-danger rounded-full |
In Vue
Section titled “In Vue”@nyxwire/vue exports the same two helpers, already configured: cn is the function above and tv is created with createTV({ twMergeConfig }). Its components merge their class prop with them, so overrides behave the same everywhere.
import { cn, tv } from '@nyxwire/vue'