import React, { PureComponent } from 'react'; import cls from 'classnames'; import PropTypes from 'prop-types'; import { FileItem } from '../../upload/interface'; import type { InputBoxProps, InputBoxState } from '../interface'; import { BaseComponent, Button, Upload, Tooltip, TextArea } from '../../index'; import { IconDeleteStroked, IconChainStroked, IconArrowUp } from '@douyinfe/semi-icons'; import { cssClasses, strings } from "@douyinfe/semi-foundation/chat/constants"; import InputBoxFoundation, { InputBoxAdapter } from '@douyinfe/semi-foundation/chat/inputboxFoundation'; import Attachment from '../attachment'; const { PREFIX_INPUT_BOX } = cssClasses; const { SEND_HOT_KEY } = strings; const textAutoSize = { minRows: 1, maxRows: 5 }; class InputBox extends BaseComponent { inputAreaRef: React.RefObject; static propTypes = { uploadProps: PropTypes.object, }; static defaultProps = { uploadProps: {} }; constructor(props: InputBoxProps) { super(props); this.inputAreaRef = React.createRef(); this.foundation = new InputBoxFoundation(this.adapter); this.state = { content: '', attachment: [] }; } get adapter(): InputBoxAdapter { return { ...super.adapter, notifyInputChange: (props: { inputValue: string; attachment: any[]}) => { const { onInputChange } = this.props; onInputChange && onInputChange(props); }, setInputValue: (value) => { this.setState({ content: value }); }, setAttachment: (attachment: any[]) => { this.setState({ attachment: attachment }); }, notifySend: (content: string, attachment: FileItem[]) => { const { onSend } = this.props; onSend && onSend(content, attachment); } }; } onClick = () => { this.inputAreaRef.current?.focus(); } renderUploadButton = () => { const { uploadProps, uploadRef, uploadTipProps, clickUpload } = this.props; if (!clickUpload) { return null; } const { attachment } = this.state; const { className, onChange, renderFileItem, children, ...rest } = uploadProps; const realUploadProps = { ...rest, className: cls(`${PREFIX_INPUT_BOX}-upload`, { [className]: className }), onChange: this.foundation.onAttachmentAdd, }; const uploadNode = {children ? children :