omni-tools/src/components/examples/ExampleCard.tsx

132 lines
3.4 KiB
TypeScript
Raw Normal View History

import {
Box,
Card,
CardContent,
2024-06-26 09:02:05 +01:00
Stack,
2024-06-25 08:39:29 +01:00
TextField,
2024-06-26 09:02:05 +01:00
Typography,
2024-06-25 08:39:29 +01:00
useTheme
} from '@mui/material';
import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
2025-02-27 01:47:44 +00:00
import ExampleOptions from './ExampleOptions';
import { GetGroupsType } from '@components/options/ToolOptions';
export interface ExampleCardProps<T> {
title: string;
description: string;
2025-03-08 07:32:20 +00:00
sampleText?: string;
2025-02-27 01:47:44 +00:00
sampleResult: string;
sampleOptions: T;
2025-03-08 07:32:20 +00:00
changeInputResult: (newInput: string | undefined, newOptions: T) => void;
2025-03-08 06:43:11 +00:00
getGroups: GetGroupsType<T> | null;
2025-02-27 01:47:44 +00:00
}
2025-02-27 01:26:48 +00:00
export default function ExampleCard<T>({
title,
description,
sampleText,
sampleResult,
2025-02-27 01:47:44 +00:00
sampleOptions,
2025-02-27 01:26:48 +00:00
changeInputResult,
getGroups
}: ExampleCardProps<T>) {
2024-06-25 08:39:29 +01:00
const theme = useTheme();
return (
<Card
raised
2025-02-27 01:26:48 +00:00
onClick={() => {
2025-02-27 13:05:38 +00:00
changeInputResult(sampleText, sampleOptions);
2025-02-27 01:26:48 +00:00
}}
sx={{
2025-03-31 01:27:44 +00:00
bgcolor: 'background.lightSecondary',
height: '100%',
overflow: 'hidden',
borderRadius: 2,
transition: 'background-color 0.3s ease',
2025-02-27 01:26:48 +00:00
cursor: 'pointer',
'&:hover': {
2025-03-31 01:27:44 +00:00
boxShadow: `12px 9px 11px 2px ${
theme.palette.mode === 'dark' ? theme.palette.grey[900] : '#b8b9be'
}, -6px -6px 12px ${theme.palette.mode === 'dark' ? 'black' : '#fff'}`
}
}}
>
<CardContent>
<Box display="flex" justifyContent="space-between" borderRadius="5px">
<Typography variant="h5" component="h2">
{title}
</Typography>
</Box>
<Stack direction={'column'} alignItems={'center'} spacing={2}>
<Typography variant="body2" color="text.secondary">
{description}
</Typography>
2024-06-24 20:19:49 -07:00
2025-03-09 01:50:09 +00:00
{sampleText && (
<Box
sx={{
2025-03-09 01:50:09 +00:00
display: 'flex',
zIndex: '2',
width: '100%',
height: '100%',
bgcolor: 'transparent',
padding: '5px 10px',
borderRadius: '5px',
boxShadow:
'inset 2px 2px 5px #b8b9be, inset -3px -3px 7px #fff;'
}}
2025-03-09 01:50:09 +00:00
>
<TextField
value={sampleText}
disabled
fullWidth
multiline
sx={{
'& .MuiOutlinedInput-root': {
zIndex: '-1',
'& fieldset': {
border: 'none'
}
}
}}
/>
</Box>
)}
2024-06-24 20:19:49 -07:00
<ArrowDownwardIcon />
<Box
sx={{
2024-06-24 20:19:49 -07:00
display: 'flex',
zIndex: '2',
width: '100%',
2024-06-24 20:19:49 -07:00
height: '100%',
bgcolor: 'transparent',
padding: '5px 10px',
borderRadius: '5px',
2024-06-24 20:19:49 -07:00
cursor: 'pointer',
boxShadow: 'inset 2px 2px 5px #b8b9be, inset -3px -3px 7px #fff;'
}}
>
<TextField
value={sampleResult}
disabled
fullWidth
multiline
sx={{
'& .MuiOutlinedInput-root': {
2024-06-24 20:19:49 -07:00
zIndex: '-1',
'& fieldset': {
border: 'none'
}
}
}}
/>
</Box>
2025-02-27 01:47:44 +00:00
<ExampleOptions options={sampleOptions} getGroups={getGroups} />
</Stack>
</CardContent>
</Card>
);
}