mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-10-10 12:53:14 +02:00
20 lines
708 B
TypeScript
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>
|
|
);
|
|
}
|