index.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
  3. import { createVNode as _createVNode } from "vue";
  4. import TimeHeader from './TimeHeader';
  5. import TimeBody from './TimeBody';
  6. import { createKeydownHandler } from '../../utils/uiUtil';
  7. import classNames from '../../../_util/classNames';
  8. import { ref } from 'vue';
  9. import useMergeProps from '../../hooks/useMergeProps';
  10. var countBoolean = function countBoolean(boolList) {
  11. return boolList.filter(function (bool) {
  12. return bool !== false;
  13. }).length;
  14. };
  15. function TimePanel(_props) {
  16. var props = useMergeProps(_props);
  17. var generateConfig = props.generateConfig,
  18. _props$format = props.format,
  19. format = _props$format === void 0 ? 'HH:mm:ss' : _props$format,
  20. prefixCls = props.prefixCls,
  21. active = props.active,
  22. operationRef = props.operationRef,
  23. showHour = props.showHour,
  24. showMinute = props.showMinute,
  25. showSecond = props.showSecond,
  26. _props$use12Hours = props.use12Hours,
  27. use12Hours = _props$use12Hours === void 0 ? false : _props$use12Hours,
  28. onSelect = props.onSelect,
  29. value = props.value;
  30. var panelPrefixCls = "".concat(prefixCls, "-time-panel");
  31. var bodyOperationRef = ref();
  32. // ======================= Keyboard =======================
  33. var activeColumnIndex = ref(-1);
  34. var columnsCount = countBoolean([showHour, showMinute, showSecond, use12Hours]);
  35. operationRef.value = {
  36. onKeydown: function onKeydown(event) {
  37. return createKeydownHandler(event, {
  38. onLeftRight: function onLeftRight(diff) {
  39. activeColumnIndex.value = (activeColumnIndex.value + diff + columnsCount) % columnsCount;
  40. },
  41. onUpDown: function onUpDown(diff) {
  42. if (activeColumnIndex.value === -1) {
  43. activeColumnIndex.value = 0;
  44. } else if (bodyOperationRef.value) {
  45. bodyOperationRef.value.onUpDown(diff);
  46. }
  47. },
  48. onEnter: function onEnter() {
  49. onSelect(value || generateConfig.getNow(), 'key');
  50. activeColumnIndex.value = -1;
  51. }
  52. });
  53. },
  54. onBlur: function onBlur() {
  55. activeColumnIndex.value = -1;
  56. }
  57. };
  58. return _createVNode("div", {
  59. "class": classNames(panelPrefixCls, _defineProperty({}, "".concat(panelPrefixCls, "-active"), active))
  60. }, [_createVNode(TimeHeader, _objectSpread(_objectSpread({}, props), {}, {
  61. "format": format,
  62. "prefixCls": prefixCls
  63. }), null), _createVNode(TimeBody, _objectSpread(_objectSpread({}, props), {}, {
  64. "prefixCls": prefixCls,
  65. "activeColumnIndex": activeColumnIndex.value,
  66. "operationRef": bodyOperationRef
  67. }), null)]);
  68. }
  69. TimePanel.displayName = 'TimePanel';
  70. TimePanel.inheritAttrs = false;
  71. export default TimePanel;