6.2.1 • Published 11 months ago

react-joystick-component v6.2.1

Weekly downloads
142
License
MIT
Repository
github
Last release
11 months ago

React Joystick Component

Bundle Size

Click here to see examples

npm i react-joystick-component --save
yarn add react-joystick-component
import { Joystick } from 'react-joystick-component';
<Joystick size={100} sticky={true} baseColor="red" stickColor="blue" move={handleMove} stop={handleStop}></Joystick>

Component Props - as described by IJoystickProps - all are optional

PropTypeDescription
sizenumberThe size in px of the Joystick base
stickSizenumberThe size in px of the Joystick stick (if unspecified, joystick size is relative to the size value
baseColorstringThe color of the Joystick base
stickColorstringThe color of the Stick
throttlenumberThe throttling rate of the move callback
stickyBooleanShould the joystick stay where it is when the interaction ends
stickImagestringThe image to be shown for the joystick
baseImagestringThe image to be shown for the pad
followCursorBooleanMake the stick follow the cursor position
moveFunctionCallback fired on every mouse move, not throttled unless a throttling rate is provided as above
stopFunctionCallback fired when the user releases the joystick
startFunctionCallback fired when the user starts moving the Joystick
disabledBooleanWhen true, block any usage of the Joystick. This will also apply the joystick-disabled and joystick-base-disabled classNames
stickShapeJoystickShapeThe shape of the joystick default = circle
baseShapeJoystickShapeThe shape of the joystick default = circle
controlPlaneShapeJoystickShapeOverride the default shape behaviour of the control plane - circle, square, axisX, axisY
minDistancenumberPercentage 0-100 - the minimum distance to start receive IJoystickMove events
pos{x: number, y: number}Override the joystick position (doesn't work if the user is interacting. You can use disabled to force this)
import {JoystickShape} from "./shape.enum"; 
interface IJoystickProps {
    size?: number;
    stickSize?: number;
    baseColor?: string;
    stickColor?: string;
    disabled?: boolean;
    throttle?: number;
    sticky?: boolean;
    stickImage?: string;
    baseImage?: string;
    followCursor?: boolean;
    move?: (event: IJoystickUpdateEvent) => void;
    stop?: (event: IJoystickUpdateEvent) => void;
    start?: (event: IJoystickUpdateEvent) => void;
    baseShape?: JoystickShape;
    stickShape?: JoystickShape;
    controlPlaneShape?: JoystickShape;
    minDistance?: number;
    pos: {x: number, y: number}
}
type JoystickDirection = "FORWARD" | "RIGHT" | "LEFT" | "BACKWARD";

export interface IJoystickUpdateEvent {
    type: "move" | "stop" | "start";
    x: number | null;
    y: number | null;
    direction: JoystickDirection | null;
    distance: number; // Percentile 0-100% of joystick 
}
6.2.1

11 months ago

6.1.0

1 year ago

6.2.0

1 year ago

6.1.1

1 year ago

5.0.0

1 year ago

6.0.0

1 year ago

4.1.0

2 years ago

4.0.1

2 years ago

2.3.0

2 years ago

2.2.0

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

3.3.1

2 years ago

3.3.0

2 years ago

3.0.3

2 years ago

3.2.0

2 years ago

3.0.2

2 years ago

3.1.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

4.0.0

2 years ago

1.4.0

5 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago