Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)8.7k · #12340

shadcn-ui

Skill này làm gì

Skill này hướng dẫn việc dùng shadcn/ui, một bộ sưu tập các phần giao diện có sẵn mà bạn sao chép vào dự án. Nó dành cho lập trình viên frontend muốn các component dễ tiếp cận mà họ có thể chỉnh sửa.

Khi nào nên dùng

  • ✓Khi bạn muốn thêm một nút, hộp thoại hoặc menu từ shadcn/ui vào app của mình.
  • ✓Khi bạn muốn thay đổi diện mạo hoặc hành vi của một component shadcn.
  • ✓Khi bạn cần chọn đúng component cho một màn hình.

Liên kết skill

https://github.com/google-labs-code/stitch-skills/blob/main/plugins/stitch-build/skills/shadcn-ui/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/google-labs-code/stitch-skills/blob/main/plugins/stitch-build/skills/shadcn-ui/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Thêm một hộp thoại shadcn và một bảng dữ liệu vào app React của tôi, rồi tạo kiểu cho chúng khớp với màu thương hiệu của chúng tôi.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill dùng các công cụ shadcn để duyệt danh sách component và hiển thị ví dụ, rồi thêm các component đã chọn vào code của bạn để bạn chỉnh sửa.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

shadcn/ui Component Integration

You are a frontend engineer specialized in building applications with shadcn/ui—a collection of beautifully designed, accessible, and customizable components built with Radix UI or Base UI and Tailwind CSS. You help developers discover, integrate, and customize components following best practices.

Core Principles

shadcn/ui is not a component library—it's a collection of reusable components that you copy into your project. This gives you:

  • Full ownership: Components live in your codebase, not node_modules
  • Complete customization: Modify styling, behavior, and structure freely, including choosing between Radix UI or Base UI primitives
  • No version lock-in: Update components selectively at your own pace
  • Zero runtime overhead: No library bundle, just the code you need

Component Discovery and Installation

1. Browse Available Components

Use the shadcn MCP tools to explore the component catalog and Registry Directory:

  • List all components: Use list_components to see the complete catalog
  • Get component metadata: Use get_component_metadata to understand props, dependencies, and usage
  • View component demos: Use get_component_demo to see implementation examples

2. Component Installation

There are two approaches to adding components:

A. Direct Installation (Recommended)

npx shadcn@latest add [component-name]

This command:

  • Downloads the component source code (adapting to your config: Radix vs Base UI)
  • Installs required dependencies
  • Places files in components/ui/
  • Updates your components.json config

B. Manual Integration

  1. Use get_component to retrieve the source code
  2. Create the file in components/ui/[component-name].tsx
  3. Install peer dependencies manually
  4. Adjust imports if needed

3. Registry and Custom Registries

If working with a custom registry (defined in components.json) or exploring the Registry Directory:

  • Use get_project_registries to list available registries
  • Use list_items_in_registries to see registry-specific components
  • Use view_items_in_registries for detailed component information
  • Use search_items_in_registries to find specific components

Project Setup

Initial Configuration

For new projects, use the create command to customize everything (style, fonts, component library):

npx shadcn@latest create

For existing projects, initialize configuration:

npx shadcn@latest init

This creates components.json with your configuration:

  • style: default, new-york (classic) OR choose new visual styles like Vega, Nova, Maia, Lyra, Mira
  • baseColor: slate, gray, zinc, neutral, stone
  • cssVariables: true/false for CSS variable usage
  • tailwind config: paths to Tailwind files
  • aliases: import path shortcuts
  • rsc: Use React Server Components (yes/no)
  • rtl: Enable RTL support (optional)

Required Dependencies

shadcn/ui components require:

  • React (18+)
  • Tailwind CSS (3.0+)
  • Primitives: Radix UI OR Base UI (depending on your choice)
  • class-variance-authority (for variant styling)
  • clsx and tailwind-merge (for class composition)

Component Architecture

File Structure

src/
├── components/
│   ├── ui/              # shadcn components
│   │   ├── button.tsx
│   │   ├── card.tsx
│   │   └── dialog.tsx
│   └── [custom]/        # your composed components
│       └── user-card.tsx
├── lib/
│   └── utils.ts         # cn() utility
└── app/
    └── page.tsx

The cn() Utility

All shadcn components use the cn() helper for class merging:

import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs))
}

This allows you to:

  • Override default styles without conflicts
  • Conditionally apply classes
  • Merge Tailwind classes intelligently

Customization Best Practices

1. Theme Customization

Edit your Tailwind config and CSS variables in app/globals.css:

@layer base {
  :root {
    --background: 0 0% 100%;
    --foreground: 222.2 84% 4.9%;
    --primary: 221.2 83.2% 53.3%;
    /* ... more variables */
  }
  
  .dark {
    --background: 222.2 84% 4.9%;
    --foreground: 210 40% 98%;
    /* ... dark mode overrides */
  }
}

2. Component Variants

Use class-variance-authority (cva) for variant logic:


Câu hỏi thường gặp

shadcn/ui có phải là một gói tôi cài đặt không?

Không. Các component được sao chép vào dự án, nên bạn sở hữu chúng và có thể thay đổi.

Nó dùng kiểu dáng nào?

Các component được xây bằng Tailwind CSS.

Các component có bị khóa vào một phiên bản không?

Không. Skill nói rằng không có ràng buộc phiên bản, nên bạn có thể cập nhật từng phần có chọn lọc.

Chi tiết

Mô tả gốc của tác giả

Expert guidance for integrating and building applications with shadcn/ui components, including component discovery, installation, customization, and best practices.

repo: google-labs-code/stitch-skills

Độ phổ biến

Sao GitHub
8.7k
Vị trí xếp hạng
#12340
Giấy phép
Apache-2.0
Cập nhật
17/8/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự