index.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {
  2. memo,
  3. useCallback,
  4. } from 'react'
  5. import {
  6. RiAttachmentLine,
  7. } from '@remixicon/react'
  8. import FileFromLinkOrLocal from '../file-from-link-or-local'
  9. import ActionButton from '@/app/components/base/action-button'
  10. import cn from '@/utils/classnames'
  11. import type { FileUpload } from '@/app/components/base/features/types'
  12. import { TransferMethod } from '@/types/app'
  13. type FileUploaderInChatInputProps = {
  14. fileConfig: FileUpload
  15. }
  16. const FileUploaderInChatInput = ({
  17. fileConfig,
  18. }: FileUploaderInChatInputProps) => {
  19. const renderTrigger = useCallback((open: boolean) => {
  20. return (
  21. <ActionButton
  22. size='l'
  23. className={cn(open && 'bg-state-base-hover')}
  24. >
  25. <RiAttachmentLine className='w-5 h-5' />
  26. </ActionButton>
  27. )
  28. }, [])
  29. return (
  30. <FileFromLinkOrLocal
  31. trigger={renderTrigger}
  32. fileConfig={fileConfig}
  33. showFromLocal={fileConfig?.allowed_file_upload_methods?.includes(TransferMethod.local_file)}
  34. showFromLink={fileConfig?.allowed_file_upload_methods?.includes(TransferMethod.remote_url)}
  35. />
  36. )
  37. }
  38. export default memo(FileUploaderInChatInput)