@alfalab/core-components-date-time-input 2.2.0 → 3.0.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/{Component-27749cf7.d.ts → Component-1ff76732.d.ts} +4 -7
- package/{Component-27749cf7.js → Component-1ff76732.js} +36 -15
- package/Component.desktop.d.ts +1 -1
- package/Component.desktop.js +2 -1
- package/Component.mobile.d.ts +1 -1
- package/Component.mobile.js +2 -1
- package/Component.responsive.d.ts +1 -1
- package/Component.responsive.js +1 -1
- package/components/date-time-input/Component.js +2 -1
- package/components/date-time-input/index.css +8 -8
- package/components/date-time-input/index.d.ts +1 -1
- package/components/date-time-input/index.js +2 -1
- package/{esm/Component-e82a534f.d.ts → cssm/Component-b91f18e8.d.ts} +4 -7
- package/cssm/{Component-d6110aa7.js → Component-b91f18e8.js} +35 -14
- package/cssm/Component.desktop.d.ts +1 -1
- package/cssm/Component.desktop.js +2 -1
- package/cssm/Component.mobile.d.ts +1 -1
- package/cssm/Component.mobile.js +2 -1
- package/cssm/Component.responsive.d.ts +1 -1
- package/cssm/Component.responsive.js +1 -1
- package/cssm/components/date-time-input/Component.js +2 -1
- package/cssm/components/date-time-input/index.d.ts +1 -1
- package/cssm/components/date-time-input/index.js +2 -1
- package/cssm/components/date-time-input/index.module.css +2 -2
- package/cssm/desktop.js +2 -1
- package/cssm/index.d.ts +2 -1
- package/cssm/index.js +2 -2
- package/cssm/mobile.js +2 -1
- package/cssm/responsive.js +2 -2
- package/cssm/utils/format.d.ts +3 -2
- package/cssm/utils/format.js +7 -3
- package/cssm/utils/index.js +2 -1
- package/desktop.js +2 -1
- package/{cssm/Component-d6110aa7.d.ts → esm/Component-074b6874.d.ts} +4 -7
- package/esm/{Component-e82a534f.js → Component-074b6874.js} +37 -16
- package/esm/Component.desktop.d.ts +1 -1
- package/esm/Component.desktop.js +2 -1
- package/esm/Component.mobile.d.ts +1 -1
- package/esm/Component.mobile.js +2 -1
- package/esm/Component.responsive.d.ts +1 -1
- package/esm/Component.responsive.js +1 -1
- package/esm/components/date-time-input/Component.js +2 -1
- package/esm/components/date-time-input/index.css +8 -8
- package/esm/components/date-time-input/index.d.ts +1 -1
- package/esm/components/date-time-input/index.js +2 -1
- package/esm/desktop.js +2 -1
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -2
- package/esm/mobile.js +2 -1
- package/esm/responsive.js +2 -2
- package/esm/utils/format.d.ts +3 -2
- package/esm/utils/format.js +6 -3
- package/esm/utils/index.js +1 -1
- package/index.d.ts +2 -1
- package/index.js +2 -2
- package/mobile.js +2 -1
- package/modern/Component.desktop.js +1 -0
- package/modern/Component.mobile.js +1 -0
- package/modern/components/date-time-input/Component.d.ts +4 -7
- package/modern/components/date-time-input/Component.js +37 -16
- package/modern/components/date-time-input/index.css +8 -8
- package/modern/components/date-time-input/index.js +1 -0
- package/modern/desktop.js +1 -0
- package/modern/index.d.ts +2 -1
- package/modern/mobile.js +1 -0
- package/modern/utils/format.d.ts +3 -2
- package/modern/utils/format.js +6 -3
- package/modern/utils/index.js +1 -1
- package/package.json +4 -3
- package/responsive.js +2 -2
- package/utils/format.d.ts +3 -2
- package/utils/format.js +7 -3
- package/utils/index.js +2 -1
|
@@ -6,6 +6,7 @@ import '@alfalab/core-components-calendar/modern';
|
|
|
6
6
|
import '@alfalab/core-components-icon-button/modern';
|
|
7
7
|
import '@alfalab/core-components-input/modern';
|
|
8
8
|
import '@alfalab/core-components-popover/modern';
|
|
9
|
+
import '@alfalab/hooks';
|
|
9
10
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
10
11
|
import './utils/format.js';
|
|
11
12
|
import 'date-fns/isValid';
|
|
@@ -6,6 +6,7 @@ import 'classnames';
|
|
|
6
6
|
import '@alfalab/core-components-icon-button/modern';
|
|
7
7
|
import '@alfalab/core-components-input/modern';
|
|
8
8
|
import '@alfalab/core-components-popover/modern';
|
|
9
|
+
import '@alfalab/hooks';
|
|
9
10
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
10
11
|
import './utils/format.js';
|
|
11
12
|
import 'date-fns/isValid';
|
|
@@ -24,14 +24,14 @@ type DateTimeInputProps = Omit<InputProps, 'onChange'> & {
|
|
|
24
24
|
/**
|
|
25
25
|
* Обработчик изменения значения
|
|
26
26
|
*/
|
|
27
|
-
onChange?: (event: ChangeEvent<HTMLInputElement
|
|
27
|
+
onChange?: (event: ChangeEvent<HTMLInputElement> | null, payload: {
|
|
28
28
|
date: Date;
|
|
29
29
|
value: string;
|
|
30
30
|
}) => void;
|
|
31
31
|
/**
|
|
32
32
|
* Обработчик окончания ввода
|
|
33
33
|
*/
|
|
34
|
-
onComplete?: (event: ChangeEvent<HTMLInputElement
|
|
34
|
+
onComplete?: (event: ChangeEvent<HTMLInputElement> | null, payload: {
|
|
35
35
|
date: Date;
|
|
36
36
|
value: string;
|
|
37
37
|
}) => void;
|
|
@@ -113,14 +113,14 @@ declare const DateTimeInput: React.ForwardRefExoticComponent<Omit<InputProps, "o
|
|
|
113
113
|
/**
|
|
114
114
|
* Обработчик изменения значения
|
|
115
115
|
*/
|
|
116
|
-
onChange?: ((event: ChangeEvent<HTMLInputElement
|
|
116
|
+
onChange?: ((event: ChangeEvent<HTMLInputElement> | null, payload: {
|
|
117
117
|
date: Date;
|
|
118
118
|
value: string;
|
|
119
119
|
}) => void) | undefined;
|
|
120
120
|
/**
|
|
121
121
|
* Обработчик окончания ввода
|
|
122
122
|
*/
|
|
123
|
-
onComplete?: ((event: ChangeEvent<HTMLInputElement
|
|
123
|
+
onComplete?: ((event: ChangeEvent<HTMLInputElement> | null, payload: {
|
|
124
124
|
date: Date;
|
|
125
125
|
value: string;
|
|
126
126
|
}) => void) | undefined;
|
|
@@ -133,9 +133,6 @@ declare const DateTimeInput: React.ForwardRefExoticComponent<Omit<InputProps, "o
|
|
|
133
133
|
*/
|
|
134
134
|
calendarProps?: (CalendarProps & Record<string, unknown>) | (CalendarProps & {
|
|
135
135
|
open: boolean;
|
|
136
|
-
/**
|
|
137
|
-
* Дополнительный класс для поповера
|
|
138
|
-
*/
|
|
139
136
|
title?: string | undefined;
|
|
140
137
|
onClose?: (() => void) | undefined;
|
|
141
138
|
yearsAmount?: number | undefined;
|
|
@@ -5,12 +5,13 @@ import { Calendar, dateInLimits } from '@alfalab/core-components-calendar/modern
|
|
|
5
5
|
import { IconButton } from '@alfalab/core-components-icon-button/modern';
|
|
6
6
|
import { Input } from '@alfalab/core-components-input/modern';
|
|
7
7
|
import { Popover } from '@alfalab/core-components-popover/modern';
|
|
8
|
+
import { useDidUpdateEffect } from '@alfalab/hooks';
|
|
8
9
|
import { CalendarMIcon } from '@alfalab/icons-glyph/CalendarMIcon';
|
|
9
|
-
import { getDateWithoutTime,
|
|
10
|
+
import { getDateWithoutTime, DATE_WITH_TIME_LENGTH, format, getFullDateTime, isCompleteDateInput, isValid, addTimeToDate, parseTimestampToDate } from '../../utils/format.js';
|
|
10
11
|
import 'date-fns/isValid';
|
|
11
12
|
import 'date-fns/parse';
|
|
12
13
|
|
|
13
|
-
const styles = {"component":"date-time-
|
|
14
|
+
const styles = {"component":"date-time-input__component_wum5f","calendarContainer":"date-time-input__calendarContainer_wum5f","calendarResponsive":"date-time-input__calendarResponsive_wum5f","block":"date-time-input__block_wum5f"};
|
|
14
15
|
require('./index.css')
|
|
15
16
|
|
|
16
17
|
/* eslint-disable no-useless-escape, jsx-a11y/click-events-have-key-events */
|
|
@@ -25,6 +26,10 @@ const DateTimeInput = React.forwardRef(({ className, inputClassName, popoverClas
|
|
|
25
26
|
useEffect(() => {
|
|
26
27
|
setOpen(defaultOpen);
|
|
27
28
|
}, [defaultOpen]);
|
|
29
|
+
useDidUpdateEffect(() => {
|
|
30
|
+
const newPropValue = propValue || '';
|
|
31
|
+
setValue((prevValue) => (prevValue === propValue ? prevValue : newPropValue));
|
|
32
|
+
}, [propValue]);
|
|
28
33
|
const checkInputValueIsValid = (newInputValue) => {
|
|
29
34
|
if (!newInputValue || error)
|
|
30
35
|
return false;
|
|
@@ -33,8 +38,23 @@ const DateTimeInput = React.forwardRef(({ className, inputClassName, popoverClas
|
|
|
33
38
|
dateInLimits(dateValue, minDate, maxDate) &&
|
|
34
39
|
!offDays.includes(dateValue));
|
|
35
40
|
};
|
|
41
|
+
const setTimeToDate = () => {
|
|
42
|
+
setValue((prevValue) => {
|
|
43
|
+
const dateWithTime = addTimeToDate(prevValue);
|
|
44
|
+
if (dateWithTime !== prevValue && dateWithTime.length === DATE_WITH_TIME_LENGTH) {
|
|
45
|
+
onComplete?.(null, {
|
|
46
|
+
date: getFullDateTime(dateWithTime),
|
|
47
|
+
value: dateWithTime,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return dateWithTime;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
36
53
|
const handleInputWrapperFocus = (event) => {
|
|
37
54
|
if (view === 'desktop') {
|
|
55
|
+
if (picker) {
|
|
56
|
+
setOpen(true);
|
|
57
|
+
}
|
|
38
58
|
if (!open && event.target.tagName !== 'INPUT' && calendarRef.current) {
|
|
39
59
|
calendarRef.current.focus();
|
|
40
60
|
}
|
|
@@ -45,21 +65,21 @@ const DateTimeInput = React.forwardRef(({ className, inputClassName, popoverClas
|
|
|
45
65
|
const target = (event.relatedTarget || document.activeElement);
|
|
46
66
|
if (calendarRef.current && calendarRef.current.contains(target) === false) {
|
|
47
67
|
setOpen(false);
|
|
48
|
-
|
|
68
|
+
setTimeToDate();
|
|
49
69
|
}
|
|
50
70
|
}
|
|
51
71
|
};
|
|
52
72
|
const handleChange = (event) => {
|
|
53
73
|
const { value: newValue } = event.target;
|
|
54
|
-
if (newValue.length >
|
|
74
|
+
if (newValue.length > DATE_WITH_TIME_LENGTH)
|
|
55
75
|
return;
|
|
56
76
|
// Позволяем вводить только цифры, точки, запятую, двоеточие и пробел
|
|
57
|
-
if (/[^\d.,
|
|
77
|
+
if (/[^\d., :]/.test(newValue)) {
|
|
58
78
|
return;
|
|
59
79
|
}
|
|
60
80
|
const dots = newValue.match(/\./g);
|
|
61
|
-
const colon = newValue.match(
|
|
62
|
-
const comma = newValue.match(
|
|
81
|
+
const colon = newValue.match(/:/g);
|
|
82
|
+
const comma = newValue.match(/,/g);
|
|
63
83
|
// Не даем вводить больше, чем 2 точки, 1 двоеточие и 1 запятую
|
|
64
84
|
if ((dots && dots.length > 2) ||
|
|
65
85
|
(colon && colon.length > 1) ||
|
|
@@ -80,37 +100,38 @@ const DateTimeInput = React.forwardRef(({ className, inputClassName, popoverClas
|
|
|
80
100
|
}
|
|
81
101
|
}
|
|
82
102
|
};
|
|
83
|
-
const
|
|
103
|
+
const handleMobileCalendarClose = () => {
|
|
84
104
|
setOpen(false);
|
|
105
|
+
setTimeToDate();
|
|
85
106
|
};
|
|
86
107
|
const handleClear = () => {
|
|
87
108
|
setValue('');
|
|
88
109
|
};
|
|
89
110
|
const handleCalendarChange = (date) => {
|
|
90
111
|
if (date) {
|
|
91
|
-
|
|
112
|
+
const newValue = parseTimestampToDate(date);
|
|
113
|
+
setValue(newValue);
|
|
114
|
+
onChange?.(null, { date: getFullDateTime(newValue), value: newValue });
|
|
92
115
|
}
|
|
93
116
|
};
|
|
94
117
|
const handleCalendarWrapperMouseDown = (event) => {
|
|
95
118
|
// Не дает инпуту терять фокус при выборе даты
|
|
96
119
|
event.preventDefault();
|
|
97
120
|
};
|
|
98
|
-
const handleInputWrapperClick = () => {
|
|
99
|
-
if (view === 'desktop' && !open) {
|
|
100
|
-
setOpen(true);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
121
|
const handleIconButtonClick = () => {
|
|
104
122
|
if (!open)
|
|
105
123
|
setOpen(true);
|
|
124
|
+
if (view === 'desktop' && inputRef.current) {
|
|
125
|
+
inputRef.current.focus();
|
|
126
|
+
}
|
|
106
127
|
};
|
|
107
128
|
const renderCalendar = () => (
|
|
108
129
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
109
130
|
React.createElement("div", { onMouseDown: handleCalendarWrapperMouseDown },
|
|
110
|
-
React.createElement(Calendar$1, { ...calendarProps, responsive: calendarResponsive, open: open, onClose:
|
|
131
|
+
React.createElement(Calendar$1, { ...calendarProps, responsive: calendarResponsive, open: open, onClose: handleMobileCalendarClose, ref: calendarRef, defaultMonth: defaultMonth, value: checkInputValueIsValid(value) ? calendarValue : undefined, onChange: handleCalendarChange, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events })));
|
|
111
132
|
return (React.createElement("div", { className: cn(styles.component, className, {
|
|
112
133
|
[styles.block]: block,
|
|
113
|
-
}),
|
|
134
|
+
}), onFocus: inputDisabled ? undefined : handleInputWrapperFocus, onBlur: handleBlur },
|
|
114
135
|
React.createElement(Input, { ...restProps, block: block, ref: mergeRefs([ref, inputRef]), value: value, onChange: handleChange, disabled: disabled, readOnly: readOnly, className: inputClassName, onClear: handleClear, error: error, rightAddons: React.createElement(React.Fragment, null,
|
|
115
136
|
rightAddons,
|
|
116
137
|
picker && (React.createElement(IconButton, { onClick: inputDisabled ? undefined : handleIconButtonClick, icon: CalendarMIcon, size: 'xxs' }))) }),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* hash:
|
|
1
|
+
/* hash: 9vegz */
|
|
2
2
|
:root {
|
|
3
3
|
|
|
4
4
|
/* Hard */
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
--gap-m: 16px;
|
|
12
12
|
}
|
|
13
13
|
:root {
|
|
14
|
-
--border-radius-
|
|
14
|
+
--border-radius-m: 8px;
|
|
15
15
|
}
|
|
16
16
|
:root {
|
|
17
17
|
--calendar-width: 344px;
|
|
@@ -37,28 +37,28 @@
|
|
|
37
37
|
/* marker */
|
|
38
38
|
}
|
|
39
39
|
:root {
|
|
40
|
-
--calendar-popover-border-radius:
|
|
40
|
+
--calendar-popover-border-radius: var(--border-radius-m);
|
|
41
41
|
}
|
|
42
|
-
.date-time-
|
|
42
|
+
.date-time-input__component_wum5f {
|
|
43
43
|
display: inline-block;
|
|
44
44
|
outline: none;
|
|
45
45
|
position: relative;
|
|
46
46
|
}
|
|
47
|
-
.date-time-
|
|
47
|
+
.date-time-input__calendarContainer_wum5f {
|
|
48
48
|
display: inline-block;
|
|
49
49
|
box-sizing: border-box;
|
|
50
50
|
border-radius: var(--calendar-popover-border-radius)
|
|
51
51
|
}
|
|
52
52
|
@media (max-width: 374px) {
|
|
53
|
-
.date-time-
|
|
53
|
+
.date-time-input__calendarContainer_wum5f {
|
|
54
54
|
width: 100%;
|
|
55
55
|
min-width: 288px
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
.date-time-
|
|
58
|
+
.date-time-input__calendarResponsive_wum5f {
|
|
59
59
|
width: var(--calendar-width);
|
|
60
60
|
padding: 0 var(--gap-m);
|
|
61
61
|
}
|
|
62
|
-
.date-time-
|
|
62
|
+
.date-time-input__block_wum5f {
|
|
63
63
|
width: 100%;
|
|
64
64
|
}
|
|
@@ -6,6 +6,7 @@ import '@alfalab/core-components-calendar/modern';
|
|
|
6
6
|
import '@alfalab/core-components-icon-button/modern';
|
|
7
7
|
import '@alfalab/core-components-input/modern';
|
|
8
8
|
import '@alfalab/core-components-popover/modern';
|
|
9
|
+
import '@alfalab/hooks';
|
|
9
10
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
10
11
|
import '../../utils/format.js';
|
|
11
12
|
import 'date-fns/isValid';
|
package/modern/desktop.js
CHANGED
|
@@ -7,6 +7,7 @@ import '@alfalab/core-components-calendar/modern';
|
|
|
7
7
|
import '@alfalab/core-components-icon-button/modern';
|
|
8
8
|
import '@alfalab/core-components-input/modern';
|
|
9
9
|
import '@alfalab/core-components-popover/modern';
|
|
10
|
+
import '@alfalab/hooks';
|
|
10
11
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
11
12
|
import './utils/format.js';
|
|
12
13
|
import 'date-fns/isValid';
|
package/modern/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { DateTimeInputResponsive as DateTimeInput
|
|
1
|
+
export { DateTimeInputResponsive as DateTimeInput } from "./responsive";
|
|
2
|
+
export type { DateTimeInputResponsiveProps as DateTimeInputProps } from "./responsive";
|
package/modern/mobile.js
CHANGED
|
@@ -7,6 +7,7 @@ import 'classnames';
|
|
|
7
7
|
import '@alfalab/core-components-icon-button/modern';
|
|
8
8
|
import '@alfalab/core-components-input/modern';
|
|
9
9
|
import '@alfalab/core-components-popover/modern';
|
|
10
|
+
import '@alfalab/hooks';
|
|
10
11
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
11
12
|
import './utils/format.js';
|
|
12
13
|
import 'date-fns/isValid';
|
package/modern/utils/format.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
declare const DATE_FORMAT = "dd.MM.yyyy";
|
|
2
2
|
declare const DATE_MASK: (string | RegExp)[];
|
|
3
|
+
declare const DATE_WITH_TIME_LENGTH: number;
|
|
3
4
|
declare const isCompleteDateInput: (input: string) => boolean;
|
|
4
5
|
declare const parseDateString: (value: string, dateFormat?: string) => Date;
|
|
5
6
|
declare const isValidTimeFormat: (value: string) => boolean;
|
|
@@ -8,5 +9,5 @@ declare const format: (value: string) => string;
|
|
|
8
9
|
declare const parseTimestampToDate: (timestamp: number) => string;
|
|
9
10
|
declare const getDateWithoutTime: (value: string) => Date;
|
|
10
11
|
declare const getFullDateTime: (value: string) => Date;
|
|
11
|
-
declare const
|
|
12
|
-
export { DATE_FORMAT, DATE_MASK, isCompleteDateInput, parseDateString, isValidTimeFormat, isValid, format, parseTimestampToDate, getDateWithoutTime, getFullDateTime,
|
|
12
|
+
declare const addTimeToDate: (value: string) => string;
|
|
13
|
+
export { DATE_FORMAT, DATE_MASK, DATE_WITH_TIME_LENGTH, isCompleteDateInput, parseDateString, isValidTimeFormat, isValid, format, parseTimestampToDate, getDateWithoutTime, getFullDateTime, addTimeToDate };
|
package/modern/utils/format.js
CHANGED
|
@@ -22,7 +22,8 @@ const DATE_MASK = [
|
|
|
22
22
|
/\d/,
|
|
23
23
|
/\d/,
|
|
24
24
|
];
|
|
25
|
-
const
|
|
25
|
+
const DATE_WITH_TIME_LENGTH = DATE_MASK.length;
|
|
26
|
+
const isCompleteDateInput = (input) => input.length === DATE_WITH_TIME_LENGTH;
|
|
26
27
|
const parseDateString = (value, dateFormat = DATE_FORMAT) => parse(value, dateFormat, new Date());
|
|
27
28
|
const isValidTimeFormat = (value) => {
|
|
28
29
|
const timeArr = value.split(':');
|
|
@@ -111,13 +112,15 @@ const getFullDateTime = (value) => {
|
|
|
111
112
|
fullDate.setFullYear(Number(year), Number(month) - 1, Number(day));
|
|
112
113
|
fullDate.setHours(Number(hours) || 0);
|
|
113
114
|
fullDate.setMinutes(Number(mins) || 0);
|
|
115
|
+
fullDate.setSeconds(0);
|
|
116
|
+
fullDate.setMilliseconds(0);
|
|
114
117
|
return fullDate;
|
|
115
118
|
};
|
|
116
|
-
const
|
|
119
|
+
const addTimeToDate = (value) => {
|
|
117
120
|
if (value.length === 10 && dateFnsIsValid(parseDateString(value))) {
|
|
118
121
|
return `${value}, 00:00`;
|
|
119
122
|
}
|
|
120
123
|
return value;
|
|
121
124
|
};
|
|
122
125
|
|
|
123
|
-
export { DATE_FORMAT, DATE_MASK, format, getDateWithoutTime, getFullDateTime, isCompleteDateInput, isValid, isValidTimeFormat, parseDateString, parseTimestampToDate
|
|
126
|
+
export { DATE_FORMAT, DATE_MASK, DATE_WITH_TIME_LENGTH, addTimeToDate, format, getDateWithoutTime, getFullDateTime, isCompleteDateInput, isValid, isValidTimeFormat, parseDateString, parseTimestampToDate };
|
package/modern/utils/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { DATE_FORMAT, DATE_MASK, format, getDateWithoutTime, getFullDateTime, isCompleteDateInput, isValid, isValidTimeFormat, parseDateString, parseTimestampToDate
|
|
1
|
+
export { DATE_FORMAT, DATE_MASK, DATE_WITH_TIME_LENGTH, addTimeToDate, format, getDateWithoutTime, getFullDateTime, isCompleteDateInput, isValid, isValidTimeFormat, parseDateString, parseTimestampToDate } from './format.js';
|
|
2
2
|
import 'date-fns/isValid';
|
|
3
3
|
import 'date-fns/parse';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alfalab/core-components-date-time-input",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
"react-dom": "^16.9.0 || ^17.0.1 || ^18.0.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@alfalab/core-components-calendar": "^6.2.
|
|
19
|
-
"@alfalab/core-components-input": "^11.1.
|
|
18
|
+
"@alfalab/core-components-calendar": "^6.2.2",
|
|
19
|
+
"@alfalab/core-components-input": "^11.1.3",
|
|
20
20
|
"@alfalab/core-components-icon-button": "^6.0.2",
|
|
21
21
|
"@alfalab/core-components-popover": "^6.0.5",
|
|
22
|
+
"@alfalab/hooks": "^1.13.0",
|
|
22
23
|
"classnames": "^2.3.1"
|
|
23
24
|
}
|
|
24
25
|
}
|
package/responsive.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Component_responsive = require('./Component.responsive.js');
|
|
4
|
-
require('./Component-
|
|
4
|
+
require('./Component-1ff76732.js');
|
|
5
5
|
require('react');
|
|
6
6
|
require('react-merge-refs');
|
|
7
7
|
require('classnames');
|
|
@@ -9,11 +9,11 @@ require('@alfalab/core-components-calendar');
|
|
|
9
9
|
require('@alfalab/core-components-icon-button');
|
|
10
10
|
require('@alfalab/core-components-input');
|
|
11
11
|
require('@alfalab/core-components-popover');
|
|
12
|
+
require('@alfalab/hooks');
|
|
12
13
|
require('@alfalab/icons-glyph/CalendarMIcon');
|
|
13
14
|
require('./utils/format.js');
|
|
14
15
|
require('date-fns/isValid');
|
|
15
16
|
require('date-fns/parse');
|
|
16
|
-
require('@alfalab/hooks');
|
|
17
17
|
require('./Component.desktop.js');
|
|
18
18
|
require('./Component.mobile.js');
|
|
19
19
|
|
package/utils/format.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
declare const DATE_FORMAT = "dd.MM.yyyy";
|
|
2
2
|
declare const DATE_MASK: (string | RegExp)[];
|
|
3
|
+
declare const DATE_WITH_TIME_LENGTH: number;
|
|
3
4
|
declare const isCompleteDateInput: (input: string) => boolean;
|
|
4
5
|
declare const parseDateString: (value: string, dateFormat?: string) => Date;
|
|
5
6
|
declare const isValidTimeFormat: (value: string) => boolean;
|
|
@@ -8,5 +9,5 @@ declare const format: (value: string) => string;
|
|
|
8
9
|
declare const parseTimestampToDate: (timestamp: number) => string;
|
|
9
10
|
declare const getDateWithoutTime: (value: string) => Date;
|
|
10
11
|
declare const getFullDateTime: (value: string) => Date;
|
|
11
|
-
declare const
|
|
12
|
-
export { DATE_FORMAT, DATE_MASK, isCompleteDateInput, parseDateString, isValidTimeFormat, isValid, format, parseTimestampToDate, getDateWithoutTime, getFullDateTime,
|
|
12
|
+
declare const addTimeToDate: (value: string) => string;
|
|
13
|
+
export { DATE_FORMAT, DATE_MASK, DATE_WITH_TIME_LENGTH, isCompleteDateInput, parseDateString, isValidTimeFormat, isValid, format, parseTimestampToDate, getDateWithoutTime, getFullDateTime, addTimeToDate };
|
package/utils/format.js
CHANGED
|
@@ -29,7 +29,8 @@ var DATE_MASK = [
|
|
|
29
29
|
/\d/,
|
|
30
30
|
/\d/,
|
|
31
31
|
];
|
|
32
|
-
var
|
|
32
|
+
var DATE_WITH_TIME_LENGTH = DATE_MASK.length;
|
|
33
|
+
var isCompleteDateInput = function (input) { return input.length === DATE_WITH_TIME_LENGTH; };
|
|
33
34
|
var parseDateString = function (value, dateFormat) {
|
|
34
35
|
if (dateFormat === void 0) { dateFormat = DATE_FORMAT; }
|
|
35
36
|
return parse__default.default(value, dateFormat, new Date());
|
|
@@ -123,9 +124,11 @@ var getFullDateTime = function (value) {
|
|
|
123
124
|
fullDate.setFullYear(Number(year), Number(month) - 1, Number(day));
|
|
124
125
|
fullDate.setHours(Number(hours) || 0);
|
|
125
126
|
fullDate.setMinutes(Number(mins) || 0);
|
|
127
|
+
fullDate.setSeconds(0);
|
|
128
|
+
fullDate.setMilliseconds(0);
|
|
126
129
|
return fullDate;
|
|
127
130
|
};
|
|
128
|
-
var
|
|
131
|
+
var addTimeToDate = function (value) {
|
|
129
132
|
if (value.length === 10 && dateFnsIsValid__default.default(parseDateString(value))) {
|
|
130
133
|
return "".concat(value, ", 00:00");
|
|
131
134
|
}
|
|
@@ -134,6 +137,8 @@ var setTimeToDate = function (value) {
|
|
|
134
137
|
|
|
135
138
|
exports.DATE_FORMAT = DATE_FORMAT;
|
|
136
139
|
exports.DATE_MASK = DATE_MASK;
|
|
140
|
+
exports.DATE_WITH_TIME_LENGTH = DATE_WITH_TIME_LENGTH;
|
|
141
|
+
exports.addTimeToDate = addTimeToDate;
|
|
137
142
|
exports.format = format;
|
|
138
143
|
exports.getDateWithoutTime = getDateWithoutTime;
|
|
139
144
|
exports.getFullDateTime = getFullDateTime;
|
|
@@ -142,4 +147,3 @@ exports.isValid = isValid;
|
|
|
142
147
|
exports.isValidTimeFormat = isValidTimeFormat;
|
|
143
148
|
exports.parseDateString = parseDateString;
|
|
144
149
|
exports.parseTimestampToDate = parseTimestampToDate;
|
|
145
|
-
exports.setTimeToDate = setTimeToDate;
|
package/utils/index.js
CHANGED
|
@@ -8,6 +8,8 @@ require('date-fns/parse');
|
|
|
8
8
|
|
|
9
9
|
exports.DATE_FORMAT = utils_format.DATE_FORMAT;
|
|
10
10
|
exports.DATE_MASK = utils_format.DATE_MASK;
|
|
11
|
+
exports.DATE_WITH_TIME_LENGTH = utils_format.DATE_WITH_TIME_LENGTH;
|
|
12
|
+
exports.addTimeToDate = utils_format.addTimeToDate;
|
|
11
13
|
exports.format = utils_format.format;
|
|
12
14
|
exports.getDateWithoutTime = utils_format.getDateWithoutTime;
|
|
13
15
|
exports.getFullDateTime = utils_format.getFullDateTime;
|
|
@@ -16,4 +18,3 @@ exports.isValid = utils_format.isValid;
|
|
|
16
18
|
exports.isValidTimeFormat = utils_format.isValidTimeFormat;
|
|
17
19
|
exports.parseDateString = utils_format.parseDateString;
|
|
18
20
|
exports.parseTimestampToDate = utils_format.parseTimestampToDate;
|
|
19
|
-
exports.setTimeToDate = utils_format.setTimeToDate;
|