Project type
Before applying this skill, check package.json for a dependency named
@drupal-canvas/headless or starting with @drupal-canvas/headless-. If one is
present, this is a Canvas Headless codebase — read
canvas-headless first; it overrides the
React-specific guidance below. If no such dependency is present, this is a
Canvas-rendered React codebase: components are React (index.jsx/.tsx) and
everything in this skill applies as written. These are the only two project
types.
Canonical definition
A Canvas component is a package of:
- An implementation entry file (
index.jsx in React projects; index.vue,
index.astro, or similar in headless projects — see
canvas-headless)
- Canvas metadata/schema (
component.yml)
- Naming and structure compatibility (
machineName, folder path, Workbench
mock path)
- Canvas-compatible props/slots modeling
- Workbench mock coverage for authored preview states
The first four parts are required for the component to be usable in Drupal
Canvas. Workbench mocks are the supported way to author named preview states
beyond Workbench's built-in Default tab.
Minimum contract (MUST)
Every Canvas component MUST satisfy all checks below:
- Component folder exists at
<components-root>/<machine-name>/ (use the
repository's configured components root, which may be defined in .env)
- The implementation entry file exists at
<components-root>/<machine-name>/index.jsx (or the framework-appropriate
extension in a headless project)
- Metadata exists at
<components-root>/<machine-name>/component.yml
component.yml includes required top-level keys (name, machineName,
status, required, props, slots)
- Folder name exactly matches
machineName in component.yml (kebab-case)
- Props/slots follow Canvas rules (for example, avoid unsupported
array-of-object prop shapes; use slots for repeatable complex content)
- Repeatable cards/items are not flattened into numbered prop groups such as
card1Title, card2Title, or car3Image; model them as parent slot content
plus a child item component instead
- Any prop that represents an image uses a single object prop with
$ref: json-schema-definitions://canvas.module/image; do not split one image
into imageUrl, imageAlt, imageWidth, or similar string/number props
- Any prop that represents a selected Drupal entity uses
$ref: json-schema-definitions://canvas.module/content-entity-reference and
has matching dataDependencies.entityFields.<propName> entries in
component.yml
If any item is missing, the component is incomplete for Canvas usage.
For local authoring and review, add a matching Workbench mock file beside the
component source and metadata:
- Use
mocks.json beside the component entry file and component.yml
- Author at least one named mock whenever the component needs a preview beyond
the auto-generated
Default tab, which renders the component using the first
example value for each prop from component.yml
Rendered-output changes are incomplete unless the component has sufficient
Workbench preview coverage.
Naming guidance
This codebase is already specific to one project or product, so component names
do not need (and must not use) a project or product prefix. Keep
machineName, folder names, and display names generic and portable (e.g.
hero, contact-form), not acme-hero or nebula-contact-form.
Default to the shortest reusable base name. Requests like "simple hero", "solid
hero", "cream hero", or "two cards" should still usually result in Hero or
Card, with differences expressed through props, variants, composition, or mock
names, not the component name itself. Use a specialized name only when the
component is truly one-off.
Use references/naming.md for naming rules and examples.
Reuse check before creation
Before creating a new component, check whether existing workspace components can
satisfy the request, especially when the user names specific components to
reuse, compose, or wrap.
This is the canonical reuse-first policy. Other skills should link here instead
of restating the same decision tree.
- Reuse existing components when they already fit or can fit with a reasonable
extension, variant, or thin wrapper.
- Do not silently create a replacement that bypasses the existing component.
- Do not silently replace a named existing component with a new implementation.
- If an existing component does not fit, explain the mismatch and choose
deliberately between extending it, wrapping it, or creating a new
purpose-specific component.
- Surface the mismatch and tradeoff when it affects whether the request is still
being followed.
Workbench mocks
Use references/component-mocks.md for mock naming, placement, format
selection, and validation.
Skill coordination
Evaluate using companion skills in this order.
canvas-design-decomposition
- Use before structuring work when you need to break down a design
(Figma frame, screenshot, scraped page, or verbal spec) into regions, a
component tree, and intentional props vs slots. This skill produces the
plan; this skill (
canvas-component-definition) enforces the resulting
folder contract and implementation. Skip step 0 when you are only editing
an existing component whose boundaries are already known.
canvas-component-metadata
- Use when creating/changing
component.yml, props/slots, enums, or fixing
prop validation errors.
canvas-component-composability
- Use when designing prop/slot structure, decomposing large components,
deciding props vs slots, reusing/composing/wrapping existing components, or
modeling repeatable list/grid content.
canvas-styling-conventions
- Use for all styling work: new components, style props, Tailwind token
usage, CVA variants, class changes, and prop changes that affect styles.
canvas-component-utils
- Use when rendering formatted HTML text or media via
FormattedText and
Image.
canvas-data-fetching
- Use when fetching/rendering Drupal content with JSON:API, SWR, includes,
and filter patterns.
- Preview coverage readiness
- Ensure
Default examples and any authored mocks.json states are
sufficient for review of the requested change.
canvas-component-push (optional)
- Use only when the user explicitly asks to push/publish/sync components to
Canvas.
- Do not run push automatically after implementation or static validation.
1---2name: canvas-component-definition3description: Start here for any Canvas component task to enforce the canonical Canvas component contract. Use for create, modify, refactor, review, migrate, or validate work. Establishes the canonical Canvas component contract, assuming repository components are Canvas targets, and guides either (1) transforming existing components to meet Canvas requirements or (2) creating new Canvas-ready components.4---56## Project type78Before applying this skill, check `package.json` for a dependency named9`@drupal-canvas/headless` or starting with `@drupal-canvas/headless-`. If one is10present, this is a Canvas Headless codebase — read11[`canvas-headless`](../canvas-headless/SKILL.md) first; it overrides the12React-specific guidance below. If no such dependency is present, this is a13Canvas-rendered React codebase: components are React (`index.jsx`/`.tsx`) and14everything in this skill applies as written. These are the only two project15types.1617## Canonical definition1819A Canvas component is a package of:20211. An implementation entry file (`index.jsx` in React projects; `index.vue`,22 `index.astro`, or similar in headless projects — see23 [`canvas-headless`](../canvas-headless/SKILL.md))242. Canvas metadata/schema (`component.yml`)253. Naming and structure compatibility (`machineName`, folder path, Workbench26 mock path)274. Canvas-compatible props/slots modeling285. Workbench mock coverage for authored preview states2930The first four parts are required for the component to be usable in Drupal31Canvas. Workbench mocks are the supported way to author named preview states32beyond Workbench's built-in `Default` tab.3334## Minimum contract (MUST)3536Every Canvas component MUST satisfy all checks below:3738- Component folder exists at `<components-root>/<machine-name>/` (use the39 repository's configured components root, which may be defined in `.env`)40- The implementation entry file exists at41 `<components-root>/<machine-name>/index.jsx` (or the framework-appropriate42 extension in a headless project)43- Metadata exists at `<components-root>/<machine-name>/component.yml`44- `component.yml` includes required top-level keys (`name`, `machineName`,45 `status`, `required`, `props`, `slots`)46- Folder name exactly matches `machineName` in `component.yml` (kebab-case)47- Props/slots follow Canvas rules (for example, avoid unsupported48 array-of-object prop shapes; use slots for repeatable complex content)49- Repeatable cards/items are not flattened into numbered prop groups such as50 `card1Title`, `card2Title`, or `car3Image`; model them as parent slot content51 plus a child item component instead52- Any prop that represents an image uses a single object prop with53 `$ref: json-schema-definitions://canvas.module/image`; do not split one image54 into `imageUrl`, `imageAlt`, `imageWidth`, or similar string/number props55- Any prop that represents a selected Drupal entity uses56 `$ref: json-schema-definitions://canvas.module/content-entity-reference` and57 has matching `dataDependencies.entityFields.<propName>` entries in58 `component.yml`5960If any item is missing, the component is incomplete for Canvas usage.6162For local authoring and review, add a matching Workbench mock file beside the63component source and metadata:6465- Use `mocks.json` beside the component entry file and `component.yml`66- Author at least one named mock whenever the component needs a preview beyond67 the auto-generated `Default` tab, which renders the component using the first68 example value for each prop from `component.yml`6970Rendered-output changes are incomplete unless the component has sufficient71Workbench preview coverage.7273## Naming guidance7475This codebase is already specific to one project or product, so component names76do **not** need (and must not use) a project or product prefix. Keep77`machineName`, folder names, and display names generic and portable (e.g.78`hero`, `contact-form`), not `acme-hero` or `nebula-contact-form`.7980Default to the shortest reusable base name. Requests like "simple hero", "solid81hero", "cream hero", or "two cards" should still usually result in `Hero` or82`Card`, with differences expressed through props, variants, composition, or mock83names, not the component name itself. Use a specialized name only when the84component is truly one-off.8586Use `references/naming.md` for naming rules and examples.8788## Reuse check before creation8990Before creating a new component, check whether existing workspace components can91satisfy the request, especially when the user names specific components to92reuse, compose, or wrap.9394This is the canonical reuse-first policy. Other skills should link here instead95of restating the same decision tree.9697- Reuse existing components when they already fit or can fit with a reasonable98 extension, variant, or thin wrapper.99- Do not silently create a replacement that bypasses the existing component.100- Do not silently replace a named existing component with a new implementation.101- If an existing component does not fit, explain the mismatch and choose102 deliberately between extending it, wrapping it, or creating a new103 purpose-specific component.104- Surface the mismatch and tradeoff when it affects whether the request is still105 being followed.106107## Workbench mocks108109Use `references/component-mocks.md` for mock naming, placement, format110selection, and validation.111112## Skill coordination113114Evaluate using companion skills in this order.1151160. `canvas-design-decomposition`117 - Use **before** structuring work when you need to **break down** a design118 (Figma frame, screenshot, scraped page, or verbal spec) into regions, a119 component tree, and intentional props vs slots. This skill produces the120 plan; **this** skill (`canvas-component-definition`) enforces the resulting121 folder contract and implementation. Skip step 0 when you are only editing122 an existing component whose boundaries are already known.1231. `canvas-component-metadata`124 - Use when creating/changing `component.yml`, props/slots, enums, or fixing125 prop validation errors.1262. `canvas-component-composability`127 - Use when designing prop/slot structure, decomposing large components,128 deciding props vs slots, reusing/composing/wrapping existing components, or129 modeling repeatable list/grid content.1303. `canvas-styling-conventions`131 - Use for all styling work: new components, style props, Tailwind token132 usage, CVA variants, class changes, and prop changes that affect styles.1334. `canvas-component-utils`134 - Use when rendering formatted HTML text or media via `FormattedText` and135 `Image`.1365. `canvas-data-fetching`137 - Use when fetching/rendering Drupal content with JSON:API, SWR, includes,138 and filter patterns.1396. Preview coverage readiness140 - Ensure `Default` examples and any authored `mocks.json` states are141 sufficient for review of the requested change.1427. `canvas-component-push` (optional)143 - Use only when the user explicitly asks to push/publish/sync components to144 Canvas.145 - Do not run push automatically after implementation or static validation.