This repository has been archived on 2026-04-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
interaktive-systeme/components/stats/CategoryProgressBarList.tsx
2024-01-02 14:38:47 +01:00

61 lines
No EOL
1.7 KiB
TypeScript

import React, { useState } from 'react';
import { View, Text, Button, StyleSheet, TouchableOpacity } from 'react-native';
import CategoryProgressBar from './CategoryProgressBar';
import { useTheme } from '../../app/contexts/ThemeContext';
interface CategoryItem {
name: string;
color: string;
maxValue: number;
currentValue: number;
}
interface CategoryProgressBarListProps {
categories: CategoryItem[];
}
const MAX_VISIBLE_BARS = 4;
const CategoryProgressBarList: React.FC<CategoryProgressBarListProps> = ({ categories }) => {
const [visibleBars, setVisibleBars] = useState(MAX_VISIBLE_BARS);
const showMore = () => {
setVisibleBars(prevVisibleBars => prevVisibleBars + MAX_VISIBLE_BARS);
};
return (
<View>
{categories.slice(0, visibleBars).map((category, index) => (
<CategoryProgressBar
key={index}
categoryName={category.name}
color={category.color}
maxValue={category.maxValue}
currentValue={category.currentValue}
/>
))}
{visibleBars < categories.length && (
<TouchableOpacity style={styles.showMoreButton} onPress={showMore}>
<Text style={styles.buttonText}>Show More</Text>
</TouchableOpacity>
)}
</View>
);
};
const styles = StyleSheet.create({
showMoreButton: {
backgroundColor: '#EF6C00',
padding: 10,
borderRadius: 5,
margin: 10,
alignItems: 'center',
},
buttonText: {
color: 'white',
fontSize: 16,
fontWeight: 'bold',
},
});
export default CategoryProgressBarList;