mirror of
https://github.com/AppFlowy-IO/AppFlowy-Web.git
synced 2025-11-29 10:47:56 +08:00
* chore: import new ui system * chore: modified padding and rounded * chore: remove vertical padding * chore: add shadow * chore: add shadcn popover (#76) * chore: add circle progress (#77) * chore: add input (#78) * feat: add shadcn toast (#80) * chore: initial import * chore: style * chore: important * chore: add dropdown menu (#81) * feat: add shadcn tooltip (#79) * chore: initial import * chore: style * chore: fix text size * chore: add tooltip shortcut * chore: code cleanup and add flex col * chore: add avatar (#82) * chore: add dialog (#83) --------- Co-authored-by: Richard Shiue <71320345+richardshiue@users.noreply.github.com>
91 lines
2.0 KiB
TypeScript
91 lines
2.0 KiB
TypeScript
import { cva, type VariantProps } from 'class-variance-authority';
|
|
import * as React from 'react';
|
|
import * as AvatarPrimitive from '@radix-ui/react-avatar';
|
|
|
|
import { cn } from '@/lib/utils';
|
|
|
|
const avatarVariants = cva(
|
|
'relative flex aspect-square shrink-0 overflow-hidden',
|
|
{
|
|
variants: {
|
|
shape: {
|
|
circle: 'rounded-full',
|
|
square: 'rounded-200',
|
|
},
|
|
variant: {
|
|
default: 'bg-transparent',
|
|
outline: 'border-[1.5px] bg-transparent border-border-grey-tertiary',
|
|
},
|
|
size: {
|
|
sm: 'h-6 text-xs leading-[16px] text-icon-primary font-normal',
|
|
md: 'h-8 text-sm font-normal',
|
|
xl: 'h-20 text-2xl font-normal',
|
|
},
|
|
},
|
|
defaultVariants: {
|
|
variant: 'default',
|
|
size: 'md',
|
|
shape: 'circle',
|
|
},
|
|
},
|
|
);
|
|
|
|
function Avatar ({
|
|
className,
|
|
size,
|
|
variant,
|
|
shape = 'circle',
|
|
...props
|
|
}: React.ComponentProps<typeof AvatarPrimitive.Root> & VariantProps<typeof avatarVariants>) {
|
|
return (
|
|
<AvatarPrimitive.Root
|
|
data-slot="avatar"
|
|
className={cn(
|
|
avatarVariants({
|
|
size,
|
|
variant,
|
|
shape,
|
|
}),
|
|
className,
|
|
)}
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function AvatarImage ({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<typeof AvatarPrimitive.Image>) {
|
|
return (
|
|
<AvatarPrimitive.Image
|
|
data-slot="avatar-image"
|
|
className={cn('aspect-square size-full', className)}
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function AvatarFallback ({
|
|
className,
|
|
children,
|
|
...props
|
|
}: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
|
|
const isString = typeof children === 'string';
|
|
const char = isString ? children.charAt(0) : '';
|
|
|
|
return (
|
|
<AvatarPrimitive.Fallback
|
|
data-slot="avatar-fallback"
|
|
className={cn(
|
|
'flex text-icon-primary w-full h-full items-center justify-center',
|
|
isString ? 'bg-fill-tertiary' : '',
|
|
className,
|
|
)}
|
|
{...props}
|
|
>{!isString ? children : char}</AvatarPrimitive.Fallback>
|
|
);
|
|
}
|
|
|
|
export { Avatar, AvatarImage, AvatarFallback };
|