Skip to content

Commit b53bb4a

Browse files
committed
Many bugs fixed, added more styles, new layout ...
1 parent 1e90003 commit b53bb4a

File tree

15 files changed

+7342
-8355
lines changed

15 files changed

+7342
-8355
lines changed

.github/workflows/storybook.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Build and Deploy
2+
on:
3+
push:
4+
paths: ["src/**"] # Trigger the action only when files change in the folders defined here
5+
jobs:
6+
build-and-deploy:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout 🛎️
10+
uses: actions/[email protected]
11+
with:
12+
persist-credentials: false
13+
- name: Install and Build 🔧
14+
run: | # Install npm packages and build the Storybook files
15+
npm install
16+
npm run build-storybook
17+
- name: Deploy 🚀
18+
uses: JamesIves/[email protected]
19+
with:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
BRANCH: main # The branch the action should deploy to.
22+
FOLDER: docs-build # The folder that the build-storybook script generates files.
23+
CLEAN: true # Automatically remove deleted files from the deploy branch
24+
TARGET_FOLDER: react-usage-bar # The folder that we serve our Storybook files from

.storybook/config.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

.storybook/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ module.exports = {
44
"@storybook/addon-docs",
55
"@storybook/addon-viewport",
66
"@storybook/addon-a11y",
7-
],
7+
]
88
}

.storybook/preview.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const parameters = {
2+
a11y: {
3+
element: '#root',
4+
config: {},
5+
options: {},
6+
manual: true,
7+
},
8+
};

.storybook/webpack.config.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

README.md

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,25 @@
33
![React Usage Bar](example.png)
44

