Terminal
Terminal/Skill
Sets up Chromatic visual tests at several viewport sizes using the Modes API, and migrates the legacy chromatic.viewports setting.
By Chromatic
Works with
npx skills add chromaui/chromatic-skills --skill chromatic-viewportsConfigure responsive visual testing across multiple screen sizes using Chromatic's Modes API.
This skill covers:
.storybook/modes.tscropToViewportchromatic.viewports APIchromatic.viewports (legacy) or a modes.ts / modes import (new API).reference/docs-map.md.reference/output-contract.md.Check story files, .storybook/preview.ts, and existing modes.ts:
chromatic.viewports found → legacy API in use, offer migration to Modes API.storybook/modes.ts or chromatic.modes found → already on Modes API, help extend or fixUse the URLs in reference/docs-map.md and fetch with WebFetch. Use fetched content as the authoritative source — do not rely on remembered examples.
Fresh setup or extension (Modes API):
Create or update .storybook/modes.ts:
export const allModes = {
mobile: { viewport: 375 },
tablet: { viewport: 768 },
desktop: { viewport: 1280 },
} as const;
Apply in a story file:
import { allModes } from '../.storybook/modes';
export default {
title: 'Component',
parameters: {
chromatic: { modes: { mobile: allModes.mobile, desktop: allModes.desktop } },
},
};
Apply globally in .storybook/preview.ts:
import { allModes } from './modes';
const preview = {
parameters: {
chromatic: { modes: allModes },
},
};
export default preview;
Control height — by default snapshots use the component's intrinsic height. To crop to the specified viewport height:
export const allModes = {
mobile: { viewport: { width: 375, height: 812 } },
} as const;
// In story:
parameters: { chromatic: { modes: { mobile: allModes.mobile }, cropToViewport: true } }
Migration from legacy:
Replace chromatic.viewports arrays with named modes. See reference/docs-map.md for the migration guide URL.
// Before (legacy)
parameters: { chromatic: { viewports: [320, 1200] } }
// After (Modes API)
parameters: { chromatic: { modes: { mobile: { viewport: 320 }, desktop: { viewport: 1200 } } } }
Always render the checklist from reference/output-contract.md, then show the complete content of every file to create or modify.
px-suffixed strings (800 or "800px") — no other CSS unitschromatic.viewports and the Modes API cannot coexist in the same story — using both throws an errorreference/docs-map.mdreference/output-contract.md