47 lines
1.3 KiB
Vue
47 lines
1.3 KiB
Vue
<script setup lang="ts">
|
|
import { inject, useAttrs } from "vue";
|
|
import { AvatarFallback } from "reka-ui";
|
|
import { avatarVariants, type AvatarVariants } from "@heroui-vue/styles";
|
|
import { avatarContextKey } from "./context";
|
|
|
|
defineOptions({ inheritAttrs: false });
|
|
|
|
const props = defineProps<{
|
|
delayMs?: number;
|
|
color?: AvatarVariants["color"];
|
|
}>();
|
|
|
|
const attrs = useAttrs();
|
|
const ctx = inject(avatarContextKey, undefined);
|
|
|
|
// Built during render (not cached): key additions/removals on $attrs must not
|
|
// depend on computed invalidation of an initially empty key set.
|
|
function restAttrs() {
|
|
const rest: Record<string, unknown> = {};
|
|
for (const key of Object.keys(attrs)) {
|
|
if (key !== "class") rest[key] = attrs[key];
|
|
}
|
|
return rest;
|
|
}
|
|
|
|
// Single tv slot call so a local `color` replaces the inherited variant
|
|
// instead of concatenating a second `--color` class (upstream composeSlotClassName).
|
|
function fallbackClass() {
|
|
const slotArgs: Record<string, unknown> = { class: attrs.class };
|
|
if (props.color !== undefined) slotArgs.color = props.color;
|
|
const slot = ctx?.slots.value.fallback ?? avatarVariants().fallback;
|
|
return slot(slotArgs);
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<AvatarFallback
|
|
v-bind="restAttrs()"
|
|
:delay-ms="delayMs"
|
|
:class="fallbackClass()"
|
|
data-slot="avatar-fallback"
|
|
>
|
|
<slot />
|
|
</AvatarFallback>
|
|
</template>
|