Skip to content

Commit

Permalink
test: create chromaticParams helper with wide viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
codeincontext committed Dec 9, 2024
1 parent d787b53 commit 887c1b8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
44 changes: 23 additions & 21 deletions apps/nextjs/.storybook/chromatic.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import "@storybook/csf";

const defaultMode = { "1200px": { viewport: 1200 } } as const;
const mobileMode = { mobile: { viewport: 375 } };
const desktopMode = { desktop: { viewport: 1200 } };
type ChromaticModes = "legacy" | "mobile" | "desktop" | "desktop-wide";

export const CHROMATIC_MOBILE_ONLY = {
chromatic: { modes: mobileMode },
};
export const CHROMATIC_DESKTOP_ONLY = {
chromatic: { modes: desktopMode },
};
export const CHROMATIC_ALL_VIEWPORTS = {
chromatic: { modes: { ...mobileMode, ...desktopMode } },
};

// NOTE: Before we used modes, all snapshots were by default in the 1200px mode.
// These options allow us to reuse the existing desktop snapshot until we're ready to migrate
export const CHROMATIC_DESKTOP_COMPAT = {
chromatic: { modes: defaultMode },
};
export const CHROMATIC_ALL_VIEWPORTS_COMPAT = {
chromatic: { modes: { ...mobileMode, ...defaultMode } },
};
export function chromaticParams(modes: ChromaticModes[]) {
return {
chromatic: {
modes: {
...(modes.includes("mobile") && {
mobile: { viewport: 375 },
}),
...(modes.includes("desktop") && {
desktop: { viewport: 1200 },
}),
...(modes.includes("desktop-wide") && {
"wide desktop": { viewport: 1400 },
}),
// NOTE: Before we used modes, all snapshots were by default in the 1200px mode.
// This option allows us to reuse the existing desktop snapshot until we're ready to migrate
...(modes.includes("legacy") && {
"1200px": { viewport: 1200 as const },
}),
},
},
};
}

declare module "@storybook/csf" {
interface Parameters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ChatContextProps } from "@/components/ContextProviders/ChatProvide
import { ChatContext } from "@/components/ContextProviders/ChatProvider";
import { DemoContext } from "@/components/ContextProviders/Demo";

import { CHROMATIC_MOBILE_ONLY } from "../../../../../.storybook/chromatic";
import { chromaticParams } from "../../../../../.storybook/chromatic";
import { MobileExportButtons } from "./MobileExportButtons";

const ChatDecorator: Story["decorators"] = (Story, { parameters }) => (
Expand Down Expand Up @@ -41,7 +41,7 @@ const meta: Meta<typeof MobileExportButtons> = {
viewport: {
defaultViewport: "mobile1",
},
...CHROMATIC_MOBILE_ONLY,
...chromaticParams(["mobile"]),
},
args: {
closeMobileLessonPullOut: () => {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ChatContextProps } from "@/components/ContextProviders/ChatProvide
import { ChatContext } from "@/components/ContextProviders/ChatProvider";
import { DemoContext } from "@/components/ContextProviders/Demo";

import { CHROMATIC_DESKTOP_COMPAT } from "../../../../../.storybook/chromatic";
import { chromaticParams } from "../../../../../.storybook/chromatic";
import ExportButtons from "./";

const ChatDecorator: Story["decorators"] = (Story, { parameters }) => (
Expand Down Expand Up @@ -44,7 +44,7 @@ const meta: Meta<typeof ExportButtons> = {
documentContainerRef: { current: null },
},
parameters: {
...CHROMATIC_DESKTOP_COMPAT,
...chromaticParams(["compat"]),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Meta, StoryObj } from "@storybook/react";

import { DemoContext } from "@/components/ContextProviders/Demo";

import { chromaticParams } from "../../../../.storybook/chromatic";
import { Header } from "./header";

const DemoDecorator: Story["decorators"] = (Story, { parameters }) => (
Expand All @@ -23,6 +24,7 @@ const meta: Meta<typeof Header> = {
decorators: [DemoDecorator],
parameters: {
layout: "fullscreen",
...chromaticParams(["legacy", "desktop"]),
docs: {
story: {
height: "150px",
Expand Down

0 comments on commit 887c1b8

Please sign in to comment.