[Add on: Viewport] How should I reset viewport between stories? #26667
-
SummaryI'm trying out a pattern to work with my designer in Chromatic. Create a component, create a story with a default. For each device we support create a new story using But, it comes with a warning in the console:
That's the default value though, per docs: https://storybook.js.org/docs/essentials/viewport Is there some other method I should be using to reset viewport on non-specialized stories? Additional informationNo response Create a reproductionNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @lancegliser, I found the answer here: #27073 (comment)
|
Beta Was this translation helpful? Give feedback.
-
Forgot I'd posted this. A came on a solution a while ago with the advent of const preview: Preview = {
parameters: {
initialGlobals: {
viewport: { value: undefined },
},
},
} My stories now just do this: // More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
const meta: Meta<typeof ErrorGraphic> = {
component: ErrorGraphic,
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/7.0/react/writing-docs/docs-page
tags: ["autodocs"],
parameters: {
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
layout: "centered",
},
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
argTypes: {
type: {
options: ["unrecoverable", "not-found", "server"],
},
},
args: {
type: "unrecoverable",
},
};
export default meta;
type Story = StoryObj<typeof ErrorGraphic>;
// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
export const Unrecoverable: Story = {
// More on args: https://storybook.js.org/docs/react/writing-stories/args
args: {},
};
export const UnrecoverableSmallMobile: Story = {
globals: {
viewport: { value: "mobile1", isRotated: false },
},
}; |
Beta Was this translation helpful? Give feedback.
Forgot I'd posted this. A came on a solution a while ago with the advent of
initialGlobals
for viewport inpreview.tsx
.My stories now just do this: