"use client" import { useEffect, useRef } from "react" import { cn } from "@/lib/utils" import type { AvailableCommandInfo } from "@/lib/types" interface SlashCommandMenuProps { commands: AvailableCommandInfo[] selectedIndex: number onSelect: (command: AvailableCommandInfo) => void } export function SlashCommandMenu({ commands, selectedIndex, onSelect, }: SlashCommandMenuProps) { const listRef = useRef(null) useEffect(() => { const el = listRef.current?.children[selectedIndex] as | HTMLElement | undefined el?.scrollIntoView({ block: "nearest" }) }, [selectedIndex]) if (commands.length === 0) return null return (
{commands.map((cmd, i) => ( ))}
) }