Avatar
fysk/avatarFreeComponent
An image element with a fallback for representing the user.
Install it
npx shadcn@latest add https://fysk.dev/r/avatar.jsonSource
1"use client"23import * as React from "react"4import * as AvatarPrimitive from "@radix-ui/react-avatar"5import { cva, type VariantProps } from "class-variance-authority"67import { cn } from "@/lib/utils"8import { useFyskConfig } from "@/components/fysk-provider"910const avatarVariants = cva(11 "relative flex shrink-0 overflow-hidden rounded-full transition-all duration-150 active:scale-[0.98]",12 {13 variants: {14 size: {15 xs: "h-7 w-7 text-[10px]",16 sm: "h-8 w-8 text-xs",17 md: "h-9 w-9 text-xs",18 lg: "h-10 w-10 text-sm",19 xl: "h-12 w-12 text-base",20 "2xl": "h-16 w-16 text-xl",21 },22 variant: {23 default: "border border-border",24 outline: "border-2 border-border bg-transparent",25 ghost: "border-none bg-transparent",26 glass: "bg-foreground/5 backdrop-blur-md border border-border/50 shadow-xs",27 }28 },29 defaultVariants: {30 size: "md",31 variant: "default",32 },33 }34)3536export interface AvatarProps37 extends React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>,38 VariantProps<typeof avatarVariants> {39 src?: string40 alt?: string41 fallback?: React.ReactNode42 state?: "idle" | "loading" | "error"43 iconLoading?: React.ReactNode44 iconError?: React.ReactNode45}4647const Avatar = React.forwardRef<48 React.ComponentRef<typeof AvatarPrimitive.Root>,49 AvatarProps50>(({ className, src, alt, fallback, size, variant, state = "idle", iconLoading: propIconLoading, iconError: propIconError, ...props }, ref) => {51 const config = useFyskConfig()5253 const isLoading = state === "loading"54 const isError = state === "error"5556 const finalIconLoading = propIconLoading || config.icons?.loading57 const finalIconError = propIconError || config.icons?.error5859 const getInitials = (name?: string) => {60 if (!name) return "FY"61 return name62 .split(" ")63 .map((n) => n[0])64 .join("")65 .toUpperCase()66 .slice(0, 2)67 }6869 return (70 <AvatarPrimitive.Root71 ref={ref}72 className={cn(avatarVariants({ size, variant, className }))}73 {...props}74 >75 <AvatarPrimitive.Image76 src={src}77// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from fysk
All 18 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Badgebadge | fysk | Components | Free | 1 dep | |
| Buttonbutton | fysk | Components | Free | 2 deps | |
| Empty Stateempty | fysk | Components | Free | 2 deps | |
| Formform | fysk | Components | Free | 4 deps | |
| fysk-providerfysk-provider | fysk | Components | Free | 2 deps | |
| Inputinput | fysk | Components | Free | 1 dep | |
| Input OTPinput-otp | fysk | Components | Free | no deps | |
| Kbdkbd | fysk | Components | Free | 1 dep |
