Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | 4x 4x 4x 27x 4x 4x 85x 27x 4x 58x 27x 27x 27x | import { styled, Theme } from "@mui/material";
import UserSummary from "components/UserSummary";
import { LiteUser } from "proto/api_pb";
import { BlockedUser } from "proto/blocking_pb";
interface FriendSummaryViewProps {
children?: React.ReactNode;
friend?: LiteUser.AsObject | BlockedUser.AsObject;
/**
* Compact rows stack their actions under the name and use a smaller avatar,
* which is what the narrow sidebar on the connections page needs — a viewport
* breakpoint can't tell how wide the column actually is.
*
* Pass false where the row has the full width of the page and a narrow action,
* so a lone icon button isn't pushed onto a line of its own.
*/
isCompact?: boolean;
isProfileLink?: boolean;
cardRef?: React.Ref<HTMLDivElement>;
}
export const FRIEND_ITEM_TEST_ID = "friend-item";
const stacked = (theme: Theme) => ({
flexDirection: "column" as const,
gap: theme.spacing(1),
});
const fullWidthActions = {
display: "flex",
justifyContent: "flex-end",
width: "100%",
};
const StyledFriendItem = styled("div", {
shouldForwardProp: (prop) => prop !== "isCompact",
})<{ isCompact: boolean }>(({ theme, isCompact }) => ({
display: "flex",
alignItems: "flex-start",
padding: `0 ${theme.spacing(1)}`,
// Wide rows still stack once the viewport itself gets narrow.
...(isCompact ? stacked(theme) : { [theme.breakpoints.down("md")]: stacked(theme) }),
}));
const ButtonWrapper = styled("div", {
shouldForwardProp: (prop) => prop !== "isCompact",
})<{ isCompact: boolean }>(({ theme, isCompact }) =>
isCompact ? fullWidthActions : { [theme.breakpoints.down("md")]: fullWidthActions },
);
function FriendSummaryView({ children, friend, isCompact = true, isProfileLink, cardRef }: FriendSummaryViewProps) {
return friend ? (
<StyledFriendItem ref={cardRef} data-testid={FRIEND_ITEM_TEST_ID} isCompact={isCompact}>
<UserSummary headlineComponent="h3" user={friend} isProfileLink={isProfileLink} smallAvatar={isCompact} />
<ButtonWrapper isCompact={isCompact}>{children}</ButtonWrapper>
</StyledFriendItem>
) : null;
}
export default FriendSummaryView;
|