Communitygithub.com

Blaise1030/astro-marketing

使用 Tailwind CSS v4、设计令牌、组件库和响应式模式构建可扩展的设计系统。适用于创建组件库、实现设计系统或标准化UI模式。

astro-marketing 是什么?

该技能专注于使用 Tailwind CSS v4 (2024+ 版本) 构建生产级的设计系统。其核心优势在于采用了新的“CSS 优先配置”方式,通过 `@theme` 指令在 CSS 中定义设计令牌(如颜色、间距、动画),取代了传统的 `tailwind.config.ts` 配置文件。技能详细展示了如何使用 OKLCH 色彩空间创建语义化的颜色令牌(包括亮色和暗色主题),并通过 `@custom-variant` 实现类名驱动的暗色模式。此外,它还介绍了组件架构(基础样式→变体→大小→状态→覆盖)和设计令牌的分层体系(品牌令牌→语义令牌→组件令牌)。此技能主要支持以 CSS 文件为核心的开发工作流,适用于从 v3 迁移到 v4 的项目,以及需要标准化 UI 模式、创建组件库的团队。用户可将其与 Astro、Next.js 等现代框架配合使用,通过 CSS 文件轻松实现可维护的主题化设计。

兼容平台~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 优先配置、设计令牌、组件变体、响应式模式和可访问性。

注意:此技能面向 Tailwind CSS v4(2024+)。对于 v3 项目,请参考升级指南。

何时使用此技能

  • 使用 Tailwind v4 创建组件库
  • 使用 CSS 优先配置实现设计令牌和主题
  • 构建响应式和可访问的组件
  • 在代码库中标准化 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-*: 值 }
require("tailwindcss-animate")CSS @keyframes 在 @theme 内 + 用于进入动画的 @starting-style

快速开始

/* app.css - Tailwind v4 CSS 优先配置 */
@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 内的关键帧会被输出 */
  --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.

相关技能