waveterm/frontend/app/element/avatar.tsx

37 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-10-01 07:00:30 +02:00
// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
2024-10-01 07:09:23 +02:00
import { memo } from "react";
2024-10-01 07:00:30 +02:00
2024-10-03 04:32:29 +02:00
import clsx from "clsx";
2024-10-01 07:00:30 +02:00
import "./avatar.less";
interface AvatarProps {
name: string;
2024-10-01 07:09:23 +02:00
status: "online" | "offline" | "busy" | "away";
2024-10-03 04:32:29 +02:00
className?: string;
2024-10-01 07:00:30 +02:00
imageUrl?: string;
}
2024-10-03 04:32:29 +02:00
const Avatar = memo(({ name, status = "offline", className, imageUrl }: AvatarProps) => {
2024-10-01 07:00:30 +02:00
const getInitials = (name: string) => {
const nameParts = name.split(" ");
const initials = nameParts.map((part) => part[0]).join("");
return initials.toUpperCase();
};
return (
2024-10-03 04:32:29 +02:00
<div className={clsx("avatar", status, className)} title="status">
2024-10-01 07:00:30 +02:00
{imageUrl ? (
<img src={imageUrl} alt={`${name}'s avatar`} className="avatar-image" />
) : (
<div className="avatar-initials">{getInitials(name)}</div>
)}
<div className={`status-indicator ${status}`} />
</div>
);
2024-10-01 07:09:23 +02:00
});
2024-10-01 07:00:30 +02:00
2024-10-01 07:09:23 +02:00
Avatar.displayName = "Avatar";
export { Avatar };