1.0.1 • Published 5 months ago

next-avatar v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

next-avatar👤

A simple and customizable Next.js/React.js avatar component that displays user initials, an image, or a fallback default avatar.

Installation

GitHub package.json version

You can install the package using npm or yarn or pnpm:

npm install next-avatar
# or
pnpm add next-avatar
# or
yarn add next-avatar

Usage

Import the Avatar component and use it in your Next.js/React.js project:

import React from 'react';
import Avatar from 'next-avatar';

const App = () => {
  return (
    <>
      <Avatar />
    </>
  );
};

export default App;

Some Examples:

<Avatar name="John Doe" size={60} />
<Avatar src="https://example.com/avatar.jpg" size={60} />
<Avatar src="https://example.com/avatar.jpg" borderRadius="99px" />
<Avatar name="Alice" color="#ff5733" fontSize="1.5em" />
<Avatar name="Alice" style={{color: "red", backgroundColor: "green"}} />

Props

PropTypeDefaultDescription
namestring''The name used to generate initials.
srcstring''The image source URL.
sizenumber50The avatar size (width & height).
colorstring'#fff'The text color for initials.
fontSizestring'1em'The font size for initials.
borderRadiusstring'50%'The border radius of the avatar.
styleReact.CSSProperties{}Additional inline styles.
defaultSrcstring'https://i.pravatar.cc/100'Fallback image URL when no name or source is provided.

Features

  • Displays user initials when no image is provided.
  • Supports custom colors and sizes.
  • Falls back to a default image if neither name nor source is available.
  • Handles broken image links gracefully.

License

MIT


🎉 Enjoy using Next Avatar Component! Feel free to contribute or report issues.