返回技能列表

setup-tailwind-typescript

pjt222
更新于 2 days ago
5 次查看
17
2
17
在 GitHub 上查看
设计reactaidesign

关于

This skill configures Tailwind CSS in a TypeScript-based Next.js or React project, handling installation and setup. It enables custom theme extensions, type-safe styling utilities, and component patterns for a design system. Use it to add Tailwind to an existing TypeScript project and configure plugins with full type safety.

快速安装

Claude Code

推荐
主要方式
npx skills add pjt222/agent-almanac -a claude-code
插件命令备选方式
/plugin add https://github.com/pjt222/agent-almanac
Git 克隆备选方式
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/setup-tailwind-typescript

在 Claude Code 中复制并粘贴此命令以安装该技能

技能文档

Set Up Tailwind CSS with TypeScript

Configure Tailwind CSS in TS project w/ custom theme, utilities, type-safe patterns.

Use When

  • Add Tailwind to existing TS project
  • Customize theme for design system
  • Type-safe component styling
  • Configure plugins + ext

In

  • Required: TS project (Next.js, Vite, standalone React)
  • Optional: Design tokens (colors, spacing, fonts)
  • Optional: Plugins to include

Do

Step 1: Install Tailwind

npm install -D tailwindcss @tailwindcss/postcss postcss

Next.js (if not included):

npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

tailwindcss, postcss, autoprefixer as dev deps. Next.js → tailwind.config.ts + postcss.config.js generated.

If err: npx tailwindcss init fails → install Tailwind first w/ npm install -D tailwindcss + retry. Monorepo → run from app root, not workspace root.

Step 2: tailwind.config.ts

import type { Config } from "tailwindcss";

const config: Config = {
  content: [
    "./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
    "./src/components/**/*.{js,ts,jsx,tsx,mdx}",
    "./src/app/**/*.{js,ts,jsx,tsx,mdx}",
  ],
  theme: {
    extend: {
      colors: {
        primary: {
          50: "#eff6ff",
          100: "#dbeafe",
          500: "#3b82f6",
          600: "#2563eb",
          700: "#1d4ed8",
          900: "#1e3a5f",
        },
        secondary: {
          500: "#6366f1",
          600: "#4f46e5",
        },
      },
      fontFamily: {
        sans: ["Inter", "system-ui", "sans-serif"],
        mono: ["JetBrains Mono", "monospace"],
      },
      spacing: {
        "18": "4.5rem",
        "88": "22rem",
      },
    },
  },
  plugins: [],
};

export default config;

→ Has content array matching paths, custom colors+fonts under theme.extend, proper TS typing w/ Config import.

If err: custom classes don't render → verify content paths match dir. Glob patterns relative to root. Missing → Tailwind won't scan.

Step 3: Global Styles

Edit src/app/globals.css:

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  html {
    @apply antialiased;
  }

  body {
    @apply bg-white text-gray-900 dark:bg-gray-950 dark:text-gray-100;
  }
}

@layer components {
  .btn-primary {
    @apply bg-primary-600 text-white px-4 py-2 rounded-lg
           hover:bg-primary-700 focus:outline-none focus:ring-2
           focus:ring-primary-500 focus:ring-offset-2
           transition-colors duration-200;
  }
}

globals.css has 3 directives + custom base+component layer. Imported in root layout.

If err: not applied → verify imported in layout.tsx (or _app.tsx for Pages). Directives present, not commented.

Step 4: Type-Safe Utility Helpers

Create src/lib/cn.ts:

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

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

Install:

npm install clsx tailwind-merge

Usage:

import { cn } from "@/lib/cn";

interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
  variant?: "primary" | "secondary" | "outline";
}

export function Button({ className, variant = "primary", ...props }: ButtonProps) {
  return (
    <button
      className={cn(
        "px-4 py-2 rounded-lg font-medium transition-colors",
        variant === "primary" && "bg-primary-600 text-white hover:bg-primary-700",
        variant === "secondary" && "bg-secondary-500 text-white hover:bg-secondary-600",
        variant === "outline" && "border border-gray-300 hover:bg-gray-50",
        className
      )}
      {...props}
    />
  );
}

