Avatar
Usage
Image
Use the image-url prop to show a picture, and the name prop to name the avatar for screen readers.
<KAvatar name="Avery Collins" image-url="/avatars/avery-collins.webp" size="2xl" />
Initials
Without an image, the avatar shows the first letter of name. Use the initials prop to show other letters. The text shrinks to fit up to three letters.
<KAvatar name="Avery Collins" size="2xl" />
<KAvatar name="Avery Collins" initials="AC" size="2xl" />
<KAvatar name="Northwind Bank Group" initials="NBG" size="2xl" />
Icon
Use the icon prop to show an icon. It takes a Lucide icon component, sized to the avatar. It suits categories and companies.
<script setup lang="ts">
import { Banknote, Landmark, Plane, ShoppingBag, Sparkles, Utensils } from 'lucide-vue-next'
</script>
<template>
<KAvatar name="Shopping" :icon="ShoppingBag" color="discovery" size="2xl" />
<KAvatar name="Dining" :icon="Utensils" color="danger" size="2xl" />
<KAvatar name="Travel" :icon="Plane" color="info" size="2xl" />
<KAvatar name="Salary" :icon="Banknote" color="success" size="2xl" />
<KAvatar name="Bank transfer" :icon="Landmark" size="2xl" />
<KAvatar name="Assistant" :icon="Sparkles" color="primary" variant="solid" size="2xl" />
</template>
Overflow count
Use the overflow-count prop to show how many more people there are, like +5. Counts from a thousand are shortened, like +1k or +3m. Screen readers read the full count, like "1200 more".
<KAvatar :overflow-count="5" size="2xl" />
<KAvatar :overflow-count="24" size="2xl" />
<KAvatar :overflow-count="1200" size="2xl" />
Variant
Use the variant prop to change the look of the avatar: soft (default) or solid.
<KAvatar name="Riley Brooks" initials="RB" color="info" size="2xl" />
<KAvatar name="Riley Brooks" initials="RB" color="info" variant="solid" size="2xl" />
Color
Use the color prop to change the color of the avatar: primary, secondary, gray (default), success, info, discovery or danger.
<KAvatar name="Avery" color="primary" size="2xl" />
<KAvatar name="Blake" color="secondary" size="2xl" />
<KAvatar name="Casey" size="2xl" />
<KAvatar name="Drew" color="success" size="2xl" />
<KAvatar name="Emery" color="info" size="2xl" />
<KAvatar name="Finley" color="discovery" size="2xl" />
<KAvatar name="Harper" color="danger" size="2xl" />
Size
Use the size prop to change the size of the avatar, from 3xs (22px) to 6xl (80px). The default is md (32px).
<KAvatar name="Avery Collins" image-url="/avatars/avery-collins.webp" size="3xs" />
<KAvatar name="Avery Collins" image-url="/avatars/avery-collins.webp" size="md" />
<KAvatar name="Avery Collins" image-url="/avatars/avery-collins.webp" size="6xl" />
Pill
Avatars are round by default. Set pill to false to get rounded corners that follow the size. It suits companies and apps.
<KAvatar name="Acme" color="primary" variant="solid" size="2xl" :pill="false" />
<KAvatar name="Northwind Bank" initials="NB" color="success" size="2xl" :pill="false" />
<KAvatar name="Kai Mensah" image-url="/avatars/kai-mensah.webp" size="2xl" :pill="false" />
Link
Use the href prop to make the avatar a link, like to a profile page. It gets a focus ring, and name becomes the name of the link.
<KAvatar name="Avery Collins" image-url="/avatars/avery-collins.webp" size="2xl" href="/members/avery-collins" />
Customization
Use the ui prop to change the classes of each part of the avatar, and class for the root element. Your classes always win: rounded-none replaces the default rounded-full instead of being added to it.
<KAvatar name="Avery Collins" image-url="/avatars/avery-collins.webp" size="2xl" :ui="{ base: 'rounded-none' }" />
API
Props
| Prop | Type | Default |
|---|---|---|
name | string | |
imageUrl | string | |
icon | Component | |
initials | string | First letter of name |
overflowCount | number | 0 |
variant | 'soft' | 'solid' | 'soft' |
color | 'primary' | 'secondary' | 'gray' | 'success' | 'info' | 'discovery' | 'danger' | 'gray' |
size | '3xs' | '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | '6xl' | 'md' |
pill | boolean | true |
href | string | |
ui | { base?, image?, icon?, label?, overflowSign? } | |
class | string |
When several are set, the avatar shows the image first, then the icon, then the overflow count, then the initials.