1 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
2 | import _createClass from 'babel-runtime/helpers/createClass';
|
3 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
4 | import _inherits from 'babel-runtime/helpers/inherits';
|
5 | import * as React from 'react';
|
6 | import Component from './DatePicker.base';
|
7 | import WeekPanel from './date/WeekPanel';
|
8 | import SingleMonth from './date/SingleMonth';
|
9 | import DOMScroller from 'zscroller/es/DOMScroller';
|
10 |
|
11 | var DatePicker = function (_Component) {
|
12 | _inherits(DatePicker, _Component);
|
13 |
|
14 | function DatePicker() {
|
15 | _classCallCheck(this, DatePicker);
|
16 |
|
17 | var _this = _possibleConstructorReturn(this, (DatePicker.__proto__ || Object.getPrototypeOf(DatePicker)).apply(this, arguments));
|
18 |
|
19 | _this.genMonthComponent = function (data) {
|
20 | if (!data) return;
|
21 | return React.createElement(SingleMonth, { key: data.title, locale: _this.props.locale || {}, monthData: data, rowSize: _this.props.rowSize, onCellClick: _this.onCellClick, getDateExtra: _this.props.getDateExtra, ref: function ref(dom) {
|
22 | data.componentRef = dom || undefined;
|
23 | data.updateLayout = function () {
|
24 | _this.computeHeight(data, dom);
|
25 | };
|
26 | data.updateLayout();
|
27 | } });
|
28 | };
|
29 | _this.computeHeight = function (data, singleMonth) {
|
30 | if (singleMonth && singleMonth.wrapperDivDOM) {
|
31 | if (!data.height && !singleMonth.wrapperDivDOM.clientHeight) {
|
32 | setTimeout(function () {
|
33 | return _this.computeHeight(data, singleMonth);
|
34 | }, 500);
|
35 | return;
|
36 | }
|
37 | data.height = singleMonth.wrapperDivDOM.clientHeight || data.height || 0;
|
38 | data.y = singleMonth.wrapperDivDOM.offsetTop || data.y || 0;
|
39 | }
|
40 | };
|
41 | _this.setLayout = function (dom) {
|
42 | if (!_this.scroller) {
|
43 | var _this$props = _this.props,
|
44 | infinite = _this$props.infinite,
|
45 | initalMonths = _this$props.initalMonths,
|
46 | onLayout = _this$props.onLayout;
|
47 |
|
48 | onLayout && onLayout(dom.clientHeight);
|
49 | var scrollHandler = _this.createOnScroll();
|
50 | if (infinite) {
|
51 | _this.scroller = new DOMScroller(dom.children[0], {
|
52 | scrollingX: false,
|
53 | onScroll: function onScroll() {
|
54 | return scrollHandler({
|
55 | client: dom.clientHeight,
|
56 | full: dom.children[0].clientHeight,
|
57 | top: _this.scroller.getValues().top
|
58 | });
|
59 | }
|
60 | }).scroller;
|
61 | _this.scroller.activatePullToRefresh(40, function () {}, function () {}, function () {
|
62 | _this.canLoadPrev() && _this.genMonthData(_this.state.months[0].firstDate, -1);
|
63 | _this.visibleMonth = _this.visibleMonth.slice(0, initalMonths);
|
64 | _this.state.months.forEach(function (m) {
|
65 | m.updateLayout && m.updateLayout();
|
66 | });
|
67 | _this.scroller.finishPullToRefresh();
|
68 | });
|
69 | } else {
|
70 | _this.scroller = true;
|
71 | dom.onscroll = function (evt) {
|
72 | scrollHandler({
|
73 | client: dom.clientHeight,
|
74 | full: evt.target.clientHeight,
|
75 | top: evt.target.scrollTop
|
76 | });
|
77 | };
|
78 | }
|
79 | }
|
80 | };
|
81 | return _this;
|
82 | }
|
83 |
|
84 | _createClass(DatePicker, [{
|
85 | key: 'render',
|
86 | value: function render() {
|
87 | var _this2 = this;
|
88 |
|
89 | var _props = this.props,
|
90 | infinite = _props.infinite,
|
91 | _props$prefixCls = _props.prefixCls,
|
92 | prefixCls = _props$prefixCls === undefined ? '' : _props$prefixCls,
|
93 | _props$locale = _props.locale,
|
94 | locale = _props$locale === undefined ? {} : _props$locale;
|
95 |
|
96 | return React.createElement(
|
97 | 'div',
|
98 | { className: prefixCls + ' date-picker' },
|
99 | React.createElement(WeekPanel, null),
|
100 | React.createElement(
|
101 | 'div',
|
102 | { className: 'wrapper', style: {
|
103 | overflowX: 'hidden',
|
104 | overflowY: infinite ? 'hidden' : 'scroll'
|
105 | }, ref: this.setLayout },
|
106 | React.createElement(
|
107 | 'div',
|
108 | null,
|
109 | this.canLoadPrev() && React.createElement(
|
110 | 'div',
|
111 | { className: 'load-tip' },
|
112 | locale.loadPrevMonth
|
113 | ),
|
114 | React.createElement(
|
115 | 'div',
|
116 | { className: 'months' },
|
117 | this.state.months.map(function (m) {
|
118 | var hidden = m.height && _this2.visibleMonth.indexOf(m) < 0;
|
119 | if (hidden) {
|
120 | return React.createElement('div', { key: m.title + '_shallow', style: { height: m.height } });
|
121 | }
|
122 | return m.component;
|
123 | })
|
124 | )
|
125 | )
|
126 | )
|
127 | );
|
128 | }
|
129 | }]);
|
130 |
|
131 | return DatePicker;
|
132 | }(Component);
|
133 |
|
134 | export default DatePicker; |
\ | No newline at end of file |