Vitral 0.2.18
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
min numberDefaults to 0.
max numberDefaults to 100.
step numberDefaults to 1.
size numberThe dial's width and height, in pixels. Defaults to 100.
strokeWidth numberThe thickness of the arc, in pixels. Defaults to 14.
showValue booleanShow the value in the middle. Defaults to true.
valueTemplate stringHow the value is written, in the middle and to assistive technology: `'{value}%'`. Defaults to `'{value}'`.
valueColor stringOverrides the value arc's colour.
rangeColor stringOverrides the track's colour.
textColor stringOverrides the text's colour.
readonly boolean—
disabled boolean—

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

Emits

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