rsuite 5.48.1 → 5.50.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 (203) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/Cascader/styles/index.less +5 -4
  3. package/DatePicker/styles/index.less +18 -11
  4. package/DateRangeInput/package.json +7 -0
  5. package/DateRangePicker/styles/index.less +20 -0
  6. package/Dropdown/styles/index.less +5 -4
  7. package/Dropdown/styles/mixin.less +0 -11
  8. package/InputGroup/styles/index.less +1 -0
  9. package/Picker/styles/index.less +51 -24
  10. package/Picker/styles/mixin.less +17 -13
  11. package/README.md +34 -24
  12. package/Sidenav/styles/index.less +2 -0
  13. package/TagInput/styles/index.less +1 -1
  14. package/cjs/AutoComplete/AutoComplete.js +25 -26
  15. package/cjs/Calendar/Calendar.d.ts +5 -1
  16. package/cjs/Calendar/CalendarContainer.d.ts +7 -1
  17. package/cjs/Calendar/CalendarContainer.js +11 -4
  18. package/cjs/Calendar/CalendarHeader.js +2 -0
  19. package/cjs/Calendar/MonthDropdown.js +7 -2
  20. package/cjs/Calendar/MonthDropdownItem.js +2 -2
  21. package/cjs/Calendar/Table.js +6 -1
  22. package/cjs/Calendar/TimeDropdown.js +17 -10
  23. package/cjs/Calendar/types.d.ts +1 -0
  24. package/cjs/Cascader/Cascader.js +46 -48
  25. package/cjs/CheckPicker/CheckPicker.d.ts +2 -2
  26. package/cjs/CheckPicker/CheckPicker.js +33 -36
  27. package/cjs/CheckTreePicker/CheckTreePicker.js +61 -64
  28. package/cjs/CustomProvider/CustomProvider.d.ts +13 -0
  29. package/cjs/CustomProvider/CustomProvider.js +2 -2
  30. package/cjs/DateInput/DateField.d.ts +9 -31
  31. package/cjs/DateInput/DateField.js +61 -12
  32. package/cjs/DateInput/DateInput.d.ts +7 -2
  33. package/cjs/DateInput/DateInput.js +74 -92
  34. package/cjs/DateInput/index.d.ts +4 -0
  35. package/cjs/DateInput/index.js +19 -1
  36. package/cjs/DateInput/useDateInputState.d.ts +7 -31
  37. package/cjs/DateInput/useDateInputState.js +39 -15
  38. package/cjs/DateInput/useIsFocused.d.ts +7 -0
  39. package/cjs/DateInput/useIsFocused.js +28 -0
  40. package/cjs/DateInput/useKeyboardInputEvent.d.ts +10 -0
  41. package/cjs/DateInput/useKeyboardInputEvent.js +44 -0
  42. package/cjs/DateInput/utils.d.ts +23 -1
  43. package/cjs/DateInput/utils.js +155 -51
  44. package/cjs/DatePicker/DatePicker.d.ts +25 -8
  45. package/cjs/DatePicker/DatePicker.js +208 -241
  46. package/cjs/DatePicker/Toolbar.js +5 -22
  47. package/cjs/DatePicker/utils.d.ts +5 -1
  48. package/cjs/DatePicker/utils.js +17 -1
  49. package/cjs/DateRangeInput/DateRangeInput.d.ts +29 -0
  50. package/cjs/DateRangeInput/DateRangeInput.js +244 -0
  51. package/cjs/DateRangeInput/index.d.ts +3 -0
  52. package/cjs/DateRangeInput/index.js +9 -0
  53. package/cjs/DateRangeInput/utils.d.ts +61 -0
  54. package/cjs/DateRangeInput/utils.js +146 -0
  55. package/cjs/DateRangePicker/Calendar.js +24 -23
  56. package/cjs/DateRangePicker/DateRangePicker.d.ts +18 -4
  57. package/cjs/DateRangePicker/DateRangePicker.js +251 -203
  58. package/cjs/DateRangePicker/types.d.ts +11 -3
  59. package/cjs/DateRangePicker/utils.d.ts +2 -1
  60. package/cjs/DateRangePicker/utils.js +7 -5
  61. package/cjs/FormControl/FormControl.d.ts +11 -1
  62. package/cjs/FormControl/FormControl.js +6 -5
  63. package/cjs/Input/Input.d.ts +11 -0
  64. package/cjs/Input/Input.js +11 -8
  65. package/cjs/InputPicker/InputPicker.js +62 -63
  66. package/cjs/MultiCascader/MultiCascader.js +40 -42
  67. package/cjs/Overlay/OverlayTrigger.d.ts +3 -0
  68. package/cjs/Overlay/OverlayTrigger.js +5 -0
  69. package/cjs/Picker/PickerIndicator.d.ts +10 -0
  70. package/cjs/Picker/PickerIndicator.js +49 -0
  71. package/cjs/Picker/PickerLabel.d.ts +9 -0
  72. package/cjs/Picker/PickerLabel.js +23 -0
  73. package/cjs/Picker/PickerToggle.d.ts +17 -22
  74. package/cjs/Picker/PickerToggle.js +52 -177
  75. package/cjs/Picker/index.d.ts +3 -0
  76. package/cjs/Picker/index.js +10 -1
  77. package/cjs/Picker/usePickerRef.d.ts +19 -0
  78. package/cjs/Picker/usePickerRef.js +88 -0
  79. package/cjs/Picker/utils.d.ts +5 -9
  80. package/cjs/Picker/utils.js +22 -89
  81. package/cjs/SelectPicker/SelectPicker.d.ts +2 -2
  82. package/cjs/SelectPicker/SelectPicker.js +39 -42
  83. package/cjs/TreePicker/TreePicker.js +72 -75
  84. package/cjs/index.d.ts +2 -0
  85. package/cjs/index.js +3 -1
  86. package/cjs/locales/index.d.ts +2 -2
  87. package/cjs/utils/constants.d.ts +2 -1
  88. package/cjs/utils/constants.js +1 -0
  89. package/cjs/utils/dateUtils.d.ts +0 -1
  90. package/cjs/utils/dateUtils.js +0 -6
  91. package/cjs/utils/getStringLength.d.ts +2 -0
  92. package/cjs/utils/getStringLength.js +18 -0
  93. package/cjs/utils/index.d.ts +3 -0
  94. package/cjs/utils/index.js +11 -2
  95. package/cjs/utils/useCustom.js +1 -1
  96. package/cjs/utils/useIsomorphicLayoutEffect.d.ts +3 -0
  97. package/cjs/utils/useIsomorphicLayoutEffect.js +9 -0
  98. package/dist/rsuite-no-reset-rtl.css +140 -207
  99. package/dist/rsuite-no-reset-rtl.min.css +1 -1
  100. package/dist/rsuite-no-reset-rtl.min.css.map +1 -1
  101. package/dist/rsuite-no-reset.css +140 -207
  102. package/dist/rsuite-no-reset.min.css +1 -1
  103. package/dist/rsuite-no-reset.min.css.map +1 -1
  104. package/dist/rsuite-rtl.css +140 -75
  105. package/dist/rsuite-rtl.min.css +1 -1
  106. package/dist/rsuite-rtl.min.css.map +1 -1
  107. package/dist/rsuite.css +140 -75
  108. package/dist/rsuite.js +4833 -258
  109. package/dist/rsuite.js.map +1 -1
  110. package/dist/rsuite.min.css +1 -1
  111. package/dist/rsuite.min.css.map +1 -1
  112. package/dist/rsuite.min.js +1 -1
  113. package/dist/rsuite.min.js.map +1 -1
  114. package/esm/AutoComplete/AutoComplete.js +28 -29
  115. package/esm/Calendar/Calendar.d.ts +5 -1
  116. package/esm/Calendar/CalendarContainer.d.ts +7 -1
  117. package/esm/Calendar/CalendarContainer.js +12 -5
  118. package/esm/Calendar/CalendarHeader.js +2 -0
  119. package/esm/Calendar/MonthDropdown.js +7 -2
  120. package/esm/Calendar/MonthDropdownItem.js +2 -2
  121. package/esm/Calendar/Table.js +6 -1
  122. package/esm/Calendar/TimeDropdown.js +17 -10
  123. package/esm/Calendar/types.d.ts +1 -0
  124. package/esm/Cascader/Cascader.js +49 -51
  125. package/esm/CheckPicker/CheckPicker.d.ts +2 -2
  126. package/esm/CheckPicker/CheckPicker.js +36 -39
  127. package/esm/CheckTreePicker/CheckTreePicker.js +64 -67
  128. package/esm/CustomProvider/CustomProvider.d.ts +13 -0
  129. package/esm/CustomProvider/CustomProvider.js +3 -3
  130. package/esm/DateInput/DateField.d.ts +9 -31
  131. package/esm/DateInput/DateField.js +61 -12
  132. package/esm/DateInput/DateInput.d.ts +7 -2
  133. package/esm/DateInput/DateInput.js +77 -95
  134. package/esm/DateInput/index.d.ts +4 -0
  135. package/esm/DateInput/index.js +4 -0
  136. package/esm/DateInput/useDateInputState.d.ts +7 -31
  137. package/esm/DateInput/useDateInputState.js +41 -18
  138. package/esm/DateInput/useIsFocused.d.ts +7 -0
  139. package/esm/DateInput/useIsFocused.js +22 -0
  140. package/esm/DateInput/useKeyboardInputEvent.d.ts +10 -0
  141. package/esm/DateInput/useKeyboardInputEvent.js +38 -0
  142. package/esm/DateInput/utils.d.ts +23 -1
  143. package/esm/DateInput/utils.js +150 -51
  144. package/esm/DatePicker/DatePicker.d.ts +25 -8
  145. package/esm/DatePicker/DatePicker.js +211 -244
  146. package/esm/DatePicker/Toolbar.js +5 -22
  147. package/esm/DatePicker/utils.d.ts +5 -1
  148. package/esm/DatePicker/utils.js +16 -1
  149. package/esm/DateRangeInput/DateRangeInput.d.ts +29 -0
  150. package/esm/DateRangeInput/DateRangeInput.js +237 -0
  151. package/esm/DateRangeInput/index.d.ts +3 -0
  152. package/esm/DateRangeInput/index.js +3 -0
  153. package/esm/DateRangeInput/utils.d.ts +61 -0
  154. package/esm/DateRangeInput/utils.js +137 -0
  155. package/esm/DateRangePicker/Calendar.js +25 -23
  156. package/esm/DateRangePicker/DateRangePicker.d.ts +18 -4
  157. package/esm/DateRangePicker/DateRangePicker.js +253 -205
  158. package/esm/DateRangePicker/types.d.ts +11 -3
  159. package/esm/DateRangePicker/utils.d.ts +2 -1
  160. package/esm/DateRangePicker/utils.js +7 -5
  161. package/esm/FormControl/FormControl.d.ts +11 -1
  162. package/esm/FormControl/FormControl.js +4 -3
  163. package/esm/Input/Input.d.ts +11 -0
  164. package/esm/Input/Input.js +12 -9
  165. package/esm/InputPicker/InputPicker.js +64 -65
  166. package/esm/MultiCascader/MultiCascader.js +43 -45
  167. package/esm/Overlay/OverlayTrigger.d.ts +3 -0
  168. package/esm/Overlay/OverlayTrigger.js +5 -0
  169. package/esm/Picker/PickerIndicator.d.ts +10 -0
  170. package/esm/Picker/PickerIndicator.js +43 -0
  171. package/esm/Picker/PickerLabel.d.ts +9 -0
  172. package/esm/Picker/PickerLabel.js +17 -0
  173. package/esm/Picker/PickerToggle.d.ts +17 -22
  174. package/esm/Picker/PickerToggle.js +54 -179
  175. package/esm/Picker/index.d.ts +3 -0
  176. package/esm/Picker/index.js +3 -0
  177. package/esm/Picker/usePickerRef.d.ts +19 -0
  178. package/esm/Picker/usePickerRef.js +82 -0
  179. package/esm/Picker/utils.d.ts +5 -9
  180. package/esm/Picker/utils.js +24 -90
  181. package/esm/SelectPicker/SelectPicker.d.ts +2 -2
  182. package/esm/SelectPicker/SelectPicker.js +42 -45
  183. package/esm/TreePicker/TreePicker.js +75 -78
  184. package/esm/index.d.ts +2 -0
  185. package/esm/index.js +1 -0
  186. package/esm/locales/index.d.ts +2 -2
  187. package/esm/utils/constants.d.ts +2 -1
  188. package/esm/utils/constants.js +1 -0
  189. package/esm/utils/dateUtils.d.ts +0 -1
  190. package/esm/utils/dateUtils.js +0 -5
  191. package/esm/utils/getStringLength.d.ts +2 -0
  192. package/esm/utils/getStringLength.js +13 -0
  193. package/esm/utils/index.d.ts +3 -0
  194. package/esm/utils/index.js +4 -1
  195. package/esm/utils/useCustom.js +2 -2
  196. package/esm/utils/useIsomorphicLayoutEffect.d.ts +3 -0
  197. package/esm/utils/useIsomorphicLayoutEffect.js +4 -0
  198. package/package.json +1 -1
  199. package/styles/color-modes/dark.less +1 -0
  200. package/styles/color-modes/high-contrast.less +1 -0
  201. package/styles/color-modes/light.less +1 -0
  202. package/styles/mixins/combobox.less +10 -0
  203. package/styles/normalize.less +230 -231
@@ -7,20 +7,15 @@ exports.default = void 0;
7
7
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
8
8
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
9
9
  var _react = _interopRequireDefault(require("react"));
10
- var _propTypes = _interopRequireDefault(require("prop-types"));
11
10
  var _Button = _interopRequireDefault(require("../Button"));
12
11
  var _utils = require("../utils");
13
12
  var _PredefinedRanges = _interopRequireDefault(require("./PredefinedRanges"));
14
13
  var _Stack = _interopRequireDefault(require("../Stack"));
15
14
  var SubmitButton = function SubmitButton(_ref) {
16
- var hide = _ref.hide,
17
- disabledOkBtn = _ref.disabledOkBtn,
15
+ var disabledOkBtn = _ref.disabledOkBtn,
18
16
  calendarDate = _ref.calendarDate,
19
17
  onOk = _ref.onOk,
20
18
  children = _ref.children;
21
- if (hide) {
22
- return null;
23
- }
24
19
  var disabled = disabledOkBtn === null || disabledOkBtn === void 0 ? void 0 : disabledOkBtn(calendarDate);
25
20
  return /*#__PURE__*/_react.default.createElement(_Button.default, {
26
21
  appearance: "primary",
@@ -33,7 +28,7 @@ var SubmitButton = function SubmitButton(_ref) {
33
28
  /**
34
29
  * Toolbar for DatePicker and DateRangePicker
35
30
  */
36
- var Toolbar = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
31
+ var Toolbar = /*#__PURE__*/_react.default.forwardRef(function Toolbar(props, ref) {
37
32
  var className = props.className,
38
33
  _props$classPrefix = props.classPrefix,
39
34
  classPrefix = _props$classPrefix === void 0 ? 'picker-toolbar' : _props$classPrefix,
@@ -66,27 +61,15 @@ var Toolbar = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
66
61
  calendarDate: calendarDate,
67
62
  locale: locale,
68
63
  disabledShortcut: disabledShortcut,
69
- onShortcutClick: onShortcutClick
64
+ onShortcutClick: onShortcutClick,
65
+ "data-testid": "daterange-predefined-bottom"
70
66
  }), /*#__PURE__*/_react.default.createElement("div", {
71
67
  className: prefix('right')
72
- }, /*#__PURE__*/_react.default.createElement(SubmitButton, {
68
+ }, !hideOkBtn && /*#__PURE__*/_react.default.createElement(SubmitButton, {
73
69
  disabledOkBtn: disabledOkBtn,
74
- hide: hideOkBtn,
75
70
  calendarDate: calendarDate,
76
71
  onOk: onOk
77
72
  }, locale === null || locale === void 0 ? void 0 : locale.ok)));
78
73
  });
79
- Toolbar.displayName = 'Toolbar';
80
- Toolbar.propTypes = {
81
- ranges: _propTypes.default.array,
82
- className: _propTypes.default.string,
83
- classPrefix: _propTypes.default.string,
84
- calendarDate: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.arrayOf(_propTypes.default.instanceOf(Date))]).isRequired,
85
- onShortcutClick: _propTypes.default.func,
86
- onOk: _propTypes.default.func,
87
- disabledShortcut: _propTypes.default.func,
88
- disabledOkBtn: _propTypes.default.func,
89
- hideOkBtn: _propTypes.default.bool
90
- };
91
74
  var _default = Toolbar;
