Skip to content

Commit 198244c

Browse files
authored
feat(progressBar): add ProgressBar component (#442)
* feat(progressBar): add ProgressBar component * fix(progress bar): typo of text description * v2.10.0
1 parent fe01347 commit 198244c

8 files changed

Lines changed: 172 additions & 1 deletion

File tree

copy-assets.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ copyFileSync(
4242
copyFileSync("src/components/pill/index.d.ts", "lib/components/pill/index.d.ts")
4343
copyFileSync("src/components/pill/alertMastercard.d.ts", "lib/components/pill/alertMastercard.d.ts")
4444
copyFileSync("src/components/pill/mastercard.d.ts", "lib/components/pill/mastercard.d.ts")
45+
46+
copyFileSync("src/components/progressBar/index.d.ts", "lib/components/progressBar/index.d.ts")
47+
4548
copyFileSync(
4649
"src/components/sidebar/portaled-sidebar.d.ts",
4750
"lib/components/sidebar/portaled-sidebar.d.ts"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netdata/netdata-ui",
3-
"version": "2.9.6",
3+
"version": "2.10.0",
44
"description": "netdata UI kit",
55
"main": "./lib/index.js",
66
"files": [
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## ProgressBar component
2+
3+
The progress bar component is used to visualise the progress of one ore more than one elements as bar style.
4+
5+
### Props:
6+
7+
```typescript
8+
interface ProgressBarProps {
9+
background?: string
10+
className?: string
11+
color?: string
12+
"data-testid"?: string
13+
containerWidth?: string
14+
height?: number
15+
value?: Value[]
16+
width?: string
17+
[s: string]: any
18+
}
19+
```
20+
21+
### Typical usage:
22+
23+
```JSX
24+
export const ProgressBars = () => (
25+
<div>
26+
<ProgressBar width="40%" />
27+
<ProgressBar
28+
value={[
29+
{ color: ["blue", "indigo"], width: "30%" },
30+
{ color: ["green", "limeGreen"], width: "60%" },
31+
]}
32+
/>
33+
</div>
34+
)
35+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { FC } from "react"
2+
3+
export interface Value {
4+
color?: string
5+
width?: string
6+
[key: string]: any
7+
}
8+
9+
export interface ProgressBarProps {
10+
background?: string
11+
className?: string
12+
color?: string
13+
"data-testid"?: string
14+
containerWidth?: string
15+
height?: number
16+
value?: Value[]
17+
width?: string
18+
[s: string]: any
19+
}
20+
21+
declare const ProgressBar: FC<ProgressBarProps>
22+
23+
export { ProgressBar }
24+
25+
export default ProgressBar
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React, { forwardRef } from "react"
2+
import Box from "src/components/templates/box"
3+
import Flex from "src/components/templates/flex"
4+
5+
const ProgressBar = forwardRef(
6+
(
7+
{
8+
background = "nodeBadgeBackground",
9+
className,
10+
color = "text",
11+
containerWidth = "100%",
12+
height = 2,
13+
value,
14+
width,
15+
...rest
16+
},
17+
ref
18+
) => {
19+
value = Array.isArray(value) ? value : [value || { width, color }]
20+
21+
return (
22+
<Flex
23+
background={background}
24+
border={{ side: "all", color: background }}
25+
className={className}
26+
data-testid="progressBar"
27+
height={height}
28+
ref={ref}
29+
round="2px"
30+
width={containerWidth}
31+
{...rest}
32+
>
33+
{value.map(({ color, width }, index) =>
34+
width === "0%" ? null : (
35+
<Box
36+
background={color}
37+
border={{ side: "all", color }}
38+
data-testid={`progressBar-progress${width}`}
39+
height="100%"
40+
key={`${width}-${index}`}
41+
position="relative"
42+
round="2px"
43+
width={width}
44+
/>
45+
)
46+
)}
47+
</Flex>
48+
)
49+
}
50+
)
51+
52+
export default ProgressBar
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from "react"
2+
import { storiesOf } from "@storybook/react"
3+
import Flex from "src/components/templates/flex"
4+
import ProgressBar from "."
5+
6+
const story = storiesOf("Atoms/ProgressBar", module)
7+
8+
const Default = () => (
9+
<Flex width="300px">
10+
<ProgressBar width="80%" color={["blue", "aquamarine"]} background={["purple", "lilac"]} />
11+
</Flex>
12+
)
13+
14+
const WithValue = () => (
15+
<Flex width="300px">
16+
<ProgressBar
17+
value={[
18+
{ color: ["blue", "indigo"], width: "20%" },
19+
{ color: ["green", "limeGreen"], width: "60%" },
20+
]}
21+
background={["yellow", "seaBuckthorn"]}
22+
/>
23+
</Flex>
24+
)
25+
26+
story.add("Default", Default)
27+
story.add("WithValue", WithValue)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from "react"
2+
import { renderWithProviders, screen } from "testUtilities"
3+
import ProgressBar from "."
4+
5+
describe("ProgressBar component", () => {
6+
test("should render component with width", () => {
7+
renderWithProviders(<ProgressBar width="20%" />)
8+
9+
expect(screen.getByTestId("progressBar")).toBeInTheDocument()
10+
expect(screen.getByTestId("progressBar-progress20%")).toBeInTheDocument()
11+
})
12+
13+
test("should render component with value", () => {
14+
renderWithProviders(
15+
<ProgressBar
16+
value={[
17+
{ color: ["blue", "indigo"], width: "30%" },
18+
{ color: ["green", "limeGreen"], width: "60%" },
19+
]}
20+
/>
21+
)
22+
23+
expect(screen.getByTestId("progressBar")).toBeInTheDocument()
24+
expect(screen.getByTestId("progressBar-progress30%")).toBeInTheDocument()
25+
expect(screen.getByTestId("progressBar-progress60%")).toBeInTheDocument()
26+
})
27+
})

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ export { default as useIntersection } from "./hooks/use-intersection"
102102

103103
export { default as Pill } from "./components/pill"
104104

105+
export { default as ProgressBar } from "./components/progressBar"
106+
105107
export { default as AlertMasterCard } from "./components/pill/alertMastercard"
106108
export { default as MasterCard } from "./components/pill/mastercard"
107109

0 commit comments

Comments
 (0)