canvas-styling-conventions
Tailwind CSS 4のテーマトークンやパターンを用いてCanvasコンポーネントのスタイルを統一し、デザイン変更やコンポーネントの修正時に一貫性のあるスタイルを適用・管理するSkill。
📜 元の英語説明(参考)
Style Canvas components with Tailwind CSS 4 theme tokens and approved utility patterns. Use when (1) Creating a new component, (2) Adding colors or styling to components, (3) Working with Tailwind theme tokens, (4) Adding or updating design tokens in global.css, (5) Creating color/style props, (6) Any change where component props are added/removed/renamed/retyped and can affect rendered styles. Covers @theme variables, CVA variants, and cn() utility.
🇯🇵 日本人クリエイター向け解説
Tailwind CSS 4のテーマトークンやパターンを用いてCanvasコンポーネントのスタイルを統一し、デザイン変更やコンポーネントの修正時に一貫性のあるスタイルを適用・管理するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o canvas-styling-conventions.zip https://jpskill.com/download/9236.zip && unzip -o canvas-styling-conventions.zip && rm canvas-styling-conventions.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/9236.zip -OutFile "$d\canvas-styling-conventions.zip"; Expand-Archive "$d\canvas-styling-conventions.zip" -DestinationPath $d -Force; ri "$d\canvas-styling-conventions.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
canvas-styling-conventions.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
canvas-styling-conventionsフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
技術スタック
| 技術 | 目的 |
|---|---|
| Tailwind CSS 4.1+ | スタイリング |
| class-variance-authority (CVA) | コンポーネントのバリアント |
clsx + tailwind-merge via cn() |
クラス名のマージ |
スタイリングにはこれらの依存関係のみを使用してください。サードパーティの CSS ライブラリを追加したり、新しいスタイリングユーティリティを作成したりしないでください。
スタイリングの規約
global.cssで定義されている Tailwind のテーマカラー (primary-*,gray-*) を使用してください。- ハードコードされたカラー値を避け、代わりにテーマトークンを使用してください。
- 既存の例から、focus、hover、および active の状態パターンに従ってください。
cn() ユーティリティ
Tailwind クラスをマージするには cn() を使用します。これは、条件付きクラスのための clsx と、競合するユーティリティを解決するための tailwind-merge を組み合わせたものです。次のいずれかのソースからインポートします。
import { cn } from "@/lib/utils";
// or
import { cn } from "drupal-canvas";
使用例:
const Button = ({ variant, className, children }) => (
<button
className={cn(
"rounded px-4 py-2",
variant === "primary" && "bg-primary-600 text-white",
variant === "secondary" && "bg-gray-200 text-gray-800",
className,
)}
>
{children}
</button>
);
スタイルをカスタマイズするための className の受け入れ
すべてのコンポーネントは、スタイルのオーバーライドを可能にするために className プロパティを受け入れる必要があります。コンシューマクラスが優先されるように、最後の引数として cn() に渡します。
const Card = ({ colorScheme, className, children }) => (
<div className={cn(cardVariants({ colorScheme }), className)}>{children}</div>
);
className は実装/構成プロパティであり、エディタプロパティではありません。component.yml に className を追加したり、必須としてマークしたり、Canvas メタデータに表示したりしないでください。
Tailwind 4 のテーマ変数
Canvas プロジェクトでは、Tailwind CSS 4 の @theme ディレクティブを使用して、global.css でデザイントークンを定義します。@theme { } 内で定義された変数は、Tailwind ユーティリティクラスとして自動的に利用可能になります。
利用可能なデザイントークンについては、常に global.css を確認してください。 @theme ブロックは、色、フォント、ブレークポイント、およびその他のデザイントークンの信頼できる情報源です。
テーマ変数がユーティリティクラスにどのようにマッピングされるか
@theme で CSS 変数を定義すると、Tailwind 4 は変数の名前空間プレフィックスに基づいて、対応するユーティリティクラスを自動的に生成します。
@theme の CSS 変数 |
生成されるユーティリティクラス |
|---|---|
--color-primary-600: #xxx |
bg-primary-600, text-primary-600, border-primary-600 |
--color-gray-100: #xxx |
bg-gray-100, text-gray-100, border-gray-100 |
--font-sans: ... |
font-sans |
--breakpoint-md: 48rem |
md: レスポンシブプレフィックス |
パターンは次のとおりです。--{namespace}-{name} は {utility}-{name} になります。
例
global.css に次の定義が与えられた場合:
@theme {
--color-primary-600: #1899cb;
--color-primary-700: #1487b4;
}
これらの色は、色を受け入れる任意のユーティリティで使用できます。
// 正しい
<button className="bg-primary-600 hover:bg-primary-700 text-white">
Click me
</button>
// 間違い
<button className="bg-[#1899cb] text-white hover:bg-[#1487b4]">Click me</button>
任意の値 (例: bg-[#xxx]) は、テーマ変数を追加することが過剰になるまれな、一度限りのケースでは許容されます。ただし、色が複数の場所に表示される場合、またはブランド/デザインシステムの値を表す場合は、代わりに @theme に追加してください。
セマンティックエイリアス
テーマ変数は、他の変数を参照してセマンティックエイリアスを作成できます。
@theme {
--color-primary-700: #1487b4;
--color-primary-dark: var(--color-primary-700);
}
bg-primary-700 と bg-primary-dark の両方が機能します。意図をより適切に表現する場合 (例: より暗いブランドバリアントの場合は primary-dark) は、セマンティックエイリアスを使用してください。
テーマ変数の追加または更新
デザインで、まだテーマで定義されていない色、フォント、またはその他の値が必要な場合は、コンポーネントに値をハードコーディングするのではなく、global.css の @theme ブロックに追加してください。
新しいテーマ変数を追加する場合:
- デザインが新しいブランドカラーまたはシェードを導入する場合
- 既存の値のセマンティックエイリアスが必要な場合 (例:
--color-accent) - デザインが特定のスペーシング、フォント、またはブレークポイント値を繰り返し使用する場合
既存のテーマ変数を更新する場合:
- ブランドカラーが変更された場合 (16 進数値を更新)
- デザインシステム全体でデザイントークンを調整する必要がある場合
例 - 新しい色の追加:
@theme {
/* 既存のトークン */
--color-primary-600: #1899cb;
/* 成功状態の新しいトークン */
--color-success: #22c55e;
--color-success-dark: #16a34a;
}
追加後、すぐに bg-success、text-success-dark などを使用できます。
テーマを整理してください。 関連するトークンを、その目的を説明するコメントとともにグループ化します。global.css の既存の命名規則に従ってください (例: primary-100 から primary-900 までの番号付きシェード、primary-dark のようなセマンティック名)。
カラープロパティは、カラーコードではなくバリアントを使用する必要があります
ユーザーがカラーコード (16 進数値、RGB、HSL、または任意の生のカラーストリング) を渡せるプロパティを作成しないでください。 代わりに、global.css のデザイントークンにマッピングする、CVA を使用した人間が読めるバリアントの小さなセットを定義します。
利用可能なデザイントークンについては、常に global.css を確認してください。 そこで定義されているトークン (primary-*、gray-* など) は、カラー値の信頼できる情報源です。
間違い - 生のカラー値を許可する:
# 間違い
props:
properties:
backgroundColor:
title: Background Color
type: string
examples:
- "#3b82f6"
// 間違い
const Card = ({ backgroundColor }) => (
<div style={{ backgroundColor }}>{/* ... */}</div>
);
正しい - デザイントークンで CVA バリアントを使用する:
# 正しい
props:
properties:
colorScheme:
title: Color Scheme
type: string
enum:
- primary
- secondary
import { cva } from "class-variance-authority";
const cardVariants = cva("rounded-md p-4", {
variants: {
colorScheme: {
primary: "bg-primary-100 text-primary-900",
secondary: "bg-gray-100 text-gray-900",
},
},
defaultVariants: {
colorScheme: "primary",
},
});
const Card = ({ colorScheme, children }) => (
<div className={cardVariants({ colorScheme })}>{children}</div>
); 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Technology stack
| Technology | Purpose |
|---|---|
| Tailwind CSS 4.1+ | Styling |
| class-variance-authority (CVA) | Component variants |
clsx + tailwind-merge via cn() |
Class name merging |
Only use these dependencies for styling. Do not add third-party CSS libraries or create new styling utilities.
Styling conventions
- Use Tailwind's theme colors (
primary-*,gray-*) defined inglobal.css. - Avoid hardcoded color values; use theme tokens instead.
- Follow the existing focus, hover, and active state patterns from examples.
The cn() utility
Use cn() to merge Tailwind classes. It combines clsx for conditional classes
with tailwind-merge to resolve conflicting utilities. Import from either
source:
import { cn } from "@/lib/utils";
// or
import { cn } from "drupal-canvas";
Example usage:
const Button = ({ variant, className, children }) => (
<button
className={cn(
"rounded px-4 py-2",
variant === "primary" && "bg-primary-600 text-white",
variant === "secondary" && "bg-gray-200 text-gray-800",
className,
)}
>
{children}
</button>
);
Accept className for style customization
Every component should accept a className prop to allow style overrides. Pass
it to cn() as the last argument so consumer classes take precedence.
const Card = ({ colorScheme, className, children }) => (
<div className={cn(cardVariants({ colorScheme }), className)}>{children}</div>
);
className is an implementation/composition prop, not an editor prop. Do not
add className to component.yml, do not mark it as required, and do not
surface it in Canvas metadata.
Tailwind 4 theme variables
Canvas projects use Tailwind CSS 4's @theme directive to define design tokens
in global.css. Variables defined inside @theme { } automatically become
available as Tailwind utility classes.
Always check global.css for available design tokens. The @theme block is
the source of truth for colors, fonts, breakpoints, and other design tokens.
How theme variables map to utility classes
When you define a CSS variable in @theme, Tailwind 4 automatically generates
corresponding utility classes based on the variable's namespace prefix:
CSS Variable in @theme |
Generated Utility Classes |
|---|---|
--color-primary-600: #xxx |
bg-primary-600, text-primary-600, border-primary-600 |
--color-gray-100: #xxx |
bg-gray-100, text-gray-100, border-gray-100 |
--font-sans: ... |
font-sans |
--breakpoint-md: 48rem |
md: responsive prefix |
The pattern is: --{namespace}-{name} becomes {utility}-{name}.
Examples
Given this definition in global.css:
@theme {
--color-primary-600: #1899cb;
--color-primary-700: #1487b4;
}
You can use these colors with any color-accepting utility:
// Correct
<button className="bg-primary-600 hover:bg-primary-700 text-white">
Click me
</button>
// Wrong
<button className="bg-[#1899cb] text-white hover:bg-[#1487b4]">Click me</button>
Arbitrary values (e.g., bg-[#xxx]) are acceptable for rare, one-off cases
where adding a theme variable would be overkill. However, if a color appears in
multiple places or represents a brand/design system value, add it to @theme
instead.
Semantic aliases
Theme variables can reference other variables to create semantic aliases:
@theme {
--color-primary-700: #1487b4;
--color-primary-dark: var(--color-primary-700);
}
Both bg-primary-700 and bg-primary-dark will work. Use semantic aliases when
they better express intent (e.g., primary-dark for a darker brand variant).
Adding or updating theme variables
When a design requires a color, font, or other value not yet defined in the
theme, add it to the @theme block in global.css rather than hardcoding the
value in a component.
When to add new theme variables:
- A design introduces a new brand color or shade
- You need a semantic alias for an existing value (e.g.,
--color-accent) - The design uses a specific spacing, font, or breakpoint value repeatedly
When to update existing theme variables:
- The brand colors change (update the hex values)
- Design tokens need adjustment across the system
Example - adding a new color:
@theme {
/* Existing tokens */
--color-primary-600: #1899cb;
/* New token for a success state */
--color-success: #22c55e;
--color-success-dark: #16a34a;
}
After adding, you can immediately use bg-success, text-success-dark, etc.
Keep the theme organized. Group related tokens together with comments
explaining their purpose. Follow the existing naming conventions in global.css
(e.g., numbered shades like primary-100 through primary-900, semantic names
like primary-dark).
Color props must use variants, not color codes
Never create props that allow users to pass color codes (hex values, RGB,
HSL, or any raw color strings). Instead, define a small set of human-readable
variants using CVA that map to the design tokens in global.css.
Always check global.css for available design tokens. The tokens defined
there (such as primary-*, gray-*, etc.) are the source of truth for color
values.
Wrong - allowing raw color values:
# Wrong
props:
properties:
backgroundColor:
title: Background Color
type: string
examples:
- "#3b82f6"
// Wrong
const Card = ({ backgroundColor }) => (
<div style={{ backgroundColor }}>{/* ... */}</div>
);
Correct - using CVA variants with design tokens:
# Correct
props:
properties:
colorScheme:
title: Color Scheme
type: string
enum:
- default
- primary
- muted
- dark
meta:enum:
default: Default (White)
primary: Primary (Blue)
muted: Muted (Light Gray)
dark: Dark
examples:
- default
// Correct
import { cva } from "class-variance-authority";
const cardVariants = cva("rounded-lg p-6", {
variants: {
colorScheme: {
default: "bg-white text-black",
primary: "bg-primary-600 text-white",
muted: "bg-gray-100 text-gray-700",
dark: "bg-gray-900 text-white",
},
},
defaultVariants: {
colorScheme: "default",
},
});
const Card = ({ colorScheme, children }) => (
<div className={cardVariants({ colorScheme })}>{children}</div>
);
This approach ensures:
- Consistent colors across the design system
- Users select from curated, meaningful options (not arbitrary values)
- Easy theme updates by modifying
global.csstokens - Better accessibility through tested color combinations