Avatar

Description

The Avatar component is a component used to display an avatar image with a fallback in case of an error while loading the image.

Usage

CN

import { Avatar } from "mogora-ui";

export default function AvatarDemo() {
  return (
    <Avatar>
      <Avatar.Image src="https://github.com/shadcn.png" alt="CN" />
      <Avatar.Fallback>CN</Avatar.Fallback>
    </Avatar>
  )
}

API Reference

Avatar

The main component that provides context for managing the isLoaded and hasError state. Props: Does not accept direct props.

Avatar.Image

A component for displaying an avatar image.

PropTypeDescription
srcstringAvatar image URL.
altstringAlternative text for the image.
classNamestring(Optional) Adds a custom class for styling
...propsImgHTMLAttributes<HTMLImageElement>Additional properties for the <img> element.

Avatar.Fallback

A component that is displayed if the image fails to load.

PropTypeDescription
childrenReactNodeFallback content, such as the user's initials.

Avatar.Fallback

    1. The Avatar component uses AvatarContext to store the status of whether the image has loaded (isLoaded) or an error has occurred (hasError).
    2. Avatar.Image will display the image if it loads successfully and hide it while it is still loading.
    3. If the image fails to load, Avatar.Fallback will be displayed as a replacement.