-
Notifications
You must be signed in to change notification settings - Fork 82
/
WithAnimation.js
84 lines (72 loc) · 1.75 KB
/
WithAnimation.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
77
78
79
80
81
82
83
84
import React, { useState } from 'react';
import styled from '@emotion/styled';
import { keyframes, css } from '@emotion/core';
import { Heading } from './components/Heading';
import Select from '../../../src';
const WithAnimation = ({ options, title }) => {
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const [open, setOpen] = useState(null);
return (
<React.Fragment>
<Heading
title={title}
source="https://github.com/sanusart/react-dropdown-select/tree/master/docs/src/examples/WithAnimation.js"
/>
<StyledSelect
multi
options={options}
values={[]}
isOpen={open}
onDropdownCloseRequest={({ close }) => {
setOpen(true);
sleep(300).then(() => {
close();
setOpen(false);
});
}}
onChange={(value) =>
console.log(`%c > onChange ${title} `, 'background: #555; color: tomato', value)
}
/>
</React.Fragment>
);
};
const hide = keyframes`
from {
transition: height 310ms ease;
}
to {
transition: height 310ms ease;
height: 0;
opacity: 0;
}
`;
const show = keyframes`
from {
transition: height 310ms ease;
height: 0;
opacity: 0;
}
to {
transition: height 310ms ease;
}
`;
const StyledSelect = styled(Select)`
transition: all 0.3s ease-out;
.react-dropdown-select-dropdown {
height: 310px;
${({ isOpen }) =>
isOpen
? css`
animation: ${hide} 310ms ease-in-out;
`
: css`
animation: ${show} 310ms ease-in-out;
`};
}
.react-dropdown-select-option {
transition: all 0.3s ease-out;
}
`;
WithAnimation.propTypes = {};
export default WithAnimation;