@alfalab/core-components-date-input 1.2.11 → 2.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/dist/Component.d.ts +16 -18
  3. package/dist/Component.js +68 -29
  4. package/dist/cssm/Component.d.ts +16 -18
  5. package/dist/cssm/Component.js +67 -28
  6. package/dist/cssm/index.js +7 -7
  7. package/dist/cssm/utils/format.d.ts +3 -1
  8. package/dist/cssm/utils/format.js +27 -3
  9. package/dist/cssm/utils/index.d.ts +0 -1
  10. package/dist/cssm/utils/index.js +5 -6
  11. package/dist/cssm/utils/native-supports.d.ts +1 -3
  12. package/dist/cssm/utils/native-supports.js +0 -4
  13. package/dist/esm/Component.d.ts +16 -18
  14. package/dist/esm/Component.js +70 -32
  15. package/dist/esm/index.css +4 -4
  16. package/dist/esm/index.js +7 -5
  17. package/dist/esm/utils/format.d.ts +3 -1
  18. package/dist/esm/utils/format.js +19 -3
  19. package/dist/esm/utils/index.d.ts +0 -1
  20. package/dist/esm/utils/index.js +5 -4
  21. package/dist/esm/utils/native-supports.d.ts +1 -3
  22. package/dist/esm/utils/native-supports.js +1 -3
  23. package/dist/index.css +4 -4
  24. package/dist/index.js +7 -7
  25. package/dist/modern/Component.d.ts +16 -18
  26. package/dist/modern/Component.js +70 -30
  27. package/dist/modern/index.css +4 -4
  28. package/dist/modern/index.js +7 -5
  29. package/dist/modern/utils/format.d.ts +3 -1
  30. package/dist/modern/utils/format.js +15 -3
  31. package/dist/modern/utils/index.d.ts +0 -1
  32. package/dist/modern/utils/index.js +5 -4
  33. package/dist/modern/utils/native-supports.d.ts +1 -3
  34. package/dist/modern/utils/native-supports.js +1 -3
  35. package/dist/utils/format.d.ts +3 -1
  36. package/dist/utils/format.js +27 -3
  37. package/dist/utils/index.d.ts +0 -1
  38. package/dist/utils/index.js +5 -6
  39. package/dist/utils/native-supports.d.ts +1 -3
  40. package/dist/utils/native-supports.js +0 -4
  41. package/package.json +5 -4
  42. package/dist/cssm/utils/date-correction-pipe.d.ts +0 -9
  43. package/dist/cssm/utils/date-correction-pipe.js +0 -59
  44. package/dist/esm/utils/date-correction-pipe.d.ts +0 -9
  45. package/dist/esm/utils/date-correction-pipe.js +0 -54
  46. package/dist/modern/utils/date-correction-pipe.d.ts +0 -9
  47. package/dist/modern/utils/date-correction-pipe.js +0 -52
  48. package/dist/utils/date-correction-pipe.d.ts +0 -9
  49. package/dist/utils/date-correction-pipe.js +0 -59
package/CHANGELOG.md CHANGED
@@ -3,6 +3,89 @@
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
+ # [2.0.0](https://github.com/alfa-laboratory/core-components/compare/@alfalab/core-components-date-input@1.3.0...@alfalab/core-components-date-input@2.0.0) (2022-02-17)
7
+
8
+
9
+ * 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)
10
+
11
+
12
+ ### BREAKING CHANGES
13
+
14
+ * Большое обновление CalendarRange
15
+
16
+ * feat(date-input): add some improvements
17
+
18
+ * feat(date-input): some updates
19
+
20
+ * feat(date-input): validation
21
+
22
+ * feat(calendar): change period selection logic
23
+
24
+ * fix(calendar): range styles
25
+
26
+ * fix(calendar): fix styles, add rangeComplete flag
27
+
28
+ * refactor(calendar-range): temporary
29
+
30
+ * fix(calendar-range): fix hook
31
+
32
+ * fix(calendar-range): fix period
33
+
34
+ * fix(calendar-range): fix tests, fix max date
35
+
36
+ * fix: update exports
37
+
38
+ * feat(calendar): allow empty values for PeriodSlider, update today
39
+
40
+ * fix(calendar-range): hide error icon
41
+
42
+ * chore(calendar-range): demo
43
+
44
+ * feat(calendar): use IconButton
45
+
46
+ * feat(calendar-range): add onChange, update demo
47
+
48
+ * fix(calendar-range): update width
49
+
50
+ * test(calendar-range): update snapshot
51
+
52
+ * fix: import date-fns separately
53
+
54
+ * fix(calendar-range): fix rest props
55
+
56
+ Co-authored-by: dmitrsavk <dmitrsavk@yandex.ru>
57
+
58
+
59
+
60
+
61
+
62
+ # [1.3.0](https://github.com/alfa-laboratory/core-components/compare/@alfalab/core-components-date-input@1.2.13...@alfalab/core-components-date-input@1.3.0) (2022-02-17)
63
+
64
+
65
+ ### Features
66
+
67
+ * **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))
68
+
69
+
70
+
71
+
72
+
73
+ ## [1.2.13](https://github.com/alfa-laboratory/core-components/compare/@alfalab/core-components-date-input@1.2.12...@alfalab/core-components-date-input@1.2.13) (2022-02-15)
74
+
75
+ **Note:** Version bump only for package @alfalab/core-components-date-input
76
+
77
+
78
+
79
+
80
+
81
+ ## [1.2.12](https://github.com/alfa-laboratory/core-components/compare/@alfalab/core-components-date-input@1.2.11...@alfalab/core-components-date-input@1.2.12) (2022-02-09)
82
+
83
+ **Note:** Version bump only for package @alfalab/core-components-date-input
84
+
85
+
86
+
87
+
88
+
6
89
  ## [1.2.11](https://github.com/alfa-laboratory/core-components/compare/@alfalab/core-components-date-input@1.2.10...@alfalab/core-components-date-input@1.2.11) (2022-02-03)
7
90
 
8
91
  **Note:** Version bump only for package @alfalab/core-components-date-input
@@ -1,16 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import React from 'react';
3
3
  import { ChangeEvent } from "react";
4
- import { MaskedInputProps } from "@alfalab/core-components-masked-input";
5
- type DateInputProps = Omit<MaskedInputProps, 'onBeforeDisplay' | 'mask' | 'onChange'> & {
6
- /**
7
- * Минимальный год, доступный для ввода
8
- */
9
- minYear?: number;
10
- /**
11
- * Максимальный год, доступный для ввода
12
- */
13
- maxYear?: number;
4
+ import { InputProps } from "@alfalab/core-components-input";
5
+ type DateInputProps = Omit<InputProps, 'onChange'> & {
14
6
  /**
15
7
  * Управление нативным режимом на мобильных устройствах
16
8
  */
@@ -22,16 +14,15 @@ type DateInputProps = Omit<MaskedInputProps, 'onBeforeDisplay' | 'mask' | 'onCha
22
14
  date: Date;
23
15
  value: string;
24
16
  }) => void;
25
- };
26
- declare const DateInput: React.ForwardRefExoticComponent<Pick<MaskedInputProps, "className" | "dataTestId" | "form" | "label" | "slot" | "style" | "title" | "pattern" | "children" | "leftAddons" | "rightAddons" | "size" | "block" | "colors" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "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" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "value" | "fieldClassName" | "labelClassName" | "addonsClassName" | "error" | "hint" | "bottomAddons" | "accept" | "alt" | "autoComplete" | "capture" | "checked" | "crossOrigin" | "height" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "readOnly" | "required" | "src" | "width" | "clear" | "success" | "inputClassName" | "focusedClassName" | "filledClassName" | "onClear" | "wrapperRef" | "keepCharPositions"> & {
27
- /**
28
- * Минимальный год, доступный для ввода
29
- */
30
- minYear?: number | undefined;
31
17
  /**
32
- * Максимальный год, доступный для ввода
18
+ * Обработчик окончания ввода
33
19
  */
34
- maxYear?: number | undefined;
20
+ onComplete?: (event: ChangeEvent<HTMLInputElement>, payload: {
21
+ date: Date;
22
+ value: string;
23
+ }) => void;
24
+ };
25
+ declare const DateInput: React.ForwardRefExoticComponent<Pick<InputProps, "className" | "dataTestId" | "form" | "label" | "slot" | "style" | "title" | "pattern" | "children" | "leftAddons" | "rightAddons" | "size" | "block" | "colors" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "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" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "value" | "fieldClassName" | "labelClassName" | "addonsClassName" | "error" | "hint" | "bottomAddons" | "accept" | "alt" | "autoComplete" | "capture" | "checked" | "crossOrigin" | "height" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "readOnly" | "required" | "src" | "width" | "clear" | "success" | "inputClassName" | "focusedClassName" | "filledClassName" | "onClear" | "wrapperRef"> & {
35
26
  /**
36
27
  * Управление нативным режимом на мобильных устройствах
37
28
  */
@@ -43,5 +34,12 @@ declare const DateInput: React.ForwardRefExoticComponent<Pick<MaskedInputProps,
43
34
  date: Date;
44
35
  value: string;
45
36
  }) => void) | undefined;
