# Backup Reserve

A settings card for the share of a home battery held back for outages. Drag the slider, use its arrow keys, or press a preset; the LCD number, the hours estimate and the segmented bar follow at once. The bar shows the reserved part, the usable part above it and the free space. Below, a switch turns storm watch on and the stepper sets the grid charging rate. Cancel restores the last saved values and Save keeps the new ones.

<demo-backup-reserve>



</demo-backup-reserve>

## Installation

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

## Usage

```vue
<script setup lang="ts">
  import { ref } from 'vue';
  import BackupReserve from '~/components/ui/backup-reserve/BackupReserve.vue';
  import type { BackupReserveSettings } from '~/components/ui/backup-reserve/types';

  const reserve = ref(30);
  const stormWatch = ref(true);
  const gridRate = ref(3.8);

  function onSave(settings: BackupReserveSettings) {
    console.log(settings);
  }
</script>

<template>
  <BackupReserve
    v-model:reserve="reserve"
    v-model:storm-watch="stormWatch"
    v-model:grid-rate="gridRate"
    :battery="64"
    :capacity="13.5"
    :essential-load="0.45"
    @save="onSave"
  />
</template>
```

The hours estimate is `reserve × capacity ÷ essential-load`, rounded. With the defaults, a 30 % reserve of 13.5 kWh covers about 9 hours of a 0.45 kW essential load.

## Props

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

<tbody>
  <tr>
    <td>
      <code>
        reserve
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        30
      </code>
    </td>
    
    <td>
      <code>
        v-model:reserve
      </code>
      
      . Reserve held back, 0–100 %.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        storm-watch
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
    </td>
    
    <td>
      <code>
        v-model:storm-watch
      </code>
      
      . The storm watch switch.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        grid-rate
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        3.8
      </code>
    </td>
    
    <td>
      <code>
        v-model:grid-rate
      </code>
      
      . Max grid charging rate in kW.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        battery
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        64
      </code>
    </td>
    
    <td>
      Current battery charge, 0–100 %.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        capacity
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        13.5
      </code>
    </td>
    
    <td>
      Battery capacity in kWh.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        essential-load
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        0.45
      </code>
    </td>
    
    <td>
      Load of the essential circuits in kW.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        presets
      </code>
    </td>
    
    <td>
      <code>
        number[]
      </code>
    </td>
    
    <td>
      <code>
        [10, 20, 30, 50, 80, 100]
      </code>
    </td>
    
    <td>
      Quick-pick reserve values.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cells
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        25
      </code>
    </td>
    
    <td>
      Segments in the LCD bar.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        charging
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
    </td>
    
    <td>
      Blinks the top battery segment.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        grid-rate-min
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        0
      </code>
    </td>
    
    <td>
      Lowest grid charging rate.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        grid-rate-max
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        11.5
      </code>
    </td>
    
    <td>
      Highest grid charging rate.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        grid-rate-step
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        0.2
      </code>
    </td>
    
    <td>
      Step of the − and + buttons.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        title
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Backup reserve'
      </code>
    </td>
    
    <td>
      Card title.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        subtitle
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Held back for outages'
      </code>
    </td>
    
    <td>
      Line under the title.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        status
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Grid up'
      </code>
    </td>
    
    <td>
      Text in the status pill. Hidden when empty.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        storm-title
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Storm watch'
      </code>
    </td>
    
    <td>
      Switch title.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        storm-description
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Fills to 100 % before alerts'
      </code>
    </td>
    
    <td>
      Switch description.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        grid-title
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Grid charging'
      </code>
    </td>
    
    <td>
      Stepper title.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        grid-description
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Max rate from the grid'
      </code>
    </td>
    
    <td>
      Stepper description.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cancel-label
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Cancel'
      </code>
    </td>
    
    <td>
      Cancel button text.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        save-label
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Save'
      </code>
    </td>
    
    <td>
      Save button text.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        color
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        '#ff9a2e'
      </code>
    </td>
    
    <td>
      Reserve and LCD accent colour.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        usable-color
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        '#4ade80'
      </code>
    </td>
    
    <td>
      Colour of the usable part of the battery.
    </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:reserve
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      Fires on every slider, preset or key change.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        update:storm-watch
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      Fires when the switch toggles.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        update:grid-rate
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      Fires when the stepper changes.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        save
      </code>
    </td>
    
    <td>
      <code>
        BackupReserveSettings
      </code>
    </td>
    
    <td>
      Fires on Save with <code>
        reserve
      </code>
      
      , <code>
        stormWatch
      </code>
      
       and <code>
        gridRate
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cancel
      </code>
    </td>
    
    <td>
      —
    </td>
    
    <td>
      Fires on Cancel, after the last saved values are restored.
    </td>
  </tr>
</tbody>
</table>

## Accessibility

- The slider thumb has `role="slider"` with `aria-valuenow`. Arrow keys change it by 1, Page Up and Page Down by 10, Home and End jump to the ends.
- The presets are a `radiogroup`. Arrow keys move the selection.
- Storm watch is a `role="switch"` with `aria-checked`.
- The grid rate readout is a `role="spinbutton"`; arrow keys change it, and the − and + buttons have labels.
- With reduced motion, the number tween, slider glide and switch spring are turned off.
