This commit is contained in:
Archer
2023-10-17 10:00:32 +08:00
committed by GitHub
parent dd8f2744bf
commit 3b776b6639
98 changed files with 1525 additions and 983 deletions

View File

@@ -0,0 +1,64 @@
import React, { useState } from 'react';
import MyModal from '../MyModal';
import { Box, Button, Grid, useTheme } from '@chakra-ui/react';
import { PromptTemplateItem } from '@fastgpt/core/ai/type';
import { ModalBody, ModalFooter } from '@chakra-ui/react';
const PromptTemplate = ({
title,
templates,
onClose,
onSuccess
}: {
title: string;
templates: PromptTemplateItem[];
onClose: () => void;
onSuccess: (e: string) => void;
}) => {
const theme = useTheme();
const [selectTemplateTitle, setSelectTemplateTitle] = useState<PromptTemplateItem>();
return (
<MyModal isOpen title={title} onClose={onClose}>
<ModalBody w={'600px'}>
<Grid gridTemplateColumns={['1fr', '1fr 1fr']} gridGap={4}>
{templates.map((item) => (
<Box
key={item.title}
border={theme.borders.base}
py={2}
px={2}
borderRadius={'md'}
cursor={'pointer'}
{...(item.title === selectTemplateTitle?.title
? {
bg: 'myBlue.100'
}
: {})}
onClick={() => setSelectTemplateTitle(item)}
>
<Box>{item.title}</Box>
<Box color={'myGray.600'} fontSize={'sm'} whiteSpace={'pre-wrap'}>
{item.value}
</Box>
</Box>
))}
</Grid>
</ModalBody>
<ModalFooter>
<Button
disabled={!selectTemplateTitle}
onClick={() => {
if (!selectTemplateTitle) return;
onSuccess(selectTemplateTitle.value);
onClose();
}}
>
</Button>
</ModalFooter>
</MyModal>
);
};
export default PromptTemplate;