37
+ /**
38
+ * Обработчик окончания ввода
39
+ */
40
+ onComplete?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
41
+ date: Date;
42
+ value: string;
43
+ }) => void) | undefined;
46
44
  } & React.RefAttributes<HTMLInputElement>>;
47
45
  export { DateInputProps, DateInput };
package/dist/Component.js CHANGED
@@ -3,15 +3,18 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
- var coreComponentsMaskedInput = require('@alfalab/core-components-masked-input');
7
- require('date-fns');
6
+ var coreComponentsInput = require('@alfalab/core-components-input');
7
+ var mergeRefs = require('react-merge-refs');
8
+ require('date-fns/parse');
9
+ require('date-fns/format');
10
+ require('date-fns/isValid');
8
11
  var utils_format = require('./utils/format.js');
9
- var utils_dateCorrectionPipe = require('./utils/date-correction-pipe.js');
10
12
  var utils_nativeSupports = require('./utils/native-supports.js');
11
13
 
12
14
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
15
 
14
16
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
17
+ var mergeRefs__default = /*#__PURE__*/_interopDefaultLegacy(mergeRefs);
15
18
 
16
19
  /*! *****************************************************************************
17
20
  Copyright (c) Microsoft Corporation.
@@ -52,40 +55,76 @@ function __rest(s, e) {
52
55
  return t;
53
56
  }
54
57
 
55
- var styles = {"nativeInput":"date-input__nativeInput_1vwk9"};
58
+ var styles = {"nativeInput":"date-input__nativeInput_1mizx"};
56
59
  require('./index.css')
57
60
 
58
- var DateInput = React__default['default'].forwardRef(function (_a, ref) {
59
- var maxYear = _a.maxYear, minYear = _a.minYear, _b = _a.mobileMode, mobileMode = _b === void 0 ? 'input' : _b, value = _a.value, defaultValue = _a.defaultValue, rightAddons = _a.rightAddons, onChange = _a.onChange, restProps = __rest(_a, ["maxYear", "minYear", "mobileMode", "value", "defaultValue", "rightAddons", "onChange"]);
60
- var uncontrolled = value === undefined;
61
- var shouldRenderNative = utils_nativeSupports.SUPPORTS_INPUT_TYPE_DATE && mobileMode === 'native';
62
- var _c = React.useState(defaultValue), stateValue = _c[0], setStateValue = _c[1];
63
- var inputValue = uncontrolled ? stateValue : value;
64
- var pipe = React.useMemo(function () {
65
- return utils_dateCorrectionPipe.createAutoCorrectedDatePipe({
66
- maxYear: maxYear,
67
- minYear: minYear,
68
- });
69
- }, [maxYear, minYear]);
70
- var changeHandler = React.useCallback(function (event, newValue, newDate) {
71
- if (uncontrolled) {
72
- setStateValue(newValue);
61
+ var DateInput = React.forwardRef(function (_a, ref) {
62
+ var _b = _a.mobileMode, mobileMode = _b === void 0 ? 'input' : _b, _c = _a.defaultValue, defaultValue = _c === void 0 ? '' : _c, rightAddons = _a.rightAddons, error = _a.error, propValue = _a.value, onBlur = _a.onBlur, onChange = _a.onChange, onComplete = _a.onComplete, restProps = __rest(_a, ["mobileMode", "defaultValue", "rightAddons", "error", "value", "onBlur", "onChange", "onComplete"]);
63
+ var inputRef = React.useRef(null);
64
+ var _d = React.useState(false), shouldRenderNative = _d[0], setShouldRenderNative = _d[1];
65
+ var _e = React.useState(propValue || defaultValue), value = _e[0], setValue = _e[1];
66
+ var _f = React.useState(!utils_format.isValid(propValue)), stateError = _f[0], setStateError = _f[1];
67
+ var handleValueValidity = React.useCallback(function (inputValue) {
68
+ // Валидируем незаполненное значение только если инпут не в фокусе (блюр, либо установка значения снаружи)
69
+ var validateIncomplete = inputRef.current && document.activeElement !== inputRef.current;
70
+ if (!inputValue || validateIncomplete || inputValue.length >= utils_format.DATE_MASK.length) {
71
+ setStateError(!utils_format.isValid(inputValue));
73
72
  }
74
- if (onChange) {
75
- onChange(event, { date: newDate, value: newValue });
76
- }
77
- }, [onChange, uncontrolled]);
73
+ }, []);
78
74
  var handleChange = React.useCallback(function (event) {
79
75
  var newValue = event.target.value;
80
- var newDate = utils_format.parseDateString(newValue);
81
- changeHandler(event, newValue, newDate);
82
- }, [changeHandler]);
76
+ // Позволяем вводить только цифры и точки
77
+ if (/[^\d.]/.test(newValue)) {
78
+ return;
79
+ }
80
+ var dots = newValue.match(/\./g);
81
+ // Не даем вводить больше, чем 2 точки
82
+ if (dots && dots.length > 2) {
83
+ return;
84
+ }
85
+ // Форматируем введенное значение (добавляем точки)
86
+ var formattedValue = utils_format.format(newValue);
87
+ var date = utils_format.parseDateString(formattedValue);
88
+ setValue(formattedValue);
89
+ if (onChange)
90
+ onChange(event, { date: date, value: formattedValue });
91
+ if (utils_format.isCompleteDateInput(formattedValue)) {
92
+ var valid = formattedValue.length > 0 && utils_format.isValid(formattedValue);
93
+ if (!valid)
94
+ return;
95
+ if (onComplete)
96
+ onComplete(event, { date: date, value: formattedValue });
97
+ }
98
+ }, [onChange, onComplete]);
83
99
  var handleNativeInputChange = React.useCallback(function (event) {
84
100
  var newDate = utils_format.parseDateString(event.target.value, utils_format.NATIVE_DATE_FORMAT);
85
101
  var newValue = event.target.value === '' ? '' : utils_format.formatDate(newDate);
86
- changeHandler(event, newValue, newDate);
87
- }, [changeHandler]);
88
- return (React__default['default'].createElement(coreComponentsMaskedInput.MaskedInput, __assign({}, restProps, { ref: ref, mask: utils_dateCorrectionPipe.mask, keepCharPositions: true, defaultValue: defaultValue, value: inputValue, onBeforeDisplay: pipe, onChange: handleChange, rightAddons: React__default['default'].createElement(React__default['default'].Fragment, null,
102
+ setValue(newValue);
103
+ if (onComplete)
104
+ onComplete(event, { date: newDate, value: newValue });
105
+ if (onChange)
106
+ onChange(event, { date: newDate, value: newValue });
107
+ }, [onComplete, onChange]);
108
+ var handleBlur = React.useCallback(function (event) {
109
+ handleValueValidity(value);
110
+ if (onBlur)
111
+ onBlur(event);
112
+ }, [handleValueValidity, onBlur, value]);
113
+ React.useEffect(function () {
114
+ if (mobileMode === 'native' && utils_nativeSupports.isInputDateSupported()) {
115
+ setShouldRenderNative(true);
116
+ }
117
+ }, [mobileMode]);
118
+ React.useEffect(function () {
119
+ if (typeof propValue !== 'undefined') {
120
+ setValue(propValue);
121
+ }
122
+ // eslint-disable-next-line react-hooks/exhaustive-deps
123
+ }, [propValue]);
124
+ React.useEffect(function () {
125
+ handleValueValidity(value);
126
+ }, [handleValueValidity, value]);
127
+ return (React__default['default'].createElement(coreComponentsInput.Input, __assign({}, restProps, { ref: mergeRefs__default['default']([ref, inputRef]), value: value, inputMode: 'decimal', pattern: '[0-9\\.]*', onChange: handleChange, onBlur: handleBlur, placeholder: '\u0414\u0414.\u041C\u041C.\u0413\u0413\u0413\u0413', error: error || stateError, rightAddons: React__default['default'].createElement(React__default['default'].Fragment, null,
89
128
  rightAddons,
90
129
  shouldRenderNative && (React__default['default'].createElement("input", { type: 'date', ref: ref, defaultValue: defaultValue, onChange: handleNativeInputChange, className: styles.nativeInput }))) })));
91
130
  });
@@ -1,16 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import React from 'react';
3
3
  import { ChangeEvent } from "react";
4
- import { MaskedInputProps } from "@alfalab/core-components-masked-input";
5
- type DateInputProps = Omit<MaskedInputProps, 'onBeforeDisplay' | 'mask' | 'onChange'> & {
6
- /**
7
- * Минимальный год, доступный для ввода
8
- */
9
- minYear?: number;
10
- /**
11
- * Максимальный год, доступный для ввода
12
- */
13
- maxYear?: number;
4
+ import { InputProps } from "@alfalab/core-components-input";
5
+ type DateInputProps = Omit<InputProps, 'onChange'> & {
14
6
  /**
15
7
  * Управление нативным режимом на мобильных устройствах
16
8
  */
@@ -22,16 +14,15 @@ type DateInputProps = Omit<MaskedInputProps, 'onBeforeDisplay' | 'mask' | 'onCha
22
14
  date: Date;
23
15
  value: string;
24
16
  }) => void;
