-
Notifications
You must be signed in to change notification settings - Fork 4
/
Progress.js
53 lines (49 loc) · 1.54 KB
/
Progress.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
import React from "react";
export default class Progress extends React.Component {
/**
* Static function that lets us select what props we want to comapre and accept
* @param {Object} props The new props collection
* @param {Object} state The current component state
*/
static getDerivedStateFromProps(props, state) {
if (state.value !== props.value) {
return {
value: props.value,
};
}
return null;
}
/**
* Constructor
* @param {Object} props Our initial React object properties
*/
constructor(props) {
super(props);
let display = props.display;
if (display) {
if (display.toLowerCase() === "false") {
display = false;
} else display = true;
} else display = true;
this.state = {
value: props.value,
display: display,
};
}
/**
* Function to render our UI
*/
render() {
const displayValue = this.state.display ? this.state.value + "%" : " ";
const progressStyles = { width: `${this.state.value}%` };
return (
<div className="progressOuterContainer">
<div className="progressInnerContainer" style={progressStyles}>
<span className="progressText">{displayValue}</span>
</div>
</div>
);
}
}