Skip to content

Overview

This package provides a number of custom hooks and helper functions.

Custom Hooks

The following custom hooks are available:

Custom Hook
Description
useSliderA custom hook for building horizontal or vertical sliders
useDialA custom hook for building rotating dials
useDragToAdjustA lower-level custom hook that handles the user draggin vertically or horizontally
useWheelToAdjustA lower-level custom hook that handles mouse wheel actions
useDragToMoveA 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 Point2DA generic 2D point type
type NullableA generic type that is maybe null or undefined
const TAUThe number of radians in a circle; useful when working with radians instead of using Math.PI*2 everywhere
clampClamp a value between a min and max value
normalisedAngleTakes an angle in radians, possibly negative, and normalises it to be between 0 and 2*Math.PI
angleToValueMaps an angle in radians to a numeric value
valueToAngleMaps a value, and returns a corresponding angle in radians, based on the parameters
angleToPointConvert an angle in radians to a 2D point on a circle with origin as its center and radius radius.
pointToAngleReturns the angle in radians of a vector from origin to point
pointEqualsChecks if two points are equal
isPointInRectChecks if a point is inside a rectangle
rad2degConverts radians to degrees
deg2radConverts degrees to radians