@zendeskgarden/react-datepickers 9.0.0-next.0 → 9.0.0-next.10

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 (55) hide show
  1. package/README.md +7 -7
  2. package/dist/esm/elements/DatePicker/DatePicker.js +169 -0
  3. package/dist/esm/elements/DatePicker/components/Calendar.js +125 -0
  4. package/dist/esm/elements/DatePicker/components/Input.js +75 -0
  5. package/dist/esm/elements/DatePicker/components/MonthSelector.js +61 -0
  6. package/dist/esm/elements/DatePicker/utils/date-picker-reducer.js +187 -0
  7. package/dist/esm/elements/DatePicker/utils/useDatePickerContext.js +14 -0
  8. package/dist/esm/elements/DatePickerRange/DatePickerRange.js +101 -0
  9. package/dist/esm/elements/DatePickerRange/components/Calendar.js +42 -0
  10. package/dist/esm/elements/DatePickerRange/components/End.js +79 -0
  11. package/dist/esm/elements/DatePickerRange/components/Month.js +270 -0
  12. package/dist/esm/elements/DatePickerRange/components/Start.js +79 -0
  13. package/dist/esm/elements/DatePickerRange/utils/date-picker-range-reducer.js +319 -0
  14. package/dist/esm/elements/DatePickerRange/utils/useDatePickerRangeContext.js +14 -0
  15. package/dist/esm/index.js +8 -0
  16. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/chevron-left-stroke.svg.js +25 -0
  17. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/chevron-right-stroke.svg.js +25 -0
  18. package/dist/esm/styled/StyledCalendar.js +21 -0
  19. package/dist/esm/styled/StyledCalendarItem.js +34 -0
  20. package/dist/esm/styled/StyledDatePicker.js +32 -0
  21. package/dist/esm/styled/StyledDay.js +54 -0
  22. package/dist/esm/styled/StyledDayLabel.js +21 -0
  23. package/dist/esm/styled/StyledHeader.js +21 -0
  24. package/dist/esm/styled/StyledHeaderLabel.js +21 -0
  25. package/dist/esm/styled/StyledHeaderPaddle.js +38 -0
  26. package/dist/esm/styled/StyledHighlight.js +50 -0
  27. package/dist/esm/styled/StyledMenu.js +22 -0
  28. package/dist/esm/styled/StyledMenuWrapper.js +27 -0
  29. package/dist/esm/styled/StyledRangeCalendar.js +22 -0
  30. package/dist/esm/types/index.js +12 -0
  31. package/dist/esm/utils/calendar-utils.js +88 -0
  32. package/dist/index.cjs.js +195 -238
  33. package/dist/typings/elements/{Datepicker/Datepicker.d.ts → DatePicker/DatePicker.d.ts} +2 -2
  34. package/dist/typings/elements/DatePicker/components/Input.d.ts +16 -0
  35. package/dist/typings/elements/{Datepicker/utils/datepicker-reducer.d.ts → DatePicker/utils/date-picker-reducer.d.ts} +6 -6
  36. package/dist/typings/elements/DatePicker/utils/useDatePickerContext.d.ts +18 -0
  37. package/dist/typings/elements/{DatepickerRange/DatepickerRange.d.ts → DatePickerRange/DatePickerRange.d.ts} +3 -3
  38. package/dist/typings/elements/{DatepickerRange/utils/datepicker-range-reducer.d.ts → DatePickerRange/utils/date-picker-range-reducer.d.ts} +6 -6
  39. package/dist/typings/elements/{DatepickerRange/utils/useDatepickerRangeContext.d.ts → DatePickerRange/utils/useDatePickerRangeContext.d.ts} +7 -7
  40. package/dist/typings/index.d.ts +3 -5
  41. package/dist/typings/styled/{StyledDatepicker.d.ts → StyledDatePicker.d.ts} +3 -3
  42. package/dist/typings/styled/StyledMenuWrapper.d.ts +2 -2
  43. package/dist/typings/styled/index.d.ts +1 -1
  44. package/dist/typings/types/index.d.ts +5 -14
  45. package/dist/typings/utils/calendar-utils.d.ts +2 -2
  46. package/package.json +8 -7
  47. package/dist/index.esm.js +0 -1714
  48. package/dist/typings/elements/Datepicker/utils/garden-placements.d.ts +0 -21
  49. package/dist/typings/elements/Datepicker/utils/useDatepickerContext.d.ts +0 -18
  50. /package/dist/typings/elements/{Datepicker → DatePicker}/components/Calendar.d.ts +0 -0
  51. /package/dist/typings/elements/{Datepicker → DatePicker}/components/MonthSelector.d.ts +0 -0
  52. /package/dist/typings/elements/{DatepickerRange → DatePickerRange}/components/Calendar.d.ts +0 -0
  53. /package/dist/typings/elements/{DatepickerRange → DatePickerRange}/components/End.d.ts +0 -0
  54. /package/dist/typings/elements/{DatepickerRange → DatePickerRange}/components/Month.d.ts +0 -0
  55. /package/dist/typings/elements/{DatepickerRange → DatePickerRange}/components/Start.d.ts +0 -0
package/dist/index.cjs.js CHANGED
@@ -1,17 +1,17 @@
1
1
  /**
2
- * Copyright Zendesk, Inc.
3
- *
4
- * Use of this source code is governed under the Apache License, Version 2.0
5
- * found at http://www.apache.org/licenses/LICENSE-2.0.
6
- */
7
-
2
+ * Copyright Zendesk, Inc.
3
+ *
4
+ * Use of this source code is governed under the Apache License, Version 2.0
5
+ * found at http://www.apache.org/licenses/LICENSE-2.0.
6
+ */
8
7
  'use strict';
9
8
 
10
9
  var React = require('react');
11
10
  var PropTypes = require('prop-types');
11
+ var reactMergeRefs = require('react-merge-refs');
12
12
  var styled = require('styled-components');
13
- var reactPopper = require('react-popper');
14
- var containerUtilities = require('@zendeskgarden/container-utilities');
13
+ var reactDom = require('@floating-ui/react-dom');
14
+ var reactTheming = require('@zendeskgarden/react-theming');
15
15
  var startOfMonth = require('date-fns/startOfMonth');
16
16
  var endOfMonth = require('date-fns/endOfMonth');
17
17
  var startOfWeek = require('date-fns/startOfWeek');
@@ -24,11 +24,11 @@ var isSameMonth = require('date-fns/isSameMonth');
24
24
  var isBefore = require('date-fns/isBefore');
25
25
  var isAfter = require('date-fns/isAfter');
26
26
  var getDate = require('date-fns/getDate');
27
- var reactTheming = require('@zendeskgarden/react-theming');
28
27
  var addMonths = require('date-fns/addMonths');
29
28
  var subMonths = require('date-fns/subMonths');
30
29
  var isValid = require('date-fns/isValid');
31
30
  var parse = require('date-fns/parse');
31
+ var containerUtilities = require('@zendeskgarden/container-utilities');
32
32
  var compareAsc = require('date-fns/compareAsc');
33
33
  var subDays = require('date-fns/subDays');
34
34
 
@@ -57,62 +57,12 @@ var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
57
57
  var styled__default = /*#__PURE__*/_interopDefault(styled);
58
58
 
59
59
  const WEEK_STARTS_ON = [0, 1, 2, 3, 4, 5, 6];
60
- const SHARED_PLACEMENT = ['auto', 'top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end'];
61
- const PLACEMENT = [...SHARED_PLACEMENT, 'end', 'end-top', 'end-bottom', 'start', 'start-top', 'start-bottom'];
62
-
63
- function getPopperPlacement(gardenPlacement) {
64
- switch (gardenPlacement) {
65
- case 'end':
66
- return 'right';
67
- case 'end-top':
68
- return 'right-start';
69
- case 'end-bottom':
70
- return 'right-end';
71
- case 'start':
72
- return 'left';
73
- case 'start-top':
74
- return 'left-start';
75
- case 'start-bottom':
76
- return 'left-end';
77
- default:
78
- return gardenPlacement;
79
- }
80
- }
81
- function getRtlPopperPlacement(gardenPlacement) {
82
- const popperPlacement = getPopperPlacement(gardenPlacement);
83
- switch (popperPlacement) {
84
- case 'left':
85
- return 'right';
86
- case 'left-start':
87
- return 'right-start';
88
- case 'left-end':
89
- return 'right-end';
90
- case 'top-start':
91
- return 'top-end';
92
- case 'top-end':
93
- return 'top-start';
94
- case 'right':
95
- return 'left';
96
- case 'right-start':
97
- return 'left-start';
98
- case 'right-end':
99
- return 'left-end';
100
- case 'bottom-start':
101
- return 'bottom-end';
102
- case 'bottom-end':
103
- return 'bottom-start';
104
- default:
105
- return popperPlacement;
106
- }
107
- }
108
- function getMenuPosition(popperPlacement) {
109
- return popperPlacement ? popperPlacement.split('-')[0] : 'bottom';
110
- }
60
+ const PLACEMENT = ['auto', ...reactTheming.PLACEMENT];
111
61
 
112
62
  const COMPONENT_ID$b = 'datepickers.menu';
113
63
  const StyledMenu = styled__default.default.div.attrs({
114
64
  'data-garden-id': COMPONENT_ID$b,
115
- 'data-garden-version': '9.0.0-next.0'
65
+ 'data-garden-version': '9.0.0-next.10'
116
66
  }).withConfig({
117
67
  displayName: "StyledMenu",
118
68
  componentId: "sc-1npbkk0-0"
@@ -127,7 +77,7 @@ const StyledMenuWrapper = styled__default.default.div.attrs(props => ({
127
77
  })).withConfig({
128
78
  displayName: "StyledMenuWrapper",
129
79
  componentId: "sc-6fowoz-0"
130
- })(["", ";", ";"], props => reactTheming.menuStyles(getMenuPosition(props.placement), {
80
+ })(["top:0;left:0;", ";", ";"], props => reactTheming.menuStyles(reactTheming.getMenuPosition(props.placement), {
131
81
  theme: props.theme,
132
82
  hidden: props.isHidden,
133
83
  margin: `${props.theme.space.base}px`,
@@ -150,13 +100,13 @@ const retrievePadding = _ref => {
150
100
  }
151
101
  return `margin: ${value}px;`;
152
102
  };
153
- const StyledDatepicker = styled__default.default.div.attrs({
103
+ const StyledDatePicker = styled__default.default.div.attrs({
154
104
  'data-garden-id': COMPONENT_ID$9
155
105
  }).withConfig({
156
- displayName: "StyledDatepicker",
157
- componentId: "sc-w3zqsp-0"
158
- })(["direction:", ";", " background-color:", ";color:", ";", ";"], props => props.theme.rtl && 'rtl', retrievePadding, props => props.theme.colors.background, props => props.theme.colors.foreground, props => reactTheming.retrieveComponentStyles(COMPONENT_ID$9, props));
159
- StyledDatepicker.defaultProps = {
106
+ displayName: "StyledDatePicker",
107
+ componentId: "sc-15hwqzh-0"
108
+ })(["direction:", ";", " background-color:", ";color:", ";", ";"], props => props.theme.rtl && 'rtl', retrievePadding, props => reactTheming.getColorV8('background', 600 , props.theme), props => reactTheming.getColorV8('foreground', 600 , props.theme), props => reactTheming.retrieveComponentStyles(COMPONENT_ID$9, props));
109
+ StyledDatePicker.defaultProps = {
160
110
  theme: reactTheming.DEFAULT_THEME
161
111
  };
162
112
 
@@ -166,7 +116,7 @@ const StyledRangeCalendar = styled__default.default.div.attrs({
166
116
  }).withConfig({
167
117
  displayName: "StyledRangeCalendar",
168
118
  componentId: "sc-1og46sy-0"
169
- })(["display:flex;overflow:auto;", "{margin:0;", "}", ";"], StyledDatepicker, props => props.theme.rtl ? `&:last-of-type {margin-right: ${props.theme.space.base * 5}px}` : `&:first-of-type {margin-right: ${props.theme.space.base * 5}px}`, props => reactTheming.retrieveComponentStyles(COMPONENT_ID$8, props));
119
+ })(["display:flex;overflow:auto;", "{margin:0;", "}", ";"], StyledDatePicker, props => props.theme.rtl ? `&:last-of-type {margin-right: ${props.theme.space.base * 5}px}` : `&:first-of-type {margin-right: ${props.theme.space.base * 5}px}`, props => reactTheming.retrieveComponentStyles(COMPONENT_ID$8, props));
170
120
  StyledRangeCalendar.defaultProps = {
171
121
  theme: reactTheming.DEFAULT_THEME
172
122
  };
@@ -197,7 +147,7 @@ const retrieveColor$1 = _ref2 => {
197
147
  let {
198
148
  theme
199
149
  } = _ref2;
200
- return styled.css([":hover{background-color:", ";color:", ";}:active{background-color:", ";color:", ";}color:", ";"], reactTheming.getColor('primaryHue', 600, theme, 0.08), theme.colors.foreground, reactTheming.getColor('primaryHue', 600, theme, 0.2), theme.colors.foreground, reactTheming.getColor('neutralHue', 600, theme));
150
+ return styled.css([":hover{background-color:", ";color:", ";}:active{background-color:", ";color:", ";}color:", ";"], reactTheming.getColorV8('primaryHue', 600, theme, 0.08), reactTheming.getColorV8('foreground', 600 , theme), reactTheming.getColorV8('primaryHue', 600, theme, 0.2), reactTheming.getColorV8('foreground', 600 , theme), reactTheming.getColorV8('neutralHue', 600, theme));
201
151
  };
202
152
  const COMPONENT_ID$6 = 'datepickers.header_paddle';
203
153
  const StyledHeaderPaddle = styled__default.default.div.attrs({
@@ -295,7 +245,7 @@ const retrieveColor = _ref2 => {
295
245
  isHighlighted,
296
246
  theme
297
247
  } = _ref2;
298
- return styled.css(["background-color:", ";"], isHighlighted && reactTheming.getColor('primaryHue', 600, theme, 0.08));
248
+ return styled.css(["background-color:", ";"], isHighlighted && reactTheming.getColorV8('primaryHue', 600, theme, 0.08));
299
249
  };
300
250
  const StyledHighlight = styled__default.default.div.attrs({
301
251
  'data-garden-id': COMPONENT_ID$1
@@ -316,26 +266,26 @@ const retrieveStyledDayColors = _ref => {
316
266
  theme
317
267
  } = _ref;
318
268
  let backgroundColor = 'inherit';
319
- let color = reactTheming.getColor('primaryHue', 600, theme);
269
+ let color = reactTheming.getColorV8('primaryHue', 600, theme);
320
270
  if (isSelected && !isDisabled) {
321
- backgroundColor = reactTheming.getColor('primaryHue', 600, theme);
322
- color = theme.colors.background;
271
+ backgroundColor = reactTheming.getColorV8('primaryHue', 600, theme);
272
+ color = reactTheming.getColorV8('background', 600 , theme);
323
273
  } else if (isDisabled) {
324
- color = reactTheming.getColor('neutralHue', 400, theme);
274
+ color = reactTheming.getColorV8('neutralHue', 400, theme);
325
275
  } else if (isToday) {
326
276
  color = 'inherit';
327
277
  } else if (isPreviousMonth) {
328
- color = reactTheming.getColor('neutralHue', 600, theme);
278
+ color = reactTheming.getColorV8('neutralHue', 600, theme);
329
279
  }
330
280
  return styled.css(["background-color:", ";color:", ";", ""], backgroundColor, color, !isSelected && !isDisabled && `
331
281
  :hover {
332
- background-color: ${reactTheming.getColor('primaryHue', 600, theme, 0.08)};
333
- color: ${reactTheming.getColor('primaryHue', 800, theme)};
282
+ background-color: ${reactTheming.getColorV8('primaryHue', 600, theme, 0.08)};
283
+ color: ${reactTheming.getColorV8('primaryHue', 800, theme)};
334
284
  }
335
285
 
336
286
  :active {
337
- background-color: ${reactTheming.getColor('primaryHue', 600, theme, 0.2)};
338
- color: ${reactTheming.getColor('primaryHue', 800, theme)};
287
+ background-color: ${reactTheming.getColorV8('primaryHue', 600, theme, 0.2)};
288
+ color: ${reactTheming.getColorV8('primaryHue', 800, theme)};
339
289
  }
340
290
  `);
341
291
  };
@@ -351,9 +301,9 @@ StyledDay.defaultProps = {
351
301
  theme: reactTheming.DEFAULT_THEME
352
302
  };
353
303
 
354
- const DatepickerContext = React.createContext(undefined);
355
- const useDatepickerContext$1 = () => {
356
- return React.useContext(DatepickerContext);
304
+ const DatePickerContext = React.createContext(undefined);
305
+ const useDatePickerContext$1 = () => {
306
+ return React.useContext(DatePickerContext);
357
307
  };
358
308
 
359
309
  const REGION_MAPPINGS = {
@@ -438,9 +388,9 @@ function getStartOfWeek(locale) {
438
388
  }
439
389
 
440
390
  var _path$1;
441
- function _extends$2() { _extends$2 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$2.apply(this, arguments); }
391
+ function _extends$1() { _extends$1 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$1.apply(this, arguments); }
442
392
  var SvgChevronLeftStroke = function SvgChevronLeftStroke(props) {
443
- return /*#__PURE__*/React__namespace.createElement("svg", _extends$2({
393
+ return /*#__PURE__*/React__namespace.createElement("svg", _extends$1({
444
394
  xmlns: "http://www.w3.org/2000/svg",
445
395
  width: 16,
446
396
  height: 16,
@@ -454,9 +404,9 @@ var SvgChevronLeftStroke = function SvgChevronLeftStroke(props) {
454
404
  };
455
405
 
456
406
  var _path;
457
- function _extends$1() { _extends$1 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$1.apply(this, arguments); }
407
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
458
408
  var SvgChevronRightStroke = function SvgChevronRightStroke(props) {
459
- return /*#__PURE__*/React__namespace.createElement("svg", _extends$1({
409
+ return /*#__PURE__*/React__namespace.createElement("svg", _extends({
460
410
  xmlns: "http://www.w3.org/2000/svg",
461
411
  width: 16,
462
412
  height: 16,
@@ -477,7 +427,7 @@ const MonthSelector = _ref => {
477
427
  const {
478
428
  state,
479
429
  dispatch
480
- } = useDatepickerContext$1();
430
+ } = useDatePickerContext$1();
481
431
  const headerLabelFormatter = React.useCallback(date => {
482
432
  const formatter = new Intl.DateTimeFormat(locale, {
483
433
  month: 'long',
@@ -518,7 +468,7 @@ const Calendar$1 = React.forwardRef((_ref, ref) => {
518
468
  const {
519
469
  state,
520
470
  dispatch
521
- } = useDatepickerContext$1();
471
+ } = useDatePickerContext$1();
522
472
  const preferredWeekStartsOn = weekStartsOn || getStartOfWeek(locale);
523
473
  const monthStartDate = startOfMonth.startOfMonth(state.previewDate);
524
474
  const monthEndDate = endOfMonth.endOfMonth(monthStartDate);
@@ -580,7 +530,7 @@ const Calendar$1 = React.forwardRef((_ref, ref) => {
580
530
  }
581
531
  }, formattedDayLabel));
582
532
  });
583
- return React__namespace.default.createElement(StyledDatepicker, {
533
+ return React__namespace.default.createElement(StyledDatePicker, {
584
534
  ref: ref,
585
535
  isCompact: isCompact,
586
536
  onMouseDown: e => {
@@ -768,12 +718,76 @@ function retrieveInitialState$1(initialProps) {
768
718
  };
769
719
  }
770
720
 
771
- const Datepicker = React.forwardRef((props, calendarRef) => {
721
+ const Input = React.forwardRef((_ref, ref) => {
722
+ let {
723
+ element,
724
+ dispatch,
725
+ state,
726
+ refKey
727
+ } = _ref;
728
+ const isInputMouseDownRef = React.useRef(false);
729
+ const handleBlur = () => {
730
+ dispatch({
731
+ type: 'CLOSE'
732
+ });
733
+ };
734
+ const handleChange = e => {
735
+ dispatch({
736
+ type: 'MANUALLY_UPDATE_INPUT',
737
+ value: e.target.value
738
+ });
739
+ };
740
+ const handleClick = () => {
741
+ if (isInputMouseDownRef.current && !state.isOpen) {
742
+ dispatch({
743
+ type: 'OPEN'
744
+ });
745
+ }
746
+ };
747
+ const handleKeyDown = e => {
748
+ switch (e.key) {
749
+ case containerUtilities.KEYS.ESCAPE:
750
+ case containerUtilities.KEYS.ENTER:
751
+ dispatch({
752
+ type: 'CLOSE'
753
+ });
754
+ break;
755
+ case containerUtilities.KEYS.UP:
756
+ case containerUtilities.KEYS.DOWN:
757
+ case containerUtilities.KEYS.SPACE:
758
+ dispatch({
759
+ type: 'OPEN'
760
+ });
761
+ break;
762
+ }
763
+ };
764
+ const handleMouseDown = () => {
765
+ isInputMouseDownRef.current = true;
766
+ };
767
+ const handleMouseUp = () => {
768
+ setTimeout(() => {
769
+ isInputMouseDownRef.current = false;
770
+ }, 0);
771
+ };
772
+ return React.cloneElement(element, {
773
+ [refKey]: ref,
774
+ onMouseDown: containerUtilities.composeEventHandlers(element.props.onMouseDown, handleMouseDown),
775
+ onMouseUp: containerUtilities.composeEventHandlers(element.props.onMouseUp, handleMouseUp),
776
+ onClick: containerUtilities.composeEventHandlers(element.props.onClick, handleClick),
777
+ onBlur: containerUtilities.composeEventHandlers(element.props.onBlur, handleBlur),
778
+ onChange: containerUtilities.composeEventHandlers(element.props.onChange, handleChange),
779
+ onKeyDown: containerUtilities.composeEventHandlers(element.props.onKeyDown, handleKeyDown),
780
+ autoComplete: 'off',
781
+ value: state.inputValue
782
+ });
783
+ });
784
+ Input.displayName = 'Input';
785
+
786
+ const PLACEMENT_DEFAULT = 'bottom-start';
787
+ const DatePicker = React.forwardRef((props, calendarRef) => {
772
788
  const {
773
789
  children,
774
- placement,
775
- popperModifiers,
776
- eventsEnabled,
790
+ placement: _placement,
777
791
  zIndex,
778
792
  isAnimated,
779
793
  refKey,
@@ -788,7 +802,7 @@ const Datepicker = React.forwardRef((props, calendarRef) => {
788
802
  customParseDate,
789
803
  ...menuProps
790
804
  } = props;
791
- const theme = React.useContext(styled.ThemeContext);
805
+ const theme = React.useContext(styled.ThemeContext) || reactTheming.DEFAULT_THEME;
792
806
  const memoizedReducer = React.useCallback(datepickerReducer({
793
807
  value,
794
808
  formatDate,
@@ -797,15 +811,43 @@ const Datepicker = React.forwardRef((props, calendarRef) => {
797
811
  onChange
798
812
  }), [value, formatDate, locale, onChange, customParseDate]);
799
813
  const [state, dispatch] = React.useReducer(memoizedReducer, retrieveInitialState$1(props));
800
- const scheduleUpdateRef = React.useRef(undefined);
801
- const inputRef = React.useRef(null);
802
- const isInputMouseDownRef = React.useRef(false);
803
- React.useEffect(() => {
804
- if (state.isOpen && scheduleUpdateRef.current) {
805
- scheduleUpdateRef.current();
814
+ const triggerRef = React.useRef(null);
815
+ const floatingRef = React.useRef(null);
816
+ const [isVisible, setIsVisible] = React.useState(state.isOpen);
817
+ const contextValue = React.useMemo(() => ({
818
+ state,
819
+ dispatch
820
+ }), [state, dispatch]);
821
+ const [floatingPlacement] = reactTheming.getFloatingPlacements(theme, _placement === 'auto' ? PLACEMENT_DEFAULT : _placement);
822
+ const {
823
+ refs,
824
+ placement,
825
+ update,
826
+ floatingStyles: {
827
+ transform
806
828
  }
829
+ } = reactDom.useFloating({
830
+ platform: {
831
+ ...reactDom.platform,
832
+ isRTL: () => theme.rtl
833
+ },
834
+ elements: {
835
+ reference: triggerRef?.current,
836
+ floating: floatingRef?.current
837
+ },
838
+ placement: floatingPlacement,
839
+ middleware: [_placement === 'auto' ? reactDom.autoPlacement() : reactDom.flip()]
807
840
  });
808
- const [isVisible, setIsVisible] = React.useState(state.isOpen);
841
+ const Child = React__namespace.default.Children.only(children);
842
+ React.useEffect(() => {
843
+ let cleanup;
844
+ if (state.isOpen && refs.reference.current && refs.floating.current) {
845
+ cleanup = reactDom.autoUpdate(refs.reference.current, refs.floating.current, update, {
846
+ elementResize: typeof ResizeObserver === 'function'
847
+ });
848
+ }
849
+ return () => cleanup && cleanup();
850
+ }, [state.isOpen, refs.reference, refs.floating, update]);
809
851
  React.useEffect(() => {
810
852
  let timeout;
811
853
  if (state.isOpen) {
@@ -828,102 +870,35 @@ const Datepicker = React.forwardRef((props, calendarRef) => {
828
870
  type: 'CONTROLLED_LOCALE_CHANGE'
829
871
  });
830
872
  }, [locale]);
831
- const popperPlacement = theme.rtl ? getRtlPopperPlacement(placement) : getPopperPlacement(placement);
832
- const contextValue = React.useMemo(() => ({
833
- state,
834
- dispatch
835
- }), [state, dispatch]);
836
- return React__namespace.default.createElement(DatepickerContext.Provider, {
873
+ return React__namespace.default.createElement(React__namespace.default.Fragment, null, React__namespace.default.createElement(Input, {
874
+ element: Child,
875
+ dispatch: dispatch,
876
+ state: state,
877
+ refKey: refKey,
878
+ ref: reactMergeRefs.mergeRefs([triggerRef, Child.ref ? Child.ref : null])
879
+ }), React__namespace.default.createElement(DatePickerContext.Provider, {
837
880
  value: contextValue
838
- }, React__namespace.default.createElement(reactPopper.Manager, null, React__namespace.default.createElement(reactPopper.Reference, null, _ref => {
839
- let {
840
- ref
841
- } = _ref;
842
- const childElement = React__namespace.default.Children.only(children);
843
- return React__namespace.default.cloneElement(childElement, {
844
- [refKey]: refValue => {
845
- ref(refValue);
846
- inputRef.current = refValue;
847
- },
848
- onMouseDown: containerUtilities.composeEventHandlers(childElement.props.onMouseDown, () => {
849
- isInputMouseDownRef.current = true;
850
- }),
851
- onMouseUp: containerUtilities.composeEventHandlers(childElement.props.onMouseUp, () => {
852
- setTimeout(() => {
853
- isInputMouseDownRef.current = false;
854
- }, 0);
855
- }),
856
- onClick: containerUtilities.composeEventHandlers(childElement.props.onClick, () => {
857
- if (isInputMouseDownRef.current && !state.isOpen) {
858
- dispatch({
859
- type: 'OPEN'
860
- });
861
- }
862
- }),
863
- onBlur: containerUtilities.composeEventHandlers(childElement.props.onBlur, () => {
864
- dispatch({
865
- type: 'CLOSE'
866
- });
867
- }),
868
- onChange: containerUtilities.composeEventHandlers(childElement.props.onChange, e => {
869
- dispatch({
870
- type: 'MANUALLY_UPDATE_INPUT',
871
- value: e.target.value
872
- });
873
- }),
874
- onKeyDown: containerUtilities.composeEventHandlers(childElement.props.onKeyDown, e => {
875
- switch (e.key) {
876
- case containerUtilities.KEYS.ESCAPE:
877
- case containerUtilities.KEYS.ENTER:
878
- dispatch({
879
- type: 'CLOSE'
880
- });
881
- break;
882
- case containerUtilities.KEYS.UP:
883
- case containerUtilities.KEYS.DOWN:
884
- case containerUtilities.KEYS.SPACE:
885
- dispatch({
886
- type: 'OPEN'
887
- });
888
- break;
889
- }
890
- }),
891
- autoComplete: 'off',
892
- value: state.inputValue
893
- });
894
- }), React__namespace.default.createElement(reactPopper.Popper, {
895
- placement: popperPlacement,
896
- modifiers: popperModifiers
897
- ,
898
- eventsEnabled: state.isOpen && eventsEnabled
899
- }, _ref2 => {
900
- let {
901
- ref,
902
- style,
903
- scheduleUpdate,
904
- placement: currentPlacement
905
- } = _ref2;
906
- scheduleUpdateRef.current = scheduleUpdate;
907
- return React__namespace.default.createElement(StyledMenuWrapper, {
908
- ref: ref,
909
- style: style,
910
- isHidden: !state.isOpen,
911
- isAnimated: isAnimated && (state.isOpen || isVisible),
912
- placement: currentPlacement,
913
- zIndex: zIndex
914
- }, (state.isOpen || isVisible) && React__namespace.default.createElement(StyledMenu, menuProps, React__namespace.default.createElement(Calendar$1, {
915
- ref: calendarRef,
916
- isCompact: isCompact,
917
- value: value,
918
- minValue: minValue,
919
- maxValue: maxValue,
920
- locale: locale,
921
- weekStartsOn: weekStartsOn
922
- })));
923
- })));
881
+ }, React__namespace.default.createElement(StyledMenuWrapper, {
882
+ ref: floatingRef,
883
+ style: {
884
+ transform
885
+ },
886
+ isHidden: !state.isOpen,
887
+ isAnimated: isAnimated && (state.isOpen || isVisible),
888
+ placement: placement,
889
+ zIndex: zIndex
890
+ }, (state.isOpen || isVisible) && React__namespace.default.createElement(StyledMenu, menuProps, React__namespace.default.createElement(Calendar$1, {
891
+ ref: calendarRef,
892
+ isCompact: isCompact,
893
+ value: value,
894
+ minValue: minValue,
895
+ maxValue: maxValue,
896
+ locale: locale,
897
+ weekStartsOn: weekStartsOn
898
+ })))));
924
899
  });
925
- Datepicker.displayName = 'Datepicker';
926
- Datepicker.propTypes = {
900
+ DatePicker.displayName = 'DatePicker';
901
+ DatePicker.propTypes = {
927
902
  value: PropTypes__default.default.any,
928
903
  onChange: PropTypes__default.default.any,
929
904
  formatDate: PropTypes__default.default.func,
@@ -935,16 +910,13 @@ Datepicker.propTypes = {
935
910
  customParseDate: PropTypes__default.default.any,
936
911
  refKey: PropTypes__default.default.string,
937
912
  placement: PropTypes__default.default.oneOf(PLACEMENT),
938
- popperModifiers: PropTypes__default.default.any,
939
913
  isAnimated: PropTypes__default.default.bool,
940
- eventsEnabled: PropTypes__default.default.bool,
941
914
  zIndex: PropTypes__default.default.number
942
915
  };
943
- Datepicker.defaultProps = {
944
- placement: 'bottom-start',
916
+ DatePicker.defaultProps = {
917
+ placement: PLACEMENT_DEFAULT,
945
918
  refKey: 'ref',
946
919
  isAnimated: true,
947
- eventsEnabled: true,
948
920
  zIndex: 1000,
949
921
  locale: 'en-US'
950
922
  };
@@ -1250,9 +1222,9 @@ function retrieveInitialState(initialProps) {
1250
1222
  };
1251
1223
  }
1252
1224
 
1253
- const DatepickerRangeContext = React.createContext(undefined);
1254
- const useDatepickerContext = () => {
1255
- return React.useContext(DatepickerRangeContext);
1225
+ const DatePickerRangeContext = React.createContext(undefined);
1226
+ const useDatePickerContext = () => {
1227
+ return React.useContext(DatePickerRangeContext);
1256
1228
  };
1257
1229
 
1258
1230
  const Start = props => {
@@ -1264,7 +1236,7 @@ const Start = props => {
1264
1236
  endValue,
1265
1237
  startInputRef,
1266
1238
  customParseDate
1267
- } = useDatepickerContext();
1239
+ } = useDatePickerContext();
1268
1240
  const onChangeCallback = React.useCallback(e => {
1269
1241
  dispatch({
1270
1242
  type: 'START_INPUT_ONCHANGE',
@@ -1318,7 +1290,7 @@ const Start = props => {
1318
1290
  onBlur: containerUtilities.composeEventHandlers(childElement.props.onBlur, onBlurCallback)
1319
1291
  });
1320
1292
  };
1321
- Start.displayName = 'DatepickerRange.Start';
1293
+ Start.displayName = 'DatePickerRange.Start';
1322
1294
 
1323
1295
  const End = props => {
1324
1296
  const {
@@ -1329,7 +1301,7 @@ const End = props => {
1329
1301
  endValue,
1330
1302
  endInputRef,
1331
1303
  customParseDate
1332
- } = useDatepickerContext();
1304
+ } = useDatePickerContext();
1333
1305
  const onChangeCallback = React.useCallback(e => {
1334
1306
  dispatch({
1335
1307
  type: 'END_INPUT_ONCHANGE',
@@ -1383,22 +1355,7 @@ const End = props => {
1383
1355
  onBlur: containerUtilities.composeEventHandlers(childElement.props.onBlur, onBlurCallback)
1384
1356
  });
1385
1357
  };
1386
- End.displayName = 'DatepickerRange.End';
1387
-
1388
- function _extends() {
1389
- _extends = Object.assign ? Object.assign.bind() : function (target) {
1390
- for (var i = 1; i < arguments.length; i++) {
1391
- var source = arguments[i];
1392
- for (var key in source) {
1393
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1394
- target[key] = source[key];
1395
- }
1396
- }
1397
- }
1398
- return target;
1399
- };
1400
- return _extends.apply(this, arguments);
1401
- }
1358
+ End.displayName = 'DatePickerRange.End';
1402
1359
 
1403
1360
  const Month = React.forwardRef((_ref, ref) => {
1404
1361
  let {
@@ -1417,7 +1374,7 @@ const Month = React.forwardRef((_ref, ref) => {
1417
1374
  startValue,
1418
1375
  endValue,
1419
1376
  onChange
1420
- } = useDatepickerContext();
1377
+ } = useDatePickerContext();
1421
1378
  const headerLabelFormatter = React.useCallback(date => {
1422
1379
  const formatter = new Intl.DateTimeFormat(locale, {
1423
1380
  month: 'long',
@@ -1594,7 +1551,7 @@ const Month = React.forwardRef((_ref, ref) => {
1594
1551
  }
1595
1552
  }, formattedDayLabel));
1596
1553
  });
1597
- return React__namespace.default.createElement(StyledDatepicker, {
1554
+ return React__namespace.default.createElement(StyledDatePicker, {
1598
1555
  ref: ref,
1599
1556
  isCompact: isCompact,
1600
1557
  onMouseDown: e => {
@@ -1635,11 +1592,11 @@ Month.displayName = 'Month';
1635
1592
  const Calendar = React.forwardRef((props, ref) => {
1636
1593
  const {
1637
1594
  state
1638
- } = useDatepickerContext();
1639
- return React__namespace.default.createElement(StyledRangeCalendar, _extends({
1595
+ } = useDatePickerContext();
1596
+ return React__namespace.default.createElement(StyledRangeCalendar, Object.assign({
1640
1597
  ref: ref,
1641
1598
  "data-garden-id": "datepickers.range",
1642
- "data-garden-version": '9.0.0-next.0'
1599
+ "data-garden-version": '9.0.0-next.10'
1643
1600
  }, props), React__namespace.default.createElement(Month, {
1644
1601
  displayDate: state.previewDate,
1645
1602
  isNextHidden: true
@@ -1648,9 +1605,9 @@ const Calendar = React.forwardRef((props, ref) => {
1648
1605
  isPreviousHidden: true
1649
1606
  }));
1650
1607
  });
1651
- Calendar.displayName = 'DatepickerRange.Calendar';
1608
+ Calendar.displayName = 'DatePickerRange.Calendar';
1652
1609
 
1653
- const DatepickerRangeComponent = props => {
1610
+ const DatePickerRangeComponent = props => {
1654
1611
  const {
1655
1612
  startValue,
1656
1613
  locale,
@@ -1711,11 +1668,11 @@ const DatepickerRangeComponent = props => {
1711
1668
  endInputRef,
1712
1669
  customParseDate
1713
1670
  }), [state, dispatch, isCompact, locale, weekStartsOn, minValue, maxValue, startValue, endValue, onChange, startInputRef, endInputRef, customParseDate]);
1714
- return React__namespace.default.createElement(DatepickerRangeContext.Provider, {
1671
+ return React__namespace.default.createElement(DatePickerRangeContext.Provider, {
1715
1672
  value: value
1716
1673
  }, children);
1717
1674
  };
1718
- DatepickerRangeComponent.propTypes = {
1675
+ DatePickerRangeComponent.propTypes = {
1719
1676
  locale: PropTypes__default.default.string,
1720
1677
  weekStartsOn: PropTypes__default.default.number,
1721
1678
  startValue: PropTypes__default.default.instanceOf(Date),
@@ -1727,14 +1684,14 @@ DatepickerRangeComponent.propTypes = {
1727
1684
  customParseDate: PropTypes__default.default.func,
1728
1685
  isCompact: PropTypes__default.default.bool
1729
1686
  };
1730
- DatepickerRangeComponent.defaultProps = {
1687
+ DatePickerRangeComponent.defaultProps = {
1731
1688
  locale: 'en-US',
1732
1689
  isCompact: false
1733
1690
  };
1734
- const DatepickerRange = DatepickerRangeComponent;
1735
- DatepickerRange.Calendar = Calendar;
1736
- DatepickerRange.End = End;
1737
- DatepickerRange.Start = Start;
1691
+ const DatePickerRange = DatePickerRangeComponent;
1692
+ DatePickerRange.Calendar = Calendar;
1693
+ DatePickerRange.End = End;
1694
+ DatePickerRange.Start = Start;
1738
1695
 
1739
- exports.Datepicker = Datepicker;
1740
- exports.DatepickerRange = DatepickerRange;
1696
+ exports.DatePicker = DatePicker;
1697
+ exports.DatePickerRange = DatePickerRange;