You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It will be great to use @storybook/addon-interactions to automate some more complex animations that goes one after another.
There is no point to use @storybook/testing-library for Pixi stories (as it simulates events over the dom elements), but steps logic can be used.
There is one problem that is a blocker to use interactions - how to get a Pixi Container (our component) that is returned from a story.
Default Storybook interactions are using canvasElement which contains rendered component, but it is a DOM element (see docs sample https://storybook.js.org/docs/react/essentials/interactions).
This DOM element is useless for us as we need an object/component returned from a story, so we can trigger certain animation method from it. Sadly, Storybook doesn't provide a way to get a value returned from a story render process.
Bellow is workaround I have made to handle this problem:
Create a decorator to store story render result:
exportconststoryResultDecorator=(story,context)=>{// storyResult is the value returned from your Story renderconststoryResult=story();// store story result into context.canvasElement so it can be get from there in the interactioncontext.canvasElement.storyResult=storyResult;// return story result as isreturnstoryResult;};
Add decorator to .storybook/preview.ts
export const decorators = [storyResultDecorator]; // can gave more decorators
Create a story with interaction (do not forget to add animateAction func to a BunnyDemo, in my case it was changing a rotation direction)
import{action}from'@storybook/addon-actions';import{BunnyDemo}from'./BunnyDemo';exportdefault{title: 'Demos-Basic',args: {bunnySize: 1,bunnySpacing: 40,someInjectedObject: {onBunnyClick: action('onBunnyClick'),},},render: (args: any)=>newBunnyDemo(args),};// plain func to add a pauseconstpause=(time=0)=>newPromise<void>(resolve=>setTimeout(()=>resolve(),time));exportconstInteraction={play: async({ step,canvasElement: { storyResult }}: any)=>{awaitstep('Wait for 3 secs',async()=>awaitpause(3000));awaitstep('Change rotation direction 1',async()=>{awaitstoryResult.animateAction();});awaitstep('Wait for 3 secs',async()=>awaitpause(3000));awaitstep('Change rotation direction 2',async()=>{awaitstoryResult.animateAction();});awaitstep('Wait for 3 secs',async()=>awaitpause(3000));awaitstep('Change rotation direction 3',async()=>{awaitstoryResult.animateAction();});},}
Maybe there is a better way to get Story render result in the interaction? Feel free to suggest.
The text was updated successfully, but these errors were encountered:
It will be great to use
@storybook/addon-interactions
to automate some more complex animations that goes one after another.There is no point to use
@storybook/testing-library
for Pixi stories (as it simulates events over the dom elements), butsteps
logic can be used.There is one problem that is a blocker to use interactions - how to get a Pixi Container (our component) that is returned from a story.
Default Storybook interactions are using canvasElement which contains rendered component, but it is a DOM element (see docs sample https://storybook.js.org/docs/react/essentials/interactions).
This DOM element is useless for us as we need an object/component returned from a story, so we can trigger certain animation method from it. Sadly, Storybook doesn't provide a way to get a value returned from a story render process.
Bellow is workaround I have made to handle this problem:
.storybook/preview.ts
animateAction
func to a BunnyDemo, in my case it was changing a rotation direction)Maybe there is a better way to get Story render result in the interaction? Feel free to suggest.
The text was updated successfully, but these errors were encountered: