chatBoxTitle.tsx 961 B

12345678910111213141516171819202122232425262728293031
  1. import React, { useMemo, ReactNode, ReactElement } from 'react';
  2. import { Message, Metadata, RenderTitleProps } from '../interface';
  3. import { cssClasses } from '@douyinfe/semi-foundation/chat/constants';
  4. const { PREFIX_CHAT_BOX } = cssClasses;
  5. interface ChatBoxTitleProps {
  6. children?: ReactNode | undefined | any;
  7. role?: Metadata;
  8. message?: Message;
  9. customRenderFunc?: (props: RenderTitleProps) => ReactNode
  10. }
  11. const ChatBoxTitle = React.memo((props: ChatBoxTitleProps) => {
  12. const { role, message, customRenderFunc } = props;
  13. const title = useMemo(() => {
  14. return <span
  15. className={`${PREFIX_CHAT_BOX}-title`}
  16. >{role?.name}</span>;
  17. }, [role]);
  18. if (customRenderFunc && typeof customRenderFunc === 'function') {
  19. return customRenderFunc({
  20. role,
  21. message,
  22. defaultTitle: title
  23. }) as ReactElement;
  24. }
  25. return title;
  26. });
  27. export default ChatBoxTitle;