rsuite 5.28.3 → 5.29.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [5.29.0](https://github.com/rsuite/rsuite/compare/v5.28.3...v5.29.0) (2023-03-24)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **Affix:** fix misalignment due to DOM content updates ([#3124](https://github.com/rsuite/rsuite/issues/3124)) ([76d21e9](https://github.com/rsuite/rsuite/commit/76d21e9e950da8c2df52d1fbc96abcada633d908))
6
+ - **Picker:** fix async container update cause offset error ([#3126](https://github.com/rsuite/rsuite/issues/3126)) ([c3e15c5](https://github.com/rsuite/rsuite/commit/c3e15c512319b0240236e35a5b28432bea1d25f3))
7
+
1
8
  ## [5.28.3](https://github.com/rsuite/rsuite/compare/v5.28.2...v5.28.3) (2023-03-17)
2
9
 
3
10
  ### Bug Fixes
@@ -1,11 +1,13 @@
1
- import { RsRefForwardingComponent, WithAsProps } from '../@types/common';
1
+ import { Offset, RsRefForwardingComponent, WithAsProps } from '../@types/common';
2
2
  export interface AffixProps extends WithAsProps {
3
+ /** Specify the container. */
4
+ container?: HTMLElement | (() => HTMLElement);
3
5
  /** Distance from top */
4
6
  top?: number;
5
7
  /** Callback after the state changes. */
6
8
  onChange?: (fixed?: boolean) => void;
7
- /** Specify the container. */
8
- container?: HTMLElement | (() => HTMLElement);
9
+ /** Callback after the offset changes. */
10
+ onOffsetChange?: (offset?: Offset) => void;
9
11
  }
10
12
  declare const Affix: RsRefForwardingComponent<'div', AffixProps>;
11
13
  export default Affix;
@@ -15,6 +15,8 @@ var _react = _interopRequireWildcard(require("react"));
15
15
 
16
16
  var _propTypes = _interopRequireDefault(require("prop-types"));
17
17
 
18
+ var _debounce = _interopRequireDefault(require("lodash/debounce"));
19
+
18
20
  var _getOffset = _interopRequireDefault(require("dom-lib/getOffset"));
19
21
 
20
22
  var _utils = require("../utils");
@@ -22,14 +24,26 @@ var _utils = require("../utils");
22
24
  /**
23
25
  * Get the layout size and offset of the mount element
24
26
  */
25
- function useOffset(mountRef) {
27
+ function useOffset(mountRef, onOffsetChange) {
26
28
  var _useState = (0, _react.useState)(null),
27
29
  offset = _useState[0],
28
30
  setOffset = _useState[1];
29
31
 
30
32
  var updateOffset = (0, _react.useCallback)(function () {
31
- setOffset((0, _getOffset.default)(mountRef.current));
32
- }, [mountRef]); // Update after the element size changes
33
+ if (!mountRef.current) {
34
+ return;
35
+ }
36
+
37
+ var newOffset = (0, _getOffset.default)(mountRef.current);
38
+
39
+ if ((newOffset === null || newOffset === void 0 ? void 0 : newOffset.height) !== (offset === null || offset === void 0 ? void 0 : offset.height) || (newOffset === null || newOffset === void 0 ? void 0 : newOffset.width) !== (offset === null || offset === void 0 ? void 0 : offset.width) || (newOffset === null || newOffset === void 0 ? void 0 : newOffset.top) !== (offset === null || offset === void 0 ? void 0 : offset.top) || (newOffset === null || newOffset === void 0 ? void 0 : newOffset.left) !== (offset === null || offset === void 0 ? void 0 : offset.left)) {
40
+ setOffset(newOffset);
41
+
42
+ if (offset !== null && newOffset !== null) {
43
+ onOffsetChange === null || onOffsetChange === void 0 ? void 0 : onOffsetChange(newOffset);
44
+ }
45
+ }
46
+ }, [mountRef, offset, onOffsetChange]); // Update after the element size changes
33
47
 
34
48
  (0, _utils.useElementResize)(function () {
35
49
  return mountRef.current;
@@ -37,7 +51,9 @@ function useOffset(mountRef) {
37
51
 
38
52
  (0, _utils.useMount)(updateOffset); // Update after window size changes
39
53
 
40
- (0, _utils.useEventListener)(window, 'resize', updateOffset, false);
54
+ (0, _utils.useEventListener)(window, 'resize', updateOffset, false); // Update after window scroll
55
+
56
+ (0, _utils.useEventListener)(window, 'scroll', (0, _debounce.default)(updateOffset, 100), false);
41
57
  return offset;
42
58
  }
43
59
  /**
@@ -80,7 +96,7 @@ function useFixed(offset, containerOffset, props) {
80
96
 
81
97
  var scrollY = window.scrollY || window.pageYOffset; // When the scroll distance exceeds the element's top value, it is fixed.
82
98
 
83
- var nextFixed = scrollY - (Number(offset.top) - Number(top)) >= 0; // If the current element is specified in the container,
99
+ var nextFixed = scrollY - (Number(offset === null || offset === void 0 ? void 0 : offset.top) - Number(top)) >= 0; // If the current element is specified in the container,
84
100
  // add to determine whether the current container is in the window range.
85
101
 
86
102
  if (containerOffset) {
@@ -91,7 +107,7 @@ function useFixed(offset, containerOffset, props) {
91
107
  setFixed(nextFixed);
92
108
  onChange === null || onChange === void 0 ? void 0 : onChange(nextFixed);
93
109
  }
94
- }, [fixed, offset, containerOffset, onChange, top]); // Add scroll event to window
110
+ }, [offset, top, containerOffset, fixed, onChange]); // Add scroll event to window
95
111
 
96
112
  (0, _utils.useEventListener)(window, 'scroll', handleScroll, false);
97
113
  return fixed;
@@ -110,9 +126,10 @@ var Affix = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
110
126
  _props$top = props.top,
111
127
  top = _props$top === void 0 ? 0 : _props$top,
112
128
  onChange = props.onChange,
113
- rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "classPrefix", "className", "children", "container", "top", "onChange"]);
129
+ onOffsetChange = props.onOffsetChange,
130
+ rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "classPrefix", "className", "children", "container", "top", "onChange", "onOffsetChange"]);
114
131
  var mountRef = (0, _react.useRef)(null);
115
- var offset = useOffset(mountRef);
132
+ var offset = useOffset(mountRef, onOffsetChange);
116
133
  var containerOffset = useContainerOffset(container);
117
134
  var fixed = useFixed(offset, containerOffset, {
118
135
  top: top,
@@ -124,14 +141,19 @@ var Affix = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
124
141
  merge = _useClassNames.merge;
125
142
 
126
143
  var classes = merge(className, (_merge = {}, _merge[withClassPrefix()] = fixed, _merge));
144
+
145
+ var _ref = offset || {},
146
+ width = _ref.width,
147
+ height = _ref.height;
148
+
127
149
  var placeholderStyles = fixed ? {
128
- width: offset === null || offset === void 0 ? void 0 : offset.width,
129
- height: offset === null || offset === void 0 ? void 0 : offset.height
150
+ width: width,
151
+ height: height
130
152
  } : undefined;
131
153
  var fixedStyles = {
132
154
  position: 'fixed',
133
155
  top: top,
134
- width: offset === null || offset === void 0 ? void 0 : offset.width,
156
+ width: width,
135
157
  zIndex: 10
136
158
  };
137
159
  var affixStyles = fixed ? fixedStyles : undefined;
@@ -33,14 +33,45 @@ export interface DatePickerProps extends PickerBaseProps<DatePickerLocale>, Form
33
33
  * Whether to disable a date on the calendar view
34
34
  *
35
35
  * @returns date should be disabled (not selectable)
36
+ * @deprecated Use {@link shouldDisableDate} instead
36
37
  */
37
38
  disabledDate?: (date?: Date) => boolean;
38
- /** Disabled hours */
39
+ /**
40
+ * Disabled hours
41
+ *
42
+ * @deprecated Use {@link shouldDisableHour} instead
43
+ */
39
44
  disabledHours?: (hour: number, date: Date) => boolean;
40
- /** Disabled minutes */
45
+ /**
46
+ * Disabled minutes
47
+ *
48
+ * @deprecated Use {@link shouldDisableMinute} instead
49
+ */
41
50
  disabledMinutes?: (minute: number, date: Date) => boolean;
42
- /** Disabled seconds */
51
+ /**
52
+ * Disabled seconds
53
+ *
54
+ * @deprecated Use {@link shouldDisableSecond} instead
55
+ */
43
56
  disabledSeconds?: (second: number, date: Date) => boolean;
57
+ /**
58
+ * Whether a date on the calendar view should be disabled
59
+ *
60
+ * @returns date should be disabled (not selectable)
61
+ */
62
+ shouldDisableDate?: (date: Date) => boolean;
63
+ /**
64
+ * Disabled hours
65
+ */
66
+ shouldDisableHour?: (hour: number, date: Date) => boolean;
67
+ /**
68
+ * Disabled minutes
69
+ */
70
+ shouldDisableMinute?: (minute: number, date: Date) => boolean;
71
+ /**
72
+ * Disabled seconds
73
+ */
74
+ shouldDisableSecond?: (second: number, date: Date) => boolean;
44
75
  /** Hidden hours */
45
76
  hideHours?: (hour: number, date: Date) => boolean;
46
77
  /** Hidden minutes */
@@ -43,6 +43,8 @@ var _Picker = require("../Picker");
43
43
 
44
44
  var _OverlayTrigger = require("../Overlay/OverlayTrigger");
45
45
 
46
+ var _deprecatePropType = require("../utils/deprecatePropType");
47
+
46
48
  var DatePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
47
49
  var _props$as = props.as,
48
50
  Component = _props$as === void 0 ? 'div' : _props$as,
@@ -77,7 +79,14 @@ var DatePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
77
79
  style = props.style,
78
80
  toggleAs = props.toggleAs,
79
81
  caretAsProp = props.caretAs,
80
- disabledDateProp = props.disabledDate,
82
+ DEPRECATED_disabledDate = props.disabledDate,
83
+ DEPRECATED_disabledHours = props.disabledHours,
84
+ DEPRECATED_disabledMinutes = props.disabledMinutes,
85
+ DEPRECATED_disabledSeconds = props.disabledSeconds,
86
+ shouldDisableDate = props.shouldDisableDate,
87
+ shouldDisableHour = props.shouldDisableHour,
88
+ shouldDisableMinute = props.shouldDisableMinute,
89
+ shouldDisableSecond = props.shouldDisableSecond,
81
90
  renderValue = props.renderValue,
82
91
  onChange = props.onChange,
83
92
  onChangeCalendarDate = props.onChangeCalendarDate,
@@ -92,7 +101,7 @@ var DatePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
92
101
  onSelect = props.onSelect,
93
102
  onToggleMonthDropdown = props.onToggleMonthDropdown,
94
103
  onToggleTimeDropdown = props.onToggleTimeDropdown,
95
- rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "className", "classPrefix", "calendarDefaultDate", "cleanable", "editable", "defaultValue", "disabled", "format", "isoWeek", "limitEndYear", "locale", "menuClassName", "appearance", "placement", "oneTap", "placeholder", "ranges", "value", "showMeridian", "showWeekNumbers", "style", "toggleAs", "caretAs", "disabledDate", "renderValue", "onChange", "onChangeCalendarDate", "onClean", "onClose", "onEntered", "onExited", "onNextMonth", "onOk", "onOpen", "onPrevMonth", "onSelect", "onToggleMonthDropdown", "onToggleTimeDropdown"]);
104
+ rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "className", "classPrefix", "calendarDefaultDate", "cleanable", "editable", "defaultValue", "disabled", "format", "isoWeek", "limitEndYear", "locale", "menuClassName", "appearance", "placement", "oneTap", "placeholder", "ranges", "value", "showMeridian", "showWeekNumbers", "style", "toggleAs", "caretAs", "disabledDate", "disabledHours", "disabledMinutes", "disabledSeconds", "shouldDisableDate", "shouldDisableHour", "shouldDisableMinute", "shouldDisableSecond", "renderValue", "onChange", "onChangeCalendarDate", "onClean", "onClose", "onEntered", "onExited", "onNextMonth", "onOk", "onOpen", "onPrevMonth", "onSelect", "onToggleMonthDropdown", "onToggleTimeDropdown"]);
96
105
 
97
106
  var _useCustom = (0, _utils.useCustom)('DatePicker', overrideLocale),
98
107
  locale = _useCustom.locale,
@@ -271,11 +280,17 @@ var DatePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
271
280
  updateValue(event, nextPageDate);
272
281
  }
