No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

hace 3 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2. 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); } }
  3. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  4. function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  5. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  6. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7. 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); }
  8. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9. 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; }
  10. import React, { Component } from 'react';
  11. import PropTypes from 'prop-types';
  12. import Select from './Select';
  13. var formatOption = function formatOption(option, disabledOptions) {
  14. var value = "".concat(option);
  15. if (option < 10) {
  16. value = "0".concat(option);
  17. }
  18. var disabled = false;
  19. if (disabledOptions && disabledOptions.indexOf(option) >= 0) {
  20. disabled = true;
  21. }
  22. return {
  23. value: value,
  24. disabled: disabled
  25. };
  26. };
  27. var Combobox =
  28. /*#__PURE__*/
  29. function (_Component) {
  30. _inherits(Combobox, _Component);
  31. function Combobox() {
  32. var _getPrototypeOf2;
  33. var _this;
  34. _classCallCheck(this, Combobox);
  35. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  36. args[_key] = arguments[_key];
  37. }
  38. _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Combobox)).call.apply(_getPrototypeOf2, [this].concat(args)));
  39. _defineProperty(_assertThisInitialized(_this), "onItemChange", function (type, itemValue) {
  40. var _this$props = _this.props,
  41. onChange = _this$props.onChange,
  42. defaultOpenValue = _this$props.defaultOpenValue,
  43. use12Hours = _this$props.use12Hours,
  44. propValue = _this$props.value,
  45. isAM = _this$props.isAM,
  46. onAmPmChange = _this$props.onAmPmChange;
  47. var value = (propValue || defaultOpenValue).clone();
  48. if (type === 'hour') {
  49. if (use12Hours) {
  50. if (isAM) {
  51. value.hour(+itemValue % 12);
  52. } else {
  53. value.hour(+itemValue % 12 + 12);
  54. }
  55. } else {
  56. value.hour(+itemValue);
  57. }
  58. } else if (type === 'minute') {
  59. value.minute(+itemValue);
  60. } else if (type === 'ampm') {
  61. var ampm = itemValue.toUpperCase();
  62. if (use12Hours) {
  63. if (ampm === 'PM' && value.hour() < 12) {
  64. value.hour(value.hour() % 12 + 12);
  65. }
  66. if (ampm === 'AM') {
  67. if (value.hour() >= 12) {
  68. value.hour(value.hour() - 12);
  69. }
  70. }
  71. }
  72. onAmPmChange(ampm);
  73. } else {
  74. value.second(+itemValue);
  75. }
  76. onChange(value);
  77. });
  78. _defineProperty(_assertThisInitialized(_this), "onEnterSelectPanel", function (range) {
  79. var onCurrentSelectPanelChange = _this.props.onCurrentSelectPanelChange;
  80. onCurrentSelectPanelChange(range);
  81. });
  82. return _this;
  83. }
  84. _createClass(Combobox, [{
  85. key: "getHourSelect",
  86. value: function getHourSelect(hour) {
  87. var _this2 = this;
  88. var _this$props2 = this.props,
  89. prefixCls = _this$props2.prefixCls,
  90. hourOptions = _this$props2.hourOptions,
  91. disabledHours = _this$props2.disabledHours,
  92. showHour = _this$props2.showHour,
  93. use12Hours = _this$props2.use12Hours,
  94. onEsc = _this$props2.onEsc;
  95. if (!showHour) {
  96. return null;
  97. }
  98. var disabledOptions = disabledHours();
  99. var hourOptionsAdj;
  100. var hourAdj;
  101. if (use12Hours) {
  102. hourOptionsAdj = [12].concat(hourOptions.filter(function (h) {
  103. return h < 12 && h > 0;
  104. }));
  105. hourAdj = hour % 12 || 12;
  106. } else {
  107. hourOptionsAdj = hourOptions;
  108. hourAdj = hour;
  109. }
  110. return React.createElement(Select, {
  111. prefixCls: prefixCls,
  112. options: hourOptionsAdj.map(function (option) {
  113. return formatOption(option, disabledOptions);
  114. }),
  115. selectedIndex: hourOptionsAdj.indexOf(hourAdj),
  116. type: "hour",
  117. onSelect: this.onItemChange,
  118. onMouseEnter: function onMouseEnter() {
  119. return _this2.onEnterSelectPanel('hour');
  120. },
  121. onEsc: onEsc
  122. });
  123. }
  124. }, {
  125. key: "getMinuteSelect",
  126. value: function getMinuteSelect(minute) {
  127. var _this3 = this;
  128. var _this$props3 = this.props,
  129. prefixCls = _this$props3.prefixCls,
  130. minuteOptions = _this$props3.minuteOptions,
  131. disabledMinutes = _this$props3.disabledMinutes,
  132. defaultOpenValue = _this$props3.defaultOpenValue,
  133. showMinute = _this$props3.showMinute,
  134. propValue = _this$props3.value,
  135. onEsc = _this$props3.onEsc;
  136. if (!showMinute) {
  137. return null;
  138. }
  139. var value = propValue || defaultOpenValue;
  140. var disabledOptions = disabledMinutes(value.hour());
  141. return React.createElement(Select, {
  142. prefixCls: prefixCls,
  143. options: minuteOptions.map(function (option) {
  144. return formatOption(option, disabledOptions);
  145. }),
  146. selectedIndex: minuteOptions.indexOf(minute),
  147. type: "minute",
  148. onSelect: this.onItemChange,
  149. onMouseEnter: function onMouseEnter() {
  150. return _this3.onEnterSelectPanel('minute');
  151. },
  152. onEsc: onEsc
  153. });
  154. }
  155. }, {
  156. key: "getSecondSelect",
  157. value: function getSecondSelect(second) {
  158. var _this4 = this;
  159. var _this$props4 = this.props,
  160. prefixCls = _this$props4.prefixCls,
  161. secondOptions = _this$props4.secondOptions,
  162. disabledSeconds = _this$props4.disabledSeconds,
  163. showSecond = _this$props4.showSecond,
  164. defaultOpenValue = _this$props4.defaultOpenValue,
  165. propValue = _this$props4.value,
  166. onEsc = _this$props4.onEsc;
  167. if (!showSecond) {
  168. return null;
  169. }
  170. var value = propValue || defaultOpenValue;
  171. var disabledOptions = disabledSeconds(value.hour(), value.minute());
  172. return React.createElement(Select, {
  173. prefixCls: prefixCls,
  174. options: secondOptions.map(function (option) {
  175. return formatOption(option, disabledOptions);
  176. }),
  177. selectedIndex: secondOptions.indexOf(second),
  178. type: "second",
  179. onSelect: this.onItemChange,
  180. onMouseEnter: function onMouseEnter() {
  181. return _this4.onEnterSelectPanel('second');
  182. },
  183. onEsc: onEsc
  184. });
  185. }
  186. }, {
  187. key: "getAMPMSelect",
  188. value: function getAMPMSelect() {
  189. var _this5 = this;
  190. var _this$props5 = this.props,
  191. prefixCls = _this$props5.prefixCls,
  192. use12Hours = _this$props5.use12Hours,
  193. format = _this$props5.format,
  194. isAM = _this$props5.isAM,
  195. onEsc = _this$props5.onEsc;
  196. if (!use12Hours) {
  197. return null;
  198. }
  199. var AMPMOptions = ['am', 'pm'] // If format has A char, then we should uppercase AM/PM
  200. .map(function (c) {
  201. return format.match(/\sA/) ? c.toUpperCase() : c;
  202. }).map(function (c) {
  203. return {
  204. value: c
  205. };
  206. });
  207. var selected = isAM ? 0 : 1;
  208. return React.createElement(Select, {
  209. prefixCls: prefixCls,
  210. options: AMPMOptions,
  211. selectedIndex: selected,
  212. type: "ampm",
  213. onSelect: this.onItemChange,
  214. onMouseEnter: function onMouseEnter() {
  215. return _this5.onEnterSelectPanel('ampm');
  216. },
  217. onEsc: onEsc
  218. });
  219. }
  220. }, {
  221. key: "render",
  222. value: function render() {
  223. var _this$props6 = this.props,
  224. prefixCls = _this$props6.prefixCls,
  225. defaultOpenValue = _this$props6.defaultOpenValue,
  226. propValue = _this$props6.value;
  227. var value = propValue || defaultOpenValue;
  228. return React.createElement("div", {
  229. className: "".concat(prefixCls, "-combobox")
  230. }, this.getHourSelect(value.hour()), this.getMinuteSelect(value.minute()), this.getSecondSelect(value.second()), this.getAMPMSelect(value.hour()));
  231. }
  232. }]);
  233. return Combobox;
  234. }(Component);
  235. _defineProperty(Combobox, "propTypes", {
  236. format: PropTypes.string,
  237. defaultOpenValue: PropTypes.object,
  238. prefixCls: PropTypes.string,
  239. value: PropTypes.object,
  240. onChange: PropTypes.func,
  241. onAmPmChange: PropTypes.func,
  242. showHour: PropTypes.bool,
  243. showMinute: PropTypes.bool,
  244. showSecond: PropTypes.bool,
  245. hourOptions: PropTypes.array,
  246. minuteOptions: PropTypes.array,
  247. secondOptions: PropTypes.array,
  248. disabledHours: PropTypes.func,
  249. disabledMinutes: PropTypes.func,
  250. disabledSeconds: PropTypes.func,
  251. onCurrentSelectPanelChange: PropTypes.func,
  252. use12Hours: PropTypes.bool,
  253. onEsc: PropTypes.func,
  254. isAM: PropTypes.bool
  255. });
  256. export default Combobox;