0.1.16 • Published 7 years ago
@render-props/point v0.1.16
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
xshould start with
- the value coordinate
initialY{number}- the value coordinate
yshould start with
- the value coordinate
minX {number}- the minimum bound for the
xcoordinate
- the minimum bound for the
maxX {number}- the maximum bound for the
xcoordinate
- the maximum bound for the
minY {number}- the minimum bound for the
ycoordinate
- the minimum bound for the
maxY {number}- the maximum bound for the
ycoordinate
- the maximum bound for the
onBoundMinX {function}- called when the minimum bound for
xhas 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
xhas 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
yhas 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
yhas 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
xorychanges. 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
xto the provided number
- sets the coordinate
setY(y <number>)- sets the coordinate
yto the provided number
- sets the coordinate
move(x <number>, y <number>)- adds
@xto the current value ofxand@ytoy. i.e.move(10, -10)would result in a state of{x: state.x + @x, y: state.y + @y}
- adds
moveX(x <number>)- adds
@xto the current value ofxi.e.moveX(10)would result in a state of{x: state.x + @x}
- adds
moveY(y <number>)- adds
@xto the current value ofyi.e.moveY(10)would result in a state of{y: state.y + @y}
- adds
State
x {number}- the current value of the
xcoordinate
- the current value of the
y {number}- the current value of the
xcoordinate
- the current value of the