2024-07-01 21:23:45 +02:00
|
|
|
import { StyleSheet, Text, TextInput, View } from "react-native";
|
|
|
|
import Slider from '@react-native-community/slider';
|
2024-07-02 17:34:23 +02:00
|
|
|
import { useEffect, useState } from "react";
|
2024-07-01 21:23:45 +02:00
|
|
|
|
|
|
|
type PercentDamageProps = {
|
|
|
|
onSetPercentage: (percent: number) => any;
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:34:23 +02:00
|
|
|
function getDamangeColor(damage : number) {
|
|
|
|
if (damage === 0) return "black";
|
|
|
|
if (damage <= 20) return "blue";
|
|
|
|
if (damage <= 50) return "orange";
|
|
|
|
return "red";
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function PercentDamage({ onSetPercentage }: PercentDamageProps) {
|
2024-07-01 21:23:45 +02:00
|
|
|
const [damage, setDamage] = useState(0);
|
2024-07-02 17:34:23 +02:00
|
|
|
const [damageColor, setDamageColor] = useState("black");
|
|
|
|
function doOnChangeText(val: number) {
|
|
|
|
setDamage(val || 0);
|
|
|
|
onSetPercentage((val / 100) || 0);
|
|
|
|
setDamageColor(getDamangeColor(val || 0));
|
2024-07-01 21:23:45 +02:00
|
|
|
}
|
2024-07-02 17:34:23 +02:00
|
|
|
|
2024-07-01 21:23:45 +02:00
|
|
|
return (
|
|
|
|
<View style={styles.wrapper}>
|
|
|
|
<Slider
|
|
|
|
minimumValue={0}
|
|
|
|
maximumValue={100}
|
|
|
|
step={5}
|
|
|
|
onValueChange={doOnChangeText}
|
2024-07-02 17:34:23 +02:00
|
|
|
/>
|
|
|
|
<Text style={{ ...styles.label, color: damageColor }}> {damage}% Damage</Text>
|
2024-07-01 21:23:45 +02:00
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
wrapper: {
|
|
|
|
padding: 5,
|
|
|
|
},
|
|
|
|
input: {
|
|
|
|
flex: 1,
|
|
|
|
margin: 5,
|
|
|
|
padding: 5,
|
|
|
|
borderWidth: 2,
|
|
|
|
borderColor: "lightgrey",
|
|
|
|
borderStyle: "solid",
|
|
|
|
},
|
|
|
|
label: {
|
|
|
|
margin: 5,
|
2024-07-02 17:34:23 +02:00
|
|
|
alignSelf: "center",
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: "bold",
|
|
|
|
fontStyle: "italic",
|
2024-07-01 21:23:45 +02:00
|
|
|
}
|
|
|
|
})
|