choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
189 lines (158 loc) • 6.55 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import React, { Component } from 'react';
import classNames from 'classnames';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import { generateShowHourMinuteSecond } from '../time-picker';
import enUS from './locale/en_US';
import TimePickerPanel from '../rc-components/time-picker/Panel';
import { Size } from '../_util/enum';
import ConfigContext from '../config-provider/ConfigContext';
function getColumns(_ref) {
var showHour = _ref.showHour,
showMinute = _ref.showMinute,
showSecond = _ref.showSecond,
use12Hours = _ref.use12Hours;
var column = 0;
if (showHour) {
column += 1;
}
if (showMinute) {
column += 1;
}
if (showSecond) {
column += 1;
}
if (use12Hours) {
column += 1;
}
return column;
}
export default function wrapPicker(Picker, defaultFormat) {
var _a;
return _a = /*#__PURE__*/function (_Component) {
_inherits(PickerWrapper, _Component);
var _super = _createSuper(PickerWrapper);
function PickerWrapper() {
var _this;
_classCallCheck(this, PickerWrapper);
_this = _super.apply(this, arguments);
_this.handleOpenChange = function (open) {
var onOpenChange = _this.props.onOpenChange;
onOpenChange(open);
};
_this.handleFocus = function (e) {
var onFocus = _this.props.onFocus;
if (onFocus) {
onFocus(e);
}
};
_this.handleBlur = function (e) {
var onBlur = _this.props.onBlur;
if (onBlur) {
onBlur(e);
}
};
_this.savePicker = function (node) {
_this.picker = node;
};
_this.getDefaultLocale = function () {
var locale = _this.props.locale;
var result = _objectSpread(_objectSpread({}, enUS), locale);
result.lang = _objectSpread(_objectSpread({}, result.lang), (locale || {}).lang);
return result;
};
_this.renderPicker = function (locale, localeCode) {
var _classNames2, _classNames3;
var _assertThisInitialize = _assertThisInitialized(_this),
props = _assertThisInitialize.props;
var getPrefixCls = _this.context.getPrefixCls;
var _props$prefixCls = props.prefixCls,
prefixCls = _props$prefixCls === void 0 ? getPrefixCls('calendar') : _props$prefixCls,
_props$inputPrefixCls = props.inputPrefixCls,
inputPrefixCls = _props$inputPrefixCls === void 0 ? getPrefixCls('input') : _props$inputPrefixCls;
var pickerClass = classNames("".concat(prefixCls, "-picker"), _defineProperty({}, "".concat(prefixCls, "-picker-").concat(props.size), !!props.size));
var pickerInputClass = classNames("".concat(prefixCls, "-picker-input"), inputPrefixCls, (_classNames2 = {}, _defineProperty(_classNames2, "".concat(inputPrefixCls, "-lg"), props.size === Size.large), _defineProperty(_classNames2, "".concat(inputPrefixCls, "-sm"), props.size === Size.small), _defineProperty(_classNames2, "".concat(inputPrefixCls, "-disabled"), props.disabled), _classNames2));
var pickerWrapperInputClass = classNames("".concat(inputPrefixCls, "-wrapper"), (_classNames3 = {}, _defineProperty(_classNames3, "".concat(inputPrefixCls, "-disabled"), props.disabled), _defineProperty(_classNames3, "".concat(inputPrefixCls, "-has-border"), props.border && props.layoutLayout === 'float'), _classNames3));
var timeFormat = props.showTime && props.showTime.format || 'HH:mm:ss';
var rcTimePickerProps = _objectSpread(_objectSpread({}, generateShowHourMinuteSecond(timeFormat)), {}, {
format: timeFormat,
use12Hours: props.showTime && props.showTime.use12Hours
});
var columns = getColumns(rcTimePickerProps);
var timePickerCls = "".concat(prefixCls, "-time-picker-column-").concat(columns);
var timePicker = props.showTime ? /*#__PURE__*/React.createElement(TimePickerPanel, _extends({}, rcTimePickerProps, props.showTime, {
prefixCls: "".concat(prefixCls, "-time-picker"),
className: timePickerCls,
placeholder: locale.timePickerLocale.placeholder,
transitionName: "slide-up"
})) : null;
return /*#__PURE__*/React.createElement(Picker, _extends({}, props, {
ref: _this.savePicker,
pickerClass: pickerClass,
pickerInputClass: pickerInputClass,
pickerWrapperInputClass: pickerWrapperInputClass,
locale: locale,
localeCode: localeCode,
timePicker: timePicker,
onOpenChange: _this.handleOpenChange,
onFocus: _this.handleFocus,
onBlur: _this.handleBlur
}));
};
return _this;
}
_createClass(PickerWrapper, [{
key: "componentDidMount",
value: function componentDidMount() {
var _this$props = this.props,
autoFocus = _this$props.autoFocus,
disabled = _this$props.disabled;
if (autoFocus && !disabled) {
this.focus();
}
}
}, {
key: "focus",
value: function focus() {
this.picker.focus();
}
}, {
key: "blur",
value: function blur() {
this.picker.blur();
}
}, {
key: "render",
value: function render() {
return /*#__PURE__*/React.createElement(LocaleReceiver, {
componentName: "DatePicker",
defaultLocale: this.getDefaultLocale
}, this.renderPicker);
}
}], [{
key: "contextType",
get: function get() {
return ConfigContext;
}
}]);
return PickerWrapper;
}(Component), _a.displayName = 'PickerWrapper', _a.defaultProps = {
format: defaultFormat || 'YYYY-MM-DD',
transitionName: 'slide-up',
popupStyle: {},
onChange: function onChange() {},
onOk: function onOk() {},
onOpenChange: function onOpenChange() {},
locale: {},
border: true,
layoutLayout: 'float'
}, _a;
}
//# sourceMappingURL=wrapPicker.js.map