import React, { useState, useEffect } from 'react'; import { cn } from '@/lib/utils'; import { Icon } from "@/components/icon/Icon"; interface SidebarGroupProps { /** Group display label (e.g. "business", "automation-ai") */ label: string; /** Number of items in this group */ count: number; /** Unique storage key prefix for persisting collapse state */ storageKey: string; /** Whether to start expanded. Defaults to true. */ defaultExpanded?: boolean; children: React.ReactNode; } function getStorageKey(storageKey: string, label: string): string { return `opencode:sidebar-group:${storageKey}:${label}`; } /** * Collapsible sidebar group with persisted expand/collapse state. * Used in Agents and Skills sidebars to group items by subfolder. */ export const SidebarGroup: React.FC = ({ label, count, storageKey, defaultExpanded = true, children, }) => { const key = getStorageKey(storageKey, label); const contentId = React.useId(); const [expanded, setExpanded] = useState(() => { try { const stored = localStorage.getItem(key); if (stored !== null) return stored === 'true'; } catch { // ignore storage errors } return defaultExpanded; }); useEffect(() => { try { localStorage.setItem(key, String(expanded)); } catch { // ignore storage errors } }, [key, expanded]); return (
); };