Sidebar or dropdown component for switching between AI chat conversations. Persistent thread state, search, and active selection — built for assistant-ui apps.
This demo uses ThreadListSidebar, which includes thread-list as a dependency and provides a complete sidebar layout. For custom implementations, you can use thread-list directly.
Getting Started
Add the component
Use threadlist-sidebar for a complete sidebar layout or thread-list for custom layouts.
ThreadListSidebar
npx shadcn@latest add @assistant-ui/threadlist-sidebarThe @assistant-uinamespace resolves the Radix or Base UI flavor from your project's style through the style-aware registry entry in components.json. Without that entry, add by direct URL instead:
npx shadcn@latest add https://r.assistant-ui.com/base/threadlist-sidebar.jsonMain Component
import type * as React from "react";import { MessagesSquare } from "lucide-react";import { GitHubIcon } from "@/components/icons/github";import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarRail,} from "@/components/ui/sidebar";import { ThreadList } from "@/components/assistant-ui/thread-list";export function ThreadListSidebar({ ...props}: React.ComponentProps<typeof Sidebar>) { return ( <Sidebar {...props}> <SidebarHeader className="aui-sidebar-header mb-2 border-b"> <div className="aui-sidebar-header-content flex items-center justify-between"> <SidebarMenu> <SidebarMenuItem> <SidebarMenuButton size="lg" render={ <a href="https://assistant-ui.com" target="_blank" rel="noopener noreferrer" /> } > <div className="aui-sidebar-header-icon-wrapper bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg"> <MessagesSquare className="aui-sidebar-header-icon size-4" /> </div> <div className="aui-sidebar-header-heading me-6 flex flex-col gap-0.5 leading-none"> <span className="aui-sidebar-header-title font-semibold"> assistant-ui </span> </div> </SidebarMenuButton> </SidebarMenuItem> </SidebarMenu> </div> </SidebarHeader> <SidebarContent className="aui-sidebar-content px-2"> <ThreadList /> </SidebarContent> <SidebarRail /> <SidebarFooter className="aui-sidebar-footer border-t"> <SidebarMenu> <SidebarMenuItem> <SidebarMenuButton size="lg" render={ <a href="https://github.com/assistant-ui/assistant-ui" target="_blank" rel="noopener noreferrer" /> } > <div className="aui-sidebar-footer-icon-wrapper bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg"> <GitHubIcon className="aui-sidebar-footer-icon size-4" /> </div> <div className="aui-sidebar-footer-heading flex flex-col gap-0.5 leading-none"> <span className="aui-sidebar-footer-title font-semibold"> GitHub </span> <span>View Source</span> </div> </SidebarMenuButton> </SidebarMenuItem> </SidebarMenu> </SidebarFooter> </Sidebar> );}export function GitHubIcon({ className }: { className?: string }) { return ( <svg aria-hidden="true" viewBox="0 0 24 24" className={className} fill="currentColor" > <path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" /> </svg> );}assistant-ui dependencies
npm install @assistant-ui/react"use client";import { Button } from "@/components/ui/button";import { Input } from "@/components/ui/input";import { Skeleton } from "@/components/ui/skeleton";import { cn } from "@/lib/utils";import { AuiIf, ThreadListItemMorePrimitive, ThreadListItemPrimitive, ThreadListPrimitive, useAuiState,} from "@assistant-ui/react";import { ArchiveIcon, MoreHorizontalIcon, PlusIcon, SearchIcon, TrashIcon,} from "lucide-react";import { forwardRef, Fragment, useMemo, useState, type ComponentPropsWithoutRef, type FC,} from "react";export const ThreadList: FC = () => { const [search, setSearch] = useState(""); const hasThreads = useAuiState((s) => s.threads.threadIds.length > 0); return ( <ThreadListRoot> <ThreadListNew /> {hasThreads && ( <ThreadListSearch value={search} onValueChange={setSearch} /> )} <ThreadListItems searchQuery={hasThreads ? search : ""} /> </ThreadListRoot> );};export const ThreadListSearch = forwardRef< HTMLInputElement, Omit<ComponentPropsWithoutRef<typeof Input>, "value" | "onChange"> & { value: string; onValueChange: (value: string) => void; }>(({ className, value, onValueChange, ...props }, ref) => { return ( <div data-slot="aui_thread-list-search" className="relative px-0.5 py-1"> <SearchIcon data-slot="aui_thread-list-search-icon" className="text-muted-foreground pointer-events-none absolute start-3 top-1/2 size-4 -translate-y-1/2" /> <Input ref={ref} type="search" value={value} onChange={(event) => onValueChange(event.target.value)} aria-label="Search threads" placeholder="Search threads" className={cn("h-8 ps-8 text-sm", className)} {...props} /> </div> );});ThreadListSearch.displayName = "ThreadListSearch";export const ThreadListRoot: FC< ComponentPropsWithoutRef<typeof ThreadListPrimitive.Root>> = ({ className, ...props }) => { return ( <ThreadListPrimitive.Root data-slot="aui_thread-list-root" className={cn("flex flex-col gap-0.5", className)} {...props} /> );};export const ThreadListItems: FC< ComponentPropsWithoutRef<"div"> & { searchQuery?: string }> = ({ className, searchQuery = "", ...props }) => { return ( <div data-slot="aui_thread-list-items" className={cn("flex flex-col gap-0.5", className)} {...props} > <AuiIf condition={(s) => s.threads.isLoading}> <ThreadListSkeleton /> </AuiIf> <AuiIf condition={(s) => !s.threads.isLoading}> <ThreadListItemGroups searchQuery={searchQuery} /> </AuiIf> </div> );};const DAY_IN_MS = 86_400_000;const dateGroupLabel = ( date: Date | undefined, startOfToday: number,): string => { if (!date || date.getTime() >= startOfToday) return "Today"; if (date.getTime() >= startOfToday - DAY_IN_MS) return "Yesterday"; return "Earlier";};type ThreadListGroup = { label: string; indices: number[] };const ThreadListItemGroups: FC<{ searchQuery?: string }> = ({ searchQuery = "",}) => { const threadIds = useAuiState((s) => s.threads.threadIds); const threadItems = useAuiState((s) => s.threads.threadItems); const query = searchQuery.trim().toLowerCase(); const { filteredIndices, groups } = useMemo(() => { const itemsById = new Map(threadItems.map((item) => [item.id, item])); const dates = threadIds.map((id) => itemsById.get(id)?.lastMessageAt); const filteredIndices = threadIds .map((id, index) => ({ id, index })) .filter( ({ id }) => !query || (itemsById.get(id)?.title || "New Chat") .toLowerCase() .includes(query), ) .map(({ index }) => index); if (!filteredIndices.some((index) => dates[index])) { return { filteredIndices, groups: null }; } const now = new Date(); const startOfToday = new Date( now.getFullYear(), now.getMonth(), now.getDate(), ).getTime(); const time = (index: number) => dates[index]?.getTime() ?? Number.MAX_SAFE_INTEGER; const sorted = [...filteredIndices].sort((a, b) => time(b) - time(a)); const result: ThreadListGroup[] = []; for (const index of sorted) { const label = dateGroupLabel(dates[index], startOfToday); const lastGroup = result[result.length - 1]; if (lastGroup?.label === label) { lastGroup.indices.push(index); } else { result.push({ label, indices: [index] }); } } return { filteredIndices, groups: result }; }, [threadIds, threadItems, query]); if (query && filteredIndices.length === 0) { return ( <div data-slot="aui_thread-list-empty" className="text-muted-foreground px-2.5 py-4 text-sm" > No threads found </div> ); } if (!groups) { return filteredIndices.map((index) => ( <ThreadListPrimitive.ItemByIndex key={threadIds[index]} index={index} components={{ ThreadListItem }} /> )); } return groups.map((group) => ( <Fragment key={group.label}> <div data-slot="aui_thread-list-group-label" className="text-muted-foreground px-2.5 pt-3 pb-1 text-xs font-medium" > {group.label} </div> {group.indices.map((index) => ( <ThreadListPrimitive.ItemByIndex key={threadIds[index]} index={index} components={{ ThreadListItem }} /> ))} </Fragment> ));};export const ThreadListNew = forwardRef< HTMLButtonElement, ComponentPropsWithoutRef<typeof Button> & { labelClassName?: string }>(({ className, labelClassName, children, ...props }, ref) => { return ( <ThreadListPrimitive.New asChild> <Button ref={ref} variant="ghost" data-slot="aui_thread-list-new" className={cn( "hover:bg-muted data-active:bg-muted h-8 justify-start gap-2 rounded-md px-2.5 text-sm font-normal", className, )} {...props} > {children ?? ( <> <PlusIcon data-slot="aui_thread-list-new-icon" className="size-4 shrink-0" /> <span data-slot="aui_thread-list-new-label" className={cn("whitespace-nowrap", labelClassName)} > New Thread </span> </> )} </Button> </ThreadListPrimitive.New> );});ThreadListNew.displayName = "ThreadListNew";const ThreadListSkeleton: FC = () => { return ( <div className="flex flex-col gap-0.5"> {Array.from({ length: 5 }, (_, i) => ( <div key={i} role="status" aria-label="Loading threads" data-slot="aui_thread-list-skeleton-wrapper" className="flex h-8 items-center px-2.5" > <Skeleton data-slot="aui_thread-list-skeleton" className="h-3.5 w-full" /> </div> ))} </div> );};export const ThreadListItem: FC = () => { return ( <ThreadListItemPrimitive.Root data-slot="aui_thread-list-item" className="group hover:bg-muted focus-visible:bg-muted data-active:bg-muted has-focus-visible:bg-muted has-data-[state=open]:bg-muted relative flex h-8 items-center rounded-md transition-colors focus-visible:outline-none" > <ThreadListItemPrimitive.Trigger data-slot="aui_thread-list-item-trigger" className="focus-visible:ring-ring/50 flex h-full min-w-0 flex-1 items-center rounded-md px-2.5 text-start text-sm outline-none group-hover:pe-9 group-has-focus-visible:pe-9 group-has-data-[state=open]:pe-9 group-data-active:pe-9 focus-visible:ring-[3px]" > <span data-slot="aui_thread-list-item-title" className="min-w-0 flex-1 truncate" > <ThreadListItemPrimitive.Title fallback="New Chat" /> </span> </ThreadListItemPrimitive.Trigger> <ThreadListItemMore /> </ThreadListItemPrimitive.Root> );};const ThreadListItemMore: FC = () => { return ( <ThreadListItemMorePrimitive.Root sharedFocusGroup> <ThreadListItemMorePrimitive.Trigger asChild> <Button variant="ghost" size="icon" data-slot="aui_thread-list-item-more" className="data-[state=open]:bg-accent absolute end-1.5 top-1/2 size-6 -translate-y-1/2 p-0 opacity-0 group-hover:opacity-100 group-has-focus-visible:opacity-100 group-data-active:opacity-100 data-[state=open]:opacity-100" > <MoreHorizontalIcon className="size-3.5" /> <span className="sr-only">More options</span> </Button> </ThreadListItemMorePrimitive.Trigger> <ThreadListItemMorePrimitive.Content side="right" align="start" sideOffset={6} data-slot="aui_thread-list-item-more-content" className="bg-popover/95 text-popover-foreground data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=open]:animate-in data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:animate-out data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-32 overflow-hidden rounded-xl border p-1.5 shadow-lg backdrop-blur-sm" > <ThreadListItemPrimitive.Archive asChild> <ThreadListItemMorePrimitive.Item data-slot="aui_thread-list-item-more-item" className="hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground flex cursor-pointer items-center gap-2 rounded-lg px-2.5 py-1.5 text-sm outline-none select-none" > <ArchiveIcon className="size-4" /> Archive </ThreadListItemMorePrimitive.Item> </ThreadListItemPrimitive.Archive> <ThreadListItemPrimitive.Delete asChild> <ThreadListItemMorePrimitive.Item data-slot="aui_thread-list-item-more-item" className="text-destructive hover:bg-destructive/10 hover:text-destructive focus:bg-destructive/10 focus:text-destructive flex cursor-pointer items-center gap-2 rounded-lg px-2.5 py-1.5 text-sm outline-none select-none" > <TrashIcon className="size-4" /> Delete </ThreadListItemMorePrimitive.Item> </ThreadListItemPrimitive.Delete> </ThreadListItemMorePrimitive.Content> </ThreadListItemMorePrimitive.Root> );};"use client";import { type ComponentPropsWithRef, forwardRef } from "react";import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger,} from "@/components/ui/tooltip";import { Button } from "@/components/ui/button";import { cn } from "@/lib/utils";export type TooltipIconButtonProps = ComponentPropsWithRef<typeof Button> & { tooltip: string; side?: "top" | "bottom" | "left" | "right";};export const TooltipIconButton = forwardRef< HTMLButtonElement, TooltipIconButtonProps>(({ children, tooltip, side = "bottom", className, ...rest }, ref) => { return ( <TooltipProvider> <Tooltip> <TooltipTrigger render={ <Button variant="ghost" size="icon" {...rest} className={cn( "aui-button-icon size-6 p-1 active:scale-90", className, )} ref={ref} /> } > {children} <span className="aui-sr-only sr-only">{tooltip}</span> </TooltipTrigger> <TooltipContent side={side}>{tooltip}</TooltipContent> </Tooltip> </TooltipProvider> );});TooltipIconButton.displayName = "TooltipIconButton";shadcn/ui dependencies
npm install @base-ui/react"use client";import * as React from "react";import { mergeProps } from "@base-ui/react/merge-props";import { useRender } from "@base-ui/react/use-render";import { cva, type VariantProps } from "class-variance-authority";import { PanelLeftIcon } from "lucide-react";import { useIsMobile } from "@/hooks/use-mobile";import { cn } from "@/lib/utils";import { Button } from "@/components/ui/button";import { Input } from "@/components/ui/input";import { Separator } from "@/components/ui/separator";import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle,} from "@/components/ui/sheet";import { Skeleton } from "@/components/ui/skeleton";import { Tooltip, TooltipContent, TooltipTrigger,} from "@/components/ui/tooltip";const SIDEBAR_COOKIE_NAME = "sidebar_state";const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;const SIDEBAR_WIDTH = "16rem";const SIDEBAR_WIDTH_MOBILE = "18rem";const SIDEBAR_WIDTH_ICON = "3rem";const SIDEBAR_KEYBOARD_SHORTCUT = "b";type SidebarContextProps = { state: "expanded" | "collapsed"; open: boolean; setOpen: (open: boolean) => void; openMobile: boolean; setOpenMobile: (open: boolean) => void; isMobile: boolean; toggleSidebar: () => void;};const SidebarContext = React.createContext<SidebarContextProps | null>(null);function useSidebar() { const context = React.useContext(SidebarContext); if (!context) { throw new Error("useSidebar must be used within a SidebarProvider."); } return context;}function SidebarProvider({ defaultOpen = true, open: openProp, onOpenChange: setOpenProp, className, style, children, ...props}: React.ComponentProps<"div"> & { defaultOpen?: boolean; open?: boolean; onOpenChange?: (open: boolean) => void;}) { const isMobile = useIsMobile(); const [openMobile, setOpenMobile] = React.useState(false); const [_open, _setOpen] = React.useState(defaultOpen); const open = openProp ?? _open; const setOpen = React.useCallback( (value: boolean | ((value: boolean) => boolean)) => { const openState = typeof value === "function" ? value(open) : value; if (setOpenProp) { setOpenProp(openState); } else { _setOpen(openState); } document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`; }, [setOpenProp, open], ); const toggleSidebar = React.useCallback(() => { return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open); }, [isMobile, setOpen, setOpenMobile]); React.useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { if ( event.key === SIDEBAR_KEYBOARD_SHORTCUT && (event.metaKey || event.ctrlKey) ) { event.preventDefault(); toggleSidebar(); } }; window.addEventListener("keydown", handleKeyDown); return () => window.removeEventListener("keydown", handleKeyDown); }, [toggleSidebar]); const state = open ? "expanded" : "collapsed"; const contextValue = React.useMemo<SidebarContextProps>( () => ({ state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar, }), [state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar], ); return ( <SidebarContext.Provider value={contextValue}> <div data-slot="sidebar-wrapper" style={ { "--sidebar-width": SIDEBAR_WIDTH, "--sidebar-width-icon": SIDEBAR_WIDTH_ICON, ...style, } as React.CSSProperties } className={cn( "group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full", className, )} {...props} > {children} </div> </SidebarContext.Provider> );}function Sidebar({ side = "left", variant = "sidebar", collapsible = "offcanvas", className, children, dir, ...props}: React.ComponentProps<"div"> & { side?: "left" | "right"; variant?: "sidebar" | "floating" | "inset"; collapsible?: "offcanvas" | "icon" | "none";}) { const { isMobile, state, openMobile, setOpenMobile } = useSidebar(); if (collapsible === "none") { return ( <div data-slot="sidebar" className={cn( "bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col", className, )} {...props} > {children} </div> ); } if (isMobile) { return ( <Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}> <SheetContent dir={dir} data-sidebar="sidebar" data-slot="sidebar" data-mobile="true" className="bg-sidebar text-sidebar-foreground w-(--sidebar-width) p-0 [&>button]:hidden" style={ { "--sidebar-width": SIDEBAR_WIDTH_MOBILE, } as React.CSSProperties } side={side} > <SheetHeader className="sr-only"> <SheetTitle>Sidebar</SheetTitle> <SheetDescription>Displays the mobile sidebar.</SheetDescription> </SheetHeader> <div className="flex h-full w-full flex-col">{children}</div> </SheetContent> </Sheet> ); } return ( <div className="group peer text-sidebar-foreground hidden md:block" data-state={state} data-collapsible={state === "collapsed" ? collapsible : ""} data-variant={variant} data-side={side} data-slot="sidebar" > <div data-slot="sidebar-gap" className={cn( "relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear", "group-data-[collapsible=offcanvas]:w-0", "group-data-[side=right]:rotate-180", variant === "floating" || variant === "inset" ? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]" : "group-data-[collapsible=icon]:w-(--sidebar-width-icon)", )} /> <div data-slot="sidebar-container" data-side={side} className={cn( "fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear data-[side=left]:left-0 data-[side=left]:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)] data-[side=right]:right-0 data-[side=right]:group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)] md:flex", variant === "floating" || variant === "inset" ? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]" : "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l", className, )} {...props} > <div data-sidebar="sidebar" data-slot="sidebar-inner" className="bg-sidebar group-data-[variant=floating]:ring-sidebar-border flex size-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:shadow-sm group-data-[variant=floating]:ring-1" > {children} </div> </div> </div> );}function SidebarTrigger({ className, onClick, ...props}: React.ComponentProps<typeof Button>) { const { toggleSidebar } = useSidebar(); return ( <Button data-sidebar="trigger" data-slot="sidebar-trigger" variant="ghost" size="icon-sm" className={cn(className)} onClick={(event) => { onClick?.(event); toggleSidebar(); }} {...props} > <PanelLeftIcon className="cn-rtl-flip" /> <span className="sr-only">Toggle Sidebar</span> </Button> );}function SidebarRail({ className, ...props }: React.ComponentProps<"button">) { const { toggleSidebar } = useSidebar(); return ( <button data-sidebar="rail" data-slot="sidebar-rail" aria-label="Toggle Sidebar" tabIndex={-1} onClick={toggleSidebar} title="Toggle Sidebar" className={cn( "hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:start-1/2 after:w-[2px] sm:flex ltr:-translate-x-1/2 rtl:-translate-x-1/2", "in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize", "[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize", "hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full", "[[data-side=left][data-collapsible=offcanvas]_&]:-right-2", "[[data-side=right][data-collapsible=offcanvas]_&]:-left-2", className, )} {...props} /> );}function SidebarInset({ className, ...props }: React.ComponentProps<"main">) { return ( <main data-slot="sidebar-inset" className={cn( "bg-background relative flex w-full flex-1 flex-col md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2", className, )} {...props} /> );}function SidebarInput({ className, ...props}: React.ComponentProps<typeof Input>) { return ( <Input data-slot="sidebar-input" data-sidebar="input" className={cn("bg-background h-8 w-full shadow-none", className)} {...props} /> );}function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="sidebar-header" data-sidebar="header" className={cn("flex flex-col gap-2 p-2", className)} {...props} /> );}function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="sidebar-footer" data-sidebar="footer" className={cn("flex flex-col gap-2 p-2", className)} {...props} /> );}function SidebarSeparator({ className, ...props}: React.ComponentProps<typeof Separator>) { return ( <Separator data-slot="sidebar-separator" data-sidebar="separator" className={cn("bg-sidebar-border mx-2 w-auto", className)} {...props} /> );}function SidebarContent({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="sidebar-content" data-sidebar="content" className={cn( "no-scrollbar flex min-h-0 flex-1 flex-col gap-0 overflow-auto group-data-[collapsible=icon]:overflow-hidden", className, )} {...props} /> );}function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="sidebar-group" data-sidebar="group" className={cn("relative flex w-full min-w-0 flex-col p-2", className)} {...props} /> );}function SidebarGroupLabel({ className, render, ...props}: useRender.ComponentProps<"div"> & React.ComponentProps<"div">) { return useRender({ defaultTagName: "div", props: mergeProps<"div">( { className: cn( "text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium outline-hidden transition-[margin,opacity] duration-200 ease-linear group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0 focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0", className, ), }, props, ), render, state: { slot: "sidebar-group-label", sidebar: "group-label", }, });}function SidebarGroupAction({ className, render, ...props}: useRender.ComponentProps<"button"> & React.ComponentProps<"button">) { return useRender({ defaultTagName: "button", props: mergeProps<"button">( { className: cn( "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-hidden transition-transform group-data-[collapsible=icon]:hidden after:absolute after:-inset-2 focus-visible:ring-2 md:after:hidden [&>svg]:size-4 [&>svg]:shrink-0", className, ), }, props, ), render, state: { slot: "sidebar-group-action", sidebar: "group-action", }, });}function SidebarGroupContent({ className, ...props}: React.ComponentProps<"div">) { return ( <div data-slot="sidebar-group-content" data-sidebar="group-content" className={cn("w-full text-sm", className)} {...props} /> );}function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) { return ( <ul data-slot="sidebar-menu" data-sidebar="menu" className={cn("flex w-full min-w-0 flex-col gap-0", className)} {...props} /> );}function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) { return ( <li data-slot="sidebar-menu-item" data-sidebar="menu-item" className={cn("group/menu-item relative", className)} {...props} /> );}const sidebarMenuButtonVariants = cva( "peer/menu-button group/menu-button ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground data-open:hover:bg-sidebar-accent data-open:hover:text-sidebar-accent-foreground data-active:bg-sidebar-accent data-active:text-sidebar-accent-foreground flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-active:font-medium [&_svg]:size-4 [&_svg]:shrink-0 [&>span:last-child]:truncate", { variants: { variant: { default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground", outline: "bg-background hover:bg-sidebar-accent hover:text-sidebar-accent-foreground shadow-[0_0_0_1px_var(--sidebar-border)] hover:shadow-[0_0_0_1px_var(--sidebar-accent)]", }, size: { default: "h-8 text-sm", sm: "h-7 text-xs", lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!", }, }, defaultVariants: { variant: "default", size: "default", }, },);function SidebarMenuButton({ render, isActive = false, variant = "default", size = "default", tooltip, className, ...props}: useRender.ComponentProps<"button"> & React.ComponentProps<"button"> & { isActive?: boolean; tooltip?: string | React.ComponentProps<typeof TooltipContent>; } & VariantProps<typeof sidebarMenuButtonVariants>) { const { isMobile, state } = useSidebar(); const comp = useRender({ defaultTagName: "button", props: mergeProps<"button">( { className: cn(sidebarMenuButtonVariants({ variant, size }), className), }, props, ), render: !tooltip ? render : <TooltipTrigger render={render} />, state: { slot: "sidebar-menu-button", sidebar: "menu-button", size, active: isActive, }, }); if (!tooltip) { return comp; } if (typeof tooltip === "string") { tooltip = { children: tooltip, }; } return ( <Tooltip> {comp} <TooltipContent side="right" align="center" hidden={state !== "collapsed" || isMobile} {...tooltip} /> </Tooltip> );}function SidebarMenuAction({ className, render, showOnHover = false, ...props}: useRender.ComponentProps<"button"> & React.ComponentProps<"button"> & { showOnHover?: boolean; }) { return useRender({ defaultTagName: "button", props: mergeProps<"button">( { className: cn( "text-sidebar-foreground ring-sidebar-ring peer-hover/menu-button:text-sidebar-accent-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-hidden transition-transform group-data-[collapsible=icon]:hidden peer-data-[size=default]/menu-button:top-1.5 peer-data-[size=lg]/menu-button:top-2.5 peer-data-[size=sm]/menu-button:top-1 after:absolute after:-inset-2 focus-visible:ring-2 md:after:hidden [&>svg]:size-4 [&>svg]:shrink-0", showOnHover && "peer-data-active/menu-button:text-sidebar-accent-foreground group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 aria-expanded:opacity-100 md:opacity-0", className, ), }, props, ), render, state: { slot: "sidebar-menu-action", sidebar: "menu-action", }, });}function SidebarMenuBadge({ className, ...props}: React.ComponentProps<"div">) { return ( <div data-slot="sidebar-menu-badge" data-sidebar="menu-badge" className={cn( "text-sidebar-foreground peer-hover/menu-button:text-sidebar-accent-foreground peer-data-active/menu-button:text-sidebar-accent-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none group-data-[collapsible=icon]:hidden peer-data-[size=default]/menu-button:top-1.5 peer-data-[size=lg]/menu-button:top-2.5 peer-data-[size=sm]/menu-button:top-1", className, )} {...props} /> );}function SidebarMenuSkeleton({ className, showIcon = false, ...props}: React.ComponentProps<"div"> & { showIcon?: boolean;}) { const [width] = React.useState(() => { return `${Math.floor(Math.random() * 40) + 50}%`; }); return ( <div data-slot="sidebar-menu-skeleton" data-sidebar="menu-skeleton" className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)} {...props} > {showIcon && ( <Skeleton className="size-4 rounded-md" data-sidebar="menu-skeleton-icon" /> )} <Skeleton className="h-4 max-w-(--skeleton-width) flex-1" data-sidebar="menu-skeleton-text" style={ { "--skeleton-width": width, } as React.CSSProperties } /> </div> );}function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) { return ( <ul data-slot="sidebar-menu-sub" data-sidebar="menu-sub" className={cn( "border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5 group-data-[collapsible=icon]:hidden", className, )} {...props} /> );}function SidebarMenuSubItem({ className, ...props}: React.ComponentProps<"li">) { return ( <li data-slot="sidebar-menu-sub-item" data-sidebar="menu-sub-item" className={cn("group/menu-sub-item relative", className)} {...props} /> );}function SidebarMenuSubButton({ render, size = "md", isActive = false, className, ...props}: useRender.ComponentProps<"a"> & React.ComponentProps<"a"> & { size?: "sm" | "md"; isActive?: boolean; }) { return useRender({ defaultTagName: "a", props: mergeProps<"a">( { className: cn( "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground data-active:bg-sidebar-accent data-active:text-sidebar-accent-foreground [&>svg]:text-sidebar-accent-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-hidden group-data-[collapsible=icon]:hidden focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[size=md]:text-sm data-[size=sm]:text-xs [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0", className, ), }, props, ), render, state: { slot: "sidebar-menu-sub-button", sidebar: "menu-sub-button", size, active: isActive, }, });}export { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarInset, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger, useSidebar,};import { Button as ButtonPrimitive } from "@base-ui/react/button";import { cva, type VariantProps } from "class-variance-authority";import { cn } from "@/lib/utils";const buttonVariants = cva( "group/button focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:ring-3 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:ring-3 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", { variants: { variant: { default: "bg-primary text-primary-foreground hover:bg-primary/80", outline: "border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50", secondary: "bg-secondary text-secondary-foreground aria-expanded:bg-secondary aria-expanded:text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)]", ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50", destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40", link: "text-primary underline-offset-4 hover:underline", }, size: { default: "h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2", xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3", sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5", lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2", icon: "size-8", "icon-xs": "size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3", "icon-sm": "size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg", "icon-lg": "size-9", }, }, defaultVariants: { variant: "default", size: "default", }, },);function Button({ className, variant = "default", size = "default", ...props}: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>) { return ( <ButtonPrimitive data-slot="button" className={cn(buttonVariants({ variant, size, className }))} {...props} /> );}export { Button, buttonVariants };import * as React from "react";import { Input as InputPrimitive } from "@base-ui/react/input";import { cn } from "@/lib/utils";function Input({ className, type, ...props }: React.ComponentProps<"input">) { return ( <InputPrimitive type={type} data-slot="input" className={cn( "border-input file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 disabled:bg-input/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 h-8 w-full min-w-0 rounded-lg border bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-3 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3 md:text-sm", className, )} {...props} /> );}export { Input };import { cn } from "@/lib/utils";function Skeleton({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="skeleton" className={cn("bg-muted animate-pulse rounded-md", className)} {...props} /> );}export { Skeleton };"use client";import { Tooltip as TooltipPrimitive } from "@base-ui/react/tooltip";import { cn } from "@/lib/utils";function TooltipProvider({ delay = 0, ...props}: TooltipPrimitive.Provider.Props) { return ( <TooltipPrimitive.Provider data-slot="tooltip-provider" delay={delay} {...props} /> );}function Tooltip({ ...props }: TooltipPrimitive.Root.Props) { return <TooltipPrimitive.Root data-slot="tooltip" {...props} />;}function TooltipTrigger({ ...props }: TooltipPrimitive.Trigger.Props) { return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />;}function TooltipContent({ className, side = "top", sideOffset = 4, align = "center", alignOffset = 0, children, ...props}: TooltipPrimitive.Popup.Props & Pick< TooltipPrimitive.Positioner.Props, "align" | "alignOffset" | "side" | "sideOffset" >) { return ( <TooltipPrimitive.Portal> <TooltipPrimitive.Positioner align={align} alignOffset={alignOffset} side={side} sideOffset={sideOffset} className="isolate z-50" > <TooltipPrimitive.Popup data-slot="tooltip-content" className={cn( "bg-foreground text-background data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 z-50 inline-flex w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-md px-3 py-1.5 text-xs has-data-[slot=kbd]:pr-1.5 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm", className, )} {...props} > {children} <TooltipPrimitive.Arrow data-slot="tooltip-arrow" className="bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px] data-[side=bottom]:top-1 data-[side=inline-end]:top-1/2! data-[side=inline-end]:-left-1 data-[side=inline-end]:-translate-y-1/2 data-[side=inline-start]:top-1/2! data-[side=inline-start]:-right-1 data-[side=inline-start]:-translate-y-1/2 data-[side=left]:top-1/2! data-[side=left]:-right-1 data-[side=left]:-translate-y-1/2 data-[side=right]:top-1/2! data-[side=right]:-left-1 data-[side=right]:-translate-y-1/2 data-[side=top]:-bottom-2.5" /> </TooltipPrimitive.Popup> </TooltipPrimitive.Positioner> </TooltipPrimitive.Portal> );}export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };ThreadList
npx shadcn@latest add @assistant-ui/thread-listThe @assistant-uinamespace resolves the Radix or Base UI flavor from your project's style through the style-aware registry entry in components.json. Without that entry, add by direct URL instead:
npx shadcn@latest add https://r.assistant-ui.com/base/thread-list.jsonMain Component
npm install @assistant-ui/react"use client";import { Button } from "@/components/ui/button";import { Input } from "@/components/ui/input";import { Skeleton } from "@/components/ui/skeleton";import { cn } from "@/lib/utils";import { AuiIf, ThreadListItemMorePrimitive, ThreadListItemPrimitive, ThreadListPrimitive, useAuiState,} from "@assistant-ui/react";import { ArchiveIcon, MoreHorizontalIcon, PlusIcon, SearchIcon, TrashIcon,} from "lucide-react";import { forwardRef, Fragment, useMemo, useState, type ComponentPropsWithoutRef, type FC,} from "react";export const ThreadList: FC = () => { const [search, setSearch] = useState(""); const hasThreads = useAuiState((s) => s.threads.threadIds.length > 0); return ( <ThreadListRoot> <ThreadListNew /> {hasThreads && ( <ThreadListSearch value={search} onValueChange={setSearch} /> )} <ThreadListItems searchQuery={hasThreads ? search : ""} /> </ThreadListRoot> );};export const ThreadListSearch = forwardRef< HTMLInputElement, Omit<ComponentPropsWithoutRef<typeof Input>, "value" | "onChange"> & { value: string; onValueChange: (value: string) => void; }>(({ className, value, onValueChange, ...props }, ref) => { return ( <div data-slot="aui_thread-list-search" className="relative px-0.5 py-1"> <SearchIcon data-slot="aui_thread-list-search-icon" className="text-muted-foreground pointer-events-none absolute start-3 top-1/2 size-4 -translate-y-1/2" /> <Input ref={ref} type="search" value={value} onChange={(event) => onValueChange(event.target.value)} aria-label="Search threads" placeholder="Search threads" className={cn("h-8 ps-8 text-sm", className)} {...props} /> </div> );});ThreadListSearch.displayName = "ThreadListSearch";export const ThreadListRoot: FC< ComponentPropsWithoutRef<typeof ThreadListPrimitive.Root>> = ({ className, ...props }) => { return ( <ThreadListPrimitive.Root data-slot="aui_thread-list-root" className={cn("flex flex-col gap-0.5", className)} {...props} /> );};export const ThreadListItems: FC< ComponentPropsWithoutRef<"div"> & { searchQuery?: string }> = ({ className, searchQuery = "", ...props }) => { return ( <div data-slot="aui_thread-list-items" className={cn("flex flex-col gap-0.5", className)} {...props} > <AuiIf condition={(s) => s.threads.isLoading}> <ThreadListSkeleton /> </AuiIf> <AuiIf condition={(s) => !s.threads.isLoading}> <ThreadListItemGroups searchQuery={searchQuery} /> </AuiIf> </div> );};const DAY_IN_MS = 86_400_000;const dateGroupLabel = ( date: Date | undefined, startOfToday: number,): string => { if (!date || date.getTime() >= startOfToday) return "Today"; if (date.getTime() >= startOfToday - DAY_IN_MS) return "Yesterday"; return "Earlier";};type ThreadListGroup = { label: string; indices: number[] };const ThreadListItemGroups: FC<{ searchQuery?: string }> = ({ searchQuery = "",}) => { const threadIds = useAuiState((s) => s.threads.threadIds); const threadItems = useAuiState((s) => s.threads.threadItems); const query = searchQuery.trim().toLowerCase(); const { filteredIndices, groups } = useMemo(() => { const itemsById = new Map(threadItems.map((item) => [item.id, item])); const dates = threadIds.map((id) => itemsById.get(id)?.lastMessageAt); const filteredIndices = threadIds .map((id, index) => ({ id, index })) .filter( ({ id }) => !query || (itemsById.get(id)?.title || "New Chat") .toLowerCase() .includes(query), ) .map(({ index }) => index); if (!filteredIndices.some((index) => dates[index])) { return { filteredIndices, groups: null }; } const now = new Date(); const startOfToday = new Date( now.getFullYear(), now.getMonth(), now.getDate(), ).getTime(); const time = (index: number) => dates[index]?.getTime() ?? Number.MAX_SAFE_INTEGER; const sorted = [...filteredIndices].sort((a, b) => time(b) - time(a)); const result: ThreadListGroup[] = []; for (const index of sorted) { const label = dateGroupLabel(dates[index], startOfToday); const lastGroup = result[result.length - 1]; if (lastGroup?.label === label) { lastGroup.indices.push(index); } else { result.push({ label, indices: [index] }); } } return { filteredIndices, groups: result }; }, [threadIds, threadItems, query]); if (query && filteredIndices.length === 0) { return ( <div data-slot="aui_thread-list-empty" className="text-muted-foreground px-2.5 py-4 text-sm" > No threads found </div> ); } if (!groups) { return filteredIndices.map((index) => ( <ThreadListPrimitive.ItemByIndex key={threadIds[index]} index={index} components={{ ThreadListItem }} /> )); } return groups.map((group) => ( <Fragment key={group.label}> <div data-slot="aui_thread-list-group-label" className="text-muted-foreground px-2.5 pt-3 pb-1 text-xs font-medium" > {group.label} </div> {group.indices.map((index) => ( <ThreadListPrimitive.ItemByIndex key={threadIds[index]} index={index} components={{ ThreadListItem }} /> ))} </Fragment> ));};export const ThreadListNew = forwardRef< HTMLButtonElement, ComponentPropsWithoutRef<typeof Button> & { labelClassName?: string }>(({ className, labelClassName, children, ...props }, ref) => { return ( <ThreadListPrimitive.New asChild> <Button ref={ref} variant="ghost" data-slot="aui_thread-list-new" className={cn( "hover:bg-muted data-active:bg-muted h-8 justify-start gap-2 rounded-md px-2.5 text-sm font-normal", className, )} {...props} > {children ?? ( <> <PlusIcon data-slot="aui_thread-list-new-icon" className="size-4 shrink-0" /> <span data-slot="aui_thread-list-new-label" className={cn("whitespace-nowrap", labelClassName)} > New Thread </span> </> )} </Button> </ThreadListPrimitive.New> );});ThreadListNew.displayName = "ThreadListNew";const ThreadListSkeleton: FC = () => { return ( <div className="flex flex-col gap-0.5"> {Array.from({ length: 5 }, (_, i) => ( <div key={i} role="status" aria-label="Loading threads" data-slot="aui_thread-list-skeleton-wrapper" className="flex h-8 items-center px-2.5" > <Skeleton data-slot="aui_thread-list-skeleton" className="h-3.5 w-full" /> </div> ))} </div> );};export const ThreadListItem: FC = () => { return ( <ThreadListItemPrimitive.Root data-slot="aui_thread-list-item" className="group hover:bg-muted focus-visible:bg-muted data-active:bg-muted has-focus-visible:bg-muted has-data-[state=open]:bg-muted relative flex h-8 items-center rounded-md transition-colors focus-visible:outline-none" > <ThreadListItemPrimitive.Trigger data-slot="aui_thread-list-item-trigger" className="focus-visible:ring-ring/50 flex h-full min-w-0 flex-1 items-center rounded-md px-2.5 text-start text-sm outline-none group-hover:pe-9 group-has-focus-visible:pe-9 group-has-data-[state=open]:pe-9 group-data-active:pe-9 focus-visible:ring-[3px]" > <span data-slot="aui_thread-list-item-title" className="min-w-0 flex-1 truncate" > <ThreadListItemPrimitive.Title fallback="New Chat" /> </span> </ThreadListItemPrimitive.Trigger> <ThreadListItemMore /> </ThreadListItemPrimitive.Root> );};const ThreadListItemMore: FC = () => { return ( <ThreadListItemMorePrimitive.Root sharedFocusGroup> <ThreadListItemMorePrimitive.Trigger asChild> <Button variant="ghost" size="icon" data-slot="aui_thread-list-item-more" className="data-[state=open]:bg-accent absolute end-1.5 top-1/2 size-6 -translate-y-1/2 p-0 opacity-0 group-hover:opacity-100 group-has-focus-visible:opacity-100 group-data-active:opacity-100 data-[state=open]:opacity-100" > <MoreHorizontalIcon className="size-3.5" /> <span className="sr-only">More options</span> </Button> </ThreadListItemMorePrimitive.Trigger> <ThreadListItemMorePrimitive.Content side="right" align="start" sideOffset={6} data-slot="aui_thread-list-item-more-content" className="bg-popover/95 text-popover-foreground data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=open]:animate-in data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:animate-out data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-32 overflow-hidden rounded-xl border p-1.5 shadow-lg backdrop-blur-sm" > <ThreadListItemPrimitive.Archive asChild> <ThreadListItemMorePrimitive.Item data-slot="aui_thread-list-item-more-item" className="hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground flex cursor-pointer items-center gap-2 rounded-lg px-2.5 py-1.5 text-sm outline-none select-none" > <ArchiveIcon className="size-4" /> Archive </ThreadListItemMorePrimitive.Item> </ThreadListItemPrimitive.Archive> <ThreadListItemPrimitive.Delete asChild> <ThreadListItemMorePrimitive.Item data-slot="aui_thread-list-item-more-item" className="text-destructive hover:bg-destructive/10 hover:text-destructive focus:bg-destructive/10 focus:text-destructive flex cursor-pointer items-center gap-2 rounded-lg px-2.5 py-1.5 text-sm outline-none select-none" > <TrashIcon className="size-4" /> Delete </ThreadListItemMorePrimitive.Item> </ThreadListItemPrimitive.Delete> </ThreadListItemMorePrimitive.Content> </ThreadListItemMorePrimitive.Root> );};assistant-ui dependencies
"use client";import { type ComponentPropsWithRef, forwardRef } from "react";import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger,} from "@/components/ui/tooltip";import { Button } from "@/components/ui/button";import { cn } from "@/lib/utils";export type TooltipIconButtonProps = ComponentPropsWithRef<typeof Button> & { tooltip: string; side?: "top" | "bottom" | "left" | "right";};export const TooltipIconButton = forwardRef< HTMLButtonElement, TooltipIconButtonProps>(({ children, tooltip, side = "bottom", className, ...rest }, ref) => { return ( <TooltipProvider> <Tooltip> <TooltipTrigger render={ <Button variant="ghost" size="icon" {...rest} className={cn( "aui-button-icon size-6 p-1 active:scale-90", className, )} ref={ref} /> } > {children} <span className="aui-sr-only sr-only">{tooltip}</span> </TooltipTrigger> <TooltipContent side={side}>{tooltip}</TooltipContent> </Tooltip> </TooltipProvider> );});TooltipIconButton.displayName = "TooltipIconButton";shadcn/ui dependencies
npm install @base-ui/reactimport { Button as ButtonPrimitive } from "@base-ui/react/button";import { cva, type VariantProps } from "class-variance-authority";import { cn } from "@/lib/utils";const buttonVariants = cva( "group/button focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:ring-3 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:ring-3 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", { variants: { variant: { default: "bg-primary text-primary-foreground hover:bg-primary/80", outline: "border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50", secondary: "bg-secondary text-secondary-foreground aria-expanded:bg-secondary aria-expanded:text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)]", ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50", destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40", link: "text-primary underline-offset-4 hover:underline", }, size: { default: "h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2", xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3", sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5", lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2", icon: "size-8", "icon-xs": "size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3", "icon-sm": "size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg", "icon-lg": "size-9", }, }, defaultVariants: { variant: "default", size: "default", }, },);function Button({ className, variant = "default", size = "default", ...props}: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>) { return ( <ButtonPrimitive data-slot="button" className={cn(buttonVariants({ variant, size, className }))} {...props} /> );}export { Button, buttonVariants };import * as React from "react";import { Input as InputPrimitive } from "@base-ui/react/input";import { cn } from "@/lib/utils";function Input({ className, type, ...props }: React.ComponentProps<"input">) { return ( <InputPrimitive type={type} data-slot="input" className={cn( "border-input file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 disabled:bg-input/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 h-8 w-full min-w-0 rounded-lg border bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-3 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3 md:text-sm", className, )} {...props} /> );}export { Input };import { cn } from "@/lib/utils";function Skeleton({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="skeleton" className={cn("bg-muted animate-pulse rounded-md", className)} {...props} /> );}export { Skeleton };"use client";import { Tooltip as TooltipPrimitive } from "@base-ui/react/tooltip";import { cn } from "@/lib/utils";function TooltipProvider({ delay = 0, ...props}: TooltipPrimitive.Provider.Props) { return ( <TooltipPrimitive.Provider data-slot="tooltip-provider" delay={delay} {...props} /> );}function Tooltip({ ...props }: TooltipPrimitive.Root.Props) { return <TooltipPrimitive.Root data-slot="tooltip" {...props} />;}function TooltipTrigger({ ...props }: TooltipPrimitive.Trigger.Props) { return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />;}function TooltipContent({ className, side = "top", sideOffset = 4, align = "center", alignOffset = 0, children, ...props}: TooltipPrimitive.Popup.Props & Pick< TooltipPrimitive.Positioner.Props, "align" | "alignOffset" | "side" | "sideOffset" >) { return ( <TooltipPrimitive.Portal> <TooltipPrimitive.Positioner align={align} alignOffset={alignOffset} side={side} sideOffset={sideOffset} className="isolate z-50" > <TooltipPrimitive.Popup data-slot="tooltip-content" className={cn( "bg-foreground text-background data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 z-50 inline-flex w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-md px-3 py-1.5 text-xs has-data-[slot=kbd]:pr-1.5 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm", className, )} {...props} > {children} <TooltipPrimitive.Arrow data-slot="tooltip-arrow" className="bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px] data-[side=bottom]:top-1 data-[side=inline-end]:top-1/2! data-[side=inline-end]:-left-1 data-[side=inline-end]:-translate-y-1/2 data-[side=inline-start]:top-1/2! data-[side=inline-start]:-right-1 data-[side=inline-start]:-translate-y-1/2 data-[side=left]:top-1/2! data-[side=left]:-right-1 data-[side=left]:-translate-y-1/2 data-[side=right]:top-1/2! data-[side=right]:-left-1 data-[side=right]:-translate-y-1/2 data-[side=top]:-bottom-2.5" /> </TooltipPrimitive.Popup> </TooltipPrimitive.Positioner> </TooltipPrimitive.Portal> );}export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };Use in your application
import { Thread } from "@/components/assistant-ui/thread";
import { ThreadListSidebar } from "@/components/assistant-ui/threadlist-sidebar";
import {
SidebarProvider,
SidebarInset,
SidebarTrigger
} from "@/components/ui/sidebar";
export default function Assistant() {
return (
<SidebarProvider>
<div className="flex h-dvh w-full">
<ThreadListSidebar />
<SidebarInset>
{/* Add sidebar trigger, location can be customized */}
<SidebarTrigger className="absolute top-4 left-4" />
<Thread />
</SidebarInset>
</div>
</SidebarProvider>
);
}import { Thread } from "@/components/assistant-ui/thread";
import { ThreadList } from "@/components/assistant-ui/thread-list";
export default function Assistant() {
return (
<div className="grid h-full grid-cols-[200px_1fr]">
<ThreadList />
<Thread />
</div>
);
}Anatomy
The ThreadList component is built with the following primitives:
import { ThreadListPrimitive, ThreadListItemPrimitive } from "@assistant-ui/react";
<ThreadListPrimitive.Root>
<ThreadListPrimitive.New />
<ThreadListPrimitive.Items>
{() => (
<ThreadListItemPrimitive.Root>
<ThreadListItemPrimitive.Trigger>
<ThreadListItemPrimitive.Title />
</ThreadListItemPrimitive.Trigger>
<ThreadListItemPrimitive.Archive />
<ThreadListItemPrimitive.Delete />
</ThreadListItemPrimitive.Root>
)}
</ThreadListPrimitive.Items>
</ThreadListPrimitive.Root>API Reference
ThreadListPrimitive.Root
Container for the thread list.
ThreadListPrimitiveRootPropsasChild: boolean= falseMerge props with child element instead of rendering a wrapper div.
ThreadListPrimitive.Items
Renders all threads in the list.
ThreadListPrimitiveItemsPropsarchived?: booleanWhen true, renders archived threads instead of active threads.
components: objectComponent configuration.
ThreadListItem: ComponentTypeComponent to render for each thread item.
ThreadListPrimitive.New
A button to create a new thread.
ThreadListPrimitiveNewPropsasChild: boolean= falseMerge props with child element instead of rendering a wrapper button.
ThreadListPrimitive.LoadMore
A button that appends the next page of threads. See the LoadMore primitive reference for usage and Threads concepts for the adapter contract.
ThreadListPrimitiveLoadMorePropsasChild: boolean= falseMerge props with child element instead of rendering a wrapper button.
ThreadListItemPrimitive.Root
Container for a single thread item. Automatically sets data-active and aria-current when this is the current thread.
ThreadListItemPrimitiveRootPropsasChild: boolean= falseMerge props with child element instead of rendering a wrapper div.
ThreadListItemPrimitive.Trigger
A button that switches to this thread when clicked.
ThreadListItemPrimitiveTriggerPropsasChild: boolean= falseMerge props with child element instead of rendering a wrapper button.
ThreadListItemPrimitive.Title
Renders the thread's title.
ThreadListItemPrimitiveTitlePropsfallback?: ReactNodeContent to display when the thread has no title.
ThreadListItemPrimitive.Archive
A button to archive the thread.
ThreadListItemPrimitiveArchivePropsasChild: boolean= falseMerge props with child element instead of rendering a wrapper button.
ThreadListItemPrimitive.Unarchive
A button to restore an archived thread.
ThreadListItemPrimitiveUnarchivePropsasChild: boolean= falseMerge props with child element instead of rendering a wrapper button.
ThreadListItemPrimitive.Delete
A button to permanently delete the thread.
ThreadListItemPrimitiveDeletePropsasChild: boolean= falseMerge props with child element instead of rendering a wrapper button.
ThreadListItemMorePrimitive
A dropdown menu for additional thread actions, built on Radix UI DropdownMenu.
ThreadListItemMorePrimitive.Root
Menu container that manages dropdown state.
ThreadListItemMorePrimitiveRootPropsasChild: boolean= falseMerge props with child element instead of rendering a wrapper div.
ThreadListItemMorePrimitive.Trigger
Button to open the menu.
ThreadListItemMorePrimitiveTriggerPropsasChild: boolean= falseMerge props with child element instead of rendering a wrapper button.
ThreadListItemMorePrimitive.Content
Menu content container.
ThreadListItemMorePrimitiveContentPropsasChild: boolean= falseMerge props with child element instead of rendering a wrapper div.
ThreadListItemMorePrimitive.Item
Individual menu item.
ThreadListItemMorePrimitiveItemPropsasChild: boolean= falseMerge props with child element instead of rendering a wrapper div.
ThreadListItemMorePrimitive.Separator
Visual separator between items.
ThreadListItemMorePrimitiveSeparatorPropsasChild: boolean= falseMerge props with child element instead of rendering a wrapper div.
Related Components
- Thread - The main chat interface displayed alongside the list