index.js
2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import * as React from 'react';
import classNames from 'classnames';
import TimeHeader from './TimeHeader';
import TimeBody from './TimeBody';
import { createKeyDownHandler } from '../../utils/uiUtil';
var countBoolean = function countBoolean(boolList) {
return boolList.filter(function (bool) {
return bool !== false;
}).length;
};
function TimePanel(props) {
var generateConfig = props.generateConfig,
_props$format = props.format,
format = _props$format === void 0 ? 'HH:mm:ss' : _props$format,
prefixCls = props.prefixCls,
active = props.active,
operationRef = props.operationRef,
showHour = props.showHour,
showMinute = props.showMinute,
showSecond = props.showSecond,
_props$use12Hours = props.use12Hours,
use12Hours = _props$use12Hours === void 0 ? false : _props$use12Hours,
onSelect = props.onSelect,
value = props.value;
var panelPrefixCls = "".concat(prefixCls, "-time-panel");
var bodyOperationRef = React.useRef(); // ======================= Keyboard =======================
var _React$useState = React.useState(-1),
_React$useState2 = _slicedToArray(_React$useState, 2),
activeColumnIndex = _React$useState2[0],
setActiveColumnIndex = _React$useState2[1];
var columnsCount = countBoolean([showHour, showMinute, showSecond, use12Hours]);
operationRef.current = {
onKeyDown: function onKeyDown(event) {
return createKeyDownHandler(event, {
onLeftRight: function onLeftRight(diff) {
setActiveColumnIndex((activeColumnIndex + diff + columnsCount) % columnsCount);
},
onUpDown: function onUpDown(diff) {
if (activeColumnIndex === -1) {
setActiveColumnIndex(0);
} else if (bodyOperationRef.current) {
bodyOperationRef.current.onUpDown(diff);
}
},
onEnter: function onEnter() {
onSelect(value || generateConfig.getNow(), 'key');
setActiveColumnIndex(-1);
}
});
},
onBlur: function onBlur() {
setActiveColumnIndex(-1);
}
};
return /*#__PURE__*/React.createElement("div", {
className: classNames(panelPrefixCls, _defineProperty({}, "".concat(panelPrefixCls, "-active"), active))
}, /*#__PURE__*/React.createElement(TimeHeader, Object.assign({}, props, {
format: format,
prefixCls: prefixCls
})), /*#__PURE__*/React.createElement(TimeBody, Object.assign({}, props, {
prefixCls: prefixCls,
activeColumnIndex: activeColumnIndex,
operationRef: bodyOperationRef
})));
}
export default TimePanel;