-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: float molecule structures over the spectrum (#1525)
* feat: svg draggable component * feat: context to pass the root svg element down on the nodes tree * refactor: resizer component to use the new useDraggable hook * refactor: set button content pointer-events one * feat: float structures * refactor: remove root context and use global context instead * refactor: rename component name * chore: fix eslint * chore: chain conditions * style: structures toolbar
- Loading branch information
1 parent
902993d
commit 843173d
Showing
25 changed files
with
638 additions
and
236 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
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
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,82 @@ | ||
import { useEffect, ReactFragment } from 'react'; | ||
|
||
import useDraggable, { Position } from './useDraggable'; | ||
|
||
type ChildType = | ||
| Array<React.ReactElement> | ||
| React.ReactElement | ||
| ReactFragment | ||
| boolean | ||
| null; | ||
|
||
type PositionChangeHandler = (data: Position) => void; | ||
|
||
export interface DraggableProps { | ||
children?: ChildType | ((x1: number, x2: number) => ChildType); | ||
initialPosition?: Position; | ||
width: number; | ||
height: number; | ||
onStart?: PositionChangeHandler; | ||
onMove?: PositionChangeHandler; | ||
onEnd?: PositionChangeHandler; | ||
parentElement?: HTMLElement | null; | ||
dragHandleClassName?: string; | ||
} | ||
|
||
export default function SVGDraggable(props: DraggableProps) { | ||
const { | ||
children, | ||
initialPosition = { x: 0, y: 0 }, | ||
width, | ||
height, | ||
onStart, | ||
onMove, | ||
onEnd, | ||
parentElement, | ||
dragHandleClassName, | ||
} = props; | ||
|
||
const { | ||
position: { | ||
value: { x, y }, | ||
action, | ||
}, | ||
onMouseDown, | ||
} = useDraggable({ | ||
position: initialPosition, | ||
parentElement, | ||
dragHandleClassName, | ||
}); | ||
|
||
useEffect(() => { | ||
const position: Position = { | ||
x, | ||
y, | ||
}; | ||
|
||
switch (action) { | ||
case 'start': | ||
onStart?.(position); | ||
break; | ||
case 'move': | ||
onMove?.(position); | ||
break; | ||
case 'end': | ||
onEnd?.(position); | ||
break; | ||
default: | ||
break; | ||
} | ||
}, [action, onEnd, onMove, onStart, x, y]); | ||
|
||
return ( | ||
<g | ||
style={{ | ||
transform: `translate(${x}px,${y}px)`, | ||
}} | ||
onMouseDown={onMouseDown} | ||
> | ||
{typeof children === 'function' ? children(width, height) : children} | ||
</g> | ||
); | ||
} |
Oops, something went wrong.