Low Battery Guard

Low Battery Guard is a copy-paste React component that stops upload died on a flat battery before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/low-battery-guard
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsUpload died on a flat battery

Was this component page useful?

How do I install Low Battery Guard?

pnpm dlx shadcn@latest add @bollard/low-battery-guard

The files land in your project. They're yours to edit.

How do I use Low Battery Guard in React?

low-battery-guard-usage.tsx
import { LowBatteryGuard } from "@/components/ui/low-battery-guard"

{!exporting && <LowBatteryGuard task="the export" minutes={45} battery={battery} onProceed={() => setExporting(true)} />

What input mistakes does Low Battery Guard catch?

  • Task longer than the battery's remaining runway
  • Battery already low before starting
  • Start when plugged in: runs the task once a charger connects
  • Silent when the task fits

What props does Low Battery Guard accept?

LowBatteryGuard props
PropTypeDefault
task* (required)

What the user is about to start, e.g. "the export".

string—
minutes* (required)

How long the task usually takes, in minutes.

number—
battery

Override the browser reading (tests, native shells, SSR hydration).

BatteryReading—
onProceed

Start the task. Enables "Start anyway" and "Start when plugged in".

() => void—
fallback

Shown when this browser can't read the battery (Safari, Firefox). Nothing by default.

React.ReactNodenull
hideAfter

How long "Charging · safe to start" stays after plugging in, in ms.

number3000
shortTitle

Templates: `{task}` (lower case reads best, e.g. "the export"), `{level}`, `{runway}`, `{duration}` are filled in.

string"Battery will run out before {task} finishes"
tightTitle

Title when the runway is close to the task's length.

string"Battery is cutting it close for {task}"
lowTitle

Title when the battery won't last.

string"Battery at {level} and not charging"
chargingTitle

Title while charging.

string"Charging · safe to start {task}"
startedTitle

Title after the task starts on plug-in.

string"Charging · {task} started"
armedTitle

Title while waiting for a charger.

string"Plug in and {task} starts by itself"
detailText

Detail line under the title.

string"{level} lasts about {runway}, {task} needs about {durati…
lowDetailText

Detail line when the battery won't last.

string"Plug in to be safe: {task} needs about {duration}"
runwayLabel

Label for the battery runway.

string"Battery ~{runway}"
durationLabel

Label for the task's length.

string"Done in ~{duration}"
startWhenPluggedLabel

Button text to start once plugged in.

string"Start when plugged in"
startAnywayLabel

Button text to start now.

string"Start anyway"
cancelLabel

Button text to stop waiting.

string"Cancel"

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

How is Low Battery Guard accessible?

  • Banner is role=status
  • Runway bar is role=img with an aria-label giving runway and duration
  • Pulse animation is motion-safe only; icons are aria-hidden

Only what the source does. Test with your own screen reader and content before shipping.

What are the limitations and server boundaries?

  • The Battery Status API is missing in Safari and Firefox; then it uses your fallback
  • Runway is an estimate from current drain
  • Doesn't pause or resume the task itself

What expensive mistakes does Low Battery Guard stop?

Upload died on a flat battery

Also known as

low battery · battery api · upload · online exam · export · plug in · charger · mobile

Field type

What dependencies does Low Battery Guard require?

Low Battery Guard facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameLow Battery Guard
Registry identifier@bollard/low-battery-guard
Install commandnpx shadcn@latest add @bollard/low-battery-guard
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about Low Battery Guard

What form validation mistake does Low Battery Guard catch?

Low Battery Guard prevents upload died on a flat battery. Before a long upload, export or call, compares battery runway with the task's length and offers to start once plugged in. Catches: Task longer than the battery's remaining runway, Battery already low before starting, Start when plugged in: runs the task once a charger connects, Silent when the task fits. Limitation: validate low-battery-guard schemas on backend.

How do I install low-battery-guard with shadcn?

Run `npx shadcn@latest add @bollard/low-battery-guard`. Sources added: registry/default/low-battery-guard/low-battery-guard.tsx. Package requirements: lucide-react.

What props customize Low Battery Guard?

Low Battery Guard accepts `task`, `minutes`, `battery`, `onProceed`, `fallback`. Configures low battery, battery api, upload behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of low-battery-guard?

The Battery Status API is missing in Safari and Firefox; then it uses your fallback. Runway is an estimate from current drain. Doesn't pause or resume the task itself Server requirement: backend verification for low-battery-guard.

How does Low Battery Guard meet accessibility guidelines?

Banner is role=status. Runway bar is role=img with an aria-label giving runway and duration. Pulse animation is motion-safe only; icons are aria-hidden. Minimizes errors: battery died during upload, exam stopped low battery.

Which components pair with Low Battery Guard?