Skip to content

Commit 825dd6f

Browse files
committed
README.md updated
1 parent ecfb19e commit 825dd6f

File tree

7 files changed

+128
-31
lines changed

7 files changed

+128
-31
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
22
coverage/
33
build/
4-
debug.log
4+
debug.log
5+
.out

README.md

Lines changed: 106 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,120 @@
1-
# react-usage-bar
1+
# React Usage Bar Graphic Component
22

3-
## Usage
3+
![React Usage Bar](example.png)
44

5-
To install dependencies
5+
## Installation
66

7-
```
8-
$ yarn install
7+
Install via npm or yarn
8+
9+
```sh
10+
npm install react-usage-bar --save
11+
yarn add react-usage-bar
912
```
1013

11-
To build
14+
Alternatively just download `UsageBar.tsx` and `styles.css` from the `src` folder and include them in your project in your chosen way.
1215

13-
```
14-
$ yarn build
15-
```
16+
Keep in mind that the source code of the project needs [Typescript](https://www.typescriptlang.org/) to work.
1617

17-
To run tests
18+
## Usage
1819

20+
The usage bar needs to receive an array of items. In order to display all the values correctly every item should follow this interface:
21+
22+
### Item type
23+
24+
| Attribute | Type | Required |
25+
| --------- | ------ | -------- |
26+
| value | number | Yes |
27+
| name | string | Yes |
28+
| color | string | No |
29+
30+
The `value` represents the quantity of space occupied by the sector with a certain `name`. The `color` property could be used to specify the background color of that portion in the bar.
31+
32+
The `total` value is also required.
33+
34+
### Example
35+
36+
```javascript
37+
import * from 'react'
38+
import UsageBar from 'react-usage-bar'
39+
40+
const App = () => {
41+
42+
const a = [
43+
{
44+
name: "UI",
45+
value: 10,
46+
color: "#000000",
47+
},
48+
{
49+
name: "Photos",
50+
value: 30,
51+
},
52+
{
53+
name: "Videos",
54+
value: 15,
55+
},
56+
{
57+
name: "System Data",
58+
value: 33,
59+
},
60+
{
61+
name: "Other",
62+
value: 8,
63+
},
64+
]
65+
66+
return <UsageBar items={a} total={100} />
67+
})
68+
69+
export default App
1970
```
20-
$ yarn test
21-
```
2271

