Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows to render custom dragable Elements #120

Open
alexfauquette opened this issue May 3, 2023 · 1 comment · May be fixed by #121
Open

Allows to render custom dragable Elements #120

alexfauquette opened this issue May 3, 2023 · 1 comment · May be fixed by #121

Comments

@alexfauquette
Copy link

Before all, thanks for this inspiring library 🤓

I was looking to create a graph with draggable points. But I do not see an easy way to customize how draggable elements are defined.

For now, there are:

  • useMovablePoint(initialPoint, props) which deal with saving position and constraint, and memorize the movable point
  • <MovablePoint /> which add the drag interaction, and render the component

What about adding a props Component to <MovablePoint /> the expect a React element with props{ ref, displayX, displayY, dragging } Such that if Component is defined, the <MovablePoint /> renders this component. Otherwise it renders the default one

DefaultComponent example
const DefaultComponent = ({ ref, dragging, displayX, displayY }) => {
  const ringSize = 15
	return <g
      ref={ref}
      style={{ "--movable-point-color": color, "--movable-point-ring-size": `${ringSize}px`,}}
      className={`mafs-movable-point ${dragging ? "mafs-movable-point-dragging" : ""}`}
      tabIndex={0}
    >
      <circle className="mafs-movable-point-hitbox" r={30} cx={displayX} cy={displayY}></circle>
      <circle
        className="mafs-movable-point-focus"
        r={ringSize + 1}
        cx={displayX}
        cy={displayY}
      ></circle>
      <circle className="mafs-movable-point-ring" r={ringSize} cx={displayX} cy={displayY}></circle>
      <circle className="mafs-movable-point-point" r={6} cx={displayX} cy={displayY}></circle>
    </g>
}
@stevenpetryk
Copy link
Owner

I think having a higher order "draggable" abstraction would be useful! It would basically be a wrapper around @use-gesture/react, but which takes into account view and user transforms.

@alexfauquette alexfauquette linked a pull request May 6, 2023 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants