All files / src/sections/PayBuilder/provider ViewSwitcherContext.tsx

87.5% Statements 7/8
0% Branches 0/2
66.66% Functions 2/3
85.71% Lines 6/7

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 28 29 30 31 32 33 34 35 36              12x             12x         43x       43x       43x             91x  
import { useState, useContext, createContext } from "react";
 
type MobileLayoutContextTypes = {
  activeView: "builder" | "preview";
  toggleView: () => void;
};
 
const ViewSwitcherContext = createContext<MobileLayoutContextTypes>({} as any);
 
type ResponsiveViewSwitcherComponent = React.FC & {
  BuilderForm: React.FC;
  FormPreview: React.FC;
};
 
export const ResponsiveViewSwitcher = (({
  children,
}: {
  children: React.ReactNode;
}) => {
  const [activeView, setActiveView] = useState<"builder" | "preview">(
    "builder",
  );
 
  const toggleView = () => {
    setActiveView(activeView === "builder" ? "preview" : "builder");
  };
 
  return (
    <ViewSwitcherContext.Provider value={{ activeView, toggleView }}>
      {children}
    </ViewSwitcherContext.Provider>
  );
}) as ResponsiveViewSwitcherComponent;
 
export const useMobileLayoutHandler = () => useContext(ViewSwitcherContext);