Storybook for Pixi.js
Using Storybook for Pixi.js graphics development
This project includes:
Background
Often conventions involve developing components in isolation and leveraging GUI frameworks such as dat.GUI for controls.
For projects of greater complexity there may be a need to classify numerous scenarios, which is the catalyst for this project.
Getting Started
Begin via any of the following:
-
Press the "Use this template" button
-
Use degit to execute:
degit github:jasonsturges/storybook-for-pixi.js
-
Use GitHub CLI to execute:
gh repo create
--template="https://github.com/jasonsturges/storybook-for-pixi.js" -
Simply
git clone
, delete the existing .git folder, and then:git init git add -A git commit -m "Initial commit"
Install and run via npm (or yarn) by executing the storybook
script:
npm install
npm run storybook
Usage
To create a story, add a new file under the "stories/" folder named "
Each story has a default export for navigation grouping and argument types:
export default {
title: "Example/Squares",
argTypes: {
width: { control: "number" },
height: { control: "number" },
stroke: { control: "color" },
},
};
In that story, create a template via the createScene()
function and returning the canvas
object:
const Template = (args) => {
const { canvas, app, viewport } = createScene({
width: args.width,
height: args.height,
});
const graphics = new PIXI.Graphics();
graphics.lineStyle(2, parseColor(args.stroke));
graphics.drawRect(100, 100, 200, 200);
viewport.addChild(graphics);
return canvas;
};
Apply the template by passing default arguments:
export const Square1 = Template.bind({});
Square1.args = {
width: 600,
height: 400,
stroke: "#ffffff",
};
export const Square2 = Template.bind({});
Square2.args = {
width: 600,
height: 400,
stroke: "#ff00ff",
};
Result of this story will be: