69 lines
1.4 KiB
JavaScript
69 lines
1.4 KiB
JavaScript
import * as React from "react";
|
|
import Card from "@mui/material/Card";
|
|
import { Typography } from "@mui/material";
|
|
import Avatar from '@mui/material/Avatar';
|
|
import Stack from '@mui/material/Stack';
|
|
|
|
function stringToColor(string) {
|
|
let hash = 0;
|
|
let i;
|
|
|
|
/* eslint-disable no-bitwise */
|
|
for (i = 0; i < string.length; i += 1) {
|
|
hash = string.charCodeAt(i) + ((hash << 5) - hash);
|
|
}
|
|
|
|
let color = '#';
|
|
|
|
for (i = 0; i < 3; i += 1) {
|
|
const value = (hash >> (i * 8)) & 0xff;
|
|
color += `00${value.toString(16)}`.slice(-2);
|
|
}
|
|
/* eslint-enable no-bitwise */
|
|
|
|
return color;
|
|
}
|
|
|
|
function stringAvatar(name) {
|
|
return {
|
|
sx: {
|
|
bgcolor: stringToColor(name),
|
|
},
|
|
children: `${name.split(' ')[0][0]}${name.split(' ')[1][0]}`,
|
|
};
|
|
}
|
|
|
|
const LetterAvatars = () => {
|
|
return (
|
|
<>
|
|
<Card
|
|
sx={{
|
|
boxShadow: "none",
|
|
borderRadius: "10px",
|
|
p: "25px",
|
|
mb: "15px",
|
|
}}
|
|
>
|
|
<Typography
|
|
as="h3"
|
|
sx={{
|
|
fontSize: 18,
|
|
fontWeight: 500,
|
|
mb: '20px'
|
|
}}
|
|
>
|
|
Letter Avatars
|
|
</Typography>
|
|
|
|
<Stack direction="row" spacing={2} className="avatars-gap">
|
|
<Avatar {...stringAvatar('Kent Dodds')} />
|
|
<Avatar {...stringAvatar('Jed Watson')} />
|
|
<Avatar {...stringAvatar('Tim Neutkens')} />
|
|
</Stack>
|
|
</Card>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default LetterAvatars;
|