question.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import type {
  2. FC,
  3. ReactNode,
  4. } from 'react'
  5. import {
  6. memo,
  7. } from 'react'
  8. import type { ChatItem } from '../types'
  9. import type { Theme } from '../embedded-chatbot/theme/theme-context'
  10. import { CssTransform } from '../embedded-chatbot/theme/utils'
  11. import { QuestionTriangle } from '@/app/components/base/icons/src/vender/solid/general'
  12. import { User } from '@/app/components/base/icons/src/public/avatar'
  13. import { Markdown } from '@/app/components/base/markdown'
  14. import ImageGallery from '@/app/components/base/image-gallery'
  15. type QuestionProps = {
  16. item: ChatItem
  17. questionIcon?: ReactNode
  18. theme: Theme | null | undefined
  19. }
  20. const Question: FC<QuestionProps> = ({
  21. item,
  22. questionIcon,
  23. theme,
  24. }) => {
  25. const {
  26. content,
  27. message_files,
  28. } = item
  29. const imgSrcs = message_files?.length ? message_files.map(item => item.url) : []
  30. return (
  31. <div className='flex justify-end mb-2 last:mb-0 pl-10'>
  32. <div className='group relative mr-4'>
  33. <QuestionTriangle
  34. className='absolute -right-2 top-0 w-2 h-3 text-[#D1E9FF]/50'
  35. style={theme ? { color: theme.chatBubbleColor } : {}}
  36. />
  37. <div
  38. className='px-4 py-3 bg-[#D1E9FF]/50 rounded-b-2xl rounded-tl-2xl text-sm text-gray-900'
  39. style={theme?.chatBubbleColorStyle ? CssTransform(theme.chatBubbleColorStyle) : {}}
  40. >
  41. {
  42. !!imgSrcs.length && (
  43. <ImageGallery srcs={imgSrcs} />
  44. )
  45. }
  46. <Markdown content={content} />
  47. </div>
  48. <div className='mt-1 h-[18px]' />
  49. </div>
  50. <div className='shrink-0 w-10 h-10'>
  51. {
  52. questionIcon || (
  53. <div className='w-full h-full rounded-full border-[0.5px] border-black/5'>
  54. <User className='w-full h-full' />
  55. </div>
  56. )
  57. }
  58. </div>
  59. </div>
  60. )
  61. }
  62. export default memo(Question)