-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rearrange list children upon dimensional changes
- Loading branch information
1 parent
44650a9
commit 4c2e8cc
Showing
3 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/stories/scrollBox/ScrollBoxDynamicDimensions.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { Graphics } from '@pixi/graphics'; | ||
import { Container } from '@pixi/display'; | ||
import { Text } from '@pixi/text'; | ||
import { argTypes, getDefaultArgs } from '../utils/argTypes'; | ||
import { ScrollBox } from '../../ScrollBox'; | ||
import { FancyButton } from '../../FancyButton'; | ||
import { defaultTextStyle } from '../../utils/helpers/styles'; | ||
import { centerElement } from '../../utils/helpers/resize'; | ||
import type { StoryFn } from '@storybook/types'; | ||
import { getColor } from '../utils/color'; | ||
|
||
const args = { | ||
fontColor: '#000000', | ||
backgroundColor: '#F5E3A9', | ||
itemsAmount: 100, | ||
}; | ||
|
||
export const UseDynamicDimensions: StoryFn = ({ | ||
fontColor, | ||
itemsAmount, | ||
backgroundColor, | ||
}: any) => | ||
{ | ||
const view = new Container(); | ||
|
||
backgroundColor = getColor(backgroundColor); | ||
fontColor = getColor(fontColor); | ||
|
||
const sizes: {w: number, h: number}[] = [ | ||
{ w: 320, h: 440 }, | ||
{ w: 630, h: 440 }, | ||
{ w: 630, h: 360 }, | ||
{ w: 320, h: 200 } | ||
]; | ||
const elementsWidth = 300; | ||
const elementsHeight = 80; | ||
const radius = 20; | ||
let currentSizeID = 0; | ||
|
||
// Component usage !!! | ||
const scrollBox = new ScrollBox({ | ||
background: backgroundColor, | ||
elementsMargin: 10, | ||
width: sizes[currentSizeID].w, | ||
height: sizes[currentSizeID].h, | ||
radius, | ||
padding: 10, | ||
}); | ||
|
||
const items = []; | ||
const resizeScrollBox = () => | ||
{ | ||
currentSizeID++; | ||
|
||
if (currentSizeID >= sizes.length) | ||
{ | ||
currentSizeID = 0; | ||
} | ||
|
||
const size = sizes[currentSizeID]; | ||
|
||
scrollBox.width = size.w; | ||
scrollBox.height = size.h; | ||
}; | ||
|
||
for (let i = 0; i < itemsAmount; i++) | ||
{ | ||
const button = new FancyButton({ | ||
defaultView: new Graphics().beginFill(0xa5e24d).drawRoundedRect(0, 0, elementsWidth, elementsHeight, radius), | ||
hoverView: new Graphics().beginFill(0xfec230).drawRoundedRect(0, 0, elementsWidth, elementsHeight, radius), | ||
pressedView: new Graphics().beginFill(0xfe6048).drawRoundedRect(0, 0, elementsWidth, elementsHeight, radius), | ||
text: new Text(`Item ${i + 1}`, { | ||
...defaultTextStyle, | ||
fill: fontColor | ||
}) | ||
}); | ||
|
||
button.anchor.set(0); | ||
button.onPress.connect(() => resizeScrollBox()); | ||
|
||
items.push(button); | ||
} | ||
|
||
scrollBox.addItems(items); | ||
|
||
view.addChild(scrollBox); | ||
|
||
return { | ||
view, | ||
resize: () => centerElement(view) | ||
}; | ||
}; | ||
|
||
export default { | ||
title: 'Components/ScrollBox/Use Dynamic Dimensions', | ||
argTypes: argTypes(args), | ||
args: getDefaultArgs(args) | ||
}; |