Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Add a "Scroll to Top" button #512

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/react/src/components/ChatHeader/ChatHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const ChatHeader = ({
styles = {},
anonymousMode,
showRoles,
messageListRef,
}) => {
const { classNames, styleOverrides } = useComponentOverrides('ChatHeader');
const channelInfo = useChannelStore((state) => state.channelInfo);
Expand Down Expand Up @@ -98,6 +99,14 @@ const ChatHeader = ({
}
}, [RCInstance, setIsUserAuthenticated]);

const scrollToTop = useCallback(() => {
if (messageListRef && messageListRef.current) {
requestAnimationFrame(() => {
messageListRef.current.scrollTop = -messageListRef.current.scrollHeight;
});
}
}, [messageListRef]);

const showStarredMessage = useCallback(async () => {
const { messages } = await RCInstance.getStarredMessages();
setMessages(messages);
Expand Down Expand Up @@ -266,6 +275,12 @@ const ChatHeader = ({
label: 'Room Information',
icon: 'info',
},
{
id: 'scroll-to-top',
action: scrollToTop,
label: 'Scroll to Top',
icon: 'arrow-up',
},
]
);
}
Expand All @@ -292,6 +307,7 @@ const ChatHeader = ({
showPinnedMessage,
showSearchMessage,
showStarredMessage,
scrollToTop,
]);

return (
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/EmbeddedChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ const EmbeddedChat = ({
setFullScreen={setFullScreen}
anonymousMode={anonymousMode}
showRoles={showRoles}
messageListRef={messageListRef}
/>
)}

Expand Down
29 changes: 29 additions & 0 deletions packages/react/src/components/Icon/icons/ArrowUp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';

const ArrowUp = (props) => (
<svg
fill="#000000"
height="200px"
width="200px"
version="1.1"
id="Layer_1"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 330 330"
{...props}
>
<g id="SVGRepo_bgCarrier" strokeWidth="0" />
<g
id="SVGRepo_tracerCarrier"
strokeLinecap="round"
strokeLinejoin="round"
/>
<g id="SVGRepo_iconCarrier">
<path
id="XMLID_224_"
d="M325.606,229.393l-150.004-150C172.79,76.58,168.974,75,164.996,75c-3.979,0-7.794,1.581-10.607,4.394 l-149.996,150c-5.858,5.858-5.858,15.355,0,21.213c5.857,5.857,15.355,5.858,21.213,0l139.39-139.393l139.397,139.393 C307.322,253.536,311.161,255,315,255c3.839,0,7.678-1.464,10.607-4.394C331.464,244.748,331.464,235.251,325.606,229.393z"
/>
</g>
</svg>
);

export default ArrowUp;
2 changes: 2 additions & 0 deletions packages/react/src/components/Icon/icons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Kebab from './Kebab';
import Check from './Check';
import ErrorCircle from './ErrorCircle';
import ArrowDown from './ArrowDown';
import ArrowUp from './ArrowUp';
import PinFilled from './PinFilled';
import VideoRecorder from './VideoRecoder';
import DisabledRecorder from './DisableRecorder';
Expand Down Expand Up @@ -87,6 +88,7 @@ const icons = {
check: Check,
'error-circle': ErrorCircle,
'arrow-down': ArrowDown,
'arrow-up': ArrowUp,
'pin-filled': PinFilled,
clipboard: Clipboard,
download: Download,
Expand Down
5 changes: 5 additions & 0 deletions packages/react/src/components/Menu/Menu.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export const Menu = {
label: 'Room Information',
icon: 'info',
},
{
id: 'scroll-to-top',
label: 'Scroll to Top',
icon: 'arrow-up',
},
{
id: 'logout',
label: 'Logout',
Expand Down
Loading