# Thermal Dial

A temperature card you set by turning its dial. Drag round the ring, scroll over the card, or focus it and use the arrow keys. The reading follows on a spring that overshoots and settles, the lit ticks carry a slow travelling wave with a brighter head, and the heat at the foot of the card rises and changes colour with the number: cold blue in winter, cyan in autumn, amber in spring and red in summer. The digits roll one slot at a time and the season above them swaps letter by letter through a blur.

<demo-thermal-dial>



</demo-thermal-dial>

## Installation

```bash
npx shadcn-vue@latest add "https://nxui.geoql.in/r/thermal-dial.json"
```

## Usage

```vue
<script setup lang="ts">
  import { computed, ref } from 'vue';
  import ThermalDial from '~/components/ui/thermal-dial/ThermalDial.vue';
  import type { ThermalDialSeason } from '~/components/ui/thermal-dial/types';

  const colorMode = useColorMode();
  const theme = computed(() => (colorMode.value === 'dark' ? 'dark' : 'light'));
  const temp = ref(22);

  function onChange(value: number, season: ThermalDialSeason) {
    console.log(value, season);
  }
</script>

<template>
  <ThermalDial v-model="temp" :theme="theme" @change="onChange" />
</template>
```

On mount the card fades in and the reading sweeps up from `min` to its value. `v-model` is optional; without it the dial starts at `default-value` and keeps its own reading. The seasons are fixed bands: below 5° is Winter, below 16° Autumn, below 26° Spring, and 26° and up Summer.

## Props

<table>
<thead>
  <tr>
    <th>
      Prop
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Default
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        model-value
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      —
    </td>
    
    <td>
      <code>
        v-model
      </code>
      
      . The reading in whole degrees, clamped to <code>
        min
      </code>
      
      –<code>
        max
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        default-value
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        38
      </code>
    </td>
    
    <td>
      The reading it settles on after the opening sweep when no <code>
        v-model
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        min
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        -9
      </code>
    </td>
    
    <td>
      Lowest reading, at the left end of the arc.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        max
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        70
      </code>
    </td>
    
    <td>
      Highest reading, at the right end of the arc.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        size
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        340
      </code>
    </td>
    
    <td>
      Card width in px. It never exceeds 80% of the viewport width.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        theme
      </code>
    </td>
    
    <td>
      <code>
        'light' | 'dark'
      </code>
    </td>
    
    <td>
      <code>
        'dark'
      </code>
    </td>
    
    <td>
      Colour theme. Pass your site's colour mode.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        hint
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
    </td>
    
    <td>
      Shows a line under the card saying how to use it.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        label
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Temperature'
      </code>
    </td>
    
    <td>
      Accessible name of the slider.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        class
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        ''
      </code>
    </td>
    
    <td>
      Extra classes for the root element.
    </td>
  </tr>
</tbody>
</table>

## Events

<table>
<thead>
  <tr>
    <th>
      Event
    </th>
    
    <th>
      Payload
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        change
      </code>
    </td>
    
    <td>
      <code>
        (value: number, season: ThermalDialSeason)
      </code>
    </td>
    
    <td>
      Fires when the user sets a new reading.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        update:modelValue
      </code>
    </td>
    
    <td>
      <code>
        (value: number)
      </code>
    </td>
    
    <td>
      <code>
        v-model
      </code>
      
       update, fired with every new whole degree.
    </td>
  </tr>
</tbody>
</table>

## Accessibility

- The card is a `role="slider"` with `aria-valuemin`, `aria-valuemax`, `aria-valuenow` and an `aria-valuetext` such as "22 degrees, Spring". The digits and season label are hidden from assistive tech because the slider already speaks them.
- Arrow Up and Right raise the reading by one degree, Down and Left lower it, Shift steps by five, Home and End jump to the ends of the scale. The mouse wheel steps one degree.
- The card shows a focus ring on its rim when focused from the keyboard.
- With reduced motion the reading jumps straight to its value, the digits and letters swap without rolling or blurring, and the wave and breathing stop.

Ported from [Thermal Dial](https://pinui.xyz/components/thermal-dial) by Pin UI, MIT licence.
