2023-11-23 00:45:06 +01:00
|
|
|
import classNames from "classnames";
|
|
|
|
|
2023-11-18 15:12:31 +01:00
|
|
|
import { UserIcon } from "@/components/UserIcon";
|
2023-11-05 17:56:56 +01:00
|
|
|
import { AccountProfile } from "@/pages/parts/auth/AccountCreatePart";
|
|
|
|
import { useAuthStore } from "@/stores/auth";
|
|
|
|
|
|
|
|
export interface AvatarProps {
|
|
|
|
profile: AccountProfile["profile"];
|
2023-11-23 00:45:06 +01:00
|
|
|
sizeClass?: string;
|
|
|
|
iconClass?: string;
|
2023-11-05 17:56:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function Avatar(props: AvatarProps) {
|
|
|
|
return (
|
|
|
|
<div
|
2023-11-23 00:45:06 +01:00
|
|
|
className={classNames(
|
|
|
|
props.sizeClass,
|
|
|
|
"rounded-full overflow-hidden flex items-center justify-center text-white"
|
|
|
|
)}
|
2023-11-05 17:56:56 +01:00
|
|
|
style={{
|
|
|
|
background: `linear-gradient(to bottom right, ${props.profile.colorA}, ${props.profile.colorB})`,
|
|
|
|
}}
|
|
|
|
>
|
2023-11-23 00:45:06 +01:00
|
|
|
<UserIcon className={props.iconClass} icon={props.profile.icon as any} />
|
2023-11-05 17:56:56 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-23 00:45:06 +01:00
|
|
|
export function UserAvatar(props: {
|
|
|
|
sizeClass?: string;
|
|
|
|
iconClass?: string;
|
|
|
|
bottom?: React.ReactNode;
|
|
|
|
}) {
|
2023-11-05 17:56:56 +01:00
|
|
|
const auth = useAuthStore();
|
|
|
|
if (!auth.account) return null;
|
2023-11-23 00:45:06 +01:00
|
|
|
return (
|
|
|
|
<div className="relative inline-block">
|
|
|
|
<Avatar
|
|
|
|
profile={auth.account.profile}
|
|
|
|
sizeClass={props.sizeClass ?? "w-[2rem] h-[2rem]"}
|
|
|
|
iconClass={props.iconClass}
|
|
|
|
/>
|
|
|
|
{props.bottom ? (
|
|
|
|
<div className="absolute bottom-0 left-1/2 transform translate-y-1/2 -translate-x-1/2">
|
|
|
|
{props.bottom}
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
);
|
2023-11-05 17:56:56 +01:00
|
|
|
}
|