1 line
2.3 KiB
JavaScript
1 line
2.3 KiB
JavaScript
import{R as E,a as u,j as t}from"./vendor-react-Dkpvlwai.js";import{d as r}from"./index-VJPzCABl.js";const S=E.forwardRef(({src:a,alt:n="Avatar",fallback:h,size:s="md",status:d,badge:e,className:m="",onClick:i},b)=>{const[x,c]=u.useState(!1),[w,g]=u.useState(!1),p={xs:"w-6 h-6 text-[10px]",sm:"w-8 h-8 text-xs",md:"w-10 h-10 text-sm",lg:"w-12 h-12 text-base",xl:"w-16 h-16 text-lg","2xl":"w-24 h-24 text-xl","3xl":"w-32 h-32 text-2xl"},f={online:"bg-kodo-lime",offline:"bg-muted",away:"bg-warning",idle:"bg-warning",busy:"bg-destructive",dnd:"bg-destructive"},v={xs:"w-1.5 h-1.5 border",sm:"w-2 h-2 border",md:"w-2.5 h-2.5 border-2",lg:"w-3 h-3 border-2",xl:"w-4 h-4 border-2","2xl":"w-5 h-5 border-4","3xl":"w-6 h-6 border-4"},j={primary:"bg-primary text-primary-foreground",destructive:"bg-destructive text-destructive-foreground",success:"bg-kodo-lime text-kodo-lime-foreground"},y={xs:"w-2.5 h-2.5 text-[6px]",sm:"w-3 h-3 text-[7px]",md:"w-4 h-4 text-[8px]",lg:"w-4.5 h-4.5 text-[9px]",xl:"w-5 h-5 text-[10px]","2xl":"w-6 h-6 text-xs","3xl":"w-8 h-8 text-sm"},N={xs:"w-1.5 h-1.5",sm:"w-2 h-2",md:"w-2.5 h-2.5",lg:"w-3 h-3",xl:"w-3.5 h-3.5","2xl":"w-4 h-4","3xl":"w-5 h-5"},k=(l=>{if(!l)return"?";const o=l.trim().split(" ");return o.length>=2?(o[0][0]+o[o.length-1][0]).toUpperCase():l.substring(0,2).toUpperCase()})(h||n),C=!a||w;return t.jsxs("div",{ref:b,className:r("relative inline-block active:scale-95 transition-transform",m,i?"cursor-pointer":""),onClick:i,children:[t.jsx("div",{className:r(p[s],"rounded-full overflow-hidden bg-card border border-border flex items-center justify-center relative"),children:C?t.jsx("span",{className:"font-bold text-muted-foreground",children:k}):t.jsxs(t.Fragment,{children:[!x&&t.jsx("div",{className:"absolute inset-0 rounded-full bg-muted animate-pulse","aria-hidden":"true"}),t.jsx("img",{src:a,alt:n,onLoad:()=>c(!0),onError:()=>{g(!0),c(!0)},className:r("w-full h-full object-cover transition-opacity duration-200",x?"opacity-100":"opacity-0")})]})}),d&&t.jsx("span",{className:r("absolute bottom-0 right-0 rounded-full border-background",f[d],v[s])}),e&&t.jsx("span",{className:r("absolute -top-0.5 -right-0.5 rounded-full border-2 border-background flex items-center justify-center font-bold leading-none",j[e.color??"primary"],e.dot?N[s]:y[s]),children:!e.dot&&e.count!=null?e.count:null})]})});S.displayName="Avatar";export{S as A};
|