@alfalab/core-components-calendar-input 8.2.7 → 8.2.9
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/calendar-input/Component.d.ts +216 -0
- package/components/calendar-input/Component.js +135 -10
- package/components/calendar-input/index.css +11 -11
- package/components/calendar-input/index.d.ts +1 -1
- package/components/calendar-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/calendar-input/Component.d.ts +216 -0
- package/cssm/components/calendar-input/Component.js +134 -11
- package/cssm/components/calendar-input/index.d.ts +1 -1
- package/cssm/components/calendar-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/calendar-input/Component.d.ts +216 -0
- package/esm/components/calendar-input/Component.js +132 -9
- package/esm/components/calendar-input/index.css +11 -11
- package/esm/components/calendar-input/index.d.ts +1 -1
- package/esm/components/calendar-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/calendar-input/Component.js +1 -1
- package/modern/components/calendar-input/index.css +11 -11
- package/package.json +6 -5
- package/responsive.js +4 -3
- package/Component-e779a21c.d.ts +0 -249
- package/Component-e779a21c.js +0 -179
- package/cssm/Component-fde0c12c.d.ts +0 -249
- package/cssm/Component-fde0c12c.js +0 -178
- package/esm/Component-e2c1f213.d.ts +0 -249
- package/esm/Component-e2c1f213.js +0 -170
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef, useState, useCallback, useRef, useEffect } from 'react';
|
|
2
|
-
import mergeRefs from 'react-merge-refs';
|
|
3
|
-
import cn from 'classnames';
|
|
4
|
-
import { dateInLimits, Calendar } from '@alfalab/core-components-calendar/esm';
|
|
5
|
-
import { parseDateString, isCompleteDateInput, formatDate, DateInput } from '@alfalab/core-components-date-input/esm';
|
|
6
|
-
import { Popover } from '@alfalab/core-components-popover/esm';
|
|
7
|
-
import { CalendarMIcon } from '@alfalab/icons-glyph/CalendarMIcon';
|
|
8
|
-
import { SUPPORTS_INPUT_TYPE_DATE } from './utils.js';
|
|
9
|
-
|
|
10
|
-
/******************************************************************************
|
|
11
|
-
Copyright (c) Microsoft Corporation.
|
|
12
|
-
|
|
13
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
14
|
-
purpose with or without fee is hereby granted.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
17
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
18
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
19
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
20
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
21
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
22
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
23
|
-
***************************************************************************** */
|
|
24
|
-
var __assign = function () {
|
|
25
|
-
__assign = Object.assign || function __assign(t) {
|
|
26
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
27
|
-
s = arguments[i];
|
|
28
|
-
for (var p in s)
|
|
29
|
-
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
30
|
-
t[p] = s[p];
|
|
31
|
-
}
|
|
32
|
-
return t;
|
|
33
|
-
};
|
|
34
|
-
return __assign.apply(this, arguments);
|
|
35
|
-
};
|
|
36
|
-
function __rest(s, e) {
|
|
37
|
-
var t = {};
|
|
38
|
-
for (var p in s)
|
|
39
|
-
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
40
|
-
t[p] = s[p];
|
|
41
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
42
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
43
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
44
|
-
t[p[i]] = s[p[i]];
|
|
45
|
-
}
|
|
46
|
-
return t;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
var styles = {"component":"calendar-input__component_14cog","block":"calendar-input__block_14cog","calendarContainer":"calendar-input__calendarContainer_14cog","calendarResponsive":"calendar-input__calendarResponsive_14cog","calendarIcon":"calendar-input__calendarIcon_14cog","nativeInput":"calendar-input__nativeInput_14cog"};
|
|
50
|
-
require('./components/calendar-input/index.css')
|
|
51
|
-
|
|
52
|
-
var CalendarInput = forwardRef(function (_a, ref) {
|
|
53
|
-
var _b, _c;
|
|
54
|
-
var _d;
|
|
55
|
-
var _e = _a.block, block = _e === void 0 ? false : _e, className = _a.className; _a.inputClassName; var popoverClassName = _a.popoverClassName, _f = _a.defaultOpen, defaultOpen = _f === void 0 ? false : _f, defaultMonth = _a.defaultMonth, _g = _a.defaultValue, defaultValue = _g === void 0 ? '' : _g, _h = _a.calendarPosition, calendarPosition = _h === void 0 ? 'popover' : _h, value = _a.value, dataTestId = _a.dataTestId, _j = _a.calendarProps, calendarProps = _j === void 0 ? {} : _j, _k = _a.minDate, minDate = _k === void 0 ? calendarProps.minDate : _k, _l = _a.maxDate, maxDate = _l === void 0 ? calendarProps.maxDate : _l, _m = _a.offDays, offDays = _m === void 0 ? calendarProps.offDays || [] : _m, _o = _a.events, events = _o === void 0 ? calendarProps.events || [] : _o, preventFlip = _a.preventFlip, _p = _a.mobileMode, mobileMode = _p === void 0 ? 'popover' : _p, _q = _a.wrapperRef, wrapperRef = _q === void 0 ? null : _q, disabled = _a.disabled, _r = _a.onChange, onChange = _r === void 0 ? function () { return null; } : _r, onInputChange = _a.onInputChange, onCalendarChange = _a.onCalendarChange, onKeyDown = _a.onKeyDown, readOnly = _a.readOnly, _s = _a.Calendar, Calendar$1 = _s === void 0 ? Calendar : _s, _t = _a.popoverPosition, popoverPosition = _t === void 0 ? 'bottom-start' : _t, zIndexPopover = _a.zIndexPopover, useAnchorWidth = _a.useAnchorWidth, rightAddons = _a.rightAddons, error = _a.error, _u = _a.view, view = _u === void 0 ? 'desktop' : _u, restProps = __rest(_a, ["block", "className", "inputClassName", "popoverClassName", "defaultOpen", "defaultMonth", "defaultValue", "calendarPosition", "value", "dataTestId", "calendarProps", "minDate", "maxDate", "offDays", "events", "preventFlip", "mobileMode", "wrapperRef", "disabled", "onChange", "onInputChange", "onCalendarChange", "onKeyDown", "readOnly", "Calendar", "popoverPosition", "zIndexPopover", "useAnchorWidth", "rightAddons", "error", "view"]);
|
|
56
|
-
var calendarResponsive = (_d = calendarProps === null || calendarProps === void 0 ? void 0 : calendarProps.responsive) !== null && _d !== void 0 ? _d : true;
|
|
57
|
-
var shouldRenderNative = SUPPORTS_INPUT_TYPE_DATE && mobileMode === 'native';
|
|
58
|
-
var shouldRenderOnlyInput = mobileMode === 'input';
|
|
59
|
-
var shouldRenderStatic = calendarPosition === 'static' && !shouldRenderOnlyInput;
|
|
60
|
-
var shouldRenderPopover = calendarPosition === 'popover' && !shouldRenderNative && !shouldRenderOnlyInput;
|
|
61
|
-
var _v = useState(false), open = _v[0], setOpen = _v[1];
|
|
62
|
-
var _w = useState(value || defaultValue), inputValue = _w[0], setInputValue = _w[1];
|
|
63
|
-
var calendarValue = inputValue ? parseDateString(inputValue).getTime() : undefined;
|
|
64
|
-
var checkInputValueIsValid = useCallback(function (newInputValue) {
|
|
65
|
-
if (!newInputValue)
|
|
66
|
-
return false;
|
|
67
|
-
var dateValue = parseDateString(newInputValue).getTime();
|
|
68
|
-
return !!(dateValue &&
|
|
69
|
-
isCompleteDateInput(newInputValue) &&
|
|
70
|
-
dateInLimits(dateValue, minDate, maxDate) &&
|
|
71
|
-
!offDays.includes(dateValue));
|
|
72
|
-
}, [maxDate, minDate, offDays]);
|
|
73
|
-
var inputDisabled = disabled || readOnly;
|
|
74
|
-
var inputWrapperRef = useRef(null);
|
|
75
|
-
var calendarRef = useRef(null);
|
|
76
|
-
var handleKeyDown = useCallback(function (event) {
|
|
77
|
-
if (event.target.tagName === 'INPUT' && event.key === 'Enter') {
|
|
78
|
-
setOpen(!open);
|
|
79
|
-
}
|
|
80
|
-
if (event.key === 'Escape') {
|
|
81
|
-
setOpen(false);
|
|
82
|
-
}
|
|
83
|
-
}, [open]);
|
|
84
|
-
var handleClick = useCallback(function () {
|
|
85
|
-
if (!open)
|
|
86
|
-
setOpen(true);
|
|
87
|
-
}, [open]);
|
|
88
|
-
var handleFocus = useCallback(function (event) {
|
|
89
|
-
if (view === 'desktop') {
|
|
90
|
-
setOpen(true);
|
|
91
|
-
if (!open && event.target.tagName !== 'INPUT' && calendarRef.current) {
|
|
92
|
-
calendarRef.current.focus();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}, [open, view]);
|
|
96
|
-
var handleBlur = useCallback(function (event) {
|
|
97
|
-
if (view === 'desktop') {
|
|
98
|
-
var target = (event.relatedTarget || document.activeElement);
|
|
99
|
-
if (calendarRef.current && calendarRef.current.contains(target) === false) {
|
|
100
|
-
setOpen(false);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}, [view]);
|
|
104
|
-
var handleInputKeyDown = useCallback(function (event) {
|
|
105
|
-
if (['ArrowDown', 'ArrowUp'].includes(event.key) && calendarRef.current) {
|
|
106
|
-
event.preventDefault();
|
|
107
|
-
calendarRef.current.focus();
|
|
108
|
-
}
|
|
109
|
-
if (onKeyDown)
|
|
110
|
-
onKeyDown(event);
|
|
111
|
-
}, [onKeyDown]);
|
|
112
|
-
var changeHandler = useCallback(function (event, newValue, newDate, initiator, shouldChange) {
|
|
113
|
-
if (initiator === void 0) { initiator = 'input'; }
|
|
114
|
-
if (shouldChange === void 0) { shouldChange = true; }
|
|
115
|
-
if (initiator === 'input' && event && onInputChange) {
|
|
116
|
-
onInputChange(event, { value: newValue, date: newDate });
|
|
117
|
-
}
|
|
118
|
-
if (initiator === 'calendar' && onCalendarChange) {
|
|
119
|
-
onCalendarChange(newDate.getTime());
|
|
120
|
-
}
|
|
121
|
-
setInputValue(newValue);
|
|
122
|
-
if (shouldChange) {
|
|
123
|
-
onChange(event, { date: newDate, value: newValue });
|
|
124
|
-
}
|
|
125
|
-
}, [onCalendarChange, onChange, onInputChange]);
|
|
126
|
-
var handleInputChange = useCallback(function (event, payload) {
|
|
127
|
-
changeHandler(event, payload.value, payload.date, 'input', !payload.value || checkInputValueIsValid(payload.value));
|
|
128
|
-
}, [changeHandler, checkInputValueIsValid]);
|
|
129
|
-
var handleCalendarChange = useCallback(function (date) {
|
|
130
|
-
if (date) {
|
|
131
|
-
changeHandler(null, formatDate(date), new Date(date), 'calendar');
|
|
132
|
-
}
|
|
133
|
-
if (view === 'desktop') {
|
|
134
|
-
setOpen(false);
|
|
135
|
-
}
|
|
136
|
-
}, [changeHandler, view]);
|
|
137
|
-
var handleCalendarWrapperMouseDown = useCallback(function (event) {
|
|
138
|
-
// Не дает инпуту терять фокус при выборе даты
|
|
139
|
-
event.preventDefault();
|
|
140
|
-
}, []);
|
|
141
|
-
var handleCalendarClose = useCallback(function () {
|
|
142
|
-
setOpen(false);
|
|
143
|
-
}, []);
|
|
144
|
-
useEffect(function () {
|
|
145
|
-
setOpen(defaultOpen);
|
|
146
|
-
}, [defaultOpen]);
|
|
147
|
-
useEffect(function () {
|
|
148
|
-
if (typeof value !== 'undefined') {
|
|
149
|
-
setInputValue(value);
|
|
150
|
-
}
|
|
151
|
-
}, [value]);
|
|
152
|
-
var renderCalendar = function () { return (
|
|
153
|
-
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
154
|
-
React.createElement("div", { onMouseDown: handleCalendarWrapperMouseDown },
|
|
155
|
-
React.createElement(Calendar$1, __assign({}, calendarProps, { responsive: calendarResponsive, open: open, onClose: handleCalendarClose, ref: calendarRef, defaultMonth: defaultMonth, value: checkInputValueIsValid(inputValue) ? calendarValue : undefined, onChange: handleCalendarChange, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events })))); };
|
|
156
|
-
return (
|
|
157
|
-
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
158
|
-
React.createElement("div", { className: cn(styles.component, className, (_b = {},
|
|
159
|
-
_b[styles.block] = block,
|
|
160
|
-
_b)), tabIndex: -1, onKeyDown: inputDisabled ? undefined : handleKeyDown, onClick: inputDisabled ? undefined : handleClick, onFocus: inputDisabled ? undefined : handleFocus, onBlur: handleBlur, "data-test-id": dataTestId },
|
|
161
|
-
React.createElement(DateInput, __assign({}, restProps, { ref: ref, wrapperRef: mergeRefs([wrapperRef, inputWrapperRef]), value: inputValue, defaultValue: defaultValue, disabled: disabled, readOnly: readOnly, mobileMode: mobileMode === 'native' ? 'native' : 'input', error: error, rightAddons: React.createElement(React.Fragment, null,
|
|
162
|
-
rightAddons,
|
|
163
|
-
shouldRenderPopover && (React.createElement(CalendarMIcon, { className: styles.calendarIcon }))), onKeyDown: handleInputKeyDown, onChange: handleInputChange, block: true })),
|
|
164
|
-
shouldRenderStatic && renderCalendar(),
|
|
165
|
-
shouldRenderPopover && (React.createElement(Popover, { open: open, useAnchorWidth: useAnchorWidth, anchorElement: inputWrapperRef.current, popperClassName: cn(styles.calendarContainer, (_c = {},
|
|
166
|
-
_c[styles.calendarResponsive] = calendarResponsive,
|
|
167
|
-
_c)), className: popoverClassName, position: popoverPosition, offset: [0, 4], withTransition: false, preventFlip: preventFlip, zIndex: zIndexPopover }, renderCalendar()))));
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
export { CalendarInput as C, __assign as _, __rest as a };
|