UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

209 lines (187 loc) 7 kB
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 _defineProperty from "@babel/runtime/helpers/defineProperty"; import React, { Component } from 'react'; import moment from 'moment'; import classNames from 'classnames'; import noop from 'lodash/noop'; import Header from './Header'; import Combobox from './Combobox'; function generateOptions(length, disabledOptions, hideDisabledOptions) { var step = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1; var arr = []; for (var value = 0; value < length; value += step) { if (!disabledOptions || disabledOptions.indexOf(value) < 0 || !hideDisabledOptions) { arr.push(value); } } return arr; } var Panel = /*#__PURE__*/function (_Component) { _inherits(Panel, _Component); var _super = _createSuper(Panel); function Panel(props) { var _this; _classCallCheck(this, Panel); _this = _super.call(this, props); _defineProperty(_assertThisInitialized(_this), "onChange", function (newValue) { _this.setState({ value: newValue }); _this.props.onChange(newValue); }); _defineProperty(_assertThisInitialized(_this), "onCurrentSelectPanelChange", function (currentSelectPanel) { _this.setState({ currentSelectPanel: currentSelectPanel }); }); _defineProperty(_assertThisInitialized(_this), "disabledHours", function () { var _this$props = _this.props, use12Hours = _this$props.use12Hours, disabledHours = _this$props.disabledHours; var disabledOptions = disabledHours(); if (use12Hours && Array.isArray(disabledOptions)) { if (_this.isAM()) { disabledOptions = disabledOptions.filter(function (h) { return h < 12; }).map(function (h) { return h === 0 ? 12 : h; }); } else { disabledOptions = disabledOptions.map(function (h) { return h === 12 ? 12 : h - 12; }); } } return disabledOptions; }); _this.state = { value: props.value, selectionRange: [] }; return _this; } _createClass(Panel, [{ key: "componentWillReceiveProps", value: function componentWillReceiveProps(nextProps) { var value = nextProps.value; if (value) { this.setState({ value: value }); } } }, { key: "close", value: function close() { this.props.onEsc(); } }, { key: "isAM", value: function isAM() { var value = this.state.value || this.props.defaultOpenValue; return value.hour() >= 0 && value.hour() < 12; } }, { key: "render", value: function render() { var _classNames; var _this$props2 = this.props, prefixCls = _this$props2.prefixCls, className = _this$props2.className, placeholder = _this$props2.placeholder, disabledMinutes = _this$props2.disabledMinutes, disabledSeconds = _this$props2.disabledSeconds, hideDisabledOptions = _this$props2.hideDisabledOptions, allowEmpty = _this$props2.allowEmpty, showHour = _this$props2.showHour, showMinute = _this$props2.showMinute, showSecond = _this$props2.showSecond, format = _this$props2.format, defaultOpenValue = _this$props2.defaultOpenValue, clearText = _this$props2.clearText, onEsc = _this$props2.onEsc, addon = _this$props2.addon, use12Hours = _this$props2.use12Hours, onClear = _this$props2.onClear, focusOnOpen = _this$props2.focusOnOpen, onKeyDown = _this$props2.onKeyDown, hourStep = _this$props2.hourStep, minuteStep = _this$props2.minuteStep, secondStep = _this$props2.secondStep, inputReadOnly = _this$props2.inputReadOnly, clearIcon = _this$props2.clearIcon; var _this$state = this.state, value = _this$state.value, currentSelectPanel = _this$state.currentSelectPanel; var disabledHourOptions = this.disabledHours(); var disabledMinuteOptions = disabledMinutes(value ? value.hour() : null); var disabledSecondOptions = disabledSeconds(value ? value.hour() : null, value ? value.minute() : null); var hourOptions = generateOptions(24, disabledHourOptions, hideDisabledOptions, hourStep); var minuteOptions = generateOptions(60, disabledMinuteOptions, hideDisabledOptions, minuteStep); var secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions, secondStep); return /*#__PURE__*/React.createElement("div", { className: classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-inner"), true), _defineProperty(_classNames, className, !!className), _classNames)) }, /*#__PURE__*/React.createElement(Header, { clearText: clearText, prefixCls: prefixCls, defaultOpenValue: defaultOpenValue, value: value, currentSelectPanel: currentSelectPanel, onEsc: onEsc, format: format, placeholder: placeholder, hourOptions: hourOptions, minuteOptions: minuteOptions, secondOptions: secondOptions, disabledHours: this.disabledHours, disabledMinutes: disabledMinutes, disabledSeconds: disabledSeconds, onChange: this.onChange, onClear: onClear, allowEmpty: allowEmpty, focusOnOpen: focusOnOpen, onKeyDown: onKeyDown, inputReadOnly: inputReadOnly, clearIcon: clearIcon }), /*#__PURE__*/React.createElement(Combobox, { prefixCls: prefixCls, value: value, defaultOpenValue: defaultOpenValue, format: format, onChange: this.onChange, showHour: showHour, showMinute: showMinute, showSecond: showSecond, hourOptions: hourOptions, minuteOptions: minuteOptions, secondOptions: secondOptions, disabledHours: this.disabledHours, disabledMinutes: disabledMinutes, disabledSeconds: disabledSeconds, onCurrentSelectPanelChange: this.onCurrentSelectPanelChange, use12Hours: use12Hours, isAM: this.isAM() }), addon(this)); } }]); return Panel; }(Component); _defineProperty(Panel, "defaultProps", { prefixCls: 'rc-time-picker-panel', onChange: noop, onClear: noop, disabledHours: noop, disabledMinutes: noop, disabledSeconds: noop, defaultOpenValue: moment(), use12Hours: false, addon: noop, onKeyDown: noop, inputReadOnly: false }); export default Panel; //# sourceMappingURL=Panel.js.map