Files
omni-tools/src/components/examples/ToolExamples.tsx

71 lines
2.1 KiB
TypeScript
Raw Normal View History

import { Box, Grid, Stack, Typography } from '@mui/material';
2025-02-27 01:47:44 +00:00
import ExampleCard, { ExampleCardProps } from './ExampleCard';
2025-02-27 01:26:48 +00:00
import React from 'react';
import { GetGroupsType } from '@components/options/ToolOptions';
2025-03-10 04:13:10 +00:00
import { useFormikContext } from 'formik';
2025-07-12 23:02:35 -07:00
import { useTranslation } from 'react-i18next';
2025-02-27 02:21:08 +00:00
export type CardExampleType<T> = Omit<
ExampleCardProps<T>,
'getGroups' | 'changeInputResult'
>;
export interface ExampleProps<T> {
title: string;
2025-02-27 02:21:08 +00:00
subtitle?: string;
exampleCards: CardExampleType<T>[];
2025-03-08 06:43:11 +00:00
getGroups: GetGroupsType<T> | null;
2025-03-08 07:32:20 +00:00
setInput?: React.Dispatch<React.SetStateAction<any>>;
}
2025-02-27 02:21:08 +00:00
export default function ToolExamples<T>({
title,
subtitle,
2025-02-27 01:26:48 +00:00
exampleCards,
getGroups,
2025-02-27 13:05:38 +00:00
setInput
2025-02-27 01:26:48 +00:00
}: ExampleProps<T>) {
2025-07-12 23:02:35 -07:00
const { t } = useTranslation();
2025-03-10 04:13:10 +00:00
const { setValues } = useFormikContext<T>();
2025-03-08 07:32:20 +00:00
function changeInputResult(newInput: string | undefined, newOptions: T) {
setInput?.(newInput);
2025-03-10 04:13:10 +00:00
setValues(newOptions);
2025-02-27 02:21:08 +00:00
const toolsElement = document.getElementById('tool');
if (toolsElement) {
toolsElement.scrollIntoView({ behavior: 'smooth' });
}
}
return (
2024-06-25 08:39:29 +01:00
<Box id={'examples'} mt={4}>
<Box mt={4} display="flex" gap={1} alignItems="center">
<Typography mb={2} fontSize={30} color={'primary'}>
2025-07-12 23:02:35 -07:00
{t('toolExamples.title', { title })}
</Typography>
<Typography mb={2} fontSize={30} color={'secondary'}>
2025-07-12 23:02:35 -07:00
{subtitle ?? t('toolExamples.subtitle')}
</Typography>
</Box>
<Stack direction={'row'} alignItems={'center'} spacing={2}>
<Grid container spacing={2}>
2024-06-24 21:00:42 -07:00
{exampleCards.map((card, index) => (
2024-06-26 00:49:26 +01:00
<Grid item xs={12} md={6} lg={4} key={index}>
<ExampleCard
title={card.title}
description={card.description}
sampleText={card.sampleText}
sampleResult={card.sampleResult}
2025-02-27 01:47:44 +00:00
sampleOptions={card.sampleOptions}
2025-02-27 01:26:48 +00:00
getGroups={getGroups}
changeInputResult={changeInputResult}
/>
</Grid>
))}
</Grid>
</Stack>
</Box>
);
}