Skip to content

Commit cd94a9d

Browse files
committed
docs: improve battery docs
1 parent 7e6d92e commit cd94a9d

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const MyComponent = mock();
3535
- [`delayed()`](./docs/delayed.md)
3636
- [`invert()`](./docs/invert.md)
3737
- Sensors
38-
- [`<BatterySensor>`](./docs/BatterySensor.md), `withBattery()`, and `@withBattery`
38+
- [`<BatterySensor>`](./docs/BatterySensor.md), [`withBattery()`](./docs/BatterySensor.md#withbattery), and [`@withBattery`](./docs/BatterySensor.md#@withbattery)
3939
- [`<MediaDeviceSensor>`](./docs/MediaDeviceSensor.md)
4040
- [`<MediaSensor>`](./docs/MediaSensor.md)
4141
- [`<NetworkSensor>`](./docs/NetworkSensor.md) and [`withNetwork()`](./docs/NetworkSensor.md#withnetwork)

docs/BatterySensor.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# `BatterySensor`
1+
# `<BatterySensor>`
22

33
Uses [`Navigator.getBattery()`](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getBattery) API to track battery level, charging status and time it takes to charge/discharge a battery.
44

5-
# Props
5+
## Props
66

77
None.
88

9-
# Example
9+
## Example
1010

1111
```jsx
1212
import {BatterySensor} from 'libreact/lib/BatterySensor';
@@ -26,3 +26,39 @@ Result
2626
"dischargingTime": null
2727
}
2828
```
29+
30+
## `withBattery()`
31+
32+
Higher order component that injects `battery` prop into your component.
33+
34+
```js
35+
import {withBattery} from 'libreact/lib/BatterySensor';
36+
37+
const MyCompWithBattery = withBattery(MyComp);
38+
```
39+
40+
Overwrite the inject prop name
41+
42+
```js
43+
const MyCompWithBattery = withBattery(MyComp, 'myBattery');
44+
```
45+
46+
or merge the props
47+
48+
```js
49+
const MyCompWithBattery = withBattery(MyComp, null);
50+
```
51+
52+
53+
## `@withBattery`
54+
55+
Statefull component class decorator that injects `battery` prop into your component.
56+
57+
```js
58+
import {withBattery} from 'libreact/lib/BatterySensor';
59+
60+
@withBattery
61+
class MyComp extends Component {
62+
63+
}
64+
```

0 commit comments

Comments
 (0)