Helpers
cn
Joins class names and resolves Tailwind conflicts, so a class passed in wins over a component's own.
When to use it
Every component uses it. Use it wherever classes are combined conditionally.
See it working
The demonstration the browser checks drive, with the keyboard as well as the pointer. More of it is on the Motion and transitions page.
Reveal, stagger, text reveal
Words arrive one after another when they come into view.
Content already on screen when the page loads stays put; only what scrolls in is animated.
Number ticker and presence
128,450
Tilt, spotlight, magnetic
Shared element and view transition
Scroll scene
A section that holds still
while the story moves with the scroll.
Then the next beat
Under reduced motion it is a plain stack.
Add it
npx shadcn@latest add @rivier-ui/cnThe registry is named once in components.json: see Installation.
Example
Import it from @/lib/cn.
cn("px-4 py-2", isActive && "bg-primary", className)What it needs
Plain markup: it can stay a server component. Packages: clsx, tailwind-merge.
It is used by
- accordion
- alert
- alert-dialog
- audio-player
- avatar
- badge
- bottom-sheet
- breadcrumb
- button
- calendar
- captions
- card
- carousel
- certainty-legend
- checkbox
- chip
- collapsible
- combobox
- command
- compare-slider
- compare-table
- composer
- consent
- context-menu
- countdown
- date-picker
- dialog
- direction-provider
- dock
- dropdown-menu
- dropzone
- empty-state
- fact-row
- field
- gallery
- hotspots
- hover-card
- input
- input-group
- kbd
- label
- language-switcher
- lightbox
- media-row-list
- menubar
- message
- navbar
- navigation-menu
- number-stepper
- otp-field
- pagination
- part-frame
- password-field
- popover
- price-breakdown
- progress
- provenance-label
- radio-group
- scene-strip
- scroll-area
- scrubber
- segmented-control
- select
- separator
- sheet
- skeleton
- slider
- slot-picker
- sortable-list
- spinner
- stat
- status-line
- steps
- streaming-text
- switch
- table
- tabs
- textarea
- thread
- tile-group
- time-picker
- timeline
- toaster
- toggle
- toggle-group
- toolbar
- tooltip
- undo-line
- video-player
- virtual-list
- wizard
- aspect
- bento-grid
- container
- grid
- map-frame
- marquee
- section
- split
- stack
- film-stage
- layout-transition
- magnetic
- number-ticker
- page-transition
- parallax
- presence
- reveal
- scroll-progress
- scroll-scene
- spotlight
- stagger
- text-reveal
- tilt
- view-transition
- model-viewer
- scene
- bar-chart
- chart
- donut-chart
- heatmap
- line-chart
- radial-progress
- sparkline
Source
The whole file. Once copied it is yours: the registry item holds the same text.
/**
* @name cn
* @category lib
* @description Joins class names and resolves Tailwind conflicts, so a class passed in wins over a component's own.
* @when Every component uses it. Use it wherever classes are combined conditionally.
* @example
* cn("px-4 py-2", isActive && "bg-primary", className)
*/
import { clsx, type ClassValue } from "clsx";
import { extendTailwindMerge } from "tailwind-merge";
// The theme adds utilities Tailwind does not have by default. Naming them here lets a class passed in
// ("h-12", "rounded-none", "duration-500") replace a component's own ("h-control", "rounded-control").
const merge = extendTailwindMerge({
extend: {
classGroups: {
h: [{ h: ["control", "control-sm", "control-lg"] }],
rounded: [{ rounded: ["control", "surface"] }],
duration: [{ duration: ["instant", "base", "slow"] }],
},
},
});
export function cn(...inputs: ClassValue[]): string {
return merge(clsx(inputs));
}