-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathSelect.stories.tsx
More file actions
75 lines (65 loc) · 2.15 KB
/
Copy pathSelect.stories.tsx
File metadata and controls
75 lines (65 loc) · 2.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
import { type Meta, type StoryFn } from '@storybook/react';
import { SelectV2, type SelectV2Props } from './Select';
type StoryProps = Pick<SelectV2Props<string>, 'disabled' | 'placeholder'>;
const Story: Meta<StoryProps> = {
title: 'SelectV2',
args: {
placeholder: 'Select a value...',
disabled: false,
},
argTypes: {
placeholder: { type: 'string' },
disabled: { type: 'boolean' },
},
};
export default Story;
const fruits = ['apple', 'banana', 'blueberry', 'grapes', 'pineapple', 'pear'];
export const Default: StoryFn<StoryProps> = (args) => (
<SelectV2
{...args}
value="apple"
onChange={() => undefined}
options={fruits.map((fruit) => ({
label: fruit,
value: fruit,
}))}
/>
);
const books = new Map(
[
{ author: 'Harper Lee', title: 'To Kill a Mockingbird' },
{ author: 'Lev Tolstoy', title: 'War and Peace' },
{ author: 'Fyodor Dostoyevsy', title: 'The Idiot' },
{ author: 'Oscar Wilde', title: 'A Picture of Dorian Gray' },
{ author: 'George Orwell', title: '1984' },
{ author: 'Jane Austen', title: 'Pride and Prejudice' },
{ author: 'Marcus Aurelius', title: 'Meditations' },
{ author: 'Fyodor Dostoevsky', title: 'The Brothers Karamazov' },
{ author: 'Lev Tolstoy', title: 'Anna Karenina' },
{ author: 'Fyodor Dostoevsky', title: 'Crime and Punishment' },
].map((book) => [`${book.author}_${book.title}`, book]),
);
const bookKeys = Array.from(books.keys());
export const Complex: StoryFn<StoryProps> = ({ placeholder, ...args }: StoryProps) => (
<SelectV2
{...args}
value={bookKeys[0] ?? ''}
onChange={() => undefined}
placeholder={placeholder}
displayedValue={(option) => books.get(option.value)?.title ?? option.value}
options={bookKeys.map((bookKey) => {
const book = books.get(bookKey);
return {
label: book ? (
<div>
<p className="text-s text-grey-primary text-start font-semibold">{book.title}</p>
<p className="text-grey-secondary text-start text-xs font-normal">{book.author}</p>
</div>
) : (
bookKey
),
value: bookKey,
};
})}
/>
);