1.0.7 • Published 2 months ago

react-battery-gauge v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

React Battery Gauge

This library is a SVG based react component for displaying battery status, ultra lightweight, highly customizable with zero dependencies

Live Demo

Click here

Short Demo

Short Demo

Storybook Demo

Click here

Usage

Install it by running

npm install react-battery-gauge # or yarn add react-battery-gauge

Include the component:

import BatteryGauge from 'react-battery-gauge'

<BatteryGauge value={40} />

Options

NameDescriptionDefaulttype
valueMeter value range 0-maxValue(100)50number
maxValueMeter max value100number
orientationChanges orientation, keeping text horizontal"horizontal""horizontal"| "vertical"
paddingPadding of gauge within canvas5number
sizeWe don't like passing both width and height, can create unusual looking shape. Size will help gauge to achieve the desired size maintaining aspect ratio300number
aspectRatioGauge aspect ratio, At padding 0 easy to create battery types -> D = 0.56, C = 0.52, AA = 0.28, AAA = 0.23, AAAA = 0.19 , default C battery0.52number
animatedEnable animation on mountfalseboolean
chargingEnable charging modefalseboolean
customizationAll individual components customisationGaugeCustomPartial

Override any customization default values:

{
  batteryBody: {
    strokeWidth: 4,
    cornerRadius: 6,
    fill: 'none',
    strokeColor: '#111'
  },
  batteryCap: {
    fill: 'none',
    strokeWidth: 4,
    strokeColor: '#111',
    cornerRadius: 2,
    capToBodyRatio: 0.4
  },
  batteryMeter: {
    fill: 'green',
    lowBatteryValue: 15,
    lowBatteryFill: 'red',
    outerGap: 1,
    noOfCells: 1, // more than 1, will create cell battery
    interCellsGap: 1
  },
  readingText: {
    lightContrastColor: '#111',
    darkContrastColor: '#fff',
    lowBatteryColor: 'red',
    fontFamily: 'Helvetica',
    fontSize: 14,
    showPercentage: true
  },
  chargingFlash: {
    scale: undefined,
    fill: 'orange',
    animated: true,
    animationDuration: 1000
  },
}

License

MIT

Free Software, Your contribution is welcome!