vis-code.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { GPTVis } from '@antv/gpt-vis';
  2. import { CheckOutlined, CloseOutlined } from '@mui/icons-material';
  3. import classNames from 'classnames';
  4. import { useState } from 'react';
  5. import { useTranslation } from 'react-i18next';
  6. import { oneDark, oneLight } from 'react-syntax-highlighter/dist/esm/styles/prism';
  7. import remarkGfm from 'remark-gfm';
  8. import { CodePreview } from './code-preview';
  9. import markdownComponents from './config';
  10. interface Props {
  11. data: {
  12. code: string[];
  13. exit_success: true;
  14. language: string;
  15. log: string;
  16. };
  17. }
  18. function VisCode({ data }: Props) {
  19. const { t } = useTranslation();
  20. const [show, setShow] = useState(0);
  21. return (
  22. <div className='bg-[#EAEAEB] rounded overflow-hidden border border-theme-primary dark:bg-theme-dark text-sm'>
  23. <div>
  24. <div className='flex'>
  25. {data.code.map((item, index) => (
  26. <div
  27. key={index}
  28. className={classNames('px-4 py-2 text-[#121417] dark:text-white cursor-pointer', {
  29. 'bg-white dark:bg-theme-dark-container': index === show,
  30. })}
  31. onClick={() => {
  32. setShow(index);
  33. }}
  34. >
  35. CODE {index + 1}: {item[0]}
  36. </div>
  37. ))}
  38. </div>
  39. {data.code.length && (
  40. <CodePreview
  41. language={data.code[show][0]}
  42. code={data.code[show][1]}
  43. customStyle={{ maxHeight: 300, margin: 0 }}
  44. light={oneLight}
  45. dark={oneDark}
  46. />
  47. )}
  48. </div>
  49. <div>
  50. <div className='flex'>
  51. <div className='bg-white dark:bg-theme-dark-container px-4 py-2 text-[#121417] dark:text-white'>
  52. {t('Terminal')}{' '}
  53. {data.exit_success ? (
  54. <CheckOutlined className='text-green-600' />
  55. ) : (
  56. <CloseOutlined className='text-red-600' />
  57. )}
  58. </div>
  59. </div>
  60. <div className='p-4 max-h-72 overflow-y-auto whitespace-normal bg-white dark:dark:bg-theme-dark'>
  61. <GPTVis components={markdownComponents} remarkPlugins={[remarkGfm]}>
  62. {data.log}
  63. </GPTVis>
  64. </div>
  65. </div>
  66. </div>
  67. );
  68. }
  69. export default VisCode;