Npm Package Url - https://www.npmjs.com/package/react-name-initials-avatar
The react-name-initials-avatar is a lightweight and customizable React component that generates avatars based on user names or initials. This component is ideal for user profile displays, comment sections, or any application where you want to visually represent users with avatars.
- Customizable - You can easily customize the appearance of the avatars by adjusting properties like size, background colors, text colors, and more.
- Easy Integration - Integrating the React Name Initials Avatar into your project is simple. Just import the component and pass the necessary props.
yarn add react-name-initials-avatar
OR
npm install react-name-initials-avatar
To use the component, import it into your React application:
import {NameInitialsAvatar} from 'react-name-initials-avatar';
function UserProfile(props) {
const { username } = props;
return (
<div className="user-profile">
<NameInitialsAvatar
name={username}
/>
<h2>{username}</h2>
</div>
);
}
export default UserProfile;
In the above example, the NameInitialsAvatar component generates an avatar based on the user's name initials. You can customize the avatar's size, background color, border radius, font weight and text color according to your design.
Key | Default | Type |
---|---|---|
name (required) |
undefined |
string |
bgColor (optional) |
white |
string |
textColor (optional) |
black |
string |
size (optional) |
40px |
string |
borderRadius (optional) |
50% |
string |
textWeight (optional) |
bold |
string |
textSize (optional) |
16px |
string |
borderColor (optional) |
black |
string |
borderStyle (optional) |
solid |
string |
borderWidth (optional) |
2px |
string |
- name - name of user
- bgColor - set background color
- textColor - set text color
- size - set container size
- borderRadius - set border radius of container
- textWeight - set font weight of text. Accepted values - normal, bold, bolder, lighter, number, initial, inherit, 100 to 900
- textSize - set font size of text
- borderColor - set border color of container
- borderStyle - set border style of container. Accepted values - none, hidden, dotted, dashed, solid, double, groove, ridge, inset, outset, initial, inherit
- borderWidth - set border width of container