Unstyled & accessible knob primitive for React.
Install the component from your command line.
npm install --save-exact react-knob-headless
By default, the knob interpolation occurs linearly, which is useful for values like "sustain", "dry/wet", "pan", etc.
A custom interpolation can be made whenever knob values should distribute non-linearly. It achieved by consuming a pair of "mapTo01" & "mapFrom01" props. This is useful for values like "frequency", "attack", "release", etc.
The primary knob primitive. This is the place where interaction happens.
Prop | Type | Default | Description |
---|---|---|---|
PropvalueRaw | Typenumber | Default— | Current value. Make sure it's not rounded. |
PropvalueMin | Typenumber | Default— | Minimum value. |
PropvalueMax | Typenumber | Default— | Maximum value. |
PropdragSensitivity | Typenumber | Default— | The sensitivity of the drag gesture. Must be a positive float value. Play with this value in different browsers to find the best one for your use case. Recommended value: 0.006 (quite optimal for most scenarios, so far). |
PropvalueRawRoundFn | Typefunction | Default— | The rounding function for the raw value. |
PropvalueRawDisplayFn | Typefunction | Default— | The function for mapping raw value to the human-readable text. |
ProponValueRawChange | Typefunction | Default— | Callback for when the raw value changes. Note, that you shouldn't round the value here, instead, you have to do it inside "valueRawRoundFn". |
PropincludeIntoTabOrder | Typeboolean | Defaultfalse | Whether to include the element into the sequential tab order. If true, the element will be focusable via the keyboard by tabbing. In most audio applications, the knob is usually controlled by the mouse / touch, so it's not needed. |
PropmapTo01 | Typefunction | DefaultmapTo01Linear() | Used for mapping the value to the normalized knob position (number from 0 to 1). This is the place for making the interpolation, if non-linear one is required. Example: logarithmic scale of frequency input, when knob center position 0.5 corresponds to ~ 1 kHz (instead of 10.1 kHz which is the "linear" center of frequency range). |
PropmapFrom01 | Typefunction | DefaultmapFrom01Linear() | Opposite of "mapTo01". |
Proparia-label | aria-labelledby | Typestring | Default— | Labelling for accesibility purposes. |
Prop...rest | Type... | Default— | The rest of HTML "div" element props. |
The optional primitive for visual accessive labelling of the knob.
Prop | Type | Default | Description |
---|---|---|---|
Propid | Typestring | Default— | Unique identifier for HTML "label" element. Must be provided to the knob via "aria-labelledby". |
Prop...rest | Type... | Default— | The rest of HTML "label" element props. |
The optional primitive for visual accessive output display of the knob.
Prop | Type | Default | Description |
---|---|---|---|
ProphtmlFor | Typestring | Default— | Unique identifier of the knob to relate the output with. Must be provided to the knob via "id". |
Prop...rest | Type... | Default— | The rest of HTML "output" element props. |