Files
omni-tools/src/pages/home/Categories.tsx

100 lines
3.2 KiB
TypeScript
Raw Normal View History

2025-02-23 14:11:21 +00:00
import { getToolsByCategory } from '@tools/index';
import Grid from '@mui/material/Grid';
2025-03-31 01:27:44 +00:00
import { Box, Card, CardContent, Stack, useTheme } from '@mui/material';
2025-02-23 14:11:21 +00:00
import { Link, useNavigate } from 'react-router-dom';
import Typography from '@mui/material/Typography';
import Button from '@mui/material/Button';
import { useState } from 'react';
2025-02-25 06:17:28 +00:00
import { categoriesColors } from 'config/uiConfig';
2025-02-27 13:05:38 +00:00
import { Icon } from '@iconify/react';
2025-02-23 14:11:21 +00:00
type ArrayElement<ArrayType extends readonly unknown[]> =
ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
const SingleCategory = function ({
category,
index
}: {
category: ArrayElement<ReturnType<typeof getToolsByCategory>>;
index: number;
}) {
const navigate = useNavigate();
2025-03-31 01:27:44 +00:00
const theme = useTheme();
2025-02-23 14:11:21 +00:00
const [hovered, setHovered] = useState<boolean>(false);
const toggleHover = () => setHovered((prevState) => !prevState);
return (
<Grid
item
xs={12}
md={6}
onMouseEnter={toggleHover}
onMouseLeave={toggleHover}
>
<Card
sx={{
height: '100%',
2025-03-31 01:27:44 +00:00
backgroundColor: hovered ? 'background.hover' : 'background.paper'
2025-02-23 14:11:21 +00:00
}}
>
2025-02-27 13:09:02 +00:00
<CardContent sx={{ height: '100%' }}>
<Stack
direction={'column'}
height={'100%'}
justifyContent={'space-between'}
>
<Box>
<Stack direction={'row'} spacing={2} alignItems={'center'}>
<Icon
icon={category.icon}
fontSize={'60px'}
style={{
transform: `scale(${hovered ? 1.1 : 1}`
}}
color={categoriesColors[index % categoriesColors.length]}
/>
<Link
2025-03-31 01:27:44 +00:00
style={{
fontSize: 20,
fontWeight: 700,
color: theme.palette.mode === 'dark' ? 'white' : 'black'
}}
2025-02-27 13:09:02 +00:00
to={'/categories/' + category.type}
>
{category.title}
</Link>
</Stack>
<Typography sx={{ mt: 2 }}>{category.description}</Typography>
</Box>
<Grid mt={1} container spacing={2}>
<Grid item xs={12} md={6}>
<Button
fullWidth
onClick={() => navigate('/categories/' + category.type)}
variant={'contained'}
>{`See all ${category.title}`}</Button>
</Grid>
<Grid item xs={12} md={6}>
<Button
2025-03-31 01:27:44 +00:00
sx={{ backgroundColor: 'background.default' }}
2025-02-27 13:09:02 +00:00
fullWidth
onClick={() => navigate(category.example.path)}
variant={'outlined'}
>{`Try ${category.example.title}`}</Button>
</Grid>
2025-02-23 14:11:21 +00:00
</Grid>
2025-02-27 13:09:02 +00:00
</Stack>
2025-02-23 14:11:21 +00:00
</CardContent>
</Card>
</Grid>
);
};
export default function Categories() {
return (
<Grid width={'80%'} container mt={2} spacing={2}>
{getToolsByCategory().map((category, index) => (
<SingleCategory key={category.type} category={category} index={index} />
))}
</Grid>
);
}