@siberiacancode/reactuse 0.0.114 → 0.0.115

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.
@@ -0,0 +1,38 @@
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): {
11
+ ref: StateRef<Target>;
12
+ clicked: boolean;
13
+ };
14
+ }
15
+ /**
16
+ * @name useDoubleClick
17
+ * @description - Hook that defines the logic when double clicking an element
18
+ * @category Sensors
19
+ *
20
+ * @overload
21
+ * @param {HookTarget} target The target element to be double clicked
22
+ * @param {(event: DoubleClickEvents) => void} callback The callback function to be invoked on double click
23
+ * @param {UseDoubleClickOptions} [options] The options for the double click
24
+ * @returns {boolean} The double clicking state
25
+ *
26
+ * @example
27
+ * useDoubleClick(ref, () => console.log('double clicked'));
28
+ *
29
+ * @overload
30
+ * @template Target The target element
31
+ * @param {(event: DoubleClickEvents) => void} callback The callback function to be invoked on double click
32
+ * @param {UseDoubleClickOptions} [options] The options for the double click
33
+ * @returns {boolean} The double clicking state
34
+ *
35
+ * @example
36
+ * const ref = useDoubleClick(() => console.log('double clicked'));
37
+ */
38
+ 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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siberiacancode/reactuse",
3
- "version": "0.0.114",
3
+ "version": "0.0.115",
4
4
  "description": "The ultimate collection of react hooks",
5
5
  "author": {
6
6
  "name": "SIBERIA CAN CODE 🧊",