-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: resizer and draggable components (#2731)
* refactor: useDraggable hook * refactor: resizer component and its hook * refactor: lefting resizer state up and remove key * refactor: create HOC for the resizer component * refactor: resizer component and remove div resizer
- Loading branch information
1 parent
b8c8e48
commit 565fb92
Showing
10 changed files
with
209 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { useScaleX } from '../1d/utilities/scale'; | ||
import { useGlobal } from '../context/GlobalContext'; | ||
|
||
import SVGResizer, { ResizerProps } from './resizer/SVGResizer'; | ||
|
||
interface ResizerWithScaleProps { | ||
disabled: boolean; | ||
from: number; | ||
to: number; | ||
onEnd: ResizerProps['onEnd']; | ||
children: ResizerProps['children']; | ||
} | ||
|
||
export function ResizerWithScale(props: ResizerWithScaleProps) { | ||
const { from, to, onEnd, disabled, children } = props; | ||
const { viewerRef } = useGlobal(); | ||
const scaleX = useScaleX(); | ||
const x2 = scaleX()(from); | ||
const x1 = scaleX()(to); | ||
const [position, setPosition] = useState({ x1, x2 }); | ||
|
||
useEffect(() => { | ||
const x2 = scaleX()(from); | ||
const x1 = scaleX()(to); | ||
setPosition({ x1, x2 }); | ||
}, [from, scaleX, to]); | ||
|
||
return ( | ||
<SVGResizer | ||
position={position} | ||
onEnd={onEnd} | ||
parentElement={viewerRef} | ||
disabled={disabled} | ||
onMove={(p) => setPosition(p)} | ||
> | ||
{children} | ||
</SVGResizer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.