Files
nostrudel/src/components/note/expanded.tsx
2023-03-04 16:22:10 -06:00

20 lines
708 B
TypeScript

import { useDisclosure } from "@chakra-ui/react";
import React, { PropsWithChildren, useContext, useMemo } from "react";
type ContextType = { expanded: boolean; onExpand: () => void; onCollapse: () => void; onToggle: () => void };
const ExpandedContext = React.createContext<ContextType | undefined>(undefined);
export function useExpand() {
const ctx = useContext(ExpandedContext);
return ctx;
}
export function ExpandProvider({ children }: PropsWithChildren) {
const { isOpen: expanded, onOpen: onExpand, onClose: onCollapse, onToggle } = useDisclosure();
return (
<ExpandedContext.Provider value={{ expanded, onExpand, onCollapse, onToggle }}>{children}</ExpandedContext.Provider>
);
}