var-panel.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use client'
  2. import { useBoolean } from 'ahooks'
  3. import type { FC } from 'react'
  4. import React, { useState } from 'react'
  5. import { useTranslation } from 'react-i18next'
  6. import {
  7. RiArrowDownSLine,
  8. RiArrowRightSLine,
  9. } from '@remixicon/react'
  10. import ImagePreview from '@/app/components/base/image-uploader/image-preview'
  11. type Props = {
  12. varList: { label: string; value: string }[]
  13. message_files: string[]
  14. }
  15. const VarPanel: FC<Props> = ({
  16. varList,
  17. message_files,
  18. }) => {
  19. const { t } = useTranslation()
  20. const [isCollapse, { toggle: toggleCollapse }] = useBoolean(false)
  21. const [imagePreviewUrl, setImagePreviewUrl] = useState('')
  22. return (
  23. <div className='rounded-xl border border-color-indigo-100 bg-indigo-25'>
  24. <div
  25. className='flex items-center h-6 pl-2 py-6 space-x-1 cursor-pointer'
  26. onClick={toggleCollapse}
  27. >
  28. {
  29. isCollapse
  30. ? <RiArrowRightSLine className='w-3 h-3 text-gray-300' />
  31. : <RiArrowDownSLine className='w-3 h-3 text-gray-300' />
  32. }
  33. <div className='text-sm font-semibold text-indigo-800 uppercase'>{t('appLog.detail.variables')}</div>
  34. </div>
  35. {!isCollapse && (
  36. <div className='px-6 pb-3'>
  37. {varList.map(({ label, value }, index) => (
  38. <div key={index} className='flex py-2 leading-[18px] text-[13px]'>
  39. <div className='shrink-0 w-[128px] flex text-primary-600'>
  40. <span className='shrink-0 opacity-60'>{'{{'}</span>
  41. <span className='truncate'>{label}</span>
  42. <span className='shrink-0 opacity-60'>{'}}'}</span>
  43. </div>
  44. <div className='pl-2.5 whitespace-pre-wrap'>{value}</div>
  45. </div>
  46. ))}
  47. {message_files.length > 0 && (
  48. <div className='mt-1 flex py-2'>
  49. <div className='shrink-0 w-[128px] leading-[18px] text-[13px] font-medium text-gray-700'>{t('appLog.detail.uploadImages')}</div>
  50. <div className="flex space-x-2">
  51. {message_files.map((url, index) => (
  52. <div
  53. key={index}
  54. className="ml-2.5 w-16 h-16 rounded-lg bg-no-repeat bg-cover bg-center cursor-pointer"
  55. style={{ backgroundImage: `url(${url})` }}
  56. onClick={() => setImagePreviewUrl(url)}
  57. />
  58. ))}
  59. </div>
  60. </div>
  61. )}
  62. </div>
  63. )}
  64. {
  65. imagePreviewUrl && (
  66. <ImagePreview
  67. url={imagePreviewUrl}
  68. onCancel={() => setImagePreviewUrl('')}
  69. />
  70. )
  71. }
  72. </div>
  73. )
  74. }
  75. export default React.memo(VarPanel)