revite/src/components/common/messaging/bars/JumpToBottom.tsx

73 lines
1.7 KiB
TypeScript
Raw Normal View History

import { DownArrowAlt } from "@styled-icons/boxicons-regular";
2021-07-05 06:23:23 -04:00
import styled from "styled-components";
import { Text } from "preact-i18n";
import {
2021-07-05 06:25:20 -04:00
SingletonMessageRenderer,
useRenderState,
2021-07-05 06:23:23 -04:00
} from "../../../../lib/renderer/Singleton";
const Bar = styled.div`
2021-07-05 06:25:20 -04:00
z-index: 10;
position: relative;
2021-07-05 06:23:23 -04:00
2021-07-05 06:25:20 -04:00
> div {
top: -26px;
height: 28px;
2021-07-05 06:25:20 -04:00
width: 100%;
position: absolute;
border-radius: 4px 4px 0 0;
display: flex;
align-items: center;
2021-07-05 06:25:20 -04:00
cursor: pointer;
font-size: 13px;
padding: 0 8px;
2021-07-05 06:25:20 -04:00
user-select: none;
color: var(--secondary-foreground);
background: var(--secondary-background);
justify-content: space-between;
transition: color ease-in-out 0.08s;
2021-07-05 06:23:23 -04:00
2021-07-05 06:25:20 -04:00
> div {
display: flex;
align-items: center;
gap: 6px;
}
2021-07-05 06:23:23 -04:00
2021-07-05 06:25:20 -04:00
&:hover {
color: var(--primary-text);
}
2021-07-05 06:23:23 -04:00
2021-07-05 06:25:20 -04:00
&:active {
transform: translateY(1px);
}
@media (pointer: coarse) {
height: 34px;
top: -32px;
padding: 0 12px;
}
2021-07-05 06:25:20 -04:00
}
`;
export default function JumpToBottom({ id }: { id: string }) {
2021-07-05 06:25:20 -04:00
const view = useRenderState(id);
if (!view || view.type !== "RENDER" || view.atBottom) return null;
2021-07-05 06:23:23 -04:00
2021-07-05 06:25:20 -04:00
return (
<Bar>
<div
onClick={() => SingletonMessageRenderer.jumpToBottom(id, true)}>
<div>
<Text id="app.main.channel.misc.viewing_old" />
</div>
<div>
<Text id="app.main.channel.misc.jump_present" />{" "}
<DownArrowAlt size={20} />
2021-07-05 06:25:20 -04:00
</div>
</div>
</Bar>
);
}