Capítulo 94 de 108
shadcn/ui fully supports Tailwind v4 + React 19: new @theme/@theme inline directives, data-slot on every primitive, no more forwardRef, OKLCH colors. New projects default to this; existing v3/React 18 projects keep working until manually upgraded.
@theme / @theme inline: Tailwind v4 directive mapping CSS custom properties to design tokens; inline lets you reference var(--background) directly without re-wrapping in hsl().data-slot: Every primitive now carries a data-slot="..." attribute for styling hooks, replacing reliance on component structure alone.forwardRef removal: Components now take React.ComponentProps<...> directly (no React.forwardRef, no ref={ref}, no displayName).size-* utility: Replaces w-* h-* pairs (e.g. size-4 instead of w-4 h-4), supported via tailwind-merge.tw-animate-css: Replaces deprecated tailwindcss-animate plugin; imported via @import "tw-animate-css" instead of @plugin 'tailwindcss-animate'.:root {
--background: hsl(0 0% 100%);
--foreground: hsl(0 0% 3.9%);
}
.dark {
--background: hsl(0 0% 3.9%);
--foreground: hsl(0 0% 98%);
}
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
}
hsl() fica na definição da variável (:root/.dark), @theme inline só referencia via var(), sem re-wrap.function AccordionItem({
className,
...props
}: React.ComponentProps<typeof AccordionPrimitive.Item>) {
return (
<AccordionPrimitive.Item
data-slot="accordion-item"
className={cn("border-b last:border-b-0", className)}
{...props}
/>
)
}
forwardRef, com data-slot, tipagem via ComponentProps.| Change | Before | After |
|---|---|---|
| Sizing utility | w-4 h-4 | size-4 |
| Animation plugin | @plugin 'tailwindcss-animate' | @import "tw-animate-css" |
| Chart color | color: "hsl(var(--chart-1))" | color: "var(--chart-1)" |
| Ref pattern | React.forwardRef<...> | React.ComponentProps<...> (no ref) |
hsl() inside @theme inline: wrap once at the :root/.dark variable definition, not again inside @theme.--overwrite without committing first: npx shadcn@latest add --all --overwrite overwrites existing components; always git commit before running it.@tailwindcss/upgrade@next codemod → move CSS vars out of @layer base → wrap in hsl() → use @theme inline → strip hsl() from the @theme block itself.remove-forward-ref codemod (or manual steps) to drop forwardRef across your local copied components.pnpm up "@radix-ui/*" cmdk lucide-react recharts tailwind-merge clsx --latest bumps the core dependency set for v4.npx shadcn@latest add --all --overwrite.