@koobiq/react-core 0.0.1-beta.9 → 0.1.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/dist/hooks/index.d.ts +14 -13
- package/dist/hooks/useBoolean/useBoolean.d.ts +4 -4
- package/dist/hooks/useDebounceCallback/index.d.ts +1 -0
- package/dist/hooks/useDebounceCallback/useDebounceCallback.d.ts +29 -0
- package/dist/hooks/useDebounceCallback/useDebounceCallback.js +39 -0
- package/dist/hooks/useInterval/useInterval.d.ts +2 -2
- package/dist/index.d.ts +10 -9
- package/dist/index.js +11 -11
- package/package.json +13 -5
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
export * from './usePrevious
|
|
2
|
-
export * from './useMultiRef
|
|
3
|
-
export * from './useIsomorphicEffect
|
|
1
|
+
export * from './usePrevious';
|
|
2
|
+
export * from './useMultiRef';
|
|
3
|
+
export * from './useIsomorphicEffect';
|
|
4
4
|
export * from './useMediaQuery';
|
|
5
|
-
export * from './useSsr
|
|
6
|
-
export * from './useDOMRef
|
|
7
|
-
export * from './useBoolean
|
|
8
|
-
export * from './useMutableRef
|
|
9
|
-
export * from './useInterval
|
|
10
|
-
export * from './useIsFirstRender
|
|
11
|
-
export * from './useEventListener
|
|
12
|
-
export * from './useResizeObserver
|
|
13
|
-
export * from './useElementSize
|
|
14
|
-
export * from './useRefs
|
|
5
|
+
export * from './useSsr';
|
|
6
|
+
export * from './useDOMRef';
|
|
7
|
+
export * from './useBoolean';
|
|
8
|
+
export * from './useMutableRef';
|
|
9
|
+
export * from './useInterval';
|
|
10
|
+
export * from './useIsFirstRender';
|
|
11
|
+
export * from './useEventListener';
|
|
12
|
+
export * from './useResizeObserver';
|
|
13
|
+
export * from './useElementSize';
|
|
14
|
+
export * from './useRefs';
|
|
15
|
+
export * from './useDebounceCallback';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Dispatch, SetStateAction } from 'react';
|
|
2
2
|
export type UseBooleanControllers = {
|
|
3
|
-
/** Set the value to `true
|
|
3
|
+
/** Set the value to `true`. */
|
|
4
4
|
on: () => void;
|
|
5
|
-
/** Set the value to `false
|
|
5
|
+
/** Set the value to `false`. */
|
|
6
6
|
off: () => void;
|
|
7
|
-
/** Toggle the value to the opposite state */
|
|
7
|
+
/** Toggle the value to the opposite state. */
|
|
8
8
|
toggle: () => void;
|
|
9
|
-
/** Set the value to a specific state */
|
|
9
|
+
/** Set the value to a specific state. */
|
|
10
10
|
set: Dispatch<SetStateAction<boolean>>;
|
|
11
11
|
};
|
|
12
12
|
export type UseBooleanReturnValue = [boolean, UseBooleanControllers];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useDebounceCallback';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type FunctionCallback = (...args: any[]) => void;
|
|
2
|
+
export type UseDebounceCallbackReturnValue<CB extends FunctionCallback> = [
|
|
3
|
+
CB,
|
|
4
|
+
() => void
|
|
5
|
+
];
|
|
6
|
+
export type UseDebounceCallbackPropOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* If `true`, the first call runs without delay.
|
|
9
|
+
* @default false
|
|
10
|
+
*/
|
|
11
|
+
firstCallWithoutDelay: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type UseDebounceCallbackProps<CB> = {
|
|
14
|
+
/**
|
|
15
|
+
* The function to be debounced.
|
|
16
|
+
* It will only run after the specified delay has passed without new calls.
|
|
17
|
+
*/
|
|
18
|
+
callback: CB;
|
|
19
|
+
/**
|
|
20
|
+
* Delay in milliseconds to wait before calling the callback.
|
|
21
|
+
* @default 300
|
|
22
|
+
*/
|
|
23
|
+
delay?: number;
|
|
24
|
+
/** Additional debounce options. */
|
|
25
|
+
options?: UseDebounceCallbackPropOptions;
|
|
26
|
+
};
|
|
27
|
+
/** A hook that waits some time before running a function. */
|
|
28
|
+
export declare function useDebounceCallback<CB extends FunctionCallback>({ callback, delay, options, }: UseDebounceCallbackProps<CB>): UseDebounceCallbackReturnValue<CB>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRef, useCallback, useEffect } from "react";
|
|
3
|
+
function useDebounceCallback({
|
|
4
|
+
callback,
|
|
5
|
+
delay = 300,
|
|
6
|
+
options = { firstCallWithoutDelay: false }
|
|
7
|
+
}) {
|
|
8
|
+
const { firstCallWithoutDelay } = options;
|
|
9
|
+
const timeoutRef = useRef(null);
|
|
10
|
+
const debouncedHandler = useCallback(
|
|
11
|
+
(...args) => {
|
|
12
|
+
if (!timeoutRef.current && firstCallWithoutDelay) {
|
|
13
|
+
callback(...args);
|
|
14
|
+
timeoutRef.current = setTimeout(() => {
|
|
15
|
+
timeoutRef.current = null;
|
|
16
|
+
}, delay);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (timeoutRef.current) {
|
|
20
|
+
clearTimeout(timeoutRef.current);
|
|
21
|
+
}
|
|
22
|
+
timeoutRef.current = setTimeout(() => {
|
|
23
|
+
callback(...args);
|
|
24
|
+
timeoutRef.current = null;
|
|
25
|
+
}, delay);
|
|
26
|
+
},
|
|
27
|
+
[callback, delay, options.firstCallWithoutDelay]
|
|
28
|
+
);
|
|
29
|
+
const cancel = useCallback(() => {
|
|
30
|
+
if (timeoutRef.current) {
|
|
31
|
+
clearTimeout(timeoutRef.current);
|
|
32
|
+
}
|
|
33
|
+
}, []);
|
|
34
|
+
useEffect(() => () => cancel(), []);
|
|
35
|
+
return [debouncedHandler, cancel];
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
useDebounceCallback
|
|
39
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare function useInterval(
|
|
2
|
-
/** A callback function that will be triggered at a given interval */
|
|
2
|
+
/** A callback function that will be triggered at a given interval. */
|
|
3
3
|
callback: () => void,
|
|
4
|
-
/** Time interval in milliseconds */
|
|
4
|
+
/** Time interval in milliseconds. */
|
|
5
5
|
interval: number | null): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export * from '
|
|
6
|
-
export * from '
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export
|
|
1
|
+
export { useRouter, mergeProps, filterDOMProps, RouterProvider, } from '@react-aria/utils';
|
|
2
|
+
export type { Node, ItemProps, PressEvent, HoverEvent, SectionProps, LinkDOMProps, FocusableElement, } from '@react-types/shared';
|
|
3
|
+
export * from '@react-aria/i18n';
|
|
4
|
+
export * from '@react-aria/focus';
|
|
5
|
+
export * from '@internationalized/date';
|
|
6
|
+
export * from '@react-aria/interactions';
|
|
7
|
+
export * from './types';
|
|
8
|
+
export * from './hooks';
|
|
9
|
+
export * from './utils';
|
|
10
|
+
export * from './styles';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { RouterProvider, filterDOMProps, mergeProps, useRouter } from "@react-aria/utils";
|
|
2
|
+
export * from "@react-aria/i18n";
|
|
3
|
+
export * from "@react-aria/focus";
|
|
4
|
+
export * from "@internationalized/date";
|
|
5
|
+
export * from "@react-aria/interactions";
|
|
6
6
|
import { usePrevious } from "./hooks/usePrevious/usePrevious.js";
|
|
7
7
|
import { useMultiRef } from "./hooks/useMultiRef/useMultiRef.js";
|
|
8
8
|
import { useIsomorphicEffect } from "./hooks/useIsomorphicEffect/useIsomorphicEffect.js";
|
|
@@ -17,6 +17,7 @@ import { useEventListener } from "./hooks/useEventListener/useEventListener.js";
|
|
|
17
17
|
import { useResizeObserver } from "./hooks/useResizeObserver/useResizeObserver.js";
|
|
18
18
|
import { useElementSize } from "./hooks/useElementSize/useElementSize.js";
|
|
19
19
|
import { useRefs } from "./hooks/useRefs/useRefs.js";
|
|
20
|
+
import { useDebounceCallback } from "./hooks/useDebounceCallback/useDebounceCallback.js";
|
|
20
21
|
import { polymorphicForwardRef } from "./utils/polymorphicForwardRef.js";
|
|
21
22
|
import { isNotNil } from "./utils/typeGuards/isNotNil.js";
|
|
22
23
|
import { isString } from "./utils/typeGuards/isString.js";
|
|
@@ -24,8 +25,9 @@ import { isNumber } from "./utils/typeGuards/isNumber.js";
|
|
|
24
25
|
import { setRef } from "./utils/setRef.js";
|
|
25
26
|
import { isBrowser } from "./utils/isBrowser.js";
|
|
26
27
|
import { capitalizeFirstLetter } from "./utils/capitalizeFirstLetter/capitalizeFirstLetter.js";
|
|
28
|
+
import { clsx } from "./styles/clsx.js";
|
|
27
29
|
export {
|
|
28
|
-
|
|
30
|
+
RouterProvider,
|
|
29
31
|
capitalizeFirstLetter,
|
|
30
32
|
clsx,
|
|
31
33
|
filterDOMProps,
|
|
@@ -38,20 +40,18 @@ export {
|
|
|
38
40
|
setRef,
|
|
39
41
|
useBoolean,
|
|
40
42
|
useDOMRef,
|
|
43
|
+
useDebounceCallback,
|
|
41
44
|
useElementSize,
|
|
42
45
|
useEventListener,
|
|
43
|
-
useFocusRing,
|
|
44
|
-
useHover,
|
|
45
46
|
useInterval,
|
|
46
47
|
useIsFirstRender,
|
|
47
48
|
useIsomorphicEffect,
|
|
48
49
|
useMediaQuery,
|
|
49
50
|
useMultiRef,
|
|
50
51
|
useMutableRef,
|
|
51
|
-
usePress,
|
|
52
52
|
usePrevious,
|
|
53
53
|
useRefs,
|
|
54
54
|
useResizeObserver,
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
useRouter,
|
|
56
|
+
useSsr
|
|
57
57
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koobiq/react-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"main": "./dist/index.js",
|
|
5
6
|
"types": "./dist/index.d.ts",
|
|
6
7
|
"exports": {
|
|
@@ -16,12 +17,19 @@
|
|
|
16
17
|
"publishConfig": {
|
|
17
18
|
"access": "public"
|
|
18
19
|
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"directory": "packages/core",
|
|
23
|
+
"url": "git+https://github.com/koobiq/react-components.git"
|
|
24
|
+
},
|
|
19
25
|
"sideEffects": false,
|
|
20
26
|
"dependencies": {
|
|
21
|
-
"@
|
|
22
|
-
"@react-aria/
|
|
23
|
-
"@react-aria/
|
|
24
|
-
"@react-
|
|
27
|
+
"@internationalized/date": "^3.8.2",
|
|
28
|
+
"@react-aria/focus": "^3.20.5",
|
|
29
|
+
"@react-aria/i18n": "^3.12.10",
|
|
30
|
+
"@react-aria/interactions": "^3.25.3",
|
|
31
|
+
"@react-aria/utils": "^3.29.1",
|
|
32
|
+
"@react-types/shared": "^3.30.0"
|
|
25
33
|
},
|
|
26
34
|
"peerDependencies": {
|
|
27
35
|
"react": "18.x || 19.x",
|