Shadcn

Introduction

  • This is NOT a component library. It's a collection of re-usable components that you can install it one by one and customize it

  • It is consist of tailwindcss (For styling and theme) and Radix UI (for headless component pattern)

Installation

  • Init the components.json , lib/utils

npx shadcn@latest init
  • Copy and paste the pre-created component one by one

npx shadcn@latest add button

Customization

  • The setting of shadcn json file

components.json
{
  "$schema": "https://ui.shadcn.com/schema.json",
  "style": "default",
  "rsc": false,
  "tsx": true,
  "tailwind": {
    // 
    "config": "tailwind.config.js",
    // the import tailwindcss css file
    "css": "src/index.css",
    // the default color of component if not customized
    "baseColor": "gray",
    // allow to use variable, e.g: primary
    "cssVariables": true,
    "prefix": ""
  },
  "aliases": {
    // the directory of component generated by command
    "components": "@/components",
    "utils": "@/lib/utils",
    "ui": "@/components/ui",
    "lib": "@/lib",
    "hooks": "@/hooks"
  },
  "iconLibrary": "lucide"
}
  • After init, the extension of theme will be added to tailwind config file

  • The extended theme (primary, ...) will be added and depend on css variable

  • Since the tailwind css class (with css variable) is applied to radix component

  • If customization is needed, it is needed to customize the css variable

Last updated

Was this helpful?