jy-headless 0.2.26 → 0.2.27
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/buttons/Button/Button.d.ts +1 -1
- package/buttons/Button/Button.js +3 -14
- package/cjs/buttons/Button/Button.d.ts +1 -1
- package/cjs/buttons/Button/Button.js +3 -14
- package/cjs/hooks/index.d.ts +2 -0
- package/cjs/hooks/useDebouncing.d.ts +2 -0
- package/cjs/hooks/useDebouncing.js +16 -0
- package/cjs/hooks/useThrottling.d.ts +2 -0
- package/cjs/hooks/useThrottling.js +16 -0
- package/cjs/index.d.ts +5 -4
- package/cjs/index.js +1 -8
- package/cjs/inputs/Input/Input.d.ts +2 -2
- package/cjs/inputs/Input/Input.js +4 -3
- package/cjs/types/buttons/index.d.ts +7 -0
- package/cjs/types/index.d.ts +2 -2
- package/cjs/types/inputs/index.d.ts +9 -0
- package/cjs/utils/ArrayUtils.d.ts +1 -3
- package/hooks/index.d.ts +2 -0
- package/hooks/useDebouncing.d.ts +2 -0
- package/hooks/useDebouncing.js +14 -0
- package/hooks/useThrottling.d.ts +2 -0
- package/hooks/useThrottling.js +14 -0
- package/index.d.ts +5 -4
- package/index.js +1 -4
- package/inputs/Input/Input.d.ts +2 -2
- package/inputs/Input/Input.js +4 -3
- package/package.json +11 -1
- package/types/buttons/index.d.ts +7 -0
- package/types/index.d.ts +2 -2
- package/types/inputs/index.d.ts +9 -0
- package/utils/ArrayUtils.d.ts +1 -3
- package/version.txt +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ButtonProps } from '../../types';
|
|
2
|
-
declare const Button: ({ onClick,
|
|
2
|
+
declare const Button: ({ onClick, loading, readOnly, disabled, useDebounce, timeout, children, ...props }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export default Button;
|
package/buttons/Button/Button.js
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import
|
|
2
|
+
import useDebouncing from '../../hooks/useDebouncing.js';
|
|
3
3
|
|
|
4
|
-
const Button = ({ onClick,
|
|
5
|
-
const
|
|
6
|
-
const handleClick = (() => {
|
|
7
|
-
if (!onClick)
|
|
8
|
-
return;
|
|
9
|
-
if (debounce) {
|
|
10
|
-
return () => {
|
|
11
|
-
clearTimeout(timer.current);
|
|
12
|
-
timer.current = setTimeout(onClick, 300);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
return onClick;
|
|
16
|
-
})();
|
|
4
|
+
const Button = ({ onClick, loading = false, readOnly = false, disabled = false, useDebounce = false, timeout = 300, children, ...props }) => {
|
|
5
|
+
const handleClick = onClick && useDebounce ? useDebouncing(onClick, timeout || 300) : onClick;
|
|
17
6
|
return (jsx("button", { onClick: handleClick, disabled: disabled || loading || readOnly, ...props, children: children }));
|
|
18
7
|
};
|
|
19
8
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ButtonProps } from '../../types';
|
|
2
|
-
declare const Button: ({ onClick,
|
|
2
|
+
declare const Button: ({ onClick, loading, readOnly, disabled, useDebounce, timeout, children, ...props }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export default Button;
|
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var
|
|
4
|
+
var useDebouncing = require('../../hooks/useDebouncing.js');
|
|
5
5
|
|
|
6
|
-
const Button = ({ onClick,
|
|
7
|
-
const
|
|
8
|
-
const handleClick = (() => {
|
|
9
|
-
if (!onClick)
|
|
10
|
-
return;
|
|
11
|
-
if (debounce) {
|
|
12
|
-
return () => {
|
|
13
|
-
clearTimeout(timer.current);
|
|
14
|
-
timer.current = setTimeout(onClick, 300);
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
return onClick;
|
|
18
|
-
})();
|
|
6
|
+
const Button = ({ onClick, loading = false, readOnly = false, disabled = false, useDebounce = false, timeout = 300, children, ...props }) => {
|
|
7
|
+
const handleClick = onClick && useDebounce ? useDebouncing(onClick, timeout || 300) : onClick;
|
|
19
8
|
return (jsxRuntime.jsx("button", { onClick: handleClick, disabled: disabled || loading || readOnly, ...props, children: children }));
|
|
20
9
|
};
|
|
21
10
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
const useDebouncing = (callback, delay) => {
|
|
6
|
+
const timer = react.useRef(null);
|
|
7
|
+
return react.useCallback(() => {
|
|
8
|
+
if (timer.current)
|
|
9
|
+
clearTimeout(timer.current);
|
|
10
|
+
timer.current = setTimeout(() => {
|
|
11
|
+
callback();
|
|
12
|
+
}, delay);
|
|
13
|
+
}, [callback, delay]);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
module.exports = useDebouncing;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
const useThrottling = (callback, delay) => {
|
|
6
|
+
const lastCalled = react.useRef(0);
|
|
7
|
+
return react.useCallback((...args) => {
|
|
8
|
+
const now = Date.now();
|
|
9
|
+
if (now - lastCalled.current >= delay) {
|
|
10
|
+
lastCalled.current = now;
|
|
11
|
+
callback(...args);
|
|
12
|
+
}
|
|
13
|
+
}, [callback, delay]);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
module.exports = useThrottling;
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { default as Button } from './buttons
|
|
2
|
-
export { default as Input } from './inputs
|
|
3
|
-
export *
|
|
4
|
-
export *
|
|
1
|
+
export { default as Button } from './buttons';
|
|
2
|
+
export { default as Input } from './inputs';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export * from './utils';
|
|
5
|
+
export * from './hooks';
|
package/cjs/index.js
CHANGED
|
@@ -2,16 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var Button = require('./buttons/Button/Button.js');
|
|
4
4
|
var Input = require('./inputs/Input/Input.js');
|
|
5
|
-
|
|
6
|
-
var index$1 = require('./utils/index.js');
|
|
7
|
-
|
|
8
|
-
function _interopNamespaceDefaultOnly (e) { return Object.freeze({ __proto__: null, default: e }); }
|
|
9
|
-
|
|
10
|
-
var index__namespace = /*#__PURE__*/_interopNamespaceDefaultOnly(index$1);
|
|
5
|
+
require('react');
|
|
11
6
|
|
|
12
7
|
|
|
13
8
|
|
|
14
9
|
exports.Button = Button;
|
|
15
10
|
exports.Input = Input;
|
|
16
|
-
exports.Types = index;
|
|
17
|
-
exports.Utils = index__namespace;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { InputProps } from '../../types
|
|
2
|
-
declare const Input: ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass, children, ...props }: InputProps) => import("react/jsx-runtime").JSX.Element;
|
|
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;
|
|
3
3
|
export default Input;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var
|
|
4
|
+
var useThrottling = require('../../hooks/useThrottling.js');
|
|
5
5
|
|
|
6
|
-
const Input = ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass, children, ...props }) => {
|
|
7
|
-
|
|
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", { id: id, onChange: handleChange, ...props }), suffixElement] }));
|
|
8
9
|
};
|
|
9
10
|
|
|
10
11
|
module.exports = Input;
|
package/cjs/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './buttons
|
|
2
|
-
export * from './inputs
|
|
1
|
+
export * from './buttons';
|
|
2
|
+
export * from './inputs';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CSSProperties, InputHTMLAttributes, ReactElement, ReactNode } from 'react';
|
|
2
|
+
export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
3
|
+
suffixElement?: ReactElement | ReactNode;
|
|
4
|
+
prefixElement?: ReactElement | ReactNode;
|
|
5
|
+
wrapperStyle?: CSSProperties;
|
|
6
|
+
wrapperClass?: string[];
|
|
7
|
+
useThrottle?: boolean;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
}
|
package/hooks/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useRef, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
const useDebouncing = (callback, delay) => {
|
|
4
|
+
const timer = useRef(null);
|
|
5
|
+
return useCallback(() => {
|
|
6
|
+
if (timer.current)
|
|
7
|
+
clearTimeout(timer.current);
|
|
8
|
+
timer.current = setTimeout(() => {
|
|
9
|
+
callback();
|
|
10
|
+
}, delay);
|
|
11
|
+
}, [callback, delay]);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { useDebouncing as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useRef, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
const useThrottling = (callback, delay) => {
|
|
4
|
+
const lastCalled = useRef(0);
|
|
5
|
+
return useCallback((...args) => {
|
|
6
|
+
const now = Date.now();
|
|
7
|
+
if (now - lastCalled.current >= delay) {
|
|
8
|
+
lastCalled.current = now;
|
|
9
|
+
callback(...args);
|
|
10
|
+
}
|
|
11
|
+
}, [callback, delay]);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { useThrottling as default };
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { default as Button } from './buttons
|
|
2
|
-
export { default as Input } from './inputs
|
|
3
|
-
export *
|
|
4
|
-
export *
|
|
1
|
+
export { default as Button } from './buttons';
|
|
2
|
+
export { default as Input } from './inputs';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export * from './utils';
|
|
5
|
+
export * from './hooks';
|
package/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
export { default as Button } from './buttons/Button/Button.js';
|
|
2
2
|
export { default as Input } from './inputs/Input/Input.js';
|
|
3
|
-
import
|
|
4
|
-
export { index as Types };
|
|
5
|
-
import * as index$1 from './utils/index.js';
|
|
6
|
-
export { index$1 as Utils };
|
|
3
|
+
import 'react';
|
package/inputs/Input/Input.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { InputProps } from '../../types
|
|
2
|
-
declare const Input: ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass, children, ...props }: InputProps) => import("react/jsx-runtime").JSX.Element;
|
|
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;
|
|
3
3
|
export default Input;
|
package/inputs/Input/Input.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import
|
|
2
|
+
import useThrottling from '../../hooks/useThrottling.js';
|
|
3
3
|
|
|
4
|
-
const Input = ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass, children, ...props }) => {
|
|
5
|
-
|
|
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", { id: id, onChange: handleChange, ...props }), suffixElement] }));
|
|
6
7
|
};
|
|
7
8
|
|
|
8
9
|
export { Input as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jy-headless",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.27",
|
|
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",
|
|
@@ -23,6 +23,16 @@
|
|
|
23
23
|
"require": "./cjs/cjs/index.js",
|
|
24
24
|
"types": "./cjs/index.d.ts"
|
|
25
25
|
},
|
|
26
|
+
"./useDebouncing": {
|
|
27
|
+
"import": "./hooks/useDebouncing.js",
|
|
28
|
+
"require": "./cjs/hooks/useDebouncing.js",
|
|
29
|
+
"types": "./hooks/useDebouncing.d.ts"
|
|
30
|
+
},
|
|
31
|
+
"./useThrottling": {
|
|
32
|
+
"import": "./hooks/useThrottling.js",
|
|
33
|
+
"require": "./cjs/hooks/useThrottling.js",
|
|
34
|
+
"types": "./hooks/useThrottling.d.ts"
|
|
35
|
+
},
|
|
26
36
|
"./index": {
|
|
27
37
|
"import": "./utils/index.js",
|
|
28
38
|
"require": "./cjs/utils/index.js",
|
package/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './buttons
|
|
2
|
-
export * from './inputs
|
|
1
|
+
export * from './buttons';
|
|
2
|
+
export * from './inputs';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CSSProperties, InputHTMLAttributes, ReactElement, ReactNode } from 'react';
|
|
2
|
+
export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
3
|
+
suffixElement?: ReactElement | ReactNode;
|
|
4
|
+
prefixElement?: ReactElement | ReactNode;
|
|
5
|
+
wrapperStyle?: CSSProperties;
|
|
6
|
+
wrapperClass?: string[];
|
|
7
|
+
useThrottle?: boolean;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
}
|
package/utils/ArrayUtils.d.ts
CHANGED
package/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.
|
|
1
|
+
0.2.27
|