rsuite 5.21.0 → 5.22.0

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.
@@ -10,6 +10,8 @@ import IconClockO from '@rsuite/icons/legacy/ClockO';
10
10
  import CalendarContainer from '../Calendar/CalendarContainer';
11
11
  import useCalendarDate from '../Calendar/useCalendarDate';
12
12
  import Toolbar from './Toolbar';
13
+ import Stack from '../Stack';
14
+ import PredefinedRanges from './PredefinedRanges';
13
15
  import { composeFunctions, createChainedFunction, DateUtils, mergeRefs, useClassNames, useControlled, useCustom } from '../utils';
14
16
  import { PickerOverlay, pickerPropTypes, PickerToggle, PickerToggleTrigger, pickTriggerPropKeys, omitTriggerPropKeys, usePickerClassName, usePublicMethods, useToggleKeyDownEvent } from '../Picker';
15
17
  import { OverlayCloseCause } from '../Overlay/OverlayTrigger';
@@ -334,6 +336,12 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
334
336
  onChangePageTime: handleChangePageTime,
335
337
  onToggleMeridian: handleToggleMeridian
336
338
  }));
339
+ var sideRanges = (ranges === null || ranges === void 0 ? void 0 : ranges.filter(function (range) {
340
+ return (range === null || range === void 0 ? void 0 : range.placement) === 'left';
341
+ })) || [];
342
+ var bottomRanges = (ranges === null || ranges === void 0 ? void 0 : ranges.filter(function (range) {
343
+ return (range === null || range === void 0 ? void 0 : range.placement) === 'bottom' || (range === null || range === void 0 ? void 0 : range.placement) === undefined;
344
+ })) || [];
337
345
 
338
346
  var renderDropdownMenu = function renderDropdownMenu(positionProps, speakerRef) {
339
347
  var left = positionProps.left,
@@ -350,16 +358,27 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
350
358
  ref: mergeRefs(overlayRef, speakerRef),
351
359
  style: styles,
352
360
  target: triggerRef
353
- }, calendar, /*#__PURE__*/React.createElement(Toolbar, {
361
+ }, /*#__PURE__*/React.createElement(Stack, {
362
+ alignItems: "flex-start"
363
+ }, sideRanges.length > 0 && /*#__PURE__*/React.createElement(PredefinedRanges, {
364
+ direction: "column",
365
+ spacing: 0,
366
+ className: prefix('date-predefined'),
367
+ ranges: sideRanges,
368
+ calendarDate: calendarDate,
369
+ locale: locale,
370
+ disabledShortcut: disabledToolbarHandle,
371
+ onClickShortcut: handleShortcutPageDate
372
+ }), /*#__PURE__*/React.createElement(React.Fragment, null, calendar, /*#__PURE__*/React.createElement(Toolbar, {
354
373
  locale: locale,
355
- ranges: ranges,
374
+ ranges: bottomRanges,
356
375
  calendarDate: calendarDate,
357
376
  disabledOkBtn: disabledToolbarHandle,
358
377
  disabledShortcut: disabledToolbarHandle,
359
378
  onClickShortcut: handleShortcutPageDate,
360
379
  onOk: handleOK,
361
380
  hideOkBtn: oneTap
362
- }));
381
+ }))));
363
382
  };
364
383
 
365
384
  var hasValue = !!value;
@@ -4,6 +4,7 @@ export interface RangeType<T> {
4
4
  label: ReactNode;
5
5
  closeOverlay?: boolean;
6
6
  value: T | ((value: T) => T);
7
+ placement?: 'bottom' | 'left';
7
8
  }
