# Avatar

The Avatar component displays a user's profile picture or initials in a circular or square format. It helps create a personalized and recognizable interface element, representing users visually across different parts of the application.

## Overview

```tsx
import { Avatar } from 'welcome-ui/Avatar'

const Example = () => {
  return (
    <>
      <Avatar
        name="Welcome UI"
        src="https://images.unsplash.com/photo-1517849845537-4d257902454a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=80"
      />
      <Avatar name="Welcome UI" />
      <Avatar />
    </>
  )
}

export default Example
```

## Examples

### Image

Pass an image url with `src="you-url"`.

```tsx
import { Avatar } from 'welcome-ui/Avatar'

const Example = () => {
  return (
    <>
      <Avatar
        name="Welcome UI"
        src="https://images.unsplash.com/photo-1517849845537-4d257902454a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=80"
      />
    </>
  )
}

export default Example
```

### Placeholder

If no image is provided and no name is given, we display a generic placeholder.

```tsx
import { Avatar } from 'welcome-ui/Avatar'

const Example = () => {
  return <Avatar />
}

export default Example
```

### Text

If no image is provided we create a two-letter initial based on the name. We choose a random colour from secondaries theme colours for the background. For `xs`and `sm` sizes, we only display the first letter.

```tsx
import { Avatar } from 'welcome-ui/Avatar'

const Example = () => {
  return (
    <>
      <Avatar name="Welcome UI t" />
      <Avatar name="Welcome UI te" />
      <Avatar name="Welcome UI tes" />
      <Avatar name="Welcome UI test" />
      <Avatar name="Welcome UI teest" />
      <Avatar name="Welcome UI teeest" />
    </>
  )
}

export default Example
```

### Size

You can use `xs`, `sm`, `md` and `lg` sizes.

```tsx
import { Avatar } from 'welcome-ui/Avatar'

const Example = () => {
  return (
    <div className="flex flex-col gap-xxl">
      <div className="flex gap-xl items-center">
        <Avatar
          name="Welcome UI"
          size="lg"
          src="https://images.unsplash.com/photo-1517849845537-4d257902454a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=80"
        />
        <Avatar
          name="Welcome UI"
          src="https://images.unsplash.com/photo-1517849845537-4d257902454a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=80"
        />
        <Avatar
          name="Welcome UI"
          size="sm"
          src="https://images.unsplash.com/photo-1517849845537-4d257902454a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=80"
        />
        <Avatar
          name="Welcome UI"
          size="xs"
          src="https://images.unsplash.com/photo-1517849845537-4d257902454a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=80"
        />
      </div>
      <div className="flex gap-xl items-center">
        <Avatar name="Welcome UI" size="lg" />
        <Avatar name="Welcome UI" />
        <Avatar name="Welcome UI" size="sm" />
        <Avatar name="Welcome UI" size="xs" />
      </div>
      <div className="flex gap-xl items-center">
        <Avatar size="lg" />
        <Avatar />
        <Avatar size="sm" />
        <Avatar size="xs" />
      </div>
    </div>
  )
}

export default Example
```

## Props

### Avatar

```tsx
interface AvatarProps {
  getInitials?: (name: string) => string
  name?: string
  /** Default: md */
  size?: 'xs' | 'sm' | 'md' | 'lg'
  src?: string
}
```