Last active
March 14, 2022 06:30
-
-
Save dipeshhkc/65d8918dcdd51806daba08bd42f01772 to your computer and use it in GitHub Desktop.
Avatar Using Name Initials in React and TailwindCSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Avatar Component | |
import { FC } from "react"; | |
interface IAvatarInitials { | |
name: string; | |
} | |
export const AvatarInitials: FC<IAvatarInitials> = ({ name }) => { | |
const userName = name.split(" "); | |
return ( | |
<div className="table h-8 w-8 bg-black text-white rounded-full"> | |
<span className="table-cell align-middle text-center"> | |
<h1 className="m-0 p-0 font-medium tracking-wide uppercase"> | |
{`${ | |
userName.length >= 2 | |
? `${userName[0].charAt(0)}${userName[1].charAt(0)}` | |
: userName[0].charAt(0) | |
}`} | |
</h1> | |
</span> | |
</div> | |
); | |
}; | |
## USAGE | |
<AvatarInitials name="Dipesh KC"/> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment