Merge pull request 'Avatar - image or text inside' (#66) from feature/avatar into develop
Reviewed-on: http://85.143.176.51:3000/free-land/front-end/pulls/66
This commit is contained in:
commit
895e054e7e
49
src/components/Avatar.tsx
Normal file
49
src/components/Avatar.tsx
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import React from "react";
|
||||||
|
import classNames from "classnames";
|
||||||
|
|
||||||
|
export type Props = {
|
||||||
|
/**
|
||||||
|
* The style avatar
|
||||||
|
*/
|
||||||
|
className?: string;
|
||||||
|
/**
|
||||||
|
* The path of image
|
||||||
|
*/
|
||||||
|
src?: string;
|
||||||
|
/**
|
||||||
|
* The alternative text in case the image is not valid
|
||||||
|
*/
|
||||||
|
alt?: string;
|
||||||
|
/**
|
||||||
|
* The text inside avatar as a child
|
||||||
|
*/
|
||||||
|
children?: React.ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
const Avatar = ({ className, src, alt, children }: Props) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{/* In case the src is valid, it will show the image */}
|
||||||
|
{src && (
|
||||||
|
<img
|
||||||
|
className="h-9 w-9 bg-contain bg-no-repeat rounded-full"
|
||||||
|
src={src}
|
||||||
|
alt={alt}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{/* The text will be shown in case it is valid */}
|
||||||
|
{children && (
|
||||||
|
<div
|
||||||
|
className={classNames(
|
||||||
|
"h-9 w-9 flex justify-center items-center text-base rounded-full bg-red-400",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Avatar;
|
Loading…
x
Reference in New Issue
Block a user