55
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
6+
![Dependencies](https://img.shields.io/badge/dependencies-up%20to%20date-brightgreen.svg)
7+
![Contributions welcome](https://img.shields.io/badge/contributions-welcome-orange.svg)
8+
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
69

7-
## Installation
10+
## 🔌 Installation
811

9-
Install via npm or yarn
12+
Install via npm
1013

1114
```sh
1215
npm install react-usage-bar --save
13-
yarn add react-usage-bar
1416
```
1517

16-
Alternatively just download `UsageBar.tsx` and `styles.css` from the `src` folder and include them in your project in your chosen way.
18+
or yarn
1719

18-
Keep in mind that the source code of the project needs [Typescript](https://www.typescriptlang.org/) to work.
20+
```sh
21+
yarn add react-usage-bar
22+
```
1923

20-
## Usage
24+
## 🔧 Usage
2125

2226
The usage bar needs to receive an array of items. In order to display all the values correctly every item should follow this interface:
2327

@@ -42,7 +46,7 @@ import "react-usage-bar/build/index.css"
4246

4347
const App = () => {
4448

45-
const a = [
49+
const itemsToDisplay = [
4650
{
4751
name: "UI",
4852
value: 10,
@@ -63,15 +67,16 @@ const App = () => {
6367
{
6468
name: "Other",
6569
value: 8,
66-
},
67-
]
70+
}]
6871

69-
return <UsageBar items={a} total={100} />
72+
return <UsageBar items={itemsToDisplay} total={100} />
7073
})
7174

7275
export default App
7376
```
7477

78+
<br>
79+
7580
## Props (Options)
7681

7782
### **showPercentage** | _boolean_ | default: `false`
@@ -86,20 +91,30 @@ When true hides all the tooltips or lables of the items.
8691

8792
Enables the component to work in dark-mode.
8893

94+
### **compactLayout** | _boolean_ | default: `false`
95+
96+
The new compact design. _**Try it**_.
97+
98+
<br>
99+
89100
## CSS Styles
90101

91-
You should import the style directly from the package directory, like this:
102+
You must import the style directly from the package directory, like this:
92103

93104
```javascript
94105
import "react-usage-bar/build/index.css"
95106
```
96107

97-
The main css classes are the following:
108+
The main css classes are the following (**Spoiler**: There are more of them):
98109

99110
### `.UsageBar`
100111

101112
The main div of the component.
102113

114+
### `.UsageBar__error`
115+
116+
The error message.
117+
103118
### `.UsageBar__bar`
104119

105120
The actual bar of the component.
@@ -112,20 +127,28 @@ The single item represented in the bar.
112127

113128
The tooltip of the item in which are written all the textual info.
114129

115-
- `::after` | Is used to make the triangular shape on the bottom (or top) of the tooltips.
130+
- `.UsageBar__bar__element--tooltip--element__percentage` - Used to control the style of the percentage lables.
131+
132+
- `::after` - Is used to make the triangular shape on the bottom (or top) of the tooltips.
116133

117-
## Docs
134+
<br>
118135

119-
You can run the documentation of the component using [Storybook](https://storybook.js.org/):
136+
## 📖 Docs (https://chrisuser.github.io/react-usage-bar)
137+
138+
<br>
139+
140+
You can also run the project in a local enviroment using [Storybook](https://storybook.js.org/):
120141

121142
```
122143
$ yarn storybook
123144
```
124145

125-
## Issues
146+
<br>
147+
148+
## Contribution
126149

127-
Please create an issue for any bug or feature requests.
150+
If you have a suggestion that would make this component better feel free to open a pull request or create an issue for any bug you find.
128151

129152
## Licence
130153

131-
React Usage Bar is [MIT licensed](https://github.com/ChrisUser/react-usage-bar/blob/master/LICENSE)
154+
React Usage Bar is [MIT licensed](https://github.com/ChrisUser/react-usage-bar/blob/master/LICENSE).

example.png

4.14 KB
Loading

package.json

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-usage-bar",
3-
"version": "1.0.3",
3+
"version": "1.0.5",
44
"description": "Usage bar, graphic component for React",
55
"main": "build/index.js",
66
"module": "build/index.es.js",
@@ -19,7 +19,7 @@
1919
"format": "prettier-standard --format",
2020
"test": "jest --coverage",
2121
"storybook": "start-storybook",
22-
"build-storybook": "build-storybook -c .storybook -o .out"
22+
"build-storybook": "build-storybook -c .storybook -o docs-build .out"
2323
},
2424
"keywords": [
2525
"react",
@@ -31,38 +31,39 @@
3131
"name": "ChrisUser",
3232
"url": "https://github.com/ChrisUser"
3333
},
34+
"homepage": "http://ChrisUser.github.io/react-usage-bar",
3435
"license": "MIT",
3536
"devDependencies": {
3637
"@babel/core": "^7.9.6",
37-
"@storybook/addon-a11y": "^5.3.19",
38-
"@storybook/addon-docs": "^5.3.19",
39-
"@storybook/addon-viewport": "^5.3.19",
40-
"@storybook/react": "^5.3.19",
38+
"@storybook/addon-a11y": "^6.4.19",
39+
"@storybook/addon-docs": "^6.4.19",
40+
"@storybook/addon-viewport": "^6.4.19",
41+
"@storybook/react": "^6.4.19",
4142
"@testing-library/jest-dom": "^5.8.0",
42-
"@testing-library/react": "^10.0.4",
43-
"@types/jest": "^25.2.3",
44-
"@types/react": "^16.9.35",
45-
"@types/react-dom": "^16.9.8",
43+
"@testing-library/react": "^12.1.3",
44+
"@types/jest": "^27.4.1",
45+
"@types/react": "^17.0.39",
46+
"@types/react-dom": "^17.0.11",
4647
"awesome-typescript-loader": "^5.2.1",
4748
"babel-loader": "^8.1.0",
48-
"jest": "^26.0.1",
49+
"jest": "^27.5.1",
4950
"prettier-standard": "^16.3.0",
50-
"react": "^16.13.1",
51+
"react": "^17.0.2",
5152
"react-docgen-typescript-loader": "^3.7.2",
52-
"react-dom": "^16.13.1",
53+
"react-dom": "^17.0.2",
5354
"rollup": "^2.10.9",
5455
"rollup-plugin-commonjs": "^10.1.0",
5556
"rollup-plugin-node-resolve": "^5.2.0",
5657
"rollup-plugin-peer-deps-external": "^2.2.2",
57-
"rollup-plugin-postcss": "^3.1.1",
58-
"rollup-plugin-terser": "^6.1.0",
59-
"rollup-plugin-typescript2": "^0.27.1",
60-
"semantic-release": "^17.0.8",
61-
"standard": "^14.3.4",
58+
"rollup-plugin-postcss": "^4.0.2",
59+
"rollup-plugin-terser": "^7.0.2",
60+
"rollup-plugin-typescript2": "^0.31.2",
61+
"semantic-release": "^19.0.2",
62+
"standard": "^16.0.4",
6263
"standard-prettier": "^1.0.1",
63-
"ts-jest": "^26.0.0",
64-
"ts-loader": "^7.0.5",
65-
"typescript": "^3.9.3"
64+
"ts-jest": "^27.1.3",
65+
"ts-loader": "^8.2.0",
66+
"typescript": "^4.5.5"
6667
},
6768
"peerDependencies": {
6869
"react": "^16",

rollup.config.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ export default {
3030
}),
3131
external(),
3232
resolve(),
33-
typescript({
34-
rollupCommonJSResolveHack: true,
35-
exclude: ["**/__tests__/**", "**/*.stories.tsx"],
36-
clean: true,
37-
}),
33+
//typescript({
34+
// rollupCommonJSResolveHack: true,
35+
// exclude: ["**/__tests__/**", "**/*.stories.tsx"],
36+
// clean: true,
37+
//}),
38+
// typescript(),
3839
terser(),
3940
commonjs({
4041
include: ["node_modules/**"],

src/UsageBar.stories.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import * as React from "react"
22
import UsageBar from "./UsageBar"
33

4-
export default { title: "UsageBar", component: UsageBar }
4+
export default {
5+
title: "Usage Bar",
6+
component: UsageBar,
7+
parameters: {}
8+
}
59

610
const items = [
711
{
812
name: "UI",
913
value: 10,
10-
color: "#000000",
14+
color: "#E85D04",
1115
},
1216
{
1317
name: "Photos",
@@ -27,18 +31,19 @@ const items = [
2731
},
2832
]
2933

30-
export const basic = () => <UsageBar items={items} total={100} />
31-
export const withPercentages = () => (
32-
<UsageBar showPercentage={true} items={items} total={100} />
33-
)
34-
export const withoutLabels = () => (
35-
<UsageBar removeLabels={true} items={items} total={100} />
34+
export const lightMode = () => <UsageBar items={items} total={100} />
35+
36+
export const withoutLabels = () => <UsageBar removeLabels items={items} total={100} />
37+
38+
export const withPercentages = () => <UsageBar showPercentage items={items} total={100} />
39+
40+
export const compactLayout = () => <UsageBar showPercentage compactLayout items={items} total={100} />
41+
42+
export const compactLayoutWithoutLabels = () => <UsageBar removeLabels compactLayout items={items} total={100} />
43+
44+
export const error = () => (
45+
<>
46+
<p>If sum of values exceeds total.</p>
47+
<UsageBar items={items} total={50} />
48+
</>
3649
)
37-
export const errors = () => {
38-
return (
39-
<div>
40-
<p>If sum of values exceeds total.</p>
41-
<UsageBar items={items} total={50} />
42-
</div>
43-
)
44-
}

0 commit comments

Comments
 (0)