You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

var-panel.tsx 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 { Variable02 } from '@/app/components/base/icons/src/vender/solid/development'
  11. import ImagePreview from '@/app/components/base/image-uploader/image-preview'
  12. import cn from '@/utils/classnames'
  13. type Props = {
  14. varList: { label: string; value: string }[]
  15. message_files: string[]
  16. }
  17. const VarPanel: FC<Props> = ({
  18. varList,
  19. message_files,
  20. }) => {
  21. const { t } = useTranslation()
  22. const [isCollapse, { toggle: toggleCollapse }] = useBoolean(false)
  23. const [imagePreviewUrl, setImagePreviewUrl] = useState('')
  24. return (
  25. <div className='rounded-[10px] border border-divider-subtle bg-chat-bubble-bg'>
  26. <div
  27. className={cn('flex items-center gap-1 px-3 pt-2.5 pb-2 border-b border-divider-subtle text-text-secondary cursor-pointer', isCollapse && 'pb-2.5 border-0')}
  28. onClick={toggleCollapse}
  29. >
  30. <Variable02 className='w-4 h-4' />
  31. <div className='grow system-md-medium'>{t('appLog.detail.variables')}</div>
  32. {
  33. isCollapse
  34. ? <RiArrowRightSLine className='w-4 h-4' />
  35. : <RiArrowDownSLine className='w-4 h-4' />
  36. }
  37. </div>
  38. {!isCollapse && (
  39. <div className='p-3 flex flex-col gap-2'>
  40. {varList.map(({ label, value }, index) => (
  41. <div key={index} className='flex py-2 system-xs-medium'>
  42. <div className='shrink-0 w-[128px] flex text-text-accent'>
  43. <span className='shrink-0 opacity-60'>{'{{'}</span>
  44. <span className='truncate'>{label}</span>
  45. <span className='shrink-0 opacity-60'>{'}}'}</span>
  46. </div>
  47. <div className='pl-2.5 whitespace-pre-wrap text-text-secondary'>{value}</div>
  48. </div>
  49. ))}
  50. {message_files.length > 0 && (
  51. <div className='mt-1 flex py-2'>
  52. <div className='shrink-0 w-[128px] system-xs-medium text-text-tertiary'>{t('appLog.detail.uploadImages')}</div>
  53. <div className="flex space-x-2">
  54. {message_files.map((url, index) => (
  55. <div
  56. key={index}
  57. className="ml-2.5 w-16 h-16 rounded-lg bg-no-repeat bg-cover bg-center cursor-pointer"
  58. style={{ backgroundImage: `url(${url})` }}
  59. onClick={() => setImagePreviewUrl(url)}
  60. />
  61. ))}
  62. </div>
  63. </div>
  64. )}
  65. </div>
  66. )}
  67. {
  68. imagePreviewUrl && (
  69. <ImagePreview
  70. url={imagePreviewUrl}
  71. title={imagePreviewUrl}
  72. onCancel={() => setImagePreviewUrl('')}
  73. />
  74. )
  75. }
  76. </div>
  77. )
  78. }
  79. export default React.memo(VarPanel)