|
1 | | -# react-usage-bar |
| 1 | +# React Usage Bar Graphic Component |
2 | 2 |
|
3 | | -## Usage |
| 3 | + |
4 | 4 |
|
5 | | -To install dependencies |
| 5 | +## Installation |
6 | 6 |
|
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 |
9 | 12 | ``` |
10 | 13 |
|
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. |
12 | 15 |
|
13 | | -``` |
14 | | -$ yarn build |
15 | | -``` |
| 16 | +Keep in mind that the source code of the project needs [Typescript](https://www.typescriptlang.org/) to work. |
16 | 17 |
|
17 | | -To run tests |
| 18 | +## Usage |
18 | 19 |
|
| 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 |
19 | 70 | ``` |
20 | | -$ yarn test |
21 | | -``` |
22 | 71 |
|
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/): |
24 | 109 |
|
25 | 110 | ``` |
26 | 111 | $ yarn storybook |
27 | 112 | ``` |
| 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) |
0 commit comments