-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHideAt.jsx
64 lines (53 loc) · 1.63 KB
/
HideAt.jsx
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
import React from 'react';
import PropTypes from 'prop-types';
import withBreakpoint from 'react-with-breakpoints';
function HideAt(props) {
const breakpoint = props.breakpoint;
const currentBreakpoint = props.currentBreakpoint;
let shouldRender;
if (breakpoint.includes('small') && currentBreakpoint === 'small') {
shouldRender = false;
} else {
shouldRender = true;
}
if (breakpoint.includes('medium')) {
if (breakpoint.includes('AndBelow') && currentBreakpoint !== 'large') {
shouldRender = false;
} else if (breakpoint.includes('AndAbove') && currentBreakpoint !== 'small') {
shouldRender = false;
} else if (breakpoint === 'medium' && currentBreakpoint === 'medium') {
shouldRender = false;
}
}
if (breakpoint.includes('large')) {
if (breakpoint.includes('AndBelow')) {
shouldRender = false;
} else if (currentBreakpoint !== 'large') {
shouldRender = true;
} else {
shouldRender = false;
}
}
if (shouldRender) {
return (<div>{ props.children }</div>);
// TODO: solve unnecessary else after return
// eslint-disable-next-line
} else {
return null;
}
}
HideAt.propTypes = {
breakpoint: PropTypes.oneOf(['small', 'medium', 'mediumAndBelow', 'mediumAndAbove', 'largeAndBelow', 'large']).isRequired,
// eslint-disable-next-line
breakpoints: PropTypes.object,
currentBreakpoint: PropTypes.string,
children: PropTypes.node,
};
HideAt.displayName = 'HideAt';
HideAt.defaultProps = {
breakpoint: '',
currentBreakpoint: '',
children: null,
};
const HideAtWithBreakpoint = withBreakpoint(HideAt);
export default HideAtWithBreakpoint;