2019-08-27 07:52:55 +00:00
|
|
|
import React from "react";
|
|
|
|
import { storiesOf } from "@storybook/react";
|
|
|
|
import { withKnobs, text, number } from "@storybook/addon-knobs/react";
|
|
|
|
import withReadme from "storybook-readme/with-readme";
|
|
|
|
import Readme from "./README.md";
|
|
|
|
import { AdvancedSelector } from "asc-web-components";
|
|
|
|
import Section from "../../.storybook/decorators/section";
|
|
|
|
import { boolean } from "@storybook/addon-knobs/dist/deprecated";
|
2019-08-27 13:02:18 +00:00
|
|
|
import { ArrayValue } from "react-values";
|
2019-08-26 08:51:36 +00:00
|
|
|
|
2019-08-27 07:52:55 +00:00
|
|
|
function getRandomInt(min, max) {
|
|
|
|
return Math.floor(Math.random() * (max - min)) + min;
|
|
|
|
}
|
|
|
|
|
|
|
|
storiesOf("Components|AdvancedSelector", module)
|
2019-08-26 08:51:36 +00:00
|
|
|
.addDecorator(withKnobs)
|
|
|
|
.addDecorator(withReadme(Readme))
|
2019-08-27 07:52:55 +00:00
|
|
|
.add("base", () => {
|
2019-08-27 14:33:11 +00:00
|
|
|
const optionsCount = number("Users count", 1000);
|
2019-08-27 07:52:55 +00:00
|
|
|
|
|
|
|
const groups = [
|
|
|
|
{
|
|
|
|
key: "group-all",
|
2019-08-27 13:02:18 +00:00
|
|
|
label: "All groups",
|
|
|
|
total: 0
|
2019-08-27 07:52:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "group-dev",
|
2019-08-27 13:02:18 +00:00
|
|
|
label: "Development",
|
|
|
|
total: 0
|
2019-08-27 07:52:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "group-management",
|
2019-08-27 13:02:18 +00:00
|
|
|
label: "Management",
|
|
|
|
total: 0
|
2019-08-27 07:52:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "group-marketing",
|
2019-08-27 13:02:18 +00:00
|
|
|
label: "Marketing",
|
|
|
|
total: 0
|
2019-08-27 07:52:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "group-mobile",
|
2019-08-27 13:02:18 +00:00
|
|
|
label: "Mobile",
|
|
|
|
total: 0
|
2019-08-27 07:52:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "group-support",
|
2019-08-27 13:02:18 +00:00
|
|
|
label: "Support",
|
|
|
|
total: 0
|
2019-08-27 07:52:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "group-web",
|
2019-08-27 13:02:18 +00:00
|
|
|
label: "Web",
|
|
|
|
total: 0
|
2019-08-26 08:51:36 +00:00
|
|
|
}
|
2019-08-27 07:52:55 +00:00
|
|
|
];
|
2019-08-27 13:02:18 +00:00
|
|
|
|
2019-08-27 07:52:55 +00:00
|
|
|
const options = Array.from({ length: optionsCount }, (v, index) => {
|
|
|
|
const additional_group = groups[getRandomInt(1, 6)];
|
2019-08-27 13:02:18 +00:00
|
|
|
groups[0].total++;
|
|
|
|
additional_group.total++;
|
2019-08-27 07:52:55 +00:00
|
|
|
return {
|
|
|
|
key: `user${index}`,
|
2019-08-27 08:34:53 +00:00
|
|
|
groups: ["group-all", additional_group.key],
|
2019-08-27 07:52:55 +00:00
|
|
|
label: `User${index + 1} (All groups, ${additional_group.label})`
|
|
|
|
};
|
|
|
|
});
|
2019-08-26 08:51:36 +00:00
|
|
|
|
|
|
|
return (
|
2019-08-27 07:52:55 +00:00
|
|
|
<Section>
|
2019-08-27 13:02:18 +00:00
|
|
|
<ArrayValue
|
|
|
|
defaultValue={options}
|
|
|
|
onChange={() => console.log("ArrayValue onChange")}
|
|
|
|
>
|
|
|
|
{({ value, set }) => (
|
|
|
|
<AdvancedSelector
|
|
|
|
placeholder={text("placeholder", "Search users")}
|
2019-08-28 07:10:09 +00:00
|
|
|
onSearchChanged={value => {
|
2019-08-27 14:33:11 +00:00
|
|
|
set(options.filter(option => {
|
|
|
|
return (
|
2019-08-28 07:10:09 +00:00
|
|
|
option.label.indexOf(value) > -1
|
2019-08-27 14:33:11 +00:00
|
|
|
);
|
|
|
|
}));
|
|
|
|
}}
|
2019-08-27 13:02:18 +00:00
|
|
|
options={value}
|
|
|
|
groups={groups}
|
|
|
|
selectedGroups={[groups[0]]}
|
|
|
|
isMultiSelect={boolean("isMultiSelect", true)}
|
|
|
|
buttonLabel={text("buttonLabel", "Add members")}
|
2019-08-28 09:05:03 +00:00
|
|
|
selectAllLabel={text("selectAllLabel", "Select all")}
|
2019-08-27 14:33:11 +00:00
|
|
|
onSelect={selectedOptions => {
|
|
|
|
console.log("onSelect", selectedOptions);
|
|
|
|
}}
|
2019-08-27 13:02:18 +00:00
|
|
|
onChangeGroup={group => {
|
|
|
|
set(options.filter(option => {
|
|
|
|
return (
|
|
|
|
option.groups &&
|
|
|
|
option.groups.length > 0 &&
|
|
|
|
option.groups.indexOf(group.key) > -1
|
|
|
|
);
|
|
|
|
}));
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</ArrayValue>
|
2019-08-27 07:52:55 +00:00
|
|
|
</Section>
|
2019-08-26 08:51:36 +00:00
|
|
|
);
|
2019-08-27 07:52:55 +00:00
|
|
|
});
|