react-simplikit 0.0.4 → 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 +9 -10
- package/dist/components/Separated/index.d.ts +4 -4
- package/dist/components/Separated/index.js +1 -1
- package/dist/hooks/useBooleanState/index.d.ts +4 -4
- package/dist/hooks/useImpressionRef/index.d.ts +7 -7
- package/dist/hooks/useInputState/index.d.ts +2 -2
- 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.js +1 -1
- 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 +9 -10
- package/esm/components/Separated/index.d.mts +4 -4
- package/esm/components/Separated/index.mjs +1 -1
- package/esm/hooks/useBooleanState/index.d.mts +4 -4
- package/esm/hooks/useImpressionRef/index.d.mts +7 -7
- package/esm/hooks/useInputState/index.d.mts +2 -2
- 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.mjs +1 -1
- package/esm/utils/buildContext/index.d.mts +5 -5
- package/esm/utils/mergeRefs/index.d.mts +2 -2
- package/package.json +1 -1
|
@@ -14,16 +14,15 @@ 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
|
*
|
|
@@ -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,
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* @param {boolean} [defaultValue=false] - The initial value of the state. Defaults to `false`.
|
|
7
7
|
*
|
|
8
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
|
|
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);
|
|
@@ -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';
|
|
@@ -9,8 +9,8 @@ import { ChangeEventHandler } from 'react';
|
|
|
9
9
|
* Defaults to an identity function that returns the input unchanged.
|
|
10
10
|
*
|
|
11
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
|
|
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.js
CHANGED
|
@@ -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,
|
|
@@ -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,16 +14,15 @@ 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
|
*
|
|
@@ -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,
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* @param {boolean} [defaultValue=false] - The initial value of the state. Defaults to `false`.
|
|
7
7
|
*
|
|
8
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
|
|
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);
|
|
@@ -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';
|
|
@@ -9,8 +9,8 @@ import { ChangeEventHandler } from 'react';
|
|
|
9
9
|
* Defaults to an identity function that returns the input unchanged.
|
|
10
10
|
*
|
|
11
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
|
|
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.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,
|
|
@@ -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) {
|