jpskill.com
🛠️ 開発・MCP コミュニティ

css-development-refactor

既存のCSSを、インラインスタイルやユーティリティクラスから、ダークモード対応やテストも備えた、より意味のある構造のCSSに書き換えて整理するSkill。

📜 元の英語説明(参考)

This skill should be used when refactoring existing CSS from inline styles or utility classes to semantic patterns. Triggers on "refactor CSS", "extract styles", "consolidate CSS", "convert inline", "clean up styles", "migrate to semantic". Transforms to semantic classes with dark mode and tests.

🇯🇵 日本人クリエイター向け解説

一言でいうと

既存のCSSを、インラインスタイルやユーティリティクラスから、ダークモード対応やテストも備えた、より意味のある構造のCSSに書き換えて整理するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o css-development-refactor.zip https://jpskill.com/download/16709.zip && unzip -o css-development-refactor.zip && rm css-development-refactor.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/16709.zip -OutFile "$d\css-development-refactor.zip"; Expand-Archive "$d\css-development-refactor.zip" -DestinationPath $d -Force; ri "$d\css-development-refactor.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して css-development-refactor.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → css-development-refactor フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

CSS開発: リファクタリング

概要

既存のCSSをセマンティックなコンポーネントパターンに変換します。

  • インラインスタイルをセマンティックなクラスに抽出
  • マークアップからのユーティリティクラスを@applyコンポジションに統合
  • ダークモードのバリアントを追加
  • テストカバレッジを追加
  • 既存の機能の維持 (動作に影響を与えないリファクタリング)

これはcss-developmentのサブスキルです - 通常、メインスキルを通じて自動的に呼び出されます。

このスキルが適用される場合

以下の場合に使用します。

  • インラインスタイルをセマンティックなクラスに変換する場合
  • マークアップから繰り返されるユーティリティの組み合わせを抽出する場合
  • 純粋なユーティリティファーストからセマンティックコンポーネントに移行する場合
  • 既存のCSSにダークモードを追加する場合
  • 散在または重複したCSSを整理する場合

パターンリファレンス

このスキルは、メインのcss-developmentスキルで文書化されているパターンに向けてリファクタリングします。

セマンティックな命名: .button-primary であり .btn-blue ではない Tailwindコンポジション: @applyを使用してユーティリティを構成 ダークモード: dark:バリアントを含める コンポジションファースト: 新しいクラスを作成する前に既存のクラスを再利用 テストカバレッジ: 静的なCSS + コンポーネントレンダリングテスト

ワークフロー

このスキルが呼び出されたら、TodoWriteチェックリストを作成し、体系的にリファクタリングします。

使用状況の通知

「css-development:refactorスキルを使用して、このCSSをセマンティックなコンポーネントパターンに変換します。」

TodoWriteチェックリストの作成

TodoWriteツールを使用します。

CSSのリファクタリング:
- [ ] 既存のCSSの分析 (リファクタリングが必要なものを特定)
- [ ] 繰り返されるパターンの発見 (重複したユーティリティの組み合わせを探す)
- [ ] 既存のコンポーネントの確認 (パターンが既に存在するかどうかを確認)
- [ ] セマンティックなクラスへの抽出 (@applyを使用して新しいクラスを作成)
- [ ] ダークモードの追加 (新しいクラスにdark:バリアントを追加)
- [ ] マークアップの更新 (インライン/ユーティリティクラスをセマンティックな名前に置き換え)
- [ ] テストの追加 (静的なCSSとレンダリングテストを作成)
- [ ] コンポーネントのドキュメント化 (使用方法のコメントを追加)
- [ ] 動作が変更されていないことの確認 (視覚的な出力が元のものと一致することを確認)

リファクタリングチェックリストの詳細

ステップ1: 既存のCSSの分析

アクション: リファクタリングが必要なCSSを読んで理解する

探すもの:

  • コンポーネントファイル内のインラインスタイル
  • マークアップ内の繰り返されるユーティリティクラスの組み合わせ
  • 複数のファイルに散在するCSS
  • ダークモードのサポートの欠如
  • セマンティックなクラス名の欠如

リファクタリングするパターンの例:

// インラインスタイル
<button style={{ background: 'indigo', padding: '1.5rem 2rem' }}>Click</button>

// マークアップ内の繰り返されるユーティリティ
<button class="bg-indigo-500 hover:bg-indigo-700 px-6 py-3 rounded-lg text-white">
  Click me
</button>
<button class="bg-indigo-500 hover:bg-indigo-700 px-6 py-3 rounded-lg text-white">
  Submit
</button>

