1- import { Container , Sprite , Text } from 'pixi.js' ;
1+ import { Container , Graphics , Text } from 'pixi.js' ;
22import { PixiStory , StoryFn } from '@pixi/storybook-renderer' ;
33import { FancyButton } from '../../FancyButton' ;
44import { List , ListType } from '../../List' ;
55import { centerElement } from '../../utils/helpers/resize' ;
6- import { defaultTextStyle } from '../../utils/helpers/styles' ;
6+ import { colors , defaultTextStyle } from '../../utils/helpers/styles' ;
77import { LIST_TYPE } from '../../utils/HelpTypes' ;
88import { argTypes , getDefaultArgs } from '../utils/argTypes' ;
99import { getColor } from '../utils/color' ;
1010import { preload } from '../utils/loader' ;
1111import { action } from '@storybook/addon-actions' ;
1212
1313const args = {
14- type : LIST_TYPE ,
15- fontColor : '#000000' ,
14+ type : [ null , ...LIST_TYPE ] ,
15+ width : 430 ,
16+ height : 330 ,
17+ radius : 20 ,
18+ bgColor : colors . pannelColor ,
19+ bgBorderColor : colors . pannelBorderColor ,
20+ fontColor : colors . textColor ,
1621 elementsMargin : 29 ,
17- itemsAmount : 12 ,
18- maxWidth : 500 ,
22+ topPadding : 20 ,
23+ leftPadding : 20 ,
24+ rightPadding : 20 ,
25+ itemsAmount : 16 ,
1926 onPress : action ( 'Button pressed' ) ,
2027} ;
2128
2229export const UseSprite : StoryFn < typeof args & { type : ListType } > = (
2330 {
2431 fontColor,
32+ width,
33+ height,
34+ radius,
35+ bgColor,
36+ bgBorderColor,
2537 elementsMargin,
38+ topPadding,
39+ leftPadding,
40+ rightPadding,
2641 itemsAmount,
2742 type,
28- maxWidth,
2943 onPress,
3044 } ,
3145 context ,
3246) =>
3347 new PixiStory < typeof args > ( {
3448 context,
35- init : ( view ) =>
49+ init : async ( view ) =>
3650 {
3751 const assets = [
38- `window.png` ,
39- `SmallButton.png` ,
40- `SmallButton-hover.png` ,
41- `SmallButton-pressed.png` ,
52+ `button.png` ,
53+ `button_hover.png` ,
54+ `button_pressed.png` ,
4255 ] ;
4356
44- preload ( assets ) . then ( ( ) =>
45- {
46- const window = Sprite . from ( `window.png` ) ;
47- const title = new Text ( {
48- text : `Levels` ,
49- style : { fill : 0x000000 , fontSize : 40 } ,
50- } ) ;
51-
52- title . anchor . set ( 0.5 ) ;
53- window . addChild ( title ) ;
54- title . x = window . width / 2 ;
55- title . y = 25 ;
56-
57- view . addChild ( window ) ;
58-
59- const items : Container [ ] = createItems ( itemsAmount , getColor ( fontColor ) ?? 0x000000 , onPress ) ;
57+ await preload ( assets ) ;
6058
61- // Component usage !!!
62- const list = new List ( {
63- type,
64- vertPadding : 70 ,
65- horPadding : 50 ,
66- elementsMargin,
67- maxWidth,
59+ const viewGraphics = new Graphics ( )
60+ . roundRect ( 0 , 0 , width , height , radius )
61+ . fill ( bgColor )
62+ . stroke ( {
63+ color : bgBorderColor ,
64+ width : 1 ,
6865 } ) ;
6966
70- items . forEach ( ( item ) => list . addChild ( item ) ) ;
67+ const items : Container [ ] = createItems ( itemsAmount , getColor ( fontColor ) ?? 0x000000 , onPress ) ;
7168
72- window . addChild ( list ) ;
73-
74- centerElement ( view ) ;
69+ // Component usage !!!
70+ const list = new List ( {
71+ elementsMargin,
72+ topPadding,
73+ leftPadding,
74+ rightPadding,
75+ type,
7576 } ) ;
77+
78+ viewGraphics . addChild ( list ) ;
79+ view . addChild ( viewGraphics ) ;
80+ items . forEach ( ( item ) => list . addChild ( item ) ) ;
81+
82+ centerElement ( view ) ;
7683 } ,
7784 resize : centerElement ,
7885 } ) ;
@@ -88,9 +95,10 @@ function createItems(
8895 for ( let i = 0 ; i < itemsAmount ; i ++ )
8996 {
9097 const button = new FancyButton ( {
91- defaultView : `SmallButton.png` ,
92- hoverView : `SmallButton-hover.png` ,
93- pressedView : `SmallButton-pressed.png` ,
98+ defaultView : `button.png` ,
99+ hoverView : `button_hover.png` ,
100+ pressedView : `button_pressed.png` ,
101+ nineSliceSprite : [ 25 , 20 , 25 , 20 ] ,
94102 text : new Text ( {
95103 text : i + 1 ,
96104 style : {
@@ -105,6 +113,9 @@ function createItems(
105113 } ,
106114 } ) ;
107115
116+ button . width = 150 ;
117+ button . height = 100 ;
118+
108119 button . scale . set ( 0.5 ) ;
109120
110121 button . onPress . connect ( ( ) => onPress ( i + 1 ) ) ;
0 commit comments