Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

NotificationsYou must be signed in to change notification settings

pixijs/storybook

Repository files navigation


Storybook for PixiJS is a UI development environment for your PixiJS Components.With it, you can visualize different states of your Components and develop them interactively.

Storybook Screenshot

Storybook runs outside of your app.So you can develop UI components in isolation without worrying about app specific dependencies and requirements.

Getting Started

We don't currently have a init script for PixiJS storybook. Currently the easiest way isto initialize with the html framework and manually edit the configuration:

cd my-appnpx storybook@"~8.0.0" init -t html

Remove HTML framework/renderer and install PixiJS framework/renderer based on your bunder:

npm remove @storybook/html @storybook/html-webpack5 --save-dev
npm install @pixi/storybook-renderer @pixi/storybook-webpack5 --save-dev

or

npm install @pixi/storybook-renderer @pixi/storybook-vite --save-dev

Replace.storybook/main.js with the below, setting up the correct paths as necessary.

constconfig={// use glob matching, eg: ../src/stories/**/*.stories.@(ts|tsx|js|jsx|mdx)stories:['RELATIVE_PATH_TO_STORIES'],staticDirs:['RELATIVE_PATH_TO_ASSETS'],logLevel:'debug',addons:['@storybook/addon-actions','@storybook/addon-backgrounds','@storybook/addon-controls','@storybook/addon-viewport','@storybook/addon-links','@storybook/addon-highlight',],core:{channelOptions:{allowFunction:false,maxDepth:10},disableTelemetry:true,},features:{buildStoriesJson:true,breakingChangesV7:true,},framework:'@pixi/storybook-webpack5',// or '@pixi/storybook-vite'};exportdefaultconfig;

Replace.storybook/preview.js with:

constpreview={parameters:{layout:'fullscreen',pixi:{// these are passed as options to `PIXI.Application` when instantiated by the// rendererapplicationOptions:{backgroundColor:0x1099bb,resolution:1,},// optional, if you want to provide custom resize logic, pass a function here,// if nothing is provided, the default resize function is used, which looks like// this, where w and h will be the width and height of the storybook canvas.resizeFn:(w,h)=>{return{rendererWidth:w,rendererHeight:h,canvasWidth:w,canvasHeight:h,};},},},};exportdefaultpreview;

Depending on where you want to keep your story source, either deletesrc/stories folderif you plan to keep your stories co-located with their components, or emptysrc/storiesof the example HTML stories and replace with your own. See below for instructions onhow to write PixiJS Stories in the correct format.

PixiJS Stories

Unlike reactive web UI frameworks, PixiJS requires a more imperative code style to interactwith the HTML5 Canvas API. Components are added to a display list, most commonly via atop level Application instance, and often need to respond to application-level events andcallbacks. This Pixi renderer, handles setting up an Application and Renderer for youand handles adding and removing your Story's DisplayObject from the Stage, but in order toaccommodate this, PixiJS stories must return a JS object with a fixed API:

typeStoryFnPixiReturnType={view:DisplayObject;// optionally respond to requestAnimationFrame tickupdate?:(delta:number)=>void;// optionally respond to application level resizingresize?:(rendererWidth:number,rendererHeight:number)=>void;// optionally clean up things when story is rerendered / removed - this happens a lot, so do it!destroy?:()=>void;}

If your component already matches this particular interface, then you can just return aninstance of it.

You can see anexample story here

Decorators

PixiJS Storybook Framework is compatible withStorybook Decorators,these just need to return stories in the above API, for example you could add margin to aStory's component like so:

import{Container}from'pixi.js';constMARGIN=10;constDOUBLE_MARGIN=MARGIN*2;exportconstbackgroundDecorator=(story)=>{// The extra Container isn't really necessary just to add margin, but it shows how it's// possible to wrap with other PIXI objectsconstroot=newContainer();// storyResult is the value returned from your Story functionconststoryResult=story();root.addChild(storyResult.view);// Decorate the storyResult with other graphics / functionality:return{view:root,update:(delta)=>storyResult.update?.(delta),resize:(screenWidth,screenHeight)=>{root.x=MARGIN;root.y=MARGIN;storyResult.resize?.(screenWidth-DOUBLE_MARGIN,screenHeight-DOUBLE_MARGIN);},destroy:()=>storyResult.destroy?.(),};};

Then add the decorator to./storybook/preview.js:

import{backgroundDecorator}from'decorators/backgroundDecorator';// ...exportconstdecorators=[backgroundDecorator];

Storybook also comes with a lot ofaddons and a great API to customize as you wish.You can also build astatic version of your Storybook and deploy it anywhere you want.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp