Added avatar component
This commit is contained in:
1 parent
a0fee0c99a
commit
7a820cffb1
4 files changed
+56
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import { Avatar as MuiAvatar } from "@mui/material";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
/**
|
||||
* @component
|
||||
* @param {Object} props
|
||||
* @param {string} props.src - Path to image for avatar
|
||||
* @param {string} props.firstName - The users first name
|
||||
* @param {string} props.lastName - The users last name
|
||||
* @param {boolean} props.small - Specifies if avatar should be large
|
||||
* @returns {JSX.Element}
|
||||
* @example
|
||||
* // Render a red label
|
||||
* <Avatar src="assets/img" first="Alex" last="Holliday" small />
|
||||
*/
|
||||
|
||||
const Avatar = ({ src, firstName, lastName, small }) => {
|
||||
const borderColor = "#F0F2F4";
|
||||
const smallStyle = small ? { width: 32, height: 32 } : {};
|
||||
return (
|
||||
<MuiAvatar
|
||||
alt={`${firstName} ${lastName}`}
|
||||
src={src}
|
||||
sx={{
|
||||
display: "inline-flex",
|
||||
border: `0.2rem solid ${borderColor}`,
|
||||
...smallStyle,
|
||||
}}
|
||||
>
|
||||
{src === undefined ? `${firstName[0]}${lastName[0]}` : null}
|
||||
</MuiAvatar>
|
||||
);
|
||||
};
|
||||
|
||||
Avatar.propTypes = {
|
||||
src: PropTypes.string,
|
||||
firstName: PropTypes.string.isRequired,
|
||||
lastName: PropTypes.string.isRequired,
|
||||
small: PropTypes.bool,
|
||||
};
|
||||
|
||||
export default Avatar;
|
||||
Whitespace-only changes.
@@ -3,6 +3,8 @@ import DropdownTeamMember from "../../Components/DropdownTeamMember";
|
||||
import "./index.css";
|
||||
import Button from "../../Components/Button";
|
||||
import Link from "../../Components/Link";
|
||||
import Avatar from "../../Components/Avatar/Avatar";
|
||||
import avatarImage from "../../assets/Images/avatar_placeholder.png";
|
||||
|
||||
const Home = () => {
|
||||
return (
|
||||
@@ -33,6 +35,18 @@ const Home = () => {
|
||||
url={"https://www.google.com"}
|
||||
/>
|
||||
</div>
|
||||
<h4>Avatar</h4>
|
||||
<div style={{ display: "flex" }}>
|
||||
<Avatar src={avatarImage} firstName="Alex" lastName="Holliday" />
|
||||
<Avatar firstName="Alex" lastName="Holliday" />
|
||||
<Avatar
|
||||
src={avatarImage}
|
||||
firstName="Alex"
|
||||
lastName="Holliday"
|
||||
small
|
||||
/>
|
||||
<Avatar firstName="Alex" lastName="Holliday" small />
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
Reference in new issue
Block a user