Communitygithub.com

Blaise1030/astro-marketing

使用 Tailwind CSS v4 建立可擴充的設計系統,包含設計代碼、元件庫和響應式模式。適合在建立元件庫、實作設計系統或標準化 UI 模式時使用。

astro-marketing 是什麼?

此技能專注於使用 Tailwind CSS v4 (2024+) 建立可供生產環境使用的設計系統。它涵蓋了 CSS-first 配置、設計代碼、元件變體、響應式模式以及無障礙性等核心概念。使用者可以學習如何利用 `@theme` 指令在 CSS 中定義語意化的顏色、間距和動畫代碼,並透過 `@custom-variant` 實現深色模式。技能也提供了從 Tailwind v3 遷移到 v4 的關鍵差異對照表,以及完整的元件架構模式,讓開發者能夠標準化 UI 模式、建立元件庫,並在整個程式碼庫中維持一致的設計語言。此技能支援所有使用 Tailwind CSS v4 的專案,例如 Next.js、Astro 或 Vite 等框架,並強調使用 OKLCH 色彩空間以獲得更好的色彩感知。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Blaise1030/astro-marketing/tree/HEAD/.agents/skills/tailwind-design-system

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Tailwind 設計系統 (v4)

使用 Tailwind CSS v4 建立可供生產環境使用的設計系統,包含 CSS-first 配置、設計代碼、元件變體、響應式模式和無障礙性。

注意:此技能針對 Tailwind CSS v4 (2024+)。若為 v3 專案,請參閱升級指南。

何時使用此技能

  • 使用 Tailwind v4 建立元件庫
  • 使用 CSS-first 配置實作設計代碼和主題
  • 建立響應式且無障礙的元件
  • 在程式碼庫中標準化 UI 模式
  • 從 Tailwind v3 遷移到 v4
  • 使用原生 CSS 功能設定深色模式

主要的 v4 變更

v3 模式v4 模式
tailwind.config.tsCSS 中的 @theme
@tailwind base/components/utilities@import "tailwindcss"
darkMode: "class"@custom-variant dark (&:where(.dark, .dark *))
theme.extend.colors@theme { --color-*: value }
require("tailwindcss-animate")CSS @keyframes 在 @theme 中 + 用於進入動畫的 @starting-style

快速開始

/* app.css - Tailwind v4 CSS-first 配置 */
@import "tailwindcss";

/* 使用 @theme 定義你的主題 */
@theme {
  /* 使用 OKLCH 的色彩語意代碼,以獲得更好的色彩感知 */
  --color-background: oklch(100% 0 0);
  --color-foreground: oklch(14.5% 0.025 264);

  --color-primary: oklch(14.5% 0.025 264);
  --color-primary-foreground: oklch(98% 0.01 264);

  --color-secondary: oklch(96% 0.01 264);
  --color-secondary-foreground: oklch(14.5% 0.025 264);

  --color-muted: oklch(96% 0.01 264);
  --color-muted-foreground: oklch(46% 0.02 264);

  --color-accent: oklch(96% 0.01 264);
  --color-accent-foreground: oklch(14.5% 0.025 264);

  --color-destructive: oklch(53% 0.22 27);
  --color-destructive-foreground: oklch(98% 0.01 264);

  --color-border: oklch(91% 0.01 264);
  --color-ring: oklch(14.5% 0.025 264);

  --color-card: oklch(100% 0 0);
  --color-card-foreground: oklch(14.5% 0.025 264);

  /* 焦點狀態的環狀偏移 */
  --color-ring-offset: oklch(100% 0 0);

  /* 圓角代碼 */
  --radius-sm: 0.25rem;
  --radius-md: 0.375rem;
  --radius-lg: 0.5rem;
  --radius-xl: 0.75rem;

  /* 動畫代碼 - 當透過 --animate-* 變數引用時,@theme 中的 keyframes 才會輸出 */
  --animate-fade-in: fade-in 0.2s ease-out;
  --animate-fade-out: fade-out 0.2s ease-in;
  --animate-slide-in: slide-in 0.3s ease-out;
  --animate-slide-out: slide-out 0.3s ease-in;

  @keyframes fade-in {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  @keyframes fade-out {
    from {
      opacity: 1;
    }
    to {
      opacity: 0;
    }
  }

  @keyframes slide-in {
    from {
      transform: translateY(-0.5rem);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }

  @keyframes slide-out {
    from {
      transform: translateY(0);
      opacity: 1;
    }
    to {
      transform: translateY(-0.5rem);
      opacity: 0;
    }
  }
}

/* 深色模式變體 - 使用 @custom-variant 進行基於 class 的深色模式 */
@custom-variant dark (&:where(.dark, .dark *));

/* 深色模式主題覆寫 */
.dark {
  --color-background: oklch(14.5% 0.025 264);
  --color-foreground: oklch(98% 0.01 264);

  --color-primary: oklch(98% 0.01 264);
  --color-primary-foreground: oklch(14.5% 0.025 264);

  --color-secondary: oklch(22% 0.02 264);
  --color-secondary-foreground: oklch(98% 0.01 264);

  --color-muted: oklch(22% 0.02 264);
  --color-muted-foreground: oklch(65% 0.02 264);

  --color-accent: oklch(22% 0.02 264);
  --color-accent-foreground: oklch(98% 0.01 264);

  --color-destructive: oklch(42% 0.15 27);
  --color-destructive-foreground: oklch(98% 0.01 264);

  --color-border: oklch(22% 0.02 264);
  --color-ring: oklch(83% 0.02 264);

  --color-card: oklch(14.5% 0.025 264);
  --color-card-foreground: oklch(98% 0.01 264);

  --color-ring-offset: oklch(14.5% 0.025 264);
}

/* 基本樣式 */
@layer base {
  * {
    @apply border-border;
  }

  body {
    @apply bg-background text-foreground antialiased;
  }
}

核心概念

1. 設計代碼階層

品牌代碼 (抽象)
    └── 語意代碼 (用途)
        └── 元件代碼 (特定)

範例:
    oklch(45% 0.2 260) → --color-primary → bg-primary

2. 元件架構

基本樣式 → 變體 → 尺寸 → 狀態 → 覆寫

詳細模式與實作範例

詳細的模式文件位於 references/details.md。當上述導覽層級不足時,請閱讀該文件。

Individual skills in this repo

This repo contains 4 individual skills — each has its own dedicated page.

相關技能