11import React from 'react' ;
22import PropTypes from 'prop-types' ;
33import { Avatar } from '@mui/material' ;
4- import makeStyles from '@mui/styles/makeStyles' ;
54
65function stringToColor ( str ) {
76 let hash = 0 ;
@@ -19,24 +18,21 @@ function stringToColor(str) {
1918 return color ;
2019}
2120
22- const useStyles = makeStyles ( ( theme ) => ( {
23- avatar : {
24- width : ( props ) => `${ props . size } px` ,
25- height : ( props ) => `${ props . size } px` ,
26- fontSize : ( props ) => theme . typography . pxToRem ( props . size / 2 ) ,
27- backgroundColor : ( props ) => props . avatarBackgroundColor ,
28- color : ( props ) => theme . palette . getContrastText ( props . avatarBackgroundColor ) ,
29- } ,
30- } ) ) ;
31-
3221export const DefaultAvatar = ( { userName = '?' , size = 24 , variant = 'circular' } ) => {
3322 const avatarBackgroundColor = stringToColor ( userName ) ;
3423 const letter = userName === '' ? '?' : String . fromCodePoint ( userName . codePointAt ( 0 ) ) . toUpperCase ( ) ;
3524
36- const classes = useStyles ( { avatarBackgroundColor, size } ) ;
37-
3825 return (
39- < Avatar className = { classes . avatar } variant = { variant } >
26+ < Avatar
27+ variant = { variant }
28+ sx = { {
29+ width : `${ size } px` ,
30+ height : `${ size } px` ,
31+ fontSize : ( theme ) => theme . typography . pxToRem ( size / 2 ) ,
32+ backgroundColor : avatarBackgroundColor ,
33+ color : ( theme ) => theme . palette . getContrastText ( avatarBackgroundColor ) ,
34+ } }
35+ >
4036 { letter }
4137 </ Avatar >
4238 ) ;
0 commit comments