jy-headless 0.2.31 → 0.2.32

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.
@@ -1,3 +1,3 @@
1
1
  import { InputProps } from '../../types';
2
- declare const Input: ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass, onChange, timeout, useThrottle, children, ...props }: InputProps) => import("react/jsx-runtime").JSX.Element;
2
+ declare const Input: ({ id, value, suffixElement, prefixElement, wrapperStyle, wrapperClass, onChange, timeout, useThrottle, children, showLimit, maxLength, ...props }: InputProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default Input;
@@ -3,9 +3,13 @@
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var useThrottling = require('../../hooks/useThrottling.js');
5
5
 
6
- const Input = ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass = [], onChange, timeout = 300, useThrottle = false, children, ...props }) => {
7
- const handleChange = onChange && useThrottle ? useThrottling(onChange, timeout) : onChange;
8
- return (jsxRuntime.jsxs("span", { "data-testid": 'input-wrapper', id: [id, 'input-wrapper'].join('-'), className: wrapperClass?.join(' '), style: wrapperStyle, children: [prefixElement, jsxRuntime.jsx("input", { role: 'textbox', id: id, onChange: handleChange, ...props }), suffixElement] }));
6
+ const Input = ({ id, value, suffixElement, prefixElement, wrapperStyle, wrapperClass = [], onChange, timeout = 300, useThrottle = false, children, showLimit, maxLength, ...props }) => {
7
+ const handleChange = (e) => {
8
+ if (maxLength && e.target.value?.length > maxLength)
9
+ return;
10
+ (onChange && useThrottle ? useThrottling(onChange, timeout) : onChange)?.(e);
11
+ };
12
+ return (jsxRuntime.jsxs("span", { "data-testid": 'input-wrapper', id: [id, 'input-wrapper'].join('-'), className: wrapperClass?.join(' '), style: wrapperStyle, children: [prefixElement, jsxRuntime.jsx("input", { role: 'textbox', id: id, value: value, onChange: handleChange, ...props }), showLimit && maxLength && (jsxRuntime.jsxs("span", { id: [id, 'input-limit'].join('-'), children: [(value ?? '').toString().length, "/", maxLength] })), suffixElement] }));
9
13
  };
10
14
 
11
15
  module.exports = Input;
@@ -6,6 +6,8 @@ export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
6
6
  wrapperClass?: string[];
7
7
  useThrottle?: boolean;
8
8
  timeout?: number;
9
+ showLimit?: boolean;
10
+ maxLength?: number;
9
11
  }
10
12
  export interface ImageInputContextData {
11
13
  id?: string;
@@ -1,3 +1,3 @@
1
1
  import { InputProps } from '../../types';
2
- declare const Input: ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass, onChange, timeout, useThrottle, children, ...props }: InputProps) => import("react/jsx-runtime").JSX.Element;
2
+ declare const Input: ({ id, value, suffixElement, prefixElement, wrapperStyle, wrapperClass, onChange, timeout, useThrottle, children, showLimit, maxLength, ...props }: InputProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default Input;
@@ -1,9 +1,13 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
2
  import useThrottling from '../../hooks/useThrottling.js';
3
3
 
4
- const Input = ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass = [], onChange, timeout = 300, useThrottle = false, children, ...props }) => {
5
- const handleChange = onChange && useThrottle ? useThrottling(onChange, timeout) : onChange;
6
- return (jsxs("span", { "data-testid": 'input-wrapper', id: [id, 'input-wrapper'].join('-'), className: wrapperClass?.join(' '), style: wrapperStyle, children: [prefixElement, jsx("input", { role: 'textbox', id: id, onChange: handleChange, ...props }), suffixElement] }));
4
+ const Input = ({ id, value, suffixElement, prefixElement, wrapperStyle, wrapperClass = [], onChange, timeout = 300, useThrottle = false, children, showLimit, maxLength, ...props }) => {
5
+ const handleChange = (e) => {
6
+ if (maxLength && e.target.value?.length > maxLength)
7
+ return;
8
+ (onChange && useThrottle ? useThrottling(onChange, timeout) : onChange)?.(e);
9
+ };
10
+ return (jsxs("span", { "data-testid": 'input-wrapper', id: [id, 'input-wrapper'].join('-'), className: wrapperClass?.join(' '), style: wrapperStyle, children: [prefixElement, jsx("input", { role: 'textbox', id: id, value: value, onChange: handleChange, ...props }), showLimit && maxLength && (jsxs("span", { id: [id, 'input-limit'].join('-'), children: [(value ?? '').toString().length, "/", maxLength] })), suffixElement] }));
7
11
  };
8
12
 
9
13
  export { Input as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jy-headless",
3
- "version": "0.2.31",
3
+ "version": "0.2.32",
4
4
  "description": "A lightweight and customizable headless UI library for React components",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/yCZwIqY/jy-headless",
@@ -6,6 +6,8 @@ export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
6
6
  wrapperClass?: string[];
7
7
  useThrottle?: boolean;
8
8
  timeout?: number;
9
+ showLimit?: boolean;
10
+ maxLength?: number;
9
11
  }
10
12
  export interface ImageInputContextData {
11
13
  id?: string;
package/version.txt CHANGED
@@ -1 +1 @@
1
- 0.2.31
1
+ 0.2.32