-
-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy path5-Hooks.stories.js
76 lines (70 loc) · 2.31 KB
/
5-Hooks.stories.js
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
import React from 'react';
import { CSSTransition } from 'react-transition-group';
import classes from './assets/hooks.module.css';
import useSelect from '../src/useSelect';
export default {
title: 'Hooks',
};
const classNames = {
appear: classes.appear,
appearActive: classes['appear-active'],
appearDone: classes['appear-done'],
enter: classes.enter,
enterActive: classes['enter-active'],
enterDone: classes['enter-done'],
exit: classes.exit,
exitActive: classes['exit-active'],
exitDone: classes['exit-done'],
};
const options = [
{ value: 's', name: 'Small' },
{ value: 'm', name: 'Medium' },
{ value: 'l', name: 'Large' },
];
const CustomSelect = ({ options, value }) => {
const [snapshot, valueProps, optionProps] = useSelect({
options,
defaultValue: value,
allowEmpty: false,
});
return (
<>
<div
{...valueProps}
className={classes.button}
>{`Size: ${snapshot.displayValue}`}</div>
<CSSTransition
in={snapshot.focus}
timeout={200}
mountOnEnter
unmountOnExit
classNames={classNames}
>
<div className={classes.select}>
<div className={classes.options}>
{snapshot.options.map((option) => (
<button
key={option.value}
{...optionProps}
value={option.value}
className={[
classes.option,
snapshot.value === option.value
? classes['is-selected']
: null,
]
.filter(Boolean)
.join(' ')}
>
{option.name}
</button>
))}
</div>
</div>
</CSSTransition>
</>
);
};
export const CustomComponents = () => {
return <CustomSelect options={options} value={null} />;
};