All files / src/componentsV2/SideMenu DrawerContext.tsx

90.9% Statements 10/11
50% Branches 1/2
100% Functions 3/3
90% Lines 9/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27            14x   14x 69x 69x             103x   14x 552x 552x     552x    
// DrawerContext.tsx
import { createContext, useContext } from "react";
import { useDrawerCollapse } from "./hooks/useDrawerCollapse";
 
type DrawerContextType = ReturnType<typeof useDrawerCollapse>;
 
const DrawerContext = createContext<DrawerContextType | null>(null);
 
export const DrawerProvider = ({ children }: { children: React.ReactNode }) => {
  const drawer = useDrawerCollapse();
  return (
    <DrawerContext.Provider value={drawer}>{children}</DrawerContext.Provider>
  );
};
 
// Settings sections whose action bar is inset to the content column need the
// sidebar width, and are also rendered without this provider in unit tests.
export const useDrawerState = () => useContext(DrawerContext);
 
export const useDrawer = () => {
  const ctx = useContext(DrawerContext);
  Iif (!ctx) {
    throw new Error("useDrawer must be used within DrawerProvider");
  }
  return ctx;
};