2024-06-24 20:09:16 -07:00
|
|
|
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-02-27 02:21:08 +00:00
|
|
|
import { FormikProps } from 'formik';
|
2024-06-24 20:09:16 -07:00
|
|
|
|
2025-02-27 02:21:08 +00:00
|
|
|
export type CardExampleType<T> = Omit<
|
|
|
|
|
ExampleCardProps<T>,
|
|
|
|
|
'getGroups' | 'changeInputResult'
|
|
|
|
|
>;
|
|
|
|
|
|
|
|
|
|
export interface ExampleProps<T> {
|
2024-06-24 20:09:16 -07:00
|
|
|
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-02-27 02:21:08 +00:00
|
|
|
formRef: React.RefObject<FormikProps<T>>;
|
2025-03-05 22:05:10 +00:00
|
|
|
setInput: React.Dispatch<React.SetStateAction<any>>;
|
2024-06-24 20:09:16 -07:00
|
|
|
}
|
|
|
|
|
|
2025-02-27 02:21:08 +00:00
|
|
|
export default function ToolExamples<T>({
|
2024-06-24 20:09:16 -07:00
|
|
|
title,
|
|
|
|
|
subtitle,
|
2025-02-27 01:26:48 +00:00
|
|
|
exampleCards,
|
|
|
|
|
getGroups,
|
2025-02-27 13:05:38 +00:00
|
|
|
formRef,
|
|
|
|
|
setInput
|
2025-02-27 01:26:48 +00:00
|
|
|
}: ExampleProps<T>) {
|
2025-02-27 13:05:38 +00:00
|
|
|
function changeInputResult(newInput: string, newOptions: T) {
|
|
|
|
|
setInput(newInput);
|
2025-02-27 02:21:08 +00:00
|
|
|
formRef.current?.setValues(newOptions);
|
|
|
|
|
const toolsElement = document.getElementById('tool');
|
|
|
|
|
if (toolsElement) {
|
|
|
|
|
toolsElement.scrollIntoView({ behavior: 'smooth' });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-24 20:09:16 -07:00
|
|
|
return (
|
2024-06-25 08:39:29 +01:00
|
|
|
<Box id={'examples'} mt={4}>
|
2024-06-24 20:09:16 -07:00
|
|
|
<Box mt={4} display="flex" gap={1} alignItems="center">
|
|
|
|
|
<Typography mb={2} fontSize={30} color={'primary'}>
|
2025-02-27 02:21:08 +00:00
|
|
|
{`${title} Examples`}
|
2024-06-24 20:09:16 -07:00
|
|
|
</Typography>
|
|
|
|
|
<Typography mb={2} fontSize={30} color={'secondary'}>
|
2025-02-27 02:21:08 +00:00
|
|
|
{subtitle ?? 'Click to try!'}
|
2024-06-24 20:09:16 -07:00
|
|
|
</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}>
|
2024-06-24 20:09:16 -07:00
|
|
|
<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}
|
2024-06-24 20:09:16 -07:00
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
))}
|
|
|
|
|
</Grid>
|
|
|
|
|
</Stack>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|