@zendeskgarden/react-datepickers 9.12.2 → 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.
- package/dist/esm/elements/DatePicker/DatePicker.js +2 -2
- package/dist/esm/elements/DatePicker/components/Calendar.js +10 -11
- package/dist/esm/elements/DatePicker/components/Input.js +6 -7
- package/dist/esm/elements/DatePicker/components/MonthSelector.js +4 -5
- package/dist/esm/elements/DatePicker/utils/date-picker-reducer.js +110 -115
- package/dist/esm/elements/DatePicker/utils/useDatePickerContext.js +2 -2
- package/dist/esm/elements/DatePickerRange/components/Calendar.js +1 -1
- package/dist/esm/elements/DatePickerRange/components/Month.js +5 -6
- package/dist/esm/elements/DatePickerRange/utils/date-picker-range-reducer.js +207 -212
- package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/chevron-left-stroke.svg.js +4 -4
- package/dist/esm/styled/StyledCalendar.js +3 -3
- package/dist/esm/styled/StyledCalendarItem.js +9 -10
- package/dist/esm/styled/StyledDatePicker.js +11 -13
- package/dist/esm/styled/StyledDay.js +7 -8
- package/dist/esm/styled/StyledDayLabel.js +3 -3
- package/dist/esm/styled/StyledHeader.js +3 -3
- package/dist/esm/styled/StyledHeaderLabel.js +3 -3
- package/dist/esm/styled/StyledHeaderPaddle.js +11 -13
- package/dist/esm/styled/StyledHighlight.js +13 -15
- package/dist/esm/styled/StyledMenu.js +3 -3
- package/dist/esm/styled/StyledMenuWrapper.js +3 -3
- package/dist/esm/styled/StyledRangeCalendar.js +3 -3
- package/dist/index.cjs.js +384 -406
- package/package.json +5 -5
|
@@ -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,
|
|
13
|
-
import {
|
|
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((
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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((
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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 =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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:
|
|
69
|
-
|
|
76
|
+
isOpen: false,
|
|
77
|
+
inputValue
|
|
70
78
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
159
|
-
|
|
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.
|
|
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((
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
} = _ref;
|
|
38
|
+
const Month = forwardRef(({
|
|
39
|
+
displayDate,
|
|
40
|
+
isPreviousHidden,
|
|
41
|
+
isNextHidden
|
|
42
|
+
}, ref) => {
|
|
44
43
|
const {
|
|
45
44
|
state,
|
|
46
45
|
dispatch,
|