src/lib/cn.ts exports cn(). clsx + tailwind-merge installed. Components use cn() to merge class names w/o conflicts.

If err: clsx|tailwind-merge not found → npm install clsx tailwind-merge. TS errs in cn.ts → verify ClassValue imported from clsx.

Step 5: Dark Mode

Update tailwind.config.ts:

const config: Config = {
  darkMode: "class", // or "media" for system preference
  // ... rest of config
};

Toggle:

"use client";
import { useEffect, useState } from "react";

export function ThemeToggle() {
  const [dark, setDark] = useState(false);

  useEffect(() => {
    document.documentElement.classList.toggle("dark", dark);
  }, [dark]);

  return (
    <button onClick={() => setDark(!dark)}>
      {dark ? "Light" : "Dark"} Mode
    </button>
  );
}

→ Dark toggles correct between light+dark. dark class on <html>, dark: prefixed classes respond.

If err: not toggling → verify darkMode: "class". dark on <html> not <body>. System-pref → darkMode: "media".

Step 6: Plugins (Optional)

npm install -D @tailwindcss/typography @tailwindcss/forms
// tailwind.config.ts
import typography from "@tailwindcss/typography";
import forms from "@tailwindcss/forms";

const config: Config = {
  // ...
  plugins: [typography, forms],
};

→ Plugins installed dev deps + registered in plugins array. Plugin classes (prose, styled forms) available.

If err: plugin classes don't render → verify installed (npm ls @tailwindcss/typography) + in plugins array. Restart dev server after config changes.

Check

  • Tailwind classes render in browser
  • Custom theme (colors, fonts, spacing) works
  • cn() merges w/o conflicts
  • Dark mode toggles
  • TS no errs in config|components
  • Prod build purges unused

Traps

  • Content paths missing: Classes don't render → check content array matches files
  • Class conflicts: Use tailwind-merge (via cn()) → prevent conflicting
  • Custom vals not working: Under extend (to add) not theme root (replaces defaults)
  • Dark mode not toggling: Check darkMode + dark on <html> not <body>

  • scaffold-nextjs-app — project setup pre-Tailwind
  • deploy-to-vercel — deploy styled app

GitHub 仓库

pjt222/agent-almanac
路径: i18n/caveman-ultra/skills/setup-tailwind-typescript
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

相关推荐技能

executing-plans

设计

该Skill用于当开发者提供完整实施计划时,以受控批次方式执行代码实现。它会先审阅计划并提出疑问,然后分批次执行任务(默认每批3个任务),并在批次间暂停等待审查。关键特性包括分批次执行、内置检查点和架构师审查机制,确保复杂系统实现的可控性。

查看技能

requesting-code-review

设计

该Skill可在完成任务、实现主要功能或合并代码前自动调度代码审查子代理,确保实现符合需求和计划。它支持通过指定git SHA范围进行精准的代码变更审查,帮助开发者在关键节点及时发现潜在问题。核心原则是"早审查、勤审查",适用于开发流程的各个关键阶段。

查看技能

connect-mcp-server

设计

这个Skill指导开发者如何将MCP服务器连接到Claude Code,支持HTTP、stdio和SSE三种传输协议。它涵盖了从安装配置到认证安全的完整流程,适用于集成GitHub、Notion、数据库等外部服务。当开发者需要添加集成、配置外部工具或提及MCP相关功能时,这个Skill能提供实用的操作指南。

查看技能

web-cli-teleport

设计

该Skill帮助开发者根据任务特性选择Claude Code的Web或CLI界面,并指导如何在两种环境间无缝迁移会话。它能分析任务复杂度、迭代需求等要素,推荐最优工作界面和工作流。关键特性包括会话状态管理、环境切换指导和上下文优化建议。

查看技能