react-simplikit 0.0.3 → 0.0.5
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/components/ImpressionArea/index.d.ts +10 -13
- package/dist/components/Separated/index.d.ts +4 -4
- package/dist/components/Separated/index.js +1 -1
- package/dist/hooks/useAsyncEffect/index.d.ts +2 -2
- package/dist/hooks/useBooleanState/index.d.ts +5 -5
- package/dist/hooks/{useCallbackOnce → useCallbackOncePerRender}/index.d.ts +5 -5
- package/dist/hooks/{useCallbackOnce → useCallbackOncePerRender}/index.js +9 -9
- package/dist/hooks/useDebounce/index.d.ts +2 -1
- package/dist/hooks/useImpressionRef/index.d.ts +7 -7
- package/dist/hooks/useInputState/index.d.ts +5 -5
- package/dist/hooks/useIntersectionObserver/index.d.ts +5 -5
- package/dist/hooks/useLoading/index.d.ts +6 -7
- package/dist/hooks/useRefEffect/index.d.ts +3 -3
- package/dist/hooks/useStorageState/index.d.ts +3 -3
- package/dist/hooks/useToggle/index.d.ts +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/utils/buildContext/index.d.ts +5 -5
- package/dist/utils/mergeRefs/index.d.ts +2 -2
- package/esm/components/ImpressionArea/index.d.mts +10 -13
- package/esm/components/Separated/index.d.mts +4 -4
- package/esm/components/Separated/index.mjs +1 -1
- package/esm/hooks/useAsyncEffect/index.d.mts +2 -2
- package/esm/hooks/useBooleanState/index.d.mts +5 -5
- package/esm/hooks/{useCallbackOnce → useCallbackOncePerRender}/index.d.mts +5 -5
- package/esm/hooks/{useCallbackOnce → useCallbackOncePerRender}/index.mjs +4 -4
- package/esm/hooks/useDebounce/index.d.mts +2 -1
- package/esm/hooks/useImpressionRef/index.d.mts +7 -7
- package/esm/hooks/useInputState/index.d.mts +5 -5
- package/esm/hooks/useIntersectionObserver/index.d.mts +5 -5
- package/esm/hooks/useLoading/index.d.mts +6 -7
- package/esm/hooks/useRefEffect/index.d.mts +3 -3
- package/esm/hooks/useStorageState/index.d.mts +3 -3
- package/esm/hooks/useToggle/index.d.mts +3 -3
- package/esm/index.d.mts +1 -1
- package/esm/index.mjs +4 -4
- package/esm/utils/buildContext/index.d.mts +5 -5
- package/esm/utils/mergeRefs/index.d.mts +2 -2
- package/package.json +9 -1
|
@@ -14,22 +14,19 @@ type Props<Tag extends ElementType> = React__default.ComponentPropsWithoutRef<Ta
|
|
|
14
14
|
* and executes callbacks when the element enters or exits the viewport. This component uses the `useImpressionRef`
|
|
15
15
|
* hook to track the element's visibility.
|
|
16
16
|
*
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {
|
|
20
|
-
* @param {number} [
|
|
21
|
-
* @param {
|
|
22
|
-
* @param {() => void} [
|
|
23
|
-
* @param {
|
|
24
|
-
* @param {
|
|
25
|
-
* @param {
|
|
26
|
-
* @param {string} [props.className] - Additional class names for styling.
|
|
17
|
+
* @param {ElementType} [as='div'] - The HTML tag to render. Defaults to `div`.
|
|
18
|
+
* @param {string} [rootMargin] - Margin to adjust the detection area.
|
|
19
|
+
* @param {number} [areaThreshold] - Minimum ratio of the element that must be visible (0 to 1).
|
|
20
|
+
* @param {number} [timeThreshold] - Minimum time the element must be visible (in milliseconds).
|
|
21
|
+
* @param {() => void} [onImpressionStart] - Callback function executed when the element enters the view.
|
|
22
|
+
* @param {() => void} [onImpressionEnd] - Callback function executed when the element exits the view.
|
|
23
|
+
* @param {Ref<HTMLElement>} [ref] - Reference to the element.
|
|
24
|
+
* @param {React.ReactNode} [children] - Child elements to be rendered inside the component.
|
|
25
|
+
* @param {string} [className] - Additional class names for styling.
|
|
27
26
|
*
|
|
28
27
|
* @returns {JSX.Element} A React component that tracks the visibility of its child elements.
|
|
29
28
|
*
|
|
30
29
|
* @example
|
|
31
|
-
* import { ImpressionArea } from 'react-simplikit';
|
|
32
|
-
*
|
|
33
30
|
* function App() {
|
|
34
31
|
* return (
|
|
35
32
|
* <ImpressionArea
|
|
@@ -38,7 +35,7 @@ type Props<Tag extends ElementType> = React__default.ComponentPropsWithoutRef<Ta
|
|
|
38
35
|
* timeThreshold={1000}
|
|
39
36
|
* areaThreshold={0.5}
|
|
40
37
|
* >
|
|
41
|
-
* <div>Track
|
|
38
|
+
* <div>Track me!</div>
|
|
42
39
|
* </ImpressionArea>
|
|
43
40
|
* );
|
|
44
41
|
* }
|
|
@@ -2,7 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
type Props = {
|
|
5
|
-
|
|
5
|
+
by: ReactNode;
|
|
6
6
|
children: ReactNode;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
@@ -12,14 +12,14 @@ type Props = {
|
|
|
12
12
|
*
|
|
13
13
|
* @param {React.ReactNode} children - The child elements to render.
|
|
14
14
|
* Only valid React elements (`React.isValidElement`) will be rendered.
|
|
15
|
-
* @param {React.ReactNode}
|
|
15
|
+
* @param {React.ReactNode} by - The component to insert between child elements.
|
|
16
16
|
*
|
|
17
17
|
* @returns {JSX.Element} A React component that separates children with a specified separator.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* function App() {
|
|
21
21
|
* return (
|
|
22
|
-
* <Separated
|
|
22
|
+
* <Separated by={<Border type="padding24" />}>
|
|
23
23
|
* {['hello', 'react', 'world'].map(item => (
|
|
24
24
|
* <div key={item}>{item}</div>
|
|
25
25
|
* ))}
|
|
@@ -33,6 +33,6 @@ type Props = {
|
|
|
33
33
|
* // <div>world</div>
|
|
34
34
|
* }
|
|
35
35
|
*/
|
|
36
|
-
declare function Separated({ children,
|
|
36
|
+
declare function Separated({ children, by: separator }: Props): react_jsx_runtime.JSX.Element;
|
|
37
37
|
|
|
38
38
|
export { Separated };
|
|
@@ -27,7 +27,7 @@ module.exports = __toCommonJS(Separated_exports);
|
|
|
27
27
|
// src/components/Separated/Separated.tsx
|
|
28
28
|
var import_react = require("react");
|
|
29
29
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
-
function Separated({ children,
|
|
30
|
+
function Separated({ children, by: separator }) {
|
|
31
31
|
const childrenArray = import_react.Children.toArray(children).filter(import_react.isValidElement);
|
|
32
32
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: childrenArray.map((child, i, { length }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
|
|
33
33
|
child,
|
|
@@ -16,9 +16,9 @@ import { DependencyList } from 'react';
|
|
|
16
16
|
* setData(data);
|
|
17
17
|
*
|
|
18
18
|
* return () => {
|
|
19
|
-
* console.log('Cleanup on unmount or
|
|
19
|
+
* console.log('Cleanup on unmount or dependencies change');
|
|
20
20
|
* };
|
|
21
|
-
* }, [
|
|
21
|
+
* }, [dependencies]);
|
|
22
22
|
*/
|
|
23
23
|
declare function useAsyncEffect(effect: () => Promise<void | (() => void)>, deps?: DependencyList): void;
|
|
24
24
|
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @param {boolean} [defaultValue=false] - The initial value of the state. Defaults to `false`.
|
|
7
7
|
*
|
|
8
|
-
* @returns {readonly [boolean, () => void, () => void, () => void]} A tuple containing:
|
|
9
|
-
* - `boolean` - The current state value
|
|
10
|
-
* - `() => void` - A function to set the state to `true
|
|
11
|
-
* - `() => void` - A function to set the state to `false
|
|
12
|
-
* - `() => void` - A function to toggle the state
|
|
8
|
+
* @returns {readonly [state: boolean, setTrue: () => void, setFalse: () => void, toggle: () => void]} A tuple containing:
|
|
9
|
+
* - state `boolean` - The current state value;
|
|
10
|
+
* - setTrue `() => void` - A function to set the state to `true`;
|
|
11
|
+
* - setFalse `() => void` - A function to set the state to `false`;
|
|
12
|
+
* - toggle `() => void` - A function to toggle the state;
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* const [open, openBottomSheet, closeBottomSheet, toggleBottomSheet] = useBooleanState(false);
|
|
@@ -12,10 +12,10 @@ import { DependencyList } from 'react';
|
|
|
12
12
|
* @returns {(...args: any[]) => void} A memoized function that will only execute once until dependencies change.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
|
-
* import {
|
|
15
|
+
* import { useCallbackOncePerRender } from 'react-simplikit';
|
|
16
16
|
*
|
|
17
17
|
* function Component() {
|
|
18
|
-
* const handleOneTimeEvent =
|
|
18
|
+
* const handleOneTimeEvent = useCallbackOncePerRender(() => {
|
|
19
19
|
* console.log('This will only run once');
|
|
20
20
|
* }, []);
|
|
21
21
|
*
|
|
@@ -25,7 +25,7 @@ import { DependencyList } from 'react';
|
|
|
25
25
|
* @example
|
|
26
26
|
* // With dependencies
|
|
27
27
|
* function TrackingComponent({ userId }: { userId: string }) {
|
|
28
|
-
* const trackUserVisit =
|
|
28
|
+
* const trackUserVisit = useCallbackOncePerRender(() => {
|
|
29
29
|
* analytics.trackVisit(userId);
|
|
30
30
|
* }, [userId]);
|
|
31
31
|
*
|
|
@@ -36,6 +36,6 @@ import { DependencyList } from 'react';
|
|
|
36
36
|
* return <div>User page</div>;
|
|
37
37
|
* }
|
|
38
38
|
*/
|
|
39
|
-
declare function
|
|
39
|
+
declare function useCallbackOncePerRender<F extends (...args: any[]) => void>(callback: F, deps: DependencyList): (...args: Parameters<F>) => void;
|
|
40
40
|
|
|
41
|
-
export {
|
|
41
|
+
export { useCallbackOncePerRender };
|
|
@@ -17,14 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// src/hooks/
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
23
|
-
|
|
20
|
+
// src/hooks/useCallbackOncePerRender/index.ts
|
|
21
|
+
var useCallbackOncePerRender_exports = {};
|
|
22
|
+
__export(useCallbackOncePerRender_exports, {
|
|
23
|
+
useCallbackOncePerRender: () => useCallbackOncePerRender
|
|
24
24
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
25
|
+
module.exports = __toCommonJS(useCallbackOncePerRender_exports);
|
|
26
26
|
|
|
27
|
-
// src/hooks/
|
|
27
|
+
// src/hooks/useCallbackOncePerRender/useCallbackOncePerRender.ts
|
|
28
28
|
var import_react2 = require("react");
|
|
29
29
|
|
|
30
30
|
// src/hooks/usePreservedCallback/usePreservedCallback.ts
|
|
@@ -39,8 +39,8 @@ function usePreservedCallback(callback) {
|
|
|
39
39
|
}, []);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
// src/hooks/
|
|
43
|
-
function
|
|
42
|
+
// src/hooks/useCallbackOncePerRender/useCallbackOncePerRender.ts
|
|
43
|
+
function useCallbackOncePerRender(callback, deps) {
|
|
44
44
|
const hasFired = (0, import_react2.useRef)(false);
|
|
45
45
|
(0, import_react2.useEffect)(() => {
|
|
46
46
|
hasFired.current = false;
|
|
@@ -55,5 +55,5 @@ function useCallbackOnce(callback, deps) {
|
|
|
55
55
|
}
|
|
56
56
|
// Annotate the CommonJS export names for ESM import in node:
|
|
57
57
|
0 && (module.exports = {
|
|
58
|
-
|
|
58
|
+
useCallbackOncePerRender
|
|
59
59
|
});
|
|
@@ -12,9 +12,10 @@ type DebounceOptions = {
|
|
|
12
12
|
* `useDebounce` is a React hook that returns a debounced version of the provided callback function.
|
|
13
13
|
* It helps optimize event handling by delaying function execution and grouping multiple calls into one.
|
|
14
14
|
*
|
|
15
|
+
* @template {(...args: unknown[]) => unknown} F - The type of the callback function.
|
|
15
16
|
* @param {F} callback - The function to debounce.
|
|
16
17
|
* @param {number} wait - The number of milliseconds to delay the function execution.
|
|
17
|
-
* @param {
|
|
18
|
+
* @param {DebounceOptions} [options] - Configuration options for debounce behavior.
|
|
18
19
|
* @param {boolean} [options.leading=false] - If `true`, the function is called at the start of the sequence.
|
|
19
20
|
* @param {boolean} [options.trailing=true] - If `true`, the function is called at the end of the sequence.
|
|
20
21
|
*
|
|
@@ -10,14 +10,14 @@ type UseImpressionRefOptions = Partial<{
|
|
|
10
10
|
* `useImpressionRef` is a custom hook that measures the time a specific DOM element is visible on the screen and executes callbacks when the element enters or exits the viewport.
|
|
11
11
|
* This hook uses `IntersectionObserver` and the `Visibility API` to track the element's visibility.
|
|
12
12
|
*
|
|
13
|
-
* @param options -
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
13
|
+
* @param {UseImpressionRefOptions} options - Options for tracking the element's visibility.
|
|
14
|
+
* @param {() => void} options.onImpressionStart - Callback function executed when the element enters the view
|
|
15
|
+
* @param {() => void} options.onImpressionEnd - Callback function executed when the element exits the view
|
|
16
|
+
* @param {number} options.timeThreshold - Minimum time the element must be visible (in milliseconds)
|
|
17
|
+
* @param {number} options.areaThreshold - Minimum ratio of the element that must be visible (0 to 1)
|
|
18
|
+
* @param {string} options.rootMargin - Margin to adjust the detection area
|
|
19
19
|
*
|
|
20
|
-
* @returns A function to set the element. Attach this function to the `ref` attribute, and the callbacks will be executed whenever the element's visibility changes.
|
|
20
|
+
* @returns {(element: Element | null) => void} A function to set the element. Attach this function to the `ref` attribute, and the callbacks will be executed whenever the element's visibility changes.
|
|
21
21
|
*
|
|
22
22
|
* @example
|
|
23
23
|
* import { useImpressionRef } from 'react-simplikit';
|
|
@@ -4,13 +4,13 @@ import { ChangeEventHandler } from 'react';
|
|
|
4
4
|
* @description
|
|
5
5
|
* `useInputState` is a React hook that manages an input state with optional value transformation.
|
|
6
6
|
*
|
|
7
|
-
* @param {string} initialValue - The initial value of the input. Defaults to an empty string (`""`).
|
|
8
|
-
* @param {(value: string) => string} [transformValue] - A function to transform the input value.
|
|
7
|
+
* @param {string} [initialValue=""] - The initial value of the input. Defaults to an empty string (`""`).
|
|
8
|
+
* @param {(value: string) => string} [transformValue=(v: string) => v] - A function to transform the input value.
|
|
9
9
|
* Defaults to an identity function that returns the input unchanged.
|
|
10
10
|
*
|
|
11
|
-
* @returns {readonly [string, (value: string) => void]} A tuple containing:
|
|
12
|
-
* - `string` - The current state value
|
|
13
|
-
* - `(value: string) => void` - A function to update the state
|
|
11
|
+
* @returns {readonly [value: string, onChange: (value: string) => void]} A tuple containing:
|
|
12
|
+
* - value `string` - The current state value;
|
|
13
|
+
* - onChange `(value: string) => void` - A function to update the state;
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* import { useInputState } from 'react-simplikit';
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* `useIntersectionObserver` is a custom hook that detects whether a specific DOM element is visible on the screen.
|
|
4
4
|
* This hook uses the `IntersectionObserver` API to execute a callback when the element enters or exits the viewport.
|
|
5
5
|
*
|
|
6
|
-
* @param callback - A callback function that is executed when the visibility of the element changes.
|
|
7
|
-
*
|
|
8
|
-
* @param options - Options for the `IntersectionObserver`.
|
|
9
|
-
*
|
|
6
|
+
* @param {(entry: IntersectionObserverEntry) => void} callback - A callback function that is executed when the visibility of the element changes.
|
|
7
|
+
* You can check `entry.isIntersecting` to determine if the element is in view.
|
|
8
|
+
* @param {IntersectionObserverInit} options - Options for the `IntersectionObserver`.
|
|
9
|
+
* You can specify values such as `root`, `rootMargin`, and `threshold`.
|
|
10
10
|
*
|
|
11
|
-
* @returns A function to set the element. Attach this function to the `ref` attribute, and the `callback` will be executed whenever the element's visibility changes.
|
|
11
|
+
* @returns {(element: Element | null) => void} A function to set the element. Attach this function to the `ref` attribute, and the `callback` will be executed whenever the element's visibility changes.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* import { useIntersectionObserver } from 'react-simplikit';
|
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
* `useLoading` is a React hook that simplifies managing the loading state of a `Promise`.
|
|
4
4
|
* It provides a state to track whether an asynchronous operation is in progress and a function to handle the loading state automatically.
|
|
5
5
|
*
|
|
6
|
-
* @returns
|
|
6
|
+
* @returns {[loading: boolean, startLoading: <T>(promise: Promise<T>) => Promise<T>]} A tuple containing:
|
|
7
|
+
* - loading `boolean` - Represents the current loading state.
|
|
8
|
+
* : The initial value is `false`.
|
|
9
|
+
* : It is set to `true` when an asynchronous task is in progress;
|
|
7
10
|
*
|
|
8
|
-
* -
|
|
9
|
-
*
|
|
10
|
-
* - It is set to `true` when an asynchronous task is in progress.
|
|
11
|
-
*
|
|
12
|
-
* - `<T>(promise: Promise<T>) => Promise<T>`: A function that executes asynchronous tasks while managing the loading state.
|
|
13
|
-
* - This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes.
|
|
11
|
+
* - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state.
|
|
12
|
+
* : This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
|
|
14
13
|
*
|
|
15
14
|
* @example
|
|
16
15
|
* function ConfirmButton() {
|
|
@@ -6,10 +6,10 @@ type CleanupCallback = () => void;
|
|
|
6
6
|
* `useRefEffect` is a custom hook that helps you set a reference to a specific DOM element and execute a callback whenever the element changes.
|
|
7
7
|
* This hook calls a cleanup function whenever the element changes to prevent memory leaks.
|
|
8
8
|
*
|
|
9
|
-
* @param callback - A callback function that is executed when the element is set. This function can return a cleanup function.
|
|
10
|
-
* @param deps - An array of dependencies that define when the callback should be re-executed. The `callback` is re-executed whenever the `deps` change.
|
|
9
|
+
* @param {(element: Element) => CleanupCallback | void} callback - A callback function that is executed when the element is set. This function can return a cleanup function.
|
|
10
|
+
* @param {DependencyList} deps - An array of dependencies that define when the callback should be re-executed. The `callback` is re-executed whenever the `deps` change.
|
|
11
11
|
*
|
|
12
|
-
* @returns A function to set the element. Pass this function to the `ref` attribute, and the `callback` will be called whenever the element changes.
|
|
12
|
+
* @returns {(element: Element | null) => void} A function to set the element. Pass this function to the `ref` attribute, and the `callback` will be called whenever the element changes.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* import { useRefEffect } from 'react-simplikit';
|
|
@@ -27,9 +27,9 @@ type StorageStateOptionsWithDefaultValue<T> = StorageStateOptions<T> & {
|
|
|
27
27
|
* @param {Storage} [options.storage=localStorage] - The storage type (`localStorage` or `sessionStorage`). Defaults to `localStorage`.
|
|
28
28
|
* @param {T} [options.defaultValue] - The initial value if no existing value is found.
|
|
29
29
|
*
|
|
30
|
-
* @returns {[Serializable<T> | undefined, (value: SetStateAction<Serializable<T> | undefined>) => void]} A tuple:
|
|
31
|
-
* -
|
|
32
|
-
* -
|
|
30
|
+
* @returns {[state: Serializable<T> | undefined, setState: (value: SetStateAction<Serializable<T> | undefined>) => void]} A tuple:
|
|
31
|
+
* - state `Serializable<T> | undefined` - The current state value retrieved from storage;
|
|
32
|
+
* - setState `(value: SetStateAction<Serializable<T> | undefined>) => void` - A function to update and persist the state;
|
|
33
33
|
*
|
|
34
34
|
* @example
|
|
35
35
|
* // Counter with persistent state
|
|
@@ -7,9 +7,9 @@ import * as React from 'react';
|
|
|
7
7
|
*
|
|
8
8
|
* @param {boolean} [initialValue=false] - The initial state value. Defaults to `false`.
|
|
9
9
|
*
|
|
10
|
-
* @returns {[boolean, () => void]} A tuple:
|
|
11
|
-
* -
|
|
12
|
-
* -
|
|
10
|
+
* @returns {[state: boolean, toggle: () => void]} A tuple:
|
|
11
|
+
* - state `boolean` - The current state value;
|
|
12
|
+
* - toggle `() => void` - A function to toggle the state;
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* import { useToggle } from 'react-simplikit';
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { Separated } from './components/Separated/index.js';
|
|
|
3
3
|
export { SwitchCase } from './components/SwitchCase/index.js';
|
|
4
4
|
export { useAsyncEffect } from './hooks/useAsyncEffect/index.js';
|
|
5
5
|
export { useBooleanState } from './hooks/useBooleanState/index.js';
|
|
6
|
-
export {
|
|
6
|
+
export { useCallbackOncePerRender } from './hooks/useCallbackOncePerRender/index.js';
|
|
7
7
|
export { useDebounce } from './hooks/useDebounce/index.js';
|
|
8
8
|
export { useImpressionRef } from './hooks/useImpressionRef/index.js';
|
|
9
9
|
export { useInputState } from './hooks/useInputState/index.js';
|
package/dist/index.js
CHANGED
|
@@ -27,7 +27,7 @@ __export(index_exports, {
|
|
|
27
27
|
mergeRefs: () => mergeRefs,
|
|
28
28
|
useAsyncEffect: () => useAsyncEffect,
|
|
29
29
|
useBooleanState: () => useBooleanState,
|
|
30
|
-
|
|
30
|
+
useCallbackOncePerRender: () => useCallbackOncePerRender,
|
|
31
31
|
useDebounce: () => useDebounce,
|
|
32
32
|
useImpressionRef: () => useImpressionRef,
|
|
33
33
|
useInputState: () => useInputState,
|
|
@@ -297,7 +297,7 @@ function ImpressionArea({
|
|
|
297
297
|
// src/components/Separated/Separated.tsx
|
|
298
298
|
var import_react7 = require("react");
|
|
299
299
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
300
|
-
function Separated({ children,
|
|
300
|
+
function Separated({ children, by: separator }) {
|
|
301
301
|
const childrenArray = import_react7.Children.toArray(children).filter(import_react7.isValidElement);
|
|
302
302
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: childrenArray.map((child, i, { length }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react7.Fragment, { children: [
|
|
303
303
|
child,
|
|
@@ -341,9 +341,9 @@ var useBooleanState = (defaultValue = false) => {
|
|
|
341
341
|
return [bool, setTrue, setFalse, toggle2];
|
|
342
342
|
};
|
|
343
343
|
|
|
344
|
-
// src/hooks/
|
|
344
|
+
// src/hooks/useCallbackOncePerRender/useCallbackOncePerRender.ts
|
|
345
345
|
var import_react10 = require("react");
|
|
346
|
-
function
|
|
346
|
+
function useCallbackOncePerRender(callback, deps) {
|
|
347
347
|
const hasFired = (0, import_react10.useRef)(false);
|
|
348
348
|
(0, import_react10.useEffect)(() => {
|
|
349
349
|
hasFired.current = false;
|
|
@@ -741,7 +741,7 @@ function buildContext(contextName, defaultContextValues) {
|
|
|
741
741
|
mergeRefs,
|
|
742
742
|
useAsyncEffect,
|
|
743
743
|
useBooleanState,
|
|
744
|
-
|
|
744
|
+
useCallbackOncePerRender,
|
|
745
745
|
useDebounce,
|
|
746
746
|
useImpressionRef,
|
|
747
747
|
useInputState,
|
|
@@ -10,12 +10,12 @@ type ProviderProps<ContextValuesType> = (ContextValuesType & {
|
|
|
10
10
|
* @description
|
|
11
11
|
* `buildContext` is a helper function that reduces repetitive code when defining React Context.
|
|
12
12
|
*
|
|
13
|
-
* @param contextName - The name of the context.
|
|
14
|
-
* @param defaultContextValues - The default values to be passed to the context.
|
|
13
|
+
* @param {string} contextName - The name of the context.
|
|
14
|
+
* @param {ContextValuesType} [defaultContextValues] - The default values to be passed to the context.
|
|
15
15
|
*
|
|
16
|
-
* @returns A tuple of the form
|
|
17
|
-
* -
|
|
18
|
-
* -
|
|
16
|
+
* @returns {[Provider: (props: ProviderProps<ContextValuesType>) => JSX.Element, useContext: () => ContextValuesType]} A tuple of the form :
|
|
17
|
+
* - Provider `(props: ProviderProps<ContextValuesType>) => JSX.Element` - The component that provides the context;
|
|
18
|
+
* - useContext `() => ContextValuesType` - The hook that uses the context;
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
21
|
* const [Provider, useContext] = buildContext<{ title: string }>('TestContext', null);
|
|
@@ -5,9 +5,9 @@ import { RefObject, RefCallback } from 'react';
|
|
|
5
5
|
* This function takes multiple refs (RefObject or RefCallback) and returns a single ref that updates all provided refs.
|
|
6
6
|
* It's useful when you need to pass multiple refs to a single element.
|
|
7
7
|
*
|
|
8
|
-
* @param refs - An array of refs to be merged. Each ref can be either a RefObject or RefCallback.
|
|
8
|
+
* @param {Array<RefObject<T> | RefCallback<T> | null | undefined>} refs - An array of refs to be merged. Each ref can be either a RefObject or RefCallback.
|
|
9
9
|
*
|
|
10
|
-
* @returns A single ref callback that updates all provided refs.
|
|
10
|
+
* @returns {RefCallback<T>} A single ref callback that updates all provided refs.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* forwardRef(function Component(props, parentRef) {
|
|
@@ -14,22 +14,19 @@ type Props<Tag extends ElementType> = React__default.ComponentPropsWithoutRef<Ta
|
|
|
14
14
|
* and executes callbacks when the element enters or exits the viewport. This component uses the `useImpressionRef`
|
|
15
15
|
* hook to track the element's visibility.
|
|
16
16
|
*
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {
|
|
20
|
-
* @param {number} [
|
|
21
|
-
* @param {
|
|
22
|
-
* @param {() => void} [
|
|
23
|
-
* @param {
|
|
24
|
-
* @param {
|
|
25
|
-
* @param {
|
|
26
|
-
* @param {string} [props.className] - Additional class names for styling.
|
|
17
|
+
* @param {ElementType} [as='div'] - The HTML tag to render. Defaults to `div`.
|
|
18
|
+
* @param {string} [rootMargin] - Margin to adjust the detection area.
|
|
19
|
+
* @param {number} [areaThreshold] - Minimum ratio of the element that must be visible (0 to 1).
|
|
20
|
+
* @param {number} [timeThreshold] - Minimum time the element must be visible (in milliseconds).
|
|
21
|
+
* @param {() => void} [onImpressionStart] - Callback function executed when the element enters the view.
|
|
22
|
+
* @param {() => void} [onImpressionEnd] - Callback function executed when the element exits the view.
|
|
23
|
+
* @param {Ref<HTMLElement>} [ref] - Reference to the element.
|
|
24
|
+
* @param {React.ReactNode} [children] - Child elements to be rendered inside the component.
|
|
25
|
+
* @param {string} [className] - Additional class names for styling.
|
|
27
26
|
*
|
|
28
27
|
* @returns {JSX.Element} A React component that tracks the visibility of its child elements.
|
|
29
28
|
*
|
|
30
29
|
* @example
|
|
31
|
-
* import { ImpressionArea } from 'react-simplikit';
|
|
32
|
-
*
|
|
33
30
|
* function App() {
|
|
34
31
|
* return (
|
|
35
32
|
* <ImpressionArea
|
|
@@ -38,7 +35,7 @@ type Props<Tag extends ElementType> = React__default.ComponentPropsWithoutRef<Ta
|
|
|
38
35
|
* timeThreshold={1000}
|
|
39
36
|
* areaThreshold={0.5}
|
|
40
37
|
* >
|
|
41
|
-
* <div>Track
|
|
38
|
+
* <div>Track me!</div>
|
|
42
39
|
* </ImpressionArea>
|
|
43
40
|
* );
|
|
44
41
|
* }
|
|
@@ -2,7 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
type Props = {
|
|
5
|
-
|
|
5
|
+
by: ReactNode;
|
|
6
6
|
children: ReactNode;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
@@ -12,14 +12,14 @@ type Props = {
|
|
|
12
12
|
*
|
|
13
13
|
* @param {React.ReactNode} children - The child elements to render.
|
|
14
14
|
* Only valid React elements (`React.isValidElement`) will be rendered.
|
|
15
|
-
* @param {React.ReactNode}
|
|
15
|
+
* @param {React.ReactNode} by - The component to insert between child elements.
|
|
16
16
|
*
|
|
17
17
|
* @returns {JSX.Element} A React component that separates children with a specified separator.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* function App() {
|
|
21
21
|
* return (
|
|
22
|
-
* <Separated
|
|
22
|
+
* <Separated by={<Border type="padding24" />}>
|
|
23
23
|
* {['hello', 'react', 'world'].map(item => (
|
|
24
24
|
* <div key={item}>{item}</div>
|
|
25
25
|
* ))}
|
|
@@ -33,6 +33,6 @@ type Props = {
|
|
|
33
33
|
* // <div>world</div>
|
|
34
34
|
* }
|
|
35
35
|
*/
|
|
36
|
-
declare function Separated({ children,
|
|
36
|
+
declare function Separated({ children, by: separator }: Props): react_jsx_runtime.JSX.Element;
|
|
37
37
|
|
|
38
38
|
export { Separated };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/components/Separated/Separated.tsx
|
|
2
2
|
import { Children, Fragment, isValidElement } from "react";
|
|
3
3
|
import { Fragment as Fragment2, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
-
function Separated({ children,
|
|
4
|
+
function Separated({ children, by: separator }) {
|
|
5
5
|
const childrenArray = Children.toArray(children).filter(isValidElement);
|
|
6
6
|
return /* @__PURE__ */ jsx(Fragment2, { children: childrenArray.map((child, i, { length }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
7
7
|
child,
|
|
@@ -16,9 +16,9 @@ import { DependencyList } from 'react';
|
|
|
16
16
|
* setData(data);
|
|
17
17
|
*
|
|
18
18
|
* return () => {
|
|
19
|
-
* console.log('Cleanup on unmount or
|
|
19
|
+
* console.log('Cleanup on unmount or dependencies change');
|
|
20
20
|
* };
|
|
21
|
-
* }, [
|
|
21
|
+
* }, [dependencies]);
|
|
22
22
|
*/
|
|
23
23
|
declare function useAsyncEffect(effect: () => Promise<void | (() => void)>, deps?: DependencyList): void;
|
|
24
24
|
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @param {boolean} [defaultValue=false] - The initial value of the state. Defaults to `false`.
|
|
7
7
|
*
|
|
8
|
-
* @returns {readonly [boolean, () => void, () => void, () => void]} A tuple containing:
|
|
9
|
-
* - `boolean` - The current state value
|
|
10
|
-
* - `() => void` - A function to set the state to `true
|
|
11
|
-
* - `() => void` - A function to set the state to `false
|
|
12
|
-
* - `() => void` - A function to toggle the state
|
|
8
|
+
* @returns {readonly [state: boolean, setTrue: () => void, setFalse: () => void, toggle: () => void]} A tuple containing:
|
|
9
|
+
* - state `boolean` - The current state value;
|
|
10
|
+
* - setTrue `() => void` - A function to set the state to `true`;
|
|
11
|
+
* - setFalse `() => void` - A function to set the state to `false`;
|
|
12
|
+
* - toggle `() => void` - A function to toggle the state;
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* const [open, openBottomSheet, closeBottomSheet, toggleBottomSheet] = useBooleanState(false);
|
|
@@ -12,10 +12,10 @@ import { DependencyList } from 'react';
|
|
|
12
12
|
* @returns {(...args: any[]) => void} A memoized function that will only execute once until dependencies change.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
|
-
* import {
|
|
15
|
+
* import { useCallbackOncePerRender } from 'react-simplikit';
|
|
16
16
|
*
|
|
17
17
|
* function Component() {
|
|
18
|
-
* const handleOneTimeEvent =
|
|
18
|
+
* const handleOneTimeEvent = useCallbackOncePerRender(() => {
|
|
19
19
|
* console.log('This will only run once');
|
|
20
20
|
* }, []);
|
|
21
21
|
*
|
|
@@ -25,7 +25,7 @@ import { DependencyList } from 'react';
|
|
|
25
25
|
* @example
|
|
26
26
|
* // With dependencies
|
|
27
27
|
* function TrackingComponent({ userId }: { userId: string }) {
|
|
28
|
-
* const trackUserVisit =
|
|
28
|
+
* const trackUserVisit = useCallbackOncePerRender(() => {
|
|
29
29
|
* analytics.trackVisit(userId);
|
|
30
30
|
* }, [userId]);
|
|
31
31
|
*
|
|
@@ -36,6 +36,6 @@ import { DependencyList } from 'react';
|
|
|
36
36
|
* return <div>User page</div>;
|
|
37
37
|
* }
|
|
38
38
|
*/
|
|
39
|
-
declare function
|
|
39
|
+
declare function useCallbackOncePerRender<F extends (...args: any[]) => void>(callback: F, deps: DependencyList): (...args: Parameters<F>) => void;
|
|
40
40
|
|
|
41
|
-
export {
|
|
41
|
+
export { useCallbackOncePerRender };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/hooks/
|
|
1
|
+
// src/hooks/useCallbackOncePerRender/useCallbackOncePerRender.ts
|
|
2
2
|
import { useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
3
3
|
|
|
4
4
|
// src/hooks/usePreservedCallback/usePreservedCallback.ts
|
|
@@ -13,8 +13,8 @@ function usePreservedCallback(callback) {
|
|
|
13
13
|
}, []);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
// src/hooks/
|
|
17
|
-
function
|
|
16
|
+
// src/hooks/useCallbackOncePerRender/useCallbackOncePerRender.ts
|
|
17
|
+
function useCallbackOncePerRender(callback, deps) {
|
|
18
18
|
const hasFired = useRef2(false);
|
|
19
19
|
useEffect2(() => {
|
|
20
20
|
hasFired.current = false;
|
|
@@ -28,5 +28,5 @@ function useCallbackOnce(callback, deps) {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
export {
|
|
31
|
-
|
|
31
|
+
useCallbackOncePerRender
|
|
32
32
|
};
|
|
@@ -12,9 +12,10 @@ type DebounceOptions = {
|
|
|
12
12
|
* `useDebounce` is a React hook that returns a debounced version of the provided callback function.
|
|
13
13
|
* It helps optimize event handling by delaying function execution and grouping multiple calls into one.
|
|
14
14
|
*
|
|
15
|
+
* @template {(...args: unknown[]) => unknown} F - The type of the callback function.
|
|
15
16
|
* @param {F} callback - The function to debounce.
|
|
16
17
|
* @param {number} wait - The number of milliseconds to delay the function execution.
|
|
17
|
-
* @param {
|
|
18
|
+
* @param {DebounceOptions} [options] - Configuration options for debounce behavior.
|
|
18
19
|
* @param {boolean} [options.leading=false] - If `true`, the function is called at the start of the sequence.
|
|
19
20
|
* @param {boolean} [options.trailing=true] - If `true`, the function is called at the end of the sequence.
|
|
20
21
|
*
|
|
@@ -10,14 +10,14 @@ type UseImpressionRefOptions = Partial<{
|
|
|
10
10
|
* `useImpressionRef` is a custom hook that measures the time a specific DOM element is visible on the screen and executes callbacks when the element enters or exits the viewport.
|
|
11
11
|
* This hook uses `IntersectionObserver` and the `Visibility API` to track the element's visibility.
|
|
12
12
|
*
|
|
13
|
-
* @param options -
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
13
|
+
* @param {UseImpressionRefOptions} options - Options for tracking the element's visibility.
|
|
14
|
+
* @param {() => void} options.onImpressionStart - Callback function executed when the element enters the view
|
|
15
|
+
* @param {() => void} options.onImpressionEnd - Callback function executed when the element exits the view
|
|
16
|
+
* @param {number} options.timeThreshold - Minimum time the element must be visible (in milliseconds)
|
|
17
|
+
* @param {number} options.areaThreshold - Minimum ratio of the element that must be visible (0 to 1)
|
|
18
|
+
* @param {string} options.rootMargin - Margin to adjust the detection area
|
|
19
19
|
*
|
|
20
|
-
* @returns A function to set the element. Attach this function to the `ref` attribute, and the callbacks will be executed whenever the element's visibility changes.
|
|
20
|
+
* @returns {(element: Element | null) => void} A function to set the element. Attach this function to the `ref` attribute, and the callbacks will be executed whenever the element's visibility changes.
|
|
21
21
|
*
|
|
22
22
|
* @example
|
|
23
23
|
* import { useImpressionRef } from 'react-simplikit';
|
|
@@ -4,13 +4,13 @@ import { ChangeEventHandler } from 'react';
|
|
|
4
4
|
* @description
|
|
5
5
|
* `useInputState` is a React hook that manages an input state with optional value transformation.
|
|
6
6
|
*
|
|
7
|
-
* @param {string} initialValue - The initial value of the input. Defaults to an empty string (`""`).
|
|
8
|
-
* @param {(value: string) => string} [transformValue] - A function to transform the input value.
|
|
7
|
+
* @param {string} [initialValue=""] - The initial value of the input. Defaults to an empty string (`""`).
|
|
8
|
+
* @param {(value: string) => string} [transformValue=(v: string) => v] - A function to transform the input value.
|
|
9
9
|
* Defaults to an identity function that returns the input unchanged.
|
|
10
10
|
*
|
|
11
|
-
* @returns {readonly [string, (value: string) => void]} A tuple containing:
|
|
12
|
-
* - `string` - The current state value
|
|
13
|
-
* - `(value: string) => void` - A function to update the state
|
|
11
|
+
* @returns {readonly [value: string, onChange: (value: string) => void]} A tuple containing:
|
|
12
|
+
* - value `string` - The current state value;
|
|
13
|
+
* - onChange `(value: string) => void` - A function to update the state;
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* import { useInputState } from 'react-simplikit';
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* `useIntersectionObserver` is a custom hook that detects whether a specific DOM element is visible on the screen.
|
|
4
4
|
* This hook uses the `IntersectionObserver` API to execute a callback when the element enters or exits the viewport.
|
|
5
5
|
*
|
|
6
|
-
* @param callback - A callback function that is executed when the visibility of the element changes.
|
|
7
|
-
*
|
|
8
|
-
* @param options - Options for the `IntersectionObserver`.
|
|
9
|
-
*
|
|
6
|
+
* @param {(entry: IntersectionObserverEntry) => void} callback - A callback function that is executed when the visibility of the element changes.
|
|
7
|
+
* You can check `entry.isIntersecting` to determine if the element is in view.
|
|
8
|
+
* @param {IntersectionObserverInit} options - Options for the `IntersectionObserver`.
|
|
9
|
+
* You can specify values such as `root`, `rootMargin`, and `threshold`.
|
|
10
10
|
*
|
|
11
|
-
* @returns A function to set the element. Attach this function to the `ref` attribute, and the `callback` will be executed whenever the element's visibility changes.
|
|
11
|
+
* @returns {(element: Element | null) => void} A function to set the element. Attach this function to the `ref` attribute, and the `callback` will be executed whenever the element's visibility changes.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* import { useIntersectionObserver } from 'react-simplikit';
|
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
* `useLoading` is a React hook that simplifies managing the loading state of a `Promise`.
|
|
4
4
|
* It provides a state to track whether an asynchronous operation is in progress and a function to handle the loading state automatically.
|
|
5
5
|
*
|
|
6
|
-
* @returns
|
|
6
|
+
* @returns {[loading: boolean, startLoading: <T>(promise: Promise<T>) => Promise<T>]} A tuple containing:
|
|
7
|
+
* - loading `boolean` - Represents the current loading state.
|
|
8
|
+
* : The initial value is `false`.
|
|
9
|
+
* : It is set to `true` when an asynchronous task is in progress;
|
|
7
10
|
*
|
|
8
|
-
* -
|
|
9
|
-
*
|
|
10
|
-
* - It is set to `true` when an asynchronous task is in progress.
|
|
11
|
-
*
|
|
12
|
-
* - `<T>(promise: Promise<T>) => Promise<T>`: A function that executes asynchronous tasks while managing the loading state.
|
|
13
|
-
* - This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes.
|
|
11
|
+
* - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state.
|
|
12
|
+
* : This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
|
|
14
13
|
*
|
|
15
14
|
* @example
|
|
16
15
|
* function ConfirmButton() {
|
|
@@ -6,10 +6,10 @@ type CleanupCallback = () => void;
|
|
|
6
6
|
* `useRefEffect` is a custom hook that helps you set a reference to a specific DOM element and execute a callback whenever the element changes.
|
|
7
7
|
* This hook calls a cleanup function whenever the element changes to prevent memory leaks.
|
|
8
8
|
*
|
|
9
|
-
* @param callback - A callback function that is executed when the element is set. This function can return a cleanup function.
|
|
10
|
-
* @param deps - An array of dependencies that define when the callback should be re-executed. The `callback` is re-executed whenever the `deps` change.
|
|
9
|
+
* @param {(element: Element) => CleanupCallback | void} callback - A callback function that is executed when the element is set. This function can return a cleanup function.
|
|
10
|
+
* @param {DependencyList} deps - An array of dependencies that define when the callback should be re-executed. The `callback` is re-executed whenever the `deps` change.
|
|
11
11
|
*
|
|
12
|
-
* @returns A function to set the element. Pass this function to the `ref` attribute, and the `callback` will be called whenever the element changes.
|
|
12
|
+
* @returns {(element: Element | null) => void} A function to set the element. Pass this function to the `ref` attribute, and the `callback` will be called whenever the element changes.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* import { useRefEffect } from 'react-simplikit';
|
|
@@ -27,9 +27,9 @@ type StorageStateOptionsWithDefaultValue<T> = StorageStateOptions<T> & {
|
|
|
27
27
|
* @param {Storage} [options.storage=localStorage] - The storage type (`localStorage` or `sessionStorage`). Defaults to `localStorage`.
|
|
28
28
|
* @param {T} [options.defaultValue] - The initial value if no existing value is found.
|
|
29
29
|
*
|
|
30
|
-
* @returns {[Serializable<T> | undefined, (value: SetStateAction<Serializable<T> | undefined>) => void]} A tuple:
|
|
31
|
-
* -
|
|
32
|
-
* -
|
|
30
|
+
* @returns {[state: Serializable<T> | undefined, setState: (value: SetStateAction<Serializable<T> | undefined>) => void]} A tuple:
|
|
31
|
+
* - state `Serializable<T> | undefined` - The current state value retrieved from storage;
|
|
32
|
+
* - setState `(value: SetStateAction<Serializable<T> | undefined>) => void` - A function to update and persist the state;
|
|
33
33
|
*
|
|
34
34
|
* @example
|
|
35
35
|
* // Counter with persistent state
|
|
@@ -7,9 +7,9 @@ import * as React from 'react';
|
|
|
7
7
|
*
|
|
8
8
|
* @param {boolean} [initialValue=false] - The initial state value. Defaults to `false`.
|
|
9
9
|
*
|
|
10
|
-
* @returns {[boolean, () => void]} A tuple:
|
|
11
|
-
* -
|
|
12
|
-
* -
|
|
10
|
+
* @returns {[state: boolean, toggle: () => void]} A tuple:
|
|
11
|
+
* - state `boolean` - The current state value;
|
|
12
|
+
* - toggle `() => void` - A function to toggle the state;
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* import { useToggle } from 'react-simplikit';
|
package/esm/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ export { Separated } from './components/Separated/index.mjs';
|
|
|
3
3
|
export { SwitchCase } from './components/SwitchCase/index.mjs';
|
|
4
4
|
export { useAsyncEffect } from './hooks/useAsyncEffect/index.mjs';
|
|
5
5
|
export { useBooleanState } from './hooks/useBooleanState/index.mjs';
|
|
6
|
-
export {
|
|
6
|
+
export { useCallbackOncePerRender } from './hooks/useCallbackOncePerRender/index.mjs';
|
|
7
7
|
export { useDebounce } from './hooks/useDebounce/index.mjs';
|
|
8
8
|
export { useImpressionRef } from './hooks/useImpressionRef/index.mjs';
|
|
9
9
|
export { useInputState } from './hooks/useInputState/index.mjs';
|
package/esm/index.mjs
CHANGED
|
@@ -248,7 +248,7 @@ function ImpressionArea({
|
|
|
248
248
|
// src/components/Separated/Separated.tsx
|
|
249
249
|
import { Children, Fragment, isValidElement } from "react";
|
|
250
250
|
import { Fragment as Fragment2, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
251
|
-
function Separated({ children,
|
|
251
|
+
function Separated({ children, by: separator }) {
|
|
252
252
|
const childrenArray = Children.toArray(children).filter(isValidElement);
|
|
253
253
|
return /* @__PURE__ */ jsx2(Fragment2, { children: childrenArray.map((child, i, { length }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
254
254
|
child,
|
|
@@ -292,9 +292,9 @@ var useBooleanState = (defaultValue = false) => {
|
|
|
292
292
|
return [bool, setTrue, setFalse, toggle2];
|
|
293
293
|
};
|
|
294
294
|
|
|
295
|
-
// src/hooks/
|
|
295
|
+
// src/hooks/useCallbackOncePerRender/useCallbackOncePerRender.ts
|
|
296
296
|
import { useEffect as useEffect5, useRef as useRef5 } from "react";
|
|
297
|
-
function
|
|
297
|
+
function useCallbackOncePerRender(callback, deps) {
|
|
298
298
|
const hasFired = useRef5(false);
|
|
299
299
|
useEffect5(() => {
|
|
300
300
|
hasFired.current = false;
|
|
@@ -691,7 +691,7 @@ export {
|
|
|
691
691
|
mergeRefs,
|
|
692
692
|
useAsyncEffect,
|
|
693
693
|
useBooleanState,
|
|
694
|
-
|
|
694
|
+
useCallbackOncePerRender,
|
|
695
695
|
useDebounce,
|
|
696
696
|
useImpressionRef,
|
|
697
697
|
useInputState,
|
|
@@ -10,12 +10,12 @@ type ProviderProps<ContextValuesType> = (ContextValuesType & {
|
|
|
10
10
|
* @description
|
|
11
11
|
* `buildContext` is a helper function that reduces repetitive code when defining React Context.
|
|
12
12
|
*
|
|
13
|
-
* @param contextName - The name of the context.
|
|
14
|
-
* @param defaultContextValues - The default values to be passed to the context.
|
|
13
|
+
* @param {string} contextName - The name of the context.
|
|
14
|
+
* @param {ContextValuesType} [defaultContextValues] - The default values to be passed to the context.
|
|
15
15
|
*
|
|
16
|
-
* @returns A tuple of the form
|
|
17
|
-
* -
|
|
18
|
-
* -
|
|
16
|
+
* @returns {[Provider: (props: ProviderProps<ContextValuesType>) => JSX.Element, useContext: () => ContextValuesType]} A tuple of the form :
|
|
17
|
+
* - Provider `(props: ProviderProps<ContextValuesType>) => JSX.Element` - The component that provides the context;
|
|
18
|
+
* - useContext `() => ContextValuesType` - The hook that uses the context;
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
21
|
* const [Provider, useContext] = buildContext<{ title: string }>('TestContext', null);
|
|
@@ -5,9 +5,9 @@ import { RefObject, RefCallback } from 'react';
|
|
|
5
5
|
* This function takes multiple refs (RefObject or RefCallback) and returns a single ref that updates all provided refs.
|
|
6
6
|
* It's useful when you need to pass multiple refs to a single element.
|
|
7
7
|
*
|
|
8
|
-
* @param refs - An array of refs to be merged. Each ref can be either a RefObject or RefCallback.
|
|
8
|
+
* @param {Array<RefObject<T> | RefCallback<T> | null | undefined>} refs - An array of refs to be merged. Each ref can be either a RefObject or RefCallback.
|
|
9
9
|
*
|
|
10
|
-
* @returns A single ref callback that updates all provided refs.
|
|
10
|
+
* @returns {RefCallback<T>} A single ref callback that updates all provided refs.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* forwardRef(function Component(props, parentRef) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-simplikit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"files": [
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"esm/**/*"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
+
"docs:gen": "tsx .scripts/index.ts generate-docs",
|
|
11
12
|
"docs:dev": "vitepress dev",
|
|
12
13
|
"docs:build": "vitepress build",
|
|
13
14
|
"docs:preview": "vitepress preview",
|
|
@@ -34,6 +35,7 @@
|
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@eslint/js": "^9.16.0",
|
|
38
|
+
"@openai/openai": "npm:@jsr/openai__openai@^4.93.0",
|
|
37
39
|
"@testing-library/dom": "^10.4.0",
|
|
38
40
|
"@testing-library/jest-dom": "^6.6.3",
|
|
39
41
|
"@testing-library/react": "^16.1.0",
|
|
@@ -41,7 +43,10 @@
|
|
|
41
43
|
"@types/node": "^22.10.2",
|
|
42
44
|
"@types/react": "^19.0.7",
|
|
43
45
|
"@vitest/coverage-v8": "^2.1.8",
|
|
46
|
+
"commander": "^13.1.0",
|
|
47
|
+
"comment-parser": "^1.4.1",
|
|
44
48
|
"corepack": "^0.30.0",
|
|
49
|
+
"dotenv": "^16.4.7",
|
|
45
50
|
"esbuild": "^0.24.0",
|
|
46
51
|
"eslint": "^9.16.0",
|
|
47
52
|
"eslint-config-prettier": "^9.1.0",
|
|
@@ -54,11 +59,14 @@
|
|
|
54
59
|
"fast-glob": "^3.3.3",
|
|
55
60
|
"globals": "^15.13.0",
|
|
56
61
|
"jsdom": "^25.0.1",
|
|
62
|
+
"listr2": "^8.2.5",
|
|
63
|
+
"ora": "^8.2.0",
|
|
57
64
|
"prettier": "^3.4.2",
|
|
58
65
|
"prettier-plugin-sort-re-exports": "^0.1.0",
|
|
59
66
|
"react": "^19.0.0",
|
|
60
67
|
"react-dom": "^19.0.0",
|
|
61
68
|
"tsup": "^8.3.5",
|
|
69
|
+
"tsx": "^4.19.2",
|
|
62
70
|
"typescript": "^5.7.2",
|
|
63
71
|
"typescript-eslint": "^8.18.0",
|
|
64
72
|
"vitepress": "^1.5.0",
|