suggested-questions.tsx 994 B

123456789101112131415161718192021222324252627282930313233343536
  1. import type { FC } from 'react'
  2. import { memo } from 'react'
  3. import type { ChatItem } from '../../types'
  4. import { useChatContext } from '../context'
  5. type SuggestedQuestionsProps = {
  6. item: ChatItem
  7. }
  8. const SuggestedQuestions: FC<SuggestedQuestionsProps> = ({
  9. item,
  10. }) => {
  11. const { onSend } = useChatContext()
  12. const {
  13. isOpeningStatement,
  14. suggestedQuestions,
  15. } = item
  16. if (!isOpeningStatement || !suggestedQuestions?.length)
  17. return null
  18. return (
  19. <div className='flex flex-wrap'>
  20. {suggestedQuestions.filter(q => !!q && q.trim()).map((question, index) => (
  21. <div
  22. key={index}
  23. className='mt-1 mr-1 max-w-full last:mr-0 shrink-0 py-[5px] leading-[18px] items-center px-4 rounded-lg border border-gray-200 shadow-xs bg-white text-xs font-medium text-primary-600 cursor-pointer'
  24. onClick={() => onSend?.(question)}
  25. >
  26. {question}
  27. </div>),
  28. )}
  29. </div>
  30. )
  31. }
  32. export default memo(SuggestedQuestions)