@atomico/use-drag-resize
Advanced tools
Comparing version 1.0.1-beta to 1.0.2-beta
import { Ref } from "atomico"; | ||
export declare function useDragResize(ref: Ref, rootState?: number[]): [boolean, number, number]; | ||
export declare function useDragResize(ref: Ref, refParent: Ref, rootState?: number[]): [boolean, number, number]; |
@@ -1,6 +0,5 @@ | ||
import { useState, useHost, useEffect } from "atomico"; | ||
import { useDebounceState } from "@atomico/use-debounce-state"; | ||
import { useListener } from "@atomico/use-listener"; | ||
import { useDebounceState } from "@atomico/use-debounce-state"; | ||
export function useDragResize(ref, rootState = [1, 1]) { | ||
const host = useHost(); | ||
import { useEffect, useState } from "atomico"; | ||
export function useDragResize(ref, refParent, rootState = [1, 1]) { | ||
const [active, setActive] = useState(false); | ||
@@ -12,12 +11,12 @@ const [[x, y], setValue] = useDebounceState(1, rootState, "fps"); | ||
useListener(ref, "mousedown", start); | ||
useListener(host, "mouseup", end); | ||
useListener(host, "mouseleave", end); | ||
useListener(refParent, "mouseup", end); | ||
useListener(refParent, "mouseleave", end); | ||
useListener(ref, "touchstart", start); | ||
useListener(host, "touchend", end); | ||
useListener(host, "touchmove", (event) => { | ||
useListener(refParent, "touchend", end); | ||
useListener(refParent, "touchmove", (event) => { | ||
const { targetTouches: [touche], } = event; | ||
const rect = host.current.getBoundingClientRect(); | ||
const rect = refParent.current.getBoundingClientRect(); | ||
const offsetX = touche.pageX - rect.x; | ||
const offsetY = touche.pageY - rect.y; | ||
const { current } = host; | ||
const { current } = refParent; | ||
setValue([ | ||
@@ -28,5 +27,5 @@ offsetX / current.clientWidth, | ||
}); | ||
useListener(host, "mousemove", (event) => { | ||
useListener(refParent, "mousemove", (event) => { | ||
if (active) { | ||
const { current } = host; | ||
const { current } = refParent; | ||
setValue([ | ||
@@ -33,0 +32,0 @@ event.offsetX / current.clientWidth, |
{ | ||
"name": "@atomico/use-drag-resize", | ||
"description": "Series of utilities in hooks format to extend the operation of Atomico", | ||
"version": "1.0.1-beta", | ||
"version": "1.0.2-beta", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "author": { |
3151
69