@skbkontur/react-ui 4.25.2 → 4.26.0-MaskedInput-2nd.7

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 (191) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/LICENSE +21 -21
  3. package/README.md +41 -13
  4. package/cjs/components/Autocomplete/Autocomplete.md +76 -3
  5. package/cjs/components/Button/Button.md +38 -11
  6. package/cjs/components/Calendar/Calendar.md +40 -0
  7. package/cjs/components/DropdownMenu/DropdownMenu.md +39 -0
  8. package/cjs/components/FileUploader/FileUploader.d.ts +2 -0
  9. package/cjs/components/FileUploader/FileUploader.js +32 -9
  10. package/cjs/components/FileUploader/FileUploader.js.map +1 -1
  11. package/cjs/components/FileUploader/FileUploader.md +29 -0
  12. package/cjs/components/Gapped/Gapped.md +43 -43
  13. package/cjs/components/Input/Input.d.ts +3 -2
  14. package/cjs/components/Input/Input.js +7 -4
  15. package/cjs/components/Input/Input.js.map +1 -1
  16. package/cjs/components/MaskedInput/ColorableInputElement/ColorableInputElement.d.ts +10 -0
  17. package/cjs/components/MaskedInput/ColorableInputElement/ColorableInputElement.js +158 -0
  18. package/cjs/components/MaskedInput/ColorableInputElement/ColorableInputElement.js.map +1 -0
  19. package/cjs/components/MaskedInput/ColorableInputElement/ColorableInputElement.styles.d.ts +3 -0
  20. package/cjs/components/MaskedInput/ColorableInputElement/ColorableInputElement.styles.js +8 -0
  21. package/cjs/components/MaskedInput/ColorableInputElement/ColorableInputElement.styles.js.map +1 -0
  22. package/cjs/components/MaskedInput/ColorableInputElement/index.d.ts +1 -0
  23. package/cjs/components/MaskedInput/ColorableInputElement/index.js +1 -0
  24. package/cjs/components/MaskedInput/ColorableInputElement/index.js.map +1 -0
  25. package/cjs/components/MaskedInput/FixedIMaskInput.d.ts +9 -0
  26. package/cjs/components/MaskedInput/FixedIMaskInput.js +215 -0
  27. package/cjs/components/MaskedInput/FixedIMaskInput.js.map +1 -0
  28. package/cjs/components/MaskedInput/MaskedInput.d.ts +43 -4
  29. package/cjs/components/MaskedInput/MaskedInput.helpers.d.ts +10 -0
  30. package/cjs/components/MaskedInput/MaskedInput.helpers.js +30 -0
  31. package/cjs/components/MaskedInput/MaskedInput.helpers.js.map +1 -0
  32. package/cjs/components/MaskedInput/MaskedInput.js +172 -23
  33. package/cjs/components/MaskedInput/MaskedInput.js.map +1 -1
  34. package/cjs/components/MaskedInput/MaskedInput.md +100 -9
  35. package/cjs/components/MaskedInput/MaskedInput.styles.d.ts +3 -0
  36. package/cjs/components/MaskedInput/MaskedInput.styles.js +4 -0
  37. package/cjs/components/MaskedInput/MaskedInput.styles.js.map +1 -0
  38. package/cjs/components/RadioGroup/RadioGroup.md +43 -43
  39. package/cjs/components/ScrollContainer/ScrollContainer.d.ts +1 -0
  40. package/cjs/components/ScrollContainer/ScrollContainer.js +6 -0
  41. package/cjs/components/ScrollContainer/ScrollContainer.js.map +1 -1
  42. package/cjs/hooks/useDrop.d.ts +1 -1
  43. package/cjs/hooks/useDrop.js.map +1 -1
  44. package/cjs/index.d.ts +1 -0
  45. package/cjs/index.js +1 -0
  46. package/cjs/index.js.map +1 -1
  47. package/cjs/internal/FileUploaderControl/FileUploaderControlProvider.d.ts +5 -2
  48. package/cjs/internal/FileUploaderControl/FileUploaderControlProvider.js +16 -3
  49. package/cjs/internal/FileUploaderControl/FileUploaderControlProvider.js.map +1 -1
  50. package/cjs/internal/FileUploaderControl/FileUploaderFile/FileUploaderFile.d.ts +1 -0
  51. package/cjs/internal/FileUploaderControl/FileUploaderFile/FileUploaderFile.js +4 -2
  52. package/cjs/internal/FileUploaderControl/FileUploaderFile/FileUploaderFile.js.map +1 -1
  53. package/cjs/internal/FileUploaderControl/FileUploaderFileList/FileUploaderFileList.d.ts +1 -0
  54. package/cjs/internal/FileUploaderControl/FileUploaderFileList/FileUploaderFileList.js +3 -2
  55. package/cjs/internal/FileUploaderControl/FileUploaderFileList/FileUploaderFileList.js.map +1 -1
  56. package/cjs/internal/RenderContainer/RenderContainer.d.ts +2 -0
  57. package/cjs/internal/RenderContainer/RenderContainer.js +6 -3
  58. package/cjs/internal/RenderContainer/RenderContainer.js.map +1 -1
  59. package/cjs/internal/RenderContainer/RenderInnerContainer.js +3 -2
  60. package/cjs/internal/RenderContainer/RenderInnerContainer.js.map +1 -1
  61. package/cjs/internal/ThemeShowcase/ThemeShowcase.md +13 -13
  62. package/cjs/internal/ZIndex/ZIndex.d.ts +7 -3
  63. package/cjs/internal/ZIndex/ZIndex.js +41 -3
  64. package/cjs/internal/ZIndex/ZIndex.js.map +1 -1
  65. package/cjs/internal/themes/Theme2022Dark.js +1 -1
  66. package/cjs/internal/themes/Theme2022Dark.js.map +1 -1
  67. package/cjs/lib/events/MouseDrag.d.ts +1 -1
  68. package/cjs/lib/events/MouseDrag.js.map +1 -1
  69. package/cjs/lib/events/keyboard/identifiers.d.ts +3 -0
  70. package/cjs/lib/events/keyboard/identifiers.js +5 -1
  71. package/cjs/lib/events/keyboard/identifiers.js.map +1 -1
  72. package/cjs/lib/listenFocusOutside.js +4 -2
  73. package/cjs/lib/listenFocusOutside.js.map +1 -1
  74. package/cjs/lib/styles/HoldSelectionColor.js +1 -1
  75. package/cjs/lib/styles/HoldSelectionColor.js.map +1 -1
  76. package/cjs/lib/styles/UiFont.d.ts +4 -0
  77. package/cjs/lib/styles/UiFont.js +61 -0
  78. package/cjs/lib/styles/UiFont.js.map +1 -0
  79. package/components/Autocomplete/Autocomplete.md +76 -3
  80. package/components/Button/Button.md +38 -11
  81. package/components/Calendar/Calendar.md +40 -0
  82. package/components/DropdownMenu/DropdownMenu.md +39 -0
  83. package/components/FileUploader/FileUploader/FileUploader.js +30 -8
  84. package/components/FileUploader/FileUploader/FileUploader.js.map +1 -1
  85. package/components/FileUploader/FileUploader.d.ts +2 -0
  86. package/components/FileUploader/FileUploader.md +29 -0
  87. package/components/Gapped/Gapped.md +43 -43
  88. package/components/Input/Input/Input.js +8 -4
  89. package/components/Input/Input/Input.js.map +1 -1
  90. package/components/Input/Input.d.ts +3 -2
  91. package/components/MaskedInput/ColorableInputElement/ColorableInputElement/ColorableInputElement.js +152 -0
  92. package/components/MaskedInput/ColorableInputElement/ColorableInputElement/ColorableInputElement.js.map +1 -0
  93. package/components/MaskedInput/ColorableInputElement/ColorableInputElement/package.json +6 -0
  94. package/components/MaskedInput/ColorableInputElement/ColorableInputElement.d.ts +10 -0
  95. package/components/MaskedInput/ColorableInputElement/ColorableInputElement.styles/ColorableInputElement.styles.js +9 -0
  96. package/components/MaskedInput/ColorableInputElement/ColorableInputElement.styles/ColorableInputElement.styles.js.map +1 -0
  97. package/components/MaskedInput/ColorableInputElement/ColorableInputElement.styles/package.json +6 -0
  98. package/components/MaskedInput/ColorableInputElement/ColorableInputElement.styles.d.ts +3 -0
  99. package/components/MaskedInput/ColorableInputElement/index/index.js +1 -0
  100. package/components/MaskedInput/ColorableInputElement/index/index.js.map +1 -0
  101. package/components/MaskedInput/ColorableInputElement/index/package.json +6 -0
  102. package/components/MaskedInput/ColorableInputElement/index.d.ts +1 -0
  103. package/components/MaskedInput/ColorableInputElement/package.json +6 -0
  104. package/components/MaskedInput/FixedIMaskInput/FixedIMaskInput.js +231 -0
  105. package/components/MaskedInput/FixedIMaskInput/FixedIMaskInput.js.map +1 -0
  106. package/components/MaskedInput/FixedIMaskInput/package.json +6 -0
  107. package/components/MaskedInput/FixedIMaskInput.d.ts +9 -0
  108. package/components/MaskedInput/MaskedInput/MaskedInput.js +134 -26
  109. package/components/MaskedInput/MaskedInput/MaskedInput.js.map +1 -1
  110. package/components/MaskedInput/MaskedInput.d.ts +43 -4
  111. package/components/MaskedInput/MaskedInput.helpers/MaskedInput.helpers.js +27 -0
  112. package/components/MaskedInput/MaskedInput.helpers/MaskedInput.helpers.js.map +1 -0
  113. package/components/MaskedInput/MaskedInput.helpers/package.json +6 -0
  114. package/components/MaskedInput/MaskedInput.helpers.d.ts +10 -0
  115. package/components/MaskedInput/MaskedInput.md +100 -9
  116. package/components/MaskedInput/MaskedInput.styles/MaskedInput.styles.js +4 -0
  117. package/components/MaskedInput/MaskedInput.styles/MaskedInput.styles.js.map +1 -0
  118. package/components/MaskedInput/MaskedInput.styles/package.json +6 -0
  119. package/components/MaskedInput/MaskedInput.styles.d.ts +3 -0
  120. package/components/RadioGroup/RadioGroup.md +43 -43
  121. package/components/ScrollContainer/ScrollContainer/ScrollContainer.js +5 -0
  122. package/components/ScrollContainer/ScrollContainer/ScrollContainer.js.map +1 -1
  123. package/components/ScrollContainer/ScrollContainer.d.ts +1 -0
  124. package/hooks/useDrop/useDrop.js.map +1 -1
  125. package/hooks/useDrop.d.ts +1 -1
  126. package/index.d.ts +1 -0
  127. package/index.js +1 -0
  128. package/index.js.map +1 -1
  129. package/internal/FileUploaderControl/FileUploaderControlProvider/FileUploaderControlProvider.js +12 -3
  130. package/internal/FileUploaderControl/FileUploaderControlProvider/FileUploaderControlProvider.js.map +1 -1
  131. package/internal/FileUploaderControl/FileUploaderControlProvider.d.ts +5 -2
  132. package/internal/FileUploaderControl/FileUploaderFile/FileUploaderFile/FileUploaderFile.js +4 -2
  133. package/internal/FileUploaderControl/FileUploaderFile/FileUploaderFile/FileUploaderFile.js.map +1 -1
  134. package/internal/FileUploaderControl/FileUploaderFile/FileUploaderFile.d.ts +1 -0
  135. package/internal/FileUploaderControl/FileUploaderFileList/FileUploaderFileList/FileUploaderFileList.js +4 -2
  136. package/internal/FileUploaderControl/FileUploaderFileList/FileUploaderFileList/FileUploaderFileList.js.map +1 -1
  137. package/internal/FileUploaderControl/FileUploaderFileList/FileUploaderFileList.d.ts +1 -0
  138. package/internal/RenderContainer/RenderContainer/RenderContainer.js +3 -1
  139. package/internal/RenderContainer/RenderContainer/RenderContainer.js.map +1 -1
  140. package/internal/RenderContainer/RenderContainer.d.ts +2 -0
  141. package/internal/RenderContainer/RenderInnerContainer/RenderInnerContainer.js +5 -4
  142. package/internal/RenderContainer/RenderInnerContainer/RenderInnerContainer.js.map +1 -1
  143. package/internal/ThemeShowcase/ThemeShowcase.md +13 -13
  144. package/internal/ZIndex/ZIndex/ZIndex.js +55 -7
  145. package/internal/ZIndex/ZIndex/ZIndex.js.map +1 -1
  146. package/internal/ZIndex/ZIndex.d.ts +7 -3
  147. package/internal/themes/Theme2022Dark/Theme2022Dark.js +1 -1
  148. package/internal/themes/Theme2022Dark/Theme2022Dark.js.map +1 -1
  149. package/lib/events/MouseDrag/MouseDrag.js.map +1 -1
  150. package/lib/events/MouseDrag.d.ts +1 -1
  151. package/lib/events/keyboard/identifiers/identifiers.js +13 -0
  152. package/lib/events/keyboard/identifiers/identifiers.js.map +1 -1
  153. package/lib/events/keyboard/identifiers.d.ts +3 -0
  154. package/lib/listenFocusOutside/listenFocusOutside.js +3 -2
  155. package/lib/listenFocusOutside/listenFocusOutside.js.map +1 -1
  156. package/lib/styles/HoldSelectionColor/HoldSelectionColor.js +1 -1
  157. package/lib/styles/HoldSelectionColor/HoldSelectionColor.js.map +1 -1
  158. package/lib/styles/UiFont/UiFont.js +27 -0
  159. package/lib/styles/UiFont/UiFont.js.map +1 -0
  160. package/lib/styles/UiFont/package.json +6 -0
  161. package/lib/styles/UiFont.d.ts +4 -0
  162. package/package.json +2 -5
  163. package/cjs/internal/MaskedInputElement/MaskedInputElement.d.ts +0 -14
  164. package/cjs/internal/MaskedInputElement/MaskedInputElement.helpers.d.ts +0 -16
  165. package/cjs/internal/MaskedInputElement/MaskedInputElement.helpers.js +0 -52
  166. package/cjs/internal/MaskedInputElement/MaskedInputElement.helpers.js.map +0 -1
  167. package/cjs/internal/MaskedInputElement/MaskedInputElement.js +0 -196
  168. package/cjs/internal/MaskedInputElement/MaskedInputElement.js.map +0 -1
  169. package/cjs/internal/MaskedInputElement/MaskedInputElement.styles.d.ts +0 -6
  170. package/cjs/internal/MaskedInputElement/MaskedInputElement.styles.js +0 -29
  171. package/cjs/internal/MaskedInputElement/MaskedInputElement.styles.js.map +0 -1
  172. package/cjs/internal/MaskedInputElement/index.d.ts +0 -1
  173. package/cjs/internal/MaskedInputElement/index.js +0 -1
  174. package/cjs/internal/MaskedInputElement/index.js.map +0 -1
  175. package/internal/MaskedInputElement/MaskedInputElement/MaskedInputElement.js +0 -206
  176. package/internal/MaskedInputElement/MaskedInputElement/MaskedInputElement.js.map +0 -1
  177. package/internal/MaskedInputElement/MaskedInputElement/package.json +0 -6
  178. package/internal/MaskedInputElement/MaskedInputElement.d.ts +0 -14
  179. package/internal/MaskedInputElement/MaskedInputElement.helpers/MaskedInputElement.helpers.js +0 -43
  180. package/internal/MaskedInputElement/MaskedInputElement.helpers/MaskedInputElement.helpers.js.map +0 -1
  181. package/internal/MaskedInputElement/MaskedInputElement.helpers/package.json +0 -6
  182. package/internal/MaskedInputElement/MaskedInputElement.helpers.d.ts +0 -16
  183. package/internal/MaskedInputElement/MaskedInputElement.styles/MaskedInputElement.styles.js +0 -16
  184. package/internal/MaskedInputElement/MaskedInputElement.styles/MaskedInputElement.styles.js.map +0 -1
  185. package/internal/MaskedInputElement/MaskedInputElement.styles/package.json +0 -6
  186. package/internal/MaskedInputElement/MaskedInputElement.styles.d.ts +0 -6
  187. package/internal/MaskedInputElement/index/index.js +0 -1
  188. package/internal/MaskedInputElement/index/index.js.map +0 -1
  189. package/internal/MaskedInputElement/index/package.json +0 -6
  190. package/internal/MaskedInputElement/index.d.ts +0 -1
  191. package/internal/MaskedInputElement/package.json +0 -6
@@ -1,9 +1,57 @@
1
1
  "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;exports.__esModule = true;exports.MaskedInput = void 0;var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));var _react = _interopRequireWildcard(require("react"));
2
2
 
3
+
4
+
5
+ var _forwardRefAndName = require("../../lib/forwardRefAndName");
6
+ var _Emotion = require("../../lib/theming/Emotion");
7
+ var _UiFont = require("../../lib/styles/UiFont");
3
8
  var _Input = require("../Input");
9
+ var _identifiers = require("../../lib/events/keyboard/identifiers");
10
+
11
+ var _MaskedInput = require("./MaskedInput.styles");
12
+ var _MaskedInput2 = require("./MaskedInput.helpers");
13
+ var _ColorableInputElement = require("./ColorableInputElement");
14
+ var _FixedIMaskInput = require("./FixedIMaskInput");var _excluded = ["mask", "maskChar", "formatChars", "alwaysShowMask", "colored", "imaskProps", "unmask", "onValueChange", "onUnexpectedInput", "onChange", "element", "className"];
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
4
54
 
5
- var _MaskedInputElement = require("../../internal/MaskedInputElement");
6
- var _forwardRefAndName = require("../../lib/forwardRefAndName");var _excluded = ["mask", "maskChar", "formatChars", "alwaysShowMask", "placeholder"];
7
55
 
8
56
 
9
57
 
@@ -32,47 +80,148 @@ var _forwardRefAndName = require("../../lib/forwardRefAndName");var _excluded =
32
80
  var MaskedInput = (0, _forwardRefAndName.forwardRefAndName)(
33
81
  'MaskedInput',
34
82
  function MaskedInput(props, ref) {
35
- var mask = props.mask,maskChar = props.maskChar,formatChars = props.formatChars,alwaysShowMask = props.alwaysShowMask,placeholder = props.placeholder,inputProps = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
83
+ var
84
+ mask =
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+ props.mask,maskChar = props.maskChar,formatChars = props.formatChars,_props$alwaysShowMask = props.alwaysShowMask,alwaysShowMask = _props$alwaysShowMask === void 0 ? false : _props$alwaysShowMask,_props$colored = props.colored,colored = _props$colored === void 0 ? true : _props$colored,_props$imaskProps = props.imaskProps,customIMaskProps = _props$imaskProps === void 0 ? {} : _props$imaskProps,_props$unmask = props.unmask,unmask = _props$unmask === void 0 ? false : _props$unmask,onValueChange = props.onValueChange,onUnexpectedInput = props.onUnexpectedInput,onChange = props.onChange,element = props.element,className = props.className,inputProps = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
98
+
99
+ var inputRef = (0, _react.useRef)(null);
100
+
36
101
  var _useState = (0, _react.useState)(false),focused = _useState[0],setFocused = _useState[1];
37
- var showPlaceholder = !(alwaysShowMask || focused);
38
- var innerRef = (0, _react.useRef)(null);
102
+ var prevValue = (0, _react.useRef)(props.value || String(props.defaultValue) || '');
103
+ var prevSelectionStart = (0, _react.useRef)(null);
104
+
105
+ (0, _react.useImperativeHandle)(
106
+ ref,
107
+ function () {return (
108
+ inputRef.current &&
109
+ Object.assign(inputRef.current, {
110
+ selectAll: inputRef.current.delaySelectAll }));},
111
+
112
+ []);
113
+
114
+
115
+ (0, _react.useEffect)(function () {var _inputRef$current;
116
+ // Для корректной работы onUnexpectedInput надо знать предыдущий value,
117
+ // но imask при монтировании не вызывает onAccept, если value невалиден или laze=false.
118
+ // Поэтому актуальный value при монтировании надо получать вручную
119
+ if ((_inputRef$current = inputRef.current) != null && _inputRef$current.input) {
120
+ prevValue.current = inputRef.current.input.value;
121
+ prevSelectionStart.current = inputRef.current.input.selectionStart;
122
+ }
123
+ }, []);
39
124
 
40
- (0, _react.useImperativeHandle)(ref, function () {return innerRef.current;});
125
+ var imaskProps = getCompatibleIMaskProps();
41
126
 
42
127
  return /*#__PURE__*/(
43
128
  _react.default.createElement(_Input.Input, (0, _extends2.default)({
44
- ref: innerRef },
129
+ ref: inputRef },
45
130
  inputProps, {
46
- placeholder: showPlaceholder ? placeholder : undefined,
47
131
  onFocus: handleFocus,
48
132
  onBlur: handleBlur,
49
- element: /*#__PURE__*/
50
- _react.default.createElement(_MaskedInputElement.MaskedInputElement, {
51
- mask: mask,
52
- maskChar: maskChar,
53
- formatChars: formatChars,
54
- alwaysShowMask: alwaysShowMask,
55
- onUnexpectedInput: handleUnexpectedInput }) })));
133
+ onInput: handleInput,
134
+ onKeyDown: handleKeyDown,
135
+ className: (0, _Emotion.cx)(_MaskedInput.globalClasses.root, _UiFont.uiFontGlobalClasses.root, className),
136
+ element:
137
+ colored ? /*#__PURE__*/
138
+ _react.default.createElement(_ColorableInputElement.ColorableInputElement, { showOnFocus: false }, /*#__PURE__*/
139
+ _react.default.createElement(_FixedIMaskInput.FixedIMaskInput, (0, _extends2.default)({}, imaskProps, { onAccept: handleAccept }))) : /*#__PURE__*/
140
+
141
+
142
+ _react.default.createElement(_FixedIMaskInput.FixedIMaskInput, (0, _extends2.default)({}, imaskProps, { onAccept: handleAccept })) })));
143
+
144
+
56
145
 