25
- };
26
- declare const DateInput: React.ForwardRefExoticComponent<Pick<MaskedInputProps, "className" | "dataTestId" | "form" | "label" | "slot" | "style" | "title" | "pattern" | "children" | "leftAddons" | "rightAddons" | "size" | "block" | "colors" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "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" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "value" | "fieldClassName" | "labelClassName" | "addonsClassName" | "error" | "hint" | "bottomAddons" | "accept" | "alt" | "autoComplete" | "capture" | "checked" | "crossOrigin" | "height" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "readOnly" | "required" | "src" | "width" | "clear" | "success" | "inputClassName" | "focusedClassName" | "filledClassName" | "onClear" | "wrapperRef" | "keepCharPositions"> & {
27
- /**
28
- * Минимальный год, доступный для ввода
29
- */
30
- minYear?: number | undefined;
31
17
  /**
32
- * Максимальный год, доступный для ввода
18
+ * Обработчик окончания ввода
33
19
  */
34
- maxYear?: number | undefined;
20
+ onComplete?: (event: ChangeEvent<HTMLInputElement>, payload: {
21
+ date: Date;
22
+ value: string;
23
+ }) => void;
24
+ };
25
+ declare const DateInput: React.ForwardRefExoticComponent<Pick<InputProps, "className" | "dataTestId" | "form" | "label" | "slot" | "style" | "title" | "pattern" | "children" | "leftAddons" | "rightAddons" | "size" | "block" | "colors" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "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" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "value" | "fieldClassName" | "labelClassName" | "addonsClassName" | "error" | "hint" | "bottomAddons" | "accept" | "alt" | "autoComplete" | "capture" | "checked" | "crossOrigin" | "height" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "readOnly" | "required" | "src" | "width" | "clear" | "success" | "inputClassName" | "focusedClassName" | "filledClassName" | "onClear" | "wrapperRef"> & {
35
26
  /**
36
27
  * Управление нативным режимом на мобильных устройствах
37
28
  */
@@ -43,5 +34,12 @@ declare const DateInput: React.ForwardRefExoticComponent<Pick<MaskedInputProps,
43
34
  date: Date;
44
35
  value: string;
45
36
  }) => void) | undefined;
