1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
4 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
5 | import _inherits from 'babel-runtime/helpers/inherits';
|
6 |
|
7 | var _class, _temp;
|
8 |
|
9 | import React from 'react';
|
10 | import { polyfill } from 'react-lifecycles-compat';
|
11 | import * as PT from 'prop-types';
|
12 | import classnames from 'classnames';
|
13 |
|
14 | import SharedPT from '../prop-types';
|
15 | import { func, obj } from '../../util';
|
16 | import defaultLocale from '../../locale/zh-cn';
|
17 |
|
18 | import Button from '../../button';
|
19 |
|
20 | var renderNode = func.renderNode;
|
21 |
|
22 |
|
23 | function normalizePreset(preset) {
|
24 | if (Array.isArray(preset)) {
|
25 | return preset;
|
26 | } else {
|
27 | return Object.keys(preset).map(function (key) {
|
28 | return {
|
29 | label: key,
|
30 | value: preset[key]
|
31 | };
|
32 | });
|
33 | }
|
34 | }
|
35 |
|
36 | var FooterPanel = (_temp = _class = function (_React$PureComponent) {
|
37 | _inherits(FooterPanel, _React$PureComponent);
|
38 |
|
39 | function FooterPanel(props) {
|
40 | _classCallCheck(this, FooterPanel);
|
41 |
|
42 | var _this = _possibleConstructorReturn(this, _React$PureComponent.call(this, props));
|
43 |
|
44 | _this.renderRanges = function () {
|
45 | if (!_this.props.preset) {
|
46 | return null;
|
47 | }
|
48 |
|
49 | var preset = normalizePreset(_this.props.preset);
|
50 |
|
51 | return preset.map(function (_ref, index) {
|
52 | var label = _ref.label,
|
53 | value = _ref.value,
|
54 | restProps = _objectWithoutProperties(_ref, ['label', 'value']);
|
55 |
|
56 | var buttonProps = obj.pickProps(Button.propTypes, restProps);
|
57 |
|
58 | var handleClick = function handleClick() {
|
59 | var date = typeof value === 'function' ? value() : value;
|
60 | _this.props.onChange(date, 'CLICK_PRESET');
|
61 | };
|
62 | return React.createElement(
|
63 | Button,
|
64 | _extends({
|
65 | text: preset.length === 1,
|
66 | size: 'small',
|
67 | type: preset.length === 1 ? 'primary' : 'secondary',
|
68 | key: label + '-' + index
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | , onClick: handleClick
|
76 | }, buttonProps),
|
77 | label
|
78 | );
|
79 | });
|
80 | };
|
81 |
|
82 | _this.prefixCls = props.prefix + 'date-picker2-footer';
|
83 | return _this;
|
84 | }
|
85 |
|
86 | FooterPanel.prototype.render = function render() {
|
87 | var _classnames, _classnames2;
|
88 |
|
89 | var prefixCls = this.prefixCls;
|
90 | var _props = this.props,
|
91 | showOk = _props.showOk,
|
92 | locale = _props.locale,
|
93 | onOk = _props.onOk,
|
94 | oKable = _props.oKable,
|
95 | extraRender = _props.extraRender,
|
96 | className = _props.className;
|
97 |
|
98 |
|
99 | var classNames = classnames(prefixCls, className, (_classnames = {}, _classnames[prefixCls + '-with-actions'] = showOk, _classnames));
|
100 |
|
101 | var extraNode = renderNode(extraRender);
|
102 | var rangeNode = this.renderRanges();
|
103 | var actionsNode = React.createElement(
|
104 | Button,
|
105 | { size: 'small', disabled: !oKable, onClick: onOk, className: prefixCls + '-ok', type: 'primary' },
|
106 | locale.ok
|
107 | );
|
108 |
|
109 | var showFooter = showOk || extraNode || rangeNode;
|
110 | var rangesCls = classnames(prefixCls + '-preset', (_classnames2 = {}, _classnames2[prefixCls + '-preset-only'] = !showOk && !extraNode, _classnames2));
|
111 |
|
112 | return showFooter ? React.createElement(
|
113 | 'div',
|
114 | { className: classNames },
|
115 | extraNode ? React.createElement(
|
116 | 'div',
|
117 | { className: prefixCls + '-extra' },
|
118 | extraNode
|
119 | ) : null,
|
120 | rangeNode ? React.createElement(
|
121 | 'div',
|
122 | { className: rangesCls },
|
123 | rangeNode
|
124 | ) : null,
|
125 | showOk ? React.createElement(
|
126 | 'div',
|
127 | { className: prefixCls + '-actions' },
|
128 | actionsNode
|
129 | ) : null
|
130 | ) : null;
|
131 | };
|
132 |
|
133 | return FooterPanel;
|
134 | }(React.PureComponent), _class.propTypes = {
|
135 | rtl: PT.bool,
|
136 | className: PT.string,
|
137 | prefix: PT.string,
|
138 | locale: PT.object,
|
139 | showOk: PT.bool,
|
140 | preset: PT.oneOfType([PT.array, PT.object]),
|
141 | onOk: PT.func,
|
142 | oKable: PT.bool,
|
143 | extraRender: SharedPT.render
|
144 | }, _class.defaultProps = {
|
145 | locale: defaultLocale.DatePicker
|
146 | }, _temp);
|
147 |
|
148 |
|
149 | export default polyfill(FooterPanel); |
\ | No newline at end of file |