273
282
  }, [formatStr, handleDateChange, oneTap, setCalendarDate, updateValue]);
274
- var disabledDate = (0, _react.useCallback)(function (date) {
275
- var _disabledDateProp;
283
+ var isDateDisabled = (0, _react.useCallback)(function (date) {
284
+ if (typeof shouldDisableDate === 'function') {
285
+ return shouldDisableDate(date);
286
+ }
287
+
288
+ if (typeof DEPRECATED_disabledDate === 'function') {
289
+ return DEPRECATED_disabledDate(date);
290
+ }
276
291
 
277
- return (_disabledDateProp = disabledDateProp === null || disabledDateProp === void 0 ? void 0 : disabledDateProp(date)) !== null && _disabledDateProp !== void 0 ? _disabledDateProp : false;
278
- }, [disabledDateProp]);
292
+ return false;
293
+ }, [DEPRECATED_disabledDate, shouldDisableDate]);
279
294
  /**
280
295
  * Callback after the input box value is changed.
281
296
  */
@@ -302,13 +317,13 @@ var DatePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
302
317
  return;
303
318
  }
304
319
 
305
- if (disabledDate(date)) {
320
+ if (isDateDisabled(date)) {
306
321
  setInputState('Error');
307
322
  return;
308
323
  }
309
324
 
310
325
  handleSelect(date, event, false);
311
- }, [formatStr, locale, parseDate, disabledDate, handleSelect]);
326
+ }, [formatStr, locale, parseDate, isDateDisabled, handleSelect]);
312
327
  /**
313
328
  * The callback after the enter key is triggered on the input
314
329
  */
@@ -330,14 +345,14 @@ var DatePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
330
345
  }, [onClose]); // Check whether the time is within the time range of the shortcut option in the toolbar.
331
346
 
332
347
  var disabledToolbarHandle = (0, _react.useCallback)(function (date) {
333
- var _disabledDateProp2;
348
+ var _DEPRECATED_disabledD;
334
349
 
335
- var allowDate = (_disabledDateProp2 = disabledDateProp === null || disabledDateProp === void 0 ? void 0 : disabledDateProp(date)) !== null && _disabledDateProp2 !== void 0 ? _disabledDateProp2 : false;
350
+ var allowDate = (_DEPRECATED_disabledD = DEPRECATED_disabledDate === null || DEPRECATED_disabledDate === void 0 ? void 0 : DEPRECATED_disabledDate(date)) !== null && _DEPRECATED_disabledD !== void 0 ? _DEPRECATED_disabledD : false;
336
351
 
337
352
  var allowTime = _utils.DateUtils.disabledTime(props, date);
338
353
 
339
354
  return allowDate || allowTime;
340
- }, [disabledDateProp, props]);
355
+ }, [DEPRECATED_disabledDate, props]);
341
356
  /**
342
357
  * Whether "OK" button is disabled
343
358
  *
@@ -369,7 +384,10 @@ var DatePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
369
384
  locale: locale,
370
385
  showWeekNumbers: showWeekNumbers,
371
386
  showMeridian: showMeridian,
372
- disabledDate: disabledDate,
387
+ disabledDate: isDateDisabled,
388
+ disabledHours: shouldDisableHour !== null && shouldDisableHour !== void 0 ? shouldDisableHour : DEPRECATED_disabledHours,
389
+ disabledMinutes: shouldDisableMinute !== null && shouldDisableMinute !== void 0 ? shouldDisableMinute : DEPRECATED_disabledMinutes,
390
+ disabledSeconds: shouldDisableSecond !== null && shouldDisableSecond !== void 0 ? shouldDisableSecond : DEPRECATED_disabledSeconds,
373
391
  limitEndYear: limitEndYear,
374
392
  format: formatStr,
375
393
  isoWeek: isoWeek,
@@ -503,10 +521,14 @@ DatePicker.displayName = 'DatePicker';
503
521
  DatePicker.propTypes = (0, _extends2.default)({}, _Picker.pickerPropTypes, {
504
522
  calendarDefaultDate: _propTypes.default.instanceOf(Date),
505
523
  defaultValue: _propTypes.default.instanceOf(Date),
506
- disabledDate: _propTypes.default.func,
507
- disabledHours: _propTypes.default.func,
508
- disabledMinutes: _propTypes.default.func,
509
- disabledSeconds: _propTypes.default.func,
524
+ disabledDate: (0, _deprecatePropType.deprecatePropTypeNew)(_propTypes.default.func, 'Use "shouldDisableDate" property instead.'),
525
+ disabledHours: (0, _deprecatePropType.deprecatePropTypeNew)(_propTypes.default.func, 'Use "shouldDisableHour" property instead.'),
526
+ disabledMinutes: (0, _deprecatePropType.deprecatePropTypeNew)(_propTypes.default.func, 'Use "shouldDisableMinute" property instead.'),
527
+ disabledSeconds: (0, _deprecatePropType.deprecatePropTypeNew)(_propTypes.default.func, 'Use "shouldDisableSecond" property instead.'),
528
+ shouldDisableDate: _propTypes.default.func,
529
+ shouldDisableHour: _propTypes.default.func,
530
+ shouldDisableMinute: _propTypes.default.func,
531
+ shouldDisableSecond: _propTypes.default.func,
510
532
  format: _propTypes.default.string,
511
533
  hideHours: _propTypes.default.func,
512
534
  hideMinutes: _propTypes.default.func,
@@ -27,8 +27,16 @@ export interface DateRangePickerProps extends PickerBaseProps, FormControlBasePr
27
27
  defaultCalendarValue?: DateRange;
28
28
  /** The character that separates two dates */
29
29
  character?: string;
30
- /** Disabled date */
30
+ /**
31
+ * Disabled date
32
+ *
33
+ * @deprecated Use {@link shouldDisableDate} instead
34
+ */
31
35
  disabledDate?: DisabledDateFunction;
36
+ /**
37
+ * Whether a date cell is disabled
38
+ */
39
+ shouldDisableDate?: DisabledDateFunction;
32
40
  /** Called when the option is selected */
33
41
  onSelect?: (date: Date, event?: React.SyntheticEvent) => void;
34
42
  /** Called after clicking the OK button */
@@ -45,6 +45,8 @@ var disabledDateUtils = _interopRequireWildcard(require("./disabledDateUtils"));
45
45
 
46
46
  var _utils2 = require("./utils");
47
47
 
48
+ var _deprecatePropType = require("../utils/deprecatePropType");
49
+
48
50
  var DateRangePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
49
51
  var _ref, _ref2, _merge;
50
52
 
@@ -64,7 +66,8 @@ var DateRangePicker = /*#__PURE__*/_react.default.forwardRef(function (props, re
64
66
  defaultCalendarValue = props.defaultCalendarValue,
65
67
  defaultValue = props.defaultValue,
66
68
  disabled = props.disabled,
67
- disabledDateProp = props.disabledDate,
69
+ DEPRECATED_disabledDateProp = props.disabledDate,
70
+ shouldDisableDate = props.shouldDisableDate,
68
71
  _props$format = props.format,
69
72
  formatStr = _props$format === void 0 ? 'yyyy-MM-dd' : _props$format,
70
73
  hoverRange = props.hoverRange,
@@ -100,7 +103,7 @@ var DateRangePicker = /*#__PURE__*/_react.default.forwardRef(function (props, re
100
103
  onOpen = props.onOpen,
101
104
  onSelect = props.onSelect,
102
105
  renderTitle = props.renderTitle,
103
- rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "classPrefix", "className", "appearance", "editable", "cleanable", "character", "defaultCalendarValue", "defaultValue", "disabled", "disabledDate", "format", "hoverRange", "isoWeek", "limitEndYear", "locale", "menuClassName", "menuStyle", "oneTap", "placeholder", "placement", "ranges", "renderValue", "showOneCalendar", "showWeekNumbers", "showMeridian", "style", "toggleAs", "caretAs", "value", "onChange", "onClean", "onClose", "onEnter", "onEntered", "onExited", "onOk", "onOpen", "onSelect", "renderTitle"]);
106
+ rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "classPrefix", "className", "appearance", "editable", "cleanable", "character", "defaultCalendarValue", "defaultValue", "disabled", "disabledDate", "shouldDisableDate", "format", "hoverRange", "isoWeek", "limitEndYear", "locale", "menuClassName", "menuStyle", "oneTap", "placeholder", "placement", "ranges", "renderValue", "showOneCalendar", "showWeekNumbers", "showMeridian", "style", "toggleAs", "caretAs", "value", "onChange", "onClean", "onClose", "onEnter", "onEntered", "onExited", "onOk", "onOpen", "onSelect", "renderTitle"]);
104
107
 
105
108
  var _useClassNames = (0, _utils.useClassNames)(classPrefix),
106
109
  merge = _useClassNames.merge,
@@ -564,10 +567,16 @@ var DateRangePicker = /*#__PURE__*/_react.default.forwardRef(function (props, re
564
567
  onClose === null || onClose === void 0 ? void 0 : onClose();
565
568
  }, [onClose]);
566
569
  var isDateDisabled = (0, _react.useCallback)(function (date, selectDate, selectedDone, target) {
567
- var _disabledDateProp;
570
+ if (typeof shouldDisableDate === 'function') {
571
+ return shouldDisableDate(date, selectDate, selectedDone, target);
572
+ }
568
573
 
569
- return (_disabledDateProp = disabledDateProp === null || disabledDateProp === void 0 ? void 0 : disabledDateProp(date, selectDate, selectedDone, target)) !== null && _disabledDateProp !== void 0 ? _disabledDateProp : false;
570
- }, [disabledDateProp]);
574
+ if (typeof DEPRECATED_disabledDateProp === 'function') {
575
+ return DEPRECATED_disabledDateProp(date, selectDate, selectedDone, target);
576
+ }
577
+
578
+ return false;
579
+ }, [DEPRECATED_disabledDateProp, shouldDisableDate]);
571
580
  var disabledByBetween = (0, _react.useCallback)(function (start, end, type) {
572
581
  // If the date is between the start and the end
573
582
  // the button is disabled
@@ -760,7 +769,8 @@ DateRangePicker.propTypes = (0, _extends2.default)({}, _Picker.pickerPropTypes,
760
769
  limitEndYear: _propTypes.default.number,
761
770
  onChange: _propTypes.default.func,
762
771
  onOk: _propTypes.default.func,
763
- disabledDate: _propTypes.default.func,
772
+ disabledDate: (0, _deprecatePropType.deprecatePropTypeNew)(_propTypes.default.func, 'Use "shouldDisableDate" property instead.'),
773
+ shouldDisableDate: _propTypes.default.func,
764
774
  onSelect: _propTypes.default.func,
765
775
  showWeekNumbers: _propTypes.default.bool,
766
776
  showMeridian: _propTypes.default.bool,
@@ -19,8 +19,6 @@ var _classnames = _interopRequireDefault(require("classnames"));
19
19
 
20
20
  var _contains = _interopRequireDefault(require("dom-lib/contains"));
21
21
 
22
- var _getContainer = _interopRequireDefault(require("dom-lib/getContainer"));
23
-
24
22
  var _on = _interopRequireDefault(require("dom-lib/on"));
25
23
 
26
24
  var _ModalManager = _interopRequireDefault(require("./ModalManager"));
@@ -112,7 +110,8 @@ var Modal = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
112
110
  var _usePortal = (0, _utils2.usePortal)({
113
111
  container: container
114
112
  }),
115
- Portal = _usePortal.Portal;
113
+ Portal = _usePortal.Portal,
114
+ containerElement = _usePortal.target;
116
115
 
117
116
  var modal = useModalManager();
118
117
 
@@ -163,8 +162,9 @@ var Modal = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
163
162
  var documentKeyDownListener = (0, _react.useRef)();
164
163
  var documentFocusListener = (0, _react.useRef)();
165
164
  var handleOpen = (0, _utils2.useEventCallback)(function () {
166
- var containerElement = (0, _getContainer.default)(container, document.body);
167
- modal.add(containerElement, containerClassName);
165
+ if (containerElement) {
166
+ modal.add(containerElement, containerClassName);
167
+ }
168
168
 
169
169
  if (!documentKeyDownListener.current) {
170
170
  documentKeyDownListener.current = (0, _on.default)(document, 'keydown', handleDocumentKeyDown);
@@ -120,7 +120,8 @@ var OverlayTrigger = /*#__PURE__*/_react.default.forwardRef(function (props, ref
120
120
  var _usePortal = (0, _utils.usePortal)({
121
121
  container: container
122
122
  }),
123
- Portal = _usePortal.Portal;
123
+ Portal = _usePortal.Portal,
124
+ containerElement = _usePortal.target;
124
125
 
125
126
  var triggerRef = (0, _react.useRef)();
126
127
  var overlayRef = (0, _react.useRef)();
@@ -367,7 +368,7 @@ var OverlayTrigger = /*#__PURE__*/_react.default.forwardRef(function (props, ref
367
368
  }) : undefined,
368
369
  onExited: (0, _utils.createChainedFunction)(followCursor ? handleExited : undefined, onExited),
369
370
  placement: placement,
370
- container: container,
371
+ container: containerElement,
371
372
  open: open
372
373
  });
373
374
  var speakerProps = {
@@ -41,6 +41,7 @@ export declare type CalendarOnlyPropsType = 'disabledHours' | 'disabledMinutes'
41
41
  export declare const calendarOnlyProps: CalendarOnlyPropsType[];
42
42
  /**
43
43
  * Verify that the time is valid.
44
+ *
44
45
  * @param props
45
46
  * @param date
46
47
  */
@@ -181,15 +181,21 @@ function validTime(calendarProps, date) {
181
181
 
182
182
  return Object.keys(calendarProps).some(function (key) {
183
183
  if (/(Hours)/.test(key)) {
184
- return calendarProps[key]((0, _getHours.default)(date), date);
184
+ var _calendarProps$key, _calendarProps$key2;
185
+
186
+ return (_calendarProps$key = (_calendarProps$key2 = calendarProps[key]) === null || _calendarProps$key2 === void 0 ? void 0 : _calendarProps$key2.call(calendarProps, (0, _getHours.default)(date), date)) !== null && _calendarProps$key !== void 0 ? _calendarProps$key : true;
185
187
  }
186
188
 
187
189
  if (/(Minutes)/.test(key)) {
188
- return calendarProps[key]((0, _getMinutes.default)(date), date);
190
+ var _calendarProps$key3, _calendarProps$key4;
191
+
192
+ return (_calendarProps$key3 = (_calendarProps$key4 = calendarProps[key]) === null || _calendarProps$key4 === void 0 ? void 0 : _calendarProps$key4.call(calendarProps, (0, _getMinutes.default)(date), date)) !== null && _calendarProps$key3 !== void 0 ? _calendarProps$key3 : true;
189
193
  }
190
194
 
191
195
  if (/(Seconds)/.test(key)) {
192
- return calendarProps[key]((0, _getSeconds.default)(date), date);
196
+ var _calendarProps$key5, _calendarProps$key6;
197
+
198
+ return (_calendarProps$key5 = (_calendarProps$key6 = calendarProps[key]) === null || _calendarProps$key6 === void 0 ? void 0 : _calendarProps$key6.call(calendarProps, (0, _getSeconds.default)(date), date)) !== null && _calendarProps$key5 !== void 0 ? _calendarProps$key5 : true;
193
199
  }
194
200
 
195
201
  return false;
@@ -197,6 +203,7 @@ function validTime(calendarProps, date) {
197
203
  }
198
204
  /**
199
205
  * Verify that the time is valid.
206
+ *
200
207
  * @param props
201
208
  * @param date
202
209
  */
@@ -7,5 +7,10 @@ import * as PropTypes from 'prop-types';
7
7
  export default function deprecatePropType<T extends PropTypes.Validator<any>>(propType: T, explanation?: string): typeof propType;
8
8
  /**
9
9
  * Prints deprecation message when user uses a deprecated prop
10
+ *
11
+ * @example
12
+ *
13
+ * deprecatePropTypeNew(PropTypes.bool, 'Use Dropdown.Separator component instead.')
14
+ *
10
15
  */
11
16
  export declare function deprecatePropTypeNew<T extends PropTypes.Validator<any>>(propType: T, explanation?: string): typeof propType;
@@ -32,6 +32,11 @@ function deprecatePropType(propType, explanation) {
32
32
  }
33
33
  /**
34
34
  * Prints deprecation message when user uses a deprecated prop
35
+ *
36
+ * @example
37
+ *
38
+ * deprecatePropTypeNew(PropTypes.bool, 'Use Dropdown.Separator component instead.')
39
+ *
35
40
  */
36
41
 
37
42
 
@@ -43,24 +43,21 @@ function usePortal(props) {
43
43
  container = _props.container,
44
44
  _props$waitMount = _props.waitMount,
45
45
  waitMount = _props$waitMount === void 0 ? false : _props$waitMount;
46
- var rootElemRef = (0, _react.useRef)(_canUseDOM.default ? document.body : null);
47
- (0, _react.useEffect)(function () {
48
- var containerElement = typeof container === 'function' ? container() : container; // Parent is either a new root or the existing dom element
49
-
50
- var parentElement = containerElement || document.body;
51
- rootElemRef.current = parentElement;
52
- }, [rootElemRef, container]);
46
+ var containerElement = typeof container === 'function' ? container() : container;
47
+ var rootElement = (0, _react.useMemo)(function () {
48
+ return _canUseDOM.default ? containerElement || document.body : null;
49
+ }, [containerElement]);
53
50
  var Portal = (0, _react.useCallback)(function (_ref2) {
54
51
  var children = _ref2.children;
55
- return rootElemRef.current != null ? /*#__PURE__*/(0, _reactDom.createPortal)(children, rootElemRef.current) : null;
56
- }, []);
52
+ return rootElement != null ? /*#__PURE__*/(0, _reactDom.createPortal)(children, rootElement) : null;
53
+ }, [rootElement]);
57
54
  var WaitMountPortal = (0, _react.useCallback)(function (props) {
58
55
  return /*#__PURE__*/_react.default.createElement(MountedPortal, (0, _extends2.default)({
59
- container: rootElemRef.current
56
+ container: rootElement
60
57
  }, props));
61
- }, []);
58
+ }, [rootElement]);
62
59
  return {
63
- target: rootElemRef.current,
60
+ target: rootElement,
64
61
  Portal: waitMount ? WaitMountPortal : Portal
65
62
  };
66
63
  }