"use client" /** * Search field for sidebar drill-in panels — expands to a full input when the * rail is open; collapses to a magnifying-glass `SidebarMenuButton` in icon mode * (same affordance as other nav rows). */ import * as React from "react" import { SidebarGroup, SidebarGroupContent, SidebarMenu, SidebarMenuButton, SidebarMenuItem, useSidebar, } from "@/components/ui/sidebar" export interface SidebarDrillInSearchFieldProps { id: string inputRef?: React.RefObject value: string onChange: (value: string) => void /** Accessible name + collapsed tooltip */ label: string placeholder: string /** Extra class on the expanded input */ inputClassName?: string /** * `standalone` — own `SidebarGroup` (Leo recents, legacy drill-in). * `menu-item` — first row inside an existing `SidebarMenu` (catalog browse). */ variant?: "standalone" | "menu-item" } export function SidebarDrillInSearchField({ id, inputRef, value, onChange, label, placeholder, inputClassName, variant = "standalone", }: SidebarDrillInSearchFieldProps) { const { state, setOpen, isMobile } = useSidebar() const collapsed = state === "collapsed" && !isMobile const focusInput = React.useCallback(() => { setOpen(true) queueMicrotask(() => inputRef?.current?.focus()) }, [inputRef, setOpen]) const inputClass = inputClassName ?? "h-8 w-full rounded-md border border-[color:var(--control-border)] bg-card pl-7 pr-2 text-xs text-foreground placeholder:text-muted-foreground focus-visible:border-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" if (variant === "menu-item") { if (collapsed) { return (