23-
To run Storybook
72+
## Props (Options)
73+
74+
### **showPercentage** | _boolean_ | default: `false`
75+
76+
When true shows the percentage value of all the elements.
77+
78+
### **removeLabels** | _boolean_ | default: `false`
79+
80+
When true hides all the tooltips or lables of the items.
81+
82+
### **darkMode** | _boolean_ | default: `false`
83+
84+
Enables the component to work in dark-mode.
85+
86+
## CSS Styles
87+
88+
### `.UsageBar`
89+
90+
The main div of the component.
91+
92+
### `.UsageBar__bar`
93+
94+
The actual bar of the component.
95+
96+
### `.UsageBar__bar__element`
97+
98+
The single item represented in the bar.
99+
100+
### `.UsageBar__bar__element--tooltip`
101+
102+
The tooltip of the item in which are written all the textual info.
103+
104+
- `::after` | Is used to make the triangular shape on the bottom (or top) of the tooltips.
105+
106+
## Docs
107+
108+
You can run the documentation of the component using [Storybook](https://storybook.js.org/):
24109

25110
```
26111
$ yarn storybook
27112
```
113+
114+
## Issues
115+
116+
Please create an issue for any bug or feature requests.
117+
118+
## Licence
119+
120+
React Usage Bar is [MIT licensed](https://github.com/ChrisUser/react-usage-bar/blob/master/LICENSE)

example.png

21.1 KB
Loading

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"lint": "standard",
1111
"format": "prettier-standard --format",
1212
"test": "jest --coverage",
13-
"storybook": "start-storybook"
13+
"storybook": "start-storybook",
14+
"build-storybook": "build-storybook -c .storybook -o .out"
1415
},
1516
"keywords": [
1617
"react",

src/UsageBar.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const withoutLabels = () => (
3737
export const errors = () => {
3838
return (
3939
<div>
40-
<span>If sum of values exceeds total.</span>
40+
<p>If sum of values exceeds total.</p>
4141
<UsageBar items={items} total={50} />
4242
</div>
4343
)

src/UsageBar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ const UsageBar: React.FC<Props> = ({
7474
)
7575

7676
return (
77-
<div className="panel">
78-
<div className="bar">
77+
<div className="UsageBar">
78+
<div className="UsageBar__bar">
7979
{items.map((element: Item) => {
8080
return (
8181
<div
82-
className="element"
82+
className="UsageBar__bar__element"
8383
style={{
8484
width: `${getPercentageValue(element.value)}%`,
8585
backgroundColor: element.color || setColor(),
@@ -88,7 +88,7 @@ const UsageBar: React.FC<Props> = ({
8888
{removeLabels ? (
8989
""
9090
) : (
91-
<div className="tooltip">
91+
<div className="UsageBar__bar__element--tooltip">
9292
{element.name +
9393
" " +
9494
(showPercentage

src/styles.css

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
--background-bar-color: hsl(0, 0%, 26%);
1010
}
1111

12-
.panel {
12+
.UsageBar {
1313
display: flex;
1414
justify-content: center;
1515
align-items: center;
@@ -21,7 +21,7 @@
2121
padding: 1em 1.3em;
2222
height: 6em;
2323
}
24-
.bar {
24+
.UsageBar__bar {
2525
position: relative;
2626
height: 0.6em;
2727
width: 100%;
@@ -34,27 +34,29 @@
3434
background-color: var(--background-bar-color);
3535
border-radius: 0.32em;
3636
}
37-
.element:first-child {
37+
.UsageBar__bar__element:first-child {
3838
border-radius: 0.32em 0 0 0.32em;
3939
}
40-
.element:last-child {
40+
.UsageBar__bar__element:last-child {
4141
border-radius: 0 0.32em 0.32em 0;
4242
}
43-
.element:nth-child(odd) > .tooltip {
43+
.UsageBar__bar__element:nth-child(odd) > .UsageBar__bar__element--tooltip {
4444
top: -2.3em;
4545
}
46-
.element:nth-child(odd) > .tooltip::after {
46+
.UsageBar__bar__element:nth-child(odd)
47+
> .UsageBar__bar__element--tooltip::after {
4748
border-top: 0.5em solid var(--background-tooltip-color);
4849
bottom: -0.44em;
4950
}
50-
.element:nth-child(even) > .tooltip {
51+
.UsageBar__bar__element:nth-child(even) > .UsageBar__bar__element--tooltip {
5152
bottom: -2.3em;
5253
}
53-
.element:nth-child(even) > .tooltip::after {
54+
.UsageBar__bar__element:nth-child(even)
55+
> .UsageBar__bar__element--tooltip::after {
5456
border-bottom: 0.5em solid var(--background-tooltip-color);
5557
top: -0.44em;
5658
}
57-
.element {
59+
.UsageBar__bar__element {
5860
display: flex;
5961
justify-content: center;
6062
align-items: center;
@@ -63,7 +65,7 @@
6365
position: relative;
6466
height: 100%;
6567
}
66-
.element > .tooltip {
68+
.UsageBar__bar__element--tooltip {
6769
display: flex;
6870
justify-content: center;
6971
align-items: center;
@@ -76,7 +78,7 @@
7678
color: var(--text-color);
7779
font-size: 0.9em;
7880
}
79-
.element > .tooltip::after {
81+
.UsageBar__bar__element--tooltip::after {
8082
z-index: -1;
8183
content: "";
8284
width: 0;

0 commit comments

Comments
 (0)