@render-props/point
v0.1.16
Published
A state container which provides an interface for setting and moving coordinate `{x, y}` values.
Downloads
6
Maintainers
Readme
Point
A state container which provides an interface for setting and moving
coordinate {x, y}
values.
Installation
yarn add @render-props/point
or npm i @render-props/point
Usage
import Point from '@render-props/point'
function MovablePoint (props) {
return (
<Point initialX={20} initialY={40}>
{({x, y, move, moveX, moveY, set, setX, setY}) => (
<div>
<span>
<strong>
X:
</strong>
<span>
{x}
</span>
<strong>
Y:
</strong>
<span>
{y}
</span>
</span>
<button onClick={() => move(10, -10)}>
Move (10, -10)
</button>
<button onClick={() => set(30, 40)}>
Set (30, 40)
</button>
</div>
)}
</Point>
)
}
Props
initialX {number}
- the value coordinate
x
should start with
- the value coordinate
initialY{number}
- the value coordinate
y
should start with
- the value coordinate
minX {number}
- the minimum bound for the
x
coordinate
- the minimum bound for the
maxX {number}
- the maximum bound for the
x
coordinate
- the maximum bound for the
minY {number}
- the minimum bound for the
y
coordinate
- the minimum bound for the
maxY {number}
- the maximum bound for the
y
coordinate
- the maximum bound for the
onBoundMinX {function}
- called when the minimum bound for
x
has been reached. Callback should include one argument for object:{x, y, minX, maxX, minY, maxY, set, setX, setY, move, moveX, moveY}
.
- called when the minimum bound for
onBoundMaxX {function}
- called when the maximum bound for
x
has been reached. Callback should include one argument for object:{x, y, minX, maxX, minY, maxY, set, setX, setY, move, moveX, moveY}
.
- called when the maximum bound for
onBoundMinY {function}
- called when the minimum bound for
y
has been reached. Callback should include one argument for object:{x, y, minX, maxX, minY, maxY, set, setX, setY, move, moveX, moveY}
.
- called when the minimum bound for
onBoundMaxY {function}
- called when the maximum bound for
y
has been reached. Callback should include one argument for object:{x, y, minX, maxX, minY, maxY, set, setX, setY, move, moveX, moveY}
.
- called when the maximum bound for
onChange {function}
- a callback which is invoked each time
x
ory
changes. Receives the new state({x, y})
as its only argument.
- a callback which is invoked each time
Render Props
Methods
set
(x <number>, y <number>)
- sets the state to
{x: @x, y: @y}
- sets the state to
setX
(x <number>)
- sets the coordinate
x
to the provided number
- sets the coordinate
setY
(y <number>)
- sets the coordinate
y
to the provided number
- sets the coordinate
move
(x <number>, y <number>)
- adds
@x
to the current value ofx
and@y
toy
. i.e.move(10, -10)
would result in a state of{x: state.x + @x, y: state.y + @y}
- adds
moveX
(x <number>)
- adds
@x
to the current value ofx
i.e.moveX(10)
would result in a state of{x: state.x + @x}
- adds
moveY
(y <number>)
- adds
@x
to the current value ofy
i.e.moveY(10)
would result in a state of{y: state.y + @y}
- adds
State
x {number}
- the current value of the
x
coordinate
- the current value of the
y {number}
- the current value of the
x
coordinate
- the current value of the