Skip to content

Commit

Permalink
fix: provide 'onClick' prop to styled container for cursor styling
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-anderson committed Mar 18, 2023
1 parent 989ad63 commit 216a44a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const Avatar = forwardRef<MaybeAvatarRef, AvatarProps>(function Avatar(
profile,
imageSrc,
showDisplayName = false,
onClick,
containerProps = {},
avatarProps = {},
...props
Expand All @@ -30,11 +31,12 @@ export const Avatar = forwardRef<MaybeAvatarRef, AvatarProps>(function Avatar(
const avatarRef = ref || localRef;

return (
<AvatarContainer className="avatar-container" {...containerProps}>
<AvatarContainer className="avatar-container" isClickable={!!onClick} {...containerProps}>
<MuiAvatar
ref={avatarRef}
alt={profile?.displayName ?? "User Avatar"}
src={imageSrc || profile?.photoUrl}
onClick={onClick}
{...avatarProps}
{...props}
>
Expand All @@ -52,17 +54,20 @@ export const Avatar = forwardRef<MaybeAvatarRef, AvatarProps>(function Avatar(
);
});

const AvatarContainer = styled("div")(({ theme: { palette }, onClick }) => ({
const AvatarContainer = styled("div", {
shouldForwardProp: (propName) => propName !== "isClickable"
})<{ isClickable: boolean }>(({ theme: { palette }, isClickable }) => ({
height: "100%",
width: "100%",
display: "flex",
flexDirection: "row",
alignItems: "center",

"& > .MuiAvatar-root": {
overflow: "hidden !important", // <-- ensure can't be overridden
background: `-webkit-linear-gradient(135deg, ${palette.primary.dark} 30%, ${palette.primary.light})`,
"&:hover": {
cursor: onClick ? "pointer" : "auto"
cursor: isClickable ? "pointer" : "auto"
}
},
"& > .MuiTypography-root": {
Expand All @@ -75,7 +80,7 @@ type AvatarProps = {
profile?: UserProfile;
imageSrc?: string;
showDisplayName?: boolean;
containerProps?: React.ComponentProps<typeof AvatarContainer>;
containerProps?: Omit<React.ComponentProps<typeof AvatarContainer>, "isClickable">;
avatarProps?: React.ComponentProps<typeof MuiAvatar>;
} & React.ComponentProps<typeof MuiAvatar>;

Expand Down

0 comments on commit 216a44a

Please sign in to comment.