8
9
  export interface InnerRange<T> extends Omit<RangeType<T>, 'value'> {
9
10
  value: T;
@@ -133,6 +133,22 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
133
133
 
134
134
 
135
135
  var selectRangeValueRef = useRef(null);
136
+ /**
137
+ * Get the time on the second calendar as the end of the date range.
138
+ */
139
+
140
+ var getCalendarEndDatetime = useCallback(function (date) {
141
+ var getHours = DateUtils.getHours,
142
+ getMinutes = DateUtils.getMinutes,
143
+ getSeconds = DateUtils.getSeconds,
144
+ set = DateUtils.set;
145
+ var calendarEndDate = (calendarDate === null || calendarDate === void 0 ? void 0 : calendarDate[1]) || (defaultCalendarValue === null || defaultCalendarValue === void 0 ? void 0 : defaultCalendarValue[1]);
146
+ return set(date, {
147
+ hours: getHours(calendarEndDate),
148
+ minutes: getMinutes(calendarEndDate),
149
+ seconds: getSeconds(calendarEndDate)
150
+ });
151
+ }, [calendarDate, defaultCalendarValue]);
136
152
  /**
137
153
  * Call this function to update the calendar panel rendering benchmark value.
138
154
  * If params `value` is not passed, it defaults to [new Date(), addMonth(new Date(), 1)].
@@ -140,21 +156,12 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
140
156
 
141
157
  var updateCalendarDateRange = useCallback(function (selectedDate, calendarKey) {
142
158
  var nextValue = selectedDate;
143
- var shouldRenderTime = DateUtils.shouldRenderTime,
144
- getHours = DateUtils.getHours,
145
- getMinutes = DateUtils.getMinutes,
146
- getSeconds = DateUtils.getSeconds,
147
- set = DateUtils.set;
159
+ var shouldRenderTime = DateUtils.shouldRenderTime;
148
160
 
149
- if (shouldRenderTime(formatStr) && calendarKey === undefined && (selectedDate === null || selectedDate === void 0 ? void 0 : selectedDate.length) === 1) {
150
- var calendarEndDate = (calendarDate === null || calendarDate === void 0 ? void 0 : calendarDate[1]) || (defaultCalendarValue === null || defaultCalendarValue === void 0 ? void 0 : defaultCalendarValue[1]);
151
- var _startDate = selectedDate[0]; // When updating the start date, the time of the end date should keep the time set by the user by default.
161
+ if (shouldRenderTime(formatStr) && calendarKey === undefined && selectedDate !== null && selectedDate !== void 0 && selectedDate.length) {
162
+ var _startDate = selectedDate[0];
152
163
 
153
- var _endDate = set(addMonths(_startDate, 1), {
154
- hours: getHours(calendarEndDate),
155
- minutes: getMinutes(calendarEndDate),
156
- seconds: getSeconds(calendarEndDate)
157
- });
164
+ var _endDate = getCalendarEndDatetime(addMonths(_startDate, 1));
158
165
 
159
166
  nextValue = [_startDate, _endDate];
160
167
  }
@@ -163,7 +170,7 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
163
170
  value: nextValue,
164
171
  calendarKey: calendarKey
165
172
  }));
166
- }, [calendarDate, defaultCalendarValue, formatStr]); // if valueProp changed then update selectValue/hoverValue
173
+ }, [getCalendarEndDatetime, formatStr]); // if valueProp changed then update selectValue/hoverValue
167
174
 
168
175
  useEffect(function () {
169
176
  setSelectedDates(valueProp !== null && valueProp !== void 0 ? valueProp : []);
@@ -327,19 +334,31 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
327
334
  nextSelectDates = hoverRangeValue;
328
335
  selectRangeValueRef.current = hoverRangeValue;
329
336
  }
330
- } // If user have completed the selection, then sort
337
+ }
331
338
 
339
+ var shouldRenderTime = DateUtils.shouldRenderTime,
340
+ isAfter = DateUtils.isAfter;
332
341
 
333
- if (nextSelectDates.length === 2 && DateUtils.isAfter(nextSelectDates[0], nextSelectDates[1])) {
334
- nextSelectDates.reverse();
342
+ if (nextSelectDates.length === 2) {
343
+ // If user have completed the selection, then sort the selected dates.
344
+ if (isAfter(nextSelectDates[0], nextSelectDates[1])) {
345
+ nextSelectDates.reverse();
346
+ }
347
+
348
+ if (shouldRenderTime(formatStr)) {
349
+ nextSelectDates[1] = getCalendarEndDatetime(nextSelectDates[1]);
350
+ }
351
+
352
+ setHoverDateRange(nextSelectDates);
353
+ } else {
354
+ setHoverDateRange([nextSelectDates[0], nextSelectDates[0]]);
335
355
  }
336
356
 
337
- setHoverDateRange(nextSelectDates.length === 2 ? nextSelectDates : [nextSelectDates[0], nextSelectDates[0]]);
338
357
  setSelectedDates(nextSelectDates);
339
358
  updateCalendarDateRange(nextSelectDates);
340
359
  onSelect === null || onSelect === void 0 ? void 0 : onSelect(date, event);
341
360
  hasDoneSelect.current = !hasDoneSelect.current;
342
- }, [getHoverRangeValue, handleValueUpdate, hoverDateRange, onSelect, oneTap, selectedDates, updateCalendarDateRange]);
361
+ }, [formatStr, getCalendarEndDatetime, getHoverRangeValue, handleValueUpdate, hoverDateRange, onSelect, oneTap, selectedDates, updateCalendarDateRange]);
343
362
  /**
344
363
  * If `selectValue` changed, there will be the following effects.
345
364
  * 1. Check if the selection is completed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsuite",
3
- "version": "5.21.0",
3
+ "version": "5.22.0",
4
4
  "description": "A suite of react components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -24,7 +24,7 @@
24
24
  "url": "git@github.com:rsuite/rsuite.git"
25
25
  },
26
26
  "dependencies": {
27
- "@babel/runtime": "^7.19.0",
27
+ "@babel/runtime": "^7.19.4",
28
28
  "@juggle/resize-observer": "^3.4.0",
29
29
  "@rsuite/icons": "^1.0.2",
30
30
  "@types/chai": "^4.3.3",
@@ -37,7 +37,7 @@
37
37
  "lodash": "^4.17.11",
38
38
  "prop-types": "^15.8.1",
39
39
  "react-window": "^1.8.7",
40
- "rsuite-table": "^5.7.2",
40
+ "rsuite-table": "^5.8.0",
41
41
  "schema-typed": "^2.0.3"
42
42
  },
43
43
  "peerDependencies": {
@@ -224,6 +224,7 @@
224
224
  @table-content-padding-horizontal: 10px; // @deprecated use @table-cell-padding-x instead
225
225
  @table-cell-padding-y: @table-body-content-padding-vertical;
226
226
  @table-cell-padding-x: @table-content-padding-horizontal;
227
+ @table-cell-hover-color: var(--rs-primary-500);
227
228
 
228
229
  @table-scrollbar-timing-duration: 0.1s;
229
230
  @table-scrollbar-width: 10px;