skills/canvas-component-utils/SKILL.md
Use utility components to render formatted text and media correctly. Use when (1) Rendering HTML text content from props, (2) Displaying images, (3) Working with formatted text or media. Covers FormattedText and Image utilities.
npx skillsauth add drupal-canvas/skills canvas-component-utilsInstall 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.
Import utilities from the drupal-canvas package:
import { FormattedText, Image } from 'drupal-canvas';
Use FormattedText to render HTML content from props. This is required for any
prop with contentMediaType: text/html in component.yml.
# component.yml
props:
properties:
text:
title: Text
type: string
contentMediaType: text/html
x-formatting-context: block
examples:
- <p>This is <strong>formatted</strong> text.</p>
import { FormattedText } from 'drupal-canvas';
const Text = ({ text, className }) => (
<FormattedText className={className}>{text}</FormattedText>
);
When to use FormattedText:
contentMediaType: text/html<p>, <strong>, <em>, <a>, or other HTML tagsDo NOT use FormattedText for:
Use Image for responsive image rendering. It handles responsive behavior and
optimization automatically. The component contract should accept a single image
object prop that matches $ref: json-schema-definitions://canvas.module/image;
do not split that data into separate imageUrl/imageAlt props.
# component.yml
props:
properties:
image:
title: Image
type: object
$ref: json-schema-definitions://canvas.module/image
examples:
- src: https://example.com/photo.jpg
alt: Description of image
width: 800
height: 600
import { Image } from 'drupal-canvas';
const Card = ({ image }) => {
if (!image?.src) return null;
const { src, alt, width, height } = image;
return (
<Image
src={src}
alt={alt}
width={width}
height={height}
className="w-full rounded-lg object-cover"
/>
);
};
Image props:
src - Image URL (required)alt - Alt text for accessibility (required)width - Original image widthheight - Original image heightclassName - Tailwind classes for stylingtesting
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.