# Operating Mode Dial

A control card for a home battery. Turn the knob to pick a mode: drag it around, click a mode label, or focus it and use the arrow keys. It springs to the nearest mode and the lit dot, the LCD panel and `v-model` follow. The tabs switch the rate schedule, and the strip under them shades each hour as off-peak, mid or peak with the peak window underlined. Cancel goes back to the last applied mode.

<demo-operating-mode-dial>



</demo-operating-mode-dial>

## Installation

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

## Usage

```vue
<script setup lang="ts">
  import { ref } from 'vue';
  import OperatingModeDial from '~/components/ui/operating-mode-dial/OperatingModeDial.vue';

  const mode = ref('time-based');
  const schedule = ref('weekdays');

  function save(value: string): void {
    console.log('apply', value);
  }
</script>

<template>
  <OperatingModeDial v-model="mode" v-model:schedule="schedule" @apply="save" />
</template>
```

Pass your own `modes` to change the positions. Each mode takes an `angle` in degrees, clockwise from 12 o'clock, between -135 and 135. Modes without an angle spread evenly.

## 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>
        string
      </code>
    </td>
    
    <td>
      <code>
        'time-based'
      </code>
    </td>
    
    <td>
      <code>
        v-model
      </code>
      
      . The selected mode value.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        modes
      </code>
    </td>
    
    <td>
      <code>
        OperatingModeOption[]
      </code>
    </td>
    
    <td>
      Four battery modes
    </td>
    
    <td>
      Dial positions: <code>
        value
      </code>
      
      , <code>
        label
      </code>
      
      , <code>
        title
      </code>
      
      , <code>
        description
      </code>
      
      , <code>
        angle
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        schedule
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      First schedule
    </td>
    
    <td>
      <code>
        v-model:schedule
      </code>
      
      . The selected schedule tab.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        schedules
      </code>
    </td>
    
    <td>
      <code>
        OperatingModeSchedule[]
      </code>
    </td>
    
    <td>
      Weekdays, Weekends, Holidays
    </td>
    
    <td>
      Tabs, each with 24 hourly tiers: <code>
        'off'
      </code>
      
      , <code>
        'mid'
      </code>
      
       or <code>
        'peak'
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        prices
      </code>
    </td>
    
    <td>
      <code>
        OperatingModePrices
      </code>
    </td>
    
    <td>
      <code>
        $0.11 / $0.24 / $0.48
      </code>
    </td>
    
    <td>
      Legend text for each tier.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        title
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Operating mode'
      </code>
    </td>
    
    <td>
      Header title.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        subtitle
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Battery and inverter'
      </code>
    </td>
    
    <td>
      Header subtitle.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        badge
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Auto'
      </code>
    </td>
    
    <td>
      Pill at the top right. <code>
        ''
      </code>
      
       hides it.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        icon
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'lucide:circle-gauge'
      </code>
    </td>
    
    <td>
      Icon in the header chip.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        accent
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        '#ff9a2e'
      </code>
    </td>
    
    <td>
      Colour of the lit mode dot and the LCD text.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        peak-color
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        '#4ade80'
      </code>
    </td>
    
    <td>
      Colour of the line under the peak window.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cancel-label
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Cancel'
      </code>
    </td>
    
    <td>
      Text of the cancel button.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        apply-label
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Apply mode'
      </code>
    </td>
    
    <td>
      Text of the apply button.
    </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>
        update:modelValue
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      The knob settled on a new mode.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        update:schedule
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      A schedule tab was picked.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        change
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      Same as <code>
        update:modelValue
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        apply
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      Apply was pressed. The mode becomes the cancel point.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cancel
      </code>
    </td>
    
    <td>
      —
    </td>
    
    <td>
      Cancel was pressed. The mode goes back to the last applied one.
    </td>
  </tr>
</tbody>
</table>

## Accessibility

- The knob is a `role="slider"` with `aria-valuenow` and `aria-valuetext` set to the mode name. Arrow keys step between modes, Home and End jump to the ends.
- Each mode label is a button with `aria-pressed`.
- The schedule tabs use `role="tablist"` and `role="tab"` with roving focus on the arrow keys.
- The LCD panel is an `aria-live` region, so the new mode description is read out.
- The spring and the colour transitions turn off when the user prefers reduced motion.
