.agents/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 balintbrews/canvas-starter 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.
# 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 }) => {
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 stylingdevelopment
Use when work must be verified in local Canvas Workbench, or when the user asks to run, open, or check a component in Workbench. Verifies that Canvas Workbench is available through the project's package runner, starts the local Workbench dev server, and keeps Workbench verification as part of the implementation workflow.
tools
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.
tools
Fetch and render Drupal content in Canvas components with JSON:API and SWR patterns. Use when building content lists, integrating with SWR, or querying related entities. Covers JsonApiClient, DrupalJsonApiParams, relationship handling, and filter patterns.
testing
Push validated Canvas component changes to Drupal Canvas and recover from common push failures. Use after component work is complete and validated. Handles dependency-related push failures that require retry.