Skip to main content

Knob

Interactive rotary knob component implemented in SVG.

Source Style
Loading...
function App() {
  const [value, setValue] = useState(64)

  return (
    <div
      style={{
        display: 'flex',
        justifyContent: 'center',
        alignItems: 'center',
        flexDirection: 'column',
      }}
    >
      <Knob.Root
        className={knobTheme.root}
        aria-label="Level"
        value={value}
        min={0}
        max={100}
        size={50}
        onChange={(v) => setValue(v)}
      >
        <Knob.SVGRoot>
          <Knob.ActiveLine className={knobTheme.activeLine} />
          <Knob.InactiveLine className={knobTheme.inactiveLine} />
          <Knob.Thumb
            className={knobTheme.thumb}
            classes={{ line: knobTheme.thumbLine }}
          />
        </Knob.SVGRoot>
      </Knob.Root>
      {value}
    </div>
  )
}

Import​

import { Knob } from '@tremolo-ui/react'

API Reference​

Each part lists the props of its own. It also takes the attributes of the element it renders, such as className and style.

In Svelte and Vue the props are the same, written their way — class rather than className, bind:value or v-model, snippets or slots for content. See Svelte and Vue.

State is on the element as a data attribute, so it is a selector away — see Styling. An attribute is only there while its state is on.

Root​

Holds the value and handles the drag, the wheel and the arrow keys. It is the control itself: it takes the focus and carries the ARIA.

PropTypeDefault
value*number—
min*number—
max*number—
stepnumber1
scaleScalelinearScale
resetValuenumber | nullstartValue
startValuenumbermin
sizestring | number—
dragCursorCursor'grabbing'
wheelModifierValue<InputEventOption> | null['raw', 1]
dragSensitivityModifierValue<number>{ default: 1, shift: 0.1 }
pointerLockbooleanfalse
keyboardModifierValue<InputEventOption> | null{ default: ['raw', 1], shift: ['raw', 0.1] }
disabledboolean—
readOnlyboolean—
angleRangenumber270
onChange(value: number) => void—
onChangeStart(value: number, source: ChangeSource) => void—
onChangeEnd(value: number, source: ChangeSource) => void—
changeEndDelaynumber500
children*ReactNode—
actionsRefRef<KnobMethods>—

Full reference: KnobProps

Custom propertyWritten byWhat it sets
--knob-sizesizeThe width and height of the knob.
Data attributeValues
[data-disabled]Present when disabled is set
[data-readonly]Present when readonly is set
[data-dragging]Present while a drag is in progress

SVGRoot​

The <svg> the drawing parts go in. It sets the view box they are drawn against.

PropTypeDefault
children*ReactNode—

Full reference: KnobSVGRootProps

InactiveLine​

The arc outside the value. It has no props of its own and takes the attributes of an SVG <path>. The arc is kept inside the view box by the strokeWidth you give it.

ActiveLine​

The arc between startValue and the value. Like Knob.InactiveLine, it takes the attributes of an SVG <path>.

Thumb​

The circle that turns with the value, and the line on it that points at the value.

PropTypeDefault
colorstring'currentColor'
lineColorstring'currentColor'
sizenumber84
lineWeightnumber6
lineLengthnumber35
classes{ line?: string }—

Full reference: KnobThumbProps