92
75
  exports.default = _default;
@@ -1,5 +1,5 @@
1
1
  import { ToolbarProps } from './Toolbar';
2
- import { InnerRange } from './types';
2
+ import { InnerRange, RangeType } from './types';
3
3
  import { DateRange } from '../DateRangePicker/types';
4
4
  export declare function getDefaultRanges<T extends Date | DateRange>(value: T): InnerRange<T>[];
5
5
  /**
@@ -8,3 +8,7 @@ export declare function getDefaultRanges<T extends Date | DateRange>(value: T):
8
8
  * @param calendarDate
9
9
  */
10
10
  export declare const getRanges: <T extends Date | DateRange>({ ranges, calendarDate }: Pick<ToolbarProps<T, T>, "calendarDate" | "ranges">) => InnerRange<T>[];
11
+ export declare function splitRanges(ranges?: RangeType<Date>[]): {
12
+ sideRanges: RangeType<Date>[];
13
+ bottomRanges: RangeType<Date>[];
14
+ };
@@ -4,6 +4,7 @@
4
4
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
5
  exports.__esModule = true;
6
6
  exports.getDefaultRanges = getDefaultRanges;
7
+ exports.splitRanges = splitRanges;
7
8
  exports.getRanges = void 0;
8
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
10
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
@@ -58,4 +59,19 @@ var getRanges = function getRanges(_ref3) {
58
59
  calendarDate: calendarDate
59
60
  }));
