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

swiftui-style-driven-components

Appleのデザインパターンに沿って、ButtonStyleやLabelStyleなどのスタイルプロトコルを活用し、環境設定に基づいた柔軟なコンポーネントや拡張可能なライブラリを構築、レビューするSkill。

📜 元の英語説明(参考)

Expert guidance on SwiftUI style-driven components following Apple patterns (ButtonStyle, LabelStyle). Use when: building components with style protocols, implementing configuration patterns, adding environment-based styling, creating extensible component libraries, or reviewing component architecture.

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

一言でいうと

Appleのデザインパターンに沿って、ButtonStyleやLabelStyleなどのスタイルプロトコルを活用し、環境設定に基づいた柔軟なコンポーネントや拡張可能なライブラリを構築、レビューするSkill。

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

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

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

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

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

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して swiftui-style-driven-components.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → swiftui-style-driven-components フォルダができる
  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 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

SwiftUI スタイル駆動コンポーネント

概要

このスキルは、スタイル駆動アーキテクチャパターンに従って SwiftUI コンポーネントを構築、レビュー、拡張するための専門的なガイダンスを提供します。このパターンは、拡張性、保守性、および Apple スタイルの API 設計を重視しており、再利用可能なコンポーネントライブラリの構築に最適です。

エージェントの行動規範

  1. 新しいコンポーネントを作成する前に、2つ以上の意味的に異なるスタイルが必要かどうかを確認します。そうでない場合は、スタイルプロトコルをスキップします。
  2. Apple のパターン(ButtonStyleLabelStyle)をゴールドスタンダードとして従ってください。
  3. 設定には、ネストされた型消去ビューを使用します(LabelStyleConfiguration.Title など)。
  4. 設定イニシャライザを public として公開しないでください。
  5. 型消去のために、style.makeBodyAnyView でラップします。
  6. スタイルプロトコルには、Sendable ではなく DynamicProperty を使用します。
  7. 存在型(any [Component]Style)を使用して、環境からスタイルを読み取ります。

コアアーキテクチャの原則

  • プロトコル: [Component]Style — どのようにレンダリングするかを定義します
  • 設定: [Component]StyleConfiguration — 何をレンダリングするかを含みます
  • コンポーネント: 内部で設定を作成し、レンダリングをスタイルに委譲します
  • 環境: コンポーネントを変更せずにサブツリーのスタイル設定を可能にします

スタイルプロトコルを使用する場合

スタイルプロトコルは、次の場合に使用します。

  • 2つ以上の意味的に異なるビジュアルスタイルが必要な場合
  • 環境ベースのスタイルカスケードが必要な場合
  • 再利用可能なコンポーネントライブラリを構築する場合
  • スタイルが環境アクセス(@Environment)を必要とする場合

スタイルプロトコルは、次の場合にスキップします。

  • 単一のビジュアル表現
  • シンプルで静的な外観
  • 1回限りの内部コンポーネント
  • スタイルのカスタマイズが不要

クイック意思決定ツリー

新しいコンポーネントを構築しますか?

  1. 複数のスタイルが必要ですか? → いいえの場合は、スタイルプロトコルをスキップします
  2. 構造を作成しますreferences/component-structure.md を参照してください
  3. プロトコルを定義しますreferences/style-protocol.md を参照してください
  4. 設定を作成します → ネストされた型消去ビューパターン
  5. デフォルトスタイルを実装します → 基本的なレンダリング
  6. 環境キーを追加しますreferences/environment-keys.md を参照してください
  7. 便利なアクセサを追加しますreferences/common-patterns.md を参照してください

新しいスタイルを追加しますか?

  1. [Component]Style に準拠する構造体を作成します
  2. makeBody(configuration:) を実装します
  3. 便利なアクセサ(.myStyle)を追加します
  4. コンポーネントの変更は不要です!

コンポーネントアーキテクチャをレビューしますか?

  1. プロトコルが DynamicProperty@ViewBuilder @MainActor を使用しているか確認します
  2. 設定がネストされた型消去ビューを使用しているか確認します
  3. 設定の init が internal であることを確認します
  4. コンポーネントが style.makeBodyAnyView でラップしているか確認します
  5. 環境キーが存在型(any [Component]Style)を使用しているか検証します
  6. 新しいスタイルでコンポーネントの変更が必要ないことを確認します

