スキル一覧に戻る

setup-tailwind-typescript

pjt222
更新日 2 days ago
7 閲覧
17
2
17
GitHubで表示
デザインreactaidesign

について

このスキルは、Next.jsまたはReactプロジェクト向けにTailwind CSSをTypeScriptで設定し、インストール、テーマカスタマイズ、型安全なスタイリングパターンを扱います。既存のTypeScriptコードベースにTailwindを追加する場合や、デザインシステムの基盤を確立するのに理想的です。セットアップには、型安全な開発のためのコンポーネントパターン、ユーティリティ拡張、プラグイン設定が含まれます。

クイックインストール

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にコピー&ペーストしてスキルをインストールします

ドキュメント

設 Tailwind CSS 與 TypeScript

於 TypeScript 項目配 Tailwind CSS,附自定主題、用、與類安之模。

用時

  • 既 TypeScript 項目加 Tailwind CSS 乃用
  • 為項目之設計系統自定 Tailwind 主題乃用
  • 設類安件之風模乃用
  • 配 Tailwind 之插件與擴乃用

  • 必要:TypeScript 項目(Next.js、Vite、或獨之 React)
  • 可選:設計系統之令(色、距、字)
  • 可選:欲含之 Tailwind 插件

第一步:裝 Tailwind CSS

npm install -D tailwindcss @tailwindcss/postcss postcss

為 Next.js(若未含):

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

得:tailwindcsspostcssautoprefixer 已裝為開發依。Next.js 者,tailwind.config.tspostcss.config.jsnpx tailwindcss init -p 生。

敗則:npx tailwindcss init 敗,先以 npm install -D tailwindcss 裝後再試。monorepo 者,於應之根目行命,非工作空之根。

第二步:配 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;

得:tailwind.config.tscontent 列合項目文件之位、theme.extend 下自定色與字、附正之 TypeScript 類(含 Config 之引)。

敗則:自定類不渲,驗 content 之徑合實之目構。徑為相對項目根之 glob 模。徑缺則 Tailwind 不掃其文件之類用。

第三步:設全風

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 含三 Tailwind 之指(@tailwind base@tailwind components@tailwind utilities)並自定基與件層之風。文件引於根布。

敗則:風未施,驗 globals.css 引於 layout.tsx(或 Pages Router 之 _app.tsx)。察 Tailwind 諸指存而未注掉。

第四步:立類安之用助

src/lib/cn.ts

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

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

裝依:

npm install clsx tailwind-merge

於件中之用:

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.tscn() 函。clsxtailwind-merge 已裝為依。件用 cn() 合類名而無衝。

敗則:clsxtailwind-merge 不可得,行 npm install clsx tailwind-mergecn.ts TypeScript 報類誤,驗 ClassValueclsx 引。

第五步:增暗模之支

tailwind.config.ts

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

切換之施:

"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 類施於 <html> 元,dark: 前之類隨應。

敗則:暗模不切,驗 darkMode: "class" 設於 tailwind.config.ts。確 dark 類切於 <html>(非 <body>)。系統偏之模用 darkMode: "media"

第六步:增插件(可選)

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],
};

得:插件已裝為開發依,註於 tailwind.config.tsplugins 列。插件之類(如 typography 之 prose、forms 之風表元)於件可得。

敗則:插件之類不渲,驗插件已裝(npm ls @tailwindcss/typography)且加於 plugins 列。配變後重啟開發服。

  • Tailwind 類於瀏覽器正渲
  • 自定主題之值(色、字、距)行
  • cn() 用合類而無衝
  • 暗模正切
  • TypeScript 於配與件無誤
  • 生產建剪未用之風

  • content 徑缺:類不渲,察配中 content 列合文件之位
  • 類衝:用 tailwind-merge(經 cn())以防衝之用類
  • 自定值不行:確自定值於 extend 下(為加),非主題之根(為代默)
  • 暗模不切:察 darkMode 之設與 dark 類於 <html><body>

  • scaffold-nextjs-app — Tailwind 配前之項目設
  • deploy-to-vercel — 展風之應用

GitHub リポジトリ

pjt222/agent-almanac
パス: i18n/wenyan/skills/setup-tailwind-typescript
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

関連スキル

executing-plans

デザイン

executing-plansスキルは、完全な実装計画があり、それを管理されたバッチでレビューチェックポイントを設けながら実行する場合に使用します。このスキルは計画を読み込んで批判的にレビューした後、小さなバッチ(デフォルトは3タスク)でタスクを実行し、各バッチの間に進捗状況を報告してアーキテクトのレビューを受けます。これにより、品質管理チェックポイントが組み込まれた体系的な実装が保証されます。

スキルを見る

requesting-code-review

デザイン

このスキルは、コードレビュアーサブエージェントを起動し、処理を進める前に要件に対してコード変更を分析します。タスク完了後、主要な機能の実装後、またはmainブランチへのマージ前などに使用すべきです。このレビューは、現在の実装と元の計画を比較することで、問題を早期に発見するのに役立ちます。

スキルを見る

connect-mcp-server

デザイン

このスキルは、開発者がHTTP、stdio、またはSSEトランスポートを使用してMCPサーバーをClaude Codeに接続するための包括的なガイドを提供します。GitHub、Notion、カスタムAPIなどの外部サービスを統合するためのインストール、設定、認証、セキュリティについて解説しています。MCP統合のセットアップ、外部ツールの設定、またはClaudeのModel Context Protocolを扱う際にご利用ください。

スキルを見る

web-cli-teleport

デザイン

このスキルは、タスク分析に基づいて開発者がClaude Code WebとCLIインターフェースの選択を支援し、これらの環境間でのシームレスなセッションテレポーテーションを可能にします。Web、CLI、モバイル環境を切り替える際のセッション状態とコンテキストを管理することで、ワークフローを最適化します。様々な段階で異なるツールを必要とする複雑なプロジェクトにご活用ください。

スキルを見る