60
61
  };
61
- exports.getRanges = getRanges;
62
+ exports.getRanges = getRanges;
63
+ function splitRanges(ranges) {
64
+ // The shortcut option on the left side of the calendar panel
65
+ var sideRanges = (ranges === null || ranges === void 0 ? void 0 : ranges.filter(function (range) {
66
+ return (range === null || range === void 0 ? void 0 : range.placement) === 'left';
67
+ })) || [];
68
+
69
+ // The shortcut option on the bottom of the calendar panel
70
+ var bottomRanges = (ranges === null || ranges === void 0 ? void 0 : ranges.filter(function (range) {
71
+ return (range === null || range === void 0 ? void 0 : range.placement) === 'bottom' || (range === null || range === void 0 ? void 0 : range.placement) === undefined;
72
+ })) || [];
73
+ return {
74
+ sideRanges: sideRanges,
75
+ bottomRanges: bottomRanges
76
+ };
77
+ }
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import { InputProps } from '../Input';
3
+ import { FormControlBaseProps } from '../@types/common';
4
+ declare type ValueType = [Date | null, Date | null] | null;
5
+ export interface DateRangeInputProps extends Omit<InputProps, 'value' | 'onChange' | 'defaultValue'>, FormControlBaseProps<ValueType> {
6
+ /**
7
+ * The character between the start and end dates.
8
+ * @default ' ~ '
9
+ **/
10
+ character?: string;
11
+ /**
12
+ * Format of the date when rendered in the input. Format of the string is based on Unicode Technical Standard.
13
+ *
14
+ * @see https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
15
+ * @default 'yyyy-MM-dd'
16
+ **/
17
+ format?: string;
18
+ /**
19
+ * The `placeholder` prop defines the text displayed in a form control when the control has no value.
20
+ */
21
+ placeholder?: string;
22
+ }
23
+ /**
24
+ * The DateRangeInput component lets users select a date with the keyboard.
25
+ * @version 5.59.0
26
+ * @see https://rsuitejs.com/components/date-range-input/
27
+ */
28
+ declare const DateRangeInput: React.ForwardRefExoticComponent<DateRangeInputProps & React.RefAttributes<unknown>>;
29
+ export default DateRangeInput;
@@ -0,0 +1,244 @@
1
+ 'use client';
2
+ "use strict";
3
+
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
+ exports.__esModule = true;
7
+ exports.default = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
+ var _react = _interopRequireWildcard(require("react"));
11
+ var _propTypes = _interopRequireDefault(require("prop-types"));
12
+ var _Input = _interopRequireDefault(require("../Input"));
13
+ var _utils = require("../utils");
14
+ var _DateInput = require("../DateInput");
15
+ var _utils2 = require("./utils");
16
+ /**
17
+ * The DateRangeInput component lets users select a date with the keyboard.
18
+ * @version 5.59.0
19
+ * @see https://rsuitejs.com/components/date-range-input/
20
+ */
21
+ var DateRangeInput = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
22
+ var className = props.className,
23
+ _props$classPrefix = props.classPrefix,
24
+ classPrefix = _props$classPrefix === void 0 ? 'date-range-input' : _props$classPrefix,
25
+ _props$character = props.character,
26
+ character = _props$character === void 0 ? ' ~ ' : _props$character,
27
+ _props$format = props.format,
28
+ formatStr = _props$format === void 0 ? 'yyyy-MM-dd' : _props$format,
29
+ valueProp = props.value,
30
+ _props$defaultValue = props.defaultValue,
31
+ defaultValue = _props$defaultValue === void 0 ? [] : _props$defaultValue,
32
+ placeholder = props.placeholder,
33
+ onChange = props.onChange,
34
+ onKeyDown = props.onKeyDown,
35
+ onBlur = props.onBlur,
36
+ onFocus = props.onFocus,
37
+ rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["className", "classPrefix", "character", "format", "value", "defaultValue", "placeholder", "onChange", "onKeyDown", "onBlur", "onFocus"]);
38
+ var _useClassNames = (0, _utils.useClassNames)(classPrefix),
39
+ withClassPrefix = _useClassNames.withClassPrefix,
40
+ merge = _useClassNames.merge;
41
+ var classes = merge(className, withClassPrefix());
42
+ var inputRef = (0, _react.useRef)();
43
+ var _useState = (0, _react.useState)({
44
+ selectedPattern: 'y',
45
+ selectionStart: 0,
46
+ selectionEnd: 0
47
+ }),
48
+ selectedState = _useState[0],
49
+ setSelectedState = _useState[1];
50
+ var _useCustom = (0, _utils.useCustom)('Calendar'),
51
+ locale = _useCustom.locale;
52
+ var rangeFormatStr = "" + formatStr + character + formatStr;
53
+ var dateLocale = locale.dateLocale;
54
+ var _useControlled = (0, _utils.useControlled)(valueProp, defaultValue),
55
+ value = _useControlled[0],
56
+ setValue = _useControlled[1],
57
+ isControlled = _useControlled[2];
58
+ var _useState2 = (0, _react.useState)(_utils2.DateType.Start),
59
+ dateType = _useState2[0],
60
+ setDateType = _useState2[1];
61
+ var dateInputOptions = {
62
+ formatStr: formatStr,
63
+ locale: dateLocale,
64
+ isControlledDate: isControlled
65
+ };
66
+ var startDateState = (0, _DateInput.useDateInputState)((0, _extends2.default)({}, dateInputOptions, {
67
+ date: (value === null || value === void 0 ? void 0 : value[0]) || null
68
+ }));
69
+ var endDateState = (0, _DateInput.useDateInputState)((0, _extends2.default)({}, dateInputOptions, {
70
+ date: (value === null || value === void 0 ? void 0 : value[1]) || null
71
+ }));
72
+ var getActiveState = function getActiveState(type) {
73
+ if (type === void 0) {
74
+ type = dateType;
75
+ }
76
+ return type === _utils2.DateType.Start ? startDateState : endDateState;
77
+ };
78
+ var _useIsFocused = (0, _DateInput.useIsFocused)({
79
+ onBlur: onBlur,
80
+ onFocus: onFocus
81
+ }),
82
+ focused = _useIsFocused[0],
83
+ focusEventProps = _useIsFocused[1];
84
+ var renderedValue = (0, _react.useMemo)(function () {
85
+ var dateString = startDateState.toDateString() + character + endDateState.toDateString();
86
+ if (!startDateState.isEmptyValue() || !endDateState.isEmptyValue()) {
87
+ return dateString;
88
+ }
89
+ return !focused ? '' : dateString;
90
+ }, [character, endDateState, focused, startDateState]);
91
+ var keyPressOptions = {
92
+ formatStr: formatStr,
93
+ rangeFormatStr: rangeFormatStr,
94
+ localize: dateLocale.localize,
95
+ selectedMonth: getActiveState().dateField.month,
96
+ dateString: renderedValue,
97
+ dateType: dateType,
98
+ character: character
99
+ };
100
+ var setSelectionRange = (0, _DateInput.useInputSelection)(inputRef);
101
+ var handleChange = (0, _utils.useEventCallback)(function (date, event) {
102
+ var nextValue = dateType === _utils2.DateType.Start ? [date, value === null || value === void 0 ? void 0 : value[1]] : [value === null || value === void 0 ? void 0 : value[0], date];
103
+ onChange === null || onChange === void 0 ? void 0 : onChange(nextValue, event);
104
+ setValue(nextValue);
105
+ });
106
+ var onSegmentChange = (0, _utils.useEventCallback)(function (event, nextDirection) {
107
+ var input = event.target;
108
+ var key = event.key;
109
+ var direction = nextDirection || (key === 'ArrowRight' ? 'right' : 'left');
110
+ if (input.selectionEnd === null || input.selectionStart === null) {
111
+ return;
112
+ }
113
+ var cursorIndex = direction === 'right' ? input.selectionEnd : input.selectionStart;
114
+ var nextDateType = dateType;
115
+ if ((0, _utils2.isSwitchDateType)(renderedValue, character, cursorIndex, direction)) {
116
+ nextDateType = dateType === _utils2.DateType.Start ? _utils2.DateType.End : _utils2.DateType.Start;
117
+ setDateType(nextDateType);
118
+ }
119
+ var state = (0, _utils2.getInputSelectedState)((0, _extends2.default)({}, keyPressOptions, {
120
+ dateType: nextDateType,
121
+ selectedMonth: getActiveState(nextDateType).dateField.month,
122
+ input: input,
123
+ direction: direction
124
+ }));
125
+ setSelectionRange(state.selectionStart, state.selectionEnd);
126
+ setSelectedState(state);
127
+ });
128
+ var onSegmentValueChange = (0, _utils.useEventCallback)(function (event) {
129
+ var input = event.target;
130
+ var key = event.key;
131
+ var offset = key === 'ArrowUp' ? 1 : -1;
132
+ var state = (0, _utils2.getInputSelectedState)((0, _extends2.default)({}, keyPressOptions, {
133
+ input: input,
134
+ valueOffset: offset
135
+ }));
136
+ setSelectedState(state);
137
+ getActiveState().setDateOffset(state.selectedPattern, offset, function (date) {
138
+ return handleChange(date, event);
139
+ });
140
+ setSelectionRange(state.selectionStart, state.selectionEnd);
141
+ });
142
+ var onSegmentValueChangeWithNumericKeys = (0, _utils.useEventCallback)(function (event) {
143
+ var input = event.target;
144
+ var key = event.key;
145
+ var pattern = selectedState.selectedPattern;
146
+ if (!pattern) {
147
+ return;
148
+ }
149
+ var field = getActiveState().getDateField(pattern);
150
+ var value = parseInt(key, 10);
151
+ var padValue = parseInt("" + (field.value || '') + key, 10);
152
+ var newValue = value;
153
+
154
+ // Check if the value entered by the user is a valid date
155
+ if ((0, _DateInput.validateDateTime)(field.name, padValue)) {
156
+ newValue = padValue;
157
+ }
158
+ if (pattern === 'M') {
159
+ // Month cannot be less than 1.
160
+ newValue = Math.max(1, newValue);
161
+ }
162
+ getActiveState().setDateField(pattern, newValue, function (date) {
163
+ return handleChange(date, event);
164
+ });
165
+
166
+ // The currently selected month will be retained as a parameter of getInputSelectedState,
167
+ // but if the user enters a month, the month value will be replaced with the value entered by the user.
168
+ var selectedMonth = pattern === 'M' ? newValue : getActiveState().dateField.month;
169
+ var nextState = (0, _utils2.getInputSelectedState)((0, _extends2.default)({}, keyPressOptions, {
170
+ input: input,
171
+ selectedMonth: selectedMonth
172
+ }));
173
+ setSelectedState(nextState);
174
+ setSelectionRange(nextState.selectionStart, nextState.selectionEnd);
175
+
176
+ // If the field is full value, move the cursor to the next field
177
+ if ((0, _DateInput.isFieldFullValue)(formatStr, newValue, pattern) && input.selectionEnd !== input.value.length) {
178
+ onSegmentChange(event, 'right');
179
+ }
180
+ });
181
+ var onSegmentValueRemove = (0, _utils.useEventCallback)(function (event) {
182
+ var input = event.target;
183
+ if (selectedState.selectedPattern) {
184
+ var nextState = (0, _utils2.getInputSelectedState)((0, _extends2.default)({}, keyPressOptions, {
185
+ input: input,
186
+ valueOffset: null
187
+ }));
188
+ setSelectedState(nextState);
189
+ setSelectionRange(nextState.selectionStart, nextState.selectionEnd);
190
+ getActiveState().setDateField(selectedState.selectedPattern, null, function (date) {
191
+ return handleChange(date, event);
192
+ });
193
+ }
194
+ });
195
+ var handleClick = (0, _utils.useEventCallback)(function (event) {
196
+ var input = event.target;
197
+ if (input.selectionStart === null) {
198
+ return;
199
+ }
200
+ var cursorIndex = input.selectionStart === renderedValue.length ? 0 : input.selectionStart;
201
+ var dateType = (0, _utils2.getDateType)(renderedValue, character, cursorIndex);
202
+ var state = (0, _utils2.getInputSelectedState)((0, _extends2.default)({}, keyPressOptions, {
203
+ dateType: dateType,
204
+ selectedMonth: getActiveState(dateType).dateField.month,
205
+ input: input
206
+ }));
207
+ setDateType(dateType);
208
+ setSelectedState(state);
209
+ setSelectionRange(state.selectionStart, state.selectionEnd);
210
+ });
211
+ var onKeyboardInput = (0, _DateInput.useKeyboardInputEvent)({
212
+ onSegmentChange: onSegmentChange,
213
+ onSegmentValueChange: onSegmentValueChange,
214
+ onSegmentValueChangeWithNumericKeys: onSegmentValueChangeWithNumericKeys,
215
+ onSegmentValueRemove: onSegmentValueRemove,
216
+ onKeyDown: onKeyDown
217
+ });
218
+ return /*#__PURE__*/_react.default.createElement(_Input.default, (0, _extends2.default)({
219
+ inputMode: focused ? 'numeric' : 'text',
220
+ autoComplete: "off",
221
+ autoCorrect: "off",
222
+ spellCheck: false,
223
+ className: classes,
224
+ ref: (0, _utils.mergeRefs)(inputRef, ref),
225
+ onKeyDown: onKeyboardInput,
226
+ onClick: handleClick,
227
+ value: renderedValue,
228
+ placeholder: placeholder || rangeFormatStr
229
+ }, focusEventProps, rest));
230
+ });
231
+ DateRangeInput.displayName = 'DateRangeInput';
232
+ DateRangeInput.propTypes = {
233
+ character: _propTypes.default.string,
234
+ className: _propTypes.default.string,
235
+ classPrefix: _propTypes.default.string,
236
+ format: _propTypes.default.string,
237
+ placeholder: _propTypes.default.string,
238
+ onChange: _propTypes.default.func,
239
+ onKeyDown: _propTypes.default.func,
240
+ onFocus: _propTypes.default.func,
241
+ onBlur: _propTypes.default.func
242
+ };
243
+ var _default = DateRangeInput;
244
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import DateRangeInput from './DateRangeInput';
2
+ export type { DateRangeInputProps } from './DateRangeInput';
3
+ export default DateRangeInput;
@@ -0,0 +1,9 @@
1
+ 'use client';
2
+ "use strict";
3
+
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
+ exports.__esModule = true;
6
+ exports.default = void 0;
7
+ var _DateRangeInput = _interopRequireDefault(require("./DateRangeInput"));
8
+ var _default = _DateRangeInput.default;
9
+ exports.default = _default;
@@ -0,0 +1,61 @@
1
+ import { type Locale } from 'date-fns';
2
+ export declare enum DateType {
3
+ Start = "Start",
4
+ End = "End"
5
+ }
6
+ interface SelectedStateOptions {
7
+ /**
8
+ * The input element
9
+ */
10
+ input: HTMLInputElement;
11
+ /**
12
+ * The direction of the arrow key, left or right
13
+ */
14
+ direction?: 'left' | 'right';
15
+ /**
16
+ * Format of the string is based on Unicode Technical Standard.
17
+ * @see https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
18
+ */
19
+ formatStr: string;
20
+ /**
21
+ * The format string of the range, which is used to calculate the selection range.
22
+ */
23
+ rangeFormatStr: string;
24
+ /**
25
+ * The locale object, date-fns locale object
26
+ */
27
+ localize: Locale['localize'];
28
+ /**
29
+ * The selected month, used to calculate the offset of the character selection range
30
+ */
31
+ selectedMonth: number | null;
32
+ /**
33
+ * The offset of the value, which is used to calculate the month.
34
+ * This value will be changed when pressing the up and down arrow keys.
35
+ */
36
+ valueOffset?: number | null;
37
+ /**
38
+ * The date is rendered in string format according to format
39
+ */
40
+ dateString: string;
41
+ /**
42
+ * The character that separates two dates
43
+ *
44
+ * Only for `DateRangeInput`
45
+ **/
46
+ character: string;
47
+ /**
48
+ * The date type, start or end
49
+ *
50
+ * Only for `DateRangeInput`
51
+ */
52
+ dateType: DateType;
53
+ }
54
+ export declare function getInputSelectedState(options: SelectedStateOptions): {
55
+ selectionStart: number;
56
+ selectionEnd: number;
57
+ selectedPattern: string;
58
+ };
59
+ export declare function getDateType(dateString: string, character: string, cursorIndex: number): DateType;
60
+ export declare function isSwitchDateType(dateString: string, character: string, cursorIndex: number, direction: 'right' | 'left'): boolean;
61
+ export {};
@@ -0,0 +1,146 @@
1
+ 'use client';
2
+ "use strict";
3
+
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
+ exports.__esModule = true;
6
+ exports.getInputSelectedState = getInputSelectedState;
7
+ exports.getDateType = getDateType;
8
+ exports.isSwitchDateType = isSwitchDateType;
9
+ exports.DateType = void 0;
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+ var _DateInput = require("../DateInput");
12
+ var DateType;
13
+ exports.DateType = DateType;
14
+ (function (DateType) {
15
+ DateType["Start"] = "Start";
16
+ DateType["End"] = "End";
17
+ })(DateType || (exports.DateType = DateType = {}));
18
+ function getInputSelectedState(options) {
19
+ var input = options.input,
20
+ direction = options.direction,
21
+ formatStr = options.formatStr,
22
+ rangeFormatStr = options.rangeFormatStr,
23
+ localize = options.localize,
24
+ selectedMonth = options.selectedMonth,
25
+ _options$valueOffset = options.valueOffset,
26
+ valueOffset = _options$valueOffset === void 0 ? 0 : _options$valueOffset,
27
+ character = options.character,
28
+ dateType = options.dateType,
29
+ dateString = options.dateString;
30
+ var getPatternSelectedIndexes = function getPatternSelectedIndexes(pattern) {
31
+ var selectionStart = 0;
32
+ var selectionEnd = 0;
33
+ if (dateType === DateType.Start) {
34
+ selectionStart = rangeFormatStr.indexOf(pattern);
35
+ selectionEnd = rangeFormatStr.split(character)[0].lastIndexOf(pattern) + 1;
36
+ } else if (dateType === DateType.End) {
37
+ var position = rangeFormatStr.indexOf(character) + character.length;
38
+ selectionStart = rangeFormatStr.indexOf(pattern, position);
39
+ selectionEnd = rangeFormatStr.lastIndexOf(pattern) + 1;
40
+ }
41
+ var endDateGap = dateString.indexOf(character) - rangeFormatStr.indexOf(character);
42
+
43
+ // If the date type is end, and the end date is not selected, the selection range needs to be adjusted.
44
+ if (dateType === DateType.End && endDateGap > 0) {
45
+ selectionStart += endDateGap;
46
+ selectionEnd += endDateGap;
47
+ }
48
+ var gap = (0, _DateInput.getSelectIndexGap)({
49
+ pattern: pattern,
50
+ formatStr: formatStr,
51
+ valueOffset: valueOffset,
52
+ selectedMonth: selectedMonth,
53
+ localize: localize
54
+ });
55
+ var isSelectedMonth = pattern === 'M';
56
+ var isNullMonth = selectedMonth === null && !(isSelectedMonth && valueOffset !== 0);
57
+
58
+ // If the month is null and the valueOffset is 0, the month will not be updated, and the gap is 0 at this time.
59
+ if (isNullMonth) {
60
+ return {
61
+ selectionStart: selectionStart,
62
+ selectionEnd: selectionEnd
63
+ };
64
+ }
65
+ if (isSelectedMonth) {
66
+ return {
67
+ selectionStart: selectionStart,
68
+ selectionEnd: selectionEnd + gap
69
+ };
70
+ }
71
+ if ((0, _DateInput.isCursorAfterMonth)(selectionStart, formatStr)) {
72
+ return {
73
+ selectionStart: selectionStart + gap,
74
+ selectionEnd: selectionEnd + gap
75
+ };
76
+ }
77
+ return {
78
+ selectionStart: selectionStart,
79
+ selectionEnd: selectionEnd
80
+ };
81
+ };
82
+ if (typeof input.selectionEnd === 'number' && typeof input.selectionStart === 'number') {
83
+ var index = input.selectionStart;
84
+ var positionOffset = -1;
85
+ if (direction === 'left') {
86
+ index = input.selectionStart - 1;
87
+ } else if (direction === 'right') {
88
+ index = input.selectionEnd + 1;
89
+ positionOffset = 1;
90
+ }
91
+
92
+ // The start position of the index of the end date
93
+ var endDateIndex = dateString.indexOf(character) + character.length;
94
+ var datePattern = (0, _DateInput.getDatePattern)({
95
+ selectionIndex: dateType === DateType.End ? index - endDateIndex : index,
96
+ positionOffset: positionOffset,
97
+ formatStr: formatStr,
98
+ dateString: dateString,
99
+ valueOffset: valueOffset,
100
+ selectedMonth: selectedMonth,
101
+ localize: localize
102
+ });
103
+ var indexes = getPatternSelectedIndexes(datePattern);
104
+ return (0, _extends2.default)({
105
+ selectedPattern: datePattern
106
+ }, indexes);
107
+ }
108
+ return {
109
+ selectedPattern: 'y',
110
+ selectionStart: 0,
111
+ selectionEnd: 0
112
+ };
113
+ }
114
+ function getDateType(dateString, character, cursorIndex) {
115
+ var splitIndex = dateString.indexOf(character);
116
+ if (cursorIndex > splitIndex) {
117
+ return DateType.End;
118
+ }
119
+ return DateType.Start;
120
+ }
121
+ function isSwitchDateType(dateString, character, cursorIndex, direction) {
122
+ var characterIndex = dateString.indexOf(character);
123
+ var startIndex = cursorIndex;
124
+ var endIndex = startIndex + character.length;
125
+ if (direction === 'left') {
126
+ endIndex = cursorIndex;
127
+ startIndex = endIndex - character.length;
128
+ }
129
+
130
+ // Check whether the cursor is a separator before and after
131
+ if (dateString.substring(startIndex, endIndex) === character) {
132
+ return true;
133
+ }
134
+
135
+ // Check whether the cursor is a number or letter before and after. If not, switch the date type.
136
+ // eg: `2020年12月01日`, the cursor is behind 01, press the right key, and switch to the end date.
137
+ if (direction === 'right') {
138
+ if (!dateString.substring(cursorIndex, characterIndex).match(/[0-9a-zA-Z]/)) {
139
+ return true;
140
+ }
141
+ }
142
+ if (!dateString.substring(characterIndex, cursorIndex).match(/[0-9a-zA-Z]/)) {
143
+ return true;
144
+ }
145
+ return false;
146
+ }