/
DateTable.jsx
65 lines (56 loc) · 1.65 KB
/
DateTable.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
// customized rc-calendar https://github.com/react-component/calendar/blob/master/
import React from 'react';
import PropTypes from 'prop-types'
import classnames from 'classnames';
import DateTHead from './DateTHead';
import DateTBody from './DateTBody';
export default class DateTable extends React.Component {
static propTypes = {
localeStr: PropTypes.string
}
static defaultProps = {
localeStr: 'zh-cn'
}
constructor(props) {
super(props);
this.state = {
tableHeight: 0,
};
}
componentDidMount() {
this.setState({
tableHeight: this.fullTable.offsetHeight,
});
}
renderEvents() {
const {
scheduleRender, startHour, step, endHour, value, type,
} = this.props;
const { tableHeight } = this.state;
const renderOpts = {
startHour, step, endHour, type, current: value, ...this.props,
};
if (scheduleRender) {
return scheduleRender(renderOpts, tableHeight);
}
return '';
}
render() {
const { prefixCls, defaultCellHeight } = this.props;
const fullTableHeight = this.fullTable ? this.fullTable.offsetHeight : 0;
const cellHeight = 0.8 * (fullTableHeight - 32) / 6;
const tableCls = classnames({
[`${prefixCls}-table`]: true,
'super-mini': cellHeight <= (defaultCellHeight || 42) && cellHeight > 0,
});
return (
<div className={tableCls} key={`${prefixCls}-date`}>
<table className={`${prefixCls}-table`} cellSpacing="0" role="grid" ref={(c) => { this.fullTable = c; }}>
<DateTHead {...this.props} />
<DateTBody {...this.props} />
</table>
{this.renderEvents()}
</div>
);
}
}