@alfalab/core-components-masked-input 4.2.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.
@@ -0,0 +1,86 @@
1
+ /// <reference types="react" />
2
+ import React from 'react';
3
+ import { InputProps } from "@alfalab/core-components-input";
4
+ type Mask = Array<string | RegExp>;
5
+ type TextMaskConfig = {
6
+ currentCaretPosition: number;
7
+ rawValue: string;
8
+ previousConformedValue: string;
9
+ mask?: Mask | ((rawValue: string) => Mask);
10
+ guide?: boolean;
11
+ showMask?: boolean;
12
+ placeholderChar?: string;
13
+ keepCharPositions?: boolean;
14
+ pipe?: (conformedValue: string, config: TextMaskConfig) => false | string | {
15
+ value: string;
16
+ indexesOfPipedChars: number[];
17
+ };
18
+ };
19
+ type MaskedInputProps = InputProps & {
20
+ /**
21
+ * Маска для поля ввода
22
+ * https://github.com/text-mask/text-mask/blob/master/componentDocumentation.md#mask-array
23
+ */
24
+ mask?: TextMaskConfig['mask'];
25
+ /**
26
+ * Управляет поведением компонента при удалении символов
27
+ */
28
+ keepCharPositions?: TextMaskConfig['keepCharPositions'];
29
+ /**
30
+ * Дает возможность изменить значение поля перед рендером
31
+ */
32
+ onBeforeDisplay?: TextMaskConfig['pipe'];
33
+ };
34
+ declare const PLACEHOLDER_CHAR = "\u2000";
35
+ declare const MaskedInput: React.ForwardRefExoticComponent<Pick<React.InputHTMLAttributes<HTMLInputElement>, "className" | "form" | "slot" | "style" | "title" | "pattern" | "children" | "defaultChecked" | "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" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "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" | "accept" | "alt" | "autoComplete" | "capture" | "checked" | "crossOrigin" | "height" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "readOnly" | "required" | "src" | "width"> & {
36
+ value?: string | undefined;
37
+ defaultValue?: string | undefined;
38
+ block?: boolean | undefined;
39
+ clear?: boolean | undefined; /**
40
+ * Управляет поведением компонента при удалении символов
41
+ */
42
+ size?: "s" | "m" | "l" | "xl" | undefined;
43
+ colors?: "default" | "inverted" | undefined;
44
+ error?: React.ReactNode;
45
+ success?: boolean | undefined;
46
+ hint?: React.ReactNode;
47
+ label?: React.ReactNode;
48
+ type?: "number" | "text" | "tel" | "email" | "card" | "money" | "password" | undefined;
49
+ wrapperRef?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
50
+ leftAddons?: React.ReactNode;
51
+ rightAddons?: React.ReactNode;
52
+ bottomAddons?: React.ReactNode;
53
+ className?: string | undefined;
54
+ fieldClassName?: string | undefined;
55
+ inputClassName?: string | undefined;
56
+ labelClassName?: string | undefined;
57
+ addonsClassName?: string | undefined;
58
+ focusedClassName?: string | undefined;
59
+ filledClassName?: string | undefined;
60
+ onChange?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
61
+ value: string;
62
+ }) => void) | undefined;
63
+ onClear?: ((event: React.MouseEvent<HTMLButtonElement, globalThis.MouseEvent>) => void) | undefined;
64
+ onClick?: ((event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => void) | undefined;
65
+ onMouseDown?: ((event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => void) | undefined;
66
+ onMouseUp?: ((event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => void) | undefined;
67
+ dataTestId?: string | undefined;
68
+ } & {
69
+ /**
70
+ * Маска для поля ввода
71
+ * https://github.com/text-mask/text-mask/blob/master/componentDocumentation.md#mask-array
72
+ */
73
+ mask?: Mask | ((rawValue: string) => Mask) | undefined;
74
+ /**
75
+ * Управляет поведением компонента при удалении символов
76
+ */
77
+ keepCharPositions?: boolean | undefined;
78
+ /**
79
+ * Дает возможность изменить значение поля перед рендером
80
+ */
81
+ onBeforeDisplay?: ((conformedValue: string, config: TextMaskConfig) => string | false | {
82
+ value: string;
83
+ indexesOfPipedChars: number[];
84
+ }) | undefined;
85
+ } & React.RefAttributes<HTMLInputElement>>;
86
+ export { MaskedInputProps, PLACEHOLDER_CHAR, MaskedInput };
@@ -0,0 +1,119 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var cn = require('classnames');
7
+ var mergeRefs = require('react-merge-refs');
8
+ var textMaskCore = require('text-mask-core');
9
+ var coreComponentsInput = require('@alfalab/core-components-input/dist/cssm');
10
+ var styles = require('./index.module.css');
11
+
12
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
+
14
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
15
+ var cn__default = /*#__PURE__*/_interopDefaultLegacy(cn);
16
+ var mergeRefs__default = /*#__PURE__*/_interopDefaultLegacy(mergeRefs);
17
+ var styles__default = /*#__PURE__*/_interopDefaultLegacy(styles);
18
+
19
+ /*! *****************************************************************************
20
+ Copyright (c) Microsoft Corporation.
21
+
22
+ Permission to use, copy, modify, and/or distribute this software for any
23
+ purpose with or without fee is hereby granted.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
26
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
27
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
28
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
29
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
30
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
31
+ PERFORMANCE OF THIS SOFTWARE.
32
+ ***************************************************************************** */
33
+ var __assign = function () {
34
+ __assign = Object.assign || function __assign(t) {
35
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
36
+ s = arguments[i];
37
+ for (var p in s)
38
+ if (Object.prototype.hasOwnProperty.call(s, p))
39
+ t[p] = s[p];
40
+ }
41
+ return t;
42
+ };
43
+ return __assign.apply(this, arguments);
44
+ };
45
+ function __rest(s, e) {
46
+ var t = {};
47
+ for (var p in s)
48
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
49
+ t[p] = s[p];
50
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
51
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
52
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
53
+ t[p[i]] = s[p[i]];
54
+ }
55
+ return t;
56
+ }
57
+
58
+ // Символ плейсхолдера не может входить в маску, поэтому вместо пробела используется \u2000
59
+ var PLACEHOLDER_CHAR = '\u2000';
60
+ var MaskedInput = React__default['default'].forwardRef(function (_a, ref) {
61
+ var _b;
62
+ var mask = _a.mask, _c = _a.keepCharPositions, keepCharPositions = _c === void 0 ? false : _c, value = _a.value, defaultValue = _a.defaultValue, className = _a.className, onBeforeDisplay = _a.onBeforeDisplay, onChange = _a.onChange, onClear = _a.onClear, restProps = __rest(_a, ["mask", "keepCharPositions", "value", "defaultValue", "className", "onBeforeDisplay", "onChange", "onClear"]);
63
+ var inputRef = React.useRef(null);
64
+ var textMask = React.useRef(null);
65
+ var _d = React.useState(value || defaultValue || ''), inputValue = _d[0], setInputValue = _d[1];
66
+ // Не показываем сырое значение до применения маски
67
+ var _e = React.useState(true), textHidden = _e[0], setTextHidden = _e[1];
68
+ var update = React.useCallback(function (newValue) {
69
+ if (newValue === void 0) { newValue = ''; }
70
+ if (textMask.current && inputRef.current) {
71
+ try {
72
+ textMask.current.update(newValue);
73
+ }
74
+ catch (e) {
75
+ // ignore masking errors
76
+ }
77
+ setInputValue(inputRef.current.value);
78
+ }
79
+ }, []);
80
+ var handleInputChange = React.useCallback(function (event) {
81
+ update(event.target.value);
82
+ if (onChange) {
83
+ onChange(event, {
84
+ value: event.target.value,
85
+ });
86
+ }
87
+ }, [onChange, update]);
88
+ var handleClear = React.useCallback(function (event) {
89
+ update('');
90
+ if (onClear)
91
+ onClear(event);
92
+ }, [onClear, update]);
93
+ React.useEffect(function () {
94
+ if (inputRef.current) {
95
+ textMask.current = textMaskCore.createTextMaskInputElement({
96
+ mask: mask,
97
+ inputElement: inputRef.current,
98
+ pipe: onBeforeDisplay,
99
+ guide: false,
100
+ keepCharPositions: keepCharPositions,
101
+ showMask: false,
102
+ placeholderChar: PLACEHOLDER_CHAR,
103
+ rawValue: '',
104
+ currentCaretPosition: 0,
105
+ previousConformedValue: '',
106
+ });
107
+ }
108
+ }, [onBeforeDisplay, mask, keepCharPositions]);
109
+ React.useEffect(function () {
110
+ update(value || defaultValue);
111
+ }, [value, update, defaultValue]);
112
+ React.useEffect(function () {
113
+ setTextHidden(false);
114
+ }, []);
115
+ return (React__default['default'].createElement(coreComponentsInput.Input, __assign({}, restProps, { className: cn__default['default'](className, (_b = {}, _b[styles__default['default'].textHidden] = textHidden, _b)), value: inputValue, onChange: handleInputChange, onClear: handleClear, ref: mergeRefs__default['default']([ref, inputRef]) })));
116
+ });
117
+
118
+ exports.MaskedInput = MaskedInput;
119
+ exports.PLACEHOLDER_CHAR = PLACEHOLDER_CHAR;
@@ -0,0 +1 @@
1
+ export * from "./Component";
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var Component = require('./Component.js');
6
+ require('react');
7
+ require('classnames');
8
+ require('react-merge-refs');
9
+ require('text-mask-core');
10
+ require('@alfalab/core-components-input/dist/cssm');
11
+ require('./index.module.css');
12
+
13
+
14
+
15
+ exports.MaskedInput = Component.MaskedInput;
16
+ exports.PLACEHOLDER_CHAR = Component.PLACEHOLDER_CHAR;
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,86 @@
1
+ /// <reference types="react" />
2
+ import React from 'react';
3
+ import { InputProps } from "@alfalab/core-components-input";
4
+ type Mask = Array<string | RegExp>;
5
+ type TextMaskConfig = {
6
+ currentCaretPosition: number;
7
+ rawValue: string;
8
+ previousConformedValue: string;
9
+ mask?: Mask | ((rawValue: string) => Mask);
10
+ guide?: boolean;
11
+ showMask?: boolean;
12
+ placeholderChar?: string;
13
+ keepCharPositions?: boolean;
14
+ pipe?: (conformedValue: string, config: TextMaskConfig) => false | string | {
15
+ value: string;
16
+ indexesOfPipedChars: number[];
17
+ };
18
+ };
19
+ type MaskedInputProps = InputProps & {
20
+ /**
21
+ * Маска для поля ввода
22
+ * https://github.com/text-mask/text-mask/blob/master/componentDocumentation.md#mask-array
23
+ */
24
+ mask?: TextMaskConfig['mask'];
25
+ /**
26
+ * Управляет поведением компонента при удалении символов
27
+ */
28
+ keepCharPositions?: TextMaskConfig['keepCharPositions'];
29
+ /**
30
+ * Дает возможность изменить значение поля перед рендером
31
+ */
32
+ onBeforeDisplay?: TextMaskConfig['pipe'];
33
+ };
34
+ declare const PLACEHOLDER_CHAR = "\u2000";
35
+ declare const MaskedInput: React.ForwardRefExoticComponent<Pick<React.InputHTMLAttributes<HTMLInputElement>, "className" | "form" | "slot" | "style" | "title" | "pattern" | "children" | "defaultChecked" | "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" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "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" | "accept" | "alt" | "autoComplete" | "capture" | "checked" | "crossOrigin" | "height" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "readOnly" | "required" | "src" | "width"> & {
36
+ value?: string | undefined;
37
+ defaultValue?: string | undefined;
38
+ block?: boolean | undefined;
39
+ clear?: boolean | undefined; /**
40
+ * Управляет поведением компонента при удалении символов
41
+ */
42
+ size?: "s" | "m" | "l" | "xl" | undefined;
43
+ colors?: "default" | "inverted" | undefined;
44
+ error?: React.ReactNode;
45
+ success?: boolean | undefined;
46
+ hint?: React.ReactNode;
47
+ label?: React.ReactNode;
48
+ type?: "number" | "text" | "tel" | "email" | "card" | "money" | "password" | undefined;
49
+ wrapperRef?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
50
+ leftAddons?: React.ReactNode;
51
+ rightAddons?: React.ReactNode;
52
+ bottomAddons?: React.ReactNode;
53
+ className?: string | undefined;
54
+ fieldClassName?: string | undefined;
55
+ inputClassName?: string | undefined;
56
+ labelClassName?: string | undefined;
57
+ addonsClassName?: string | undefined;
58
+ focusedClassName?: string | undefined;
59
+ filledClassName?: string | undefined;
60
+ onChange?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
61
+ value: string;
62
+ }) => void) | undefined;
63
+ onClear?: ((event: React.MouseEvent<HTMLButtonElement, globalThis.MouseEvent>) => void) | undefined;
64
+ onClick?: ((event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => void) | undefined;
65
+ onMouseDown?: ((event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => void) | undefined;
66
+ onMouseUp?: ((event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => void) | undefined;
67
+ dataTestId?: string | undefined;
68
+ } & {
69
+ /**
70
+ * Маска для поля ввода
71
+ * https://github.com/text-mask/text-mask/blob/master/componentDocumentation.md#mask-array
72
+ */
73
+ mask?: Mask | ((rawValue: string) => Mask) | undefined;
74
+ /**
75
+ * Управляет поведением компонента при удалении символов
76
+ */
77
+ keepCharPositions?: boolean | undefined;
78
+ /**
79
+ * Дает возможность изменить значение поля перед рендером
80
+ */
81
+ onBeforeDisplay?: ((conformedValue: string, config: TextMaskConfig) => string | false | {
82
+ value: string;
83
+ indexesOfPipedChars: number[];
84
+ }) | undefined;
85
+ } & React.RefAttributes<HTMLInputElement>>;
86
+ export { MaskedInputProps, PLACEHOLDER_CHAR, MaskedInput };
@@ -0,0 +1,109 @@
1
+ import React, { useRef, useState, useCallback, useEffect } from 'react';
2
+ import cn from 'classnames';
3
+ import mergeRefs from 'react-merge-refs';
4
+ import { createTextMaskInputElement } from 'text-mask-core';
5
+ import { Input } from '@alfalab/core-components-input/dist/esm';
6
+
7
+ /*! *****************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
+ ***************************************************************************** */
21
+ var __assign = function () {
22
+ __assign = Object.assign || function __assign(t) {
23
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
24
+ s = arguments[i];
25
+ for (var p in s)
26
+ if (Object.prototype.hasOwnProperty.call(s, p))
27
+ t[p] = s[p];
28
+ }
29
+ return t;
30
+ };
31
+ return __assign.apply(this, arguments);
32
+ };
33
+ function __rest(s, e) {
34
+ var t = {};
35
+ for (var p in s)
36
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
37
+ t[p] = s[p];
38
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
39
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
40
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
41
+ t[p[i]] = s[p[i]];
42
+ }
43
+ return t;
44
+ }
45
+
46
+ var styles = {"textHidden":"masked-input__textHidden_2no40"};
47
+ require('./index.css')
48
+
49
+ // Символ плейсхолдера не может входить в маску, поэтому вместо пробела используется \u2000
50
+ var PLACEHOLDER_CHAR = '\u2000';
51
+ var MaskedInput = React.forwardRef(function (_a, ref) {
52
+ var _b;
53
+ var mask = _a.mask, _c = _a.keepCharPositions, keepCharPositions = _c === void 0 ? false : _c, value = _a.value, defaultValue = _a.defaultValue, className = _a.className, onBeforeDisplay = _a.onBeforeDisplay, onChange = _a.onChange, onClear = _a.onClear, restProps = __rest(_a, ["mask", "keepCharPositions", "value", "defaultValue", "className", "onBeforeDisplay", "onChange", "onClear"]);
54
+ var inputRef = useRef(null);
55
+ var textMask = useRef(null);
56
+ var _d = useState(value || defaultValue || ''), inputValue = _d[0], setInputValue = _d[1];
57
+ // Не показываем сырое значение до применения маски
58
+ var _e = useState(true), textHidden = _e[0], setTextHidden = _e[1];
59
+ var update = useCallback(function (newValue) {
60
+ if (newValue === void 0) { newValue = ''; }
61
+ if (textMask.current && inputRef.current) {
62
+ try {
63
+ textMask.current.update(newValue);
64
+ }
65
+ catch (e) {
66
+ // ignore masking errors
67
+ }
68
+ setInputValue(inputRef.current.value);
69
+ }
70
+ }, []);
71
+ var handleInputChange = useCallback(function (event) {
72
+ update(event.target.value);
73
+ if (onChange) {
74
+ onChange(event, {
75
+ value: event.target.value,
76
+ });
77
+ }
78
+ }, [onChange, update]);
79
+ var handleClear = useCallback(function (event) {
80
+ update('');
81
+ if (onClear)
82
+ onClear(event);
83
+ }, [onClear, update]);
84
+ useEffect(function () {
85
+ if (inputRef.current) {
86
+ textMask.current = createTextMaskInputElement({
87
+ mask: mask,
88
+ inputElement: inputRef.current,
89
+ pipe: onBeforeDisplay,
90
+ guide: false,
91
+ keepCharPositions: keepCharPositions,
92
+ showMask: false,
93
+ placeholderChar: PLACEHOLDER_CHAR,
94
+ rawValue: '',
95
+ currentCaretPosition: 0,
96
+ previousConformedValue: '',
97
+ });
98
+ }
99
+ }, [onBeforeDisplay, mask, keepCharPositions]);
100
+ useEffect(function () {
101
+ update(value || defaultValue);
102
+ }, [value, update, defaultValue]);
103
+ useEffect(function () {
104
+ setTextHidden(false);
105
+ }, []);
106
+ return (React.createElement(Input, __assign({}, restProps, { className: cn(className, (_b = {}, _b[styles.textHidden] = textHidden, _b)), value: inputValue, onChange: handleInputChange, onClear: handleClear, ref: mergeRefs([ref, inputRef]) })));
107
+ });
108
+
109
+ export { MaskedInput, PLACEHOLDER_CHAR };
@@ -0,0 +1 @@
1
+ /* hash: 2no40 */
@@ -0,0 +1 @@
1
+ export * from "./Component";
@@ -0,0 +1,6 @@
1
+ export { MaskedInput, PLACEHOLDER_CHAR } from './Component.js';
2
+ import 'react';
3
+ import 'classnames';
4
+ import 'react-merge-refs';
5
+ import 'text-mask-core';
6
+ import '@alfalab/core-components-input/dist/esm';
package/dist/index.css ADDED
@@ -0,0 +1 @@
1
+ /* hash: 2no40 */
@@ -0,0 +1 @@
1
+ export * from "./Component";