signal-desktop/ts/components/conversation/ScrollDownButton.tsx

52 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2019-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import type { LocalizerType } from '../../types/Util';
export type Props = {
2022-06-13 23:37:29 +00:00
unreadCount?: number;
conversationId: string;
scrollDown: (conversationId: string) => void;
i18n: LocalizerType;
};
2020-09-14 19:51:27 +00:00
export const ScrollDownButton = ({
conversationId,
2022-06-13 23:37:29 +00:00
unreadCount,
2020-09-14 19:51:27 +00:00
i18n,
scrollDown,
}: Props): JSX.Element => {
2022-06-13 23:37:29 +00:00
const altText = unreadCount ? i18n('messagesBelow') : i18n('scrollDown');
let badgeText: string | undefined;
if (unreadCount) {
if (unreadCount < 100) {
badgeText = unreadCount.toString();
} else {
badgeText = '99+';
}
}
2020-09-14 19:51:27 +00:00
return (
2022-06-13 23:37:29 +00:00
<div className="ScrollDownButton">
2020-09-14 19:51:27 +00:00
<button
type="button"
2022-06-13 23:37:29 +00:00
className="ScrollDownButton__button"
2020-09-14 19:51:27 +00:00
onClick={() => {
scrollDown(conversationId);
}}
title={altText}
>
2022-06-13 23:37:29 +00:00
{badgeText ? (
<div className="ScrollDownButton__button__badge">{badgeText}</div>
) : null}
<div className="ScrollDownButton__button__icon" />
2020-09-14 19:51:27 +00:00
</button>
</div>
);
};