Skip to content

Commit

Permalink
Migrate Chromatic Viewports
Browse files Browse the repository at this point in the history
Chromatic has changed the way they handle viewports for stories.
https://www.chromatic.com/docs/storybook/viewports/#migration-from-viewports-legacy-to-modes
  • Loading branch information
JacobArrow committed Nov 4, 2024
1 parent 70ef6ec commit adf3720
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .storybook/modes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Set the viewport widths that Chromatic tests with globally.
export const allModes = {
xs: {
viewport: "xs",
},
xl: {
viewport: "xl",
},
};
20 changes: 16 additions & 4 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "../src/styles/css/base.css";
import { allModes } from "../.storybook/modes";

export const parameters = {
layout: "fullscreen",
Expand All @@ -9,13 +10,24 @@ export const parameters = {
date: /Date$/,
},
},
viewport: {
viewports: {
xs: { name: "XSmall", styles: { width: "400px", height: "900px" } },
sm: { name: "Small", styles: { width: "640px", height: "900px" } },
md: { name: "Medium", styles: { width: "768px", height: "900px" } },
lg: { name: "Large", styles: { width: "1024px", height: "900px" } },
xl: { name: "XL", styles: { width: "1200px", height: "900px" } },
"2xl": { name: "2XL", styles: { width: "1536px", height: "900px" } },
},
},
chromatic: {
// Notifies Chromatic to pause the animations when they finish at a global level
// This is because Chromatic doesn't show the cover image when the animation starts with opacity 0
pauseAnimationAtEnd: true,
// Set the viewport widths that Chromatic tests with globally.
// 400 lies between our screen-xs & screen-s variables.
// 1200 is the chromatic viewport we were using as default before adding an extra one for phones.
viewports: [400, 1200],
// Instructs Chromatic to test all stories at the specified viewport
modes: {
"400px": allModes["xs"],
"1200px": allModes["xl"],
},
},
};

0 comments on commit adf3720

Please sign in to comment.