Skip to content

Advanced Primitives

These exports are intentionally low-level. Most apps should use useNumberFieldState, useNumberField, or the NumberField components.

import {
useControllableState,
usePressAndHold,
useScrubArea,
NumberFieldContext,
useNumberFieldContext,
} from "raqam";

Tiny controlled/uncontrolled state helper used internally by raqam.

const [value, setValue] = useControllableState<number | null>({
value: controlledValue,
defaultValue: 0,
onChange: setControlledValue,
});

Use it when you are building your own wrapper component and want the same controlled/uncontrolled semantics as NumberField.Root.

Returns pointer handlers that fire once immediately, then repeat with acceleration while the pointer stays down.

const hold = usePressAndHold(() => stepBy(1), {
delay: 400,
interval: 200,
disabled,
});
<button type="button" {...hold}>+</button>

Options:

OptionDefaultDescription
delay400Milliseconds before repeating starts.
interval200Initial repeat interval; it accelerates down to a 50ms floor.
disabledfalseDisables the handlers.

Pointer Lock powered drag-to-adjust behavior for custom scrub handles.

const { scrubAreaProps, isScrubbing } = useScrubArea(state, {
direction: "horizontal",
pixelSensitivity: 4,
});
<span {...scrubAreaProps}>
Drag to adjust {isScrubbing ? "" : null}
</span>

Options:

OptionDefaultDescription
direction"horizontal""horizontal", "vertical", or "both".
pixelSensitivity4Drag distance required for each step.

Return value:

KeyDescription
isScrubbingWhether pointer lock is active.
scrubAreaPropsProps to spread onto the scrub handle element.
virtualCursorPointer-lock cursor coordinates for custom overlays.

NumberFieldContext / useNumberFieldContext()

Section titled “NumberFieldContext / useNumberFieldContext()”

Context escape hatch for advanced compound components.

function CustomAdornment() {
const { state } = useNumberFieldContext();
return <span>{state.inputValue}</span>;
}

The context value exposes:

KeyDescription
stateCurrent NumberFieldState.
ariaCurrent NumberFieldAria prop bags.
inputRefRef for the active input element.
propsRoot props passed into NumberField.Root.