仕組み
The knob sweeps 270deg. A drag measures the knob once when it starts and then works only from angles: each move adds the change in angle (unwrapped across 180deg) to an exact reading, which is rounded to the nearest step, so the cap clicks from detent to detent with a 90ms springy turn. Pressing the ring of lights jumps to that reading; pressing the cap grabs it where it is; near the centre the pointer is ignored because the angle swings too fast there. The cap's body and its light stay still and carry all the shading; only a transparent layer with the notch turns. The lights are placed by rotation in CSS. When the reading jumps, each light waits 10ms per light of distance from the previous reading (at most 360ms), so the ring lights up, or goes out, in the order a hand would pass it. Shadows are set separately for the dark theme, where the lights glow more.
向いている場面
- A value people set by feel rather than type: oven or thermostat temperature, volume, fan speed, brightness.
- Product pages and control panels that should feel like a physical device.
- Touch screens, where a large round target is easy to turn with a thumb.
向かない場面
- Exact numbers or wide ranges with fine steps: use a number input or a range slider.
- Dense forms, where a 208px control takes too much room.
使い方
import { useState } from 'react'
import { DialKnob } from './DialKnob.jsx'
export function OvenDial() {
const [temp, setTemp] = useState(180)
return (
<DialKnob
label="Temperature"
min={50}
max={250}
step={5}
value={temp}
onChange={setTemp}
formatValue={(v) => `${v}°C`}
/>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
value / defaultValue / onChange | number / number / (value) => void | - / min / - | The reading, controlled or uncontrolled. onChange fires on every step while turning. |
onChangeEnd | (value) => void | — | Fires once when a drag ends, after each key press and when scrolling pauses: the moment to save. |
min / max / step | number / number / number | 0 / 100 / 1 | The range and the size of one detent. The 270deg sweep runs from min at seven-thirty to max at four-thirty. |
dots | number | one per step, at most 41 | How many lights make up the ring. |
label / formatValue | string / (value) => string | 'Level' / String | The name and the reading as text, used by screen readers (aria-label, aria-valuetext) and by the readout. |
readout | boolean | true | Shows the label in small capitals and the reading under the knob. Turn it off when the reading is shown elsewhere. |
size | 'sm' | 'md' | 'lg' | 'md' | 150, 208 or 264px across, ring included. |
wheel | boolean | true | Lets the scroll wheel turn the knob while it has focus. It never reacts to a page simply being scrolled past it. |
disabled | boolean | false | Fades the knob and ignores input. |
...rest | HTMLAttributes | — | Other attributes go to the root <div>. |
アクセシビリティ
- The dial is role="slider" with aria-valuemin, aria-valuemax, aria-valuenow and aria-valuetext from formatValue, named by label; the lights and the readout are hidden from assistive tech.
- Right and Up add a step, Left and Down take one away, PageUp and PageDown move a tenth of the range, Home and End go to the ends. Focus shows a ring round the well.
- The scroll wheel only turns the knob while it has focus, so scrolling the page never changes it by accident.
- Touch: touch-action is none on the dial, so a finger turning it does not scroll the page; the whole dial, ring included, is the target.
- The notch shows the reading as well as the lights, so it does not depend on colour alone.
- Reduced motion turns the cap and lights the ring at once.
モーション
Dragging: each detent turns in 90ms on cubic-bezier(0.3, 1.5, 0.6, 1). A jump: the cap turns over --ds-duration-slow on --ds-ease-out while the lights change over --ds-duration-fast, 10ms apart. A theme change cross-fades the shading over --ds-duration-slow.
プロジェクトに追加
Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。
DialKnob.jsxdial-knob.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。







