[UPD] made the progress bar easier to modify

This commit is contained in:
Chloé CHAUVIN
2022-09-26 12:24:05 +02:00
parent 0a216d0cff
commit eb5e44d6d6
+35 -16
View File
@@ -1,5 +1,4 @@
import React from "react"; import React from "react";
import { View } from "react-native";
const ProgressBar = ( const ProgressBar = (
props: { props: {
@@ -11,13 +10,17 @@ const ProgressBar = (
{ {
const { progress, maxValue, barWidth, title } = props; const { progress, maxValue, barWidth, title } = props;
const box = {
width: `${barWidth}%`,
height: 20,
margin: 20,
}
const containerStyles = { const containerStyles = {
height: 20, padding: 2,
width: `${barWidth}%`, backgroundColor: "#e0e0de",
backgroundColor: "#e0e0de", borderRadius: 50,
borderRadius: 50, }
margin: 20
}
function computePercent(progress: number, maxValue: number) function computePercent(progress: number, maxValue: number)
{ {
@@ -29,28 +32,43 @@ const ProgressBar = (
width: `${computePercent(progress, maxValue)}%`, width: `${computePercent(progress, maxValue)}%`,
backgroundColor: "#18A558", backgroundColor: "#18A558",
borderRadius: 'inherit', borderRadius: 'inherit',
textAlign: 'center' textAlign: 'center',
} }
const labelStyles = { const labelStyles = {
padding: 5, padding: 5,
color: 'white', color: 'white',
fontWeight: 'bold' fontWeight: 'bold',
}
const titleStyle = {
padding: 5,
color: 'black',
fontWeight: 'bold',
fontSize: 20,
textAlign: 'center',
} }
if (title != null) { if (title != null) {
// put the title in the middle TODO
return ( return (
<div style={containerStyles}> <div style={box}>
<div style={fillerStyles}> <div style={titleStyle}>
<span style={labelStyles}> {title}
{`${computePercent(progress, maxValue)}%`}
</span>
</div> </div>
<div style={containerStyles}>
<div style={fillerStyles}>
<span style={labelStyles}>
{`${computePercent(progress, maxValue)}%`}
</span>
</div>
</div>
<div><p>ceci est un sous titre yay</p></div>
</div> </div>
); );
} }
return ( return (
<div style={box}>
<div style={containerStyles}> <div style={containerStyles}>
<div style={fillerStyles}> <div style={fillerStyles}>
<span style={labelStyles}> <span style={labelStyles}>
@@ -58,6 +76,7 @@ const ProgressBar = (
</span> </span>
</div> </div>
</div> </div>
</div>
); );
} }