From 83a171925ff8540f5acad8ce415a3cc747259e94 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 12 Mar 2024 10:46:35 +0100 Subject: [PATCH] chore: move the styles into the avatar theme so it can be overriden Signed-off-by: blam --- .../src/components/Avatar/Avatar.tsx | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/packages/core-components/src/components/Avatar/Avatar.tsx b/packages/core-components/src/components/Avatar/Avatar.tsx index 3727c892f9..2b3336830a 100644 --- a/packages/core-components/src/components/Avatar/Avatar.tsx +++ b/packages/core-components/src/components/Avatar/Avatar.tsx @@ -23,21 +23,23 @@ import { extractInitials, stringToColor } from './utils'; /** @public */ export type AvatarClassKey = 'avatar'; -const useStyles = makeStyles( - (theme: Theme) => ({ - avatar: { - width: '4rem', - height: '4rem', - color: theme.palette.common.white, - }, - avatarText: { - fontWeight: theme.typography.fontWeightBold, - letterSpacing: '1px', - textTransform: 'uppercase', - }, - }), - { name: 'BackstageAvatar' }, -); +const useStyles = (styles: CSSProperties) => + makeStyles( + (theme: Theme) => ({ + avatar: { + width: '4rem', + height: '4rem', + color: theme.palette.common.white, + ...styles, + }, + avatarText: { + fontWeight: theme.typography.fontWeightBold, + letterSpacing: '1px', + textTransform: 'uppercase', + }, + }), + { name: 'BackstageAvatar' }, + )(); /** * Properties for {@link Avatar}. @@ -69,13 +71,15 @@ export interface AvatarProps { */ export function Avatar(props: AvatarProps) { const { displayName, picture, customStyles } = props; - const classes = useStyles(); let styles = { ...customStyles }; const fontStyles = { fontFamily: styles.fontFamily, fontSize: styles.fontSize, fontWeight: styles.fontWeight, }; + + const classes = useStyles(styles); + // We only calculate the background color if there's not an avatar // picture. If there is a picture, it might have a transparent // background and we don't know whether the calculated background