forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsticky.jsx
74 lines (69 loc) · 2.17 KB
/
sticky.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
72
73
74
import React from 'react';
import PropTypes from 'prop-types';
import Header from './fixed/header';
import StickyHeader from './sticky/header';
import { statics } from './util';
export default function sticky(BaseComponent) {
/** Table */
class StickyTable extends React.Component {
static StickyHeader = StickyHeader;
static propTypes = {
/**
* 表头是否是sticky
*/
stickyHeader: PropTypes.bool,
/**
* 距离窗口顶部达到指定偏移量后触发
*/
offsetTop: PropTypes.number,
/**
* affix组件的的属性
*/
affixProps: PropTypes.object,
components: PropTypes.object,
...BaseComponent.propTypes,
};
static defaultProps = {
components: {},
...BaseComponent.defaultProps,
};
static childContextTypes = {
Header: PropTypes.any,
offsetTop: PropTypes.number,
affixProps: PropTypes.object,
};
getChildContext() {
return {
Header: this.props.components.Header || Header,
offsetTop: this.props.offsetTop,
affixProps: this.props.affixProps,
};
}
render() {
/* eslint-disable no-unused-vars */
const {
stickyHeader,
offsetTop,
affixProps,
...others
} = this.props;
let { components, maxBodyHeight, fixedHeader } = this.props;
if (stickyHeader) {
components = { ...components };
components.Header = StickyHeader;
fixedHeader = true;
maxBodyHeight = Math.max(maxBodyHeight, 10000);
}
return (
<BaseComponent
{...others}
components={components}
fixedHeader={fixedHeader}
maxBodyHeight={maxBodyHeight}
/>
);
}
}
statics(StickyTable, BaseComponent);
return StickyTable;
}