var-panel.tsx 2.6 KB

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