/
table-fixed-cell.jsx
71 lines (63 loc) · 1.68 KB
/
table-fixed-cell.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
65
66
67
68
69
70
71
import * as React from 'react';
import * as PropTypes from 'prop-types';
import { ThemeColors } from './layout';
import { getStickyPosition } from '../utils/css-fallback-properties';
export class FixedCell extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
stickyPosition: getStickyPosition(),
};
}
componentDidMount() {
this.setState({ stickyPosition: getStickyPosition() });
}
render() {
const {
component: CellPlaceholder,
position,
selected,
showLeftDivider,
showRightDivider,
side,
style,
...restProps
} = this.props;
const { backgroundColor, borderColor } = this.context;
const { stickyPosition } = this.state;
return (
<CellPlaceholder
style={{
backgroundClip: 'padding-box',
backgroundColor: selected ? null : backgroundColor,
position: stickyPosition,
zIndex: 300,
[side]: position,
...borderColor ? {
...showLeftDivider ? { borderLeft: `1px solid ${borderColor}` } : null,
...showRightDivider ? { borderRight: `1px solid ${borderColor}` } : null,
} : null,
...style,
}}
{...restProps}
/>
);
}
}
FixedCell.contextType = ThemeColors;
FixedCell.propTypes = {
component: PropTypes.func.isRequired,
position: PropTypes.number,
selected: PropTypes.bool,
showLeftDivider: PropTypes.bool,
showRightDivider: PropTypes.bool,
side: PropTypes.string.isRequired,
style: PropTypes.object,
};
FixedCell.defaultProps = {
position: undefined,
selected: false,
showLeftDivider: false,
showRightDivider: false,
style: null,
};