@snack-uikit/fields 0.51.17 → 0.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
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
+ # 0.52.0 (2026-03-04)
7
+
8
+
9
+ ### Features
10
+
11
+ * **FF-8094:** add withCharacterCount hoc ([a5e5d8b](https://github.com/cloud-ru-tech/snack-uikit/commit/a5e5d8be1a1a552ca6abbaa9cefc2c7f00badb95))
12
+
13
+
14
+
15
+
16
+
6
17
  ## 0.51.17 (2026-03-04)
7
18
 
8
19
  ### Only dependencies have been changed
package/README.md CHANGED
@@ -927,6 +927,29 @@ FieldStepper в основном предназначен для работы с
927
927
  | error | `string` | - | |
928
928
  | ref | `LegacyRef<HTMLInputElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs} |
929
929
  | key | `Key` | - | |
930
+ ## withCharacterCount
931
+ ### Props
932
+ | name | type | default value | description |
933
+ |------|------|---------------|-------------|
934
+ | __@metadata@877* | `DecoratorMetadataObject` | - | |
935
+ | __@hasInstance@875* | `(value: any) => boolean` | - | Determines whether the given value inherits from this function if this function was used as a constructor function. A constructor function can control which objects are recognized as its instances by 'instanceof' by overriding this method. |
936
+ | name* | `string` | - | Returns the name of the function. Function names are read-only and can not be changed. |
937
+ | caller* | `Function` | - | |
938
+ | arguments* | `any` | - | |
939
+ | length* | `number` | - | |
940
+ | prototype* | `any` | - | |
941
+ | bind* | `(this: Function, thisArg: any, ...argArray: any[]) => any` | - | For a given function, creates a bound function that has the same body as the original function. The this object of the bound function is associated with the specified object, and has the specified initial parameters. @param thisArg An object to which the this keyword can refer inside the new function. @param argArray A list of arguments to be passed to the new function. |
942
+ | call* | `(this: Function, thisArg: any, ...argArray: any[]) => any` | - | Calls a method of an object, substituting another object for the current object. @param thisArg The object to be used as the current object. @param argArray A list of arguments to be passed to the method. |
943
+ | apply* | `(this: Function, thisArg: any, argArray?: any) => any` | - | Calls the function, substituting the specified object for the this value of the function, and the specified array for the arguments of the function. @param thisArg The object to be used as the this object. @param argArray A set of arguments to be passed to the function. |
944
+ | propTypes | `WeakValidationMap<TProps>` | - | Used to declare the types of the props accepted by the component. These types will be checked during rendering and in development only. We recommend using TypeScript instead of checking prop types at runtime. @see {@link https://react.dev/reference/react/Component#static-proptypes React Docs} @see {@link https://react.dev/reference/react/Component#static-proptypes React Docs} |
945
+ | contextType | `Context<any>` | - | |
946
+ | contextTypes | `ValidationMap<any>` | - | @deprecated use {@link ComponentClass.contextType } instead Lets you specify which legacy context is consumed by this component. @see {@link https://legacy.reactjs.org/docs/legacy-context.html Legacy React Docs} @deprecated Lets you specify which legacy context is consumed by this component. @see {@link https://legacy.reactjs.org/docs/legacy-context.html Legacy React Docs} |
947
+ | childContextTypes | `ValidationMap<any>` | - | @deprecated @see {@link https://legacy.reactjs.org/docs/legacy-context.html#how-to-use-context Legacy React Docs} |
948
+ | defaultProps | `Partial<TProps>` | - | Used to define default values for the props accepted by the component. @see {@link https://react.dev/reference/react/Component#static-defaultprops React Docs} @see {@link https://react.dev/reference/react/Component#static-defaultprops React Docs} @example ```tsx type Props = { name?: string } const MyComponent: FC<Props> = (props) => { return <div>{props.name}</div> } MyComponent.defaultProps = { name: 'John Doe' } ``` |
949
+ | displayName | `string` | - | Used in debugging messages. You might want to set it explicitly if you want to display a different name for debugging purposes. @see {@link https://legacy.reactjs.org/docs/react-component.html#displayname Legacy React Docs} @see {@link https://legacy.reactjs.org/docs/react-component.html#displayname Legacy React Docs} @example ```tsx const MyComponent: FC = () => { return <div>Hello!</div> } MyComponent.displayName = 'MyAwesomeComponent' ``` |
950
+ | getDerivedStateFromProps | `GetDerivedStateFromProps<TProps, any>` | - | |
951
+ | getDerivedStateFromError | `GetDerivedStateFromError<TProps, any>` | - | |
952
+ | toString | `() => string` | function toString() { [native code] } | Returns a string representation of a function. |
930
953
 
931
954
 
932
955
  [//]: DOCUMENTATION_SECTION_END
@@ -0,0 +1 @@
1
+ export * from './withCharacterCount';
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = {
8
+ enumerable: true,
9
+ get: function () {
10
+ return m[k];
11
+ }
12
+ };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ } : function (o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ });
19
+ var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", {
23
+ value: true
24
+ });
25
+ __exportStar(require("./withCharacterCount"), exports);
@@ -0,0 +1,8 @@
1
+ import { ComponentType } from 'react';
2
+ import { InputPrivateProps } from '@snack-uikit/input-private';
3
+ export type WithCharacterCountProps = {
4
+ handleReachLimit?(): void;
5
+ };
6
+ type FieldProps = Pick<InputPrivateProps, 'onChange' | 'maxLength'>;
7
+ export declare function withCharacterCount<TProps extends FieldProps>(FieldComponent: ComponentType<TProps>): import("react").ForwardRefExoticComponent<import("react").PropsWithoutRef<TProps & WithCharacterCountProps> & import("react").RefAttributes<HTMLInputElement>>;
8
+ export {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ var __rest = void 0 && (void 0).__rest || function (s, e) {
4
+ var t = {};
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
8
+ }
9
+ return t;
10
+ };
11
+ Object.defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+ exports.withCharacterCount = withCharacterCount;
15
+ const jsx_runtime_1 = require("react/jsx-runtime");
16
+ const react_1 = require("react");
17
+ function withCharacterCount(FieldComponent) {
18
+ return (0, react_1.forwardRef)((_a, ref) => {
19
+ var {
20
+ handleReachLimit,
21
+ onChange,
22
+ maxLength
23
+ } = _a,
24
+ restProps = __rest(_a, ["handleReachLimit", "onChange", "maxLength"]);
25
+ const handleLimitedChange = (0, react_1.useCallback)((value, e) => {
26
+ if (!maxLength || value.length > maxLength) {
27
+ return;
28
+ }
29
+ onChange === null || onChange === void 0 ? void 0 : onChange(value, e);
30
+ if (value.length === maxLength && handleReachLimit) {
31
+ handleReachLimit();
32
+ }
33
+ }, [maxLength, handleReachLimit, onChange]);
34
+ return (0, jsx_runtime_1.jsx)(FieldComponent, Object.assign({}, restProps, {
35
+ ref: ref,
36
+ maxLength: maxLength,
37
+ onChange: handleLimitedChange
38
+ }));
39
+ });
40
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './components';
2
2
  export * from './constants';
3
+ export * from './hocs';
3
4
  export { setNonce } from '@snack-uikit/scroll';
package/dist/cjs/index.js CHANGED
@@ -25,6 +25,7 @@ Object.defineProperty(exports, "__esModule", {
25
25
  exports.setNonce = void 0;
26
26
  __exportStar(require("./components"), exports);
27
27
  __exportStar(require("./constants"), exports);
28
+ __exportStar(require("./hocs"), exports);
28
29
  var scroll_1 = require("@snack-uikit/scroll");
29
30
  Object.defineProperty(exports, "setNonce", {
30
31
  enumerable: true,
@@ -0,0 +1 @@
1
+ export * from './withCharacterCount';
@@ -0,0 +1 @@
1
+ export * from './withCharacterCount';
@@ -0,0 +1,8 @@
1
+ import { ComponentType } from 'react';
2
+ import { InputPrivateProps } from '@snack-uikit/input-private';
3
+ export type WithCharacterCountProps = {
4
+ handleReachLimit?(): void;
5
+ };
6
+ type FieldProps = Pick<InputPrivateProps, 'onChange' | 'maxLength'>;
7
+ export declare function withCharacterCount<TProps extends FieldProps>(FieldComponent: ComponentType<TProps>): import("react").ForwardRefExoticComponent<import("react").PropsWithoutRef<TProps & WithCharacterCountProps> & import("react").RefAttributes<HTMLInputElement>>;
8
+ export {};
@@ -0,0 +1,28 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { forwardRef, useCallback } from 'react';
14
+ export function withCharacterCount(FieldComponent) {
15
+ return forwardRef((_a, ref) => {
16
+ var { handleReachLimit, onChange, maxLength } = _a, restProps = __rest(_a, ["handleReachLimit", "onChange", "maxLength"]);
17
+ const handleLimitedChange = useCallback((value, e) => {
18
+ if (!maxLength || value.length > maxLength) {
19
+ return;
20
+ }
21
+ onChange === null || onChange === void 0 ? void 0 : onChange(value, e);
22
+ if (value.length === maxLength && handleReachLimit) {
23
+ handleReachLimit();
24
+ }
25
+ }, [maxLength, handleReachLimit, onChange]);
26
+ return (_jsx(FieldComponent, Object.assign({}, restProps, { ref: ref, maxLength: maxLength, onChange: handleLimitedChange })));
27
+ });
28
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './components';
2
2
  export * from './constants';
3
+ export * from './hocs';
3
4
  export { setNonce } from '@snack-uikit/scroll';
package/dist/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './components';
2
2
  export * from './constants';
3
+ export * from './hocs';
3
4
  export { setNonce } from '@snack-uikit/scroll';
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Fields",
7
- "version": "0.51.17",
7
+ "version": "0.52.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -66,5 +66,5 @@
66
66
  "peerDependencies": {
67
67
  "@snack-uikit/locale": "*"
68
68
  },
69
- "gitHead": "0dbf2d0248621db41f5f53a7e4df55338d6ff4bd"
69
+ "gitHead": "afb2d2dbb5fdeedfed3e1056b6fd2fc197f42ab0"
70
70
  }
@@ -0,0 +1 @@
1
+ export * from './withCharacterCount';
@@ -0,0 +1,39 @@
1
+ import { ChangeEvent, ComponentType, forwardRef, Ref, useCallback } from 'react';
2
+
3
+ import { InputPrivateProps } from '@snack-uikit/input-private';
4
+
5
+ export type WithCharacterCountProps = {
6
+ handleReachLimit?(): void;
7
+ };
8
+
9
+ type FieldProps = Pick<InputPrivateProps, 'onChange' | 'maxLength'>;
10
+
11
+ export function withCharacterCount<TProps extends FieldProps>(FieldComponent: ComponentType<TProps>) {
12
+ return forwardRef<HTMLInputElement, TProps & WithCharacterCountProps>(
13
+ ({ handleReachLimit, onChange, maxLength, ...restProps }, ref) => {
14
+ const handleLimitedChange = useCallback(
15
+ (value: string, e?: ChangeEvent<HTMLInputElement>) => {
16
+ if (!maxLength || value.length > maxLength) {
17
+ return;
18
+ }
19
+
20
+ onChange?.(value, e);
21
+
22
+ if (value.length === maxLength && handleReachLimit) {
23
+ handleReachLimit();
24
+ }
25
+ },
26
+ [maxLength, handleReachLimit, onChange],
27
+ );
28
+
29
+ return (
30
+ <FieldComponent
31
+ {...(restProps as unknown as TProps)}
32
+ ref={ref as Ref<HTMLInputElement>}
33
+ maxLength={maxLength}
34
+ onChange={handleLimitedChange}
35
+ />
36
+ );
37
+ },
38
+ );
39
+ }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './components';
2
2
  export * from './constants';
3
+ export * from './hocs';
3
4
  export { setNonce } from '@snack-uikit/scroll';