index.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import { Message3Fill } from '@/app/components/base/icons/src/public/other'
  4. import Button from '@/app/components/base/button'
  5. import Divider from '@/app/components/base/divider'
  6. import InputsFormContent from '@/app/components/base/chat/chat-with-history/inputs-form/content'
  7. import { useChatWithHistoryContext } from '../context'
  8. import cn from '@/utils/classnames'
  9. type Props = {
  10. collapsed: boolean
  11. setCollapsed: (collapsed: boolean) => void
  12. }
  13. const InputsFormNode = ({
  14. collapsed,
  15. setCollapsed,
  16. }: Props) => {
  17. const { t } = useTranslation()
  18. const {
  19. isMobile,
  20. currentConversationId,
  21. handleStartChat,
  22. themeBuilder,
  23. } = useChatWithHistoryContext()
  24. return (
  25. <div className={cn('pt-6 px-4 flex flex-col items-center', isMobile && 'pt-4')}>
  26. <div className={cn(
  27. 'w-full max-w-[672px] bg-components-panel-bg rounded-2xl border-[0.5px] border-components-panel-border shadow-md',
  28. collapsed && 'bg-components-card-bg border border-components-card-border shadow-none',
  29. )}>
  30. <div className={cn(
  31. 'flex items-center gap-3 px-6 py-4 rounded-t-2xl',
  32. !collapsed && 'border-b border-divider-subtle',
  33. isMobile && 'px-4 py-3',
  34. )}>
  35. <Message3Fill className='shrink-0 w-6 h-6' />
  36. <div className='grow text-text-secondary system-xl-semibold'>{t('share.chat.chatSettingsTitle')}</div>
  37. {collapsed && (
  38. <Button className='text-text-tertiary uppercase' size='small' variant='ghost' onClick={() => setCollapsed(false)}>{currentConversationId ? t('common.operation.view') : t('common.operation.edit')}</Button>
  39. )}
  40. {!collapsed && currentConversationId && (
  41. <Button className='text-text-tertiary uppercase' size='small' variant='ghost' onClick={() => setCollapsed(true)}>{t('common.operation.close')}</Button>
  42. )}
  43. </div>
  44. {!collapsed && (
  45. <div className={cn('p-6', isMobile && 'p-4')}>
  46. <InputsFormContent showTip={!!currentConversationId} />
  47. </div>
  48. )}
  49. {!collapsed && !currentConversationId && (
  50. <div className={cn('p-6', isMobile && 'p-4')}>
  51. <Button
  52. variant='primary'
  53. className='w-full'
  54. onClick={() => handleStartChat(() => setCollapsed(true))}
  55. style={
  56. themeBuilder?.theme
  57. ? {
  58. backgroundColor: themeBuilder?.theme.primaryColor,
  59. }
  60. : {}
  61. }
  62. >{t('share.chat.startChat')}</Button>
  63. </div>
  64. )}
  65. </div>
  66. {collapsed && (
  67. <div className='py-4 flex items-center w-full max-w-[720px]'>
  68. <Divider bgStyle='gradient' className='basis-1/2 h-px rotate-180' />
  69. <Divider bgStyle='gradient' className='basis-1/2 h-px' />
  70. </div>
  71. )}
  72. </div>
  73. )
  74. }
  75. export default InputsFormNode