@ucloud-fe/react-components 1.4.5 → 1.4.6
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.
|
@@ -49,7 +49,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
49
49
|
|
|
50
50
|
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) { (0, _defineProperty2.default)(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; }
|
|
51
51
|
|
|
52
|
-
var formatInput = function formatInput(v, allFormat) {
|
|
52
|
+
var formatInput = function formatInput(v, allFormat, precision) {
|
|
53
53
|
(0, _newArrowCheck2.default)(this, _this);
|
|
54
54
|
if (v == '') return null;
|
|
55
55
|
var l = allFormat.length;
|
|
@@ -62,7 +62,7 @@ var formatInput = function formatInput(v, allFormat) {
|
|
|
62
62
|
var d = (0, _moment.default)(v, format, true);
|
|
63
63
|
|
|
64
64
|
if (d.isValid()) {
|
|
65
|
-
return d;
|
|
65
|
+
return precision ? d.startOf(precision) : d;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -154,6 +154,15 @@ var usePicker = function usePicker(props, displayToFormatAndTimeMode, mode, onCl
|
|
|
154
154
|
allFormat = _useMemo4[1],
|
|
155
155
|
timeMode = _useMemo4[2];
|
|
156
156
|
|
|
157
|
+
var precision = (0, _react.useMemo)(function () {
|
|
158
|
+
(0, _newArrowCheck2.default)(this, _this2);
|
|
159
|
+
if (mode === 'month') return 'month';
|
|
160
|
+
if (!(timeMode !== null && timeMode !== void 0 && timeMode.length)) return 'date';
|
|
161
|
+
if (timeMode.indexOf('ss') >= 0) return 'second';
|
|
162
|
+
if (timeMode.indexOf('mm') >= 0) return 'minute';
|
|
163
|
+
if (timeMode.indexOf('HH') >= 0) return 'hour';
|
|
164
|
+
return 'date';
|
|
165
|
+
}.bind(this), [mode, timeMode]);
|
|
157
166
|
var d = (0, _react.useMemo)(function () {
|
|
158
167
|
(0, _newArrowCheck2.default)(this, _this2);
|
|
159
168
|
return new Date();
|
|
@@ -223,7 +232,7 @@ var usePicker = function usePicker(props, displayToFormatAndTimeMode, mode, onCl
|
|
|
223
232
|
var currentValue;
|
|
224
233
|
|
|
225
234
|
if (useInputValue) {
|
|
226
|
-
var inputDValue = formatInput(inputValue, allFormat);
|
|
235
|
+
var inputDValue = formatInput(inputValue, allFormat, precision);
|
|
227
236
|
if (inputDValue === false) return locale.inputErrorTip;
|
|
228
237
|
currentValue = inputDValue;
|
|
229
238
|
} else {
|
|
@@ -237,13 +246,13 @@ var usePicker = function usePicker(props, displayToFormatAndTimeMode, mode, onCl
|
|
|
237
246
|
}
|
|
238
247
|
|
|
239
248
|
return true;
|
|
240
|
-
}.bind(this), [allFormat, calValue, inputValue, locale.dateErrorTip, locale.inputErrorTip, locale.nullableErrorTip, nullable, rules, useInputValue, value]);
|
|
249
|
+
}.bind(this), [allFormat, calValue, inputValue, locale.dateErrorTip, locale.inputErrorTip, locale.nullableErrorTip, nullable, precision, rules, useInputValue, value]);
|
|
241
250
|
var handleInputChange = (0, _react.useCallback)(function (e) {
|
|
242
251
|
(0, _newArrowCheck2.default)(this, _this2);
|
|
243
252
|
if (!visible) setVisible(true);
|
|
244
253
|
var v = e.target.value;
|
|
245
254
|
setInputValue(v);
|
|
246
|
-
var d = formatInput(v, allFormat);
|
|
255
|
+
var d = formatInput(v, allFormat, precision);
|
|
247
256
|
|
|
248
257
|
if (d) {
|
|
249
258
|
setCalValue(d);
|
|
@@ -253,7 +262,7 @@ var usePicker = function usePicker(props, displayToFormatAndTimeMode, mode, onCl
|
|
|
253
262
|
}
|
|
254
263
|
|
|
255
264
|
setUseInputValue(true);
|
|
256
|
-
}.bind(this), [allFormat, calValue, visible]);
|
|
265
|
+
}.bind(this), [allFormat, calValue, precision, visible]);
|
|
257
266
|
var clear = (0, _react.useCallback)(function () {
|
|
258
267
|
(0, _newArrowCheck2.default)(this, _this2);
|
|
259
268
|
setInputValue('');
|
|
@@ -289,6 +298,7 @@ var usePicker = function usePicker(props, displayToFormatAndTimeMode, mode, onCl
|
|
|
289
298
|
var handleCalendarChange = (0, _react.useCallback)(function (v) {
|
|
290
299
|
(0, _newArrowCheck2.default)(this, _this2);
|
|
291
300
|
v = (0, _utils.getValidDate)(v, rules);
|
|
301
|
+
v = (0, _utils.setPrecision)(v, precision);
|
|
292
302
|
setCalValue((0, _moment.default)(+v));
|
|
293
303
|
setInputValue(formatDate((0, _moment.default)(+v), format));
|
|
294
304
|
setUseInputValue(false);
|
|
@@ -297,7 +307,7 @@ var usePicker = function usePicker(props, displayToFormatAndTimeMode, mode, onCl
|
|
|
297
307
|
onChange && onChange((0, _moment.default)(+v));
|
|
298
308
|
setVisible(false);
|
|
299
309
|
}
|
|
300
|
-
}.bind(this), [clickConfirm, format, onChange, rules]);
|
|
310
|
+
}.bind(this), [clickConfirm, format, onChange, precision, rules]);
|
|
301
311
|
var handleInputFocus = (0, _react.useCallback)(function () {
|
|
302
312
|
var _this3 = this;
|
|
303
313
|
|
|
@@ -2,12 +2,13 @@ import { Moment } from 'moment';
|
|
|
2
2
|
import { TDate } from '@z-r/calendar';
|
|
3
3
|
import { isDateDisabled, getValidDate } from '../../components/Calendar/utils';
|
|
4
4
|
declare type Range = [TDate | void | null, TDate | void | null];
|
|
5
|
-
declare type Precision = 'second' | 'minute' | 'hour' | 'date' | 'month' | 'year';
|
|
5
|
+
export declare type Precision = 'second' | 'minute' | 'hour' | 'date' | 'month' | 'year';
|
|
6
6
|
export interface Rules {
|
|
7
7
|
range?: Range;
|
|
8
8
|
custom?: (date: Moment, value?: Moment | null) => boolean;
|
|
9
9
|
}
|
|
10
10
|
export declare const formatToShort: (format: string) => string;
|
|
11
|
+
export declare const setPrecision: (v: TDate, precision?: Precision | undefined) => TDate;
|
|
11
12
|
declare const isRangeDateValid: (value: [TDate | null, TDate | null], rules: {
|
|
12
13
|
range?: Range | undefined;
|
|
13
14
|
maxRange?: any;
|
|
@@ -17,7 +17,7 @@ Object.defineProperty(exports, "getValidDate", {
|
|
|
17
17
|
return _utils.getValidDate;
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
-
exports.isRangeDateValid = exports.isDateValid = exports.formatToShort = void 0;
|
|
20
|
+
exports.isRangeDateValid = exports.isDateValid = exports.setPrecision = exports.formatToShort = void 0;
|
|
21
21
|
|
|
22
22
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
23
23
|
|
|
@@ -36,6 +36,18 @@ var formatToShort = function formatToShort(format) {
|
|
|
36
36
|
|
|
37
37
|
exports.formatToShort = formatToShort;
|
|
38
38
|
|
|
39
|
+
var setPrecision = function setPrecision(v, precision) {
|
|
40
|
+
(0, _newArrowCheck2.default)(this, _this);
|
|
41
|
+
|
|
42
|
+
if (precision) {
|
|
43
|
+
v = (0, _moment.default)(+v).startOf(precision);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return v;
|
|
47
|
+
}.bind(void 0);
|
|
48
|
+
|
|
49
|
+
exports.setPrecision = setPrecision;
|
|
50
|
+
|
|
39
51
|
var isRangeDateValid = function isRangeDateValid(value, rules, precision) {
|
|
40
52
|
(0, _newArrowCheck2.default)(this, _this);
|
|
41
53
|
|