@alfalab/core-components-masked-input 6.3.18 → 6.3.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Component.js CHANGED
@@ -15,7 +15,7 @@ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
15
15
  var mergeRefs__default = /*#__PURE__*/_interopDefaultCompat(mergeRefs);
16
16
  var cn__default = /*#__PURE__*/_interopDefaultCompat(cn);
17
17
 
18
- var styles = {"textHidden":"masked-input__textHidden_1gxmc"};
18
+ var styles = {"textHidden":"masked-input__textHidden_mrvxw"};
19
19
  require('./index.css')
20
20
 
21
21
  // Символ плейсхолдера не может входить в маску, поэтому вместо пробела используется \u2000
package/esm/Component.js CHANGED
@@ -5,7 +5,7 @@ import cn from 'classnames';
5
5
  import { createTextMaskInputElement } from 'text-mask-core';
6
6
  import { Input } from '@alfalab/core-components-input/esm';
7
7
 
8
- var styles = {"textHidden":"masked-input__textHidden_1gxmc"};
8
+ var styles = {"textHidden":"masked-input__textHidden_mrvxw"};
9
9
  require('./index.css')
10
10
 
11
11
  // Символ плейсхолдера не может входить в маску, поэтому вместо пробела используется \u2000
package/esm/index.css CHANGED
@@ -1,4 +1,4 @@
1
- /* hash: 1ubv8 */
2
- .masked-input__textHidden_1gxmc input {
1
+ /* hash: 1vhqg */
2
+ .masked-input__textHidden_mrvxw input {
3
3
  opacity: 0;
4
4
  }
package/index.css CHANGED
@@ -1,4 +1,4 @@
1
- /* hash: 1ubv8 */
2
- .masked-input__textHidden_1gxmc input {
1
+ /* hash: 1vhqg */
2
+ .masked-input__textHidden_mrvxw input {
3
3
  opacity: 0;
4
4
  }
@@ -4,7 +4,7 @@ import cn from 'classnames';
4
4
  import { createTextMaskInputElement } from 'text-mask-core';
5
5
  import { Input } from '@alfalab/core-components-input/modern';
6
6
 
7
- const styles = {"textHidden":"masked-input__textHidden_1gxmc"};
7
+ const styles = {"textHidden":"masked-input__textHidden_mrvxw"};
8
8
  require('./index.css')
9
9
 
10
10
  // Символ плейсхолдера не может входить в маску, поэтому вместо пробела используется \u2000
package/modern/index.css CHANGED
@@ -1,4 +1,4 @@
1
- /* hash: 1ubv8 */
2
- .masked-input__textHidden_1gxmc input {
1
+ /* hash: 1vhqg */
2
+ .masked-input__textHidden_mrvxw input {
3
3
  opacity: 0;
4
4
  }
@@ -0,0 +1,53 @@
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<Omit<import("@alfalab/core-components-input/components/base-input").BaseInputProps, "FormControlComponent"> & {
36
+ breakpoint?: number | undefined;
37
+ defaultMatchMediaValue?: boolean | (() => boolean) | undefined;
38
+ } & {
39
+ /**
40
+ * Маска для поля ввода
41
+ * https://github.com/text-mask/text-mask/blob/master/componentDocumentation.md#mask-array
42
+ */
43
+ mask?: TextMaskConfig['mask'];
44
+ /**
45
+ * Управляет поведением компонента при удалении символов
46
+ */
47
+ keepCharPositions?: TextMaskConfig['keepCharPositions'];
48
+ /**
49
+ * Дает возможность изменить значение поля перед рендером
50
+ */
51
+ onBeforeDisplay?: TextMaskConfig['pipe'];
52
+ } & React.RefAttributes<HTMLInputElement>>;
53
+ export { TextMaskConfig, MaskedInputProps, PLACEHOLDER_CHAR, MaskedInput };
@@ -0,0 +1,66 @@
1
+ import React, { useState, useRef, useCallback, useEffect } from 'react';
2
+ import mergeRefs from 'react-merge-refs';
3
+ import cn from 'classnames';
4
+ import { createTextMaskInputElement } from 'text-mask-core';
5
+ import { Input } from '@alfalab/core-components-input/moderncssm';
6
+ import styles from './index.module.css';
7
+
8
+ // Символ плейсхолдера не может входить в маску, поэтому вместо пробела используется \u2000
9
+ const PLACEHOLDER_CHAR = '\u2000';
10
+ const MaskedInput = React.forwardRef(({ mask, keepCharPositions = false, value, defaultValue, className, onBeforeDisplay, onChange, onClear, ...restProps }, ref) => {
11
+ const [inputNode, setInputNode] = useState(null);
12
+ const textMask = useRef(null);
13
+ const [inputValue, setInputValue] = useState(value || defaultValue || '');
14
+ // Не показываем сырое значение до применения маски
15
+ const [textHidden, setTextHidden] = useState(true);
16
+ const update = useCallback((newValue = '') => {
17
+ if (textMask.current && inputNode) {
18
+ try {
19
+ textMask.current.update(newValue);
20
+ }
21
+ catch (e) {
22
+ // ignore masking errors
23
+ }
24
+ setInputValue(inputNode.value);
25
+ }
26
+ }, [inputNode]);
27
+ const handleInputChange = useCallback((event) => {
28
+ update(event.target.value);
29
+ if (onChange) {
30
+ onChange(event, {
31
+ value: event.target.value,
32
+ });
33
+ }
34
+ }, [onChange, update]);
35
+ const handleClear = useCallback((event) => {
36
+ update('');
37
+ if (onClear)
38
+ onClear(event);
39
+ }, [onClear, update]);
40
+ useEffect(() => {
41
+ if (inputNode) {
42
+ textMask.current = createTextMaskInputElement({
43
+ mask,
44
+ inputElement: inputNode,
45
+ pipe: onBeforeDisplay,
46
+ guide: false,
47
+ keepCharPositions,
48
+ showMask: false,
49
+ placeholderChar: PLACEHOLDER_CHAR,
50
+ rawValue: '',
51
+ currentCaretPosition: 0,
52
+ previousConformedValue: '',
53
+ });
54
+ }
55
+ }, [onBeforeDisplay, mask, keepCharPositions, inputNode]);
56
+ useEffect(() => {
57
+ update(value || defaultValue);
58
+ }, [value, update, defaultValue]);
59
+ useEffect(() => {
60
+ setTextHidden(false);
61
+ }, []);
62
+ return (React.createElement(Input, { ...restProps, className: cn(className, { [styles.textHidden]: textHidden }), value: inputValue, onChange: handleInputChange, onClear: handleClear, ref: mergeRefs([ref, setInputNode]) }));
63
+ });
64
+ MaskedInput.displayName = 'MaskedInput';
65
+
66
+ export { MaskedInput, PLACEHOLDER_CHAR };
@@ -0,0 +1 @@
1
+ export * from "./Component";
@@ -0,0 +1 @@
1
+ export { MaskedInput, PLACEHOLDER_CHAR } from './Component.js';
@@ -0,0 +1,3 @@
1
+ .textHidden input {
2
+ opacity: 0;
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfalab/core-components-masked-input",
3
- "version": "6.3.18",
3
+ "version": "6.3.19",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -14,12 +14,12 @@
14
14
  "react": "^16.9.0 || ^17.0.1 || ^18.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@alfalab/core-components-input": "^15.0.5",
17
+ "@alfalab/core-components-input": "^15.1.0",
18
18
  "classnames": "^2.3.1",
19
19
  "react-merge-refs": "^1.1.0",
20
20
  "text-mask-core": "^5.1.2",
21
21
  "tslib": "^2.4.0"
22
22
  },
23
- "themesVersion": "13.0.2",
24
- "varsVersion": "9.11.1"
23
+ "themesVersion": "13.1.0",
24
+ "varsVersion": "9.12.0"
25
25
  }