57
146
 
58
147
 
148
+ function getCompatibleIMaskProps() {
149
+ return (0, _extends2.default)({
150
+ mask: mask.replace(/0/g, '{\\0}'),
151
+ placeholderChar: (0, _MaskedInput2.getMaskChar)(maskChar),
152
+ definitions: (0, _MaskedInput2.getDefinitions)(formatChars),
153
+ // FIXME: Должно быть eager=true, но в imask ломается удаление по delete
154
+ eager: 'append',
155
+ overwrite: 'shift',
156
+ lazy: !alwaysShowMask && (props.disabled || !focused),
157
+ unmask: unmask },
158
+ customIMaskProps);
59
159
 
160
+ }
161
+
162
+ function handleAccept() {for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}
163
+ var value = args[0],e = args[2];
164
+
165
+ // Метод onAccept может вызываться при монтировании, если не задан проп defaultValue.
166
+ // Но нативный input никогда не вызывает onChange при монтировании.
167
+ // Наше событие onValueChange в Input вывается в тех же случаях, что и нативный onChange,
168
+ // поэтому чтобы сохранить консинстентность будем ориентироваться на наличие аргумента e.
169
+ // Он содержит нативное событие, вызвавшее изменение.
170
+ e && (onValueChange == null ? void 0 : onValueChange(value));
171
+ !e && (prevValue.current = value);
172
+ }
60
173
 
