revite/src/components/common/user/UserHeader.tsx

85 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-07-05 06:23:23 -04:00
import { Cog } from "@styled-icons/boxicons-solid";
import { Link } from "react-router-dom";
2021-06-19 10:29:04 -04:00
import { User } from "revolt.js";
import styled from "styled-components";
2021-07-05 06:23:23 -04:00
2021-06-19 15:24:11 -04:00
import { openContextMenu } from "preact-context-menu";
2021-07-05 06:23:23 -04:00
import { Text } from "preact-i18n";
import { Localizer } from "preact-i18n";
2021-06-20 15:30:42 -04:00
import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice";
2021-07-05 06:23:23 -04:00
2021-06-20 15:30:42 -04:00
import { useIntermediate } from "../../../context/intermediate/Intermediate";
2021-06-19 10:29:04 -04:00
2021-07-05 06:23:23 -04:00
import Header from "../../ui/Header";
import IconButton from "../../ui/IconButton";
import Tooltip from "../Tooltip";
import UserIcon from "./UserIcon";
import UserStatus from "./UserStatus";
2021-06-19 10:29:04 -04:00
const HeaderBase = styled.div`
2021-07-05 06:23:23 -04:00
gap: 0;
flex-grow: 1;
min-width: 0;
display: flex;
flex-direction: column;
* {
min-width: 0;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
2021-06-19 10:29:04 -04:00
2021-07-05 06:23:23 -04:00
.username {
cursor: pointer;
font-size: 16px;
font-weight: 600;
}
2021-06-19 10:29:04 -04:00
2021-07-05 06:23:23 -04:00
.status {
cursor: pointer;
font-size: 12px;
margin-top: -2px;
}
2021-06-19 10:29:04 -04:00
`;
interface Props {
2021-07-05 06:23:23 -04:00
user: User;
2021-06-19 10:29:04 -04:00
}
export default function UserHeader({ user }: Props) {
2021-07-05 06:23:23 -04:00
const { writeClipboard } = useIntermediate();
2021-06-19 10:29:04 -04:00
2021-07-05 06:23:23 -04:00
return (
<Header borders placement="secondary">
<HeaderBase>
<Localizer>
<Tooltip content={<Text id="app.special.copy_username" />}>
<span
className="username"
onClick={() => writeClipboard(user.username)}>
@{user.username}
</span>
</Tooltip>
</Localizer>
<span
className="status"
onClick={() => openContextMenu("Status")}>
<UserStatus user={user} />
</span>
</HeaderBase>
{!isTouchscreenDevice && (
<div className="actions">
<Link to="/settings">
<IconButton>
<Cog size={24} />
</IconButton>
</Link>
</div>
)}
</Header>
);
2021-06-19 10:29:04 -04:00
}