37
+ /**
38
+ * Обработчик окончания ввода
39
+ */
40
+ onComplete?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
41
+ date: Date;
42
+ value: string;
43
+ }) => void) | undefined;
46
44
  } & React.RefAttributes<HTMLInputElement>>;
47
45
  export { DateInputProps, DateInput };
@@ -3,16 +3,19 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
- var coreComponentsMaskedInput = require('@alfalab/core-components-masked-input/dist/cssm');
7
- require('date-fns');
6
+ var coreComponentsInput = require('@alfalab/core-components-input/dist/cssm');
7
+ var mergeRefs = require('react-merge-refs');
8
+ require('date-fns/parse');
9
+ require('date-fns/format');
10
+ require('date-fns/isValid');
8
11
  var utils_format = require('./utils/format.js');
9
- var utils_dateCorrectionPipe = require('./utils/date-correction-pipe.js');
10
12
  var utils_nativeSupports = require('./utils/native-supports.js');
11
13
  var styles = require('./index.module.css');
12
14
 
13
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
16
 
15
17
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
18
+ var mergeRefs__default = /*#__PURE__*/_interopDefaultLegacy(mergeRefs);
16
19
  var styles__default = /*#__PURE__*/_interopDefaultLegacy(styles);
17
20
 
18
21
  /*! *****************************************************************************
@@ -54,37 +57,73 @@ function __rest(s, e) {
54
57
  return t;
55
58
  }
56
59
 
57
- var DateInput = React__default['default'].forwardRef(function (_a, ref) {
58
- var maxYear = _a.maxYear, minYear = _a.minYear, _b = _a.mobileMode, mobileMode = _b === void 0 ? 'input' : _b, value = _a.value, defaultValue = _a.defaultValue, rightAddons = _a.rightAddons, onChange = _a.onChange, restProps = __rest(_a, ["maxYear", "minYear", "mobileMode", "value", "defaultValue", "rightAddons", "onChange"]);
59
- var uncontrolled = value === undefined;
60
- var shouldRenderNative = utils_nativeSupports.SUPPORTS_INPUT_TYPE_DATE && mobileMode === 'native';
61
- var _c = React.useState(defaultValue), stateValue = _c[0], setStateValue = _c[1];
62
- var inputValue = uncontrolled ? stateValue : value;
63
- var pipe = React.useMemo(function () {
64
- return utils_dateCorrectionPipe.createAutoCorrectedDatePipe({
65
- maxYear: maxYear,
66
- minYear: minYear,
67
- });
68
- }, [maxYear, minYear]);
69
- var changeHandler = React.useCallback(function (event, newValue, newDate) {
70
- if (uncontrolled) {
71
- setStateValue(newValue);
60
+ var DateInput = React.forwardRef(function (_a, ref) {
61
+ var _b = _a.mobileMode, mobileMode = _b === void 0 ? 'input' : _b, _c = _a.defaultValue, defaultValue = _c === void 0 ? '' : _c, rightAddons = _a.rightAddons, error = _a.error, propValue = _a.value, onBlur = _a.onBlur, onChange = _a.onChange, onComplete = _a.onComplete, restProps = __rest(_a, ["mobileMode", "defaultValue", "rightAddons", "error", "value", "onBlur", "onChange", "onComplete"]);
62
+ var inputRef = React.useRef(null);
63
+ var _d = React.useState(false), shouldRenderNative = _d[0], setShouldRenderNative = _d[1];
64
+ var _e = React.useState(propValue || defaultValue), value = _e[0], setValue = _e[1];
65
+ var _f = React.useState(!utils_format.isValid(propValue)), stateError = _f[0], setStateError = _f[1];
66
+ var handleValueValidity = React.useCallback(function (inputValue) {
67
+ // Валидируем незаполненное значение только если инпут не в фокусе (блюр, либо установка значения снаружи)
68
+ var validateIncomplete = inputRef.current && document.activeElement !== inputRef.current;
69
+ if (!inputValue || validateIncomplete || inputValue.length >= utils_format.DATE_MASK.length) {
70
+ setStateError(!utils_format.isValid(inputValue));
72
71
  }
73
- if (onChange) {
74
- onChange(event, { date: newDate, value: newValue });
75
- }
76
- }, [onChange, uncontrolled]);
72
+ }, []);
77
73
  var handleChange = React.useCallback(function (event) {
78
74
  var newValue = event.target.value;
79
- var newDate = utils_format.parseDateString(newValue);
80
- changeHandler(event, newValue, newDate);
81
- }, [changeHandler]);
75
+ // Позволяем вводить только цифры и точки
76
+ if (/[^\d.]/.test(newValue)) {
77
+ return;
78
+ }
79
+ var dots = newValue.match(/\./g);
80
+ // Не даем вводить больше, чем 2 точки
81
+ if (dots && dots.length > 2) {
82
+ return;
83
+ }
84
+ // Форматируем введенное значение (добавляем точки)
85
+ var formattedValue = utils_format.format(newValue);
86
+ var date = utils_format.parseDateString(formattedValue);
87
+ setValue(formattedValue);
88
+ if (onChange)
89
+ onChange(event, { date: date, value: formattedValue });
90
+ if (utils_format.isCompleteDateInput(formattedValue)) {
91
+ var valid = formattedValue.length > 0 && utils_format.isValid(formattedValue);
92
+ if (!valid)
93
+ return;
94
+ if (onComplete)
95
+ onComplete(event, { date: date, value: formattedValue });
96
+ }
97
+ }, [onChange, onComplete]);
82
98
  var handleNativeInputChange = React.useCallback(function (event) {
83
99
  var newDate = utils_format.parseDateString(event.target.value, utils_format.NATIVE_DATE_FORMAT);
84
100
  var newValue = event.target.value === '' ? '' : utils_format.formatDate(newDate);
85
- changeHandler(event, newValue, newDate);
86
- }, [changeHandler]);
87
- return (React__default['default'].createElement(coreComponentsMaskedInput.MaskedInput, __assign({}, restProps, { ref: ref, mask: utils_dateCorrectionPipe.mask, keepCharPositions: true, defaultValue: defaultValue, value: inputValue, onBeforeDisplay: pipe, onChange: handleChange, rightAddons: React__default['default'].createElement(React__default['default'].Fragment, null,
101
+ setValue(newValue);
102
+ if (onComplete)
103
+ onComplete(event, { date: newDate, value: newValue });
104
+ if (onChange)
105
+ onChange(event, { date: newDate, value: newValue });
106
+ }, [onComplete, onChange]);
107
+ var handleBlur = React.useCallback(function (event) {
108
+ handleValueValidity(value);
109
+ if (onBlur)
110
+ onBlur(event);
111
+ }, [handleValueValidity, onBlur, value]);
112
+ React.useEffect(function () {
113
+ if (mobileMode === 'native' && utils_nativeSupports.isInputDateSupported()) {
114
+ setShouldRenderNative(true);
115
+ }
116
+ }, [mobileMode]);
117
+ React.useEffect(function () {
118
+ if (typeof propValue !== 'undefined') {
119
+ setValue(propValue);
120
+ }
121
+ // eslint-disable-next-line react-hooks/exhaustive-deps
122
+ }, [propValue]);
123
+ React.useEffect(function () {
124
+ handleValueValidity(value);
125
+ }, [handleValueValidity, value]);
126
+ return (React__default['default'].createElement(coreComponentsInput.Input, __assign({}, restProps, { ref: mergeRefs__default['default']([ref, inputRef]), value: value, inputMode: 'decimal', pattern: '[0-9\\.]*', onChange: handleChange, onBlur: handleBlur, placeholder: '\u0414\u0414.\u041C\u041C.\u0413\u0413\u0413\u0413', error: error || stateError, rightAddons: React__default['default'].createElement(React__default['default'].Fragment, null,
88
127
  rightAddons,
89
128
  shouldRenderNative && (React__default['default'].createElement("input", { type: 'date', ref: ref, defaultValue: defaultValue, onChange: handleNativeInputChange, className: styles__default['default'].nativeInput }))) })));
90
129
  });
@@ -4,10 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var Component = require('./Component.js');
6
6
  require('react');
7
- require('@alfalab/core-components-masked-input/dist/cssm');
8
- require('date-fns');
7
+ require('@alfalab/core-components-input/dist/cssm');
8
+ require('react-merge-refs');
9
+ require('date-fns/parse');
10
+ require('date-fns/format');
11
+ require('date-fns/isValid');
9
12
  var utils_format = require('./utils/format.js');
10
- var utils_dateCorrectionPipe = require('./utils/date-correction-pipe.js');
11
13
  var utils_nativeSupports = require('./utils/native-supports.js');
12
14
  require('./index.module.css');
13
15
 
@@ -17,11 +19,9 @@ exports.DateInput = Component.DateInput;
17
19
  exports.DATE_FORMAT = utils_format.DATE_FORMAT;
18
20
  exports.DATE_MASK = utils_format.DATE_MASK;
19
21
  exports.NATIVE_DATE_FORMAT = utils_format.NATIVE_DATE_FORMAT;
22
+ exports.format = utils_format.format;
20
23
  exports.formatDate = utils_format.formatDate;
21
24
  exports.isCompleteDateInput = utils_format.isCompleteDateInput;
25
+ exports.isValid = utils_format.isValid;
22
26
  exports.parseDateString = utils_format.parseDateString;
23
- exports.createAutoCorrectedDatePipe = utils_dateCorrectionPipe.createAutoCorrectedDatePipe;
24
- exports.mask = utils_dateCorrectionPipe.mask;
25
- exports.IS_BROWSER = utils_nativeSupports.IS_BROWSER;
26
- exports.SUPPORTS_INPUT_TYPE_DATE = utils_nativeSupports.SUPPORTS_INPUT_TYPE_DATE;
27
27
  exports.isInputDateSupported = utils_nativeSupports.isInputDateSupported;
@@ -4,4 +4,6 @@ declare const DATE_MASK: (string | RegExp)[];
4
4
  declare const isCompleteDateInput: (input: string) => boolean;
5
5
  declare const formatDate: (date: number | Date, dateFormat?: string) => string;
6
6
  declare const parseDateString: (value: string, dateFormat?: string) => Date;
7
- export { DATE_FORMAT, NATIVE_DATE_FORMAT, DATE_MASK, isCompleteDateInput, formatDate, parseDateString };
7
+ declare const isValid: (inputValue?: string | undefined) => boolean;
8
+ declare const format: (value: string) => string;
9
+ export { DATE_FORMAT, NATIVE_DATE_FORMAT, DATE_MASK, isCompleteDateInput, formatDate, parseDateString, isValid, format };
@@ -2,7 +2,15 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dateFns = require('date-fns');
5
+ var parse = require('date-fns/parse');
6
+ var dateFnsFormat = require('date-fns/format');
7
+ var dateFnsIsValid = require('date-fns/isValid');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ var parse__default = /*#__PURE__*/_interopDefaultLegacy(parse);
12
+ var dateFnsFormat__default = /*#__PURE__*/_interopDefaultLegacy(dateFnsFormat);
13
+ var dateFnsIsValid__default = /*#__PURE__*/_interopDefaultLegacy(dateFnsIsValid);
6
14
 
