@hi-ui/time-picker 4.0.10 → 4.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/lib/cjs/@types/index.js +0 -1
- package/lib/cjs/Input.js +30 -50
- package/lib/cjs/Panel.js +18 -32
- package/lib/cjs/PopContent.js +45 -66
- package/lib/cjs/Selector.js +18 -30
- package/lib/cjs/TimePicker.js +77 -118
- package/lib/cjs/hooks/useFilter.js +0 -5
- package/lib/cjs/index.js +0 -5
- package/lib/cjs/styles/index.scss.js +1 -4
- package/lib/cjs/utils/analysisFormat.js +1 -5
- package/lib/cjs/utils/disposeInputValue.js +12 -16
- package/lib/cjs/utils/generateSelectorData.js +5 -13
- package/lib/cjs/utils/getFormatDefault.js +0 -2
- package/lib/cjs/utils/getNowString.js +0 -5
- package/lib/cjs/utils/getRange.js +0 -6
- package/lib/cjs/utils/valueChecker.js +8 -20
- package/lib/esm/@types/index.js +0 -2
- package/lib/esm/Input.js +28 -39
- package/lib/esm/Panel.js +16 -22
- package/lib/esm/PopContent.js +43 -53
- package/lib/esm/Selector.js +16 -22
- package/lib/esm/TimePicker.js +74 -96
- package/lib/esm/hooks/useFilter.js +0 -4
- package/lib/esm/styles/index.scss.js +1 -3
- package/lib/esm/utils/analysisFormat.js +1 -4
- package/lib/esm/utils/disposeInputValue.js +12 -15
- package/lib/esm/utils/generateSelectorData.js +5 -12
- package/lib/esm/utils/getFormatDefault.js +0 -1
- package/lib/esm/utils/getNowString.js +0 -3
- package/lib/esm/utils/getRange.js +0 -5
- package/lib/esm/utils/valueChecker.js +8 -18
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,34 @@
|
|
1
1
|
# @hi-ui/time-picker
|
2
2
|
|
3
|
+
## 4.0.12
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- fix: 修复 rollup3 打包 cjs 模块问题
|
8
|
+
- Updated dependencies
|
9
|
+
- @hi-ui/env@4.0.3
|
10
|
+
- @hi-ui/core@4.0.7
|
11
|
+
- @hi-ui/use-uncontrolled-state@4.0.3
|
12
|
+
- @hi-ui/icons@4.0.17
|
13
|
+
- @hi-ui/button@4.0.8
|
14
|
+
- @hi-ui/popper@4.1.2
|
15
|
+
- @hi-ui/classname@4.0.3
|
16
|
+
|
17
|
+
## 4.0.11
|
18
|
+
|
19
|
+
### Patch Changes
|
20
|
+
|
21
|
+
- [#2672](https://github.com/XiaoMi/hiui/pull/2672) [`1ebe27830`](https://github.com/XiaoMi/hiui/commit/1ebe2783098b3a8cd980bd10076d67635463800e) Thanks [@zyprepare](https://github.com/zyprepare)! - build: 升级到 rollup3,重新构建发布组件
|
22
|
+
|
23
|
+
- Updated dependencies [[`1ebe27830`](https://github.com/XiaoMi/hiui/commit/1ebe2783098b3a8cd980bd10076d67635463800e)]:
|
24
|
+
- @hi-ui/core@4.0.6
|
25
|
+
- @hi-ui/use-uncontrolled-state@4.0.2
|
26
|
+
- @hi-ui/icons@4.0.16
|
27
|
+
- @hi-ui/button@4.0.7
|
28
|
+
- @hi-ui/popper@4.1.1
|
29
|
+
- @hi-ui/classname@4.0.2
|
30
|
+
- @hi-ui/env@4.0.2
|
31
|
+
|
3
32
|
## 4.0.10
|
4
33
|
|
5
34
|
### Patch Changes
|
package/lib/cjs/@types/index.js
CHANGED
@@ -13,7 +13,6 @@ Object.defineProperty(exports, '__esModule', {
|
|
13
13
|
value: true
|
14
14
|
});
|
15
15
|
exports.TimePickerSelectorType = void 0;
|
16
|
-
|
17
16
|
(function (TimePickerSelectorType) {
|
18
17
|
TimePickerSelectorType[TimePickerSelectorType["hour"] = 1] = "hour";
|
19
18
|
TimePickerSelectorType[TimePickerSelectorType["minute"] = 2] = "minute";
|
package/lib/cjs/Input.js
CHANGED
@@ -10,67 +10,55 @@
|
|
10
10
|
'use strict';
|
11
11
|
|
12
12
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
13
|
-
|
14
13
|
Object.defineProperty(exports, '__esModule', {
|
15
14
|
value: true
|
16
15
|
});
|
17
|
-
|
18
16
|
var React = require('react');
|
19
|
-
|
20
17
|
var classname = require('@hi-ui/classname');
|
21
|
-
|
22
18
|
var valueChecker = require('./utils/valueChecker.js');
|
23
|
-
|
24
19
|
var disposeInputValue = require('./utils/disposeInputValue.js');
|
25
|
-
|
26
20
|
var core = require('@hi-ui/core');
|
27
|
-
|
28
|
-
function _interopDefaultLegacy(e) {
|
21
|
+
function _interopDefaultCompat(e) {
|
29
22
|
return e && _typeof(e) === 'object' && 'default' in e ? e : {
|
30
23
|
'default': e
|
31
24
|
};
|
32
25
|
}
|
33
|
-
|
34
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
35
|
-
|
26
|
+
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
36
27
|
var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
37
28
|
var _cx;
|
38
|
-
|
39
29
|
var prefix = props.prefix,
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
30
|
+
value = props.value,
|
31
|
+
format = props.format,
|
32
|
+
hourStep = props.hourStep,
|
33
|
+
minuteStep = props.minuteStep,
|
34
|
+
secondStep = props.secondStep,
|
35
|
+
disabledHours = props.disabledHours,
|
36
|
+
disabledMinutes = props.disabledMinutes,
|
37
|
+
disabledSeconds = props.disabledSeconds,
|
38
|
+
type = props.type,
|
39
|
+
placeholders = props.placeholders,
|
40
|
+
_onChange = props.onChange,
|
41
|
+
_onFocus = props.onFocus,
|
42
|
+
disabled = props.disabled,
|
43
|
+
onValidChange = props.onValidChange,
|
44
|
+
isFitContent = props.isFitContent,
|
45
|
+
size = props.size;
|
56
46
|
var i18n = core.useLocaleContext();
|
57
47
|
var toText = i18n.get('timePicker.to');
|
58
48
|
var componentClass = React.useMemo(function () {
|
59
49
|
return prefix + "__input";
|
60
50
|
}, [prefix]);
|
61
|
-
|
62
51
|
var _useState = React.useState(value),
|
63
|
-
|
64
|
-
|
65
|
-
|
52
|
+
cacheValue = _useState[0],
|
53
|
+
setCacheValue = _useState[1];
|
66
54
|
var getPanelType = React.useCallback(function (index) {
|
67
55
|
if (type === 'single') {
|
68
56
|
return 'single';
|
69
57
|
} else {
|
70
58
|
return index === 0 ? 'range-start' : 'range-end';
|
71
59
|
}
|
72
|
-
}, [type]);
|
73
|
-
|
60
|
+
}, [type]);
|
61
|
+
// 检查值是否合规
|
74
62
|
var validChecker = React.useCallback(function (checkValue, panelType) {
|
75
63
|
return valueChecker.valueChecker({
|
76
64
|
value: checkValue,
|
@@ -87,16 +75,14 @@ var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
87
75
|
},
|
88
76
|
panelType: panelType
|
89
77
|
});
|
90
|
-
}, [hourStep, minuteStep, secondStep, disabledHours, disabledMinutes, disabledSeconds, format]);
|
91
|
-
|
78
|
+
}, [hourStep, minuteStep, secondStep, disabledHours, disabledMinutes, disabledSeconds, format]);
|
79
|
+
// 缓存同步外部
|
92
80
|
React.useEffect(function () {
|
93
81
|
setCacheValue(function (pre) {
|
94
82
|
var result = value.slice(0, type === 'single' ? 1 : 2);
|
95
|
-
|
96
83
|
if (result.join('') !== pre.join('')) {
|
97
84
|
return result;
|
98
85
|
}
|
99
|
-
|
100
86
|
return pre;
|
101
87
|
});
|
102
88
|
}, [value, type]);
|
@@ -104,7 +90,6 @@ var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
104
90
|
var valueValid = disposeValue.every(function (item, index) {
|
105
91
|
return validChecker(item, getPanelType(index));
|
106
92
|
});
|
107
|
-
|
108
93
|
if (type === 'range' && valueValid) {
|
109
94
|
// 数据格式正确,检查范围数据
|
110
95
|
// 全为空字符串,则认为是合法的(还未选择)
|
@@ -112,9 +97,8 @@ var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
112
97
|
return item === '';
|
113
98
|
})) {
|
114
99
|
return true;
|
115
|
-
}
|
116
|
-
|
117
|
-
|
100
|
+
}
|
101
|
+
// 结束时间要>开始时间
|
118
102
|
return disposeValue[1] > disposeValue[0];
|
119
103
|
} else {
|
120
104
|
return valueValid;
|
@@ -125,26 +109,22 @@ var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
125
109
|
if (needValid === void 0) {
|
126
110
|
needValid = true;
|
127
111
|
}
|
128
|
-
|
129
112
|
var newValue = disposeInputValue.disposeInputValue(format, disposeValue);
|
130
113
|
var result = [].concat(cacheValue);
|
131
114
|
result[index] = newValue;
|
132
|
-
setCacheValue(result);
|
133
|
-
|
115
|
+
setCacheValue(result);
|
116
|
+
// 合法,则通知外部
|
134
117
|
if (!needValid || validChecker(newValue, getPanelType(index))) {
|
135
118
|
return [].concat(result);
|
136
119
|
}
|
137
|
-
|
138
120
|
return undefined;
|
139
121
|
};
|
140
|
-
|
141
122
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
142
123
|
className: componentClass + "__wrapper"
|
143
124
|
}, /*#__PURE__*/React__default["default"].createElement("input", {
|
144
125
|
className: componentClass + "__interact-area",
|
145
126
|
onChange: function onChange(e) {
|
146
127
|
var result = dispose(e.target.value);
|
147
|
-
|
148
128
|
if (result) {
|
149
129
|
_onChange(result);
|
150
130
|
}
|
@@ -158,8 +138,8 @@ var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
158
138
|
}), /*#__PURE__*/React__default["default"].createElement("div", {
|
159
139
|
className: componentClass + "__shadow-text"
|
160
140
|
}, matchValue || placeholders[index]));
|
161
|
-
}, [componentClass, disabled, placeholders, isFitContent, format, cacheValue, validChecker, getPanelType, _onChange, _onFocus]);
|
162
|
-
|
141
|
+
}, [componentClass, disabled, placeholders, isFitContent, format, cacheValue, validChecker, getPanelType, _onChange, _onFocus]);
|
142
|
+
// 通知外部,输入框内容合法性变更
|
163
143
|
React.useEffect(function () {
|
164
144
|
onValidChange(judgeIsValid(cacheValue));
|
165
145
|
}, [judgeIsValid, cacheValue, onValidChange]);
|
package/lib/cjs/Panel.js
CHANGED
@@ -10,41 +10,32 @@
|
|
10
10
|
'use strict';
|
11
11
|
|
12
12
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
13
|
-
|
14
13
|
Object.defineProperty(exports, '__esModule', {
|
15
14
|
value: true
|
16
15
|
});
|
17
|
-
|
18
16
|
var React = require('react');
|
19
|
-
|
20
17
|
var analysisFormat = require('./utils/analysisFormat.js');
|
21
|
-
|
22
18
|
var generateSelectorData = require('./utils/generateSelectorData.js');
|
23
|
-
|
24
19
|
var classname = require('@hi-ui/classname');
|
25
|
-
|
26
20
|
var Selector = require('./Selector.js');
|
27
|
-
|
28
|
-
function _interopDefaultLegacy(e) {
|
21
|
+
function _interopDefaultCompat(e) {
|
29
22
|
return e && _typeof(e) === 'object' && 'default' in e ? e : {
|
30
23
|
'default': e
|
31
24
|
};
|
32
25
|
}
|
33
|
-
|
34
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
35
|
-
|
26
|
+
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
36
27
|
var Panel = function Panel(props) {
|
37
28
|
var hourStep = props.hourStep,
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
29
|
+
secondStep = props.secondStep,
|
30
|
+
minuteStep = props.minuteStep,
|
31
|
+
disabledHours = props.disabledHours,
|
32
|
+
disabledMinutes = props.disabledMinutes,
|
33
|
+
disabledSeconds = props.disabledSeconds,
|
34
|
+
prefix = props.prefix,
|
35
|
+
format = props.format,
|
36
|
+
value = props.value,
|
37
|
+
panel = props.panel,
|
38
|
+
_onChange = props.onChange;
|
48
39
|
var componentPrefix = React.useMemo(function () {
|
49
40
|
return prefix + "__panel";
|
50
41
|
}, [prefix]);
|
@@ -75,7 +66,8 @@ var Panel = function Panel(props) {
|
|
75
66
|
selectorTypes: selectorTypes,
|
76
67
|
separateValue: separateValue
|
77
68
|
});
|
78
|
-
}, [disabledHours, disabledMinutes, disabledSeconds, secondStep, hourStep, minuteStep, panel, selectorTypes, separateValue]);
|
69
|
+
}, [disabledHours, disabledMinutes, disabledSeconds, secondStep, hourStep, minuteStep, panel, selectorTypes, separateValue]);
|
70
|
+
// const renderHeader = useCallback(() => {
|
79
71
|
// return (
|
80
72
|
// <div className={`${componentPrefix}__header`}>
|
81
73
|
// {selectorTypes.map((item) => (
|
@@ -86,21 +78,17 @@ var Panel = function Panel(props) {
|
|
86
78
|
// </div>
|
87
79
|
// )
|
88
80
|
// }, [selectorTypes, componentPrefix])
|
89
|
-
|
90
81
|
var renderSelectors = React.useCallback(function () {
|
91
82
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
92
83
|
className: componentPrefix + "__selector-container"
|
93
84
|
}, selectorTypes.map(function (type, index) {
|
94
85
|
var _cx;
|
95
|
-
|
96
86
|
var position = selectorTypes.length === 1 ? Selector.SelectorPosition.single : Selector.SelectorPosition.middle;
|
97
|
-
|
98
87
|
if (selectorTypes.length > 1 && index === 0) {
|
99
88
|
position = Selector.SelectorPosition.left;
|
100
89
|
} else if (selectorTypes.length > 1 && index === selectorTypes.length - 1) {
|
101
90
|
position = Selector.SelectorPosition.right;
|
102
91
|
}
|
103
|
-
|
104
92
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
105
93
|
className: componentPrefix + "__selector-content",
|
106
94
|
key: type
|
@@ -111,15 +99,13 @@ var Panel = function Panel(props) {
|
|
111
99
|
// itemHeight={itemHeight}
|
112
100
|
// fullDisplayItemNumber={fullDisplayItemNumber}
|
113
101
|
onChange: function onChange(e) {
|
114
|
-
var result = [].concat(separateValue).slice(0, selectorTypes.length);
|
102
|
+
var result = [].concat(separateValue).slice(0, selectorTypes.length);
|
103
|
+
// 如果 value = '',则代表为空值
|
115
104
|
// 此时选择任意项,其他项直接视作 0
|
116
|
-
|
117
105
|
if (value === '') {
|
118
106
|
result = [0, 0, 0].slice(0, selectorTypes.length);
|
119
107
|
}
|
120
|
-
|
121
108
|
result[index] = Number(e.id);
|
122
|
-
|
123
109
|
_onChange(result.map(function (item) {
|
124
110
|
return String(item).padStart(2, '0');
|
125
111
|
}).join(':'));
|
@@ -129,12 +115,12 @@ var Panel = function Panel(props) {
|
|
129
115
|
className: classname.cx(componentPrefix + "__indicator", (_cx = {}, _cx[componentPrefix + "__indicator--left"] = index === 0, _cx[componentPrefix + "__indicator--right"] = index === selectorTypes.length - 1, _cx))
|
130
116
|
}));
|
131
117
|
}));
|
132
|
-
}, [selectorTypes, componentPrefix, prefix, getSelectorData, _onChange, separateValue,
|
118
|
+
}, [selectorTypes, componentPrefix, prefix, getSelectorData, _onChange, separateValue,
|
119
|
+
// itemHeight,
|
133
120
|
// fullDisplayItemNumber,
|
134
121
|
value]);
|
135
122
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
136
123
|
className: componentPrefix
|
137
124
|
}, renderSelectors());
|
138
125
|
};
|
139
|
-
|
140
126
|
exports.Panel = Panel;
|
package/lib/cjs/PopContent.js
CHANGED
@@ -10,67 +10,53 @@
|
|
10
10
|
'use strict';
|
11
11
|
|
12
12
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
13
|
-
|
14
13
|
Object.defineProperty(exports, '__esModule', {
|
15
14
|
value: true
|
16
15
|
});
|
17
|
-
|
18
16
|
var React = require('react');
|
19
|
-
|
20
17
|
var index = require('./@types/index.js');
|
21
|
-
|
22
18
|
var getRange = require('./utils/getRange.js');
|
23
|
-
|
24
19
|
var Panel = require('./Panel.js');
|
25
|
-
|
26
20
|
var analysisFormat = require('./utils/analysisFormat.js');
|
27
|
-
|
28
21
|
var getFormatDefault = require('./utils/getFormatDefault.js');
|
29
|
-
|
30
22
|
var TimePicker = require('./TimePicker.js');
|
31
|
-
|
32
23
|
var useFilter = require('./hooks/useFilter.js');
|
33
|
-
|
34
|
-
function _interopDefaultLegacy(e) {
|
24
|
+
function _interopDefaultCompat(e) {
|
35
25
|
return e && _typeof(e) === 'object' && 'default' in e ? e : {
|
36
26
|
'default': e
|
37
27
|
};
|
38
28
|
}
|
39
|
-
|
40
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
41
|
-
|
29
|
+
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
42
30
|
var DefaultDisabledFunc = function DefaultDisabledFunc() {
|
43
31
|
return [];
|
44
32
|
};
|
45
|
-
|
46
33
|
var PopContent = function PopContent(props) {
|
47
34
|
var _props$prefix = props.prefix,
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
35
|
+
prefix = _props$prefix === void 0 ? TimePicker.timePickerPrefix : _props$prefix,
|
36
|
+
dangerousValue = props.value,
|
37
|
+
_onChange = props.onChange,
|
38
|
+
format = props.format,
|
39
|
+
type = props.type,
|
40
|
+
hourStep = props.hourStep,
|
41
|
+
minuteStep = props.minuteStep,
|
42
|
+
secondStep = props.secondStep,
|
43
|
+
_props$disabledHours = props.disabledHours,
|
44
|
+
originalDisabledHours = _props$disabledHours === void 0 ? DefaultDisabledFunc : _props$disabledHours,
|
45
|
+
_props$disabledSecond = props.disabledSeconds,
|
46
|
+
originalDisabledSeconds = _props$disabledSecond === void 0 ? DefaultDisabledFunc : _props$disabledSecond,
|
47
|
+
_props$disabledMinute = props.disabledMinutes,
|
48
|
+
originalDisabledMinutes = _props$disabledMinute === void 0 ? DefaultDisabledFunc : _props$disabledMinute,
|
49
|
+
style = props.style;
|
50
|
+
// 将值统一转化为函数
|
63
51
|
// 由于 pop content 会被 date-picker 直接调用,故而在此多做一次兼容处理
|
64
|
-
|
65
52
|
var _useFilter = useFilter.useFilter({
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
53
|
+
disabledHours: originalDisabledHours,
|
54
|
+
disabledMinutes: originalDisabledMinutes,
|
55
|
+
disabledSeconds: originalDisabledSeconds
|
56
|
+
}),
|
57
|
+
disabledHours = _useFilter.disabledHours,
|
58
|
+
disabledMinutes = _useFilter.disabledMinutes,
|
59
|
+
disabledSeconds = _useFilter.disabledSeconds;
|
74
60
|
var value = React.useMemo(function () {
|
75
61
|
return dangerousValue.map(function (item) {
|
76
62
|
return item || getFormatDefault.getFormatDefault(format);
|
@@ -99,75 +85,68 @@ var PopContent = function PopContent(props) {
|
|
99
85
|
}, [selectorTypes]);
|
100
86
|
var customDisabledHours = React.useCallback(function (panel) {
|
101
87
|
var result = disabledHours(panel);
|
102
|
-
|
103
88
|
if (panel === 'range-end') {
|
104
89
|
var startHour = getMatchTypeValue(0, index.TimePickerSelectorType.hour);
|
105
|
-
var isLastOne = judgeTypeIsLastOne(index.TimePickerSelectorType.hour);
|
90
|
+
var isLastOne = judgeTypeIsLastOne(index.TimePickerSelectorType.hour);
|
91
|
+
// 当当前类型为最后一个类型的时候
|
106
92
|
// 不能够选择与开始一致的值
|
107
|
-
|
108
93
|
result = [].concat(result, getRange.getRange(0, isLastOne ? startHour : startHour - 1));
|
109
94
|
}
|
110
|
-
|
111
95
|
return result;
|
112
96
|
}, [getMatchTypeValue, disabledHours, judgeTypeIsLastOne]);
|
113
97
|
var customDisabledMinute = React.useCallback(function (hour, panel) {
|
114
98
|
var result = disabledMinutes(hour, panel);
|
115
|
-
|
116
99
|
if (panel === 'range-end') {
|
117
100
|
var startHour = getMatchTypeValue(0, index.TimePickerSelectorType.hour);
|
118
|
-
var startMinute = getMatchTypeValue(0, index.TimePickerSelectorType.minute);
|
101
|
+
var startMinute = getMatchTypeValue(0, index.TimePickerSelectorType.minute);
|
102
|
+
// 当前类型中包含了小时
|
119
103
|
// minute 有值
|
120
|
-
|
121
104
|
if (hour >= 0) {
|
122
105
|
// 开始时间等于结束时间,则直接禁用开始时间之前的时间
|
123
106
|
if (startHour === hour) {
|
124
|
-
var isLastOne = judgeTypeIsLastOne(index.TimePickerSelectorType.minute);
|
107
|
+
var isLastOne = judgeTypeIsLastOne(index.TimePickerSelectorType.minute);
|
108
|
+
// 当当前类型为最后一个类型的时候
|
125
109
|
// 不能够选择与开始一致的值
|
126
|
-
|
127
110
|
result = [].concat(result, getRange.getRange(0, isLastOne ? startMinute : startMinute - 1));
|
128
|
-
}
|
111
|
+
}
|
112
|
+
// 开始时间大于结束时间,直接禁用所有
|
129
113
|
else if (startHour > hour) {
|
130
114
|
result = [].concat(result, getRange.getRange(0, 59));
|
131
115
|
}
|
132
116
|
}
|
133
117
|
}
|
134
|
-
|
135
118
|
return result;
|
136
119
|
}, [getMatchTypeValue, judgeTypeIsLastOne, disabledMinutes]);
|
137
120
|
var customDisabledSeconds = React.useCallback(function (hour, minute, panel) {
|
138
121
|
var result = disabledSeconds(hour, minute, panel);
|
139
|
-
|
140
122
|
if (panel === 'range-end') {
|
141
123
|
var startHour = getMatchTypeValue(0, index.TimePickerSelectorType.hour);
|
142
124
|
var startMinute = getMatchTypeValue(0, index.TimePickerSelectorType.minute);
|
143
125
|
var startSecond = getMatchTypeValue(0, index.TimePickerSelectorType.second);
|
144
|
-
var allDisabled = false;
|
145
|
-
|
126
|
+
var allDisabled = false;
|
127
|
+
// 如果小时存在,并且开始小时大于结束,禁用所有秒
|
146
128
|
if (hour >= 0 && startHour > hour) {
|
147
129
|
allDisabled = true;
|
148
|
-
}
|
149
|
-
|
150
|
-
|
130
|
+
}
|
131
|
+
// 如果小时存在,并且开始结束小时一样,并且开始分钟大于结束分钟,禁用所有秒
|
151
132
|
if (hour >= 0 && startHour === hour && minute >= 0 && startMinute > minute) {
|
152
133
|
allDisabled = true;
|
153
134
|
}
|
154
|
-
|
155
135
|
if (allDisabled) {
|
156
136
|
result = [].concat(result, getRange.getRange(0, 59));
|
157
137
|
} else {
|
158
138
|
// hour 不存在 或者存在并且开始与结束相同
|
159
139
|
// 则视作,小时相等
|
160
|
-
var isHourEqual = hour < 0 || startHour === hour;
|
140
|
+
var isHourEqual = hour < 0 || startHour === hour;
|
141
|
+
// minute 不存在 或者存在并且开始与结束相同
|
161
142
|
// 则视作,分钟相等
|
162
|
-
|
163
|
-
|
164
|
-
|
143
|
+
var isMinuteEqual = minute < 0 || startMinute === minute;
|
144
|
+
// 分钟小时相等,则需要根据 开始 秒 做禁用处理
|
165
145
|
if (isHourEqual && isMinuteEqual) {
|
166
146
|
result = [].concat(result, getRange.getRange(0, startSecond));
|
167
147
|
}
|
168
148
|
}
|
169
149
|
}
|
170
|
-
|
171
150
|
return result;
|
172
151
|
}, [getMatchTypeValue, disabledSeconds]);
|
173
152
|
var componentClass = React.useMemo(function () {
|
@@ -176,7 +155,8 @@ var PopContent = function PopContent(props) {
|
|
176
155
|
var renderPanel = React.useCallback(function (index) {
|
177
156
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
178
157
|
className: componentClass + "__panel-container"
|
179
|
-
}, /*#__PURE__*/React__default["default"].createElement(Panel.Panel
|
158
|
+
}, /*#__PURE__*/React__default["default"].createElement(Panel.Panel
|
159
|
+
// itemHeight={itemHeight}
|
180
160
|
// fullDisplayItemNumber={fullDisplayItemNumber}
|
181
161
|
, {
|
182
162
|
// itemHeight={itemHeight}
|
@@ -194,11 +174,11 @@ var PopContent = function PopContent(props) {
|
|
194
174
|
onChange: function onChange(e) {
|
195
175
|
var result = [].concat(value);
|
196
176
|
result[index] = e;
|
197
|
-
|
198
177
|
_onChange(result);
|
199
178
|
}
|
200
179
|
}));
|
201
|
-
}, [hourStep, minuteStep, secondStep, customDisabledHours, customDisabledMinute, customDisabledSeconds, format, prefix, type, value, _onChange,
|
180
|
+
}, [hourStep, minuteStep, secondStep, customDisabledHours, customDisabledMinute, customDisabledSeconds, format, prefix, type, value, _onChange,
|
181
|
+
// fullDisplayItemNumber,
|
202
182
|
// itemHeight,
|
203
183
|
componentClass]);
|
204
184
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
@@ -208,5 +188,4 @@ var PopContent = function PopContent(props) {
|
|
208
188
|
className: componentClass + "__separator"
|
209
189
|
}), type === 'range' && renderPanel(1));
|
210
190
|
};
|
211
|
-
|
212
191
|
exports.PopContent = PopContent;
|
package/lib/cjs/Selector.js
CHANGED
@@ -10,41 +10,33 @@
|
|
10
10
|
'use strict';
|
11
11
|
|
12
12
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
13
|
-
|
14
13
|
Object.defineProperty(exports, '__esModule', {
|
15
14
|
value: true
|
16
15
|
});
|
17
|
-
|
18
16
|
var React = require('react');
|
19
|
-
|
20
17
|
var classname = require('@hi-ui/classname');
|
21
|
-
|
22
|
-
function _interopDefaultLegacy(e) {
|
18
|
+
function _interopDefaultCompat(e) {
|
23
19
|
return e && _typeof(e) === 'object' && 'default' in e ? e : {
|
24
20
|
'default': e
|
25
21
|
};
|
26
22
|
}
|
27
|
-
|
28
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
29
|
-
|
23
|
+
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
30
24
|
exports.SelectorPosition = void 0;
|
31
|
-
|
32
25
|
(function (SelectorPosition) {
|
33
26
|
SelectorPosition["left"] = "left";
|
34
27
|
SelectorPosition["right"] = "right";
|
35
28
|
SelectorPosition["middle"] = "middle";
|
36
29
|
SelectorPosition["single"] = "single";
|
37
30
|
})(exports.SelectorPosition || (exports.SelectorPosition = {}));
|
38
|
-
|
39
31
|
var Selector = function Selector(props) {
|
40
32
|
var prefix = props.prefix,
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
33
|
+
value = props.value,
|
34
|
+
data = props.data,
|
35
|
+
onChange = props.onChange,
|
36
|
+
position = props.position;
|
45
37
|
var componentPrefix = prefix + "__selector";
|
46
|
-
var stopScrollTimeoutHandler = React.useRef(-1);
|
47
|
-
|
38
|
+
var stopScrollTimeoutHandler = React.useRef(-1);
|
39
|
+
// 滚动容器引用
|
48
40
|
var scrollContainerRef = React.useRef(null);
|
49
41
|
var topItemGagerRef = React.useRef(null);
|
50
42
|
var bottomItemGagerRef = React.useRef(null);
|
@@ -59,22 +51,20 @@ var Selector = function Selector(props) {
|
|
59
51
|
}, []);
|
60
52
|
var onScroll = React.useCallback(function (e) {
|
61
53
|
e.persist();
|
62
|
-
e.stopPropagation();
|
63
|
-
|
64
|
-
clearTimeout(stopScrollTimeoutHandler.current);
|
65
|
-
|
54
|
+
e.stopPropagation();
|
55
|
+
// 清除用做判断是否滚动停止的定时器
|
56
|
+
clearTimeout(stopScrollTimeoutHandler.current);
|
57
|
+
// 计算当前选中的 index 下标
|
66
58
|
var currentIndex = calcCurrentIndex(e.target.scrollTop);
|
67
|
-
|
68
59
|
if (currentIndex > data.length) {
|
69
60
|
currentIndex = data.length - 1;
|
70
|
-
}
|
61
|
+
}
|
62
|
+
// 200ms 后如果事件没有再次响应,则视作滚动停止
|
71
63
|
// 不论是否禁用,我们都需要自动滚动到对应 index
|
72
|
-
|
73
|
-
|
74
64
|
stopScrollTimeoutHandler.current = setTimeout(function () {
|
75
|
-
scrollToMatchIndex(currentIndex);
|
65
|
+
scrollToMatchIndex(currentIndex);
|
66
|
+
// 通知外部改变
|
76
67
|
// 如果当前 item 被禁用了,则无通知
|
77
|
-
|
78
68
|
if (!data[currentIndex].disabled) {
|
79
69
|
onChange(data[currentIndex]);
|
80
70
|
}
|
@@ -88,9 +78,9 @@ var Selector = function Selector(props) {
|
|
88
78
|
React.useEffect(function () {
|
89
79
|
var currentIndex = data.findIndex(function (item) {
|
90
80
|
return item.id === value;
|
91
|
-
});
|
81
|
+
});
|
82
|
+
// 避免非法值跳转
|
92
83
|
// 避免重复执行操作,只有当 value 对应的下标改变的时候才需要执行
|
93
|
-
|
94
84
|
if (currentIndex >= 0 && lastValueMatchIndexCache.current !== currentIndex) {
|
95
85
|
lastValueMatchIndexCache.current = currentIndex;
|
96
86
|
scrollToMatchIndex(currentIndex);
|
@@ -106,7 +96,6 @@ var Selector = function Selector(props) {
|
|
106
96
|
className: classname.cx(componentPrefix + "__scroll-part", componentPrefix + "__demarcate")
|
107
97
|
}, data.map(function (item, index) {
|
108
98
|
var _cx;
|
109
|
-
|
110
99
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
111
100
|
className: classname.cx(componentPrefix + "__item", componentPrefix + "__demarcate", (_cx = {}, _cx[componentPrefix + "__item--disabled"] = item.disabled, _cx[componentPrefix + "__item--active"] = item.id === value, _cx)),
|
112
101
|
key: item.id,
|
@@ -131,5 +120,4 @@ var Selector = function Selector(props) {
|
|
131
120
|
ref: bottomItemGagerRef
|
132
121
|
}))));
|
133
122
|
};
|
134
|
-
|
135
123
|
exports.Selector = Selector;
|