react-battery-level 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,83 +2,87 @@
2
2
 
3
3
  ## Simple customizable battery component!
4
4
 
5
- ## Features
5
+ ## 목차
6
6
 
7
- - **SVG-Based**: Crisp and clean rendering at any size or resolution.
8
- - **Dynamic Gauge**: Visual battery level represented by a customizable SVG fill.
9
- - **Charging State**: Optional SVG lightning bolt icon for charging indication.
10
- - **Customizable Appearance**: Configure the dimensions, color, and styles of the SVG elements.
11
- - **Percentage Display**: Option to display the battery percentage text within the SVG.
7
+ - [Installation](#installation)
8
+ - [Usage](#usage)
9
+ - [Props](#props)
10
+ - [License](#license)
11
+
12
+ ### Features
12
13
 
13
14
  <div align="center">
14
- <img width="300px" src="/demo/demo1.gif">
15
- <img width="300px" src="/demo/demo2.gif">
16
- <img width="300px" src="/demo/demo3.gif">
15
+ <img width="300px" src="/demo/demo.gif">
17
16
  </div>
18
17
 
19
- ## Installation
18
+ ### Installation
20
19
 
21
20
  ```bash
22
- npm install react-battery-level --save
21
+ npm i react-battery-level
23
22
  ```
24
23
 
25
- ## Usage
24
+ ### Usage
26
25
 
27
26
  ```jsx
28
- import { useState } from "react";
29
- import BatteryLevel from "react-battery-level";
27
+ import BatteryLevel from 'react-battery-level';
30
28
 
31
29
  function App() {
32
- const [gauge, setGauge] = useState(75);
33
30
  return (
34
- //Adjust only width to maintain aspect ratio.
35
31
  <BatteryLevel
36
- width="10vw"
37
- gauge={gauge}
38
- gaugeColor={gauge <= 20 ? "#FF5713" : "#6EF47A"}
39
- isCharging={true}
40
- isShowGaugePercentage={false}
41
- lightningBoltStyles={{
42
- fill: gauge <= 20 ? "#FF5713" : "#6EF47A",
43
- stroke: "white",
44
- strokeWidth: 0.5,
32
+ width="250"
33
+ gauge={75}
34
+ isCharging
35
+ borderStyles={{
36
+ color: '#000',
45
37
  }}
46
38
  />
47
39
  );
48
40
  }
41
+
49
42
  export default App;
50
43
  ```
51
44
 
52
45
  ## Props
53
46
 
54
- | Prop | Type | Default | Description |
55
- | ----------------------- | -------------------- | ----------- | ------------------------------------------------------ |
56
- | `width` | `number` \| `string` | `"100%"` | Optional. The width of the SVG battery icon. |
57
- | `height` | `number` \| `string` | `"100%"` | Optional. The height of the SVG battery icon. |
58
- | `gauge` | `number` | None | Required. The charge level of the battery (0-100). |
59
- | `gaugeColor` | `string` | `"#6EF47A"` | Optional. The color of the battery fill. |
60
- | `isCharging` | `boolean` | `false` | Required. Indicates if the battery is charging. |
61
- | `isShowGaugePercentage` | `boolean` | `true` | Optional. Shows the battery percentage inside the SVG. |
62
- | `lightningBoltStyles` | `object` | `{}` | Optional. Styling for the SVG lightning bolt. |
63
- | `gaugePercentageStyles` | `object` | `{}` | Optional. Styling for the battery percentage text. |
64
-
65
- <br>
66
-
67
- ### `lightningBoltStyles` Object
68
-
69
- | Key | Type | Default | Description |
70
- | ------------- | -------------------- | --------- | ---------------------------------------- |
71
- | `fill` | `string` | `"white"` | SVG fill color for the lightning bolt. |
72
- | `stroke` | `string` | `"black"` | SVG stroke color for the lightning bolt. |
73
- | `strokeWidth` | `number` \| `string` | `0.5` | SVG stroke width for the lightning bolt. |
74
-
75
- ### `gaugePercentageStyles` Object
76
-
77
- | Key | Type | Default | Description |
78
- | ---------- | -------------------- | --------- | ------------------------------------------ |
79
- | `fontSize` | `number` \| `string` | `7` | Font size for the battery percentage text. |
80
- | `color` | `string` | `"black"` | Color for the battery percentage text. |
81
-
82
- ## License
47
+ `BatteryLevel` 컴포넌트는 다음과 같은 props를 받습니다:
48
+
49
+ | Prop | Type | Default | Description |
50
+ | ------------------ | -------------------- | ----------- | ------------------------------------------------------ |
51
+ | `width` | `number` \| `string` | `"150"` | Optional. The width of the battery icon. |
52
+ | `height` | `number` \| `string` | `"100%"` | Optional. The height of the battery icon. |
53
+ | `gauge` | `number` | None | Required. The charge level of the battery (0-100). |
54
+ | `gaugeColor` | `string` | `"#34C759"` | Optional. The color of the battery fill. |
55
+ | `isCharging` | `boolean` | `false` | Optional. Indicates if the battery is charging. |
56
+ | `showPercentage` | `boolean` | `false` | Optional. Shows the battery percentage inside the SVG. |
57
+ | `borderStyles` | `object` | `{}` | Optional. Styling for the border. |
58
+ | `lightningStyles` | `object` | `{}` | Optional. Styling for the lightning bolt. |
59
+ | `percentageStyles` | `object` | `{}` | Optional. Styling for the battery percentage text. |
60
+
61
+ ### `borderStyles` Object
62
+
63
+ | Key | Type | Default | Description |
64
+ | ------------- | -------- | --------- | ------------------------------------ |
65
+ | `color` | `string` | `"black"` | Stroke color for the battery border. |
66
+ | `strokeWidth` | `number` | `1` | Stroke width for the battery border. |
67
+ | `radius` | `number` | `5` | Border radius for the battery. |
68
+
69
+ ### `lightningStyles` Object
70
+
71
+ | Key | Type | Default | Description |
72
+ | ------------- | -------- | -------------------------- | -------------------------------------------- |
73
+ | `fill` | `string` | `"yellow"` | Fill color for the lightning bolt. |
74
+ | `stroke` | `string` | `none` | Stroke color for the lightning bolt. |
75
+ | `strokeWidth` | `number` | `0.5` | Stroke width for the lightning bolt. |
76
+ | `position` | `object` | `{ x: 15, y: -1 }` | Position of the lightning bolt. |
77
+ | `transform` | `object` | `{ scale: 1, rotate: 10 }` | Transform properties for the lightning bolt. |
78
+
79
+ ### `percentageStyles` Object
80
+
81
+ | Key | Type | Default | Description |
82
+ | ---------- | -------- | --------- | ------------------------------------------ |
83
+ | `fontSize` | `number` | `8` | Font size for the battery percentage text. |
84
+ | `color` | `string` | `"black"` | Color for the battery percentage text. |
85
+
86
+ ### License
83
87
 
84
88
  MIT
package/demo/demo.gif ADDED
Binary file
package/dist/index.d.ts CHANGED
@@ -1,19 +1,3 @@
1
- type Props = {
2
- width?: number | string;
3
- height?: number | string;
4
- gauge: number;
5
- gaugeColor?: string;
6
- isCharging: boolean;
7
- isShowGaugePercentage: boolean;
8
- lightningBoltStyles?: {
9
- fill: string;
10
- stroke: string;
11
- strokeWidth: string | number;
12
- };
13
- gaugePercentageStyles?: {
14
- fontSize: string | number;
15
- color: string;
16
- };
17
- };
18
- declare const BatteryLevel: ({ gauge, width, height, isCharging, isShowGaugePercentage, gaugeColor, lightningBoltStyles, gaugePercentageStyles, }: Props) => import("react/jsx-runtime").JSX.Element;
1
+ import { BatteryProps } from './types';
2
+ declare const BatteryLevel: ({ width, height, gauge, gaugeColor, isCharging, lightningStyles, showPercentage, percentageStyles, borderStyles, }: BatteryProps) => import("react/jsx-runtime").JSX.Element;
19
3
  export default BatteryLevel;
package/dist/index.js CHANGED
@@ -1,112 +1,42 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- var __assign =
3
- (this && this.__assign) ||
4
- function () {
5
- __assign =
6
- Object.assign ||
7
- function (t) {
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
8
3
  for (var s, i = 1, n = arguments.length; i < n; i++) {
9
- s = arguments[i];
10
- for (var p in s)
11
- if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
12
7
  }
13
8
  return t;
14
- };
9
+ };
15
10
  return __assign.apply(this, arguments);
16
- };
17
-
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
13
  var BatteryLevel = function (_a) {
19
- var gauge = _a.gauge,
20
- _b = _a.width,
21
- width = _b === void 0 ? "100%" : _b,
22
- _c = _a.height,
23
- height = _c === void 0 ? "100%" : _c,
24
- _d = _a.isCharging,
25
- isCharging = _d === void 0 ? false : _d,
26
- _e = _a.isShowGaugePercentage,
27
- isShowGaugePercentage = _e === void 0 ? true : _e,
28
- _f = _a.gaugeColor,
29
- gaugeColor = _f === void 0 ? "#6EF47A" : _f,
30
- _g = _a.lightningBoltStyles,
31
- lightningBoltStyles =
32
- _g === void 0
33
- ? {
34
- fill: "white",
35
- stroke: "black",
36
- strokeWidth: 0.5,
37
- }
38
- : _g,
39
- _h = _a.gaugePercentageStyles,
40
- gaugePercentageStyles =
41
- _h === void 0
42
- ? {
43
- fontSize: 7,
44
- color: "black",
45
- }
46
- : _h;
47
- var maxGaugeWidth = 73;
48
- var batteryHeight = 73;
49
- var gaugeWidth = gauge * (maxGaugeWidth / 100);
50
- return _jsxs(
51
- "svg",
52
- __assign(
53
- {
54
- width: width,
55
- height: height,
56
- viewBox: "0 0 45 23",
57
- fill: "none",
58
- xmlns: "http://www.w3.org/2000/svg",
59
- },
60
- {
61
- children: [
62
- _jsx("path", {
63
- d: "M44.2102 11.4C44.2102 9.96999 43.2702 8.76999 41.9702 8.35999V14.43C43.2702 14.02 44.2102 12.82 44.2102 11.39V11.4Z",
64
- fill: "black",
65
- }),
66
- _jsx("path", {
67
- d: "M41.9702 14.93C41.8702 14.93 41.7602 14.9 41.6702 14.83C41.5402 14.74 41.4702 14.59 41.4702 14.43V8.35999C41.4702 8.19999 41.5502 8.04999 41.6702 7.95999C41.8002 7.86999 41.9702 7.83999 42.1202 7.88999C43.6702 8.37999 44.7102 9.78999 44.7102 11.4C44.7102 13.01 43.6702 14.42 42.1202 14.91C42.0702 14.93 42.0202 14.93 41.9702 14.93ZM42.4702 9.13999V13.65C43.2302 13.16 43.7102 12.32 43.7102 11.39C43.7102 10.46 43.2302 9.61999 42.4702 9.12999V9.13999Z",
68
- fill: "black",
69
- }),
70
- _jsx("path", {
71
- d: "M33.5 22.74H7.60995C3.94995 22.74 0.959961 19.76 0.959961 16.09V6.7C0.959961 3.04 3.93995 0.0500031 7.60995 0.0500031H33.5C37.16 0.0500031 40.1499 3.03 40.1499 6.7V16.09C40.1499 19.75 37.17 22.74 33.5 22.74ZM7.60995 2.56C5.31995 2.56 3.45996 4.42 3.45996 6.71V16.1C3.45996 18.39 5.31995 20.25 7.60995 20.25H33.5C35.79 20.25 37.6499 18.39 37.6499 16.1V6.71C37.6499 4.42 35.79 2.56 33.5 2.56H7.60995Z",
72
- fill: "black",
73
- }),
74
- _jsx("rect", {
75
- id: "4",
76
- x: "4.1",
77
- y: "3",
78
- width: gaugeWidth + "%",
79
- height: batteryHeight + "%",
80
- rx: "3",
81
- ry: "3",
82
- fill: gaugeColor,
83
- }),
84
- isShowGaugePercentage &&
85
- _jsxs(
86
- "text",
87
- __assign(
88
- {
89
- x: "20",
90
- y: "11",
91
- fontSize: gaugePercentageStyles.fontSize,
92
- color: gaugePercentageStyles.color,
93
- textAnchor: "middle",
94
- alignmentBaseline: "central",
95
- fill: "black",
96
- },
97
- { children: [gauge, "%"] }
98
- )
99
- ),
100
- isCharging &&
101
- _jsx("path", {
102
- d: "M27.6495 12.15L18.7595 7.23C18.7595 7.23 18.6696 7.21 18.6396 7.23C18.5996 7.25 18.5796 7.29 18.5796 7.34V10.3H11.5996C11.5396 10.3 11.4896 10.34 11.4796 10.39C11.4696 10.44 11.4895 10.5 11.5395 10.53L20.4295 15.45C20.4295 15.45 20.4696 15.47 20.4896 15.47C20.5096 15.47 20.5296 15.47 20.5496 15.45C20.5896 15.43 20.6096 15.39 20.6096 15.34V12.38H27.5896C27.6496 12.38 27.6995 12.34 27.7095 12.29C27.7195 12.24 27.6995 12.18 27.6495 12.15Z",
103
- fill: lightningBoltStyles.fill,
104
- stroke: lightningBoltStyles.stroke,
105
- strokeWidth: lightningBoltStyles.strokeWidth,
106
- }),
107
- ],
108
- }
109
- )
110
- );
14
+ var _b = _a.width, width = _b === void 0 ? '150' : _b, _c = _a.height, height = _c === void 0 ? '100%' : _c, gauge = _a.gauge, _d = _a.gaugeColor, gaugeColor = _d === void 0 ? '#34C759' : _d, _e = _a.isCharging, isCharging = _e === void 0 ? false : _e, _f = _a.lightningStyles, lightningStyles = _f === void 0 ? {} : _f, _g = _a.showPercentage, showPercentage = _g === void 0 ? false : _g, _h = _a.percentageStyles, percentageStyles = _h === void 0 ? {} : _h, _j = _a.borderStyles, borderStyles = _j === void 0 ? {} : _j;
15
+ var BATTERY_WIDTH = 42;
16
+ var BATTERY_HEIGHT = 22;
17
+ var BATTERY_X = 1;
18
+ var BATTERY_Y = 1;
19
+ var PADDING = 2;
20
+ var GAUGE_MAX_WIDTH = BATTERY_WIDTH - PADDING * 2;
21
+ var defaultBorderStyles = {
22
+ color: 'black',
23
+ strokeWidth: 1,
24
+ radius: 5,
25
+ };
26
+ var defaultLightningStyles = {
27
+ fill: 'yellow',
28
+ stroke: 'none',
29
+ strokeWidth: 0.5,
30
+ position: { x: 15, y: -1 },
31
+ transform: { scale: 1, rotate: 10 },
32
+ };
33
+ var defaultPercentageStyles = {
34
+ fontSize: 8,
35
+ color: 'black',
36
+ };
37
+ var appliedBorderStyles = __assign(__assign({}, defaultBorderStyles), borderStyles);
38
+ var appliedLightningStyles = __assign(__assign(__assign({}, defaultLightningStyles), lightningStyles), { position: __assign(__assign({}, defaultLightningStyles.position), lightningStyles.position), transform: __assign(__assign({}, defaultLightningStyles.transform), lightningStyles.transform) });
39
+ var appliedPercentageStyles = __assign(__assign({}, defaultPercentageStyles), percentageStyles);
40
+ return (_jsxs("svg", __assign({ width: width, height: height, viewBox: "0 0 50 25", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, { children: [_jsx("rect", { x: "1", y: "1", width: BATTERY_WIDTH, height: BATTERY_HEIGHT, rx: appliedBorderStyles.radius, stroke: appliedBorderStyles.color, strokeWidth: appliedBorderStyles.strokeWidth }), _jsx("path", { d: "M44.6 8V16C46.2094 15.32244 47.256 13.74626 47.256 12C47.256 10.25374 46.2094 8.67756 44.6 8Z", fill: appliedBorderStyles.color, fillOpacity: "1" }), _jsx("rect", { x: BATTERY_X + PADDING, y: BATTERY_Y + PADDING, width: GAUGE_MAX_WIDTH * (gauge / 100), height: "18", rx: "3", fill: gaugeColor }), showPercentage && (_jsxs("text", __assign({ x: BATTERY_X + 22, y: BATTERY_Y + 11, fontSize: appliedPercentageStyles.fontSize, color: appliedPercentageStyles.color, textAnchor: "middle", alignmentBaseline: "central", fill: "black" }, { children: [gauge, "%"] }))), isCharging && (_jsx("g", __assign({ transform: "\n translate(".concat(appliedLightningStyles.position.x, ", ").concat(appliedLightningStyles.position.y, ") \n scale(").concat(appliedLightningStyles.transform.scale, ") \n rotate(").concat(appliedLightningStyles.transform.rotate, ")\n ") }, { children: _jsx("path", { d: "M12 0L4 12H10L5 24L16 10H9L12 0Z", fill: appliedLightningStyles.fill, stroke: appliedLightningStyles.stroke, strokeWidth: appliedLightningStyles.strokeWidth }) })))] })));
111
41
  };
112
42
  export default BatteryLevel;
@@ -0,0 +1,30 @@
1
+ export type BatteryProps = {
2
+ width?: number | string;
3
+ height?: number | string;
4
+ gauge: number;
5
+ gaugeColor?: string;
6
+ isCharging?: boolean;
7
+ lightningStyles?: {
8
+ fill?: string;
9
+ stroke?: string;
10
+ strokeWidth?: number;
11
+ position?: {
12
+ x?: number;
13
+ y?: number;
14
+ };
15
+ transform?: {
16
+ scale?: number;
17
+ rotate?: number;
18
+ };
19
+ };
20
+ showPercentage?: boolean;
21
+ percentageStyles?: {
22
+ fontSize?: number;
23
+ color?: string;
24
+ };
25
+ borderStyles?: {
26
+ color?: string;
27
+ strokeWidth?: number;
28
+ radius?: number;
29
+ };
30
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-battery-level",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "private": false,
5
5
  "description": "Simple customizable react battery component",
6
6
  "main": "dist/index.js",
@@ -26,10 +26,12 @@
26
26
  "license": "MIT",
27
27
  "keywords": [
28
28
  "battery",
29
- "gauge",
30
- "battery svg",
31
29
  "battery indicator",
32
- "battery level"
30
+ "battery level",
31
+ "react battery",
32
+ "react battery level",
33
+ "react battery gauge",
34
+ "react battery indicator"
33
35
  ],
34
36
  "scripts": {
35
37
  "start": "react-scripts start",
package/demo/demo1.gif DELETED
Binary file
package/demo/demo2.gif DELETED
Binary file
package/demo/demo3.gif DELETED
Binary file