Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
♻️ Migrate Avatar to Base UI and modernize its API (#2429)
Luke Vella58c703c1cb8d
diff --git a/apps/web/src/app/[locale]/(space)/settings/event-types/event-types-settings-page.tsx b/apps/web/src/app/[locale]/(space)/settings/event-types/event-types-settings-page.tsxindex 2757a0719..c86847bcf 100644--- a/apps/web/src/app/[locale]/(space)/settings/event-types/event-types-settings-page.tsx+++ b/apps/web/src/app/[locale]/(space)/settings/event-types/event-types-settings-page.tsx@@ -101,7 +101,7 @@ function EventTypeCard({<RandomGradientBar /><div className="p-3"><div className="flex items-start justify-between gap-2">- <OptimizedAvatarImage size="lg" src={hostImage} name={hostName} />+ <OptimizedAvatarImage size="md" src={hostImage} name={hostName} /><DropdownMenu><DropdownMenuTrigger asChild><Button variant="ghost" size="icon">diff --git a/apps/web/src/components/discussion/discussion.tsx b/apps/web/src/components/discussion/discussion.tsxindex 6ea01c3c5..133a80570 100644--- a/apps/web/src/components/discussion/discussion.tsx+++ b/apps/web/src/components/discussion/discussion.tsx@@ -190,7 +190,7 @@ function DiscussionInner() {<Participant><OptimizedAvatarImagename={comment.authorName}- size="md"+ size="sm"/><ParticipantName>{comment.authorName}</ParticipantName>{session.ownsObject(comment) ? (@@ -228,7 +228,7 @@ function DiscussionInner() {)}</div></div>- <div className="w-fit whitespace-pre-wrap pl-7 text-sm leading-relaxed">+ <div className="w-fit whitespace-pre-wrap pl-8 text-sm leading-relaxed"><TruncatedLinkify>{comment.content}</TruncatedLinkify></div></div>diff --git a/apps/web/src/components/optimized-avatar-image.tsx b/apps/web/src/components/optimized-avatar-image.tsxindex cbd9160ab..6eeb1257e 100644--- a/apps/web/src/components/optimized-avatar-image.tsx+++ b/apps/web/src/components/optimized-avatar-image.tsx@@ -35,7 +35,8 @@ export function OptimizedAvatarImage({className?: string;email?: string;}) {- const [isLoaded, setLoaded] = React.useState(false);+ const [loadedSrc, setLoadedSrc] = React.useState<string | null>(null);+ const [erroredSrc, setErroredSrc] = React.useState<string | null>(null);const [gravatarUrl, setGravatarUrl] = React.useState<string | null>(null);React.useEffect(() => {@@ -58,10 +59,12 @@ export function OptimizedAvatarImage({.toUpperCase();const imageSrc = src || gravatarUrl;+ const isLoaded = !!imageSrc && loadedSrc === imageSrc;+ const hasError = !!imageSrc && erroredSrc === imageSrc;return (- <Avatar className={cn("rounded-full", className)} size={size}>- {imageSrc ? (+ <Avatar className={className} size={size === "md" ? "default" : size}>+ {imageSrc && !hasError ? (imageSrc.startsWith("https") || imageSrc.startsWith("data:") ? (<AvatarImage src={imageSrc} alt={name} />) : (@@ -72,13 +75,16 @@ export function OptimizedAvatarImage({alt={name}style={{ objectFit: "cover" }}onLoad={() => {- setLoaded(true);+ setLoadedSrc(imageSrc);+ }}+ onError={() => {+ setErroredSrc(imageSrc);}}/>)) : null}{!imageSrc || !isLoaded ? (- <AvatarFallback seed={name} className={cn("shrink-0")}>+ <AvatarFallback className={cn("shrink-0")}>{/^\p{L}+$/u.test(initials) ? (initials) : (diff --git a/apps/web/src/components/participant-avatar-bar.tsx b/apps/web/src/components/participant-avatar-bar.tsxdeleted file mode 100644index 1bf1080e0..000000000--- a/apps/web/src/components/participant-avatar-bar.tsx+++ /dev/null@@ -1,94 +0,0 @@-import { cn } from "@rallly/ui";-import {- Tooltip,- TooltipContent,- TooltipPortal,- TooltipTrigger,-} from "@rallly/ui/tooltip";--import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";-import { Trans } from "@/i18n/client";--interface ParticipantAvatarBarProps {- participants: { name: string; image?: string }[];- max?: number;-}--export const ParticipantAvatarBar = ({- participants,- max = Number.POSITIVE_INFINITY,-}: ParticipantAvatarBarProps) => {- const totalParticipants = participants.length;-- const visibleCount = totalParticipants <= max ? totalParticipants : max - 1;-- const visibleParticipants = participants.slice(0, visibleCount);-- const tooltipParticipants = participants.slice(- visibleCount,- visibleCount + 10,- );-- const remainingCount =- totalParticipants - visibleCount - tooltipParticipants.length;-- const hiddenCount = totalParticipants - visibleCount;-- return (- <ul className="flex cursor-default items-center -space-x-1 rounded-full bg-background p-0.5">- {visibleParticipants.map((participant, index) => (- // biome-ignore lint/suspicious/noArrayIndexKey: Fix this later- <Tooltip delayDuration={100} key={index}>- <TooltipTrigger asChild>- <li className="z-10 inline-flex items-center justify-center rounded-full ring-2 ring-background">- <OptimizedAvatarImage- name={participant.name}- src={participant.image}- size="sm"- />- </li>- </TooltipTrigger>- <TooltipPortal>- <TooltipContent>{participant.name}</TooltipContent>- </TooltipPortal>- </Tooltip>- ))}- {hiddenCount > 0 ? (- <li className="relative z-10 inline-flex items-center justify-center rounded-full ring-2 ring-white">- <Tooltip>- <TooltipTrigger asChild>- <span- className={cn(- "select-none",- "rounded-full bg-gray-100 px-1.5 font-semibold text-xs",- "inline-flex h-5 items-center justify-center",- )}- >- +{hiddenCount}- </span>- </TooltipTrigger>- <TooltipPortal>- <TooltipContent className="z-10">- <ul>- {tooltipParticipants.map((participant, index) => (- // biome-ignore lint/suspicious/noArrayIndexKey: Fix this later- <li key={index}>{participant.name}</li>- ))}- {remainingCount > 0 && (- <li>- <Trans- i18nKey="moreParticipants"- values={{ count: remainingCount }}- defaults="{count} more…"- />- </li>- )}- </ul>- </TooltipContent>- </TooltipPortal>- </Tooltip>- </li>- ) : null}- </ul>- );-};diff --git a/apps/web/src/components/poll/desktop-poll.tsx b/apps/web/src/components/poll/desktop-poll.tsxindex e6b412135..ca15ee7a9 100644--- a/apps/web/src/components/poll/desktop-poll.tsx+++ b/apps/web/src/components/poll/desktop-poll.tsx@@ -1,3 +1,5 @@+"use client";+import { cn } from "@rallly/ui";import { Badge } from "@rallly/ui/badge";import { Button } from "@rallly/ui/button";diff --git a/apps/web/src/components/poll/desktop-poll/participant-row-form.tsx b/apps/web/src/components/poll/desktop-poll/participant-row-form.tsxindex 98913d1a9..82bd7abdf 100644--- a/apps/web/src/components/poll/desktop-poll/participant-row-form.tsx+++ b/apps/web/src/components/poll/desktop-poll/participant-row-form.tsx@@ -66,7 +66,7 @@ const ParticipantRowForm = ({{name ? (<OptimizedAvatarImagename={participantName}- size="md"+ size="sm"email={email}src={image ?? undefined}/>diff --git a/apps/web/src/components/poll/desktop-poll/participant-row.tsx b/apps/web/src/components/poll/desktop-poll/participant-row.tsxindex caf1b0a5c..a3433b014 100644--- a/apps/web/src/components/poll/desktop-poll/participant-row.tsx+++ b/apps/web/src/components/poll/desktop-poll/participant-row.tsx@@ -1,3 +1,5 @@+"use client";+import type { VoteType } from "@rallly/database";import { cn } from "@rallly/ui";import { Badge } from "@rallly/ui/badge";@@ -63,7 +65,7 @@ export const ParticipantRowView: React.FunctionComponent<{<div className="flex max-w-full items-center justify-between gap-x-1"><Participant><OptimizedAvatarImage- size="md"+ size="sm"name={name}email={email}src={image ?? undefined}diff --git a/apps/web/src/components/poll/mobile-poll/poll-option.tsx b/apps/web/src/components/poll/mobile-poll/poll-option.tsxindex 1593cbabe..0f54a88b1 100644--- a/apps/web/src/components/poll/mobile-poll/poll-option.tsx+++ b/apps/web/src/components/poll/mobile-poll/poll-option.tsx@@ -68,7 +68,7 @@ const PollOptionVoteSummary: React.FunctionComponent<{ optionId: string }> = ({<div key={i} className="flex"><div className="relative mr-2.5 flex size-4 items-center justify-center"><OptimizedAvatarImage- size="md"+ size="sm"name={name}email={email ?? undefined}src={image ?? undefined}@@ -76,7 +76,7 @@ const PollOptionVoteSummary: React.FunctionComponent<{ optionId: string }> = ({<VoteIcontype="yes"size="sm"- className="absolute bottom-full left-full -translate-x-1 translate-y-2 rounded-full bg-background"+ className="absolute bottom-0 left-full -translate-x-1 translate-y-1 rounded-full bg-background"/></div><div className="truncate text-sm">{name}</div>@@ -87,7 +87,7 @@ const PollOptionVoteSummary: React.FunctionComponent<{ optionId: string }> = ({<div key={i} className="flex"><div className="relative mr-2.5 flex size-4 items-center justify-center"><OptimizedAvatarImage- size="md"+ size="sm"name={name}email={email ?? undefined}src={image ?? undefined}@@ -95,7 +95,7 @@ const PollOptionVoteSummary: React.FunctionComponent<{ optionId: string }> = ({<VoteIcontype="ifNeedBe"size="sm"- className="absolute bottom-full left-full -translate-x-1 translate-y-2 rounded-full bg-background"+ className="absolute bottom-0 left-full -translate-x-1 translate-y-1 rounded-full bg-background"/></div><div className="truncate text-sm"> {name}</div>@@ -108,7 +108,7 @@ const PollOptionVoteSummary: React.FunctionComponent<{ optionId: string }> = ({<div key={i} className="flex"><div className="relative mr-2.5 flex size-4 items-center justify-center"><OptimizedAvatarImage- size="md"+ size="sm"name={name}email={email ?? undefined}src={image ?? undefined}@@ -116,7 +116,7 @@ const PollOptionVoteSummary: React.FunctionComponent<{ optionId: string }> = ({<VoteIcontype="no"size="sm"- className="absolute bottom-full left-full -translate-x-1 translate-y-2 rounded-full bg-background"+ className="absolute bottom-0 left-full -translate-x-1 translate-y-1 rounded-full bg-background"/></div><div className="truncate text-sm">{name}</div>diff --git a/apps/web/src/components/poll/you-avatar.tsx b/apps/web/src/components/poll/you-avatar.tsxindex 01e38a5aa..b082c063a 100644--- a/apps/web/src/components/poll/you-avatar.tsx+++ b/apps/web/src/components/poll/you-avatar.tsx@@ -2,7 +2,7 @@ import { UserIcon } from "lucide-react";export function YouAvatar() {return (- <div className="inline-flex size-5 items-center justify-center rounded-full bg-muted font-medium text-muted-foreground text-xs">+ <div className="inline-flex size-6 items-center justify-center rounded-full border bg-muted font-medium text-muted-foreground text-xs"><UserIcon className="size-4" /></div>);diff --git a/apps/web/src/components/user-dropdown.tsx b/apps/web/src/components/user-dropdown.tsxindex 84e7b70a6..6a282801a 100644--- a/apps/web/src/components/user-dropdown.tsx+++ b/apps/web/src/components/user-dropdown.tsx@@ -76,7 +76,7 @@ export const UserDropdown = ({ className }: { className?: string }) => {className={cn("group min-w-0", className)}><Button variant="ghost">- <OptimizedAvatarImage src={image} name={name} size="md" />+ <OptimizedAvatarImage src={image} name={name} size="sm" /><span className="truncate">{name}</span><ChevronDownIcon data-icon="inline-end" /></Button>diff --git a/apps/web/src/features/poll/components/polls-infinite-list.tsx b/apps/web/src/features/poll/components/polls-infinite-list.tsxindex 24470cbcb..01e763728 100644--- a/apps/web/src/features/poll/components/polls-infinite-list.tsx+++ b/apps/web/src/features/poll/components/polls-infinite-list.tsx@@ -118,7 +118,7 @@ function PollListItem({<Tooltip><TooltipTrigger><OptimizedAvatarImage- size="md"+ size="sm"name={user.name}src={user.image ?? undefined}/>diff --git a/apps/web/src/features/scheduled-event/components/scheduled-event-list.tsx b/apps/web/src/features/scheduled-event/components/scheduled-event-list.tsxindex 254d869be..5ca37a28e 100644--- a/apps/web/src/features/scheduled-event/components/scheduled-event-list.tsx+++ b/apps/web/src/features/scheduled-event/components/scheduled-event-list.tsx@@ -150,7 +150,7 @@ export function ScheduledEventListItem({<Tooltip><TooltipTrigger><OptimizedAvatarImage- size="md"+ size="sm"name={createdBy.name}src={createdBy.image}/>diff --git a/apps/web/src/features/space/components/space-icon.tsx b/apps/web/src/features/space/components/space-icon.tsxindex 9bc42281b..6c3345214 100644--- a/apps/web/src/features/space/components/space-icon.tsx+++ b/apps/web/src/features/space/components/space-icon.tsx@@ -1,31 +1,45 @@"use client";import { cn } from "@rallly/ui";-import type { AvatarProps } from "@rallly/ui/avatar";import { Avatar, AvatarFallback } from "@rallly/ui/avatar";import Image from "next/image";+import * as React from "react";type SpaceIconProps = {name: string;className?: string;src?: string;-} & AvatarProps;+ size?: "default" | "sm" | "lg" | "xl";+};++export function SpaceIcon({+ name,+ src,+ className,+ size = "default",+}: SpaceIconProps) {+ const [erroredSrc, setErroredSrc] = React.useState<string | null>(null);+ const hasError = src !== undefined && erroredSrc === src;-export function SpaceIcon({ name, src, className, size }: SpaceIconProps) {return (- <Avatar className={cn(className)} size={size}>- {src ? (+ <Avatar+ className={cn("overflow-hidden", className)}+ size={size}+ shape="square"+ >+ {src && !hasError ? (<Imagesrc={`/api/storage/${src}`}width={128}height={128}alt={name}style={{ objectFit: "cover" }}+ onError={() => {+ setErroredSrc(src);+ }}/>) : (- <AvatarFallback seed={name}>- {name.slice(0, 2).toUpperCase()}- </AvatarFallback>+ <AvatarFallback>{name.slice(0, 2).toUpperCase()}</AvatarFallback>)}</Avatar>);diff --git a/packages/ui/src/avatar.tsx b/packages/ui/src/avatar.tsxindex 0f20de8cf..26934d06c 100644--- a/packages/ui/src/avatar.tsx+++ b/packages/ui/src/avatar.tsx@@ -1,65 +1,137 @@-import * as AvatarPrimitive from "@radix-ui/react-avatar";-import { cn } from "@rallly/ui";+"use client";++import { Avatar as AvatarPrimitive } from "@base-ui/react/avatar";import type { VariantProps } from "class-variance-authority";import { cva } from "class-variance-authority";-import * as React from "react";+import type * as React from "react";++import { cn } from "./lib/utils";-const avatarVariants = cva("relative flex shrink-0 overflow-hidden", {- variants: {- size: {- xl: "size-12 rounded-xl text-lg",- lg: "size-8 rounded-md text-xs",- md: "size-5 rounded-md text-[9px]",- sm: "size-4 rounded text-[8px]",+const avatarVariants = cva(+ "group/avatar relative flex shrink-0 select-none after:absolute after:inset-0 after:rounded-[inherit] after:border after:border-border after:mix-blend-darken dark:after:mix-blend-lighten",+ {+ variants: {+ size: {+ sm: "size-6",+ default: "size-8",+ lg: "size-10",+ xl: "size-12",+ },+ shape: {+ circle: "rounded-full",+ square: "",+ },+ },+ compoundVariants: [+ { shape: "square", size: "sm", className: "rounded-md" },+ { shape: "square", size: "default", className: "rounded-md" },+ { shape: "square", size: "lg", className: "rounded-lg" },+ { shape: "square", size: "xl", className: "rounded-lg" },+ ],+ defaultVariants: {+ size: "default",+ shape: "circle",},},- defaultVariants: {- size: "md",- },-});+);++function Avatar({+ className,+ size = "default",+ shape = "circle",+ ...props+}: AvatarPrimitive.Root.Props & VariantProps<typeof avatarVariants>) {+ return (+ <AvatarPrimitive.Root+ data-slot="avatar"+ data-size={size}+ data-shape={shape}+ className={cn(avatarVariants({ size, shape }), className)}+ {...props}+ />+ );+}++function AvatarImage({ className, ...props }: AvatarPrimitive.Image.Props) {+ return (+ <AvatarPrimitive.Image+ data-slot="avatar-image"+ className={cn(+ "aspect-square size-full rounded-[inherit] object-cover",+ className,+ )}+ {...props}+ />+ );+}-export type AvatarProps = VariantProps<typeof avatarVariants>;+function AvatarFallback({+ className,+ ...props+}: AvatarPrimitive.Fallback.Props) {+ return (+ <AvatarPrimitive.Fallback+ data-slot="avatar-fallback"+ className={cn(+ "flex size-full items-center justify-center rounded-[inherit] bg-muted text-muted-foreground text-xs group-data-[size=sm]/avatar:text-[0.625rem]",+ className,+ )}+ {...props}+ />+ );+}-const Avatar = React.forwardRef<- React.ComponentRef<typeof AvatarPrimitive.Root>,- React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root> &- VariantProps<typeof avatarVariants>->(({ className, size = "md", ...props }, ref) => (- <AvatarPrimitive.Root- ref={ref}- className={cn(avatarVariants({ size }), className)}- {...props}- />-));-Avatar.displayName = AvatarPrimitive.Root.displayName;+function AvatarBadge({ className, ...props }: React.ComponentProps<"span">) {+ return (+ <span+ data-slot="avatar-badge"+ className={cn(+ "absolute right-0 bottom-0 z-10 inline-flex select-none items-center justify-center rounded-full bg-primary text-primary-foreground bg-blend-color ring-2 ring-background",+ "group-data-[size=sm]/avatar:size-2 group-data-[size=sm]/avatar:[&>svg]:hidden",+ "group-data-[size=default]/avatar:size-2.5 group-data-[size=default]/avatar:[&>svg]:size-2",+ "group-data-[size=lg]/avatar:size-3 group-data-[size=lg]/avatar:[&>svg]:size-2",+ "group-data-[size=xl]/avatar:size-3.5 group-data-[size=xl]/avatar:[&>svg]:size-2.5",+ className,+ )}+ {...props}+ />+ );+}-const AvatarImage = React.forwardRef<- React.ComponentRef<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;+function AvatarGroup({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="avatar-group"+ className={cn(+ "group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-background",+ className,+ )}+ {...props}+ />+ );+}-const AvatarFallback = React.forwardRef<- React.ComponentRef<typeof AvatarPrimitive.Fallback>,- React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback> & {- seed?: string;- }->(({ className, ...props }, ref) => (- <AvatarPrimitive.Fallback- ref={ref}- className={cn(- "flex h-full w-full items-center justify-center bg-foreground/10 font-medium text-muted-foreground dark:bg-foreground/10",- className,- )}- {...props}- />-));-AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName;+function AvatarGroupCount({+ className,+ ...props+}: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="avatar-group-count"+ className={cn(+ "relative flex size-8 shrink-0 items-center justify-center rounded-full bg-muted text-muted-foreground text-sm ring-2 ring-background group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 group-has-data-[size=xl]/avatar-group:size-12 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3 group-has-data-[size=xl]/avatar-group:[&>svg]:size-6",+ className,+ )}+ {...props}+ />+ );+}-export { Avatar, AvatarFallback, AvatarImage };+export {+ Avatar,+ AvatarImage,+ AvatarFallback,+ AvatarGroup,+ AvatarGroupCount,+ AvatarBadge,+};