Skip to content

Commit 1664026

Browse files
committed
test(storybook): adds simple and multidrag examples
1 parent 473b45e commit 1664026

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

stories/classic.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.list {
2+
background-color: #ddd;
3+
padding: 1rem;
4+
}
5+
6+
.item {
7+
list-style: none;
8+
padding: 2rem;
9+
border: #0005 solid black;
10+
margin-top: -1px;
11+
margin-bottom: -1px;
12+
background-color: #7cf;
13+
}
14+
15+
.item:first-child {
16+
border-radius: 0.5rem 0.5rem 0 0;
17+
}
18+
19+
.item:last-child {
20+
border-radius: 0 0 0.5rem 0.5rem;
21+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// also exported from '@storybook/react' if you can deal with breaking changes in 6.1
2+
import { Meta } from "@storybook/react";
3+
import { ReactSortable, ReactSortableProps } from "../../src";
4+
import { ULLITemplate, ULLITemplateProps } from "../templates/ul-li";
5+
6+
export default {
7+
title: "Example/MultiDrag",
8+
component: ReactSortable,
9+
args: {
10+
animation: 200,
11+
multiDrag: true,
12+
list: [
13+
{
14+
id: "1",
15+
text: "Hello, World!",
16+
},
17+
{
18+
id: "2",
19+
text: "Hello, Earth!",
20+
},
21+
{
22+
id: "3",
23+
text: "Goodbye, World!",
24+
},
25+
],
26+
},
27+
} as Meta<ReactSortableProps<ULLITemplateProps>>;
28+
29+
export const Primary = ULLITemplate.bind({});
30+
Primary.args = {
31+
tag: "ul",
32+
};

stories/templates/ul-li.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from "react";
2+
// also exported from '@storybook/react' if you can deal with breaking changes in 6.1
3+
import { Story } from "@storybook/react";
4+
import { ReactSortable, ReactSortableProps } from "../../dist";
5+
import "../classic.css";
6+
7+
export interface ULLITemplateProps {
8+
id: string;
9+
text: string;
10+
}
11+
12+
export const ULLITemplate: Story<ReactSortableProps<ULLITemplateProps>> = (
13+
args
14+
) => {
15+
const [list, setList] = React.useState<ULLITemplateProps[]>(args.list);
16+
17+
return (
18+
<ReactSortable className="list" {...args} list={list} setList={setList}>
19+
{list.map(({ id, text }) => (
20+
<li className="item" key={id}>
21+
{text}
22+
</li>
23+
))}
24+
</ReactSortable>
25+
);
26+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// also exported from '@storybook/react' if you can deal with breaking changes in 6.1
2+
import { Meta } from "@storybook/react";
3+
import { ReactSortableProps, ReactSortable } from "../../src";
4+
import { ULLITemplate, ULLITemplateProps } from "../templates/ul-li";
5+
6+
export default {
7+
title: "Example/Simple List",
8+
component: ReactSortable,
9+
args: {
10+
animation: 200,
11+
list: [
12+
{
13+
id: "1",
14+
text: "Hello, World!",
15+
},
16+
{
17+
id: "2",
18+
text: "Hello, Earth!",
19+
},
20+
{
21+
id: "3",
22+
text: "Goodbye, World!",
23+
},
24+
],
25+
},
26+
} as Meta<ReactSortableProps<ULLITemplateProps>>;
27+
28+
export const Primary = ULLITemplate.bind({});
29+
Primary.args = {
30+
tag: "ul",
31+
};

0 commit comments

Comments
 (0)