Vitral 0.2
Form

Knob

A dial for a bounded number, set by dragging, pressing anywhere on it or the keyboard.

Import

main.ts
import { Knob } from '@vitral/vue';

Basic

Volume
<script setup lang="ts">import { Knob, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const volume = ref(60);</script> <template>    <StackPanel spacing="0.375rem">        <span id="knob-volume">Volume</span>        <Knob v-model="volume" aria-labelledby="knob-volume" value-template="{value}%" />    </StackPanel></template>

Range, step and size

<script setup lang="ts">import { Knob } from '@vitral/vue';import { ref } from 'vue'; const temperature = ref(21);const balance = ref(0);</script> <template>    <Knob v-model="temperature" :min="16" :max="30" :step="0.5" :size="140" :stroke-width="10" value-template="{value}°C" aria-label="Temperature" />    <Knob v-model="balance" :min="-50" :max="50" value-color="var(--vt-help-color)" aria-label="Balance" /></template>

Read-only and disabled

<script setup lang="ts">import { Knob } from '@vitral/vue';</script> <template>    <Knob :model-value="75" readonly aria-label="Battery" value-template="{value}%" />    <Knob :model-value="30" disabled aria-label="Disabled" /></template>

API

Read from packages/vue/src/components/Knob/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
minnumberDefaults to 0.
maxnumberDefaults to 100.
stepnumberDefaults to 1.
sizenumberThe dial's width and height, in pixels. Defaults to 100.
strokeWidthnumberThe thickness of the arc, in pixels. Defaults to 14.
showValuebooleanShow the value in the middle. Defaults to true.
valueTemplatestringHow the value is written, in the middle and to assistive technology: `'{value}%'`. Defaults to `'{value}'`.
valueColorstringOverrides the value arc's colour.
rangeColorstringOverrides the track's colour.
textColorstringOverrides the text's colour.
readonlyboolean—
disabledboolean—

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Emits

EventPayloadDescription
changevalue: numberThe value was changed by the reader: a drag ended or a key was pressed.