-
Notifications
You must be signed in to change notification settings - Fork 3
/
carousel.stories.tsx
56 lines (49 loc) · 1.56 KB
/
carousel.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React from 'react';
import { Meta, Story } from '@storybook/react';
import { usePony } from '../src/use-pony/usePony';
import { ActionKind } from '../src/use-pony/usePony.interface';
export const MyCarousel = () => {
const items = new Array(10).fill(null).map((_, idx) => ({
id: idx,
name: `item number ${idx}`,
}));
const {
getSectionProps,
getHeadingProps,
getCarouselWrapperProps,
getCarouselProps,
getCarouselItemProps,
getButtonProps,
getAnnouncerProps,
state,
} = usePony({ numItems: items.length });
return (
<div {...getSectionProps()}>
<h1 {...getHeadingProps()}>Heading</h1>
<div {...getCarouselWrapperProps()}>
<ul {...getCarouselProps()}>
{items.map((item, idx) => (
<li key={idx} {...getCarouselItemProps(idx)}>
{item.name}
</li>
))}
</ul>
</div>
<button {...getButtonProps(ActionKind.Previous)}>Previous</button>
<button {...getButtonProps(ActionKind.Next)}>Next</button>
<div {...getAnnouncerProps()}>
<p>{`Item ${state.activeSlideIndex + 1} of ${items.length}`}</p>
</div>
</div>
);
};
const meta: Meta = {
title: 'Carousel',
component: MyCarousel,
};
export default meta;
const Template: Story = (args) => <MyCarousel {...args} />;
// By passing using the Args format for exported stories, you can control the props for a component for reuse in a test
// https://storybook.js.org/docs/react/workflows/unit-testing
export const Default = Template.bind({});
Default.args = {};