|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
-
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
-
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
-
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
-
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
-
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
-
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
-
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
-
- import React, { Component } from 'react';
- import PropTypes from 'prop-types';
- import Select from './Select';
-
- var formatOption = function formatOption(option, disabledOptions) {
- var value = "".concat(option);
-
- if (option < 10) {
- value = "0".concat(option);
- }
-
- var disabled = false;
-
- if (disabledOptions && disabledOptions.indexOf(option) >= 0) {
- disabled = true;
- }
-
- return {
- value: value,
- disabled: disabled
- };
- };
-
- var Combobox =
- /*#__PURE__*/
- function (_Component) {
- _inherits(Combobox, _Component);
-
- function Combobox() {
- var _getPrototypeOf2;
-
- var _this;
-
- _classCallCheck(this, Combobox);
-
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
-
- _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Combobox)).call.apply(_getPrototypeOf2, [this].concat(args)));
-
- _defineProperty(_assertThisInitialized(_this), "onItemChange", function (type, itemValue) {
- var _this$props = _this.props,
- onChange = _this$props.onChange,
- defaultOpenValue = _this$props.defaultOpenValue,
- use12Hours = _this$props.use12Hours,
- propValue = _this$props.value,
- isAM = _this$props.isAM,
- onAmPmChange = _this$props.onAmPmChange;
- var value = (propValue || defaultOpenValue).clone();
-
- if (type === 'hour') {
- if (use12Hours) {
- if (isAM) {
- value.hour(+itemValue % 12);
- } else {
- value.hour(+itemValue % 12 + 12);
- }
- } else {
- value.hour(+itemValue);
- }
- } else if (type === 'minute') {
- value.minute(+itemValue);
- } else if (type === 'ampm') {
- var ampm = itemValue.toUpperCase();
-
- if (use12Hours) {
- if (ampm === 'PM' && value.hour() < 12) {
- value.hour(value.hour() % 12 + 12);
- }
-
- if (ampm === 'AM') {
- if (value.hour() >= 12) {
- value.hour(value.hour() - 12);
- }
- }
- }
-
- onAmPmChange(ampm);
- } else {
- value.second(+itemValue);
- }
-
- onChange(value);
- });
-
- _defineProperty(_assertThisInitialized(_this), "onEnterSelectPanel", function (range) {
- var onCurrentSelectPanelChange = _this.props.onCurrentSelectPanelChange;
- onCurrentSelectPanelChange(range);
- });
-
- return _this;
- }
-
- _createClass(Combobox, [{
- key: "getHourSelect",
- value: function getHourSelect(hour) {
- var _this2 = this;
-
- var _this$props2 = this.props,
- prefixCls = _this$props2.prefixCls,
- hourOptions = _this$props2.hourOptions,
- disabledHours = _this$props2.disabledHours,
- showHour = _this$props2.showHour,
- use12Hours = _this$props2.use12Hours,
- onEsc = _this$props2.onEsc;
-
- if (!showHour) {
- return null;
- }
-
- var disabledOptions = disabledHours();
- var hourOptionsAdj;
- var hourAdj;
-
- if (use12Hours) {
- hourOptionsAdj = [12].concat(hourOptions.filter(function (h) {
- return h < 12 && h > 0;
- }));
- hourAdj = hour % 12 || 12;
- } else {
- hourOptionsAdj = hourOptions;
- hourAdj = hour;
- }
-
- return React.createElement(Select, {
- prefixCls: prefixCls,
- options: hourOptionsAdj.map(function (option) {
- return formatOption(option, disabledOptions);
- }),
- selectedIndex: hourOptionsAdj.indexOf(hourAdj),
- type: "hour",
- onSelect: this.onItemChange,
- onMouseEnter: function onMouseEnter() {
- return _this2.onEnterSelectPanel('hour');
- },
- onEsc: onEsc
- });
- }
- }, {
- key: "getMinuteSelect",
- value: function getMinuteSelect(minute) {
- var _this3 = this;
-
- var _this$props3 = this.props,
- prefixCls = _this$props3.prefixCls,
- minuteOptions = _this$props3.minuteOptions,
- disabledMinutes = _this$props3.disabledMinutes,
- defaultOpenValue = _this$props3.defaultOpenValue,
- showMinute = _this$props3.showMinute,
- propValue = _this$props3.value,
- onEsc = _this$props3.onEsc;
-
- if (!showMinute) {
- return null;
- }
-
- var value = propValue || defaultOpenValue;
- var disabledOptions = disabledMinutes(value.hour());
- return React.createElement(Select, {
- prefixCls: prefixCls,
- options: minuteOptions.map(function (option) {
- return formatOption(option, disabledOptions);
- }),
- selectedIndex: minuteOptions.indexOf(minute),
- type: "minute",
- onSelect: this.onItemChange,
- onMouseEnter: function onMouseEnter() {
- return _this3.onEnterSelectPanel('minute');
- },
- onEsc: onEsc
- });
- }
- }, {
- key: "getSecondSelect",
- value: function getSecondSelect(second) {
- var _this4 = this;
-
- var _this$props4 = this.props,
- prefixCls = _this$props4.prefixCls,
- secondOptions = _this$props4.secondOptions,
- disabledSeconds = _this$props4.disabledSeconds,
- showSecond = _this$props4.showSecond,
- defaultOpenValue = _this$props4.defaultOpenValue,
- propValue = _this$props4.value,
- onEsc = _this$props4.onEsc;
-
- if (!showSecond) {
- return null;
- }
-
- var value = propValue || defaultOpenValue;
- var disabledOptions = disabledSeconds(value.hour(), value.minute());
- return React.createElement(Select, {
- prefixCls: prefixCls,
- options: secondOptions.map(function (option) {
- return formatOption(option, disabledOptions);
- }),
- selectedIndex: secondOptions.indexOf(second),
- type: "second",
- onSelect: this.onItemChange,
- onMouseEnter: function onMouseEnter() {
- return _this4.onEnterSelectPanel('second');
- },
- onEsc: onEsc
- });
- }
- }, {
- key: "getAMPMSelect",
- value: function getAMPMSelect() {
- var _this5 = this;
-
- var _this$props5 = this.props,
- prefixCls = _this$props5.prefixCls,
- use12Hours = _this$props5.use12Hours,
- format = _this$props5.format,
- isAM = _this$props5.isAM,
- onEsc = _this$props5.onEsc;
-
- if (!use12Hours) {
- return null;
- }
-
- var AMPMOptions = ['am', 'pm'] // If format has A char, then we should uppercase AM/PM
- .map(function (c) {
- return format.match(/\sA/) ? c.toUpperCase() : c;
- }).map(function (c) {
- return {
- value: c
- };
- });
- var selected = isAM ? 0 : 1;
- return React.createElement(Select, {
- prefixCls: prefixCls,
- options: AMPMOptions,
- selectedIndex: selected,
- type: "ampm",
- onSelect: this.onItemChange,
- onMouseEnter: function onMouseEnter() {
- return _this5.onEnterSelectPanel('ampm');
- },
- onEsc: onEsc
- });
- }
- }, {
- key: "render",
- value: function render() {
- var _this$props6 = this.props,
- prefixCls = _this$props6.prefixCls,
- defaultOpenValue = _this$props6.defaultOpenValue,
- propValue = _this$props6.value;
- var value = propValue || defaultOpenValue;
- return React.createElement("div", {
- className: "".concat(prefixCls, "-combobox")
- }, this.getHourSelect(value.hour()), this.getMinuteSelect(value.minute()), this.getSecondSelect(value.second()), this.getAMPMSelect(value.hour()));
- }
- }]);
-
- return Combobox;
- }(Component);
-
- _defineProperty(Combobox, "propTypes", {
- format: PropTypes.string,
- defaultOpenValue: PropTypes.object,
- prefixCls: PropTypes.string,
- value: PropTypes.object,
- onChange: PropTypes.func,
- onAmPmChange: PropTypes.func,
- showHour: PropTypes.bool,
- showMinute: PropTypes.bool,
- showSecond: PropTypes.bool,
- hourOptions: PropTypes.array,
- minuteOptions: PropTypes.array,
- secondOptions: PropTypes.array,
- disabledHours: PropTypes.func,
- disabledMinutes: PropTypes.func,
- disabledSeconds: PropTypes.func,
- onCurrentSelectPanelChange: PropTypes.func,
- use12Hours: PropTypes.bool,
- onEsc: PropTypes.func,
- isAM: PropTypes.bool
- });
-
- export default Combobox;
|