If all you want to show is the percentage number then all I did was to add the percentage to the <p>
tag and used the percentage number used to increase the progress bar to display the percentage number.
Since the number increases from 0 to 1 as per the docs
, what we can do is to multiply the output by 100 and take a Math.floor
of that.
Codepen - Demo
const { ProgressIndicator, Fabric: FabricComponent, initializeIcons } = window.Fabric;
// Initialize icons in case this example uses them
initializeIcons();
const intervalDelay = 100;
const intervalIncrement = 0.01;
const ProgressIndicatorBasicExample: React.FunctionComponent = () => {
const [percentComplete, setPercentComplete] = React.useState(0);
React.useEffect(() => {
const id = setInterval(() => {
setPercentComplete((intervalIncrement + percentComplete) % 1);
}, intervalDelay);
return () => {
clearInterval(id);
};
});
return (
<>
<ProgressIndicator label="Example title" description="Example description"
percentComplete={percentComplete} />
<p>{Math.floor(percentComplete * 100)}%</p>
</>
);
};
const ProgressIndicatorBasicExampleWrapper = () => <FabricComponent><ProgressIndicatorBasicExample /></FabricComponent>;
ReactDOM.render(<ProgressIndicatorBasicExampleWrapper />, document.getElementById('content'))