Skip to content

Commit

Permalink
fix: modal bounding box for chromatic stories
Browse files Browse the repository at this point in the history
  • Loading branch information
karrui committed Apr 29, 2024
1 parent ba82872 commit 85a8848
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions frontend/src/components/Modal/Modal.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useDisclosure } from '@chakra-ui/hooks'
import {
Box,
ButtonGroup,
Modal,
ModalBody,
Expand All @@ -12,15 +13,22 @@ import {
} from '@chakra-ui/react'
import { Meta, StoryFn } from '@storybook/react'

import { fullScreenDecorator, viewports } from '~utils/storybook'
import { getMobileViewParameters } from '~/utils/storybook'

import Button from '~components/Button'

export default {
title: 'Components/Modal',
// Required for Chromatic to know the dimensions of the snapshot to take,
// since the modal is rendered in a portal and Chromatic only detects the
// bounding box of the button that opens the modal.
decorators: [fullScreenDecorator],
decorators: [
(storyFn) => (
<Box w="100vw" h="100vh">
{storyFn()}
</Box>
),
],
parameters: {
layout: 'fullscreen',
// Prevent flaky tests due to modal animating in.
Expand Down Expand Up @@ -49,12 +57,12 @@ const Template: StoryFn<StoryModalProps> = ({ bodyContent, ...args }) => {
<ModalContent>
<ModalCloseButton />
<ModalHeader>Create workspace</ModalHeader>
<ModalBody whiteSpace="pre-wrap">
<ModalBody whiteSpace="pre-line">
{bodyContent ?? generateLorem()}
</ModalBody>
<ModalFooter>
<ButtonGroup>
<Button variant="clear" colorScheme="secondary" onClick={onClose}>
<Button variant="clear" onClick={onClose}>
Cancel
</Button>
<Button>Create workspace</Button>
Expand Down Expand Up @@ -85,9 +93,4 @@ Mobile.args = {
size: 'mobile',
bodyContent: generateLorem(5),
}
Mobile.parameters = {
viewport: {
defaultViewport: 'mobile1',
},
chromatic: { viewports: [viewports.xs] },
}
Mobile.parameters = getMobileViewParameters()

0 comments on commit 85a8848

Please sign in to comment.