@zendeskgarden/react-datepickers 9.12.3 → 9.12.4

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.
@@ -9,8 +9,8 @@ import { createPortal } from 'react-dom';
9
9
  import PropTypes from 'prop-types';
10
10
  import { mergeRefs } from 'react-merge-refs';
11
11
  import { ThemeContext } from 'styled-components';
12
- import { useFloating, platform, autoPlacement, flip, autoUpdate } from '@floating-ui/react-dom';
13
- import { WEEK_STARTS_ON, PLACEMENT } from '../../types/index.js';
12
+ import { useFloating, autoPlacement, flip, platform, autoUpdate } from '@floating-ui/react-dom';
13
+ import { PLACEMENT, WEEK_STARTS_ON } from '../../types/index.js';
14
14
  import { Calendar } from './components/Calendar.js';
15
15
  import { datepickerReducer, retrieveInitialState } from './utils/date-picker-reducer.js';
16
16
  import { DatePickerContext } from './utils/useDatePickerContext.js';
@@ -33,15 +33,14 @@ import useDatePickerContext from '../utils/useDatePickerContext.js';
33
33
  import { getStartOfWeek } from '../../../utils/calendar-utils.js';
34
34
  import { MonthSelector } from './MonthSelector.js';
35
35
 
36
- const Calendar = forwardRef((_ref, ref) => {
37
- let {
38
- value,
39
- minValue,
40
- maxValue,
41
- isCompact,
42
- locale,
43
- weekStartsOn
44
- } = _ref;
36
+ const Calendar$1 = forwardRef(({
37
+ value,
38
+ minValue,
39
+ maxValue,
40
+ isCompact,
41
+ locale,
42
+ weekStartsOn
43
+ }, ref) => {
45
44
  const {
46
45
  state,
47
46
  dispatch
@@ -120,6 +119,6 @@ const Calendar = forwardRef((_ref, ref) => {
120
119
  $isCompact: isCompact
121
120
  }, dayLabels, items));
122
121
  });
123
- Calendar.displayName = 'Calendar';
122
+ Calendar$1.displayName = 'Calendar';
124
123
 
125
- export { Calendar };
124
+ export { Calendar$1 as Calendar };
@@ -7,13 +7,12 @@
7
7
  import { forwardRef, useRef, cloneElement } from 'react';
8
8
  import { composeEventHandlers, KEYS } from '@zendeskgarden/container-utilities';
9
9
 
10
- const Input = forwardRef((_ref, ref) => {
11
- let {
12
- element,
13
- dispatch,
14
- state,
15
- refKey
16
- } = _ref;
10
+ const Input = forwardRef(({
11
+ element,
12
+ dispatch,
13
+ state,
14
+ refKey
15
+ }, ref) => {
17
16
  const isInputMouseDownRef = useRef(false);
18
17
  const handleBlur = () => {
19
18
  dispatch({
@@ -21,11 +21,10 @@ import useDatePickerContext from '../utils/useDatePickerContext.js';
21
21
  import SvgChevronLeftStroke from '../../../node_modules/@zendeskgarden/svg-icons/src/16/chevron-left-stroke.svg.js';
22
22
  import SvgChevronRightStroke from '../../../node_modules/@zendeskgarden/svg-icons/src/16/chevron-right-stroke.svg.js';
23
23
 
24
- const MonthSelector = _ref => {
25
- let {
26
- locale,
27
- isCompact
28
- } = _ref;
24
+ const MonthSelector = ({
25
+ locale,
26
+ isCompact
27
+ }) => {
29
28
  const {
30
29
  state,
31
30
  dispatch
@@ -11,11 +11,10 @@ import { parse } from 'date-fns/parse';
11
11
  import { isBefore } from 'date-fns/isBefore';
12
12
  import { isSameDay } from 'date-fns/isSameDay';
13
13
 
14
- function parseInputValue(_ref) {
15
- let {
16
- inputValue,
17
- customParseDate
18
- } = _ref;
14
+ function parseInputValue$1({
15
+ inputValue,
16
+ customParseDate
17
+ }) {
19
18
  if (customParseDate) {
20
19
  return customParseDate(inputValue);
21
20
  }
@@ -34,12 +33,11 @@ function parseInputValue(_ref) {
34
33
  }
35
34
  return new Date(NaN);
36
35
  }
37
- function formatInputValue(_ref2) {
38
- let {
39
- date,
40
- locale,
41
- formatDate
42
- } = _ref2;
36
+ function formatInputValue({
37
+ date,
38
+ locale,
39
+ formatDate
40
+ }) {
43
41
  if (!date) {
44
42
  return '';
45
43
  }
@@ -52,115 +50,112 @@ function formatInputValue(_ref2) {
52
50
  year: 'numeric'
53
51
  }).format(date);
54
52
  }
55
- const datepickerReducer = _ref3 => {
56
- let {
57
- value,
58
- formatDate,
59
- locale,
60
- customParseDate,
61
- onChange
62
- } = _ref3;
63
- return (state, action) => {
64
- switch (action.type) {
65
- case 'OPEN':
53
+ const datepickerReducer = ({
54
+ value,
55
+ formatDate,
56
+ locale,
57
+ customParseDate,
58
+ onChange
59
+ }) => (state, action) => {
60
+ switch (action.type) {
61
+ case 'OPEN':
62
+ return {
63
+ ...state,
64
+ isOpen: true,
65
+ previewDate: value || new Date()
66
+ };
67
+ case 'CLOSE':
68
+ {
69
+ const inputValue = formatInputValue({
70
+ date: value,
71
+ locale,
72
+ formatDate
73
+ });
66
74
  return {
67
75
  ...state,
68
- isOpen: true,
69
- previewDate: value || new Date()
76
+ isOpen: false,
77
+ inputValue
70
78
  };
71
- case 'CLOSE':
72
- {
73
- const inputValue = formatInputValue({
74
- date: value,
75
- locale,
76
- formatDate
77
- });
78
- return {
79
- ...state,
80
- isOpen: false,
81
- inputValue
82
- };
83
- }
84
- case 'PREVIEW_NEXT_MONTH':
85
- {
86
- const previewDate = addMonths(state.previewDate, 1);
87
- return {
88
- ...state,
89
- previewDate
90
- };
91
- }
92
- case 'PREVIEW_PREVIOUS_MONTH':
93
- {
94
- const previewDate = subMonths(state.previewDate, 1);
95
- return {
96
- ...state,
97
- previewDate
98
- };
99
- }
100
- case 'MANUALLY_UPDATE_INPUT':
101
- {
102
- const inputValue = action.value;
103
- const currentDate = parseInputValue({
104
- inputValue,
105
- customParseDate
106
- });
107
- if (onChange && currentDate && isValid(currentDate) && !isSameDay(value, currentDate)) {
108
- onChange(currentDate);
109
- }
110
- return {
111
- ...state,
112
- isOpen: true,
113
- inputValue
114
- };
115
- }
116
- case 'CONTROLLED_VALUE_CHANGE':
117
- {
118
- const previewDate = action.value || new Date();
119
- const inputValue = formatInputValue({
120
- date: action.value,
121
- locale,
122
- formatDate
123
- });
124
- return {
125
- ...state,
126
- previewDate,
127
- inputValue
128
- };
129
- }
130
- case 'CONTROLLED_LOCALE_CHANGE':
131
- {
132
- const inputValue = formatInputValue({
133
- date: value,
134
- locale,
135
- formatDate
136
- });
137
- return {
138
- ...state,
139
- inputValue
140
- };
79
+ }
80
+ case 'PREVIEW_NEXT_MONTH':
81
+ {
82
+ const previewDate = addMonths(state.previewDate, 1);
83
+ return {
84
+ ...state,
85
+ previewDate
86
+ };
87
+ }
88
+ case 'PREVIEW_PREVIOUS_MONTH':
89
+ {
90
+ const previewDate = subMonths(state.previewDate, 1);
91
+ return {
92
+ ...state,
93
+ previewDate
94
+ };
95
+ }
96
+ case 'MANUALLY_UPDATE_INPUT':
97
+ {
98
+ const inputValue = action.value;
99
+ const currentDate = parseInputValue$1({
100
+ inputValue,
101
+ customParseDate
102
+ });
103
+ if (onChange && currentDate && isValid(currentDate) && !isSameDay(value, currentDate)) {
104
+ onChange(currentDate);
141
105
  }
142
- case 'SELECT_DATE':
143
- {
144
- const inputValue = formatInputValue({
145
- date: action.value,
146
- locale,
147
- formatDate
148
- });
149
- if (onChange && action.value && isValid(action.value) && !isSameDay(value, action.value)) {
150
- onChange(action.value);
151
- }
152
- return {
153
- ...state,
154
- isOpen: false,
155
- inputValue
156
- };
106
+ return {
107
+ ...state,
108
+ isOpen: true,
109
+ inputValue
110
+ };
111
+ }
112
+ case 'CONTROLLED_VALUE_CHANGE':
113
+ {
114
+ const previewDate = action.value || new Date();
115
+ const inputValue = formatInputValue({
116
+ date: action.value,
117
+ locale,
118
+ formatDate
119
+ });
120
+ return {
121
+ ...state,
122
+ previewDate,
123
+ inputValue
124
+ };
125
+ }
126
+ case 'CONTROLLED_LOCALE_CHANGE':
127
+ {
128
+ const inputValue = formatInputValue({
129
+ date: value,
130
+ locale,
131
+ formatDate
132
+ });
133
+ return {
134
+ ...state,
135
+ inputValue
136
+ };
137
+ }
138
+ case 'SELECT_DATE':
139
+ {
140
+ const inputValue = formatInputValue({
141
+ date: action.value,
142
+ locale,
143
+ formatDate
144
+ });
145
+ if (onChange && action.value && isValid(action.value) && !isSameDay(value, action.value)) {
146
+ onChange(action.value);
157
147
  }
158
- default:
159
- throw new Error();
160
- }
161
- };
148
+ return {
149
+ ...state,
150
+ isOpen: false,
151
+ inputValue
152
+ };
153
+ }
154
+ default:
155
+ throw new Error();
156
+ }
162
157
  };
163
- function retrieveInitialState(initialProps) {
158
+ function retrieveInitialState$1(initialProps) {
164
159
  let previewDate = initialProps.value;
165
160
  if (previewDate === undefined || !isValid(previewDate)) {
166
161
  previewDate = new Date();
@@ -184,4 +179,4 @@ function retrieveInitialState(initialProps) {
184
179
  };
185
180
  }
186
181
 
187
- export { datepickerReducer, retrieveInitialState };
182
+ export { datepickerReducer, retrieveInitialState$1 as retrieveInitialState };
@@ -7,8 +7,8 @@
7
7
  import { createContext, useContext } from 'react';
8
8
 
9
9
  const DatePickerContext = createContext(undefined);
10
- const useDatePickerContext = () => {
10
+ const useDatePickerContext$1 = () => {
11
11
  return useContext(DatePickerContext);
12
12
  };
13
13
 
14
- export { DatePickerContext, useDatePickerContext as default };
14
+ export { DatePickerContext, useDatePickerContext$1 as default };
@@ -28,7 +28,7 @@ const Calendar = forwardRef((props, ref) => {
28
28
  return React__default.createElement(StyledRangeCalendar, Object.assign({
29
29
  ref: ref,
30
30
  "data-garden-id": "datepickers.range",
31
- "data-garden-version": '9.12.3'
31
+ "data-garden-version": '9.12.4'
32
32
  }, props), React__default.createElement(Month, {
33
33
  displayDate: state.previewDate,
34
34
  isNextHidden: true
@@ -35,12 +35,11 @@ import { StyledDay } from '../../../styled/StyledDay.js';
35
35
  import { getStartOfWeek } from '../../../utils/calendar-utils.js';
36
36
  import useDatePickerContext from '../utils/useDatePickerRangeContext.js';
37
37
 
38
- const Month = forwardRef((_ref, ref) => {
39
- let {
40
- displayDate,
41
- isPreviousHidden,
42
- isNextHidden
43
- } = _ref;
38
+ const Month = forwardRef(({
39
+ displayDate,
40
+ isPreviousHidden,
41
+ isNextHidden
42
+ }, ref) => {
44
43
  const {
45
44
  state,
46
45
  dispatch,