@siberiacancode/reactuse 0.0.114 → 0.0.116

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.
Files changed (30) hide show
  1. package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
  2. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
  3. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs +2 -0
  4. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -0
  5. package/dist/cjs/hooks/useLongPress/useLongPress.cjs +1 -1
  6. package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
  7. package/dist/cjs/hooks/useMouse/useMouse.cjs.map +1 -1
  8. package/dist/cjs/hooks/useParallax/useParallax.cjs +1 -1
  9. package/dist/cjs/hooks/useParallax/useParallax.cjs.map +1 -1
  10. package/dist/cjs/hooks/useWindowFocus/useWindowFocus.cjs.map +1 -1
  11. package/dist/cjs/index.cjs +1 -1
  12. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
  13. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
  14. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs +29 -0
  15. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -0
  16. package/dist/esm/hooks/useLongPress/useLongPress.mjs +30 -17
  17. package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
  18. package/dist/esm/hooks/useMouse/useMouse.mjs.map +1 -1
  19. package/dist/esm/hooks/useParallax/useParallax.mjs +90 -85
  20. package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
  21. package/dist/esm/hooks/useWindowFocus/useWindowFocus.mjs.map +1 -1
  22. package/dist/esm/index.mjs +253 -251
  23. package/dist/esm/index.mjs.map +1 -1
  24. package/dist/types/hooks/index.d.ts +1 -0
  25. package/dist/types/hooks/useActiveElement/useActiveElement.d.ts +2 -0
  26. package/dist/types/hooks/useClickOutside/useClickOutside.d.ts +1 -1
  27. package/dist/types/hooks/useDoubleClick/useDoubleClick.d.ts +37 -0
  28. package/dist/types/hooks/useLongPress/useLongPress.d.ts +27 -25
  29. package/dist/types/hooks/useWindowFocus/useWindowFocus.d.ts +2 -0
  30. package/package.json +1 -1
@@ -0,0 +1,37 @@
1
+ import { HookTarget } from '../../utils/helpers';
2
+ import { StateRef } from '../useRefState/useRefState';
3
+ export type DoubleClickEvents = MouseEvent | TouchEvent;
4
+ export interface UseDoubleClickOptions {
5
+ threshold?: number;
6
+ onSingleClick?: (event: DoubleClickEvents) => void;
7
+ }
8
+ export interface UseDoubleClick {
9
+ (target: HookTarget, callback: (event: DoubleClickEvents) => void, options?: UseDoubleClickOptions): boolean;
10
+ <Target extends Element>(callback: (event: DoubleClickEvents) => void, options?: UseDoubleClickOptions, target?: never): StateRef<Target>;
11
+ }
12
+ /**
13
+ * @name useDoubleClick
14
+ * @description - Hook that defines the logic when double clicking an element
15
+ * @category Sensors
16
+ *
17
+ * @overload
18
+ * @param {HookTarget} target The target element to be double clicked
19
+ * @param {(event: DoubleClickEvents) => void} callback The callback function to be invoked on double click
20
+ * @param {UseDoubleClickOptions} [options] The options for the double click
21
+ * @returns {boolean} The double clicking state
22
+ *
23
+ * @example
24
+ * useDoubleClick(ref, () => console.log('double clicked'));
25
+ *
26
+ * @overload
27
+ * @template Target The target element
28
+ * @param {(event: DoubleClickEvents) => void} callback The callback function to be invoked on double click
29
+ * @param {UseDoubleClickOptions} [options] The options for the double click
30
+ * @returns {boolean} The double clicking state
31
+ *
32
+ * @example
33
+ * const ref = useDoubleClick(() => console.log('double clicked'));
34
+ *
35
+ * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useDoubleClick.html}
36
+ */
37
+ export declare const useDoubleClick: UseDoubleClick;
@@ -1,38 +1,40 @@
1
- import { MouseEventHandler, RefObject, TouchEventHandler } from 'react';
2
- export type UseLongPressTarget = (() => Element) | Element | RefObject<Element | null | undefined>;
3
- export type LongPressReactEvents<Target extends Element = Element> = MouseEventHandler<Target> | TouchEventHandler<Target>;
1
+ import { HookTarget } from '../../utils/helpers';
2
+ import { StateRef } from '../useRefState/useRefState';
3
+ export type LongPressEvents = MouseEvent | TouchEvent;
4
4
  export interface UseLongPressOptions {
5
5
  threshold?: number;
6
- onCancel?: (event: LongPressReactEvents) => void;
7
- onFinish?: (event: LongPressReactEvents) => void;
8
- onStart?: (event: LongPressReactEvents) => void;
6
+ onCancel?: (event: LongPressEvents) => void;
7
+ onFinish?: (event: LongPressEvents) => void;
8
+ onStart?: (event: LongPressEvents) => void;
9
9
  }
10
- export interface UseLongPressBind {
11
- /** The callback function to be invoked on mouse down */
12
- onMouseDown: MouseEventHandler<Element>;
13
- /** The callback function to be invoked on mouse up */
14
- onMouseUp: MouseEventHandler<Element>;
15
- /** The callback function to be invoked on touch end */
16
- onTouchEnd: TouchEventHandler<Element>;
17
- /** The callback function to be invoked on touch start */
18
- onTouchStart: TouchEventHandler<Element>;
10
+ export interface UseLongPress {
11
+ (target: HookTarget, callback: (event: LongPressEvents) => void, options?: UseLongPressOptions): boolean;
12
+ <Target extends Element>(callback: (event: LongPressEvents) => void, options?: UseLongPressOptions, target?: never): {
13
+ ref: StateRef<Target>;
14
+ pressed: boolean;
15
+ };
19
16
  }
20
- export type UseLongPressReturn = [UseLongPressBind, boolean];
21
17
  /**
22
18
  * @name useLongPress
23
19
  * @description - Hook that defines the logic when long pressing an element
24
20
  * @category Sensors
25
21
  *
22
+ * @overload
23
+ * @param {HookTarget} target The target element to be long pressed
24
+ * @param {(event: LongPressEvents) => void} callback The callback function to be invoked on long press
25
+ * @param {UseLongPressOptions} [options] The options for the long press
26
+ * @returns {boolean} The long pressing state
27
+ *
28
+ * @example
29
+ * const pressed = useLongPress(ref, () => console.log('callback'));
30
+ *
31
+ * @overload
26
32
  * @template Target The target element
27
- * @param {Target} target The target element to be long pressed
28
- * @param {(event: Event) => void} callback The callback function to be invoked on long press
29
- * @param {number} [options.threshold=400] The threshold time in milliseconds
30
- * @param {(event: Event) => void} [options.onStart] The callback function to be invoked on long press start
31
- * @param {(event: Event) => void} [options.onFinish] The callback function to be invoked on long press finish
32
- * @param {(event: Event) => void} [options.onCancel] The callback function to be invoked on long press cancel
33
- * @returns {UseLongPressReturn<Target>} The ref of the target element
33
+ * @param {(event: LongPressEvents) => void} callback The callback function to be invoked on long press
34
+ * @param {UseLongPressOptions} [options] The options for the long press
35
+ * @returns {boolean} The long pressing state
34
36
  *
35
37
  * @example
36
- * const [bind, longPressing] = useLongPress(() => console.log('callback'));
38
+ * const { ref, pressed } = useLongPress(() => console.log('callback'));
37
39
  */
38
- export declare const useLongPress: (callback: (event: LongPressReactEvents) => void, options?: UseLongPressOptions) => UseLongPressReturn;
40
+ export declare const useLongPress: UseLongPress;
@@ -7,5 +7,7 @@
7
7
  *
8
8
  * @example
9
9
  * const focused = useWindowFocus();
10
+ *
11
+ * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useWindowFocus.html}
10
12
  */
11
13
  export declare const useWindowFocus: () => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siberiacancode/reactuse",
3
- "version": "0.0.114",
3
+ "version": "0.0.116",
4
4
  "description": "The ultimate collection of react hooks",
5
5
  "author": {
6
6
  "name": "SIBERIA CAN CODE 🧊",