1313 * limitations under the License.
1414 */
1515
16+ import type { Decorator } from '@storybook/react' ;
1617import { Fragment } from 'react' ;
18+ import { screen , userEvent , within } from '@storybook/testing-library' ;
1719
18- import { Stack } from '../../../../.storybook/components/index.js' ;
20+ import {
21+ FullViewport ,
22+ Stack ,
23+ } from '../../../../.storybook/components/index.js' ;
24+ import { modes } from '../../../../.storybook/modes.js' ;
1925import Button from '../Button/index.js' ;
2026import Headline from '../Headline/index.js' ;
2127import Body from '../Body/index.js' ;
@@ -28,6 +34,21 @@ export default {
2834 title : 'Components/Modal' ,
2935 component : Modal ,
3036 subcomponents : { ModalProvider } ,
37+ parameters : {
38+ chromatic : {
39+ modes : {
40+ mobile : modes . smallMobile ,
41+ desktop : modes . desktop ,
42+ } ,
43+ } ,
44+ } ,
45+ decorators : [
46+ ( Story ) => (
47+ < FullViewport >
48+ < Story />
49+ </ FullViewport >
50+ ) ,
51+ ] as Decorator [ ] ,
3152} ;
3253
3354const defaultModalChildren = ( ) => (
@@ -39,6 +60,20 @@ const defaultModalChildren = () => (
3960 </ Fragment >
4061) ;
4162
63+ const openModal = async ( {
64+ canvasElement,
65+ } : {
66+ canvasElement : HTMLCanvasElement ;
67+ } ) => {
68+ const canvas = within ( canvasElement ) ;
69+ const button = canvas . getByRole ( 'button' , {
70+ name : 'Open modal' ,
71+ } ) ;
72+
73+ await userEvent . click ( button ) ;
74+ await screen . findByRole ( 'dialog' ) ;
75+ } ;
76+
4277export const Base = ( modal : ModalProps ) : JSX . Element => {
4378 const ComponentWithModal = ( ) => {
4479 const { setModal } = useModal ( ) ;
@@ -61,6 +96,7 @@ Base.args = {
6196 variant : 'contextual' ,
6297 closeButtonLabel : 'Close modal' ,
6398} ;
99+ Base . play = openModal ;
64100
65101export const Variants = ( modal : ModalProps ) : JSX . Element => {
66102 const ComponentWithModal = ( { variant } : Pick < ModalProps , 'variant' > ) => {
@@ -86,6 +122,9 @@ Variants.args = {
86122 children : defaultModalChildren ,
87123 closeButtonLabel : 'Close modal' ,
88124} ;
125+ Variants . parameters = {
126+ chromatic : { disableSnapshot : true } ,
127+ } ;
89128
90129export const PreventClose = ( modal : ModalProps ) : JSX . Element => {
91130 const ComponentWithModal = ( ) => {
@@ -123,6 +162,7 @@ PreventClose.args = {
123162 variant : 'immersive' ,
124163 preventClose : true ,
125164} ;
165+ PreventClose . play = openModal ;
126166
127167export const InitiallyOpen = ( modal : ModalProps ) : JSX . Element => {
128168 const initialModal = { id : 'initial' , component : Modal , ...modal } ;
@@ -171,11 +211,13 @@ CustomStyles.args = {
171211 Custom styles
172212 </ Headline >
173213 < Body style = { { margin : '1rem' } } >
174- Custom styles can be applied using the < code > css</ code > prop.
214+ Custom styles can be applied using the < code > className</ code > or{ ' ' }
215+ < code > style</ code > props.
175216 </ Body >
176217 </ Fragment >
177218 ) ,
178219 style : { padding : '0' } ,
179220 variant : 'contextual' ,
180221 closeButtonLabel : 'Close modal' ,
181222} ;
223+ CustomStyles . play = openModal ;
0 commit comments