Avatar

An img element that includes fallback and supports Nuxt Image.

Usage

The Avatar uses the <NuxtImg> component when @nuxt/image is installed, falling back to img otherwise.

employee
<template>
  <B24Avatar src="/b24ui/avatar/employee.png" alt="employee" />
</template>
You can pass any property from the HTML <img> element such as alt, loading, etc.
To opt-out of @nuxt/image, use the as prop: :as="{ img: 'img' }".

Src

Use the src prop to set the image URL.

<template>
  <B24Avatar src="https://github.com/bitrix24.png" />
</template>

Size

Use the size prop to set the size of the Avatar.

<template>
  <B24Avatar size="2xl" src="/b24ui/avatar/assistant.png" />
</template>
The <img> element's width and height are automatically set based on the size prop.

Icon

Use the icon prop to display a fallback Icon.

<script setup lang="ts">
import RocketIcon from '@bitrix24/b24icons-vue/main/RocketIcon'
</script>

<template>
  <B24Avatar :icon="RocketIcon" size="md" />
</template>

Text

Use the text prop to display a fallback text.

+24
<template>
  <B24Avatar text="+24" size="xl" />
</template>

Alt

When no icon or text is provided, the initials of the alt prop is used as fallback.

EN
<template>
  <B24Avatar alt="Employee Name" size="xl" />
</template>
The alt prop is passed to the img element as the alt attribute.

Chip

Use the chip prop to display a chip around the Avatar.

+1
<template>
  <B24Avatar
    src="/b24ui/avatar/assistant.png"
    :chip="{
      text: '+1',
      inset: true,
      hideZero: true
    }"
  />
</template>

Examples

With tooltip

You can use a Tooltip component to display a tooltip when hovering the Avatar.

Employee Name
<template>
  <B24Tooltip text="Employee Name">
    <B24Avatar
      src="/b24ui/avatar/employee.png"
      alt="Employee Name"
    />
  </B24Tooltip>
</template>

With mask

You can use a CSS mask to display an Avatar with a custom shape instead of a simple circle.

Employee Name
<template>
  <B24Avatar class="rounded-none squircle" src="/b24ui/avatar/employee.png" alt="Employee Name" size="3xl" />
</template>

<style>
.squircle {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M8.65 20H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12t.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5t.738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737t-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5t-.737-.15t-.663-.425z'/%3E%3C/svg%3E");
  mask-size: contain;
  mask-position: center;
  mask-repeat: no-repeat;
}
</style>

API

Props

Prop Default Type
as'span'any

The element or component this component should render as.

src string
alt string
iconIconComponent

Display an icon on the left side.

text string
size'md' "md" | "3xs" | "2xs" | "xs" | "sm" | "lg" | "xl" | "2xl" | "3xl"
chipboolean | ChipProps
crossorigin "" | "anonymous" | "use-credentials"
decoding "async" | "auto" | "sync"
height string | number
loading "lazy" | "eager"
referrerpolicy "" | "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url"
sizes string
srcset string
usemap string
width string | number
b24ui { root?: ClassNameValue; image?: ClassNameValue; fallback?: ClassNameValue; icon?: ClassNameValue; }
This component also supports all native <img> HTML attributes.

Theme

app.config.ts
export default defineAppConfig({
  b24ui: {
    avatar: {
      slots: {
        root: 'air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7)',
        image: 'h-full w-full rounded-[inherit] object-cover',
        fallback: 'font-(--ui-font-weight-medium) text-(--ui-color-design-plain-content-icon-secondary) truncate',
        icon: 'text-(--ui-color-design-plain-content-icon-secondary) shrink-0'
      },
      variants: {
        size: {
          '3xs': {
            root: 'size-[10px] text-4xs font-(--ui-font-weight-regular)',
            icon: 'size-[10px]'
          },
          '2xs': {
            root: 'size-[20px] text-(length:--ui-font-size-4xs)/(--ui-font-line-height-reset) font-(--ui-font-weight-regular)',
            icon: 'size-[18px]'
          },
          xs: {
            root: 'size-[24px] text-(length:--ui-font-size-3xs)/(--ui-font-line-height-reset) font-(--ui-font-weight-regular)',
            icon: 'size-[22px]'
          },
          sm: {
            root: 'size-[28px] text-(length:--ui-font-size-xs)/(--ui-font-line-height-reset)',
            icon: 'size-[26px]'
          },
          md: {
            root: 'size-[32px] text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset)',
            icon: 'size-[28px]'
          },
          lg: {
            root: 'size-[42px] text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset)',
            icon: 'size-[38px]'
          },
          xl: {
            root: 'ring-2 size-[48px] text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset)',
            icon: 'size-[44px]'
          },
          '2xl': {
            root: 'ring-2 size-[60px] text-(length:--ui-font-size-5xl)/(--ui-font-line-height-reset)',
            icon: 'size-[56px]'
          },
          '3xl': {
            root: 'ring-2 size-[94px] text-[34px]/(--ui-font-line-height-reset)',
            icon: 'size-[90px]'
          }
        }
      },
      defaultVariants: {
        size: 'md'
      }
    }
  }
})
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import bitrix24UIPluginVite from '@bitrix24/b24ui-nuxt/vite'

export default defineConfig({
  plugins: [
    vue(),
    bitrix24UIPluginVite({
      b24ui: {
        avatar: {
          slots: {
            root: 'air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7)',
            image: 'h-full w-full rounded-[inherit] object-cover',
            fallback: 'font-(--ui-font-weight-medium) text-(--ui-color-design-plain-content-icon-secondary) truncate',
            icon: 'text-(--ui-color-design-plain-content-icon-secondary) shrink-0'
          },
          variants: {
            size: {
              '3xs': {
                root: 'size-[10px] text-4xs font-(--ui-font-weight-regular)',
                icon: 'size-[10px]'
              },
              '2xs': {
                root: 'size-[20px] text-(length:--ui-font-size-4xs)/(--ui-font-line-height-reset) font-(--ui-font-weight-regular)',
                icon: 'size-[18px]'
              },
              xs: {
                root: 'size-[24px] text-(length:--ui-font-size-3xs)/(--ui-font-line-height-reset) font-(--ui-font-weight-regular)',
                icon: 'size-[22px]'
              },
              sm: {
                root: 'size-[28px] text-(length:--ui-font-size-xs)/(--ui-font-line-height-reset)',
                icon: 'size-[26px]'
              },
              md: {
                root: 'size-[32px] text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset)',
                icon: 'size-[28px]'
              },
              lg: {
                root: 'size-[42px] text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset)',
                icon: 'size-[38px]'
              },
              xl: {
                root: 'ring-2 size-[48px] text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset)',
                icon: 'size-[44px]'
              },
              '2xl': {
                root: 'ring-2 size-[60px] text-(length:--ui-font-size-5xl)/(--ui-font-line-height-reset)',
                icon: 'size-[56px]'
              },
              '3xl': {
                root: 'ring-2 size-[94px] text-[34px]/(--ui-font-line-height-reset)',
                icon: 'size-[90px]'
              }
            }
          },
          defaultVariants: {
            size: 'md'
          }
        }
      }
    })
  ]
})
Releases
Published under MIT License.

Copyright © 2024-present Bitrix24