61
- function handleUnexpectedInput(value) {
62
- if (props.onUnexpectedInput) {
63
- props.onUnexpectedInput(value);
64
- } else if (innerRef.current) {
65
- innerRef.current.blink();
174
+ /**
175
+ * Отслеживаем неожиданные нажатия
176
+ * handleAccept не вызывается когда значение с маской не меняется
177
+ * Сначала вызывается handleAccept, затем handleInput
178
+ */
179
+ function handleInput(e) {
180
+ var _e$currentTarget = e.currentTarget,value = _e$currentTarget.value,selectionStart = _e$currentTarget.selectionStart;
181
+
182
+ // При вводе неожиданных символов или удалении каретка может перепрыгивать фиксированные символы.
183
+ // Такие случаи не расцениваем как неожиданный ввод, т.к. пользователь может намеренно их вводить.
184
+ if (prevValue.current === value && selectionStart === prevSelectionStart.current) {
185
+ handleUnexpectedInput(value);
66
186
  }
187
+ prevValue.current = value;
188
+ prevSelectionStart.current = selectionStart;
189
+
190
+ props.onInput == null ? void 0 : props.onInput(e);
67
191
  }
68
192
 
69
- function handleFocus(e) {
193
+ function handleFocus(e) {var _inputRef$current2;
70
194
  setFocused(true);
71
- props.onFocus && props.onFocus(e);
195
+ props.onFocus == null ? void 0 : props.onFocus(e);
196
+
197
+ // Если value из пропов отличается от value, которое получит input после обработки,
198
+ // то imask будет ставить каретку за последним валидным символом.
199
+ props.selectAllOnFocus && ((_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.delaySelectAll());
200
+ }
201
+
202
+ function handleUnexpectedInput(value) {var _inputRef$current3;
203
+ var blink = ((_inputRef$current3 = inputRef.current) == null ? void 0 : _inputRef$current3.blink.bind(inputRef.current)) || function () {return undefined;};
204
+ onUnexpectedInput ? onUnexpectedInput(value, blink) : blink();
72
205
  }
73
206
 
74
207
  function handleBlur(e) {
75
208
  setFocused(false);
76
- props.onBlur && props.onBlur(e);
209
+ props.onBlur == null ? void 0 : props.onBlur(e);
210
+ }
211
+
212
+ function handleKeyDown(e) {
213
+ var _e$currentTarget2 = e.currentTarget,value = _e$currentTarget2.value,selectionStart = _e$currentTarget2.selectionStart,selectionEnd = _e$currentTarget2.selectionEnd;
214
+
215
+ if (
216
+ (0, _identifiers.isKeyBackspace)(e) && selectionStart === 0 && selectionEnd === 0 ||
217
+ (0, _identifiers.isKeyDelete)(e) && prevSelectionStart.current === value.length)
218
+ {
219
+ // Случаи, когда нажатие клавиш не тригерит `onInput`
220
+ handleUnexpectedInput(value);
221
+ prevValue.current = e.currentTarget.value;
222
+ }
223
+ prevSelectionStart.current = selectionStart;
224
+
225
+ props.onKeyDown == null ? void 0 : props.onKeyDown(e);
77
226
  }
78
227
  });exports.MaskedInput = MaskedInput;
@@ -1 +1 @@
1
- {"version":3,"sources":["MaskedInput.tsx"],"names":["MaskedInput","props","ref","mask","maskChar","formatChars","alwaysShowMask","placeholder","inputProps","focused","setFocused","showPlaceholder","innerRef","current","undefined","handleFocus","handleBlur","handleUnexpectedInput","value","onUnexpectedInput","blink","e","onFocus","onBlur"],"mappings":"8cAAA;;AAEA;;AAEA;AACA,gE;;;;;;;;;;;;;;;;;;;;;;AAsBA;AACA;AACA;AACA;AACO,IAAMA,WAAW,GAAG;AACzB,aADyB;AAEzB,SAASA,WAAT,CAAqBC,KAArB,EAA8CC,GAA9C,EAAsE;AACpE,MAAQC,IAAR,GAAoFF,KAApF,CAAQE,IAAR,CAAcC,QAAd,GAAoFH,KAApF,CAAcG,QAAd,CAAwBC,WAAxB,GAAoFJ,KAApF,CAAwBI,WAAxB,CAAqCC,cAArC,GAAoFL,KAApF,CAAqCK,cAArC,CAAqDC,WAArD,GAAoFN,KAApF,CAAqDM,WAArD,CAAqEC,UAArE,+CAAoFP,KAApF;AACA,kBAA8B,qBAAS,KAAT,CAA9B,CAAOQ,OAAP,gBAAgBC,UAAhB;AACA,MAAMC,eAAe,GAAG,EAAEL,cAAc,IAAIG,OAApB,CAAxB;AACA,MAAMG,QAAQ,GAAG,mBAAc,IAAd,CAAjB;;AAEA,kCAAoBV,GAApB,EAAyB,oBAAMU,QAAQ,CAACC,OAAf,EAAzB;;AAEA;AACE,iCAAC,YAAD;AACE,MAAA,GAAG,EAAED,QADP;AAEMJ,IAAAA,UAFN;AAGE,MAAA,WAAW,EAAEG,eAAe,GAAGJ,WAAH,GAAiBO,SAH/C;AAIE,MAAA,OAAO,EAAEC,WAJX;AAKE,MAAA,MAAM,EAAEC,UALV;AAME,MAAA,OAAO;AACL,mCAAC,sCAAD;AACE,QAAA,IAAI,EAAEb,IADR;AAEE,QAAA,QAAQ,EAAEC,QAFZ;AAGE,QAAA,WAAW,EAAEC,WAHf;AAIE,QAAA,cAAc,EAAEC,cAJlB;AAKE,QAAA,iBAAiB,EAAEW,qBALrB,GAPJ,IADF;;;;;;AAmBA,WAASA,qBAAT,CAA+BC,KAA/B,EAA8C;AAC5C,QAAIjB,KAAK,CAACkB,iBAAV,EAA6B;AAC3BlB,MAAAA,KAAK,CAACkB,iBAAN,CAAwBD,KAAxB;AACD,KAFD,MAEO,IAAIN,QAAQ,CAACC,OAAb,EAAsB;AAC3BD,MAAAA,QAAQ,CAACC,OAAT,CAAiBO,KAAjB;AACD;AACF;;AAED,WAASL,WAAT,CAAqBM,CAArB,EAA4D;AAC1DX,IAAAA,UAAU,CAAC,IAAD,CAAV;AACAT,IAAAA,KAAK,CAACqB,OAAN,IAAiBrB,KAAK,CAACqB,OAAN,CAAcD,CAAd,CAAjB;AACD;;AAED,WAASL,UAAT,CAAoBK,CAApB,EAA2D;AACzDX,IAAAA,UAAU,CAAC,KAAD,CAAV;AACAT,IAAAA,KAAK,CAACsB,MAAN,IAAgBtB,KAAK,CAACsB,MAAN,CAAaF,CAAb,CAAhB;AACD;AACF,CA9CwB,CAApB,C","sourcesContent":["import React, { Ref, useImperativeHandle, useRef, useState } from 'react';\n\nimport { Input, InputProps, InputType } from '../Input';\nimport { Nullable } from '../../typings/utility-types';\nimport { MaskedInputElement } from '../../internal/MaskedInputElement';\nimport { forwardRefAndName } from '../../lib/forwardRefAndName';\n\nexport interface MaskedProps {\n /** Паттерн маски */\n mask: string;\n /** Символ маски */\n maskChar?: Nullable<string>;\n /**\n * Словарь символов-регулярок для маски\n * @default { '9': '[0-9]', 'a': '[A-Za-z]', '*': '[A-Za-z0-9]' }\n */\n formatChars?: Record<string, string>;\n /** Показывать символы маски */\n alwaysShowMask?: boolean;\n}\n\nexport type MaskInputType = Exclude<InputType, 'number' | 'date' | 'time' | 'password'>;\n\nexport interface MaskedInputProps extends MaskedProps, Omit<InputProps, 'mask' | 'maxLength' | 'type' | 'element'> {\n type?: MaskInputType;\n}\n\n/**\n * Интерфейс пропсов наследуется от `Input`.\n * Из пропсов `Input` исключены некоторые не применимые к полю с маской пропсы и сокращен список возможных значений в type.\n */\nexport const MaskedInput = forwardRefAndName(\n 'MaskedInput',\n function MaskedInput(props: MaskedInputProps, ref: Ref<Input | null>) {\n const { mask, maskChar, formatChars, alwaysShowMask, placeholder, ...inputProps } = props;\n const [focused, setFocused] = useState(false);\n const showPlaceholder = !(alwaysShowMask || focused);\n const innerRef = useRef<Input>(null);\n\n useImperativeHandle(ref, () => innerRef.current);\n\n return (\n <Input\n ref={innerRef}\n {...inputProps}\n placeholder={showPlaceholder ? placeholder : undefined}\n onFocus={handleFocus}\n onBlur={handleBlur}\n element={\n <MaskedInputElement\n mask={mask}\n maskChar={maskChar}\n formatChars={formatChars}\n alwaysShowMask={alwaysShowMask}\n onUnexpectedInput={handleUnexpectedInput}\n />\n }\n />\n );\n\n function handleUnexpectedInput(value: string) {\n if (props.onUnexpectedInput) {\n props.onUnexpectedInput(value);\n } else if (innerRef.current) {\n innerRef.current.blink();\n }\n }\n\n function handleFocus(e: React.FocusEvent<HTMLInputElement>) {\n setFocused(true);\n props.onFocus && props.onFocus(e);\n }\n\n function handleBlur(e: React.FocusEvent<HTMLInputElement>) {\n setFocused(false);\n props.onBlur && props.onBlur(e);\n }\n },\n);\n"]}
1
+ {"version":3,"sources":["MaskedInput.tsx"],"names":["MaskedInput","props","ref","mask","maskChar","formatChars","alwaysShowMask","colored","imaskProps","customIMaskProps","unmask","onValueChange","onUnexpectedInput","onChange","element","className","inputProps","inputRef","focused","setFocused","prevValue","value","String","defaultValue","prevSelectionStart","current","Object","assign","selectAll","delaySelectAll","input","selectionStart","getCompatibleIMaskProps","handleFocus","handleBlur","handleInput","handleKeyDown","globalClasses","root","uiFontGlobalClasses","handleAccept","replace","placeholderChar","definitions","eager","overwrite","lazy","disabled","args","e","currentTarget","handleUnexpectedInput","onInput","onFocus","selectAllOnFocus","blink","bind","undefined","onBlur","selectionEnd","length","onKeyDown"],"mappings":"8cAAA;;;;AAIA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,oD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA;AACA;AACA;AACA;AACO,IAAMA,WAAW,GAAG;AACzB,aADyB;AAEzB,SAASA,WAAT,CAAqBC,KAArB,EAA8CC,GAA9C,EAAsE;AACpE;AACEC,EAAAA,IADF;;;;;;;;;;;;;AAcIF,EAAAA,KAdJ,CACEE,IADF,CAEEC,QAFF,GAcIH,KAdJ,CAEEG,QAFF,CAGEC,WAHF,GAcIJ,KAdJ,CAGEI,WAHF,yBAcIJ,KAdJ,CAIEK,cAJF,CAIEA,cAJF,sCAImB,KAJnB,0CAcIL,KAdJ,CAKEM,OALF,CAKEA,OALF,+BAKY,IALZ,sCAcIN,KAdJ,CAMEO,UANF,CAMcC,gBANd,kCAMiC,EANjC,qCAcIR,KAdJ,CAOES,MAPF,CAOEA,MAPF,8BAOW,KAPX,iBAQEC,aARF,GAcIV,KAdJ,CAQEU,aARF,CASEC,iBATF,GAcIX,KAdJ,CASEW,iBATF,CAUEC,QAVF,GAcIZ,KAdJ,CAUEY,QAVF,CAWEC,OAXF,GAcIb,KAdJ,CAWEa,OAXF,CAYEC,SAZF,GAcId,KAdJ,CAYEc,SAZF,CAaKC,UAbL,+CAcIf,KAdJ;;AAgBA,MAAMgB,QAAQ,GAAG,mBAAc,IAAd,CAAjB;;AAEA,kBAA8B,qBAAS,KAAT,CAA9B,CAAOC,OAAP,gBAAgBC,UAAhB;AACA,MAAMC,SAAS,GAAG,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ACD;AACDG,IAAAA,kBAAkB,CAACC,OAAnB,GAA6BM,cAA7B;;AAEA9B,IAAAA,KAAK,CAAC4D,SAAN,oBAAA5D,KAAK,CAAC4D,SAAN,CAAkBZ,CAAlB;AACD;AACF,CAnJwB,CAApB,C","sourcesContent":["import React, { Ref, useImperativeHandle, useRef, useState, useEffect } from 'react';\nimport { IMaskInputProps } from 'react-imask';\n\nimport { Nullable } from '../../typings/utility-types';\nimport { forwardRefAndName } from '../../lib/forwardRefAndName';\nimport { cx } from '../../lib/theming/Emotion';\nimport { uiFontGlobalClasses } from '../../lib/styles/UiFont';\nimport { Input, InputProps, InputType } from '../Input';\nimport { isKeyBackspace, isKeyDelete } from '../../lib/events/keyboard/identifiers';\n\nimport { globalClasses } from './MaskedInput.styles';\nimport { getDefinitions, getMaskChar } from './MaskedInput.helpers';\nimport { ColorableInputElement } from './ColorableInputElement';\nimport { FixedIMaskInput } from './FixedIMaskInput';\n\nexport interface MaskedProps {\n /** Паттерн маски */\n mask: string;\n /**\n * Символ маски\n *\n * @default _\n */\n maskChar?: Nullable<string>;\n /**\n * Словарь символов-регулярок для маски\n *\n * @default { '9': '[0-9]', 'a': '[A-Za-z]', '*': '[A-Za-z0-9]' }\n */\n formatChars?: Record<string, string>;\n /**\n * Всегда показывать символы маски\n *\n * @default false\n */\n alwaysShowMask?: boolean;\n /**\n * Обработчик неправильного ввода.\n * Вторым агрументом будет передан метод вспыхивания акцентным цветом.\n *\n * Если обработчик не задан, то инпут вспыхивает по-умолчанию.\n *\n * @param value значение инпута.\n * @param blink вспыхнуть акцентным цвтетом.\n */\n onUnexpectedInput?: (value: string, blink: () => void) => void;\n /**\n * Убирать из value символы, не введённые пользователем\n *\n * @default false\n */\n unmask?: boolean;\n /**\n * Раскрашивать символы маски\n *\n * @default true\n * @ignore\n */\n colored?: boolean;\n /**\n * Пропы для компонента `IMaskInput`. Необходимы для юнит-тестов\n *\n * @ignore\n */\n imaskProps?: IMaskInputProps<HTMLInputElement>;\n}\n\nexport type MaskInputType = Exclude<InputType, 'number' | 'date' | 'time' | 'password'>;\n\nexport interface MaskedInputProps\n extends MaskedProps,\n Omit<InputProps, 'mask' | 'maxLength' | 'type' | 'alwaysShowMask' | 'onUnexpectedInput'> {\n type?: MaskInputType;\n}\n\n/**\n * Интерфейс пропсов наследуется от `Input`.\n * Из пропсов `Input` исключены некоторые не применимые к полю с маской пропсы и сокращен список возможных значений в type.\n */\nexport const MaskedInput = forwardRefAndName(\n 'MaskedInput',\n function MaskedInput(props: MaskedInputProps, ref: Ref<Input | null>) {\n const {\n mask,\n maskChar,\n formatChars,\n alwaysShowMask = false,\n colored = true,\n imaskProps: customIMaskProps = {},\n unmask = false,\n onValueChange,\n onUnexpectedInput,\n onChange,\n element,\n className,\n ...inputProps\n } = props;\n\n const inputRef = useRef<Input>(null);\n\n const [focused, setFocused] = useState(false);\n const prevValue = useRef<string>(props.value || String(props.defaultValue) || '');\n const prevSelectionStart = useRef<number | null>(null);\n\n useImperativeHandle(\n ref,\n () =>\n inputRef.current &&\n Object.assign(inputRef.current, {\n selectAll: inputRef.current.delaySelectAll,\n }),\n [],\n );\n\n useEffect(() => {\n // Для корректной работы onUnexpectedInput надо знать предыдущий value,\n // но imask при монтировании не вызывает onAccept, если value невалиден или laze=false.\n // Поэтому актуальный value при монтировании надо получать вручную\n if (inputRef.current?.input) {\n prevValue.current = inputRef.current.input.value;\n prevSelectionStart.current = inputRef.current.input.selectionStart;\n }\n }, []);\n\n const imaskProps = getCompatibleIMaskProps();\n\n return (\n <Input\n ref={inputRef}\n {...inputProps}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onInput={handleInput}\n onKeyDown={handleKeyDown}\n className={cx(globalClasses.root, uiFontGlobalClasses.root, className)}\n element={\n colored ? (\n <ColorableInputElement showOnFocus={false}>\n <FixedIMaskInput {...imaskProps} onAccept={handleAccept} />\n </ColorableInputElement>\n ) : (\n <FixedIMaskInput {...imaskProps} onAccept={handleAccept} />\n )\n }\n />\n );\n\n function getCompatibleIMaskProps(): IMaskInputProps<HTMLInputElement> {\n return {\n mask: mask.replace(/0/g, '{\\\\0}') as any,\n placeholderChar: getMaskChar(maskChar),\n definitions: getDefinitions(formatChars),\n // FIXME: Должно быть eager=true, но в imask ломается удаление по delete\n eager: 'append',\n overwrite: 'shift',\n lazy: !alwaysShowMask && (props.disabled || !focused),\n unmask,\n ...customIMaskProps,\n } as IMaskInputProps<HTMLInputElement>;\n }\n\n function handleAccept(...args: Parameters<Required<IMaskInputProps<HTMLInputElement>>['onAccept']>) {\n const [value, , e] = args;\n\n // Метод onAccept может вызываться при монтировании, если не задан проп defaultValue.\n // Но нативный input никогда не вызывает onChange при монтировании.\n // Наше событие onValueChange в Input вывается в тех же случаях, что и нативный onChange,\n // поэтому чтобы сохранить консинстентность будем ориентироваться на наличие аргумента e.\n // Он содержит нативное событие, вызвавшее изменение.\n e && onValueChange?.(value);\n !e && (prevValue.current = value);\n }\n\n /**\n * Отслеживаем неожиданные нажатия\n * handleAccept не вызывается когда значение с маской не меняется\n * Сначала вызывается handleAccept, затем handleInput\n */\n function handleInput(e: React.ChangeEvent<HTMLInputElement>) {\n const { value, selectionStart } = e.currentTarget;\n\n // При вводе неожиданных символов или удалении каретка может перепрыгивать фиксированные символы.\n // Такие случаи не расцениваем как неожиданный ввод, т.к. пользователь может намеренно их вводить.\n if (prevValue.current === value && selectionStart === prevSelectionStart.current) {\n handleUnexpectedInput(value);\n }\n prevValue.current = value;\n prevSelectionStart.current = selectionStart;\n\n props.onInput?.(e);\n }\n\n function handleFocus(e: React.FocusEvent<HTMLInputElement>) {\n setFocused(true);\n props.onFocus?.(e);\n\n // Если value из пропов отличается от value, которое получит input после обработки,\n // то imask будет ставить каретку за последним валидным символом.\n props.selectAllOnFocus && inputRef.current?.delaySelectAll();\n }\n\n function handleUnexpectedInput(value: string) {\n const blink = inputRef.current?.blink.bind(inputRef.current) || (() => undefined);\n onUnexpectedInput ? onUnexpectedInput(value, blink) : blink();\n }\n\n function handleBlur(e: React.FocusEvent<HTMLInputElement>) {\n setFocused(false);\n props.onBlur?.(e);\n }\n\n function handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {\n const { value, selectionStart, selectionEnd } = e.currentTarget;\n\n if (\n (isKeyBackspace(e) && selectionStart === 0 && selectionEnd === 0) ||\n (isKeyDelete(e) && prevSelectionStart.current === value.length)\n ) {\n // Случаи, когда нажатие клавиш не тригерит `onInput`\n handleUnexpectedInput(value);\n prevValue.current = e.currentTarget.value;\n }\n prevSelectionStart.current = selectionStart;\n\n props.onKeyDown?.(e);\n }\n },\n);\n"]}
@@ -1,21 +1,112 @@
1
+ #### `mask`
2
+
3
+ Паттерн ввода. Пример с номером телефона.
4
+
1
5
  ```jsx harmony
2
- <MaskedInput mask={'+7 999 999-99-99'} placeholder={"Номер телефона"} />
6
+ const [value, setValue] = React.useState('');
7
+
8
+ <>
9
+ <span>value: "{value}"</span>
10
+ <br />
11
+ <br />
12
+ <MaskedInput
13
+ mask="+7 (999) 999-99-99"
14
+ placeholder="Номер телефона"
15
+ value={value}
16
+ onValueChange={setValue}
17
+ />
18
+ </>
3
19
  ```
4
20
 
5
- Можно изменить символ значения с маской
21
+ #### `alwaysShowMask`
22
+
23
+ Показывает маску всегда.
24
+
6
25
  ```jsx harmony
7
- <MaskedInput mask={'9999 9999 9999 9999'} maskChar={'X'} placeholder={"Номер карты"} />
26
+ <MaskedInput mask="+7 (999) 999-99-99" alwaysShowMask />
8
27
  ```
9
28
 
10
- **alwaysShowMask** позволяет показывать маску всегда. Placeholder в этом случае игнорируется.
29
+ #### `maskChar`
30
+
31
+ Символом маски может быть любой символ.
32
+
11
33
  ```jsx harmony
12
- <MaskedInput mask={'9999 9999 9999 9999'} alwaysShowMask maskChar={'X'} placeholder={"Номер карты"} />
34
+ const [value, setValue] = React.useState('');
35
+
36
+ <>
37
+ <span>value: "{value}"</span>
38
+ <br />
39
+ <br />
40
+ <MaskedInput
41
+ mask="9999 9999 9999 9999"
42
+ maskChar="X"
43
+ placeholder="Номер карты"
44
+ alwaysShowMask
45
+ value={value}
46
+ onValueChange={setValue}
47
+ />
48
+ </>
13
49
  ```
14
50
 
15
- Для форматирования по маске используется пакет [iMask](https://imask.js.org/). Используйте особенности пакета принимая всю ответственность на себя.
51
+ #### `formatChars`
16
52
 
17
- `MaskedInput` гарантирует поддержку работы 3 пропов: **mask**, **maskChar**, **alwaysShowMask** с заданными по-умолчанию **formatChars**.
53
+ При необходимости можно настроить собственный словарь.
18
54
 
19
- Остальное поведение может меняться в мажорных релизах.
55
+ ```jsx harmony
56
+ const [value, setValue] = React.useState('');
57
+
58
+ <MaskedInput
59
+ mask="Hh:Mm:Ss"
60
+ alwaysShowMask
61
+ formatChars={{
62
+ H: '[0-2]',
63
+ h: value.startsWith('2') ? '[0-3]' : '[0-9]',
64
+ M: '[0-5]',
65
+ m: '[0-9]',
66
+ S: '[0-5]',
67
+ s: '[0-9]',
68
+ }}
69
+ value={value}
70
+ onValueChange={setValue}
71
+ />
72
+ ```
20
73
 
21
- Например, iMask [позволяет добавлять](https://imask.js.org/guide.html#masked-pattern) в значения без форматирования константы с помощью фигурных скобок. Использовать этот вариант **НЕ РЕКОМЕНДУЕТСЯ**.
74
+ #### `unmask`
75
+
76
+ Можно сразу получать очищенный value, содержащий только введённый пользователем символы.
77
+
78
+ ```jsx harmony
79
+ const [value, setValue] = React.useState('');
80
+
81
+ <>
82
+ <span>value: "{value}"</span>
83
+ <br />
84
+ <br />
85
+ <MaskedInput
86
+ mask="+7 (999) 999-99-99"
87
+ unmask
88
+ alwaysShowMask
89
+ value={value}
90
+ onValueChange={setValue}
91
+ />
92
+ </>
93
+ ```
94
+
95
+ Если обернуть фиксированные символы в фигурные скобки, то они попадут в `value` при `unmask = true`.
96
+
97
+ ```jsx harmony
98
+ const [value, setValue] = React.useState('');
99
+
100
+ <>
101
+ <span>value: "{value}"</span>
102
+ <br />
103
+ <br />
104
+ <MaskedInput
105
+ mask="+{7} (999) 999-99-99"
106
+ unmask
107
+ alwaysShowMask
108
+ value={value}
109
+ onValueChange={setValue}
110
+ />
111
+ </>
112
+ ```
@@ -0,0 +1,3 @@
1
+ export declare const globalClasses: {
2
+ root: string;
3
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";exports.__esModule = true;exports.globalClasses = void 0;var _Emotion = require("../../lib/theming/Emotion");
2
+
3
+ var globalClasses = (0, _Emotion.prefix)('masked-input')({
4
+ root: 'root' });exports.globalClasses = globalClasses;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["MaskedInput.styles.ts"],"names":["globalClasses","root"],"mappings":"sEAAA;;AAEO,IAAMA,aAAa,GAAG,qBAAO,cAAP,EAAuB;AAClDC,EAAAA,IAAI,EAAE,MAD4C,EAAvB,CAAtB,C","sourcesContent":["import { prefix } from '../../lib/theming/Emotion';\n\nexport const globalClasses = prefix('masked-input')({\n root: 'root',\n});\n"]}
@@ -1,43 +1,43 @@
1
- ```jsx harmony
2
- import { Gapped, Radio } from '@skbkontur/react-ui';
3
-
4
- let items = ['One', 'Two', 'Three', 'Four'];
5
-
6
- let simpleRadioGroup = (
7
- <div>
8
- <h2>Numbers</h2>
9
- <RadioGroup name="number-simple" items={items} defaultValue="One" />
10
- </div>
11
- );
12
-
13
- let complexRadioGroup = (
14
- <div>
15
- <h2>Numbers</h2>
16
- <RadioGroup name="number-complex" defaultValue="3">
17
- <Gapped gap={40}>
18
- <Gapped vertical gap={0}>
19
- <b>Odd</b>
20
- <Radio value="1">One</Radio>
21
- <Radio value="3">Three</Radio>
22
- <Radio value="5" disabled>
23
- Five
24
- </Radio>
25
- <Radio value="7">Seven</Radio>
26
- </Gapped>
27
- <Gapped vertical gap={0}>
28
- <b>Even</b>
29
- <Radio value="2">Two</Radio>
30
- <Radio value="4">Four</Radio>
31
- <Radio value="6">Six</Radio>
32
- <Radio value="8">Eight</Radio>
33
- </Gapped>
34
- </Gapped>
35
- </RadioGroup>
36
- </div>
37
- );
38
-
39
- <div>
40
- {simpleRadioGroup}
41
- {complexRadioGroup}
42
- </div>;
43
- ```
1
+ ```jsx harmony
2
+ import { Gapped, Radio } from '@skbkontur/react-ui';
3
+
4
+ let items = ['One', 'Two', 'Three', 'Four'];
5
+
6
+ let simpleRadioGroup = (
7
+ <div>
8
+ <h2>Numbers</h2>
9
+ <RadioGroup name="number-simple" items={items} defaultValue="One" />
10
+ </div>
11
+ );
12
+
13
+ let complexRadioGroup = (
14
+ <div>
15
+ <h2>Numbers</h2>
16
+ <RadioGroup name="number-complex" defaultValue="3">
17
+ <Gapped gap={40}>
18
+ <Gapped vertical gap={0}>
19
+ <b>Odd</b>
20
+ <Radio value="1">One</Radio>
21
+ <Radio value="3">Three</Radio>
22
+ <Radio value="5" disabled>
23
+ Five
24
+ </Radio>
25
+ <Radio value="7">Seven</Radio>
26
+ </Gapped>
27
+ <Gapped vertical gap={0}>
28
+ <b>Even</b>
29
+ <Radio value="2">Two</Radio>
30
+ <Radio value="4">Four</Radio>
31
+ <Radio value="6">Six</Radio>
32
+ <Radio value="8">Eight</Radio>
33
+ </Gapped>
34
+ </Gapped>
35
+ </RadioGroup>
36
+ </div>
37
+ );
38
+
39
+ <div>
40
+ {simpleRadioGroup}
41
+ {complexRadioGroup}
42
+ </div>;
43
+ ```
@@ -59,6 +59,7 @@ export interface ScrollContainerProps extends CommonProps {
59
59
  * Отключить анимации
60
60
  */
61
61
  disableAnimations?: boolean;
62
+ scrollRef?: React.Ref<HTMLDivElement | null>;
62
63
  }
63
64
  export declare const ScrollContainerDataTids: {
64
65
  readonly root: "ScrollContainer__root";
@@ -13,6 +13,7 @@ var _rootNode = require("../../lib/rootNode");
13
13
  var _getDOMRect = require("../../lib/dom/getDOMRect");
14
14
  var _createPropsGetter = require("../../lib/createPropsGetter");
15
15
  var _currentEnvironment = require("../../lib/currentEnvironment");
16
+ var _callChildRef = require("../../lib/callChildRef/callChildRef");
16
17
 
17
18
  var _ScrollContainer = require("./ScrollContainer.styles");
18
19
  var _ScrollContainer2 = require("./ScrollContainer.constants");
@@ -81,6 +82,7 @@ var _ScrollBar = require("./ScrollBar");var _class, _class2, _temp;
81
82
 
82
83
 
83
84
 
85
+
84
86
 
85
87
 
86
88
  var ScrollContainerDataTids = {
@@ -344,6 +346,10 @@ ScrollContainer = (0, _rootNode.rootNode)(_class = (_temp = _class2 = /*#__PURE_
344
346
  _this.inner.removeEventListener('wheel', _this.handleInnerScrollWheel);
345
347
  }
346
348
  _this.inner = element;
349
+
350
+ if (_this.props.scrollRef) {
351
+ (0, _callChildRef.callChildRef)(_this.props.scrollRef, element);
352
+ }
347
353
  };_this.
348
354
 
349
355
  handleNativeScroll = function (event) {var _this$scrollY, _this$scrollX;