@true-engineering/true-react-common-ui-kit 3.20.0 → 3.21.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/LICENSE +201 -201
- package/README.md +12 -0
- package/dist/components/DatePicker/types.d.ts +1 -1
- package/dist/components/WithPopup/WithPopup.d.ts +1 -1
- package/dist/true-react-common-ui-kit.js +61 -61
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +61 -61
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/package.json +1 -1
- package/src/components/AccountInfo/AccountInfo.stories.tsx +32 -32
- package/src/components/AccountInfo/AccountInfo.tsx +80 -80
- package/src/components/AddButton/AddButton.stories.tsx +21 -21
- package/src/components/AddButton/AddButton.tsx +52 -52
- package/src/components/Button/Button.tsx +129 -129
- package/src/components/Colors/Colors.stories.tsx +7 -7
- package/src/components/DateInput/DateInput.tsx +90 -90
- package/src/components/DateInput/constants.ts +2 -2
- package/src/components/DatePicker/DatePicker.tsx +310 -308
- package/src/components/DatePicker/types.ts +1 -0
- package/src/components/Description/Description.stories.tsx +27 -27
- package/src/components/Description/Description.tsx +61 -61
- package/src/components/FiltersPane/components/FilterValueView/FilterValueView.tsx +166 -166
- package/src/components/FiltersPane/components/FilterWithDates/FilterWithDates.tsx +210 -210
- package/src/components/FiltersPane/components/FilterWithPeriod/FilterWithPeriod.tsx +177 -177
- package/src/components/Flag/Flag.stories.tsx +29 -29
- package/src/components/Flag/Flag.tsx +26 -26
- package/src/components/Flag/augment.d.ts +1 -1
- package/src/components/FlexibleTable/components/FlexibleTableCell/FlexibleTableCell.styles.ts +38 -38
- package/src/components/FlexibleTable/components/FlexibleTableRow/FlexibleTableRow.styles.ts +25 -25
- package/src/components/FlexibleTable/components/FlexibleTableRow/FlexibleTableRow.tsx +196 -196
- package/src/components/FlexibleTable/helpers.ts +13 -13
- package/src/components/Icon/Icon.stories.tsx +86 -86
- package/src/components/Icon/complexIcons/augment.d.ts +1 -1
- package/src/components/Icon/complexIcons/avatarGreen.svg +57 -57
- package/src/components/Icon/complexIcons/index.ts +1 -1
- package/src/components/IncrementInput/IncrementInput.tsx +105 -105
- package/src/components/Input/Input.tsx +297 -297
- package/src/components/Input/types.ts +32 -32
- package/src/components/List/List.stories.tsx +70 -70
- package/src/components/List/List.tsx +33 -33
- package/src/components/List/components/ListItem/ListItem.tsx +57 -57
- package/src/components/Modal/Modal.stories.tsx +105 -105
- package/src/components/MultiSelect/MultiSelect.stories.tsx +46 -46
- package/src/components/MultiSelect/MultiSelect.tsx +106 -106
- package/src/components/MultiSelect/components/MultiSelectInput/MultiSelectInput.tsx +53 -53
- package/src/components/Notification/Notification.stories.tsx +46 -46
- package/src/components/Notification/Notification.tsx +69 -69
- package/src/components/NumberInput/NumberInput.tsx +137 -137
- package/src/components/NumberInput/index.ts +1 -1
- package/src/components/PhoneInput/PhoneInput.tsx +214 -214
- package/src/components/PhoneInput/components/PhoneInputCountryList/PhoneInputCountryList.tsx +155 -155
- package/src/components/PhoneInput/types.ts +16 -16
- package/src/components/RadioButton/RadioButton.stories.tsx +46 -46
- package/src/components/RadioButton/RadioButton.tsx +57 -57
- package/src/components/ScrollIntoViewIfNeeded/index.ts +1 -1
- package/src/components/Select/MultiSelect.stories.tsx +240 -240
- package/src/components/Select/Select.stories.tsx +235 -235
- package/src/components/Select/constants.ts +2 -2
- package/src/components/Select/types.ts +1 -1
- package/src/components/Selector/Selector.stories.tsx +62 -62
- package/src/components/Selector/Selector.tsx +115 -115
- package/src/components/Selector/index.ts +2 -2
- package/src/components/Selector/types.ts +12 -12
- package/src/components/Skeleton/Skeleton.stories.tsx +19 -19
- package/src/components/SmartInput/SmartInput.tsx +134 -134
- package/src/components/Status/Status.stories.tsx +73 -73
- package/src/components/Status/Status.styles.ts +143 -143
- package/src/components/Status/Status.tsx +49 -49
- package/src/components/Status/constants.ts +11 -11
- package/src/components/Status/index.ts +3 -3
- package/src/components/Status/types.ts +5 -5
- package/src/components/Switch/Switch.stories.tsx +40 -40
- package/src/components/Switch/Switch.tsx +75 -75
- package/src/components/TextArea/TextArea.styles.ts +1 -3
- package/src/components/TextWithInfo/TextWithInfo.stories.tsx +53 -53
- package/src/components/TextWithInfo/TextWithInfo.tsx +62 -62
- package/src/components/TextWithTooltip/TextWithTooltip.stories.tsx +58 -58
- package/src/components/ThemedPreloader/ThemedPreloader.stories.tsx +41 -41
- package/src/components/ThemedPreloader/ThemedPreloader.tsx +54 -54
- package/src/components/ThemedPreloader/components/DefaultPreloader/index.ts +1 -1
- package/src/components/Toaster/Toaster.stories.tsx +30 -30
- package/src/components/Tooltip/Tooltip.stories.tsx +19 -19
- package/src/components/Tooltip/Tooltip.tsx +35 -35
- package/src/components/Tooltip/types.ts +1 -1
- package/src/components/WithPopup/WithPopup.tsx +1 -1
- package/src/helpers/popper-helpers.ts +17 -17
- package/src/hooks/use-dropdown.ts +84 -84
- package/src/hooks/use-is-mounted.ts +15 -15
- package/src/theme/helpers.ts +76 -76
- package/src/vite-env.d.ts +1 -1
|
@@ -1,308 +1,310 @@
|
|
|
1
|
-
import { useState, useEffect, FC, FocusEvent, SyntheticEvent, forwardRef, useMemo } from 'react';
|
|
2
|
-
import ReactDatePicker from 'react-datepicker';
|
|
3
|
-
import 'react-datepicker/dist/react-datepicker.css';
|
|
4
|
-
import clsx from 'clsx';
|
|
5
|
-
import { isAfter, isBefore, isValid } from 'date-fns';
|
|
6
|
-
import {
|
|
7
|
-
isEmpty,
|
|
8
|
-
isNotEmpty,
|
|
9
|
-
isStringNotEmpty,
|
|
10
|
-
} from '@true-engineering/true-react-platform-helpers';
|
|
11
|
-
import { addDataAttributes } from '../../helpers';
|
|
12
|
-
import { useTweakStyles } from '../../hooks';
|
|
13
|
-
import { ICommonProps } from '../../types';
|
|
14
|
-
import { DateInput, EMPTY_DATE_INPUT_VALUE, IDateInputProps } from '../DateInput';
|
|
15
|
-
import { DatePickerHeader, PopperContainer } from './components';
|
|
16
|
-
import { DatePickerComponent, DEFAULT_DATE_FORMAT } from './constants';
|
|
17
|
-
import { areDatesEquals, getDateFormatter, getDateValueParser } from './helpers';
|
|
18
|
-
import { IDatePickerBaseProps, IRange } from './types';
|
|
19
|
-
import { useStyles, IDatePickerStyles } from './DatePicker.styles';
|
|
20
|
-
|
|
21
|
-
export interface IDatePickerProps extends IDatePickerBaseProps, ICommonProps<IDatePickerStyles> {
|
|
22
|
-
selectedDate?: Date | null;
|
|
23
|
-
locale: Locale;
|
|
24
|
-
months?: string[];
|
|
25
|
-
/** @default 'dd.MM.yyyy' */
|
|
26
|
-
dateFormat?: string;
|
|
27
|
-
/** @default 1 */
|
|
28
|
-
calendarStartDay?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
29
|
-
/** @default false */
|
|
30
|
-
isRange?: boolean;
|
|
31
|
-
/** @default false */
|
|
32
|
-
isInline?: boolean;
|
|
33
|
-
/** @default false */
|
|
34
|
-
shouldRenderPopperInBody?: boolean;
|
|
35
|
-
customInput?: FC<IDateInputProps>;
|
|
36
|
-
onChangeDate?: (date: Date | null, event?: SyntheticEvent) => void;
|
|
37
|
-
onChangeRange?: (date: IRange, event?: SyntheticEvent) => void;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const DatePicker = forwardRef<ReactDatePicker, IDatePickerProps>(
|
|
41
|
-
(
|
|
42
|
-
{
|
|
43
|
-
data,
|
|
44
|
-
selectedDate = null,
|
|
45
|
-
minDate,
|
|
46
|
-
maxDate,
|
|
47
|
-
endDate = null,
|
|
48
|
-
startDate = null,
|
|
49
|
-
locale,
|
|
50
|
-
months,
|
|
51
|
-
calendarStartDay = 1,
|
|
52
|
-
dateFormat = DEFAULT_DATE_FORMAT,
|
|
53
|
-
monthsShown,
|
|
54
|
-
placeholder,
|
|
55
|
-
isRange = false,
|
|
56
|
-
isInline = false,
|
|
57
|
-
isDisabled,
|
|
58
|
-
isClearable,
|
|
59
|
-
strictParsing,
|
|
60
|
-
focusSelectedMonth,
|
|
61
|
-
disabledKeyboardNavigation,
|
|
62
|
-
shouldRenderPopperInBody = false,
|
|
63
|
-
allowSameDay = false,
|
|
64
|
-
shouldCloseOnSelect,
|
|
65
|
-
showPreviousMonths,
|
|
66
|
-
preventOpenOnFocus,
|
|
67
|
-
popperModifiers,
|
|
68
|
-
popperPlacement,
|
|
69
|
-
todayButton,
|
|
70
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const [
|
|
112
|
-
const [
|
|
113
|
-
const [
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
//
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
!areDatesEquals(value?.[
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
(isNotEmpty(newStart) && !
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
(isNotEmpty(newEnd) && !
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
//
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
);
|
|
1
|
+
import { useState, useEffect, FC, FocusEvent, SyntheticEvent, forwardRef, useMemo } from 'react';
|
|
2
|
+
import ReactDatePicker from 'react-datepicker';
|
|
3
|
+
import 'react-datepicker/dist/react-datepicker.css';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
import { isAfter, isBefore, isValid } from 'date-fns';
|
|
6
|
+
import {
|
|
7
|
+
isEmpty,
|
|
8
|
+
isNotEmpty,
|
|
9
|
+
isStringNotEmpty,
|
|
10
|
+
} from '@true-engineering/true-react-platform-helpers';
|
|
11
|
+
import { addDataAttributes } from '../../helpers';
|
|
12
|
+
import { useTweakStyles } from '../../hooks';
|
|
13
|
+
import { ICommonProps } from '../../types';
|
|
14
|
+
import { DateInput, EMPTY_DATE_INPUT_VALUE, IDateInputProps } from '../DateInput';
|
|
15
|
+
import { DatePickerHeader, PopperContainer } from './components';
|
|
16
|
+
import { DatePickerComponent, DEFAULT_DATE_FORMAT } from './constants';
|
|
17
|
+
import { areDatesEquals, getDateFormatter, getDateValueParser } from './helpers';
|
|
18
|
+
import { IDatePickerBaseProps, IRange } from './types';
|
|
19
|
+
import { useStyles, IDatePickerStyles } from './DatePicker.styles';
|
|
20
|
+
|
|
21
|
+
export interface IDatePickerProps extends IDatePickerBaseProps, ICommonProps<IDatePickerStyles> {
|
|
22
|
+
selectedDate?: Date | null;
|
|
23
|
+
locale: Locale;
|
|
24
|
+
months?: string[];
|
|
25
|
+
/** @default 'dd.MM.yyyy' */
|
|
26
|
+
dateFormat?: string;
|
|
27
|
+
/** @default 1 */
|
|
28
|
+
calendarStartDay?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
29
|
+
/** @default false */
|
|
30
|
+
isRange?: boolean;
|
|
31
|
+
/** @default false */
|
|
32
|
+
isInline?: boolean;
|
|
33
|
+
/** @default false */
|
|
34
|
+
shouldRenderPopperInBody?: boolean;
|
|
35
|
+
customInput?: FC<IDateInputProps>;
|
|
36
|
+
onChangeDate?: (date: Date | null, event?: SyntheticEvent) => void;
|
|
37
|
+
onChangeRange?: (date: IRange, event?: SyntheticEvent) => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const DatePicker = forwardRef<ReactDatePicker, IDatePickerProps>(
|
|
41
|
+
(
|
|
42
|
+
{
|
|
43
|
+
data,
|
|
44
|
+
selectedDate = null,
|
|
45
|
+
minDate,
|
|
46
|
+
maxDate,
|
|
47
|
+
endDate = null,
|
|
48
|
+
startDate = null,
|
|
49
|
+
locale,
|
|
50
|
+
months,
|
|
51
|
+
calendarStartDay = 1,
|
|
52
|
+
dateFormat = DEFAULT_DATE_FORMAT,
|
|
53
|
+
monthsShown,
|
|
54
|
+
placeholder,
|
|
55
|
+
isRange = false,
|
|
56
|
+
isInline = false,
|
|
57
|
+
isDisabled,
|
|
58
|
+
isClearable,
|
|
59
|
+
strictParsing,
|
|
60
|
+
focusSelectedMonth,
|
|
61
|
+
disabledKeyboardNavigation,
|
|
62
|
+
shouldRenderPopperInBody = false,
|
|
63
|
+
allowSameDay = false,
|
|
64
|
+
shouldCloseOnSelect,
|
|
65
|
+
showPreviousMonths,
|
|
66
|
+
preventOpenOnFocus,
|
|
67
|
+
popperModifiers,
|
|
68
|
+
popperPlacement,
|
|
69
|
+
todayButton,
|
|
70
|
+
highlightDates,
|
|
71
|
+
calendarContainer,
|
|
72
|
+
dayClassName,
|
|
73
|
+
customInput: CustomInput = DateInput,
|
|
74
|
+
customInputRef,
|
|
75
|
+
renderCustomHeader,
|
|
76
|
+
filterDate,
|
|
77
|
+
onYearChange,
|
|
78
|
+
onMonthChange,
|
|
79
|
+
onCalendarOpen,
|
|
80
|
+
onCalendarClose,
|
|
81
|
+
onChangeDate,
|
|
82
|
+
onChangeRange,
|
|
83
|
+
onBlur,
|
|
84
|
+
onFocus,
|
|
85
|
+
onKeyDown,
|
|
86
|
+
tweakStyles,
|
|
87
|
+
...inputProps
|
|
88
|
+
},
|
|
89
|
+
ref,
|
|
90
|
+
) => {
|
|
91
|
+
const classes = useStyles({ theme: tweakStyles });
|
|
92
|
+
|
|
93
|
+
const tweakDateInputStyles = useTweakStyles({
|
|
94
|
+
tweakStyles,
|
|
95
|
+
className: 'tweakDateInput',
|
|
96
|
+
currentComponentName: 'DatePicker',
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const { formatDate, parseDateValue } = useMemo(
|
|
100
|
+
() => ({
|
|
101
|
+
formatDate: getDateFormatter(dateFormat),
|
|
102
|
+
parseDateValue: getDateValueParser(dateFormat),
|
|
103
|
+
}),
|
|
104
|
+
[dateFormat],
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
108
|
+
|
|
109
|
+
const [dateValue, setDateValue] = useState(formatDate(selectedDate));
|
|
110
|
+
|
|
111
|
+
const [start, setStart] = useState(startDate);
|
|
112
|
+
const [startDateValue, setStartDateValue] = useState(formatDate(startDate));
|
|
113
|
+
const [end, setEnd] = useState(endDate);
|
|
114
|
+
const [endDateValue, setEndDateValue] = useState(formatDate(endDate));
|
|
115
|
+
|
|
116
|
+
const hasDateInputValue = isRange
|
|
117
|
+
? isStringNotEmpty(startDateValue) || isStringNotEmpty(endDateValue)
|
|
118
|
+
: isStringNotEmpty(dateValue);
|
|
119
|
+
|
|
120
|
+
const dateInputProps: IDateInputProps = {
|
|
121
|
+
...inputProps,
|
|
122
|
+
isRange,
|
|
123
|
+
isDisabled,
|
|
124
|
+
isClearable,
|
|
125
|
+
isActive: isOpen,
|
|
126
|
+
iconType: isClearable && hasDateInputValue ? undefined : 'calendar',
|
|
127
|
+
tweakStyles: tweakDateInputStyles,
|
|
128
|
+
...(isRange ? { startDate: startDateValue, endDate: endDateValue } : { date: dateValue }),
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const handleChangeDate = (value: Date | null, event?: SyntheticEvent) => {
|
|
132
|
+
onChangeDate?.(value, event);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const isDateInRange = (date: Date) =>
|
|
136
|
+
(isEmpty(minDate) || isAfter(date, minDate)) && (isEmpty(maxDate) || isBefore(date, maxDate));
|
|
137
|
+
|
|
138
|
+
// TODO: Если пропса allowSameDay равна true и введена только начальная дата, то
|
|
139
|
+
// невозможно будет стереть значение в инпуте. Обойти это можно только если
|
|
140
|
+
// полностью выбрать период, а затем уже очищать инпут (баг в react-datepicker. В этом
|
|
141
|
+
// случае value равняется не [null, null], а [start, null])
|
|
142
|
+
const handleChangeRange = (value: IRange, event?: SyntheticEvent) => {
|
|
143
|
+
if (
|
|
144
|
+
allowSameDay ||
|
|
145
|
+
!areDatesEquals(value?.[0], startDate) ||
|
|
146
|
+
!areDatesEquals(value?.[1], endDate)
|
|
147
|
+
) {
|
|
148
|
+
setStart(value?.[0] ?? null);
|
|
149
|
+
setEnd(value?.[1] ?? null);
|
|
150
|
+
onChangeRange?.(value, event);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const handleChangeDateRangeInput = (value: string) => {
|
|
155
|
+
const newStartDateValue = value.slice(0, 10);
|
|
156
|
+
let newStart = parseDateValue(newStartDateValue);
|
|
157
|
+
const newEndDateValue = value.slice(13);
|
|
158
|
+
let newEnd = parseDateValue(newEndDateValue);
|
|
159
|
+
|
|
160
|
+
if (
|
|
161
|
+
(isNotEmpty(newStart) && !isValid(newStart)) ||
|
|
162
|
+
(isNotEmpty(newStart) && !isDateInRange(newStart))
|
|
163
|
+
) {
|
|
164
|
+
newStart = start;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (
|
|
168
|
+
(isNotEmpty(newEnd) && !isValid(newEnd)) ||
|
|
169
|
+
(isNotEmpty(newEnd) && !isDateInRange(newEnd))
|
|
170
|
+
) {
|
|
171
|
+
newEnd = end;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Если оставить пустой начальную дату и заполненной конечную,
|
|
175
|
+
// то ломается react-datepicker и в календарике ничего нельзя выбирать
|
|
176
|
+
if (
|
|
177
|
+
(isEmpty(newStart) && isValid(newEnd)) ||
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
179
|
+
(isValid(newStart) && isValid(newEnd) && isAfter(newStart!, newEnd!))
|
|
180
|
+
) {
|
|
181
|
+
newStart = newEnd;
|
|
182
|
+
newEnd = null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
setStartDateValue(newStartDateValue);
|
|
186
|
+
setStart(newStart);
|
|
187
|
+
setEndDateValue(newEndDateValue);
|
|
188
|
+
setEnd(newEnd);
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const handleDateInputBlur = (event: FocusEvent<HTMLInputElement>) => {
|
|
192
|
+
onBlur?.(event);
|
|
193
|
+
setDateValue(formatDate(selectedDate));
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const setDateRangeValues = (startValue: Date | null = null, endValue: Date | null = null) => {
|
|
197
|
+
let convertedStartDate = formatDate(startValue);
|
|
198
|
+
const convertedEndDate = formatDate(endValue);
|
|
199
|
+
if (convertedStartDate === '' && convertedEndDate !== '') {
|
|
200
|
+
// Если выставлять пустую строку, то конечная дата перепрыгивает на место начальной
|
|
201
|
+
convertedStartDate = EMPTY_DATE_INPUT_VALUE;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
setStart(startValue);
|
|
205
|
+
setStartDateValue(convertedStartDate);
|
|
206
|
+
setEnd(endValue);
|
|
207
|
+
setEndDateValue(convertedEndDate);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const handleDateRangeInputBlur = (event: FocusEvent<HTMLInputElement>) => {
|
|
211
|
+
onBlur?.(event);
|
|
212
|
+
handleChangeRange([start, end], event);
|
|
213
|
+
setDateRangeValues(start, end);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const handleOpenCalendar = () => {
|
|
217
|
+
setIsOpen(true);
|
|
218
|
+
onCalendarOpen?.();
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const handleCloseCalendar = () => {
|
|
222
|
+
setIsOpen(false);
|
|
223
|
+
if (isRange) {
|
|
224
|
+
handleChangeRange([start, end]);
|
|
225
|
+
setDateRangeValues(start, end);
|
|
226
|
+
} else {
|
|
227
|
+
setDateValue(formatDate(selectedDate));
|
|
228
|
+
}
|
|
229
|
+
onCalendarClose?.();
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
useEffect(() => {
|
|
233
|
+
setDateValue(formatDate(selectedDate));
|
|
234
|
+
setDateRangeValues(startDate, endDate);
|
|
235
|
+
}, [selectedDate, startDate, endDate]);
|
|
236
|
+
|
|
237
|
+
return (
|
|
238
|
+
<div className={classes.root} {...addDataAttributes(data)}>
|
|
239
|
+
<DatePickerComponent
|
|
240
|
+
ref={ref}
|
|
241
|
+
minDate={minDate}
|
|
242
|
+
maxDate={maxDate}
|
|
243
|
+
locale={locale}
|
|
244
|
+
dateFormat={dateFormat}
|
|
245
|
+
placeholderText={placeholder}
|
|
246
|
+
calendarStartDay={calendarStartDay}
|
|
247
|
+
inline={isInline}
|
|
248
|
+
disabled={isDisabled}
|
|
249
|
+
showPreviousMonths={showPreviousMonths}
|
|
250
|
+
focusSelectedMonth={focusSelectedMonth}
|
|
251
|
+
monthsShown={monthsShown}
|
|
252
|
+
allowSameDay={allowSameDay}
|
|
253
|
+
showPopperArrow={false}
|
|
254
|
+
popperClassName={classes.popper}
|
|
255
|
+
calendarClassName={classes.datepicker}
|
|
256
|
+
dayClassName={(v) => clsx(classes.day, dayClassName?.(v))}
|
|
257
|
+
disabledKeyboardNavigation={disabledKeyboardNavigation}
|
|
258
|
+
popperContainer={shouldRenderPopperInBody ? PopperContainer : undefined}
|
|
259
|
+
popperModifiers={popperModifiers}
|
|
260
|
+
popperPlacement={popperPlacement}
|
|
261
|
+
selectsRange={isRange}
|
|
262
|
+
strictParsing={strictParsing}
|
|
263
|
+
preventOpenOnFocus={preventOpenOnFocus}
|
|
264
|
+
shouldCloseOnSelect={shouldCloseOnSelect}
|
|
265
|
+
customInputRef={customInputRef}
|
|
266
|
+
customInput={<CustomInput {...dateInputProps} />}
|
|
267
|
+
renderCustomHeader={
|
|
268
|
+
renderCustomHeader ??
|
|
269
|
+
((baseProps) => <DatePickerHeader {...baseProps} months={months} />)
|
|
270
|
+
}
|
|
271
|
+
todayButton={todayButton}
|
|
272
|
+
highlightDates={highlightDates}
|
|
273
|
+
calendarContainer={calendarContainer}
|
|
274
|
+
filterDate={filterDate}
|
|
275
|
+
onYearChange={onYearChange}
|
|
276
|
+
onMonthChange={onMonthChange}
|
|
277
|
+
onFocus={onFocus}
|
|
278
|
+
onKeyDown={onKeyDown}
|
|
279
|
+
onCalendarOpen={handleOpenCalendar}
|
|
280
|
+
onCalendarClose={handleCloseCalendar}
|
|
281
|
+
onChangeRaw={(_, value?: string) => {
|
|
282
|
+
// Если передали value, значит этот обработчик вызвался после изменения значения в инпуте
|
|
283
|
+
// (react-datepicker вызывает эту функцию также при клике на дату в календаре)
|
|
284
|
+
if (value === undefined) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (isRange) {
|
|
288
|
+
handleChangeDateRangeInput(value);
|
|
289
|
+
} else {
|
|
290
|
+
setDateValue(value);
|
|
291
|
+
}
|
|
292
|
+
}}
|
|
293
|
+
{...(isRange
|
|
294
|
+
? {
|
|
295
|
+
startDate: start,
|
|
296
|
+
endDate: end,
|
|
297
|
+
selected: start,
|
|
298
|
+
onBlur: handleDateRangeInputBlur,
|
|
299
|
+
onChange: handleChangeRange,
|
|
300
|
+
}
|
|
301
|
+
: {
|
|
302
|
+
selected: selectedDate,
|
|
303
|
+
onBlur: handleDateInputBlur,
|
|
304
|
+
onChange: handleChangeDate,
|
|
305
|
+
})}
|
|
306
|
+
/>
|
|
307
|
+
</div>
|
|
308
|
+
);
|
|
309
|
+
},
|
|
310
|
+
);
|