Overview
This package provides a number of custom hooks and helper functions.
Custom Hooks
The following custom hooks are available:
Custom Hook | Description |
---|---|
useSlider | A custom hook for building horizontal or vertical sliders |
useDial | A custom hook for building rotating dials |
useDragToAdjust | A lower-level custom hook that handles the user draggin vertically or horizontally |
useWheelToAdjust | A lower-level custom hook that handles mouse wheel actions |
useDragToMove | A lower-level custom hook that tracks the position of a target element the user is dragging |
These hooks are all you need to build sliders, knobs, and dials. These hooks use a few helper functions that are also available, should you need them:
Helper functions
Helper Function | Description |
---|---|
type Point2D | A generic 2D point type |
type Nullable | A generic type that is maybe null or undefined |
const TAU | The number of radians in a circle; useful when working with radians instead of using Math.PI*2 everywhere |
clamp | Clamp a value between a min and max value |
normalisedAngle | Takes an angle in radians, possibly negative, and normalises it to be between 0 and 2*Math.PI |
angleToValue | Maps an angle in radians to a numeric value |
valueToAngle | Maps a value, and returns a corresponding angle in radians, based on the parameters |
angleToPoint | Convert an angle in radians to a 2D point on a circle with origin as its center and radius radius . |
pointToAngle | Returns the angle in radians of a vector from origin to point |
pointEquals | Checks if two points are equal |
isPointInRect | Checks if a point is inside a rectangle |
rad2deg | Converts radians to degrees |
deg2rad | Converts degrees to radians |