owncast/web/components/chat/ChatContainer/ScrollToBotBtn.tsx

37 lines
937 B
TypeScript
Raw Normal View History

2022-09-30 14:16:35 +03:00
import { Button } from 'antd';
import dynamic from 'next/dynamic';
2022-09-30 14:16:35 +03:00
import { FC, MutableRefObject } from 'react';
import { ChatMessage } from '../../../interfaces/chat-message.model';
import styles from './ChatContainer.module.scss';
// Lazy loaded components
const VerticalAlignBottomOutlined = dynamic(
() => import('@ant-design/icons/VerticalAlignBottomOutlined'),
{
ssr: false,
},
);
2022-09-30 14:16:35 +03:00
type Props = {
chatContainerRef: MutableRefObject<any>;
messages: ChatMessage[];
};
export const ScrollToBotBtn: FC<Props> = ({ chatContainerRef, messages }) => (
<div className={styles.toBottomWrap}>
<Button
type="default"
style={{ color: 'currentColor' }}
icon={<VerticalAlignBottomOutlined />}
onClick={() =>
chatContainerRef.current.scrollToIndex({
index: messages.length - 1,
behavior: 'auto',
2022-09-30 14:16:35 +03:00
})
}
>
Go to last message
</Button>
</div>
);