diff --git a/components/atoms/Avatar/avatar.tsx b/components/atoms/Avatar/avatar.tsx index dd2a54bddf..02c41a60b4 100644 --- a/components/atoms/Avatar/avatar.tsx +++ b/components/atoms/Avatar/avatar.tsx @@ -3,34 +3,77 @@ import Image, { StaticImageData } from "next/image"; import AvatarImage from "../../../public/hacktoberfest-icon.png"; interface AvatarProps { - className?: string; - avatarURL?: string | StaticImageData; - initials?: string; - alt?: string; - size?: "sm" | "base" | "lg"; - hasBorder?: boolean; + className?: string; + avatarURL?: string | StaticImageData; + initials?: string; + alt?: string; + size?: "sm" | "base" | "lg" | number; + hasBorder?: boolean; } const avatarLoader = () => { return "https://images.unsplash.com/photo-1534528741775-53994a69daeb?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1064&q=80"; }; -const Avatar: React.FC = ({ className, avatarURL, initials, alt, size, hasBorder }) => { +const Avatar = (props: AvatarProps): JSX.Element => { + switch (typeof props.size) { + case "string": + return ; + case "number": + return ; + default: + return invalid avatar size props!!!; + } +}; + +export default Avatar; + +const CustomAvatar = ({ className, avatarURL, initials, alt, size, hasBorder }: AvatarProps): JSX.Element => { return (
- { avatarURL ? - + {avatarURL ? ( + {alt - : -
- { initials } -
- } + alt={alt ? alt : "Avatar"} + width={size} + height={size} + /* loader={avatarLoader} */ src={avatarURL ? avatarURL : AvatarImage} + /> + ) : ( +
{initials}
+ )}
); }; -export default Avatar; \ No newline at end of file +const DefaultAvatar = ({ className, avatarURL, initials, alt, size, hasBorder }: AvatarProps): JSX.Element => { + return ( +
+ {avatarURL ? ( + {alt + ) : ( +
+ {initials} +
+ )} +
+ ); +}; diff --git a/stories/atoms/avatar.stories.tsx b/stories/atoms/avatar.stories.tsx index 0448ac2500..2c7c2bbf57 100644 --- a/stories/atoms/avatar.stories.tsx +++ b/stories/atoms/avatar.stories.tsx @@ -28,4 +28,14 @@ export const HasBorder = AvatarTemplate.bind({}); HasBorder.args = { size: "base", hasBorder: true, avatarURL: "https://images.unsplash.com/photo-1534528741775-53994a69daeb?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1064&q=80", initials: "BD", alt:"Hello" }; export const NoURL = AvatarTemplate.bind({}); -NoURL.args = { size: "base", hasBorder: true, initials: "BD", alt:"Hello" }; \ No newline at end of file +NoURL.args = { size: "base", hasBorder: true, initials: "BD", alt:"Hello" }; + +export const CustomAvatar = AvatarTemplate.bind({}); +CustomAvatar.args = { + size: 56, + hasBorder: true, + avatarURL: + "https://images.unsplash.com/photo-1534528741775-53994a69daeb?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1064&q=80", + initials: "BD", + alt: "Hello" +}; \ No newline at end of file