omni-tools/src/components/ToolHeader.tsx

127 lines
3.3 KiB
TypeScript
Raw Normal View History

2025-02-25 13:41:57 +00:00
import { Box, Button, styled, useTheme } from '@mui/material';
2024-06-22 22:06:16 +01:00
import Typography from '@mui/material/Typography';
2024-06-25 19:45:29 +01:00
import ToolBreadcrumb from './ToolBreadcrumb';
import { capitalizeFirstLetter } from '../utils/string';
2024-06-26 00:47:21 +01:00
import Grid from '@mui/material/Grid';
2025-02-25 06:17:10 +00:00
import { Icon, IconifyIcon } from '@iconify/react';
import { categoriesColors } from '../config/uiConfig';
2025-04-02 04:25:02 +00:00
import { getToolsByCategory } from '@tools/index';
2025-07-09 17:47:44 +01:00
import { useEffect, useState } from 'react';
2024-06-19 21:18:35 +01:00
2025-02-25 13:41:57 +00:00
const StyledButton = styled(Button)(({ theme }) => ({
backgroundColor: 'white',
'&:hover': {
backgroundColor: theme.palette.primary.main,
color: 'white'
}
}));
2024-06-19 21:18:35 +01:00
interface ToolHeaderProps {
title: string;
description: string;
2025-02-25 06:24:00 +00:00
icon?: IconifyIcon | string;
2024-06-25 19:45:29 +01:00
type: string;
2024-06-19 21:18:35 +01:00
}
2024-06-23 01:35:40 -07:00
function ToolLinks() {
2025-07-09 17:47:44 +01:00
const [examplesVisible, setExamplesVisible] = useState(false);
useEffect(() => {
const timeout = setTimeout(() => {
const element = document.getElementById('examples');
if (element && isVisible(element)) {
setExamplesVisible(true);
}
}, 500);
return () => clearTimeout(timeout);
}, []);
2025-02-25 13:41:57 +00:00
const scrollToElement = (id: string) => {
document.getElementById(id)?.scrollIntoView({ behavior: 'smooth' });
};
2025-07-09 17:47:44 +01:00
function isVisible(elm: HTMLElement | null) {
return !!elm;
}
2024-06-23 01:35:40 -07:00
return (
2024-06-26 00:47:21 +01:00
<Grid container spacing={2} mt={1}>
2025-02-27 02:21:08 +00:00
<Grid item md={12} lg={6}>
2025-02-25 13:41:57 +00:00
<StyledButton
2025-03-31 01:27:44 +00:00
sx={{ backgroundColor: 'background.paper' }}
2025-02-25 06:17:10 +00:00
fullWidth
variant="outlined"
onClick={() => scrollToElement('tool')}
2025-02-25 06:17:10 +00:00
>
2024-06-26 00:47:21 +01:00
Use This Tool
2025-02-25 13:41:57 +00:00
</StyledButton>
2024-06-26 00:47:21 +01:00
</Grid>
2025-07-09 17:47:44 +01:00
{examplesVisible && (
<Grid item md={12} lg={6}>
<StyledButton
fullWidth
variant="outlined"
sx={{ backgroundColor: 'background.paper' }}
onClick={() => scrollToElement('examples')}
>
See Examples
</StyledButton>
</Grid>
)}
2025-02-27 02:21:08 +00:00
{/*<Grid item md={12} lg={4}>*/}
{/* <StyledButton fullWidth variant="outlined" href="#tour">*/}
{/* Learn How to Use*/}
{/* </StyledButton>*/}
{/*</Grid>*/}
2024-06-26 00:47:21 +01:00
</Grid>
2024-06-23 01:35:40 -07:00
);
}
2024-06-23 01:26:04 +01:00
export default function ToolHeader({
2025-02-25 06:17:10 +00:00
icon,
2024-06-23 01:26:04 +01:00
title,
2024-06-25 19:45:29 +01:00
description,
type
2024-06-23 01:26:04 +01:00
}: ToolHeaderProps) {
2024-06-22 22:06:16 +01:00
return (
2024-06-25 19:45:29 +01:00
<Box my={4}>
<ToolBreadcrumb
items={[
{ title: 'All tools', link: '/' },
{
2025-04-02 04:25:02 +00:00
title: getToolsByCategory().find(
(category) => category.type === type
)!.rawTitle,
2024-06-25 19:45:29 +01:00
link: '/categories/' + type
},
{ title }
]}
/>
2024-06-26 00:47:21 +01:00
<Grid mt={1} container spacing={2}>
<Grid item xs={12} md={8}>
2024-06-25 19:45:29 +01:00
<Typography mb={2} fontSize={30} color={'primary'}>
{title}
</Typography>
<Typography fontSize={20}>{description}</Typography>
<ToolLinks />
2024-06-26 00:47:21 +01:00
</Grid>
2025-02-25 06:17:10 +00:00
{icon && (
2024-06-26 00:47:21 +01:00
<Grid item xs={12} md={4}>
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
2025-02-25 06:17:10 +00:00
<Icon
icon={icon}
fontSize={'250'}
color={
categoriesColors[
Math.floor(Math.random() * categoriesColors.length)
]
}
/>
2024-06-26 00:47:21 +01:00
</Box>
</Grid>
)}
</Grid>
2024-06-25 19:45:29 +01:00
</Box>
2024-06-22 22:06:16 +01:00
);
2024-06-19 21:18:35 +01:00
}