@alfalab/core-components-calendar-input 5.2.7 → 6.1.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/CHANGELOG.md +89 -0
- package/dist/Component.d.ts +9 -1
- package/dist/Component.js +35 -24
- package/dist/cssm/Component.d.ts +9 -1
- package/dist/cssm/Component.js +34 -23
- package/dist/cssm/index.js +6 -4
- package/dist/cssm/index.module.css +2 -7
- package/dist/cssm/utils.d.ts +2 -2
- package/dist/cssm/utils.js +24 -5
- package/dist/esm/Component.d.ts +9 -1
- package/dist/esm/Component.js +36 -25
- package/dist/esm/index.css +12 -17
- package/dist/esm/index.js +5 -3
- package/dist/esm/utils.d.ts +2 -2
- package/dist/esm/utils.js +16 -3
- package/dist/index.css +12 -17
- package/dist/index.js +5 -3
- package/dist/modern/Component.d.ts +9 -1
- package/dist/modern/Component.js +35 -24
- package/dist/modern/index.css +12 -17
- package/dist/modern/index.js +5 -3
- package/dist/modern/utils.d.ts +2 -2
- package/dist/modern/utils.js +15 -3
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +24 -5
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,95 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [6.1.0](https://github.com/alfa-laboratory/core-components/compare/@alfalab/core-components-calendar-input@6.0.0...@alfalab/core-components-calendar-input@6.1.0) (2022-03-01)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* changed dropdown component's box shadow styles ([#1010](https://github.com/alfa-laboratory/core-components/issues/1010)) ([2f997f5](https://github.com/alfa-laboratory/core-components/commit/2f997f5722c89b38a8064924b73c0a8046025aea))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* Исправить импорты в сторях. ([#998](https://github.com/alfa-laboratory/core-components/issues/998)) ([e6a654a](https://github.com/alfa-laboratory/core-components/commit/e6a654a0599451c7d149484cb61d8067eed083b7))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# [6.0.0](https://github.com/alfa-laboratory/core-components/compare/@alfalab/core-components-calendar-input@5.3.0...@alfalab/core-components-calendar-input@6.0.0) (2022-02-17)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
* refactor/calendar-range (#984) ([714f615](https://github.com/alfa-laboratory/core-components/commit/714f61590586bafe1060e652943e95c133ed002a)), closes [#984](https://github.com/alfa-laboratory/core-components/issues/984)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### BREAKING CHANGES
|
|
29
|
+
|
|
30
|
+
* Большое обновление CalendarRange
|
|
31
|
+
|
|
32
|
+
* feat(date-input): add some improvements
|
|
33
|
+
|
|
34
|
+
* feat(date-input): some updates
|
|
35
|
+
|
|
36
|
+
* feat(date-input): validation
|
|
37
|
+
|
|
38
|
+
* feat(calendar): change period selection logic
|
|
39
|
+
|
|
40
|
+
* fix(calendar): range styles
|
|
41
|
+
|
|
42
|
+
* fix(calendar): fix styles, add rangeComplete flag
|
|
43
|
+
|
|
44
|
+
* refactor(calendar-range): temporary
|
|
45
|
+
|
|
46
|
+
* fix(calendar-range): fix hook
|
|
47
|
+
|
|
48
|
+
* fix(calendar-range): fix period
|
|
49
|
+
|
|
50
|
+
* fix(calendar-range): fix tests, fix max date
|
|
51
|
+
|
|
52
|
+
* fix: update exports
|
|
53
|
+
|
|
54
|
+
* feat(calendar): allow empty values for PeriodSlider, update today
|
|
55
|
+
|
|
56
|
+
* fix(calendar-range): hide error icon
|
|
57
|
+
|
|
58
|
+
* chore(calendar-range): demo
|
|
59
|
+
|
|
60
|
+
* feat(calendar): use IconButton
|
|
61
|
+
|
|
62
|
+
* feat(calendar-range): add onChange, update demo
|
|
63
|
+
|
|
64
|
+
* fix(calendar-range): update width
|
|
65
|
+
|
|
66
|
+
* test(calendar-range): update snapshot
|
|
67
|
+
|
|
68
|
+
* fix: import date-fns separately
|
|
69
|
+
|
|
70
|
+
* fix(calendar-range): fix rest props
|
|
71
|
+
|
|
72
|
+
Co-authored-by: dmitrsavk <dmitrsavk@yandex.ru>
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# [5.3.0](https://github.com/alfa-laboratory/core-components/compare/@alfalab/core-components-calendar-input@5.2.7...@alfalab/core-components-calendar-input@5.3.0) (2022-02-17)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
### Bug Fixes
|
|
82
|
+
|
|
83
|
+
* imports for glyph icons ([#994](https://github.com/alfa-laboratory/core-components/issues/994)) ([8e807f2](https://github.com/alfa-laboratory/core-components/commit/8e807f26abf0f942fe8eadbd201caecb297b35dc))
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
### Features
|
|
87
|
+
|
|
88
|
+
* **calendar:** design & logic updates ([#991](https://github.com/alfa-laboratory/core-components/issues/991)) ([358142c](https://github.com/alfa-laboratory/core-components/commit/358142c6d259e1463954139cc648787cdf461f76)), closes [#993](https://github.com/alfa-laboratory/core-components/issues/993) [#990](https://github.com/alfa-laboratory/core-components/issues/990)
|
|
89
|
+
* **date-input:** add some improvements ([#971](https://github.com/alfa-laboratory/core-components/issues/971)) ([47756ca](https://github.com/alfa-laboratory/core-components/commit/47756ca1d4eea89f78ed7234e95c02e51dd72e49))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
6
95
|
## [5.2.7](https://github.com/alfa-laboratory/core-components/compare/@alfalab/core-components-calendar-input@5.2.6...@alfalab/core-components-calendar-input@5.2.7) (2022-02-15)
|
|
7
96
|
|
|
8
97
|
**Note:** Version bump only for package @alfalab/core-components-calendar-input
|
package/dist/Component.d.ts
CHANGED
|
@@ -45,6 +45,10 @@ type CalendarInputProps = Omit<DateInputProps, 'onChange' | 'mobileMode'> & {
|
|
|
45
45
|
* Максимальная дата, доступная для выбора (timestamp)
|
|
46
46
|
*/
|
|
47
47
|
maxDate?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Список событий
|
|
50
|
+
*/
|
|
51
|
+
events?: Array<Date | number>;
|
|
48
52
|
/**
|
|
49
53
|
* Список выходных
|
|
50
54
|
*/
|
|
@@ -97,7 +101,7 @@ type CalendarInputProps = Omit<DateInputProps, 'onChange' | 'mobileMode'> & {
|
|
|
97
101
|
*/
|
|
98
102
|
useAnchorWidth?: boolean;
|
|
99
103
|
};
|
|
100
|
-
declare const CalendarInput: React.ForwardRefExoticComponent<Pick<DateInputProps, "
|
|
104
|
+
declare const CalendarInput: React.ForwardRefExoticComponent<Pick<DateInputProps, "children" | "value" | "form" | "label" | "slot" | "style" | "title" | "pattern" | "dir" | "className" | "dataTestId" | "height" | "name" | "width" | "hidden" | "color" | "size" | "block" | "clear" | "multiple" | "disabled" | "leftAddons" | "rightAddons" | "colors" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "draggable" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "list" | "step" | "autoFocus" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "fieldClassName" | "labelClassName" | "addonsClassName" | "error" | "hint" | "bottomAddons" | "accept" | "alt" | "autoComplete" | "capture" | "checked" | "crossOrigin" | "max" | "maxLength" | "min" | "minLength" | "readOnly" | "required" | "src" | "success" | "inputClassName" | "focusedClassName" | "filledClassName" | "onClear" | "wrapperRef" | "onComplete"> & {
|
|
101
105
|
/**
|
|
102
106
|
* Дополнительный класс
|
|
103
107
|
*/
|
|
@@ -138,6 +142,10 @@ declare const CalendarInput: React.ForwardRefExoticComponent<Pick<DateInputProps
|
|
|
138
142
|
* Максимальная дата, доступная для выбора (timestamp)
|
|
139
143
|
*/
|
|
140
144
|
maxDate?: number | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* Список событий
|
|
147
|
+
*/
|
|
148
|
+
events?: (number | Date)[] | undefined;
|
|
141
149
|
/**
|
|
142
150
|
* Список выходных
|
|
143
151
|
*/
|
package/dist/Component.js
CHANGED
|
@@ -6,9 +6,13 @@ var React = require('react');
|
|
|
6
6
|
var cn = require('classnames');
|
|
7
7
|
var mergeRefs = require('react-merge-refs');
|
|
8
8
|
var coreComponentsPopover = require('@alfalab/core-components-popover');
|
|
9
|
+
var CalendarMIcon = require('@alfalab/icons-glyph/CalendarMIcon');
|
|
9
10
|
var coreComponentsDateInput = require('@alfalab/core-components-date-input');
|
|
10
11
|
var coreComponentsCalendar = require('@alfalab/core-components-calendar');
|
|
11
|
-
|
|
12
|
+
require('date-fns/parse');
|
|
13
|
+
require('date-fns/format');
|
|
14
|
+
require('date-fns/isSameDay');
|
|
15
|
+
var utils = require('./utils.js');
|
|
12
16
|
|
|
13
17
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
18
|
|
|
@@ -55,24 +59,28 @@ function __rest(s, e) {
|
|
|
55
59
|
return t;
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
var styles = {"component":"calendar-
|
|
62
|
+
var styles = {"component":"calendar-input__component_1u5qx","block":"calendar-input__block_1u5qx","calendarContainer":"calendar-input__calendarContainer_1u5qx","calendarIcon":"calendar-input__calendarIcon_1u5qx","nativeInput":"calendar-input__nativeInput_1u5qx"};
|
|
59
63
|
require('./index.css')
|
|
60
64
|
|
|
61
65
|
var CalendarInput = React.forwardRef(function (_a, ref) {
|
|
62
66
|
var _b;
|
|
63
|
-
var _c = _a.block, block = _c === void 0 ? false : _c, className = _a.className, inputClassName = _a.inputClassName, popoverClassName = _a.popoverClassName, _d = _a.defaultOpen, defaultOpen = _d === void 0 ? false : _d, defaultMonth = _a.defaultMonth, _e = _a.defaultValue, defaultValue = _e === void 0 ? '' : _e, _f = _a.calendarPosition, calendarPosition = _f === void 0 ? 'popover' : _f, value = _a.value, dataTestId = _a.dataTestId, _g = _a.calendarProps, calendarProps = _g === void 0 ? {} : _g, _h = _a.minDate, minDate = _h === void 0 ? calendarProps.minDate : _h, _j = _a.maxDate, maxDate = _j === void 0 ? calendarProps.maxDate : _j, _k = _a.offDays, offDays = _k === void 0 ? calendarProps.offDays || [] : _k, preventFlip = _a.preventFlip,
|
|
64
|
-
var
|
|
65
|
-
var shouldRenderNative = coreComponentsDateInput.SUPPORTS_INPUT_TYPE_DATE && mobileMode === 'native';
|
|
67
|
+
var _c = _a.block, block = _c === void 0 ? false : _c, className = _a.className, inputClassName = _a.inputClassName, popoverClassName = _a.popoverClassName, _d = _a.defaultOpen, defaultOpen = _d === void 0 ? false : _d, defaultMonth = _a.defaultMonth, _e = _a.defaultValue, defaultValue = _e === void 0 ? '' : _e, _f = _a.calendarPosition, calendarPosition = _f === void 0 ? 'popover' : _f, value = _a.value, dataTestId = _a.dataTestId, _g = _a.calendarProps, calendarProps = _g === void 0 ? {} : _g, _h = _a.minDate, minDate = _h === void 0 ? calendarProps.minDate : _h, _j = _a.maxDate, maxDate = _j === void 0 ? calendarProps.maxDate : _j, _k = _a.offDays, offDays = _k === void 0 ? calendarProps.offDays || [] : _k, _l = _a.events, events = _l === void 0 ? calendarProps.events || [] : _l, preventFlip = _a.preventFlip, _m = _a.mobileMode, mobileMode = _m === void 0 ? 'popover' : _m, _o = _a.wrapperRef, wrapperRef = _o === void 0 ? null : _o, disabled = _a.disabled, _p = _a.onChange, onChange = _p === void 0 ? function () { return null; } : _p, onInputChange = _a.onInputChange, onCalendarChange = _a.onCalendarChange, onKeyDown = _a.onKeyDown, readOnly = _a.readOnly, _q = _a.Calendar, Calendar = _q === void 0 ? coreComponentsCalendar.Calendar : _q, _r = _a.popoverPosition, popoverPosition = _r === void 0 ? 'bottom-start' : _r, zIndexPopover = _a.zIndexPopover, useAnchorWidth = _a.useAnchorWidth, rightAddons = _a.rightAddons, error = _a.error, 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"]);
|
|
68
|
+
var shouldRenderNative = utils.SUPPORTS_INPUT_TYPE_DATE && mobileMode === 'native';
|
|
66
69
|
var shouldRenderOnlyInput = mobileMode === 'input';
|
|
67
70
|
var shouldRenderStatic = calendarPosition === 'static' && !shouldRenderOnlyInput;
|
|
68
71
|
var shouldRenderPopover = calendarPosition === 'popover' && !shouldRenderNative && !shouldRenderOnlyInput;
|
|
69
|
-
var
|
|
70
|
-
var
|
|
71
|
-
var inputValue = uncontrolled ? stateValue : value;
|
|
72
|
+
var _s = React.useState(false), open = _s[0], setOpen = _s[1];
|
|
73
|
+
var _t = React.useState(value || defaultValue), inputValue = _t[0], setInputValue = _t[1];
|
|
72
74
|
var calendarValue = inputValue ? coreComponentsDateInput.parseDateString(inputValue).getTime() : undefined;
|
|
73
|
-
var
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
var checkInputValueIsValid = React.useCallback(function (newInputValue) {
|
|
76
|
+
if (!newInputValue || error)
|
|
77
|
+
return false;
|
|
78
|
+
var dateValue = coreComponentsDateInput.parseDateString(newInputValue).getTime();
|
|
79
|
+
return (dateValue &&
|
|
80
|
+
coreComponentsDateInput.isCompleteDateInput(newInputValue) &&
|
|
81
|
+
coreComponentsCalendar.dateInLimits(dateValue, minDate, maxDate) &&
|
|
82
|
+
!offDays.includes(dateValue));
|
|
83
|
+
}, [error, maxDate, minDate, offDays]);
|
|
76
84
|
var inputDisabled = disabled || readOnly;
|
|
77
85
|
var inputWrapperRef = React.useRef(null);
|
|
78
86
|
var calendarRef = React.useRef(null);
|
|
@@ -117,18 +125,14 @@ var CalendarInput = React.forwardRef(function (_a, ref) {
|
|
|
117
125
|
if (initiator === 'calendar' && onCalendarChange) {
|
|
118
126
|
onCalendarChange(newDate.getTime());
|
|
119
127
|
}
|
|
128
|
+
setInputValue(newValue);
|
|
120
129
|
if (shouldChange) {
|
|
121
|
-
|
|
122
|
-
setStateValue(newValue);
|
|
123
|
-
}
|
|
124
|
-
if (onChange) {
|
|
125
|
-
onChange(event, { date: newDate, value: newValue });
|
|
126
|
-
}
|
|
130
|
+
onChange(event, { date: newDate, value: newValue });
|
|
127
131
|
}
|
|
128
|
-
}, [onCalendarChange, onChange, onInputChange
|
|
132
|
+
}, [onCalendarChange, onChange, onInputChange]);
|
|
129
133
|
var handleInputChange = React.useCallback(function (event, payload) {
|
|
130
|
-
changeHandler(event, payload.value, payload.date, 'input', !payload.value ||
|
|
131
|
-
}, [changeHandler]);
|
|
134
|
+
changeHandler(event, payload.value, payload.date, 'input', !payload.value || checkInputValueIsValid(payload.value));
|
|
135
|
+
}, [changeHandler, checkInputValueIsValid]);
|
|
132
136
|
var handleCalendarChange = React.useCallback(function (date) {
|
|
133
137
|
changeHandler(null, coreComponentsDateInput.formatDate(date), new Date(date), 'calendar');
|
|
134
138
|
setOpen(false);
|
|
@@ -140,16 +144,23 @@ var CalendarInput = React.forwardRef(function (_a, ref) {
|
|
|
140
144
|
React.useEffect(function () {
|
|
141
145
|
setOpen(defaultOpen);
|
|
142
146
|
}, [defaultOpen]);
|
|
147
|
+
React.useEffect(function () {
|
|
148
|
+
if (typeof value !== 'undefined') {
|
|
149
|
+
setInputValue(value);
|
|
150
|
+
}
|
|
151
|
+
}, [value]);
|
|
143
152
|
var renderCalendar = React.useCallback(function () { return (
|
|
144
153
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
145
154
|
React__default['default'].createElement("div", { onMouseDown: handleCalendarWrapperMouseDown },
|
|
146
|
-
React__default['default'].createElement(Calendar, __assign({}, calendarProps, { ref: calendarRef, defaultMonth: defaultMonth, value:
|
|
155
|
+
React__default['default'].createElement(Calendar, __assign({}, calendarProps, { ref: calendarRef, defaultMonth: defaultMonth, value: checkInputValueIsValid(inputValue) ? calendarValue : undefined, onChange: handleCalendarChange, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events })))); }, [
|
|
147
156
|
calendarProps,
|
|
148
157
|
calendarValue,
|
|
158
|
+
checkInputValueIsValid,
|
|
149
159
|
defaultMonth,
|
|
160
|
+
events,
|
|
150
161
|
handleCalendarChange,
|
|
151
162
|
handleCalendarWrapperMouseDown,
|
|
152
|
-
|
|
163
|
+
inputValue,
|
|
153
164
|
maxDate,
|
|
154
165
|
minDate,
|
|
155
166
|
offDays,
|
|
@@ -159,9 +170,9 @@ var CalendarInput = React.forwardRef(function (_a, ref) {
|
|
|
159
170
|
React__default['default'].createElement("div", { className: cn__default['default'](styles.component, className, (_b = {},
|
|
160
171
|
_b[styles.block] = block,
|
|
161
172
|
_b)), tabIndex: -1, onKeyDown: inputDisabled ? undefined : handleKeyDown, onClick: inputDisabled ? undefined : handleClick, onFocus: inputDisabled ? undefined : handleFocus, onBlur: handleBlur, "data-test-id": dataTestId },
|
|
162
|
-
React__default['default'].createElement(coreComponentsDateInput.DateInput, __assign({}, restProps, { ref: ref, wrapperRef: mergeRefs__default['default']([wrapperRef, inputWrapperRef]), value: inputValue, defaultValue: defaultValue, disabled: disabled, readOnly: readOnly, mobileMode: mobileMode === 'native' ? 'native' : 'input', rightAddons: React__default['default'].createElement(React__default['default'].Fragment, null,
|
|
173
|
+
React__default['default'].createElement(coreComponentsDateInput.DateInput, __assign({}, restProps, { ref: ref, wrapperRef: mergeRefs__default['default']([wrapperRef, inputWrapperRef]), value: inputValue, defaultValue: defaultValue, disabled: disabled, readOnly: readOnly, mobileMode: mobileMode === 'native' ? 'native' : 'input', error: error, rightAddons: React__default['default'].createElement(React__default['default'].Fragment, null,
|
|
163
174
|
rightAddons,
|
|
164
|
-
React__default['default'].createElement(CalendarMIcon.CalendarMIcon, { className: styles.calendarIcon })), onKeyDown: handleInputKeyDown, onChange: handleInputChange, block: true })),
|
|
175
|
+
shouldRenderPopover && (React__default['default'].createElement(CalendarMIcon.CalendarMIcon, { className: styles.calendarIcon }))), onKeyDown: handleInputKeyDown, onChange: handleInputChange, block: true })),
|
|
165
176
|
shouldRenderStatic && renderCalendar(),
|
|
166
177
|
shouldRenderPopover && (React__default['default'].createElement(coreComponentsPopover.Popover, { open: open, useAnchorWidth: useAnchorWidth, anchorElement: inputWrapperRef.current, popperClassName: styles.calendarContainer, className: popoverClassName, position: popoverPosition, offset: [0, 8], withTransition: false, preventFlip: preventFlip, zIndex: zIndexPopover }, renderCalendar()))));
|
|
167
178
|
});
|
package/dist/cssm/Component.d.ts
CHANGED
|
@@ -45,6 +45,10 @@ type CalendarInputProps = Omit<DateInputProps, 'onChange' | 'mobileMode'> & {
|
|
|
45
45
|
* Максимальная дата, доступная для выбора (timestamp)
|
|
46
46
|
*/
|
|
47
47
|
maxDate?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Список событий
|
|
50
|
+
*/
|
|
51
|
+
events?: Array<Date | number>;
|
|
48
52
|
/**
|
|
49
53
|
* Список выходных
|
|
50
54
|
*/
|
|
@@ -97,7 +101,7 @@ type CalendarInputProps = Omit<DateInputProps, 'onChange' | 'mobileMode'> & {
|
|
|
97
101
|
*/
|
|
98
102
|
useAnchorWidth?: boolean;
|
|
99
103
|
};
|
|
100
|
-
declare const CalendarInput: React.ForwardRefExoticComponent<Pick<DateInputProps, "children" | "value" | "form" | "label" | "slot" | "style" | "title" | "pattern" | "dir" | "className" | "dataTestId" | "height" | "name" | "width" | "hidden" | "color" | "size" | "block" | "clear" | "multiple" | "disabled" | "leftAddons" | "rightAddons" | "colors" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "draggable" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "list" | "step" | "autoFocus" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "fieldClassName" | "labelClassName" | "addonsClassName" | "error" | "hint" | "bottomAddons" | "accept" | "alt" | "autoComplete" | "capture" | "checked" | "crossOrigin" | "max" | "maxLength" | "min" | "minLength" | "readOnly" | "required" | "src" | "success" | "inputClassName" | "focusedClassName" | "filledClassName" | "onClear" | "wrapperRef" | "
|
|
104
|
+
declare const CalendarInput: React.ForwardRefExoticComponent<Pick<DateInputProps, "children" | "value" | "form" | "label" | "slot" | "style" | "title" | "pattern" | "dir" | "className" | "dataTestId" | "height" | "name" | "width" | "hidden" | "color" | "size" | "block" | "clear" | "multiple" | "disabled" | "leftAddons" | "rightAddons" | "colors" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "draggable" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "list" | "step" | "autoFocus" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "fieldClassName" | "labelClassName" | "addonsClassName" | "error" | "hint" | "bottomAddons" | "accept" | "alt" | "autoComplete" | "capture" | "checked" | "crossOrigin" | "max" | "maxLength" | "min" | "minLength" | "readOnly" | "required" | "src" | "success" | "inputClassName" | "focusedClassName" | "filledClassName" | "onClear" | "wrapperRef" | "onComplete"> & {
|
|
101
105
|
/**
|
|
102
106
|
* Дополнительный класс
|
|
103
107
|
*/
|
|
@@ -138,6 +142,10 @@ declare const CalendarInput: React.ForwardRefExoticComponent<Pick<DateInputProps
|
|
|
138
142
|
* Максимальная дата, доступная для выбора (timestamp)
|
|
139
143
|
*/
|
|
140
144
|
maxDate?: number | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* Список событий
|
|
147
|
+
*/
|
|
148
|
+
events?: (number | Date)[] | undefined;
|
|
141
149
|
/**
|
|
142
150
|
* Список выходных
|
|
143
151
|
*/
|
package/dist/cssm/Component.js
CHANGED
|
@@ -6,9 +6,13 @@ var React = require('react');
|
|
|
6
6
|
var cn = require('classnames');
|
|
7
7
|
var mergeRefs = require('react-merge-refs');
|
|
8
8
|
var coreComponentsPopover = require('@alfalab/core-components-popover/dist/cssm');
|
|
9
|
+
var CalendarMIcon = require('@alfalab/icons-glyph/CalendarMIcon');
|
|
9
10
|
var coreComponentsDateInput = require('@alfalab/core-components-date-input/dist/cssm');
|
|
10
11
|
var coreComponentsCalendar = require('@alfalab/core-components-calendar/dist/cssm');
|
|
11
|
-
|
|
12
|
+
require('date-fns/parse');
|
|
13
|
+
require('date-fns/format');
|
|
14
|
+
require('date-fns/isSameDay');
|
|
15
|
+
var utils = require('./utils.js');
|
|
12
16
|
var styles = require('./index.module.css');
|
|
13
17
|
|
|
14
18
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -59,19 +63,23 @@ function __rest(s, e) {
|
|
|
59
63
|
|
|
60
64
|
var CalendarInput = React.forwardRef(function (_a, ref) {
|
|
61
65
|
var _b;
|
|
62
|
-
var _c = _a.block, block = _c === void 0 ? false : _c, className = _a.className, inputClassName = _a.inputClassName, popoverClassName = _a.popoverClassName, _d = _a.defaultOpen, defaultOpen = _d === void 0 ? false : _d, defaultMonth = _a.defaultMonth, _e = _a.defaultValue, defaultValue = _e === void 0 ? '' : _e, _f = _a.calendarPosition, calendarPosition = _f === void 0 ? 'popover' : _f, value = _a.value, dataTestId = _a.dataTestId, _g = _a.calendarProps, calendarProps = _g === void 0 ? {} : _g, _h = _a.minDate, minDate = _h === void 0 ? calendarProps.minDate : _h, _j = _a.maxDate, maxDate = _j === void 0 ? calendarProps.maxDate : _j, _k = _a.offDays, offDays = _k === void 0 ? calendarProps.offDays || [] : _k, preventFlip = _a.preventFlip,
|
|
63
|
-
var
|
|
64
|
-
var shouldRenderNative = coreComponentsDateInput.SUPPORTS_INPUT_TYPE_DATE && mobileMode === 'native';
|
|
66
|
+
var _c = _a.block, block = _c === void 0 ? false : _c, className = _a.className, inputClassName = _a.inputClassName, popoverClassName = _a.popoverClassName, _d = _a.defaultOpen, defaultOpen = _d === void 0 ? false : _d, defaultMonth = _a.defaultMonth, _e = _a.defaultValue, defaultValue = _e === void 0 ? '' : _e, _f = _a.calendarPosition, calendarPosition = _f === void 0 ? 'popover' : _f, value = _a.value, dataTestId = _a.dataTestId, _g = _a.calendarProps, calendarProps = _g === void 0 ? {} : _g, _h = _a.minDate, minDate = _h === void 0 ? calendarProps.minDate : _h, _j = _a.maxDate, maxDate = _j === void 0 ? calendarProps.maxDate : _j, _k = _a.offDays, offDays = _k === void 0 ? calendarProps.offDays || [] : _k, _l = _a.events, events = _l === void 0 ? calendarProps.events || [] : _l, preventFlip = _a.preventFlip, _m = _a.mobileMode, mobileMode = _m === void 0 ? 'popover' : _m, _o = _a.wrapperRef, wrapperRef = _o === void 0 ? null : _o, disabled = _a.disabled, _p = _a.onChange, onChange = _p === void 0 ? function () { return null; } : _p, onInputChange = _a.onInputChange, onCalendarChange = _a.onCalendarChange, onKeyDown = _a.onKeyDown, readOnly = _a.readOnly, _q = _a.Calendar, Calendar = _q === void 0 ? coreComponentsCalendar.Calendar : _q, _r = _a.popoverPosition, popoverPosition = _r === void 0 ? 'bottom-start' : _r, zIndexPopover = _a.zIndexPopover, useAnchorWidth = _a.useAnchorWidth, rightAddons = _a.rightAddons, error = _a.error, 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"]);
|
|
67
|
+
var shouldRenderNative = utils.SUPPORTS_INPUT_TYPE_DATE && mobileMode === 'native';
|
|
65
68
|
var shouldRenderOnlyInput = mobileMode === 'input';
|
|
66
69
|
var shouldRenderStatic = calendarPosition === 'static' && !shouldRenderOnlyInput;
|
|
67
70
|
var shouldRenderPopover = calendarPosition === 'popover' && !shouldRenderNative && !shouldRenderOnlyInput;
|
|
68
|
-
var
|
|
69
|
-
var
|
|
70
|
-
var inputValue = uncontrolled ? stateValue : value;
|
|
71
|
+
var _s = React.useState(false), open = _s[0], setOpen = _s[1];
|
|
72
|
+
var _t = React.useState(value || defaultValue), inputValue = _t[0], setInputValue = _t[1];
|
|
71
73
|
var calendarValue = inputValue ? coreComponentsDateInput.parseDateString(inputValue).getTime() : undefined;
|
|
72
|
-
var
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
var checkInputValueIsValid = React.useCallback(function (newInputValue) {
|
|
75
|
+
if (!newInputValue || error)
|
|
76
|
+
return false;
|
|
77
|
+
var dateValue = coreComponentsDateInput.parseDateString(newInputValue).getTime();
|
|
78
|
+
return (dateValue &&
|
|
79
|
+
coreComponentsDateInput.isCompleteDateInput(newInputValue) &&
|
|
80
|
+
coreComponentsCalendar.dateInLimits(dateValue, minDate, maxDate) &&
|
|
81
|
+
!offDays.includes(dateValue));
|
|
82
|
+
}, [error, maxDate, minDate, offDays]);
|
|
75
83
|
var inputDisabled = disabled || readOnly;
|
|
76
84
|
var inputWrapperRef = React.useRef(null);
|
|
77
85
|
var calendarRef = React.useRef(null);
|
|
@@ -116,18 +124,14 @@ var CalendarInput = React.forwardRef(function (_a, ref) {
|
|
|
116
124
|
if (initiator === 'calendar' && onCalendarChange) {
|
|
117
125
|
onCalendarChange(newDate.getTime());
|
|
118
126
|
}
|
|
127
|
+
setInputValue(newValue);
|
|
119
128
|
if (shouldChange) {
|
|
120
|
-
|
|
121
|
-
setStateValue(newValue);
|
|
122
|
-
}
|
|
123
|
-
if (onChange) {
|
|
124
|
-
onChange(event, { date: newDate, value: newValue });
|
|
125
|
-
}
|
|
129
|
+
onChange(event, { date: newDate, value: newValue });
|
|
126
130
|
}
|
|
127
|
-
}, [onCalendarChange, onChange, onInputChange
|
|
131
|
+
}, [onCalendarChange, onChange, onInputChange]);
|
|
128
132
|
var handleInputChange = React.useCallback(function (event, payload) {
|
|
129
|
-
changeHandler(event, payload.value, payload.date, 'input', !payload.value ||
|
|
130
|
-
}, [changeHandler]);
|
|
133
|
+
changeHandler(event, payload.value, payload.date, 'input', !payload.value || checkInputValueIsValid(payload.value));
|
|
134
|
+
}, [changeHandler, checkInputValueIsValid]);
|
|
131
135
|
var handleCalendarChange = React.useCallback(function (date) {
|
|
132
136
|
changeHandler(null, coreComponentsDateInput.formatDate(date), new Date(date), 'calendar');
|
|
133
137
|
setOpen(false);
|
|
@@ -139,16 +143,23 @@ var CalendarInput = React.forwardRef(function (_a, ref) {
|
|
|
139
143
|
React.useEffect(function () {
|
|
140
144
|
setOpen(defaultOpen);
|
|
141
145
|
}, [defaultOpen]);
|
|
146
|
+
React.useEffect(function () {
|
|
147
|
+
if (typeof value !== 'undefined') {
|
|
148
|
+
setInputValue(value);
|
|
149
|
+
}
|
|
150
|
+
}, [value]);
|
|
142
151
|
var renderCalendar = React.useCallback(function () { return (
|
|
143
152
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
144
153
|
React__default['default'].createElement("div", { onMouseDown: handleCalendarWrapperMouseDown },
|
|
145
|
-
React__default['default'].createElement(Calendar, __assign({}, calendarProps, { ref: calendarRef, defaultMonth: defaultMonth, value:
|
|
154
|
+
React__default['default'].createElement(Calendar, __assign({}, calendarProps, { ref: calendarRef, defaultMonth: defaultMonth, value: checkInputValueIsValid(inputValue) ? calendarValue : undefined, onChange: handleCalendarChange, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events })))); }, [
|
|
146
155
|
calendarProps,
|
|
147
156
|
calendarValue,
|
|
157
|
+
checkInputValueIsValid,
|
|
148
158
|
defaultMonth,
|
|
159
|
+
events,
|
|
149
160
|
handleCalendarChange,
|
|
150
161
|
handleCalendarWrapperMouseDown,
|
|
151
|
-
|
|
162
|
+
inputValue,
|
|
152
163
|
maxDate,
|
|
153
164
|
minDate,
|
|
154
165
|
offDays,
|
|
@@ -158,9 +169,9 @@ var CalendarInput = React.forwardRef(function (_a, ref) {
|
|
|
158
169
|
React__default['default'].createElement("div", { className: cn__default['default'](styles__default['default'].component, className, (_b = {},
|
|
159
170
|
_b[styles__default['default'].block] = block,
|
|
160
171
|
_b)), tabIndex: -1, onKeyDown: inputDisabled ? undefined : handleKeyDown, onClick: inputDisabled ? undefined : handleClick, onFocus: inputDisabled ? undefined : handleFocus, onBlur: handleBlur, "data-test-id": dataTestId },
|
|
161
|
-
React__default['default'].createElement(coreComponentsDateInput.DateInput, __assign({}, restProps, { ref: ref, wrapperRef: mergeRefs__default['default']([wrapperRef, inputWrapperRef]), value: inputValue, defaultValue: defaultValue, disabled: disabled, readOnly: readOnly, mobileMode: mobileMode === 'native' ? 'native' : 'input', rightAddons: React__default['default'].createElement(React__default['default'].Fragment, null,
|
|
172
|
+
React__default['default'].createElement(coreComponentsDateInput.DateInput, __assign({}, restProps, { ref: ref, wrapperRef: mergeRefs__default['default']([wrapperRef, inputWrapperRef]), value: inputValue, defaultValue: defaultValue, disabled: disabled, readOnly: readOnly, mobileMode: mobileMode === 'native' ? 'native' : 'input', error: error, rightAddons: React__default['default'].createElement(React__default['default'].Fragment, null,
|
|
162
173
|
rightAddons,
|
|
163
|
-
React__default['default'].createElement(CalendarMIcon.CalendarMIcon, { className: styles__default['default'].calendarIcon })), onKeyDown: handleInputKeyDown, onChange: handleInputChange, block: true })),
|
|
174
|
+
shouldRenderPopover && (React__default['default'].createElement(CalendarMIcon.CalendarMIcon, { className: styles__default['default'].calendarIcon }))), onKeyDown: handleInputKeyDown, onChange: handleInputChange, block: true })),
|
|
164
175
|
shouldRenderStatic && renderCalendar(),
|
|
165
176
|
shouldRenderPopover && (React__default['default'].createElement(coreComponentsPopover.Popover, { open: open, useAnchorWidth: useAnchorWidth, anchorElement: inputWrapperRef.current, popperClassName: styles__default['default'].calendarContainer, className: popoverClassName, position: popoverPosition, offset: [0, 8], withTransition: false, preventFlip: preventFlip, zIndex: zIndexPopover }, renderCalendar()))));
|
|
166
177
|
});
|
package/dist/cssm/index.js
CHANGED
|
@@ -7,12 +7,14 @@ require('react');
|
|
|
7
7
|
require('classnames');
|
|
8
8
|
require('react-merge-refs');
|
|
9
9
|
require('@alfalab/core-components-popover/dist/cssm');
|
|
10
|
+
require('@alfalab/icons-glyph/CalendarMIcon');
|
|
10
11
|
require('@alfalab/core-components-date-input/dist/cssm');
|
|
11
12
|
require('@alfalab/core-components-calendar/dist/cssm');
|
|
12
|
-
require('
|
|
13
|
-
require('
|
|
14
|
-
require('date-fns');
|
|
13
|
+
require('date-fns/parse');
|
|
14
|
+
require('date-fns/format');
|
|
15
|
+
require('date-fns/isSameDay');
|
|
15
16
|
var utils = require('./utils.js');
|
|
17
|
+
require('./index.module.css');
|
|
16
18
|
|
|
17
19
|
|
|
18
20
|
|
|
@@ -23,6 +25,6 @@ exports.IS_BROWSER = utils.IS_BROWSER;
|
|
|
23
25
|
exports.NATIVE_DATE_FORMAT = utils.NATIVE_DATE_FORMAT;
|
|
24
26
|
exports.SUPPORTS_INPUT_TYPE_DATE = utils.SUPPORTS_INPUT_TYPE_DATE;
|
|
25
27
|
exports.formatDate = utils.formatDate;
|
|
26
|
-
exports.isCompleteDateInput = utils.isCompleteDateInput;
|
|
27
28
|
exports.isInputDateSupported = utils.isInputDateSupported;
|
|
29
|
+
exports.isValidInputValue = utils.isValidInputValue;
|
|
28
30
|
exports.parseDateString = utils.parseDateString;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
:root {
|
|
2
|
-
--color-light-border-primary: #dbdee1;
|
|
3
2
|
--color-light-graphic-primary: #0b1f35;
|
|
4
3
|
}
|
|
5
4
|
:root {
|
|
6
|
-
--shadow-s: 0 0 8px rgba(11, 31, 53, 0.04), 0 4px 8px rgba(11, 31, 53, 0.08);
|
|
7
5
|
|
|
8
6
|
/* Hard */
|
|
9
7
|
|
|
@@ -15,7 +13,7 @@
|
|
|
15
13
|
--gap-2xs: 4px;
|
|
16
14
|
}
|
|
17
15
|
:root {
|
|
18
|
-
--border-radius-
|
|
16
|
+
--border-radius-s: 4px;
|
|
19
17
|
}
|
|
20
18
|
:root {
|
|
21
19
|
|
|
@@ -39,8 +37,7 @@
|
|
|
39
37
|
}
|
|
40
38
|
:root {
|
|
41
39
|
--calendar-input-icon-color: var(--color-light-graphic-primary);
|
|
42
|
-
--calendar-input-popover-border-
|
|
43
|
-
--calendar-input-popover-border-radius: var(--border-radius-m);
|
|
40
|
+
--calendar-input-popover-border-radius: 0 0 var(--border-radius-s) var(--border-radius-s);
|
|
44
41
|
}
|
|
45
42
|
.component {
|
|
46
43
|
display: inline-block;
|
|
@@ -53,8 +50,6 @@
|
|
|
53
50
|
.calendarContainer {
|
|
54
51
|
display: inline-block;
|
|
55
52
|
box-sizing: border-box;
|
|
56
|
-
box-shadow: var(--shadow-s);
|
|
57
|
-
border: 1px solid var(--calendar-input-popover-border-color);
|
|
58
53
|
border-radius: var(--calendar-input-popover-border-radius)
|
|
59
54
|
}
|
|
60
55
|
@media (max-width: 374px) {
|
package/dist/cssm/utils.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ declare const NATIVE_DATE_FORMAT = "yyyy-MM-dd";
|
|
|
3
3
|
declare const DATE_MASK: (string | RegExp)[];
|
|
4
4
|
declare const IS_BROWSER: boolean;
|
|
5
5
|
declare const SUPPORTS_INPUT_TYPE_DATE: boolean;
|
|
6
|
-
declare const isCompleteDateInput: (input: string) => boolean;
|
|
7
6
|
declare const formatDate: (date: number | Date, dateFormat?: string) => string;
|
|
8
7
|
declare const parseDateString: (value: string, dateFormat?: string) => Date;
|
|
9
8
|
/**
|
|
10
9
|
* Возвращает `true`, если поддерживается `input[type="date"]`
|
|
11
10
|
*/
|
|
12
11
|
declare function isInputDateSupported(): boolean;
|
|
13
|
-
|
|
12
|
+
declare const isValidInputValue: (newInputValue: string | undefined, minDate: number | undefined, maxDate: number | undefined, offDays?: (number | Date)[]) => boolean;
|
|
13
|
+
export { DATE_FORMAT, NATIVE_DATE_FORMAT, DATE_MASK, IS_BROWSER, SUPPORTS_INPUT_TYPE_DATE, formatDate, parseDateString, isInputDateSupported, isValidInputValue };
|
package/dist/cssm/utils.js
CHANGED
|
@@ -2,21 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var coreComponentsDateInput = require('@alfalab/core-components-date-input/dist/cssm');
|
|
6
|
+
var coreComponentsCalendar = require('@alfalab/core-components-calendar/dist/cssm');
|
|
7
|
+
var parse = require('date-fns/parse');
|
|
8
|
+
var format = require('date-fns/format');
|
|
9
|
+
var isSameDay = require('date-fns/isSameDay');
|
|
10
|
+
|
|
11
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
+
|
|
13
|
+
var parse__default = /*#__PURE__*/_interopDefaultLegacy(parse);
|
|
14
|
+
var format__default = /*#__PURE__*/_interopDefaultLegacy(format);
|
|
15
|
+
var isSameDay__default = /*#__PURE__*/_interopDefaultLegacy(isSameDay);
|
|
6
16
|
|
|
7
17
|
var DATE_FORMAT = 'dd.MM.yyyy';
|
|
8
18
|
var NATIVE_DATE_FORMAT = 'yyyy-MM-dd';
|
|
9
19
|
var DATE_MASK = [/\d/, /\d/, '.', /\d/, /\d/, '.', /\d/, /\d/, /\d/, /\d/];
|
|
10
20
|
var IS_BROWSER = typeof window !== 'undefined';
|
|
11
21
|
var SUPPORTS_INPUT_TYPE_DATE = IS_BROWSER && isInputDateSupported();
|
|
12
|
-
var isCompleteDateInput = function (input) { return input.length === DATE_MASK.length; };
|
|
13
22
|
var formatDate = function (date, dateFormat) {
|
|
14
23
|
if (dateFormat === void 0) { dateFormat = DATE_FORMAT; }
|
|
15
|
-
return
|
|
24
|
+
return format__default['default'](date, dateFormat);
|
|
16
25
|
};
|
|
17
26
|
var parseDateString = function (value, dateFormat) {
|
|
18
27
|
if (dateFormat === void 0) { dateFormat = DATE_FORMAT; }
|
|
19
|
-
return
|
|
28
|
+
return parse__default['default'](value, dateFormat, new Date());
|
|
20
29
|
};
|
|
21
30
|
/**
|
|
22
31
|
* Возвращает `true`, если поддерживается `input[type="date"]`
|
|
@@ -28,6 +37,16 @@ function isInputDateSupported() {
|
|
|
28
37
|
input.setAttribute('value', value);
|
|
29
38
|
return input.value !== value;
|
|
30
39
|
}
|
|
40
|
+
var isValidInputValue = function (newInputValue, minDate, maxDate, offDays) {
|
|
41
|
+
if (offDays === void 0) { offDays = []; }
|
|
42
|
+
if (!newInputValue)
|
|
43
|
+
return false;
|
|
44
|
+
var dateValue = parseDateString(newInputValue).getTime();
|
|
45
|
+
return Boolean(dateValue &&
|
|
46
|
+
coreComponentsDateInput.isCompleteDateInput(newInputValue) &&
|
|
47
|
+
coreComponentsCalendar.dateInLimits(dateValue, minDate, maxDate) &&
|
|
48
|
+
!offDays.some(function (offDay) { return isSameDay__default['default'](offDay, dateValue); }));
|
|
49
|
+
};
|
|
31
50
|
|
|
32
51
|
exports.DATE_FORMAT = DATE_FORMAT;
|
|
33
52
|
exports.DATE_MASK = DATE_MASK;
|
|
@@ -35,6 +54,6 @@ exports.IS_BROWSER = IS_BROWSER;
|
|
|
35
54
|
exports.NATIVE_DATE_FORMAT = NATIVE_DATE_FORMAT;
|
|
36
55
|
exports.SUPPORTS_INPUT_TYPE_DATE = SUPPORTS_INPUT_TYPE_DATE;
|
|
37
56
|
exports.formatDate = formatDate;
|
|
38
|
-
exports.isCompleteDateInput = isCompleteDateInput;
|
|
39
57
|
exports.isInputDateSupported = isInputDateSupported;
|
|
58
|
+
exports.isValidInputValue = isValidInputValue;
|
|
40
59
|
exports.parseDateString = parseDateString;
|