diff --git a/src/components/portrait/portrait.component.tsx b/src/components/portrait/portrait.component.tsx index 7b27979602..104ac92cc6 100644 --- a/src/components/portrait/portrait.component.tsx +++ b/src/components/portrait/portrait.component.tsx @@ -84,6 +84,7 @@ const Portrait = ({ ...rest }: PortraitProps) => { const [externalError, setExternalError] = useState(false); + const hasValidImg = Boolean(src) && !externalError; invariant( !(src && gravatar), @@ -165,6 +166,7 @@ const Portrait = ({ {...filterStyledSystemMarginProps(rest)} onClick={onClick} {...tagProps} + hasValidImg={hasValidImg} darkBackground={darkBackground} size={size} shape={shape} @@ -180,6 +182,7 @@ const Portrait = ({ {...filterStyledSystemMarginProps(rest)} onClick={onClick} {...tagProps} + hasValidImg={hasValidImg} darkBackground={darkBackground} size={size} shape={shape} diff --git a/src/components/portrait/portrait.stories.tsx b/src/components/portrait/portrait.stories.tsx index 0237b1af2f..de67ca7683 100644 --- a/src/components/portrait/portrait.stories.tsx +++ b/src/components/portrait/portrait.stories.tsx @@ -59,10 +59,26 @@ WithTooltip.storyName = "With Tooltip"; export const Sizes: Story = () => { return ( - - {(["XS", "S", "M", "ML", "L", "XL", "XXL"] as const).map((size) => ( - - ))} + + + {(["XS", "S", "M", "ML", "L", "XL", "XXL"] as const).map((size) => ( + + ))} + + + {(["XS", "S", "M", "ML", "L", "XL", "XXL"] as const).map((size) => ( + + ))} + + + {(["XS", "S", "M", "ML", "L", "XL", "XXL"] as const).map((size) => ( + + ))} + ); }; diff --git a/src/components/portrait/portrait.style.tsx b/src/components/portrait/portrait.style.tsx index 8c6b3947f6..9071c50a38 100644 --- a/src/components/portrait/portrait.style.tsx +++ b/src/components/portrait/portrait.style.tsx @@ -12,6 +12,7 @@ type StyledPortraitProps = { darkBackground?: boolean; size: PortraitSizes; shape?: PortraitShapes; + hasValidImg?: boolean; onClick?: (ev: React.MouseEvent) => void; }; @@ -30,12 +31,11 @@ export const StyledPortraitInitials = styled.div< export const StyledPortraitGravatar = styled.img` height: inherit; - width: inherit; `; export const StyledCustomImg = styled.img` height: inherit; - width: inherit; + min-width: inherit; `; // && is used here to increase the specificity @@ -44,7 +44,7 @@ export const StyledIcon = styled(Icon)>` && { color: inherit; height: inherit; - width: inherit; + min-width: inherit; ::before { font-size: ${({ size }) => PORTRAIT_SIZE_PARAMS[size].iconDimensions}px; @@ -63,13 +63,16 @@ export const StyledPortraitContainer = styled.div< darkBackground ? "var(--colorsUtilityYin090)" : "var(--colorsUtilityReadOnly400)"}; - width: ${({ size }) => PORTRAIT_SIZE_PARAMS[size].dimensions}px; + ${({ hasValidImg, size }) => + hasValidImg && `max-width: ${PORTRAIT_SIZE_PARAMS[size].dimensions}px;`} + min-width: ${({ size }) => PORTRAIT_SIZE_PARAMS[size].dimensions}px; height: ${({ size }) => PORTRAIT_SIZE_PARAMS[size].dimensions}px; overflow: hidden; border-radius: ${({ shape }) => shape === "square" ? "0px" : "var(--borderRadiusCircle)"}; border: 1px solid var(--colorsUtilityReadOnly600); display: inline-block; + ${({ onClick }) => onClick && "cursor: pointer"} ${margin} `;