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.
 
 
 
 

318 líneas
12 KiB

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