1 | import "core-js/modules/es7.object.get-own-property-descriptors";
|
2 | import "core-js/modules/es6.symbol";
|
3 | import "core-js/modules/web.dom.iterable";
|
4 | import "core-js/modules/es6.array.iterator";
|
5 | import "core-js/modules/es6.object.to-string";
|
6 | import "core-js/modules/es6.object.keys";
|
7 | import _extends from "@babel/runtime/helpers/extends";
|
8 | import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
9 | import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
10 | import _createClass from "@babel/runtime/helpers/createClass";
|
11 | import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
12 | import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
13 | import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
14 | import _inherits from "@babel/runtime/helpers/inherits";
|
15 |
|
16 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
17 |
|
18 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
19 |
|
20 | import React from 'react';
|
21 | import TimePicker from './rc-time-picker/lib/index';
|
22 | import DateTimeFormat from 'gregorian-calendar-format';
|
23 | import GregorianCalendar from 'gregorian-calendar';
|
24 | import classNames from 'classnames';
|
25 | import defaultLocale from './locale/zh_CN';
|
26 | export default function wrapPicker(Picker, defaultFormat) {
|
27 | var _class, _temp;
|
28 |
|
29 | return _temp = _class =
|
30 |
|
31 | function (_React$Component) {
|
32 | _inherits(PickerWrapper, _React$Component);
|
33 |
|
34 | function PickerWrapper(props) {
|
35 | var _this;
|
36 |
|
37 | _classCallCheck(this, PickerWrapper);
|
38 |
|
39 | _this = _possibleConstructorReturn(this, _getPrototypeOf(PickerWrapper).call(this, props));
|
40 |
|
41 | _this.getFormatter = function () {
|
42 | if (!_this.formats) {
|
43 | _this.formats = {};
|
44 | }
|
45 |
|
46 | var formats = _this.formats;
|
47 | var format = _this.props.format;
|
48 |
|
49 | if (formats[format]) {
|
50 | return formats[format];
|
51 | }
|
52 |
|
53 | formats[format] = new DateTimeFormat(format, _this.getLocale().lang.format);
|
54 | return formats[format];
|
55 | };
|
56 |
|
57 | _this.parseDateFromValue = function (value) {
|
58 | if (value) {
|
59 | if (typeof value === 'string') {
|
60 | return _this.getFormatter().parse(value, {
|
61 | locale: _this.getLocale()
|
62 | });
|
63 | } else if (value instanceof Date) {
|
64 | var date = new GregorianCalendar(_this.getLocale());
|
65 | date.setTime(+value);
|
66 | return date;
|
67 | }
|
68 | }
|
69 |
|
70 | return value;
|
71 | };
|
72 |
|
73 | _this.toggleOpen = function (e) {
|
74 | _this.props.changeActive(e.open);
|
75 | };
|
76 |
|
77 | _this.state = {};
|
78 | _this.clickDataTable = _this.clickDataTable.bind(_assertThisInitialized(_this));
|
79 | _this.toggleOpen = _this.toggleOpen.bind(_assertThisInitialized(_this));
|
80 | return _this;
|
81 | }
|
82 |
|
83 |
|
84 | _createClass(PickerWrapper, [{
|
85 | key: "componentWillReceiveProps",
|
86 | value: function componentWillReceiveProps(nextProps) {
|
87 | var temp = this.state.timeValue;
|
88 |
|
89 | if (temp) {
|
90 | temp.clickTips = false;
|
91 | this.setState({
|
92 | timeValue: temp
|
93 | });
|
94 | }
|
95 | }
|
96 | }, {
|
97 | key: "clickDataTable",
|
98 | value: function clickDataTable(value) {
|
99 | var _this2 = this;
|
100 |
|
101 | value.clickTips = true;
|
102 | this.setState({
|
103 | timeValue: value
|
104 | });
|
105 |
|
106 | setTimeout(function () {
|
107 | _this2.state.timeValue.clickTips = false;
|
108 | }, 0);
|
109 | }
|
110 | }, {
|
111 | key: "getLocale",
|
112 | value: function getLocale() {
|
113 | var props = this.props;
|
114 | var locale = defaultLocale;
|
115 | var context = this.context;
|
116 |
|
117 | if (context.antLocale && context.antLocale.DatePicker) {
|
118 | locale = context.antLocale.DatePicker;
|
119 | }
|
120 |
|
121 |
|
122 | var result = _objectSpread({}, locale, {}, props.locale);
|
123 |
|
124 | result.lang = _objectSpread({}, locale.lang, {}, props.locale.lang);
|
125 | return result;
|
126 | }
|
127 | }, {
|
128 | key: "render",
|
129 | value: function render() {
|
130 | var props = this.props;
|
131 | var pickerClass = classNames({
|
132 | 'ant-calendar-picker': true,
|
133 | 'ant-calendar-picker_has-error': this.props.errorStatus,
|
134 | 'ant-calendar-picker-open': props.IsActive || this.props.errorStatus
|
135 | });
|
136 | var pickerInputClass = classNames({
|
137 | 'ant-calendar-range-picker': true,
|
138 | 'ant-input': true,
|
139 | 'ant-input-lg': props.size === 'large',
|
140 | 'ant-input-sm': props.size === 'small'
|
141 | });
|
142 | var locale = this.getLocale();
|
143 | var timePicker = props.showTime ? React.createElement(TimePicker, {
|
144 | prefixCls: "ant-time-picker",
|
145 | dateValue: this.props.value,
|
146 | placeholder: locale.timePickerLocale.placeholder,
|
147 | value: this.state.timeValue,
|
148 | locale: locale.timePickerLocale,
|
149 | transitionName: "slide-up"
|
150 | }) : null;
|
151 | return React.createElement(Picker, _extends({}, this.props, {
|
152 | showStatus: this.props.showStatus,
|
153 | pickerClass: pickerClass,
|
154 | pickerInputClass: pickerInputClass,
|
155 | locale: locale,
|
156 | timePicker: timePicker,
|
157 | open: this.props.IsActive,
|
158 | clickDataTable: this.clickDataTable,
|
159 | toggleOpen: this.toggleOpen,
|
160 | getFormatter: this.getFormatter,
|
161 | parseDateFromValue: this.parseDateFromValue
|
162 | }));
|
163 | }
|
164 | }]);
|
165 |
|
166 | return PickerWrapper;
|
167 | }(React.Component), _class.defaultProps = {
|
168 | format: defaultFormat || 'yyyy-MM-dd',
|
169 | transitionName: 'slide-up',
|
170 | popupStyle: {},
|
171 | onChange: function onChange() {},
|
172 | onOk: function onOk() {},
|
173 | locale: {},
|
174 | align: {
|
175 | offset: [0, -9]
|
176 | },
|
177 | ipuBlur: function ipuBlur() {},
|
178 | open: false
|
179 | }, _temp;
|
180 | } |
\ | No newline at end of file |