Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 3 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  2. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. 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); } }
  5. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  6. function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9. 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); }
  10. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11. 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; }
  12. import React, { Component } from 'react';
  13. import PropTypes from 'prop-types';
  14. import moment from 'moment';
  15. import classNames from 'classnames';
  16. import { polyfill } from 'react-lifecycles-compat';
  17. import Header from './Header';
  18. import Combobox from './Combobox';
  19. function noop() {}
  20. function generateOptions(length, disabledOptions, hideDisabledOptions) {
  21. var step = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
  22. var arr = [];
  23. for (var value = 0; value < length; value += step) {
  24. if (!disabledOptions || disabledOptions.indexOf(value) < 0 || !hideDisabledOptions) {
  25. arr.push(value);
  26. }
  27. }
  28. return arr;
  29. }
  30. function toNearestValidTime(time, hourOptions, minuteOptions, secondOptions) {
  31. var hour = hourOptions.slice().sort(function (a, b) {
  32. return Math.abs(time.hour() - a) - Math.abs(time.hour() - b);
  33. })[0];
  34. var minute = minuteOptions.slice().sort(function (a, b) {
  35. return Math.abs(time.minute() - a) - Math.abs(time.minute() - b);
  36. })[0];
  37. var second = secondOptions.slice().sort(function (a, b) {
  38. return Math.abs(time.second() - a) - Math.abs(time.second() - b);
  39. })[0];
  40. return moment("".concat(hour, ":").concat(minute, ":").concat(second), 'HH:mm:ss');
  41. }
  42. var Panel =
  43. /*#__PURE__*/
  44. function (_Component) {
  45. _inherits(Panel, _Component);
  46. function Panel() {
  47. var _getPrototypeOf2;
  48. var _this;
  49. _classCallCheck(this, Panel);
  50. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  51. args[_key] = arguments[_key];
  52. }
  53. _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Panel)).call.apply(_getPrototypeOf2, [this].concat(args)));
  54. _defineProperty(_assertThisInitialized(_this), "state", {});
  55. _defineProperty(_assertThisInitialized(_this), "onChange", function (newValue) {
  56. var onChange = _this.props.onChange;
  57. _this.setState({
  58. value: newValue
  59. });
  60. onChange(newValue);
  61. });
  62. _defineProperty(_assertThisInitialized(_this), "onAmPmChange", function (ampm) {
  63. var onAmPmChange = _this.props.onAmPmChange;
  64. onAmPmChange(ampm);
  65. });
  66. _defineProperty(_assertThisInitialized(_this), "onCurrentSelectPanelChange", function (currentSelectPanel) {
  67. _this.setState({
  68. currentSelectPanel: currentSelectPanel
  69. });
  70. });
  71. _defineProperty(_assertThisInitialized(_this), "disabledHours", function () {
  72. var _this$props = _this.props,
  73. use12Hours = _this$props.use12Hours,
  74. disabledHours = _this$props.disabledHours;
  75. var disabledOptions = disabledHours();
  76. if (use12Hours && Array.isArray(disabledOptions)) {
  77. if (_this.isAM()) {
  78. disabledOptions = disabledOptions.filter(function (h) {
  79. return h < 12;
  80. }).map(function (h) {
  81. return h === 0 ? 12 : h;
  82. });
  83. } else {
  84. disabledOptions = disabledOptions.map(function (h) {
  85. return h === 12 ? 12 : h - 12;
  86. });
  87. }
  88. }
  89. return disabledOptions;
  90. });
  91. return _this;
  92. }
  93. _createClass(Panel, [{
  94. key: "close",
  95. // https://github.com/ant-design/ant-design/issues/5829
  96. value: function close() {
  97. var onEsc = this.props.onEsc;
  98. onEsc();
  99. }
  100. }, {
  101. key: "isAM",
  102. value: function isAM() {
  103. var defaultOpenValue = this.props.defaultOpenValue;
  104. var value = this.state.value;
  105. var realValue = value || defaultOpenValue;
  106. return realValue.hour() >= 0 && realValue.hour() < 12;
  107. }
  108. }, {
  109. key: "render",
  110. value: function render() {
  111. var _this$props2 = this.props,
  112. prefixCls = _this$props2.prefixCls,
  113. className = _this$props2.className,
  114. placeholder = _this$props2.placeholder,
  115. disabledMinutes = _this$props2.disabledMinutes,
  116. disabledSeconds = _this$props2.disabledSeconds,
  117. hideDisabledOptions = _this$props2.hideDisabledOptions,
  118. showHour = _this$props2.showHour,
  119. showMinute = _this$props2.showMinute,
  120. showSecond = _this$props2.showSecond,
  121. format = _this$props2.format,
  122. defaultOpenValue = _this$props2.defaultOpenValue,
  123. clearText = _this$props2.clearText,
  124. onEsc = _this$props2.onEsc,
  125. addon = _this$props2.addon,
  126. use12Hours = _this$props2.use12Hours,
  127. focusOnOpen = _this$props2.focusOnOpen,
  128. onKeyDown = _this$props2.onKeyDown,
  129. hourStep = _this$props2.hourStep,
  130. minuteStep = _this$props2.minuteStep,
  131. secondStep = _this$props2.secondStep,
  132. inputReadOnly = _this$props2.inputReadOnly,
  133. clearIcon = _this$props2.clearIcon;
  134. var _this$state = this.state,
  135. value = _this$state.value,
  136. currentSelectPanel = _this$state.currentSelectPanel;
  137. var disabledHourOptions = this.disabledHours();
  138. var disabledMinuteOptions = disabledMinutes(value ? value.hour() : null);
  139. var disabledSecondOptions = disabledSeconds(value ? value.hour() : null, value ? value.minute() : null);
  140. var hourOptions = generateOptions(24, disabledHourOptions, hideDisabledOptions, hourStep);
  141. var minuteOptions = generateOptions(60, disabledMinuteOptions, hideDisabledOptions, minuteStep);
  142. var secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions, secondStep);
  143. var validDefaultOpenValue = toNearestValidTime(defaultOpenValue, hourOptions, minuteOptions, secondOptions);
  144. return React.createElement("div", {
  145. className: classNames(className, "".concat(prefixCls, "-inner"))
  146. }, React.createElement(Header, {
  147. clearText: clearText,
  148. prefixCls: prefixCls,
  149. defaultOpenValue: validDefaultOpenValue,
  150. value: value,
  151. currentSelectPanel: currentSelectPanel,
  152. onEsc: onEsc,
  153. format: format,
  154. placeholder: placeholder,
  155. hourOptions: hourOptions,
  156. minuteOptions: minuteOptions,
  157. secondOptions: secondOptions,
  158. disabledHours: this.disabledHours,
  159. disabledMinutes: disabledMinutes,
  160. disabledSeconds: disabledSeconds,
  161. onChange: this.onChange,
  162. focusOnOpen: focusOnOpen,
  163. onKeyDown: onKeyDown,
  164. inputReadOnly: inputReadOnly,
  165. clearIcon: clearIcon
  166. }), React.createElement(Combobox, {
  167. prefixCls: prefixCls,
  168. value: value,
  169. defaultOpenValue: validDefaultOpenValue,
  170. format: format,
  171. onChange: this.onChange,
  172. onAmPmChange: this.onAmPmChange,
  173. showHour: showHour,
  174. showMinute: showMinute,
  175. showSecond: showSecond,
  176. hourOptions: hourOptions,
  177. minuteOptions: minuteOptions,
  178. secondOptions: secondOptions,
  179. disabledHours: this.disabledHours,
  180. disabledMinutes: disabledMinutes,
  181. disabledSeconds: disabledSeconds,
  182. onCurrentSelectPanelChange: this.onCurrentSelectPanelChange,
  183. use12Hours: use12Hours,
  184. onEsc: onEsc,
  185. isAM: this.isAM()
  186. }), addon(this));
  187. }
  188. }], [{
  189. key: "getDerivedStateFromProps",
  190. value: function getDerivedStateFromProps(props, state) {
  191. if ('value' in props) {
  192. return _objectSpread({}, state, {
  193. value: props.value
  194. });
  195. }
  196. return null;
  197. }
  198. }]);
  199. return Panel;
  200. }(Component);
  201. _defineProperty(Panel, "propTypes", {
  202. clearText: PropTypes.string,
  203. prefixCls: PropTypes.string,
  204. className: PropTypes.string,
  205. defaultOpenValue: PropTypes.object,
  206. value: PropTypes.object,
  207. placeholder: PropTypes.string,
  208. format: PropTypes.string,
  209. inputReadOnly: PropTypes.bool,
  210. disabledHours: PropTypes.func,
  211. disabledMinutes: PropTypes.func,
  212. disabledSeconds: PropTypes.func,
  213. hideDisabledOptions: PropTypes.bool,
  214. onChange: PropTypes.func,
  215. onAmPmChange: PropTypes.func,
  216. onEsc: PropTypes.func,
  217. showHour: PropTypes.bool,
  218. showMinute: PropTypes.bool,
  219. showSecond: PropTypes.bool,
  220. use12Hours: PropTypes.bool,
  221. hourStep: PropTypes.number,
  222. minuteStep: PropTypes.number,
  223. secondStep: PropTypes.number,
  224. addon: PropTypes.func,
  225. focusOnOpen: PropTypes.bool,
  226. onKeyDown: PropTypes.func,
  227. clearIcon: PropTypes.node
  228. });
  229. _defineProperty(Panel, "defaultProps", {
  230. prefixCls: 'rc-time-picker-panel',
  231. onChange: noop,
  232. disabledHours: noop,
  233. disabledMinutes: noop,
  234. disabledSeconds: noop,
  235. defaultOpenValue: moment(),
  236. use12Hours: false,
  237. addon: noop,
  238. onKeyDown: noop,
  239. onAmPmChange: noop,
  240. inputReadOnly: false
  241. });
  242. polyfill(Panel);
  243. export default Panel;