shipbase
shipbase
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
export default function AvatarDemo() {
return (
<Avatar>
<AvatarImage src="https://github.com/iamdin.png" alt="@shipbase" />
<AvatarFallback>shipbase</AvatarFallback>
</Avatar>
)
}
<script setup lang="ts">
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
</script>
<template>
<Avatar>
<AvatarImage src="https://github.com/iamdin.png" alt="@shipbase" />
<AvatarFallback>shipbase</AvatarFallback>
</Avatar>
</template>
Installation
Copy and paste the following code into your project.
"use client"
import * as React from "react"
import { Avatar as AvatarPrimitive } from "@ark-ui/react/avatar"
import { cn } from "@/lib/utils"
const Avatar = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Root
ref={ref}
className={cn(
"relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
className
)}
{...props}
/>
))
Avatar.displayName = AvatarPrimitive.Root.displayName
const AvatarImage = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Image>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Image
ref={ref}
className={cn("aspect-square h-full w-full", className)}
{...props}
/>
))
AvatarImage.displayName = AvatarPrimitive.Image.displayName
const AvatarFallback = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Fallback>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Fallback
ref={ref}
className={cn(
"flex h-full w-full items-center justify-center rounded-full bg-muted",
className
)}
{...props}
/>
))
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName
export { Avatar, AvatarFallback, AvatarImage }
Avatar.vue
<script setup lang="ts">
import { cn } from "@/lib/utils"
import { AvatarRoot } from "@ark-ui/vue/avatar"
import type { HTMLAttributes } from "vue"
const props = defineProps<{
class?: HTMLAttributes["class"]
}>()
</script>
<template>
<AvatarRoot
v-bind="props"
:class="cn('relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full', props.class)">
<slot />
</AvatarRoot>
</template>
AvatarImage.vue
<script setup lang="ts">
import { cn } from "@/lib/utils"
import { AvatarImage } from "@ark-ui/vue/avatar"
import type { HTMLAttributes } from "vue"
const props = defineProps<{
class?: HTMLAttributes["class"]
}>()
</script>
<template>
<AvatarImage
v-bind="props"
:class="cn('aspect-square h-full w-full', props.class)">
<slot />
</AvatarImage>
</template>
AvatarFallback.vue
<script setup lang="ts">
import { cn } from "@/lib/utils"
import { AvatarFallback } from "@ark-ui/vue/avatar"
import type { HTMLAttributes } from "vue"
const props = defineProps<{
class?: HTMLAttributes["class"]
}>()
</script>
<template>
<AvatarFallback
v-bind="props"
:class="cn('flex h-full w-full items-center justify-center rounded-full bg-muted', props.class)">
<slot />
</AvatarFallback>
</template>
index.ts
export { default as Avatar } from "./Avatar.vue"
export { default as AvatarImage } from "./AvatarImage.vue"
export { default as AvatarFallback } from "./AvatarFallback.vue"
Update the import paths to match your project setup.
Usage
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
<Avatar>
<AvatarImage src="https://github.com/iamdin.png" />
<AvatarFallback>UI</AvatarFallback>
</Avatar>