-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathAutoHideFollowButton.js
More file actions
49 lines (41 loc) · 1.09 KB
/
AutoHideFollowButton.js
File metadata and controls
49 lines (41 loc) · 1.09 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
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import useScrollToEnd from '../hooks/useScrollToEnd';
import useSticky from '../hooks/useSticky';
import useStyleToClassName from '../hooks/internal/useStyleToClassName';
const ROOT_STYLE = {
backgroundColor: 'rgba(0, 0, 0, .2)',
borderRadius: 10,
borderWidth: 0,
bottom: 5,
cursor: 'pointer',
height: 20,
outline: 0,
position: 'absolute',
right: 20,
width: 20,
'&:hover': {
backgroundColor: 'rgba(0, 0, 0, .4)'
},
'&:active': {
backgroundColor: 'rgba(0, 0, 0, .6)'
}
};
const AutoHideFollowButton = ({ children, className = '' }) => {
const [sticky] = useSticky();
const rootCSS = useStyleToClassName()(ROOT_STYLE);
const scrollToEnd = useScrollToEnd();
return (
!sticky && (
<button className={classNames(rootCSS, (className || '') + '')} onClick={scrollToEnd} type="button">
{children}
</button>
)
);
};
AutoHideFollowButton.propTypes = {
children: PropTypes.any,
className: PropTypes.string
};
export default AutoHideFollowButton;