Skip to content

Instantly share code, notes, and snippets.

@dipeshhkc
Last active March 14, 2022 06:30
Show Gist options
  • Save dipeshhkc/65d8918dcdd51806daba08bd42f01772 to your computer and use it in GitHub Desktop.
Save dipeshhkc/65d8918dcdd51806daba08bd42f01772 to your computer and use it in GitHub Desktop.
Avatar Using Name Initials in React and TailwindCSS
## 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