// 非セマンティックなCSS
.btn-blue {
  background: blue;
  padding: 12px 24px;
}

キャプチャ:

  • ファイルの場所
  • パターンの頻度 (繰り返される回数)
  • 現在のアプローチ (インライン、ユーティリティ、古いCSS)

分析が完了したら完了としてマークします。


ステップ2: 繰り返されるパターンの発見

アクション: セマンティックなクラスにすべき重複したユーティリティの組み合わせを特定する

Grepツールを使用して、繰り返されるパターンを検索します。

# 一般的なユーティリティの組み合わせを検索
grep -r "bg-indigo-500 hover:bg-indigo-700 px-6 py-3" .
grep -r "rounded-lg shadow-md p-6" .

パターンの分類:

  • 高頻度 (5回以上): 確実に抽出
  • 中頻度 (2〜4回): おそらく抽出
  • 低頻度 (1回): そのままにするか、既存のクラスを構成する

各パターンについて:

  • 発生回数をカウント
  • ファイルの場所をリスト
  • セマンティックな目的を特定 (これはボタンですか?カードですか?バッジですか?)

パターンがカタログ化されたら完了としてマークします。


ステップ3: 既存のコンポーネントの確認

アクション: styles/components.cssを読んで、パターンが既に存在するかどうかを確認する

新しいクラスを作成する前に、以下を確認してください。

  • 同様のクラスが既に存在するか?
  • 既存のクラスを構成できるか?
  • 既存のクラスのバリアントが機能するか?

例:

発見されたパターン: bg-indigo-500 hover:bg-indigo-700 px-6 py-3 rounded-lg text-white
確認: .button-primaryは既に存在するか? はい
解決策: 新しいクラスを作成する代わりに.button-primaryを使用する

各パターンの決定:

  • ✅ 既存のクラスをそのまま使用
  • ✅ 既存のクラスを構成
  • ✅ 既存のクラスのバリアントを作成
  • ⚠️ 新しいクラスを作成 (既存の解決策がない場合のみ)

再利用の機会が特定されたら完了としてマークします。


ステップ4: セマンティックなクラスへの抽出

アクション: 抽出が必要なパターンについて、styles/components.cssに新しいセマンティックなクラスを作成する

抽出される各パターンについて:

  1. 既存のパターンに従ってセマンティックな名前を選択
  2. @applyを使用してCSSクラスを作成
  3. ダークモードのバリアントを含める
  4. ドキュメントのコメントを追加

抽出の例:

抽出前 (マークアップ内):

<button class="bg-indigo-500 hover:bg-indigo-700 px-6 py-3 rounded-lg text-white transition-all duration-200">
  Click me
</button>

抽出後 (components.css内):

/* プライマリボタン - ホバー状態を持つメインのコールトゥアクションボタン
   使用方法: <button className="button-primary">Click me</button> */
.button-primary {
  @apply bg-indigo-500 hover:bg-indigo-700 dark:bg-indigo-600 dark:hover:bg-indigo-800;
  @apply px-6 py-3 rounded-lg text-white;
  @apply transition-all duration-200;
}

Editツールを使用して、新しいクラスをcomponents.cssに追加します。

すべてのセマンティックなクラスが作成されたら完了としてマークします。


ステップ5: ダークモードの追加

アクション: すべての新しい/リファクタリングされたクラスにdark:バリアントがあることを確認する

ステップ4で作成された各クラスについて:

  • 背景にdark:バリアントを追加
  • テキストの色にdark:バリアントを追加
  • 境界線にdark:バリアントを追加
  • ダークモードでテスト (可能な場合)

パターン:

.component {
  @apply bg-white dark:bg-gray-800;
  @apply text-gray-900 dark:text-white;
  @apply border-gray-200 dark:border-gray-700;
}

ダークモードのカバレッジが追加されたら完了としてマークします。


ステップ6: マークアップの更新

アクション: インラインスタイルとユーティリティを置き換えます

📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

CSS Development: Refactor

Overview

Transforms existing CSS into semantic component patterns:

  • Extract inline styles to semantic classes
  • Consolidate utility classes from markup into @apply compositions
  • Add dark mode variants
  • Add test coverage
  • Preserve existing functionality (behavior-neutral refactoring)

This is a sub-skill of css-development - typically invoked automatically via the main skill.

When This Skill Applies

Use when:

  • Converting inline styles to semantic classes
  • Extracting repeated utility combinations from markup
  • Migrating from pure utility-first to semantic components
  • Adding dark mode to existing CSS
  • Cleaning up scattered or duplicated CSS

Pattern Reference

This skill refactors toward patterns documented in the main css-development skill:

Semantic naming: .button-primary not .btn-blue Tailwind composition: Use @apply to compose utilities Dark mode: Include dark: variants Composition first: Reuse existing classes before creating new Test coverage: Static CSS + component rendering tests

Workflow

When this skill is invoked, create a TodoWrite checklist and refactor systematically.

Announce Usage

"I'm using the css-development:refactor skill to transform this CSS into semantic component patterns."

Create TodoWrite Checklist

Use the TodoWrite tool:

Refactoring CSS:
- [ ] Analyze existing CSS (identify what needs refactoring)
- [ ] Find repeated patterns (look for duplicated utility combinations)
- [ ] Check existing components (see if patterns already exist)
- [ ] Extract to semantic classes (create new classes using @apply)
- [ ] Include dark mode (add dark: variants to new classes)
- [ ] Update markup (replace inline/utility classes with semantic names)
- [ ] Add tests (write static CSS and rendering tests)
- [ ] Document components (add usage comments)
- [ ] Verify behavior unchanged (ensure visual output matches original)

Refactoring Checklist Details

Step 1: Analyze Existing CSS

Action: Read and understand the CSS that needs refactoring

Look for:

  • Inline styles in component files
  • Repeated utility class combinations in markup
  • CSS scattered across multiple files
  • Missing dark mode support
  • Lack of semantic class names

Example patterns to refactor:

// Inline styles
<button style={{ background: 'indigo', padding: '1.5rem 2rem' }}>Click</button>

// Repeated utilities in markup
<button class="bg-indigo-500 hover:bg-indigo-700 px-6 py-3 rounded-lg text-white">
  Click me
</button>
<button class="bg-indigo-500 hover:bg-indigo-700 px-6 py-3 rounded-lg text-white">
  Submit
</button>

// Non-semantic CSS
.btn-blue {
  background: blue;
  padding: 12px 24px;
}

Capture:

  • File locations
  • Pattern frequency (how many times repeated)
  • Current approach (inline, utilities, old CSS)

Mark as completed when analysis is done.


Step 2: Find Repeated Patterns

Action: Identify duplicated utility combinations that should become semantic classes

Use Grep tool to search for repeated patterns:

# Search for common utility combinations
grep -r "bg-indigo-500 hover:bg-indigo-700 px-6 py-3" .
grep -r "rounded-lg shadow-md p-6" .

Categorize patterns:

  • High frequency (5+ occurrences): Definitely extract
  • Medium frequency (2-4 occurrences): Probably extract
  • Low frequency (1 occurrence): Keep as-is or compose existing classes

For each pattern:

  • Count occurrences
  • List file locations
  • Identify semantic purpose (is this a button? card? badge?)

Mark as completed when patterns are cataloged.


Step 3: Check Existing Components

Action: Read styles/components.css to see if patterns already exist

Before creating new classes, check:

  • Does a similar class already exist?
  • Can existing classes be composed?
  • Would a variant of an existing class work?

Example:

Pattern found: bg-indigo-500 hover:bg-indigo-700 px-6 py-3 rounded-lg text-white
Check: Does .button-primary already exist? YES
Solution: Use .button-primary instead of creating new class

Decision for each pattern:

  • ✅ Use existing class as-is
  • ✅ Compose existing classes
  • ✅ Create variant of existing class
  • ⚠️ Create new class (only if no existing solution)

Mark as completed when reuse opportunities are identified.


Step 4: Extract to Semantic Classes

Action: Create new semantic classes in styles/components.css for patterns that need extraction

For each pattern being extracted:

  1. Choose semantic name following existing patterns
  2. Write CSS class using @apply
  3. Include dark mode variants
  4. Add documentation comment

Example extraction:

Before (in markup):

<button class="bg-indigo-500 hover:bg-indigo-700 px-6 py-3 rounded-lg text-white transition-all duration-200">
  Click me
</button>

After (in components.css):

/* Primary button - Main call-to-action button with hover states
   Usage: <button className="button-primary">Click me</button> */
.button-primary {
  @apply bg-indigo-500 hover:bg-indigo-700 dark:bg-indigo-600 dark:hover:bg-indigo-800;
  @apply px-6 py-3 rounded-lg text-white;
  @apply transition-all duration-200;
}

Use Edit tool to add each new class to components.css

Mark as completed when all semantic classes are created.


Step 5: Include Dark Mode

Action: Ensure all new/refactored classes have dark: variants

For each class created in Step 4:

  • Add dark: variants for backgrounds
  • Add dark: variants for text colors
  • Add dark: variants for borders
  • Test in dark mode (if possible)

Pattern:

.component {
  @apply bg-white dark:bg-gray-800;
  @apply text-gray-900 dark:text-white;
  @apply border-gray-200 dark:border-gray-700;
}

Mark as completed when dark mode coverage is added.


Step 6: Update Markup

Action: Replace inline styles and utility classes with semantic class names

For each file using the old pattern:

  1. Read the file with Read tool
  2. Use Edit tool to replace old pattern with semantic class
  3. Verify the replacement is correct

Example:

Before:

<button class="bg-indigo-500 hover:bg-indigo-700 px-6 py-3 rounded-lg text-white">
  Click me
</button>

After:

<button class="button-primary">
  Click me
</button>

Handle custom classes:

<!-- If there were additional custom classes, preserve them -->
<button class="button-primary w-full mt-4">
  Click me
</button>

Track changes:

  • Count files updated
  • Count instances replaced
  • Note any edge cases

Mark as completed when all markup is updated.


Step 7: Add Tests

Action: Add test coverage for refactored components

Static CSS test in styles/__tests__/components.test.ts:

it('should have button-primary class', () => {
  const content = readFileSync('styles/components.css', 'utf-8');
  expect(content).toContain('.button-primary');
});

it('should have dark mode variants in button-primary', () => {
  const content = readFileSync('styles/components.css', 'utf-8');
  expect(content).toContain('dark:bg-indigo');
});

Component rendering test (if applicable):

it('applies button-primary class after refactor', () => {
  render(<Button variant="primary">Click</Button>);
  expect(screen.getByRole('button')).toHaveClass('button-primary');
});

Run tests to ensure they pass:

npm test

Mark as completed when tests are added and passing.


Step 8: Document Components

Action: Ensure all refactored classes have documentation

Documentation includes:

  • Comment in CSS explaining purpose
  • Usage example
  • Migration notes (if helpful)

Example:

/* Primary button - Main CTA button (refactored from inline utilities)
   Usage: <button className="button-primary">Click me</button>
   Replaces: bg-indigo-500 hover:bg-indigo-700 px-6 py-3 rounded-lg text-white */
.button-primary {
  @apply bg-indigo-500 hover:bg-indigo-700 dark:bg-indigo-600 dark:hover:bg-indigo-800;
  @apply px-6 py-3 rounded-lg text-white;
  @apply transition-all duration-200;
}

Mark as completed when documentation is added.


Step 9: Verify Behavior Unchanged

Action: Ensure visual output and behavior match the original

Verification steps:

  1. Run tests (if project has them):

    npm test
  2. Visual inspection (if possible):

    • Start dev server
    • Check refactored components look the same
    • Test in light and dark mode
    • Test interactive states (hover, focus, active)
  3. Check for regressions:

    • Compare before/after screenshots (if available)
    • Verify no console errors
    • Check responsive behavior

If behavior changed:

  • Identify the difference
  • Fix the semantic class to match original behavior
  • Re-test

Behavior must be preserved - refactoring should be visually neutral

Mark as completed when behavior is verified unchanged.


Completion

When all checklist items are completed:

  1. Generate summary of refactoring work:
## CSS Refactoring Summary

### Changes Made

**Semantic classes created:**
- `.button-primary` (extracted from 8 instances across 5 files)
- `.card` (extracted from 12 instances across 7 files)
- `.badge-success` (extracted from 4 instances across 3 files)

**Files modified:**
- `styles/components.css` (+45 lines, 3 new classes)
- `components/Button.tsx` (replaced utilities with .button-primary)
- `components/Card.tsx` (replaced utilities with .card)
- `components/Badge.tsx` (replaced utilities with .badge-success)
- `styles/__tests__/components.test.ts` (+12 lines, 3 new tests)

**Dark mode support:**
- ✅ All refactored classes include dark: variants
- ✅ Tested in both light and dark mode

**Test coverage:**
- ✅ Static CSS tests added for all new classes
- ✅ Component rendering tests updated
- ✅ All tests passing

**Behavior verification:**
- ✅ Visual output matches original
- ✅ No console errors
- ✅ Interactive states work correctly

### Impact

**Code reduction:**
- Removed 247 lines of repeated utility classes from markup
- Added 45 lines of semantic CSS
- Net reduction: 202 lines

**Maintainability:**
- Styling centralized in components.css
- Changes now made in one place instead of many
- Consistent component appearance

**Dark mode:**
- Added dark mode support that didn't exist before
- All components now work in light and dark themes
  1. Suggest next steps:

    • Commit the refactoring
    • Document the new patterns for the team
    • Continue refactoring other components
  2. Offer validation: "Would you like me to validate the refactored CSS using the css-development:validate skill?"

Mark as completed when summary is presented.