トリアージプレイブック

  • コンポーネントファイル構造の作成references/component-structure.md
  • スタイルプロトコルの定義references/style-protocol.md
  • コンテンツを含む設定の作成references/style-protocol.md
  • 環境キーの設定references/environment-keys.md
  • 便利なイニシャライザの追加references/common-patterns.md
  • パラメータ化されたスタイルまたはアダプティブスタイルreferences/common-patterns.md
  • デザイントークンの使用references/design-system.md
  • スナップショットテストの作成references/testing.md
  • プレビューの整理references/previews.md
  • アクセシビリティ要件references/accessibility.md

クイックリファレンス

コンポーネント構造

[Component]/
├── EnvironmentKeys/[Component]StyleKey.swift
├── Styles/
│   ├── [Component]Style.swift
│   ├── [Component]StyleConfiguration.swift
│   └── Default[Component]Style.swift
└── [Component].swift

パターンの概要

  • スタイルプロトコル: DynamicProperty, @ViewBuilder @MainActor func makeBody
  • 設定: ネストされた struct Content: Viewprivate let _body: () -> AnyView
  • 設定 Init: internal (not public)
  • コンポーネント Body: AnyView(style.makeBody(configuration: .init(...)))
  • 環境キー: @Entry public var style: any [Component]Style = .automatic
  • View Modifier: func style(_ style: some [Component]Style) -> some View

ベストプラクティス

実行すること

  • スタイルプロトコルには DynamicProperty を使用します
  • 設定にはネストされた型消去ビューを使用します
  • 設定イニシャライザを internal にします
  • style.makeBodyAnyView でラップします
  • マジックナンバーではなくデザイントークンを使用します
  • 便利なアクセサ(.compact.outlined)を提供します

実行しないこと

  • プロトコルに明示的な Sendable を追加しないでください
  • 設定イニシャライザを public にしないでください
  • 設定をコンポーネントイニシャライザに渡さないでください
  • コンテンツプロパティをスタイルプロトコルに配置しないでください
  • 単一バリアントコンポーネントにスタイルプロトコルを使用しないでください
  • AnyView を設定プロパティタイプとして直接使用しないでください

レビューチェックリスト

アーキテクチャ

  • [ ] スタイルプロトコルは DynamicProperty を使用しています
  • [ ] makeBody@ViewBuilder @MainActor を持っています
  • [ ] 設定はネストされた型消去ビューを使用しています
  • [ ] 設定 init は internal です
  • [ ] コンポーネントは style.makeBodyAnyView でラップしています
  • [ ] 新しいスタイルでコンポーネントの変更は不要です

