Использование
Если установлен @nuxt/image, Avatar использует компонент <NuxtImg>, иначе — обычный img.
<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.
<template>
<B24Avatar
src="/b24ui/avatar/assistant.png"
loading="lazy"
:chip="{
text: '+1',
inset: true,
hideZero: true
}"
/>
</template>
Примеры
С подсказкой
Компонент Tooltip показывает подсказку при наведении на Avatar.
С маской
CSS-маска позволяет показать Avatar не кругом, а в нестандартной форме.
API
Пропсы
Тема
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'
}
}