Email for professionals and teams
make columns resizable
Hieu Nguyen (Jack)3896f2e50619
diff --git a/src/app/(admin)/layout.tsx b/src/app/(admin)/layout.tsxindex dbe70b3..d1e37d8 100644--- a/src/app/(admin)/layout.tsx+++ b/src/app/(admin)/layout.tsx@@ -10,6 +10,7 @@ import { MailboxSelector } from "@/components/mailbox-selector";import { LicenseIndicator } from "@/components/license-indicator";import { AdminNav } from "@/components/admin-nav";import { SidebarProvider } from "@/components/sidebar-state";+import { SidebarResizeBoundary } from "@/components/sidebar-resize-boundary";import { ShortcutsProvider } from "@/components/shortcuts";export default function DashboardLayout({@@ -24,8 +25,11 @@ export default function DashboardLayout({<ComposeProvider><ShortcutsProvider><div className="grid h-dvh grid-cols-[var(--sidebar-width)_minmax(0,1fr)] overflow-hidden bg-[#f6f8fc] transition-[grid-template-columns] duration-200">- <aside className="min-h-0 overflow-y-auto overscroll-contain px-3 py-4 scrollbar-gutter-stable">- <AdminNav />+ <aside className="relative min-h-0 min-w-0">+ <div className="h-full overflow-y-auto overscroll-contain px-3 py-4 scrollbar-gutter-stable">+ <AdminNav />+ </div>+ <SidebarResizeBoundary /></aside><div className="flex min-h-0 min-w-0 flex-col"><span className="fixed top-2 right-4 flex items-center gap-4">diff --git a/src/app/(dashboard)/inbox/[messageId]/page.tsx b/src/app/(dashboard)/inbox/[messageId]/page.tsxindex 7d21205..2394868 100644--- a/src/app/(dashboard)/inbox/[messageId]/page.tsx+++ b/src/app/(dashboard)/inbox/[messageId]/page.tsx@@ -200,10 +200,11 @@ export default function MessageDetailPage() {managedAvatarUrl={message.direction === "outbound" && message.mailboxId? `/api/mailboxes/${message.mailboxId}/avatar`: undefined}+ className="mt-2"/>- <div>- <p className="text-sm text-neutral-900 mt-1.25">- <b>+ <div className="flex-1 min-w-0">+ <p className="text-sm text-neutral-900 mt-1.25 flex flex-row items-center gap-1 w-full overflow-hidden">+ <b className="whitespace-nowrap">{message.direction === "inbound" ? (<ContactDetailsTriggermailboxId={message.mailboxId}@@ -214,7 +215,7 @@ export default function MessageDetailPage() {fromName)}</b>{" "}- <span className="text-neutral-500"><{fromAddress}></span>+ <span className="text-neutral-500 text-xs flex-1 overflow-hidden text-ellipsis min-w-0"><{fromAddress}></span></p><p className="text-xs text-neutral-500">to{" "}diff --git a/src/app/(dashboard)/layout.tsx b/src/app/(dashboard)/layout.tsxindex d1ea398..8f75b93 100644--- a/src/app/(dashboard)/layout.tsx+++ b/src/app/(dashboard)/layout.tsx@@ -12,6 +12,7 @@ import { MailboxSelector } from "@/components/mailbox-selector";import { LicenseIndicator } from "@/components/license-indicator";import { DashboardNav } from "@/components/dashboard-nav";import { SidebarProvider } from "@/components/sidebar-state";+import { SidebarResizeBoundary } from "@/components/sidebar-resize-boundary";import { ShortcutsProvider } from "@/components/shortcuts";export default function DashboardLayout({@@ -27,8 +28,11 @@ export default function DashboardLayout({<MailSearchProvider><ShortcutsProvider><div className="grid h-dvh grid-cols-[var(--sidebar-width)_minmax(0,1fr)] overflow-hidden bg-[#f6f8fc] transition-[grid-template-columns] duration-200">- <aside className="min-h-0 overflow-y-auto overscroll-contain px-3 py-4 scrollbar-gutter-stable">- <DashboardNav />+ <aside className="relative min-h-0 min-w-0">+ <div className="h-full overflow-y-auto overscroll-contain px-3 py-4 scrollbar-gutter-stable">+ <DashboardNav />+ </div>+ <SidebarResizeBoundary /></aside><div className="flex min-h-0 min-w-0 flex-col"><header className="flex h-16 w-full shrink-0 items-center gap-3 pr-4 text-sm">diff --git a/src/components/column-width-preferences-types.d.ts b/src/components/column-width-preferences-types.d.tsnew file mode 100644index 0000000..043bbd2--- /dev/null+++ b/src/components/column-width-preferences-types.d.ts@@ -0,0 +1 @@+export type ColumnWidthPreference = "sidebar" | "message-list";diff --git a/src/components/column-width-preferences.ts b/src/components/column-width-preferences.tsnew file mode 100644index 0000000..03d7463--- /dev/null+++ b/src/components/column-width-preferences.ts@@ -0,0 +1,25 @@+import type { ColumnWidthPreference } from "./column-width-preferences-types";++function storageKey(userId: string, column: ColumnWidthPreference) {+ return `mailflare-column-width:${column}:${userId}`;+}++export function readColumnWidth(userId: string, column: ColumnWidthPreference, fallback: number, min: number, max: number) {+ try {+ const stored = localStorage.getItem(storageKey(userId, column));+ if (stored === null) return fallback;+ const width = Number(stored);+ return Number.isFinite(width) ? Math.max(min, Math.min(max, width)) : fallback;+ } catch {+ return fallback;+ }+}++export function saveColumnWidth(userId: string | null, column: ColumnWidthPreference, width: number) {+ if (!userId) return;+ try {+ localStorage.setItem(storageKey(userId, column), String(width));+ } catch {+ // Storage can be unavailable; resizing still works for this session.+ }+}diff --git a/src/components/components-nav.tsx b/src/components/components-nav.tsxindex f1a9227..950ef79 100644--- a/src/components/components-nav.tsx+++ b/src/components/components-nav.tsx@@ -8,6 +8,7 @@ import { getMessageDragData } from "@/lib/messages/drag-utils";import { useSelectedMailbox } from "./mailbox-provider";import { useSidebar } from "./sidebar-state";import { useCompose } from "./compose/compose-context";+import { Tooltip } from "./ui/tooltip";import {preloadMailboxPage,waitForNavigationProgress,@@ -67,12 +68,12 @@ export function NavItem({ link }: { link: NavLink }) {: {};if (link.href === "/compose") {- return (+ const composeButton = (<buttontype="button"onClick={openComposer}className={classes}- title={minimal ? link.label : undefined}+ aria-label={minimal ? link.label : undefined}{...dropProps}><Icon@@ -92,6 +93,7 @@ export function NavItem({ link }: { link: NavLink }) {)}</button>);+ return minimal && link.label ? <Tooltip label={link.label} placement="right" className="mx-auto">{composeButton}</Tooltip> : composeButton;}async function navigate(event: MouseEvent<HTMLAnchorElement>) {@@ -127,20 +129,11 @@ export function NavItem({ link }: { link: NavLink }) {}}- return (- <>- {navigationProgress !== null && (- <div className="fixed inset-x-0 top-0 z-[120] h-1 bg-blue-100">- <div- className="h-full bg-blue-600 transition-[width] duration-100 ease-out"- style={{ width: `${navigationProgress}%` }}- />- </div>- )}+ const navLink = (<Linkhref={link.href}onClick={navigate}- title={minimal ? link.label : undefined}+ aria-label={minimal ? link.label : undefined}className={cn(!minimal && "-ml-3 pl-6", classes)}{...dropProps}>@@ -161,6 +154,19 @@ export function NavItem({ link }: { link: NavLink }) {</span>)}</Link>+ );++ return (+ <>+ {navigationProgress !== null && (+ <div className="fixed inset-x-0 top-0 z-[120] h-1 bg-blue-100">+ <div+ className="h-full bg-blue-600 transition-[width] duration-100 ease-out"+ style={{ width: `${navigationProgress}%` }}+ />+ </div>+ )}+ {minimal && link.label ? <Tooltip label={link.label} placement="right" className="mx-auto">{navLink}</Tooltip> : navLink}</>);}diff --git a/src/components/compose/rich-text-editor-types.d.ts b/src/components/compose/rich-text-editor-types.d.tsindex 227300a..7cbdb44 100644--- a/src/components/compose/rich-text-editor-types.d.ts+++ b/src/components/compose/rich-text-editor-types.d.ts@@ -10,6 +10,7 @@ export type RichTextEditorProps = {className?: string;toolbarStart?: React.ReactNode;toolbarEnd?: React.ReactNode;+ footerContent?: React.ReactNode;};export type ToolbarCommand = {diff --git a/src/components/compose/rich-text-editor.tsx b/src/components/compose/rich-text-editor.tsxindex 534257c..0603fda 100644--- a/src/components/compose/rich-text-editor.tsx+++ b/src/components/compose/rich-text-editor.tsx@@ -42,6 +42,7 @@ export function RichTextEditor({className,toolbarStart,toolbarEnd,+ footerContent,}: RichTextEditorProps) {const editorRef = useRef<HTMLDivElement | null>(null);const [active, setActive] = useState<Record<string, boolean>>({});@@ -169,6 +170,7 @@ export function RichTextEditor({</div>)}</div>+ {footerContent}<div className="relative flex items-center gap-0.5 border-t border-neutral-100 px-4 py-3">{toolbarStart}{COMMANDS.map((item) => (diff --git a/src/components/contacts/contact-avatar.tsx b/src/components/contacts/contact-avatar.tsxindex eec8d6f..36e2ba0 100644--- a/src/components/contacts/contact-avatar.tsx+++ b/src/components/contacts/contact-avatar.tsx@@ -63,7 +63,7 @@ export function ContactAvatar({<ProgressiveAvatarImagesrc={avatarUrl}alt=""- className={cn("h-8 w-8 shrink-0 rounded-full border border-neutral-200 object-cover", className)}+ className={cn("h-9 w-9 shrink-0 rounded-full object-cover", className)}onError={() => {if (managedAvatarUrl) setImageFailed(true);else if (managedAvatar) setManagedAvatar(false);@@ -75,7 +75,7 @@ export function ContactAvatar({return (<span- className={cn("flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-neutral-200 text-sm font-semibold text-neutral-700", className)}+ className={cn("flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-neutral-200 text-sm font-semibold text-neutral-700", className)}style={getAvatarColorStyle(normalizeEmailAddress(address) || name)}aria-hidden>diff --git a/src/components/messages/conversation-thread.tsx b/src/components/messages/conversation-thread.tsxindex c8d8a1e..15aa007 100644--- a/src/components/messages/conversation-thread.tsx+++ b/src/components/messages/conversation-thread.tsx@@ -155,6 +155,7 @@ export function ConversationMessageCard({name={sender}hasManagedAvatar={message.fromContactHasAvatar}managedAvatarUrl={outbound && mailboxId ? `/api/mailboxes/${mailboxId}/avatar` : undefined}+ className={expanded ? "mt-1" : ""}/><span className="min-w-0 flex-1"><div className="flex flex-col">diff --git a/src/components/messages/message-folder-page.tsx b/src/components/messages/message-folder-page.tsxindex f323cf0..69d4b9c 100644--- a/src/components/messages/message-folder-page.tsx+++ b/src/components/messages/message-folder-page.tsx@@ -129,7 +129,7 @@ function MessageListRow({}const className =- `group relative grid min-h-12 w-full grid-cols-[24px_32px_minmax(160px,240px)_1fr_auto] items-center gap-3 px-6 text-left text-sm hover:z-10 hover:bg-[#f2f6fc] hover:shadow-sm ${active || selected ? "bg-blue-50" : ""+ `group relative grid min-h-12 w-full grid-cols-[24px_32px_minmax(160px,260px)_1fr_auto] items-center gap-3 px-6 text-left text-sm hover:z-10 hover:bg-[#f2f6fc] hover:shadow-sm ${active || selected ? "bg-blue-50" : ""} ${draggable ? "cursor-grab active:cursor-grabbing" : ""}`;const content = (<>diff --git a/src/components/messages/message-split-layout.tsx b/src/components/messages/message-split-layout.tsxindex f505892..2bac283 100644--- a/src/components/messages/message-split-layout.tsx+++ b/src/components/messages/message-split-layout.tsx@@ -1,7 +1,10 @@"use client";import { usePathname } from "next/navigation";-import { useState } from "react";+import { useEffect, useRef, useState } from "react";+import { useSidebar } from "@/components/sidebar-state";+import { readColumnWidth, saveColumnWidth } from "@/components/column-width-preferences";+import { ResizeHandle } from "@/components/ui/resize-handle";import { BulkMessageSelectionPane } from "./bulk-message-selection-pane";import { MessageFolderPage } from "./message-folder-page";import type { MessageSplitLayoutProps, SelectedMessage } from "./types";@@ -12,22 +15,59 @@ export function MessageSplitLayout({}: MessageSplitLayoutProps) {const pathname = usePathname();const [selectedMessages, setSelectedMessages] = useState<SelectedMessage[]>([]);+ const [listWidth, setListWidth] = useState(360);+ const [containerWidth, setContainerWidth] = useState(0);+ const containerRef = useRef<HTMLDivElement>(null);+ const startWidth = useRef(listWidth);+ const resizedWidth = useRef(listWidth);+ const { userId, setForcedMinimal } = useSidebar();const detailPrefix = `${config.hrefPrefix}/`;const selectedMessageId = pathname.startsWith(detailPrefix)? pathname.slice(detailPrefix.length).split("/")[0]: undefined;+ useEffect(() => {+ if (userId) setListWidth(readColumnWidth(userId, "message-list", 360, 250, 1200));+ }, [userId]);++ useEffect(() => {+ if (!selectedMessageId) {+ setForcedMinimal(false);+ return;+ }+ const container = containerRef.current;+ if (!container) return;+ const observer = new ResizeObserver(() => setContainerWidth(container.clientWidth));+ observer.observe(container);+ return () => observer.disconnect();+ }, [selectedMessageId, setForcedMinimal]);++ useEffect(() => () => setForcedMinimal(false), [setForcedMinimal]);+if (!selectedMessageId) return children;return (- <div className="h-full min-h-0 overflow-hidden lg:grid lg:grid-cols-[minmax(300px,360px)_minmax(0,1fr)]">- <aside className="hidden min-h-0 overflow-hidden border-r border-neutral-200 bg-white lg:block">+ <div ref={containerRef} className="h-full min-h-0 overflow-hidden lg:grid" style={{ gridTemplateColumns: `${Math.max(250, Math.min(listWidth, (containerWidth || 1000) - 280))}px minmax(0,1fr)` }}>+ <aside className="relative hidden min-h-0 border-r border-neutral-200 bg-white lg:block">+ <div className="h-full min-h-0 overflow-hidden"><MessageFolderPageconfig={config}compactselectedMessageId={selectedMessageId}selection={{ selectedMessages, setSelectedMessages }}/>+ </div>+ <ResizeHandle+ label="Resize message list"+ onResizeStart={() => { startWidth.current = listWidth; resizedWidth.current = listWidth; }}+ onResize={(delta) => {+ const requestedWidth = startWidth.current + delta;+ setForcedMinimal(requestedWidth < 250);+ resizedWidth.current = Math.max(250, Math.min(requestedWidth, Math.max(250, (containerRef.current?.clientWidth ?? 1000) - 280)));+ setListWidth(resizedWidth.current);+ }}+ onResizeEnd={() => saveColumnWidth(userId, "message-list", resizedWidth.current)}+ /></aside><section className="min-h-0 min-w-0 overflow-hidden bg-white">{selectedMessages.length > 0 ? (diff --git a/src/components/sidebar-header.tsx b/src/components/sidebar-header.tsxindex fcb8e74..b5da2ca 100644--- a/src/components/sidebar-header.tsx+++ b/src/components/sidebar-header.tsx@@ -5,15 +5,17 @@ import { Menu } from "lucide-react";import { useBranding } from "./branding-provider";import { useSidebar } from "./sidebar-state";import type { SidebarHeaderProps } from "./sidebar-state-types";+import { Tooltip } from "./ui/tooltip";export function SidebarHeader({ href, label }: SidebarHeaderProps) {const branding = useBranding();const { minimal, toggle } = useSidebar();+ const toggleButton = <button type="button" onClick={toggle} className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full text-neutral-600 hover:bg-neutral-200" aria-label={minimal ? "Expand menu" : "Collapse menu"}>+ {minimal ? <img src={branding.iconUrl} height={28} width={28} alt="" /> : <Menu className="h-5 w-5" />}+ </button>;return (<div className={`mb-3 flex h-10 items-center ${minimal ? "justify-center" : "gap-2 px-1"}`}>- <button type="button" onClick={toggle} className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full text-neutral-600 hover:bg-neutral-200" aria-label={minimal ? "Expand menu" : "Collapse menu"}>- {minimal ? <img src={branding.iconUrl} height={28} width={28} alt="" /> : <Menu className="h-5 w-5" />}- </button>+ {minimal ? <Tooltip label="Expand menu" placement="right">{toggleButton}</Tooltip> : toggleButton}{!minimal && <Link href={href} className="flex min-w-0 items-center gap-3"><img src={branding.iconUrl} height={28} width={28} alt="" /><span className="truncate text-lg font-semibold text-neutral-800">{label ?? branding.appName}</span></Link>}</div>);diff --git a/src/components/sidebar-resize-boundary.tsx b/src/components/sidebar-resize-boundary.tsxnew file mode 100644index 0000000..c8d90db--- /dev/null+++ b/src/components/sidebar-resize-boundary.tsx@@ -0,0 +1,25 @@+"use client";++import { useRef } from "react";+import { ResizeHandle } from "./ui/resize-handle";+import { useSidebar } from "./sidebar-state";+import { saveColumnWidth } from "./column-width-preferences";++export function SidebarResizeBoundary() {+ const { minimal, width, userId, setWidth } = useSidebar();+ const startWidth = useRef(width);+ const resizedWidth = useRef(width);++ return (+ <ResizeHandle+ label="Resize left menu"+ onResizeStart={() => { startWidth.current = width; resizedWidth.current = width; }}+ onResize={(delta) => {+ if (minimal) return;+ resizedWidth.current = Math.max(200, Math.min(480, window.innerWidth - 570, startWidth.current + delta));+ setWidth(resizedWidth.current);+ }}+ onResizeEnd={() => saveColumnWidth(userId, "sidebar", resizedWidth.current)}+ />+ );+}diff --git a/src/components/sidebar-state-types.d.ts b/src/components/sidebar-state-types.d.tsindex 7ccee1d..10e435c 100644--- a/src/components/sidebar-state-types.d.ts+++ b/src/components/sidebar-state-types.d.ts@@ -2,7 +2,11 @@ import type { ReactNode } from "react";export type SidebarState = {minimal: boolean;+ width: number;+ userId: string | null;toggle(): void;+ setWidth(width: number): void;+ setForcedMinimal(minimal: boolean): void;};export type SidebarProviderProps = {diff --git a/src/components/sidebar-state.tsx b/src/components/sidebar-state.tsxindex 1f7d6d4..062a6b8 100644--- a/src/components/sidebar-state.tsx+++ b/src/components/sidebar-state.tsx@@ -1,12 +1,16 @@"use client";import { createContext, useContext, useEffect, useState } from "react";+import { readColumnWidth } from "./column-width-preferences";import type { SidebarProviderProps, SidebarState } from "./sidebar-state-types";-const SidebarContext = createContext<SidebarState>({ minimal: false, toggle: () => undefined });+const SidebarContext = createContext<SidebarState>({ minimal: false, width: 260, userId: null, toggle: () => undefined, setWidth: () => undefined, setForcedMinimal: () => undefined });-export function SidebarProvider({ children, expandedWidth = 240 }: SidebarProviderProps) {+export function SidebarProvider({ children, expandedWidth = 260 }: SidebarProviderProps) {const [minimal, setMinimal] = useState(false);+ const [forcedMinimal, setForcedMinimal] = useState(false);+ const [width, setWidth] = useState(expandedWidth);+ const [userId, setUserId] = useState<string | null>(null);const [storageKey, setStorageKey] = useState<string | null>(null);useEffect(() => {@@ -20,11 +24,13 @@ export function SidebarProvider({ children, expandedWidth = 240 }: SidebarProvid}).then((data) => {const userId = data?.user?.id;- if (!userId) return;- const key = `mailflare-sidebar-minimal:${userId}`;+ if (!userId) return;+ setUserId(userId);+ const key = `mailflare-sidebar-minimal:${userId}`;setStorageKey(key);try {- setMinimal(localStorage.getItem(key) === "true");+ setMinimal(localStorage.getItem(key) === "true");+ setWidth(readColumnWidth(userId, "sidebar", expandedWidth, 200, 480));} catch {// Storage can be unavailable in private windows; keep the default.}@@ -33,6 +39,12 @@ export function SidebarProvider({ children, expandedWidth = 240 }: SidebarProvid}, []);function toggle() {+ if (forcedMinimal) {+ setForcedMinimal(false);+ setMinimal(false);+ if (storageKey) localStorage.setItem(storageKey, "false");+ return;+ }setMinimal((current) => {const next = !current;if (storageKey) localStorage.setItem(storageKey, String(next));@@ -41,8 +53,8 @@ export function SidebarProvider({ children, expandedWidth = 240 }: SidebarProvid}return (- <SidebarContext.Provider value={{ minimal, toggle }}>- <div className="h-full" style={{ "--sidebar-width": `${minimal ? 72 : expandedWidth}px` } as React.CSSProperties}>+ <SidebarContext.Provider value={{ minimal: minimal || forcedMinimal, width, userId, toggle, setWidth, setForcedMinimal }}>+ <div className="h-full" style={{ "--sidebar-width": `${minimal || forcedMinimal ? 72 : width}px` } as React.CSSProperties}>{children}</div></SidebarContext.Provider>diff --git a/src/components/ui/resize-handle-types.d.ts b/src/components/ui/resize-handle-types.d.tsnew file mode 100644index 0000000..f48ecdd--- /dev/null+++ b/src/components/ui/resize-handle-types.d.ts@@ -0,0 +1,6 @@+export type ResizeHandleProps = {+ label: string;+ onResizeStart?: () => void;+ onResize: (delta: number) => void;+ onResizeEnd?: () => void;+};diff --git a/src/components/ui/resize-handle.tsx b/src/components/ui/resize-handle.tsxnew file mode 100644index 0000000..3d770d9--- /dev/null+++ b/src/components/ui/resize-handle.tsx@@ -0,0 +1,41 @@+"use client";++import { useRef } from "react";+import type { PointerEvent } from "react";+import type { ResizeHandleProps } from "./resize-handle-types";++export function ResizeHandle({ label, onResizeStart, onResize, onResizeEnd }: ResizeHandleProps) {+ const startX = useRef<number | null>(null);++ function handlePointerDown(event: PointerEvent<HTMLDivElement>) {+ if (event.button !== 0) return;+ startX.current = event.clientX;+ event.currentTarget.setPointerCapture(event.pointerId);+ onResizeStart?.();+ event.preventDefault();+ }++ function handlePointerMove(event: PointerEvent<HTMLDivElement>) {+ if (startX.current === null) return;+ onResize(event.clientX - startX.current);+ }++ function handlePointerEnd() {+ if (startX.current === null) return;+ startX.current = null;+ onResizeEnd?.();+ }++ return (+ <div+ role="separator"+ aria-label={label}+ aria-orientation="vertical"+ className="absolute inset-y-0 right-0 z-20 w-2 translate-x-1/2 cursor-col-resize touch-none"+ onPointerDown={handlePointerDown}+ onPointerMove={handlePointerMove}+ onPointerUp={handlePointerEnd}+ onPointerCancel={handlePointerEnd}+ />+ );+}diff --git a/src/components/ui/tooltip-types.d.ts b/src/components/ui/tooltip-types.d.tsindex 9b9689b..e660b2f 100644--- a/src/components/ui/tooltip-types.d.ts+++ b/src/components/ui/tooltip-types.d.ts@@ -4,6 +4,7 @@ export type TooltipProps = {label: string;children: ReactNode;className?: string;+ placement?: "auto" | "right";};export type TooltipPosition = {diff --git a/src/components/ui/tooltip-utils.ts b/src/components/ui/tooltip-utils.tsindex 7ab0fb0..1bcbe5a 100644--- a/src/components/ui/tooltip-utils.ts+++ b/src/components/ui/tooltip-utils.ts@@ -1,4 +1,4 @@-import type { TooltipPosition } from "./tooltip-types";+import type { TooltipPosition, TooltipProps } from "./tooltip-types";const TOOLTIP_GAP = 8;const VIEWPORT_PADDING = 8;@@ -6,9 +6,19 @@ const VIEWPORT_PADDING = 8;export function getTooltipPosition(trigger: HTMLElement,tooltip: HTMLElement,+ placement: TooltipProps["placement"] = "auto",): TooltipPosition {const triggerRect = trigger.getBoundingClientRect();const tooltipRect = tooltip.getBoundingClientRect();+ if (placement === "right") {+ return {+ left: Math.min(triggerRect.right + TOOLTIP_GAP, window.innerWidth - tooltipRect.width - VIEWPORT_PADDING),+ top: Math.min(+ Math.max(triggerRect.top + triggerRect.height / 2 - tooltipRect.height / 2, VIEWPORT_PADDING),+ window.innerHeight - tooltipRect.height - VIEWPORT_PADDING,+ ),+ };+ }const centeredLeft = triggerRect.left + triggerRect.width / 2 - tooltipRect.width / 2;const left = Math.min(Math.max(centeredLeft, VIEWPORT_PADDING),diff --git a/src/components/ui/tooltip.tsx b/src/components/ui/tooltip.tsxindex a8010f8..094c4de 100644--- a/src/components/ui/tooltip.tsx+++ b/src/components/ui/tooltip.tsx@@ -6,7 +6,7 @@ import { createPortal } from "react-dom";import type { TooltipPosition, TooltipProps } from "./tooltip-types";import { getTooltipPosition } from "./tooltip-utils";-export function Tooltip({ label, children, className }: TooltipProps) {+export function Tooltip({ label, children, className, placement = "auto" }: TooltipProps) {const [open, setOpen] = useState(false);const [position, setPosition] = useState<TooltipPosition | null>(null);const triggerRef = useRef<HTMLSpanElement>(null);@@ -17,7 +17,7 @@ export function Tooltip({ label, children, className }: TooltipProps) {function updatePosition() {if (!triggerRef.current || !tooltipRef.current) return;- setPosition(getTooltipPosition(triggerRef.current, tooltipRef.current));+ setPosition(getTooltipPosition(triggerRef.current, tooltipRef.current, placement));}updatePosition();@@ -28,7 +28,7 @@ export function Tooltip({ label, children, className }: TooltipProps) {window.removeEventListener("resize", updatePosition);window.removeEventListener("scroll", updatePosition, true);};- }, [label, open]);+ }, [label, open, placement]);return (<span