header.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import {
  4. Bars3Icon,
  5. PencilSquareIcon,
  6. } from '@heroicons/react/24/solid'
  7. import { useTranslation } from 'react-i18next'
  8. import AppIcon from '@/app/components/base/app-icon'
  9. import { ReplayIcon } from '@/app/components/app/chat/icon-component'
  10. import Tooltip from '@/app/components/base/tooltip'
  11. export type IHeaderProps = {
  12. title: string
  13. customerIcon?: React.ReactNode
  14. icon: string
  15. icon_background: string
  16. isMobile?: boolean
  17. isEmbedScene?: boolean
  18. onShowSideBar?: () => void
  19. onCreateNewChat?: () => void
  20. }
  21. const Header: FC<IHeaderProps> = ({
  22. title,
  23. isMobile,
  24. customerIcon,
  25. icon,
  26. icon_background,
  27. isEmbedScene = false,
  28. onShowSideBar,
  29. onCreateNewChat,
  30. }) => {
  31. const { t } = useTranslation()
  32. if (!isMobile)
  33. return null
  34. if (isEmbedScene) {
  35. return (
  36. <div
  37. className={`
  38. shrink-0 flex items-center justify-between h-14 px-4 bg-gray-100
  39. bg-gradient-to-r from-blue-600 to-sky-500
  40. `}
  41. >
  42. <div className="flex items-center space-x-2">
  43. {customerIcon || <AppIcon size="small" icon={icon} background={icon_background} />}
  44. <div
  45. className={'text-sm font-bold text-white'}
  46. >
  47. {title}
  48. </div>
  49. </div>
  50. <Tooltip
  51. selector={'embed-scene-restart-button'}
  52. htmlContent={t('share.chat.resetChat')}
  53. position='top'
  54. >
  55. <div className='flex cursor-pointer hover:rounded-lg hover:bg-black/5 w-8 h-8 items-center justify-center' onClick={() => {
  56. onCreateNewChat?.()
  57. }}>
  58. <ReplayIcon className="h-4 w-4 text-sm font-bold text-white" />
  59. </div>
  60. </Tooltip>
  61. </div>
  62. )
  63. }
  64. return (
  65. <div className="shrink-0 flex items-center justify-between h-14 px-4 bg-gray-100">
  66. <div
  67. className='flex items-center justify-center h-8 w-8 cursor-pointer'
  68. onClick={() => onShowSideBar?.()}
  69. >
  70. <Bars3Icon className="h-4 w-4 text-gray-500" />
  71. </div>
  72. <div className='flex items-center space-x-2'>
  73. <AppIcon size="small" icon={icon} background={icon_background} />
  74. <div className=" text-sm text-gray-800 font-bold">{title}</div>
  75. </div>
  76. <div className='flex items-center justify-center h-8 w-8 cursor-pointer'
  77. onClick={() => onCreateNewChat?.()}
  78. >
  79. <PencilSquareIcon className="h-4 w-4 text-gray-500" />
  80. </div>
  81. </div>
  82. )
  83. }
  84. export default React.memo(Header)