v2.15.0

Avatar

Элемент img с запасным видом; поддерживает Nuxt Image.

Использование

Если установлен @nuxt/image, Avatar использует компонент <NuxtImg>, иначе — обычный img.

employee
<template>
  <B24Avatar src="/b24ui/avatar/employee.png" alt="employee" loading="lazy" />
</template>
Можно передать любое свойство HTML-элемента <img>: alt, loading и другие.
Чтобы отказаться от @nuxt/image, используйте пропс as: :as="{ img: 'img' }".

Источник изображения

Пропс src задаёт адрес изображения.

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

Размер

Пропс size задаёт размер Avatar.

<template>
  <B24Avatar size="2xl" src="/b24ui/avatar/assistant.png" loading="lazy" />
</template>
Атрибуты width и height элемента <img> выставляются автоматически по пропсу size.

Иконка

Пропс icon показывает запасную иконку.

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

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

Текст

Пропс text показывает запасной текст.

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

Альтернативный текст

Если нет ни иконки, ни текста, запасным видом служат инициалы из пропса alt.

ИП
<template>
  <B24Avatar alt="Иван Петров" size="xl" />
</template>
Пропс alt передаётся элементу img как атрибут alt.

Цвет

Пропс color меняет цвет Avatar.

ИП
<template>
  <B24Avatar color="air-boost" alt="Иван Петров" />
</template>

Чип

Пропс chip показывает чип рядом с Avatar.

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

Примеры

С подсказкой

Компонент Tooltip показывает подсказку при наведении на Avatar.

Имя сотрудника
<template>
  <B24Tooltip text="Имя сотрудника">
    <B24Avatar
      src="/b24ui/avatar/employee.png"
      alt="Имя сотрудника"
      loading="lazy"
    />
  </B24Tooltip>
</template>

С маской

CSS-маска позволяет показать Avatar не кругом, а в нестандартной форме.

Имя сотрудника
<template>
  <B24Avatar
    class="rounded-none squircle"
    src="/b24ui/avatar/employee.png"
    alt="Имя сотрудника"
    size="3xl"
    loading="lazy"
  />
</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

Пропсы

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"
color'air-secondary-no-accent'"air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot" | "air-secondary" | "air-secondary-alert" | "air-secondary-accent" | "air-secondary-accent-1" | "air-secondary-accent-2" | "air-secondary-no-accent" | "air-tertiary" | "air-tertiary-accent" | "air-tertiary-no-accent" | "air-selection" | "air-boost" | "air-primary-no-accent"
chipboolean | ChipProps
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
crossorigin "anonymous" | "use-credentials"
b24ui { root?: SlotClass; image?: SlotClass; fallback?: SlotClass; icon?: SlotClass; }
Компонент поддерживает и все нативные HTML-атрибуты <img>.

Тема

https://github.com/bx-shef/b24-ui/tree/main/src/theme/avatar.ts
export default {
  slots: {
    root: 'air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--b24ui-background) ring ring-(--b24ui-border-color)',
    image: 'h-full w-full rounded-[inherit] object-cover',
    fallback: 'font-(--ui-font-weight-medium) text-(--b24ui-color) truncate',
    icon: 'text-(--b24ui-icon) shrink-0'
  },
  variants: {
    color: {
      'air-primary': {
        root: 'style-filled'
      },
      'air-primary-success': {
        root: 'style-filled-success'
      },
      'air-primary-alert': {
        root: 'style-filled-alert'
      },
      'air-primary-copilot': {
        root: 'style-filled-copilot'
      },
      'air-primary-warning': {
        root: 'style-filled-warning'
      },
      'air-primary-no-accent': {
        root: 'style-filled-no-accent'
      },
      'air-secondary': {
        root: 'style-tinted'
      },
      'air-secondary-alert': {
        root: 'style-tinted-alert'
      },
      'air-secondary-accent': {
        root: 'style-outline'
      },
      'air-secondary-accent-1': {
        root: 'style-outline-accent-1'
      },
      'air-secondary-accent-2': {
        root: 'style-outline-accent-2'
      },
      'air-secondary-no-accent': {
        root: 'style-outline-no-accent'
      },
      'air-tertiary': {
        root: 'style-plain'
      },
      'air-tertiary-accent': {
        root: 'style-plain-accent'
      },
      'air-tertiary-no-accent': {
        root: 'style-plain-no-accent'
      },
      'air-selection': {
        root: 'style-selection'
      },
      'air-boost': {
        root: 'style-filled-boost'
      }
    },
    size: {
      '3xs': {
        root: 'size-2.5 text-4xs font-(--ui-font-weight-regular)',
        icon: 'size-2.5'
      },
      '2xs': {
        root: 'size-5 text-(length:--ui-font-size-4xs)/(--ui-font-line-height-reset) font-(--ui-font-weight-regular)',
        icon: 'size-4.5'
      },
      xs: {
        root: 'size-6 text-(length:--ui-font-size-3xs)/(--ui-font-line-height-reset) font-(--ui-font-weight-regular)',
        icon: 'size-5.5'
      },
      sm: {
        root: 'size-7 text-(length:--ui-font-size-xs)/(--ui-font-line-height-reset)',
        icon: 'size-6.5'
      },
      md: {
        root: 'size-8 text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset)',
        icon: 'size-7'
      },
      lg: {
        root: 'size-10.5 text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset)',
        icon: 'size-9.5'
      },
      xl: {
        root: 'ring-2 size-12 text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset)',
        icon: 'size-11'
      },
      '2xl': {
        root: 'ring-2 size-15 text-(length:--ui-font-size-5xl)/(--ui-font-line-height-reset)',
        icon: 'size-14'
      },
      '3xl': {
        root: 'ring-2 size-23.5 text-6xl/(--ui-font-line-height-reset)',
        icon: 'size-22.5'
      }
    }
  },
  defaultVariants: {
    size: 'md',
    color: 'air-secondary-no-accent'
  }
}