1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
3 | import _createClass from 'babel-runtime/helpers/createClass';
|
4 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
5 | import _inherits from 'babel-runtime/helpers/inherits';
|
6 |
|
7 | import PropTypes from 'prop-types';
|
8 | import React from 'react';
|
9 | import RCDatePicker from 'rmc-date-picker/es/DatePicker';
|
10 | import PopupDatePicker from 'rmc-date-picker/es/Popup';
|
11 | import { getComponentLocale } from '../_util/getLocale';
|
12 | import { formatFn } from './utils';
|
13 |
|
14 | var DatePicker = function (_React$Component) {
|
15 | _inherits(DatePicker, _React$Component);
|
16 |
|
17 | function DatePicker() {
|
18 | _classCallCheck(this, DatePicker);
|
19 |
|
20 | var _this = _possibleConstructorReturn(this, (DatePicker.__proto__ || Object.getPrototypeOf(DatePicker)).apply(this, arguments));
|
21 |
|
22 | _this.setScrollValue = function (v) {
|
23 | _this.scrollValue = v;
|
24 | };
|
25 | _this.onOk = function (v) {
|
26 | if (_this.scrollValue !== undefined) {
|
27 | v = _this.scrollValue;
|
28 | }
|
29 | if (_this.props.onChange) {
|
30 | _this.props.onChange(v);
|
31 | }
|
32 | if (_this.props.onOk) {
|
33 | _this.props.onOk(v);
|
34 | }
|
35 | };
|
36 | _this.onVisibleChange = function (visible) {
|
37 | _this.scrollValue = undefined;
|
38 | if (_this.props.onVisibleChange) {
|
39 | _this.props.onVisibleChange(visible);
|
40 | }
|
41 | };
|
42 | _this.fixOnOk = function (picker) {
|
43 | if (picker) {
|
44 | picker.onOk = _this.onOk;
|
45 | }
|
46 | };
|
47 | return _this;
|
48 | }
|
49 |
|
50 | _createClass(DatePicker, [{
|
51 | key: 'render',
|
52 | value: function render() {
|
53 |
|
54 | var props = this.props,
|
55 | context = this.context;
|
56 | var children = props.children,
|
57 | value = props.value,
|
58 | popupPrefixCls = props.popupPrefixCls;
|
59 |
|
60 | var locale = getComponentLocale(props, context, 'DatePicker', function () {
|
61 | return require('./locale/zh_CN');
|
62 | });
|
63 | var okText = locale.okText,
|
64 | dismissText = locale.dismissText,
|
65 | extra = locale.extra,
|
66 | DatePickerLocale = locale.DatePickerLocale;
|
67 | |
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | var dataPicker = React.createElement(RCDatePicker, { minuteStep: props.minuteStep, locale: DatePickerLocale, minDate: props.minDate, maxDate: props.maxDate, mode: props.mode, pickerPrefixCls: props.pickerPrefixCls, prefixCls: props.prefixCls, defaultDate: value || new Date(), use12Hours: props.use12Hours, onValueChange: props.onValueChange, onScrollChange: this.setScrollValue });
|
83 | return React.createElement(
|
84 | PopupDatePicker,
|
85 | _extends({ datePicker: dataPicker, WrapComponent: 'div', transitionName: 'am-slide-up', maskTransitionName: 'am-fade' }, props, { prefixCls: popupPrefixCls, date: value || new Date(), dismissText: this.props.dismissText || dismissText, okText: this.props.okText || okText, ref: this.fixOnOk, onVisibleChange: this.onVisibleChange }),
|
86 | children && React.isValidElement(children) && React.cloneElement(children, {
|
87 | extra: value ? formatFn(this, value) : this.props.extra || extra
|
88 | })
|
89 | );
|
90 | }
|
91 | }]);
|
92 |
|
93 | return DatePicker;
|
94 | }(React.Component);
|
95 |
|
96 | export default DatePicker;
|
97 |
|
98 | DatePicker.defaultProps = {
|
99 | mode: 'datetime',
|
100 | prefixCls: 'am-picker',
|
101 | pickerPrefixCls: 'am-picker-col',
|
102 | popupPrefixCls: 'am-picker-popup',
|
103 | minuteStep: 1,
|
104 | use12Hours: false
|
105 | };
|
106 | DatePicker.contextTypes = {
|
107 | antLocale: PropTypes.object
|
108 | }; |
\ | No newline at end of file |