mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-19 03:46:20 +02:00
⬆️ v3.0.0 (#704)
This commit is contained in:
parent
735056f25f
commit
c22b3abc4d
385 changed files with 19912 additions and 5250 deletions
67
apps/web/src/components/user.tsx
Normal file
67
apps/web/src/components/user.tsx
Normal file
|
@ -0,0 +1,67 @@
|
|||
import { UserIcon } from "@rallly/icons";
|
||||
import clsx from "clsx";
|
||||
|
||||
import { useUser } from "@/components/user-provider";
|
||||
import { getRandomAvatarColor } from "@/utils/color-hash";
|
||||
|
||||
export const CurrentUserAvatar = ({
|
||||
size = "md",
|
||||
className,
|
||||
}: Omit<UserAvatarProps, "name">) => {
|
||||
const { user } = useUser();
|
||||
|
||||
return (
|
||||
<UserAvatar
|
||||
className={className}
|
||||
name={user.isGuest ? undefined : user.name}
|
||||
size={size}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
interface UserAvatarProps {
|
||||
name?: string;
|
||||
size?: "sm" | "md" | "lg";
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export const UserAvatar = ({
|
||||
size = "md",
|
||||
name,
|
||||
className,
|
||||
}: UserAvatarProps) => {
|
||||
const colors = name ? getRandomAvatarColor(name) : null;
|
||||
return (
|
||||
<span
|
||||
className={clsx(
|
||||
"inline-flex items-center justify-center overflow-hidden rounded-full font-semibold",
|
||||
{
|
||||
"h-6 w-6 text-sm": size === "sm",
|
||||
"h-8 w-8 text-base": size === "md",
|
||||
"h-14 w-14 text-2xl": size === "lg",
|
||||
},
|
||||
!name
|
||||
? "bg-gray-200"
|
||||
: colors?.requiresDarkText
|
||||
? "text-gray-800"
|
||||
: "text-white",
|
||||
className,
|
||||
)}
|
||||
style={{
|
||||
backgroundColor: colors?.color,
|
||||
}}
|
||||
>
|
||||
{name ? (
|
||||
name[0].toUpperCase()
|
||||
) : (
|
||||
<UserIcon
|
||||
className={clsx({
|
||||
"h-4 w-4": size === "sm",
|
||||
"h-6 w-6": size === "md",
|
||||
"h-8 w-8": size === "lg",
|
||||
})}
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue