mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-22 20:29:23 +00:00
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
![]() |
import React, { createContext, useContext, useState, useRef } from 'react';
|
||
|
import { SidebarState, SidebarRefs, SidebarContextValue, SidebarProviderProps } from '../types/sidebar';
|
||
|
|
||
|
const SidebarContext = createContext<SidebarContextValue | undefined>(undefined);
|
||
|
|
||
|
export function SidebarProvider({ children }: SidebarProviderProps) {
|
||
|
// All sidebar state management
|
||
|
const quickAccessRef = useRef<HTMLDivElement>(null);
|
||
|
const toolPanelRef = useRef<HTMLDivElement>(null);
|
||
|
|
||
|
const [sidebarsVisible, setSidebarsVisible] = useState(true);
|
||
|
const [leftPanelView, setLeftPanelView] = useState<'toolPicker' | 'toolContent'>('toolPicker');
|
||
|
const [readerMode, setReaderMode] = useState(false);
|
||
|
|
||
|
const sidebarState: SidebarState = {
|
||
|
sidebarsVisible,
|
||
|
leftPanelView,
|
||
|
readerMode,
|
||
|
};
|
||
|
|
||
|
const sidebarRefs: SidebarRefs = {
|
||
|
quickAccessRef,
|
||
|
toolPanelRef,
|
||
|
};
|
||
|
|
||
|
const contextValue: SidebarContextValue = {
|
||
|
sidebarState,
|
||
|
sidebarRefs,
|
||
|
setSidebarsVisible,
|
||
|
setLeftPanelView,
|
||
|
setReaderMode,
|
||
|
};
|
||
|
|
||
|
return (
|
||
|
<SidebarContext.Provider value={contextValue}>
|
||
|
{children}
|
||
|
</SidebarContext.Provider>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
export function useSidebarContext(): SidebarContextValue {
|
||
|
const context = useContext(SidebarContext);
|
||
|
if (context === undefined) {
|
||
|
throw new Error('useSidebarContext must be used within a SidebarProvider');
|
||
|
}
|
||
|
return context;
|
||
|
}
|