@ucloud-fe/react-components 1.4.3 → 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.
- package/CHANGELOG.md +18 -0
- package/dist/main.min.js +2 -2
- package/lib/components/Calendar/style/index.js +5 -5
- package/lib/components/DatePicker/Range.js +32 -10
- package/lib/components/DatePicker/usePicker.d.ts +1 -1
- package/lib/components/DatePicker/usePicker.js +32 -12
- package/lib/components/DatePicker/useRangePicker.d.ts +3 -1
- package/lib/components/DatePicker/useRangePicker.js +6 -4
- package/lib/components/DatePicker/utils.d.ts +2 -1
- package/lib/components/DatePicker/utils.js +13 -1
- package/package.json +1 -1
|
@@ -240,7 +240,7 @@ var Range = function Range(_ref2) {
|
|
|
240
240
|
onInitialChange && onInitialChange(initialValue);
|
|
241
241
|
updateValueWithoutCallOnChange(initialValue);
|
|
242
242
|
}.bind(this));
|
|
243
|
-
var handleStartChange = (0, _react.useCallback)(function (value) {
|
|
243
|
+
var handleStartChange = (0, _react.useCallback)(function (value, isClear) {
|
|
244
244
|
(0, _newArrowCheck2.default)(this, _this3);
|
|
245
245
|
|
|
246
246
|
var _cacheValue = (0, _slicedToArray2.default)(cacheValue, 2),
|
|
@@ -250,15 +250,21 @@ var Range = function Range(_ref2) {
|
|
|
250
250
|
var rangeDateValidResult = (0, _utils.isRangeDateValid)(newValue, rules, precision);
|
|
251
251
|
setRangeError(undefined);
|
|
252
252
|
|
|
253
|
-
if (
|
|
253
|
+
if (isClear) {
|
|
254
|
+
var _actionRefS$current, _actionRefE$current;
|
|
255
|
+
|
|
256
|
+
onChange(newValue);
|
|
257
|
+
(_actionRefS$current = actionRefS.current) === null || _actionRefS$current === void 0 ? void 0 : _actionRefS$current.hide();
|
|
258
|
+
(_actionRefE$current = actionRefE.current) === null || _actionRefE$current === void 0 ? void 0 : _actionRefE$current.hide();
|
|
259
|
+
} else if (rangeDateValidResult !== true) {
|
|
254
260
|
var _inputRefE$current;
|
|
255
261
|
|
|
256
262
|
(_inputRefE$current = inputRefE.current) === null || _inputRefE$current === void 0 ? void 0 : _inputRefE$current.focus();
|
|
257
263
|
|
|
258
264
|
if (rangeDateValidResult === 'startGreaterThanEnd') {
|
|
259
|
-
var _actionRefE$
|
|
265
|
+
var _actionRefE$current2;
|
|
260
266
|
|
|
261
|
-
(_actionRefE$
|
|
267
|
+
(_actionRefE$current2 = actionRefE.current) === null || _actionRefE$current2 === void 0 ? void 0 : _actionRefE$current2.clear();
|
|
262
268
|
} else {
|
|
263
269
|
setRangeError(locale[rangeDateValidResult + 'Tip']);
|
|
264
270
|
}
|
|
@@ -274,7 +280,7 @@ var Range = function Range(_ref2) {
|
|
|
274
280
|
|
|
275
281
|
setCacheValue(newValue);
|
|
276
282
|
}.bind(this), [cacheValue, rules, precision, isFirstEditing, locale, onChange]);
|
|
277
|
-
var handleEndChange = (0, _react.useCallback)(function (value) {
|
|
283
|
+
var handleEndChange = (0, _react.useCallback)(function (value, isClear) {
|
|
278
284
|
(0, _newArrowCheck2.default)(this, _this3);
|
|
279
285
|
|
|
280
286
|
var _cacheValue2 = (0, _slicedToArray2.default)(cacheValue, 1),
|
|
@@ -284,15 +290,21 @@ var Range = function Range(_ref2) {
|
|
|
284
290
|
var rangeDateValidResult = (0, _utils.isRangeDateValid)(newValue, rules, precision);
|
|
285
291
|
setRangeError(undefined);
|
|
286
292
|
|
|
287
|
-
if (
|
|
293
|
+
if (isClear) {
|
|
294
|
+
var _actionRefS$current2, _actionRefE$current3;
|
|
295
|
+
|
|
296
|
+
onChange(newValue);
|
|
297
|
+
(_actionRefS$current2 = actionRefS.current) === null || _actionRefS$current2 === void 0 ? void 0 : _actionRefS$current2.hide();
|
|
298
|
+
(_actionRefE$current3 = actionRefE.current) === null || _actionRefE$current3 === void 0 ? void 0 : _actionRefE$current3.hide();
|
|
299
|
+
} else if (rangeDateValidResult !== true) {
|
|
288
300
|
var _inputRefS$current;
|
|
289
301
|
|
|
290
302
|
(_inputRefS$current = inputRefS.current) === null || _inputRefS$current === void 0 ? void 0 : _inputRefS$current.focus();
|
|
291
303
|
|
|
292
304
|
if (rangeDateValidResult === 'startGreaterThanEnd') {
|
|
293
|
-
var _actionRefS$
|
|
305
|
+
var _actionRefS$current3;
|
|
294
306
|
|
|
295
|
-
(_actionRefS$
|
|
307
|
+
(_actionRefS$current3 = actionRefS.current) === null || _actionRefS$current3 === void 0 ? void 0 : _actionRefS$current3.clear();
|
|
296
308
|
} else {
|
|
297
309
|
setRangeError(locale[rangeDateValidResult + 'Tip']);
|
|
298
310
|
}
|
|
@@ -308,6 +320,14 @@ var Range = function Range(_ref2) {
|
|
|
308
320
|
|
|
309
321
|
setCacheValue(newValue);
|
|
310
322
|
}.bind(this), [cacheValue, rules, precision, isFirstEditing, locale, onChange]);
|
|
323
|
+
var onClearS = (0, _react.useCallback)(function () {
|
|
324
|
+
(0, _newArrowCheck2.default)(this, _this3);
|
|
325
|
+
handleStartChange(null, true);
|
|
326
|
+
}.bind(this), [handleStartChange]);
|
|
327
|
+
var onClearE = (0, _react.useCallback)(function () {
|
|
328
|
+
(0, _newArrowCheck2.default)(this, _this3);
|
|
329
|
+
handleEndChange(null, true);
|
|
330
|
+
}.bind(this), [handleEndChange]);
|
|
311
331
|
var handleOptionChange = (0, _react.useCallback)(function (value) {
|
|
312
332
|
(0, _newArrowCheck2.default)(this, _this3);
|
|
313
333
|
if (value !== 'custom') onChange(getValueFromOption(options, value));
|
|
@@ -346,7 +366,8 @@ var Range = function Range(_ref2) {
|
|
|
346
366
|
nullable: nullableS,
|
|
347
367
|
placeholder: placeholderS,
|
|
348
368
|
shortcuts: shortcutsS,
|
|
349
|
-
actionRef: actionRefS
|
|
369
|
+
actionRef: actionRefS,
|
|
370
|
+
onClear: onClearS
|
|
350
371
|
}, sharedPickerProps), {}, {
|
|
351
372
|
rules: isFirstEditing === 2 ? _objectSpread(_objectSpread({}, rules), {}, {
|
|
352
373
|
range: [(_rules$range = rules.range) === null || _rules$range === void 0 ? void 0 : _rules$range[0], cacheValue[1]]
|
|
@@ -374,7 +395,8 @@ var Range = function Range(_ref2) {
|
|
|
374
395
|
nullable: nullableE,
|
|
375
396
|
placeholder: placeholderE,
|
|
376
397
|
shortcuts: shortcutsE,
|
|
377
|
-
actionRef: actionRefE
|
|
398
|
+
actionRef: actionRefE,
|
|
399
|
+
onClear: onClearE
|
|
378
400
|
}, sharedPickerProps), {}, {
|
|
379
401
|
rules: isFirstEditing === 2 ? _objectSpread(_objectSpread({}, rules), {}, {
|
|
380
402
|
range: [cacheValue[0], (_rules$range2 = rules.range) === null || _rules$range2 === void 0 ? void 0 : _rules$range2[1]]
|
|
@@ -7,5 +7,5 @@ declare type TProps<D> = {
|
|
|
7
7
|
interface DisplayToFormatAndTimeMode<D> {
|
|
8
8
|
(display?: D): [string[]] | [string[], string[]];
|
|
9
9
|
}
|
|
10
|
-
declare const usePicker: <D>(props: TProps<D>, displayToFormatAndTimeMode: DisplayToFormatAndTimeMode<D>, mode: 'date' | 'month') => any[];
|
|
10
|
+
declare const usePicker: <D>(props: TProps<D>, displayToFormatAndTimeMode: DisplayToFormatAndTimeMode<D>, mode: 'date' | 'month', onClear?: (() => void) | undefined) => any[];
|
|
11
11
|
export default usePicker;
|
|
@@ -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
|
|
|
@@ -106,7 +106,7 @@ var align = {
|
|
|
106
106
|
targetOffset: [0, 0]
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
var usePicker = function usePicker(props, displayToFormatAndTimeMode, mode) {
|
|
109
|
+
var usePicker = function usePicker(props, displayToFormatAndTimeMode, mode, onClear) {
|
|
110
110
|
var _this2 = this;
|
|
111
111
|
|
|
112
112
|
(0, _newArrowCheck2.default)(this, _this);
|
|
@@ -154,6 +154,15 @@ var usePicker = function usePicker(props, displayToFormatAndTimeMode, mode) {
|
|
|
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) {
|
|
|
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) {
|
|
|
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,12 +262,16 @@ var usePicker = function usePicker(props, displayToFormatAndTimeMode, mode) {
|
|
|
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('');
|
|
260
269
|
setCalValue(null);
|
|
261
270
|
}.bind(this), []);
|
|
271
|
+
var hide = (0, _react.useCallback)(function () {
|
|
272
|
+
(0, _newArrowCheck2.default)(this, _this2);
|
|
273
|
+
setVisible(false);
|
|
274
|
+
}.bind(this), []);
|
|
262
275
|
var handleConfirm = (0, _react.useCallback)(function (v) {
|
|
263
276
|
(0, _newArrowCheck2.default)(this, _this2);
|
|
264
277
|
var currentValue = v !== undefined ? v : calValue;
|
|
@@ -274,12 +287,18 @@ var usePicker = function usePicker(props, displayToFormatAndTimeMode, mode) {
|
|
|
274
287
|
}.bind(this), [calValue, nullable, onChange, rules, value]);
|
|
275
288
|
var handleInputClear = (0, _react.useCallback)(function () {
|
|
276
289
|
(0, _newArrowCheck2.default)(this, _this2);
|
|
277
|
-
clear();
|
|
278
|
-
|
|
279
|
-
|
|
290
|
+
clear(); // 不走 onChange,区分两种操作
|
|
291
|
+
|
|
292
|
+
if (onClear) {
|
|
293
|
+
onClear();
|
|
294
|
+
} else {
|
|
295
|
+
handleConfirm(null);
|
|
296
|
+
}
|
|
297
|
+
}.bind(this), [clear, handleConfirm, onClear]);
|
|
280
298
|
var handleCalendarChange = (0, _react.useCallback)(function (v) {
|
|
281
299
|
(0, _newArrowCheck2.default)(this, _this2);
|
|
282
300
|
v = (0, _utils.getValidDate)(v, rules);
|
|
301
|
+
v = (0, _utils.setPrecision)(v, precision);
|
|
283
302
|
setCalValue((0, _moment.default)(+v));
|
|
284
303
|
setInputValue(formatDate((0, _moment.default)(+v), format));
|
|
285
304
|
setUseInputValue(false);
|
|
@@ -288,7 +307,7 @@ var usePicker = function usePicker(props, displayToFormatAndTimeMode, mode) {
|
|
|
288
307
|
onChange && onChange((0, _moment.default)(+v));
|
|
289
308
|
setVisible(false);
|
|
290
309
|
}
|
|
291
|
-
}.bind(this), [clickConfirm, format, onChange, rules]);
|
|
310
|
+
}.bind(this), [clickConfirm, format, onChange, precision, rules]);
|
|
292
311
|
var handleInputFocus = (0, _react.useCallback)(function () {
|
|
293
312
|
var _this3 = this;
|
|
294
313
|
|
|
@@ -396,7 +415,8 @@ var usePicker = function usePicker(props, displayToFormatAndTimeMode, mode) {
|
|
|
396
415
|
error: typeof error === 'string' ? error : null,
|
|
397
416
|
active: visible
|
|
398
417
|
}, {
|
|
399
|
-
clear: clear
|
|
418
|
+
clear: clear,
|
|
419
|
+
hide: hide
|
|
400
420
|
}];
|
|
401
421
|
}.bind(void 0);
|
|
402
422
|
|
|
@@ -2,15 +2,17 @@ import { ReactNode, MutableRefObject } from 'react';
|
|
|
2
2
|
import { DatePickerProps } from './DatePicker';
|
|
3
3
|
export declare type RangeActionRef = {
|
|
4
4
|
clear: () => void;
|
|
5
|
+
hide: () => void;
|
|
5
6
|
};
|
|
6
7
|
export declare type RangePickerRef = {
|
|
7
8
|
focus: () => void;
|
|
8
9
|
clear: () => void;
|
|
9
10
|
} | undefined;
|
|
10
|
-
declare const useRangePicker: ({ prefix, type, suffix, actionRef, ...pickProps }: DatePickerProps & {
|
|
11
|
+
declare const useRangePicker: ({ prefix, type, suffix, actionRef, onClear, ...pickProps }: DatePickerProps & {
|
|
11
12
|
prefix?: boolean | undefined;
|
|
12
13
|
type?: "date" | "month" | undefined;
|
|
13
14
|
suffix?: ReactNode;
|
|
14
15
|
actionRef: MutableRefObject<RangeActionRef | undefined>;
|
|
16
|
+
onClear?: (() => void) | undefined;
|
|
15
17
|
}) => any[];
|
|
16
18
|
export default useRangePicker;
|
|
@@ -29,7 +29,7 @@ var _Month = require("./Month");
|
|
|
29
29
|
|
|
30
30
|
var _usePicker3 = _interopRequireDefault(require("./usePicker"));
|
|
31
31
|
|
|
32
|
-
var _excluded = ["prefix", "type", "suffix", "actionRef"];
|
|
32
|
+
var _excluded = ["prefix", "type", "suffix", "actionRef", "onClear"];
|
|
33
33
|
|
|
34
34
|
var _this = void 0;
|
|
35
35
|
|
|
@@ -57,10 +57,11 @@ var useRangePicker = function useRangePicker(_ref) {
|
|
|
57
57
|
type = _ref$type === void 0 ? 'date' : _ref$type,
|
|
58
58
|
suffix = _ref.suffix,
|
|
59
59
|
actionRef = _ref.actionRef,
|
|
60
|
+
onClear = _ref.onClear,
|
|
60
61
|
pickProps = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
61
62
|
var isMonth = type === 'month';
|
|
62
63
|
|
|
63
|
-
var _usePicker = (0, _usePicker3.default)(_objectSpread({}, pickProps), isMonth ? _Month.displayToFormatAndTimeMode : _DatePicker.displayToFormatAndTimeMode, type),
|
|
64
|
+
var _usePicker = (0, _usePicker3.default)(_objectSpread({}, pickProps), isMonth ? _Month.displayToFormatAndTimeMode : _DatePicker.displayToFormatAndTimeMode, type, onClear),
|
|
64
65
|
_usePicker2 = (0, _slicedToArray2.default)(_usePicker, 9),
|
|
65
66
|
inputProps = _usePicker2[0],
|
|
66
67
|
popoverProps = _usePicker2[2],
|
|
@@ -75,9 +76,10 @@ var useRangePicker = function useRangePicker(_ref) {
|
|
|
75
76
|
(0, _react.useImperativeHandle)(actionRef, function () {
|
|
76
77
|
(0, _newArrowCheck2.default)(this, _this2);
|
|
77
78
|
return {
|
|
78
|
-
clear: actions.clear
|
|
79
|
+
clear: actions.clear,
|
|
80
|
+
hide: actions.hide
|
|
79
81
|
};
|
|
80
|
-
}.bind(this), [actions.clear]);
|
|
82
|
+
}.bind(this), [actions.clear, actions.hide]);
|
|
81
83
|
return [// inputProps
|
|
82
84
|
_objectSpread(_objectSpread({}, inputProps), {}, {
|
|
83
85
|
customStyle: inputCustomStyle,
|
|
@@ -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
|
|