Learning
shadcn/ui

Hogyan működik

A shadcn/ui CLI komponenseket generál a projektbe; cva variánsok, cn helper és a Tailwind merge szerepe.

Hogyan működik

A shadcn/ui CLI egy paranccsal letölti és a projektedbe másolja a kért komponens forráskódját. Innen kezdve ez a te kódod.

Folyamat

  1. npx shadcn-ui@latest add button
  2. Létrejön pl. components/ui/button.tsx
  3. A fájl tartalmazza a teljes komponenst (React + Tailwind + Radix)
  4. Testreszabod a saját igényeid szerint

Mit generál? (rövid részlet)

import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"

// ... buttonVariants cva ...

A cn utility

Az init létrehozza a lib/utils.ts-t, benne a cn helperrel, ami clsx + tailwind-merge kombináció.

Rövid összefoglaló

  • A CLI kódot generál, nem csomagot telepít.
  • cva a variáns alapú stylinghoz, cn a class merge-hez.

On this page