Avatar
Show a profile image with a fallback when it cannot load.
Demos
Size
TM
Usage
vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Images and fallbacks
Supply src for a portrait and text for the fallback. The fallback also appears when the image cannot load. Set alt to identify the person, or use an empty string when adjacent text already provides their name.
TMImage
ILInitials
TMImage unavailable
vue
<AppLayout :viewport="false" scroll="page">
<template #header>Workspace</template>
<template #left><ProjectNavigation /></template>
<ProjectList />
<template #footer>2 projects</template>
</AppLayout>
Installation
Complete the shared installation. Copy Avatar.vue and index.ts into app/components/ui/avatar/.
app/components/ui/avatar/Avatar.vue
<script setup lang="ts">
import { Accordion as Primitive } from 'akaza-ui'
import { computed, useAttrs } from 'vue'
import { cn } from '../../../utils/ui'
import uiConfig from '../ui.config'
import {
accordionVariants,
resolveAccordionVariants,
type AccordionProps,
type AccordionSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<AccordionProps>(), {
valueKey: undefined,
labelKey: undefined,
contentKey: undefined,
disabledKey: undefined,
type: undefined,
collapsible: true,
disabled: undefined,
orientation: undefined,
unmountOnHide: undefined,
as: undefined,
ui: undefined,
modelValue: undefined,
})
defineSlots<AccordionSlots>()
const attrs = useAttrs()
const styles = computed(() => accordionVariants(resolveAccordionVariants(props, uiConfig)))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
return Object.fromEntries(
Object.entries(styles.value).map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'root' ? props.class : undefined),
]),
)
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, size: _size, ...native } = props
return native
})
</script>
<template>
<component :is="Primitive" v-bind="{ ...primitiveProps, ...attrs }" :ui="mergedUi">
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof AccordionSlots" v-bind="scope ?? {}"
/></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
size | xs, sm, md, lg, xl | sm |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
src | string | — | Image URL. |
alt | string | "" | Alt text for the image. |
text | string | — | Fallback text (e.g. initials) when no #fallback slot is provided. |
delayMs | number | 0 | Delay in ms before showing the fallback. Prevents flash on fast loads. |
as | string | "span" | Root element tag. |
ui | AvatarUi | — | CSS class overrides. |
Slots
| Slot | Scoped props | Description |
|---|---|---|
image | { src, alt, status } | The image element. |
fallback | { status } | Shown when image is unavailable or loading. |
status is one of: "idle" · "loading" · "loaded" · "error"
Events
| Event | Payload | Description |
|---|---|---|
status-change | [status: AvatarImageStatus] | Fired when image loading status changes. |