安裝
SunUI 適用於任何使用 Tailwind CSS v4 與 shadcn CLI 的 React 專案,包括 Next.js、Vite 與 Remix。
1. 設定 shadcn
如果專案裡還沒有 components.json,先初始化 shadcn。它會加入 SunUI 區塊需要的主題 tokens 與 cn 輔助函式。
$ npx shadcn@latest init2. 加入區塊
每個區塊頁都有它的安裝指令,例如:
$ npx shadcn@latest add https://sunui.synvize.com/r/countdown-banner.jsonCLI 會把原始碼複製到 components/,必要時也會安裝 framer-motion。
3. 選用:使用 @sunui 命名空間
註冊一次免費 registry,之後就能直接用名稱安裝區塊。
components.json
{
"registries": {
"@sunui": "https://sunui.synvize.com/r/{name}.json"
}
}$ npx shadcn@latest add @sunui/countdown-banner不用 shadcn 安裝
用 Tailwind CSS v4 但沒有用 shadcn/ui,或想直接複製貼上?先做一次下面三步,之後複製任一免費區塊頁上的原始碼即可。
1. 安裝相依套件。
$ npm install framer-motion clsx tailwind-merge2. 在 lib/utils.ts 加上 cn 輔助函式。
lib/utils.ts
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}3. 加入主題變數。區塊使用 bg-card、text-muted-foreground 這類顏色 token,少了它們會沒有底色與文字色。下載 sunui-theme.css,放在全域 CSS 旁邊,接在 Tailwind 後面 import。
app/globals.css
@import "tailwindcss";
@import "./sunui-theme.css";已經跑過 npx shadcn init 的專案不用做第 3 步,這些變數已經有了。這份檔案會在 :root 定義 --primary、--border 這類常見名稱,請確認沒有和你自己的變數撞名。要讓選中狀態與結果顯示你的品牌色,設定 --sunui-spot 與 --sunui-spot-foreground。