-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMultiSelectInput.stories.tsx
More file actions
150 lines (129 loc) · 4.15 KB
/
MultiSelectInput.stories.tsx
File metadata and controls
150 lines (129 loc) · 4.15 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import React from 'react';
import { Story } from '@storybook/react/types-6-0';
import { useArgs } from '@storybook/client-api';
import { IoOpenOutline } from 'react-icons/io5';
import MultiSelectInput, { MultiSelectInputProps } from '#components/MultiSelectInput';
import QuickActionButton from '#components/QuickActionButton';
export default {
title: 'Input/MultiSelectInput',
component: MultiSelectInput,
argTypes: {},
};
interface Option {
key: string;
label: string;
parentKey: string;
parentLabel: string;
}
const options: Option[] = [
{ key: '1', label: 'Potato Potato Potato Potato Potato Potato Potato', parentKey: '1', parentLabel: 'Brown' },
{ key: '2', label: 'Tomato', parentKey: '2', parentLabel: 'Red' },
{ key: '3', label: 'Pumpkin', parentKey: '2', parentLabel: 'Red' },
{ key: '4', label: 'Gourd', parentKey: '3', parentLabel: 'Green' },
{ key: '5', label: 'Spinach', parentKey: '3', parentLabel: 'Green' },
{ key: '6', label: 'Eggplant', parentKey: '4', parentLabel: 'PurplePurplPurplPurplPurplPurplPurplPurplPurplPurplPurplPurplPurplPurpleeeeeeeeeeeee' },
];
// eslint-disable-next-line max-len
const Template: Story<MultiSelectInputProps<string, string, Option, { containerClassName?: string }>> = (props) => {
const [{ value }, updateArgs] = useArgs();
const setValue = (e: string[]) => {
updateArgs({ value: e });
};
return (
<MultiSelectInput
label="Vegetables"
{...props}
options={options}
value={value}
onChange={setValue}
keySelector={(d) => d.key}
labelSelector={(d) => d.label}
/>
);
};
function handleClick(_:string | undefined, e: React.MouseEvent<HTMLButtonElement>) {
// NOTE: This intentionally breaks HTML semantics (link inside a button).
// This workaround is to allow clickable links inside SelectInput options
// where a button wrapper is required.
e.stopPropagation();
window.open('https://www.google.com/search?q=story', '_blank');
}
export const WithActions = Template.bind({});
WithActions.args = {
actionsSelector: () => (
<QuickActionButton
name={undefined}
onClick={handleClick}
transparent
>
<IoOpenOutline />
</QuickActionButton>
),
};
export const NoValue = Template.bind({});
NoValue.args = {
value: undefined,
};
export const Default = Template.bind({});
Default.args = {
value: ['1', '3'],
};
export const Disabled = Template.bind({});
Disabled.args = {
value: ['1', '3'],
disabled: true,
};
export const ReadOnly = Template.bind({});
ReadOnly.args = {
value: ['1', '3'],
readOnly: true,
};
// eslint-disable-next-line max-len
const GroupedTemplate: Story<MultiSelectInputProps<string, string, Option, { containerClassName?: string }>> = (props) => {
const [{ value }, updateArgs] = useArgs();
const setValue = (e: string[]) => {
updateArgs({ value: e });
};
return (
<MultiSelectInput
label="Vegetables"
{...props}
options={options}
value={value}
onChange={setValue}
keySelector={(d) => d.key}
labelSelector={(d) => d.label}
grouped
groupKeySelector={(d) => d.parentKey}
groupLabelSelector={(d) => d.parentLabel}
/>
);
};
export const NoValueGrouped = GroupedTemplate.bind({});
NoValueGrouped.args = {
value: undefined,
};
export const DefaultGrouped = GroupedTemplate.bind({});
DefaultGrouped.args = {
value: ['1', '3'],
};
export const DisabledGrouped = GroupedTemplate.bind({});
DisabledGrouped.args = {
value: ['1', '3'],
disabled: true,
};
export const ReadOnlyGrouped = GroupedTemplate.bind({});
ReadOnlyGrouped.args = {
value: ['1', '3'],
readOnly: true,
};
export const WithPlaceholder = GroupedTemplate.bind({});
WithPlaceholder.args = {
label: 'Vegetable',
placeholder: 'Name',
};
export const OptionStartingWithP = GroupedTemplate.bind({});
OptionStartingWithP.args = {
value: ['2', '3'],
hideOptionFilter: (opt: Option) => opt.label.startsWith('P'),
};