環境

  • [ ] @Entry マクロを使用しています
  • [ ] 存在型(any [Component]Style)として保存します
  • [ ] Modifier は不透明なパラメータ(some [Component]Style)を使用します
  • [ ] デフォルト値が提供されています(.automatic

品質

  • [ ] プレビューはすべてのスタイルをカバーしています(references/previews.md を参照してください)
  • [ ] スナップショットテストが存在します(references/testing.md を参照してください)
  • [ ] アクセシビリティがサポートされています(references/accessibility.md を参照してください)
  • [ ] デザイントークンが使用されています(references/design-system.md を参照してください)

参照ファイル

  • references/component-structure.md — 新しいコンポーネントの作成、ファイル構成
  • references/style-protocol.md — プロトコル定義、設定パターン、スタイルの追加
  • references/environment-keys.md — 環境インジェクション、使用パターン
  • references/common-patterns.md — 便利なイニシャライザ/アクセサ、パラメータ化されたスタイル
  • references/testing.md — スナップショットテスト、テスト構成
  • references/previews.md — プレビュー構造、チェックリスト
  • **`referen

(原文がここで切り詰められています)

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

SwiftUI Style-Driven Components

Overview

This skill provides expert guidance on building, reviewing, and extending SwiftUI components following the style-driven architecture pattern. This pattern emphasizes extensibility, maintainability, and Apple-style API design, making it ideal for building reusable component libraries.

Agent Behavior Contract

  1. Before creating a new component, verify it needs 2+ meaningfully different styles. If not, skip the style protocol.
  2. Follow Apple's patterns (ButtonStyle, LabelStyle) as the gold standard.
  3. Use nested type-erased views in configuration (like LabelStyleConfiguration.Title).
  4. Never expose configuration initializers as public.
  5. Wrap style.makeBody in AnyView for type erasure.
  6. Use DynamicProperty for style protocols, not Sendable.
  7. Read styles from environment using existential type (any [Component]Style).

Core Architecture Principles

  • Protocol: [Component]Style — defines HOW to render
  • Configuration: [Component]StyleConfiguration — contains WHAT to render
  • Component: Creates configuration internally, delegates rendering to style
  • Environment: Enables subtree styling without modifying components

When to Use Style Protocol

Use style protocol when:

  • 2+ meaningfully different visual styles needed
  • Environment-based style cascading desired
  • Building reusable component library
  • Styles need environment access (@Environment)

Skip style protocol when:

  • Single visual representation
  • Simple, static appearance
  • One-off internal component
  • No style customization needed

Quick Decision Tree

Building a new component?

  1. Needs multiple styles? → If no, skip style protocol
  2. Create structure → See references/component-structure.md
  3. Define protocol → See references/style-protocol.md
  4. Create configuration → Nested type-erased views pattern
  5. Implement default style → Basic rendering
  6. Add environment key → See references/environment-keys.md
  7. Add convenience accessors → See references/common-patterns.md

Adding a new style?

  1. Create struct conforming to [Component]Style
  2. Implement makeBody(configuration:)
  3. Add convenience accessor (.myStyle)
  4. No component changes needed!

Reviewing component architecture?

  1. Check protocol uses DynamicProperty, @ViewBuilder @MainActor
  2. Verify configuration uses nested type-erased views
  3. Confirm configuration init is internal
  4. Check component wraps style.makeBody in AnyView
  5. Validate environment key uses existential (any [Component]Style)
  6. Ensure new styles don't require component changes

Triage Playbook

  • Creating component file structurereferences/component-structure.md
  • Defining style protocolreferences/style-protocol.md
  • Creating configuration with contentreferences/style-protocol.md
  • Setting up environment keysreferences/environment-keys.md
  • Adding convenience initializersreferences/common-patterns.md
  • Parameterized or adaptive stylesreferences/common-patterns.md
  • Using design tokensreferences/design-system.md
  • Writing snapshot testsreferences/testing.md
  • Organizing previewsreferences/previews.md
  • Accessibility requirementsreferences/accessibility.md

Quick Reference

Component Structure

[Component]/
├── EnvironmentKeys/[Component]StyleKey.swift
├── Styles/
│   ├── [Component]Style.swift
│   ├── [Component]StyleConfiguration.swift
│   └── Default[Component]Style.swift
└── [Component].swift

Pattern Summary

  • Style Protocol: DynamicProperty, @ViewBuilder @MainActor func makeBody
  • Configuration: Nested struct Content: View with private let _body: () -> AnyView
  • Configuration Init: internal (not public)
  • Component Body: AnyView(style.makeBody(configuration: .init(...)))
  • Environment Key: @Entry public var style: any [Component]Style = .automatic
  • View Modifier: func style(_ style: some [Component]Style) -> some View

Best Practices

DO

  • Use DynamicProperty for style protocols
  • Use nested type-erased views in configuration
  • Make configuration initializers internal
  • Wrap style.makeBody in AnyView
  • Use design tokens, not magic numbers
  • Provide convenience accessors (.compact, .outlined)

DON'T

  • Add explicit Sendable to protocols
  • Make configuration initializers public
  • Pass configuration to component initializer
  • Put content properties in style protocol
  • Use style protocol for single-variant components
  • Use AnyView directly as configuration property type

Review Checklist

Architecture

  • [ ] Style protocol uses DynamicProperty
  • [ ] makeBody has @ViewBuilder @MainActor
  • [ ] Configuration uses nested type-erased views
  • [ ] Configuration init is internal
  • [ ] Component wraps style.makeBody in AnyView
  • [ ] New styles don't require component changes

Environment

  • [ ] Uses @Entry macro
  • [ ] Stores as existential (any [Component]Style)
  • [ ] Modifier uses opaque parameter (some [Component]Style)
  • [ ] Default value provided (.automatic)

Quality

  • [ ] Previews cover all styles (see references/previews.md)
  • [ ] Snapshot tests exist (see references/testing.md)
  • [ ] Accessibility supported (see references/accessibility.md)
  • [ ] Design tokens used (see references/design-system.md)

Reference Files

  • references/component-structure.md — Creating new component, file organization
  • references/style-protocol.md — Protocol definition, configuration pattern, adding styles
  • references/environment-keys.md — Environment injection, usage patterns
  • references/common-patterns.md — Convenience initializers/accessors, parameterized styles
  • references/testing.md — Snapshot tests, test organization
  • references/previews.md — Preview structure, checklist
  • references/design-system.md — Design tokens, typography, colors
  • references/accessibility.md — Labels, identifiers, Dynamic Type

Philosophy

Style-driven components prioritize:

  1. Extensibility — Add styles without modifying components
  2. Apple Patterns — Follow ButtonStyle, LabelStyle conventions
  3. Simplicity — Skip style protocol for single-variant components
  4. Type Safety — Generic APIs with internal type erasure
  5. Consistency — All components follow same patterns