[UPD] made the progress bar easier to modify
This commit is contained in:
@@ -1,25 +1,28 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { View } from "react-native";
|
|
||||||
|
|
||||||
const ProgressBar = (
|
const ProgressBar = (
|
||||||
props: {
|
props: {
|
||||||
progress: number;
|
progress: number;
|
||||||
maxValue: number;
|
maxValue: number;
|
||||||
barWidth: number;
|
barWidth: number;
|
||||||
title?: string;
|
title?: string;
|
||||||
}) =>
|
}) =>
|
||||||
{
|
{
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
return progress * 100 / maxValue;;
|
return progress * 100 / maxValue;;
|
||||||
}
|
}
|
||||||
@@ -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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user