skills/canvas-component-definition/SKILL.md
Start here for any React 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.
npx skillsauth add drupal-canvas/skills canvas-component-definitionInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
A Canvas component is a package of:
index.jsx)component.yml)machineName, folder path, Workbench
mock path)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.
Every Canvas component MUST satisfy all checks below:
<components-root>/<machine-name>/ (use the
repository's configured components root, which may be defined in .env)<components-root>/<machine-name>/index.jsx<components-root>/<machine-name>/component.ymlcomponent.yml includes required top-level keys (name, machineName,
status, required, props, slots)machineName in component.yml (kebab-case)card1Title, card2Title, or car3Image; model them as parent slot content
plus a child item component instead$ref: json-schema-definitions://canvas.module/image; do not split one image
into imageUrl, imageAlt, imageWidth, or similar string/number propsIf 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:
mocks.json beside index.jsx and component.ymlDefault tab, which renders the component using the first
example value for each prop from component.ymlRendered-output changes are incomplete unless the component has sufficient Workbench preview coverage.
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.
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.
Use references/component-mocks.md for mock naming, placement, format
selection, and validation.
Evaluate using companion skills in this order.
canvas-design-decomposition
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
component.yml, props/slots, enums, or fixing
prop validation errors.canvas-component-composability
canvas-styling-conventions
canvas-component-utils
FormattedText and
Image.canvas-data-fetching
Default examples and any authored mocks.json states are
sufficient for review of the requested change.canvas-component-push (optional)
testing
Use for any task touching site chrome — header, footer, sidebar, or global navigation that repeats across pages — and for any region-spec work (create, modify, review, validate region JSON, or the project-level layout component). Also load when a task creates or edits multiple pages that share chrome, or asks for a "site" or "navigation between pages"; shared chrome belongs in regions, never inlined into page JSON.
content-media
Create and modify content templates that map Drupal content entities to Canvas component layouts. Use when asked to (1) Create a new content template, (2) Modify an existing content template, (3) Add or change entity field mappings in a template, (4) Compose components in a content template via slots. Content templates live in the configured `contentTemplatesDir` (default `content-templates/`) and define how Drupal entity types, bundles, and view modes render as Canvas component trees.
tools
Plans and builds Drupal Canvas navigation UI (main nav, footer links, sidebar nav, mobile drawers, breadcrumbs) using design decomposition for structure and props/slots, then JSON:API menu or page-context patterns from canvas-data-fetching. Use when the user asks for navigation, header or footer links, menus, menu_items, mobile nav, or breadcrumb trails. Run after canvas-design-decomposition for layout and API sketches; follow canvas-data-fetching for SWR, JsonApiClient, sortMenu, and menu fallbacks.
development
Plans structure for a component library with props/slots and right-sized component granularity. Run before building or adding Canvas components (new `src/components/` folders, component.yml, React), or for plan-only / breakdown-only work, whenever UI must map to a coherent tree. Mandatory for every new Figma frame or greenfield screen—repository drafts do not replace phases A–G.