rsuite 5.48.1 → 5.49.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.
Files changed (138) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/Cascader/styles/index.less +1 -0
  3. package/DatePicker/styles/index.less +18 -11
  4. package/DateRangeInput/package.json +7 -0
  5. package/DateRangePicker/styles/index.less +10 -0
  6. package/InputGroup/styles/index.less +1 -0
  7. package/Picker/styles/index.less +20 -0
  8. package/README.md +32 -22
  9. package/Sidenav/styles/index.less +2 -0
  10. package/cjs/Calendar/CalendarContainer.d.ts +2 -0
  11. package/cjs/Calendar/CalendarContainer.js +11 -4
  12. package/cjs/Calendar/CalendarHeader.js +2 -0
  13. package/cjs/Calendar/MonthDropdown.js +7 -2
  14. package/cjs/Calendar/MonthDropdownItem.js +2 -2
  15. package/cjs/Calendar/Table.js +6 -1
  16. package/cjs/Calendar/TimeDropdown.js +17 -10
  17. package/cjs/Calendar/types.d.ts +1 -0
  18. package/cjs/CustomProvider/CustomProvider.d.ts +13 -0
  19. package/cjs/CustomProvider/CustomProvider.js +2 -2
  20. package/cjs/DateInput/DateField.d.ts +9 -31
  21. package/cjs/DateInput/DateField.js +61 -12
  22. package/cjs/DateInput/DateInput.d.ts +7 -2
  23. package/cjs/DateInput/DateInput.js +74 -92
  24. package/cjs/DateInput/index.d.ts +4 -0
  25. package/cjs/DateInput/index.js +19 -1
  26. package/cjs/DateInput/useDateInputState.d.ts +7 -31
  27. package/cjs/DateInput/useDateInputState.js +39 -15
  28. package/cjs/DateInput/useIsFocused.d.ts +7 -0
  29. package/cjs/DateInput/useIsFocused.js +28 -0
  30. package/cjs/DateInput/useKeyboardInputEvent.d.ts +10 -0
  31. package/cjs/DateInput/useKeyboardInputEvent.js +44 -0
  32. package/cjs/DateInput/utils.d.ts +23 -1
  33. package/cjs/DateInput/utils.js +155 -51
  34. package/cjs/DatePicker/DatePicker.d.ts +20 -7
  35. package/cjs/DatePicker/DatePicker.js +210 -241
  36. package/cjs/DatePicker/PickerIndicator.d.ts +10 -0
  37. package/cjs/DatePicker/PickerIndicator.js +48 -0
  38. package/cjs/DatePicker/PickerLabel.d.ts +9 -0
  39. package/cjs/DatePicker/PickerLabel.js +23 -0
  40. package/cjs/DatePicker/Toolbar.js +3 -21
  41. package/cjs/DatePicker/utils.d.ts +5 -1
  42. package/cjs/DatePicker/utils.js +17 -1
  43. package/cjs/DateRangeInput/DateRangeInput.d.ts +29 -0
  44. package/cjs/DateRangeInput/DateRangeInput.js +244 -0
  45. package/cjs/DateRangeInput/index.d.ts +3 -0
  46. package/cjs/DateRangeInput/index.js +9 -0
  47. package/cjs/DateRangeInput/utils.d.ts +61 -0
  48. package/cjs/DateRangeInput/utils.js +146 -0
  49. package/cjs/DateRangePicker/DateRangePicker.js +12 -2
  50. package/cjs/Input/Input.d.ts +11 -0
  51. package/cjs/Input/Input.js +11 -8
  52. package/cjs/Overlay/OverlayTrigger.d.ts +3 -0
  53. package/cjs/Overlay/OverlayTrigger.js +5 -0
  54. package/cjs/Picker/usePickerRef.d.ts +17 -0
  55. package/cjs/Picker/usePickerRef.js +82 -0
  56. package/cjs/index.d.ts +2 -0
  57. package/cjs/index.js +3 -1
  58. package/cjs/locales/index.d.ts +2 -2
  59. package/cjs/utils/index.d.ts +2 -0
  60. package/cjs/utils/index.js +8 -2
  61. package/cjs/utils/useCustom.js +1 -1
  62. package/cjs/utils/useIsomorphicLayoutEffect.d.ts +3 -0
  63. package/cjs/utils/useIsomorphicLayoutEffect.js +9 -0
  64. package/dist/rsuite-no-reset-rtl.css +51 -141
  65. package/dist/rsuite-no-reset-rtl.min.css +1 -1
  66. package/dist/rsuite-no-reset-rtl.min.css.map +1 -1
  67. package/dist/rsuite-no-reset.css +51 -141
  68. package/dist/rsuite-no-reset.min.css +1 -1
  69. package/dist/rsuite-no-reset.min.css.map +1 -1
  70. package/dist/rsuite-rtl.css +51 -9
  71. package/dist/rsuite-rtl.min.css +1 -1
  72. package/dist/rsuite-rtl.min.css.map +1 -1
  73. package/dist/rsuite.css +51 -9
  74. package/dist/rsuite.js +4800 -246
  75. package/dist/rsuite.js.map +1 -1
  76. package/dist/rsuite.min.css +1 -1
  77. package/dist/rsuite.min.css.map +1 -1
  78. package/dist/rsuite.min.js +1 -1
  79. package/dist/rsuite.min.js.map +1 -1
  80. package/esm/Calendar/CalendarContainer.d.ts +2 -0
  81. package/esm/Calendar/CalendarContainer.js +12 -5
  82. package/esm/Calendar/CalendarHeader.js +2 -0
  83. package/esm/Calendar/MonthDropdown.js +7 -2
  84. package/esm/Calendar/MonthDropdownItem.js +2 -2
  85. package/esm/Calendar/Table.js +6 -1
  86. package/esm/Calendar/TimeDropdown.js +17 -10
  87. package/esm/Calendar/types.d.ts +1 -0
  88. package/esm/CustomProvider/CustomProvider.d.ts +13 -0
  89. package/esm/CustomProvider/CustomProvider.js +3 -3
  90. package/esm/DateInput/DateField.d.ts +9 -31
  91. package/esm/DateInput/DateField.js +61 -12
  92. package/esm/DateInput/DateInput.d.ts +7 -2
  93. package/esm/DateInput/DateInput.js +77 -95
  94. package/esm/DateInput/index.d.ts +4 -0
  95. package/esm/DateInput/index.js +4 -0
  96. package/esm/DateInput/useDateInputState.d.ts +7 -31
  97. package/esm/DateInput/useDateInputState.js +41 -18
  98. package/esm/DateInput/useIsFocused.d.ts +7 -0
  99. package/esm/DateInput/useIsFocused.js +22 -0
  100. package/esm/DateInput/useKeyboardInputEvent.d.ts +10 -0
  101. package/esm/DateInput/useKeyboardInputEvent.js +38 -0
  102. package/esm/DateInput/utils.d.ts +23 -1
  103. package/esm/DateInput/utils.js +150 -51
  104. package/esm/DatePicker/DatePicker.d.ts +20 -7
  105. package/esm/DatePicker/DatePicker.js +213 -244
  106. package/esm/DatePicker/PickerIndicator.d.ts +10 -0
  107. package/esm/DatePicker/PickerIndicator.js +42 -0
  108. package/esm/DatePicker/PickerLabel.d.ts +9 -0
  109. package/esm/DatePicker/PickerLabel.js +17 -0
  110. package/esm/DatePicker/Toolbar.js +3 -21
  111. package/esm/DatePicker/utils.d.ts +5 -1
  112. package/esm/DatePicker/utils.js +16 -1
  113. package/esm/DateRangeInput/DateRangeInput.d.ts +29 -0
  114. package/esm/DateRangeInput/DateRangeInput.js +237 -0
  115. package/esm/DateRangeInput/index.d.ts +3 -0
  116. package/esm/DateRangeInput/index.js +3 -0
  117. package/esm/DateRangeInput/utils.d.ts +61 -0
  118. package/esm/DateRangeInput/utils.js +137 -0
  119. package/esm/DateRangePicker/DateRangePicker.js +12 -2
  120. package/esm/Input/Input.d.ts +11 -0
  121. package/esm/Input/Input.js +12 -9
  122. package/esm/Overlay/OverlayTrigger.d.ts +3 -0
  123. package/esm/Overlay/OverlayTrigger.js +5 -0
  124. package/esm/Picker/usePickerRef.d.ts +17 -0
  125. package/esm/Picker/usePickerRef.js +77 -0
  126. package/esm/index.d.ts +2 -0
  127. package/esm/index.js +1 -0
  128. package/esm/locales/index.d.ts +2 -2
  129. package/esm/utils/index.d.ts +2 -0
  130. package/esm/utils/index.js +3 -1
  131. package/esm/utils/useCustom.js +2 -2
  132. package/esm/utils/useIsomorphicLayoutEffect.d.ts +3 -0
  133. package/esm/utils/useIsomorphicLayoutEffect.js +4 -0
  134. package/package.json +1 -1
  135. package/styles/color-modes/dark.less +1 -0
  136. package/styles/color-modes/high-contrast.less +1 -0
  137. package/styles/color-modes/light.less +1 -0
  138. package/styles/normalize.less +230 -231
@@ -1,10 +1,89 @@
1
1
  'use client';
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  import { setYear, setMonth, setDate, setHours, setMinutes, setSeconds } from '../utils/dateUtils';
4
+ import { safeSetSelection } from '../utils';
4
5
  export function getPatternGroups(format, pattern) {
5
6
  var _format$match;
6
7
  return ((_format$match = format.match(new RegExp("(" + pattern + ")+"))) === null || _format$match === void 0 ? void 0 : _format$match[0]) || '';
7
8
  }
9
+ export function getSelectIndexGap(options) {
10
+ var pattern = options.pattern,
11
+ formatStr = options.formatStr,
12
+ valueOffset = options.valueOffset,
13
+ selectedMonth = options.selectedMonth,
14
+ localize = options.localize;
15
+ var gap = 0;
16
+ var monthIsAbbreviated = formatStr.includes('MMM');
17
+ var monthIsFull = formatStr.includes('MMMM');
18
+
19
+ // If the month is abbreviated or full, the gap needs to be adjusted.
20
+ if (monthIsAbbreviated || monthIsFull) {
21
+ var isSelectedMonth = pattern === 'M';
22
+
23
+ // If the selected is the month, and the valueOffset is null,
24
+ // it means that the delete key is pressed, and the default pattern is displayed, and the gap is 0 at this time.
25
+ if (isSelectedMonth && valueOffset === null) {
26
+ return 0;
27
+ }
28
+
29
+ // If the month is null and the valueOffset is 0, the month will not be updated, and the gap is 0 at this time.
30
+ if (selectedMonth === null && valueOffset === 0) {
31
+ return 0;
32
+ }
33
+ var month = selectedMonth ? selectedMonth + (isSelectedMonth ? valueOffset || 0 : 0) : 1;
34
+ if (month > 12) {
35
+ month = 1;
36
+ } else if (month === 0) {
37
+ month = 12;
38
+ }
39
+ var monthStr = localize === null || localize === void 0 ? void 0 : localize.month(month - 1, {
40
+ width: monthIsFull ? 'wide' : 'abbreviated'
41
+ });
42
+ gap = monthStr.length - (monthIsFull ? 4 : 3);
43
+ }
44
+ return gap;
45
+ }
46
+ export function getDatePattern(options) {
47
+ var selectionIndex = options.selectionIndex,
48
+ _options$positionOffs = options.positionOffset,
49
+ positionOffset = _options$positionOffs === void 0 ? -1 : _options$positionOffs,
50
+ formatStr = options.formatStr,
51
+ dateString = options.dateString,
52
+ valueOffset = options.valueOffset,
53
+ selectedMonth = options.selectedMonth,
54
+ localize = options.localize;
55
+ var pattern = formatStr.charAt(selectionIndex || 0);
56
+ if (selectionIndex < 0 || selectionIndex > dateString.length - 1) {
57
+ pattern = formatStr.trim().charAt(0);
58
+ return pattern;
59
+ }
60
+ var gap = 0;
61
+ if (isCursorAfterMonth(selectionIndex, formatStr)) {
62
+ gap = getSelectIndexGap({
63
+ pattern: pattern,
64
+ formatStr: formatStr,
65
+ valueOffset: valueOffset,
66
+ selectedMonth: selectedMonth,
67
+ localize: localize
68
+ });
69
+ }
70
+ pattern = formatStr.charAt(selectionIndex - gap);
71
+
72
+ // If the pattern is not a letter, then get the pattern from the previous or next letter.
73
+ if (!pattern.match(/[y|d|M|H|h|m|s|a]/)) {
74
+ var nextIndex = selectionIndex + positionOffset;
75
+ pattern = getDatePattern(_extends({}, options, {
76
+ selectionIndex: nextIndex
77
+ }));
78
+ }
79
+ return pattern;
80
+ }
81
+
82
+ // Determine whether the cursor is after the month.
83
+ // If the currently operated field is after the month, the selected field needs to be moved backward.
84
+ export function isCursorAfterMonth(cursorIndex, formatStr) {
85
+ return cursorIndex > formatStr.indexOf('M');
86
+ }
8
87
  export function getInputSelectedState(options) {
9
88
  var input = options.input,
10
89
  direction = options.direction,
@@ -14,74 +93,61 @@ export function getInputSelectedState(options) {
14
93
  dateString = options.dateString,
15
94
  _options$valueOffset = options.valueOffset,
16
95
  valueOffset = _options$valueOffset === void 0 ? 0 : _options$valueOffset;
17
- var getSelectIndexGap = function getSelectIndexGap(pattern) {
18
- var gap = 0;
19
- var monthIsAbbreviated = formatStr.includes('MMM');
20
- var monthIsFull = formatStr.includes('MMMM');
21
-
22
- // If the month is abbreviated or full, the gap needs to be adjusted.
23
- if (monthIsAbbreviated || monthIsFull) {
24
- var isSelected = pattern === 'M';
25
- if (selectedMonth === null && valueOffset === 0) {
26
- return gap;
27
- }
28
- var month = selectedMonth ? selectedMonth + (isSelected ? valueOffset : 0) : 1;
29
- if (month > 12) {
30
- month = 1;
31
- } else if (month === 0) {
32
- month = 12;
33
- }
34
- var monthStr = localize === null || localize === void 0 ? void 0 : localize.month(month - 1, {
35
- width: monthIsFull ? 'wide' : 'abbreviated'
36
- });
37
- gap = monthStr.length - (monthIsFull ? 4 : 3);
38
- }
39
- return gap;
40
- };
41
- var getDatePattern = function getDatePattern(selectionIndex, positionOffset) {
42
- if (positionOffset === void 0) {
43
- positionOffset = -1;
44
- }
45
- var pattern = formatStr.charAt((input === null || input === void 0 ? void 0 : input.selectionStart) || 0);
46
- if (selectionIndex < 0 || selectionIndex > dateString.length - 1) {
47
- pattern = formatStr.trim().charAt(0);
48
- return pattern;
49
- }
50
- var gap = getSelectIndexGap(pattern);
51
- pattern = formatStr.charAt(selectionIndex - gap);
52
-
53
- // If the pattern is not a letter, then get the pattern from the previous or next letter.
54
- if (!pattern.match(/[y|d|M|H|h|m|s|a]/)) {
55
- var nextIndex = selectionIndex + positionOffset;
56
- pattern = getDatePattern(nextIndex, positionOffset);
57
- }
58
- return pattern;
59
- };
60
96
  var getPatternSelectedIndexes = function getPatternSelectedIndexes(pattern) {
61
97
  var selectionStart = formatStr.indexOf(pattern);
62
98
  var selectionEnd = formatStr.lastIndexOf(pattern) + 1;
63
- var gap = getSelectIndexGap(pattern);
64
- if (pattern === 'M') {
99
+ var gap = getSelectIndexGap({
100
+ pattern: pattern,
101
+ formatStr: formatStr,
102
+ valueOffset: valueOffset,
103
+ selectedMonth: selectedMonth,
104
+ localize: localize
105
+ });
106
+ var isSelectedMonth = pattern === 'M';
107
+ var isNullMonth = selectedMonth === null && !(isSelectedMonth && valueOffset !== 0);
108
+
109
+ // If the month is null and the valueOffset is 0, the month will not be updated, and the gap is 0 at this time.
110
+ if (isNullMonth) {
111
+ return {
112
+ selectionStart: selectionStart,
113
+ selectionEnd: selectionEnd
114
+ };
115
+ }
116
+ if (isSelectedMonth) {
65
117
  return {
66
118
  selectionStart: selectionStart,
67
119
  selectionEnd: selectionEnd + gap
68
120
  };
69
121
  }
122
+ if (isCursorAfterMonth(selectionStart, formatStr)) {
123
+ return {
124
+ selectionStart: selectionStart + gap,
125
+ selectionEnd: selectionEnd + gap
126
+ };
127
+ }
70
128
  return {
71
- selectionStart: selectionStart + gap,
72
- selectionEnd: selectionEnd + gap
129
+ selectionStart: selectionStart,
130
+ selectionEnd: selectionEnd
73
131
  };
74
132
  };
75
133
  if (typeof input.selectionEnd === 'number' && typeof input.selectionStart === 'number') {
76
- var index = input.selectionStart;
134
+ var selectionIndex = input.selectionStart;
77
135
  var positionOffset = -1;
78
136
  if (direction === 'left') {
79
- index = input.selectionStart - 1;
137
+ selectionIndex = input.selectionStart - 1;
80
138
  } else if (direction === 'right') {
81
- index = input.selectionEnd + 1;
139
+ selectionIndex = input.selectionEnd + 1;
82
140
  positionOffset = 1;
83
141
  }
84
- var datePattern = getDatePattern(index, positionOffset);
142
+ var datePattern = getDatePattern({
143
+ selectionIndex: selectionIndex,
144
+ positionOffset: positionOffset,
145
+ formatStr: formatStr,
146
+ dateString: dateString,
147
+ valueOffset: valueOffset,
148
+ selectedMonth: selectedMonth,
149
+ localize: localize
150
+ });
85
151
  var indexes = getPatternSelectedIndexes(datePattern);
86
152
  return _extends({
87
153
  selectedPattern: datePattern
@@ -148,4 +214,37 @@ export function modifyDate(date, type, value) {
148
214
  return setSeconds(date, value);
149
215
  }
150
216
  return date;
217
+ }
218
+ export function isFieldFullValue(formatStr, value, pattern) {
219
+ var patternGroup = getPatternGroups(formatStr, pattern);
220
+ if (value.toString().length === patternGroup.length) {
221
+ return true;
222
+ }
223
+ switch (pattern) {
224
+ case 'M':
225
+ return parseInt(value + "0") > 12;
226
+ case 'd':
227
+ return parseInt(value + "0") > 31;
228
+ case 'H':
229
+ return parseInt(value + "0") > 23;
230
+ case 'h':
231
+ return parseInt(value + "0") > 12;
232
+ case 'm':
233
+ case 's':
234
+ return parseInt(value + "0") > 59;
235
+ default:
236
+ return false;
237
+ }
238
+ }
239
+ var isTestEnvironment = undefined === 'test';
240
+ export function useInputSelection(input) {
241
+ return function setSelectionRange(selectionStart, selectionEnd) {
242
+ if (isTestEnvironment) {
243
+ safeSetSelection(input.current, selectionStart, selectionEnd);
244
+ return;
245
+ }
246
+ requestAnimationFrame(function () {
247
+ safeSetSelection(input.current, selectionStart, selectionEnd);
248
+ });
249
+ };
151
250
  }
@@ -1,14 +1,15 @@
1
1
  import React from 'react';
2
2
  import { RangeType } from './Toolbar';
3
3
  import { DatePickerLocale } from '../locales';
4
- import { PickerToggleProps } from '../Picker';
5
4
  import { FormControlBaseProps, PickerBaseProps, RsRefForwardingComponent } from '../@types/common';
6
5
  export type { RangeType } from './Toolbar';
7
- export interface DatePickerProps extends PickerBaseProps<DatePickerLocale>, FormControlBaseProps<Date | null>, Pick<PickerToggleProps, 'caretAs' | 'readOnly' | 'plaintext' | 'loading'> {
8
- /** Predefined date Ranges */
9
- ranges?: RangeType<Date>[];
6
+ export interface DatePickerProps extends PickerBaseProps<DatePickerLocale>, FormControlBaseProps<Date | null> {
7
+ /** Custom caret component */
8
+ caretAs?: React.ElementType | null;
10
9
  /** Calendar panel default presentation date and time */
11
10
  calendarDefaultDate?: Date;
11
+ /** Whether disabled the component */
12
+ disabled?: boolean;
12
13
  /** Rendered as an input, the date can be entered via the keyboard */
13
14
  editable?: boolean;
14
15
  /** Format date */
@@ -21,16 +22,26 @@ export interface DatePickerProps extends PickerBaseProps<DatePickerLocale>, Form
21
22
  inline?: boolean;
22
23
  /** ISO 8601 standard, each calendar week begins on Monday and Sunday on the seventh day */
23
24
  isoWeek?: boolean;
25
+ /** A label displayed at the beginning of toggle button */
26
+ label?: React.ReactNode;
24
27
  /** Set the upper limit of the available year relative to the current selection date */
25
28
  limitEndYear?: number;
26
29
  /** Set the lower limit of the available year relative to the current selection date */
27
30
  limitStartYear?: number;
31
+ /** Whether to display a loading state indicator */
32
+ loading?: boolean;
33
+ /** one tap to select */
34
+ oneTap?: boolean;
35
+ /** Whether plaintext the component */
36
+ plaintext?: boolean;
37
+ /** Whether read only the component */
38
+ readOnly?: boolean;
39
+ /** Predefined date Ranges */
40
+ ranges?: RangeType<Date>[];
28
41
  /** Whether to show week numbers */
29
42
  showWeekNumbers?: boolean;
30
43
  /** Meridian format */
31
44
  showMeridian?: boolean;
32
- /** one tap to select */
33
- oneTap?: boolean;
34
45
  /**
35
46
  * Whether to disable a date on the calendar view
36
47
  *
@@ -98,7 +109,9 @@ export interface DatePickerProps extends PickerBaseProps<DatePickerLocale>, Form
98
109
  onShortcutClick?: (range: RangeType<Date>, event: React.MouseEvent) => void;
99
110
  /** Called when clean */
100
111
  onClean?: (event: React.MouseEvent) => void;
101
- /** Custom render value */
112
+ /**
113
+ * @deprecated
114
+ */
102
115
  renderValue?: (value: Date, format: string) => string;
103
116
  }
104
117
  /**