7
15
  var DATE_FORMAT = 'dd.MM.yyyy';
8
16
  var NATIVE_DATE_FORMAT = 'yyyy-MM-dd';
@@ -10,16 +18,32 @@ var DATE_MASK = [/\d/, /\d/, '.', /\d/, /\d/, '.', /\d/, /\d/, /\d/, /\d/];
10
18
  var isCompleteDateInput = function (input) { return input.length === DATE_MASK.length; };
11
19
  var formatDate = function (date, dateFormat) {
12
20
  if (dateFormat === void 0) { dateFormat = DATE_FORMAT; }
13
- return dateFns.format(date, dateFormat);
21
+ return dateFnsFormat__default['default'](date, dateFormat);
14
22
  };
15
23
  var parseDateString = function (value, dateFormat) {
16
24
  if (dateFormat === void 0) { dateFormat = DATE_FORMAT; }
17
- return dateFns.parse(value, dateFormat, new Date());
25
+ return parse__default['default'](value, dateFormat, new Date());
26
+ };
27
+ var isValid = function (inputValue) {
28
+ return !inputValue || (isCompleteDateInput(inputValue) && dateFnsIsValid__default['default'](parseDateString(inputValue)));
18
29
  };
30
+ var format = function (value) {
31
+ return value
32
+ .replace(/^(\d\d)(\d)$/, '$1.$2') // 121 => 12.1
33
+ .replace(/^(\d\d)\.(\d\d)(\d)$/, '$1.$2.$3') // 12.122 => 12.12.2
34
+ .replace(/^(\d\d)\d\.(.*)/, '$1.$2') // 123.12.2005 => 12.12.2005
35
+ .replace(/^(\d\d\.\d\d)\d\.(.*)/, '$1.$2') // 12.123.2005 => 12.12.2005
36
+ .replace(/^(\d\d\.\d\d\.\d\d\d\d).*/, '$1') // 12.12.20056 => 12.12.2005
37
+ .replace(/\.$/, '') // 12. => 12
38
+ .replace(/^(\d\d\.\d\d)(\d\d\d\d)/, '$1.$2') // 12.122005 => 12.12.2005
39
+ .replace(/^(\d\d)(\d\d\.\d\d\d\d)/, '$1.$2');
40
+ }; // 1212.2005 => 12.12.2005
19
41
 
20
42
  exports.DATE_FORMAT = DATE_FORMAT;
21
43
  exports.DATE_MASK = DATE_MASK;
22
44
  exports.NATIVE_DATE_FORMAT = NATIVE_DATE_FORMAT;
45
+ exports.format = format;
23
46
  exports.formatDate = formatDate;
24
47
  exports.isCompleteDateInput = isCompleteDateInput;
48
+ exports.isValid = isValid;
25
49
  exports.parseDateString = parseDateString;
@@ -1,3 +1,2 @@
1
1
  export * from "./format";
2
- export * from "./date-correction-pipe";
3
2
  export * from "./native-supports";