feat(sidebar): implement inbox sidebar with docked and floating modes, add sidebar context for state management

This commit is contained in:
Anish Sarkar 2026-01-27 19:46:43 +05:30
parent b3f08a7aa7
commit f7122cd477
7 changed files with 362 additions and 146 deletions

View file

@ -0,0 +1,37 @@
"use client";
import { createContext, useContext, type ReactNode } from "react";
interface SidebarContextValue {
isCollapsed: boolean;
setIsCollapsed: (collapsed: boolean) => void;
toggleCollapsed: () => void;
}
const SidebarContext = createContext<SidebarContextValue | null>(null);
interface SidebarProviderProps {
children: ReactNode;
value: SidebarContextValue;
}
export function SidebarProvider({ children, value }: SidebarProviderProps) {
return <SidebarContext.Provider value={value}>{children}</SidebarContext.Provider>;
}
export function useSidebarContext(): SidebarContextValue {
const context = useContext(SidebarContext);
if (!context) {
throw new Error("useSidebarContext must be used within a SidebarProvider");
}
return context;
}
/**
* Safe version that returns null if not within provider
* Useful for components that may be rendered outside the sidebar context
*/
export function useSidebarContextSafe(): SidebarContextValue | null {
return useContext(SidebarContext);
}