@alfalab/core-components-date-time-input 3.0.6 → 3.0.7
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.desktop.d.ts +4 -3
- package/Component.desktop.js +3 -2
- package/Component.mobile.d.ts +4 -3
- package/Component.mobile.js +3 -2
- package/Component.responsive.d.ts +10 -3
- package/Component.responsive.js +6 -5
- package/components/date-time-input/Component.d.ts +192 -0
- package/components/date-time-input/Component.js +148 -12
- package/components/date-time-input/index.css +6 -6
- package/components/date-time-input/index.d.ts +1 -1
- package/components/date-time-input/index.js +2 -1
- package/cssm/Component.desktop.d.ts +4 -3
- package/cssm/Component.desktop.js +3 -2
- package/cssm/Component.mobile.d.ts +4 -3
- package/cssm/Component.mobile.js +3 -2
- package/cssm/Component.responsive.d.ts +10 -3
- package/cssm/Component.responsive.js +6 -5
- package/cssm/components/date-time-input/Component.d.ts +192 -0
- package/cssm/components/date-time-input/Component.js +147 -13
- package/cssm/components/date-time-input/index.d.ts +1 -1
- package/cssm/components/date-time-input/index.js +2 -1
- package/cssm/desktop.js +2 -1
- package/cssm/index.js +4 -3
- package/cssm/mobile.js +3 -2
- package/cssm/responsive.js +4 -3
- package/desktop.js +2 -1
- package/esm/Component.desktop.d.ts +4 -3
- package/esm/Component.desktop.js +4 -3
- package/esm/Component.mobile.d.ts +4 -3
- package/esm/Component.mobile.js +4 -3
- package/esm/Component.responsive.d.ts +10 -3
- package/esm/Component.responsive.js +6 -5
- package/esm/components/date-time-input/Component.d.ts +192 -0
- package/esm/components/date-time-input/Component.js +145 -11
- package/esm/components/date-time-input/index.css +6 -6
- 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.js +4 -3
- package/esm/mobile.js +3 -2
- package/esm/responsive.js +4 -3
- package/index.js +4 -3
- package/mobile.js +3 -2
- package/modern/Component.desktop.d.ts +3 -2
- package/modern/Component.desktop.js +2 -2
- package/modern/Component.mobile.d.ts +3 -2
- package/modern/Component.mobile.js +2 -2
- package/modern/Component.responsive.d.ts +9 -2
- package/modern/Component.responsive.js +4 -4
- package/modern/components/date-time-input/Component.js +1 -1
- package/modern/components/date-time-input/index.css +6 -6
- package/package.json +7 -6
- package/responsive.js +4 -3
- package/Component-45618e75.d.ts +0 -225
- package/Component-45618e75.js +0 -192
- package/cssm/Component-b91f18e8.d.ts +0 -225
- package/cssm/Component-b91f18e8.js +0 -191
- package/esm/Component-9d1d72a0.d.ts +0 -225
- package/esm/Component-9d1d72a0.js +0 -183
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useState, useEffect } from 'react';
|
|
2
|
-
import mergeRefs from 'react-merge-refs';
|
|
3
|
-
import cn from 'classnames';
|
|
4
|
-
import { Calendar, dateInLimits } from '@alfalab/core-components-calendar/esm';
|
|
5
|
-
import { IconButton } from '@alfalab/core-components-icon-button/esm';
|
|
6
|
-
import { Input } from '@alfalab/core-components-input/esm';
|
|
7
|
-
import { Popover } from '@alfalab/core-components-popover/esm';
|
|
8
|
-
import { useDidUpdateEffect } from '@alfalab/hooks';
|
|
9
|
-
import { CalendarMIcon } from '@alfalab/icons-glyph/CalendarMIcon';
|
|
10
|
-
import { getDateWithoutTime, DATE_WITH_TIME_LENGTH, format, getFullDateTime, isCompleteDateInput, isValid, addTimeToDate, parseTimestampToDate } from './utils/format.js';
|
|
11
|
-
|
|
12
|
-
/******************************************************************************
|
|
13
|
-
Copyright (c) Microsoft Corporation.
|
|
14
|
-
|
|
15
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
16
|
-
purpose with or without fee is hereby granted.
|
|
17
|
-
|
|
18
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
19
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
20
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
21
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
22
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
23
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
24
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
25
|
-
***************************************************************************** */
|
|
26
|
-
var __assign = function () {
|
|
27
|
-
__assign = Object.assign || function __assign(t) {
|
|
28
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
29
|
-
s = arguments[i];
|
|
30
|
-
for (var p in s)
|
|
31
|
-
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
32
|
-
t[p] = s[p];
|
|
33
|
-
}
|
|
34
|
-
return t;
|
|
35
|
-
};
|
|
36
|
-
return __assign.apply(this, arguments);
|
|
37
|
-
};
|
|
38
|
-
function __rest(s, e) {
|
|
39
|
-
var t = {};
|
|
40
|
-
for (var p in s)
|
|
41
|
-
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
42
|
-
t[p] = s[p];
|
|
43
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
44
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
45
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
46
|
-
t[p[i]] = s[p[i]];
|
|
47
|
-
}
|
|
48
|
-
return t;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var styles = {"component":"date-time-input__component_sjtx8","calendarContainer":"date-time-input__calendarContainer_sjtx8","calendarResponsive":"date-time-input__calendarResponsive_sjtx8","block":"date-time-input__block_sjtx8"};
|
|
52
|
-
require('./components/date-time-input/index.css')
|
|
53
|
-
|
|
54
|
-
/* eslint-disable no-useless-escape, jsx-a11y/click-events-have-key-events */
|
|
55
|
-
var DateTimeInput = React.forwardRef(function (_a, ref) {
|
|
56
|
-
var _b, _c;
|
|
57
|
-
var _d;
|
|
58
|
-
var className = _a.className, inputClassName = _a.inputClassName, popoverClassName = _a.popoverClassName, disabled = _a.disabled, readOnly = _a.readOnly, picker = _a.picker, _e = _a.defaultValue, defaultValue = _e === void 0 ? '' : _e, propValue = _a.value, onChange = _a.onChange, onComplete = _a.onComplete, rightAddons = _a.rightAddons, useAnchorWidth = _a.useAnchorWidth, block = _a.block, _f = _a.popoverPosition, popoverPosition = _f === void 0 ? 'bottom-start' : _f, zIndexPopover = _a.zIndexPopover, preventFlip = _a.preventFlip, _g = _a.Calendar, Calendar$1 = _g === void 0 ? Calendar : _g, _h = _a.calendarProps, calendarProps = _h === void 0 ? {} : _h, defaultMonth = _a.defaultMonth, _j = _a.minDate, minDate = _j === void 0 ? calendarProps.minDate : _j, _k = _a.maxDate, maxDate = _k === void 0 ? calendarProps.maxDate : _k, _l = _a.offDays, offDays = _l === void 0 ? calendarProps.offDays || [] : _l, _m = _a.events, events = _m === void 0 ? calendarProps.events || [] : _m, _o = _a.defaultOpen, defaultOpen = _o === void 0 ? false : _o, error = _a.error, _p = _a.view, view = _p === void 0 ? 'desktop' : _p, restProps = __rest(_a, ["className", "inputClassName", "popoverClassName", "disabled", "readOnly", "picker", "defaultValue", "value", "onChange", "onComplete", "rightAddons", "useAnchorWidth", "block", "popoverPosition", "zIndexPopover", "preventFlip", "Calendar", "calendarProps", "defaultMonth", "minDate", "maxDate", "offDays", "events", "defaultOpen", "error", "view"]);
|
|
59
|
-
var inputRef = useRef(null);
|
|
60
|
-
var calendarRef = useRef(null);
|
|
61
|
-
var _q = useState(propValue || defaultValue), value = _q[0], setValue = _q[1];
|
|
62
|
-
var _r = useState(false), open = _r[0], setOpen = _r[1];
|
|
63
|
-
var calendarValue = value ? getDateWithoutTime(value).getTime() : undefined;
|
|
64
|
-
var inputDisabled = disabled || readOnly;
|
|
65
|
-
var calendarResponsive = (_d = calendarProps === null || calendarProps === void 0 ? void 0 : calendarProps.responsive) !== null && _d !== void 0 ? _d : true;
|
|
66
|
-
useEffect(function () {
|
|
67
|
-
setOpen(defaultOpen);
|
|
68
|
-
}, [defaultOpen]);
|
|
69
|
-
useDidUpdateEffect(function () {
|
|
70
|
-
var newPropValue = propValue || '';
|
|
71
|
-
setValue(function (prevValue) { return (prevValue === propValue ? prevValue : newPropValue); });
|
|
72
|
-
}, [propValue]);
|
|
73
|
-
var checkInputValueIsValid = function (newInputValue) {
|
|
74
|
-
if (!newInputValue || error)
|
|
75
|
-
return false;
|
|
76
|
-
var dateValue = getDateWithoutTime(newInputValue).getTime();
|
|
77
|
-
return (dateValue &&
|
|
78
|
-
dateInLimits(dateValue, minDate, maxDate) &&
|
|
79
|
-
!offDays.includes(dateValue));
|
|
80
|
-
};
|
|
81
|
-
var setTimeToDate = function () {
|
|
82
|
-
setValue(function (prevValue) {
|
|
83
|
-
var dateWithTime = addTimeToDate(prevValue);
|
|
84
|
-
if (dateWithTime !== prevValue && dateWithTime.length === DATE_WITH_TIME_LENGTH) {
|
|
85
|
-
onComplete === null || onComplete === void 0 ? void 0 : onComplete(null, {
|
|
86
|
-
date: getFullDateTime(dateWithTime),
|
|
87
|
-
value: dateWithTime,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
return dateWithTime;
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
var handleInputWrapperFocus = function (event) {
|
|
94
|
-
if (view === 'desktop') {
|
|
95
|
-
if (picker) {
|
|
96
|
-
setOpen(true);
|
|
97
|
-
}
|
|
98
|
-
if (!open && event.target.tagName !== 'INPUT' && calendarRef.current) {
|
|
99
|
-
calendarRef.current.focus();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
var handleBlur = function (event) {
|
|
104
|
-
if (view === 'desktop') {
|
|
105
|
-
var target = (event.relatedTarget || document.activeElement);
|
|
106
|
-
if (calendarRef.current && calendarRef.current.contains(target) === false) {
|
|
107
|
-
setOpen(false);
|
|
108
|
-
setTimeToDate();
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
var handleChange = function (event) {
|
|
113
|
-
var newValue = event.target.value;
|
|
114
|
-
if (newValue.length > DATE_WITH_TIME_LENGTH)
|
|
115
|
-
return;
|
|
116
|
-
// Позволяем вводить только цифры, точки, запятую, двоеточие и пробел
|
|
117
|
-
if (/[^\d., :]/.test(newValue)) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
var dots = newValue.match(/\./g);
|
|
121
|
-
var colon = newValue.match(/:/g);
|
|
122
|
-
var comma = newValue.match(/,/g);
|
|
123
|
-
// Не даем вводить больше, чем 2 точки, 1 двоеточие и 1 запятую
|
|
124
|
-
if ((dots && dots.length > 2) ||
|
|
125
|
-
(colon && colon.length > 1) ||
|
|
126
|
-
(comma && comma.length > 1)) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
var formattedValue = format(newValue);
|
|
130
|
-
var date = getFullDateTime(formattedValue);
|
|
131
|
-
setValue(formattedValue);
|
|
132
|
-
if (onChange)
|
|
133
|
-
onChange(event, { date: date, value: formattedValue });
|
|
134
|
-
if (isCompleteDateInput(formattedValue)) {
|
|
135
|
-
var valid = isValid(formattedValue);
|
|
136
|
-
if (!valid)
|
|
137
|
-
return;
|
|
138
|
-
if (onComplete) {
|
|
139
|
-
onComplete(event, { date: date, value: formattedValue });
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
var handleMobileCalendarClose = function () {
|
|
144
|
-
setOpen(false);
|
|
145
|
-
setTimeToDate();
|
|
146
|
-
};
|
|
147
|
-
var handleClear = function () {
|
|
148
|
-
setValue('');
|
|
149
|
-
};
|
|
150
|
-
var handleCalendarChange = function (date) {
|
|
151
|
-
if (date) {
|
|
152
|
-
var newValue = parseTimestampToDate(date);
|
|
153
|
-
setValue(newValue);
|
|
154
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(null, { date: getFullDateTime(newValue), value: newValue });
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
var handleCalendarWrapperMouseDown = function (event) {
|
|
158
|
-
// Не дает инпуту терять фокус при выборе даты
|
|
159
|
-
event.preventDefault();
|
|
160
|
-
};
|
|
161
|
-
var handleIconButtonClick = function () {
|
|
162
|
-
if (!open)
|
|
163
|
-
setOpen(true);
|
|
164
|
-
if (view === 'desktop' && inputRef.current) {
|
|
165
|
-
inputRef.current.focus();
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
var renderCalendar = function () { return (
|
|
169
|
-
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
170
|
-
React.createElement("div", { onMouseDown: handleCalendarWrapperMouseDown },
|
|
171
|
-
React.createElement(Calendar$1, __assign({}, 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 })))); };
|
|
172
|
-
return (React.createElement("div", { className: cn(styles.component, className, (_b = {},
|
|
173
|
-
_b[styles.block] = block,
|
|
174
|
-
_b)), onFocus: inputDisabled ? undefined : handleInputWrapperFocus, onBlur: handleBlur },
|
|
175
|
-
React.createElement(Input, __assign({}, 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,
|
|
176
|
-
rightAddons,
|
|
177
|
-
picker && (React.createElement(IconButton, { onClick: inputDisabled ? undefined : handleIconButtonClick, icon: CalendarMIcon, size: 'xxs' }))) })),
|
|
178
|
-
picker && (React.createElement(Popover, { open: open, useAnchorWidth: useAnchorWidth, anchorElement: inputRef.current, popperClassName: cn(styles.calendarContainer, (_c = {},
|
|
179
|
-
_c[styles.calendarResponsive] = calendarResponsive,
|
|
180
|
-
_c)), className: popoverClassName, position: popoverPosition, offset: [0, 8], withTransition: false, preventFlip: preventFlip, zIndex: zIndexPopover }, renderCalendar()))));
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
export { DateTimeInput as D, __assign as _, __rest as a };
|