14
14
// You should have received a copy of the GNU Affero General Public License
15
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
17
- import React , { Fragment } from "react" ;
18
- import { styled } from "@mui/material/styles" ;
19
- import LinearProgress , {
20
- linearProgressClasses ,
21
- LinearProgressProps ,
22
- } from "@mui/material/LinearProgress" ;
23
- import Box from "@mui/material/Box" ;
17
+ import React from "react" ;
18
+ import { ProgressBar , ProgressBarProps } from "mds" ;
24
19
25
20
interface IProgressBarWrapper {
26
21
value : number ;
@@ -30,62 +25,28 @@ interface IProgressBarWrapper {
30
25
size ?: string ;
31
26
error ?: boolean ;
32
27
cancelled ?: boolean ;
28
+ notificationLabel ?: string ;
33
29
}
34
30
35
- const BorderLinearProgress = styled ( LinearProgress ) ( ( ) => ( {
36
- height : 10 ,
37
- borderRadius : 5 ,
38
- [ `&.${ linearProgressClasses . colorPrimary } ` ] : {
39
- backgroundColor : "#f1f1f1" ,
40
- } ,
41
- [ `& .${ linearProgressClasses . bar } ` ] : {
42
- borderRadius : 5 ,
43
- } ,
44
- } ) ) ;
45
- const SmallBorderLinearProgress = styled ( BorderLinearProgress ) ( ( ) => ( {
46
- height : 6 ,
47
- borderRadius : 3 ,
48
- [ `& .${ linearProgressClasses . bar } ` ] : {
49
- borderRadius : 3 ,
50
- } ,
51
- } ) ) ;
52
-
53
31
function LinearProgressWithLabel (
54
- props : { error : boolean ; cancelled : boolean } & LinearProgressProps ,
32
+ props : { error : boolean ; cancelled : boolean } & ProgressBarProps ,
55
33
) {
56
- let color = "#000" ;
57
- let size = 18 ;
34
+ let label = "" ;
58
35
59
36
if ( props . error ) {
60
- color = "#C83B51" ;
61
- size = 14 ;
37
+ label = `Error: ${ props . notificationLabel || "" } ` ;
62
38
} else if ( props . cancelled ) {
63
- color = "#FFBD62" ;
64
- size = 14 ;
39
+ label = `Cancelled` ;
65
40
}
66
41
67
42
return (
68
- < Box sx = { { display : "flex" , alignItems : "center" } } >
69
- < Box sx = { { width : "100%" , mr : 3 } } >
70
- < BorderLinearProgress variant = "determinate" { ...props } />
71
- </ Box >
72
- < Box
73
- sx = { {
74
- minWidth : 35 ,
75
- fontSize : size ,
76
- color : color ,
77
- } }
78
- className = { "value" }
79
- >
80
- { props . cancelled ? (
81
- "Cancelled"
82
- ) : (
83
- < Fragment >
84
- { props . error ? "Failed" : `${ Math . round ( props . value || 0 ) } %` }
85
- </ Fragment >
86
- ) }
87
- </ Box >
88
- </ Box >
43
+ < ProgressBar
44
+ variant = { "determinate" }
45
+ value = { props . value }
46
+ color = { props . color }
47
+ progressLabel
48
+ notificationLabel = { label }
49
+ />
89
50
) ;
90
51
}
91
52
@@ -97,22 +58,24 @@ const ProgressBarWrapper = ({
97
58
size = "regular" ,
98
59
error,
99
60
cancelled,
61
+ notificationLabel,
100
62
} : IProgressBarWrapper ) => {
101
63
let color : any ;
102
64
if ( error ) {
103
- color = "error " ;
65
+ color = "red " ;
104
66
} else if ( cancelled ) {
105
- color = "warning " ;
67
+ color = "orange " ;
106
68
} else if ( value === 100 && ready ) {
107
- color = "success " ;
69
+ color = "green " ;
108
70
} else {
109
- color = "primary " ;
71
+ color = "blue " ;
110
72
}
111
- const propsComponent : LinearProgressProps = {
73
+ const propsComponent : ProgressBarProps = {
112
74
variant :
113
75
indeterminate && ! ready && ! cancelled ? "indeterminate" : "determinate" ,
114
76
value : ready ? 100 : value ,
115
77
color : color ,
78
+ notificationLabel : notificationLabel || "" ,
116
79
} ;
117
80
if ( withLabel ) {
118
81
return (
@@ -124,10 +87,12 @@ const ProgressBarWrapper = ({
124
87
) ;
125
88
}
126
89
if ( size === "small" ) {
127
- return < SmallBorderLinearProgress { ...propsComponent } /> ;
90
+ return (
91
+ < ProgressBar { ...propsComponent } sx = { { height : 6 , borderRadius : 6 } } />
92
+ ) ;
128
93
}
129
94
130
- return < BorderLinearProgress { ...propsComponent } /> ;
95
+ return < ProgressBar { ...propsComponent } /> ;
131
96
} ;
132
97
133
98
export default ProgressBarWrapper ;
0 commit comments