diff --git a/src/Components/Curtains/Curtains.tsx b/src/Components/Curtains/Curtains.tsx index 12d6076..fb9eaf0 100644 --- a/src/Components/Curtains/Curtains.tsx +++ b/src/Components/Curtains/Curtains.tsx @@ -50,21 +50,38 @@ export function useCurtains(): CurtainsContextState return useContext(CurtainsContext); } + + /** - * Curtain callable. + * A generic callable curtain element. + */ +export type CallableCurtainElement = (...args: any) => React.ReactNode; + +/** + * A callable curtain function with typed parameters. + */ +export type CallableCurtain = (...args: Parameters) => CurtainUuidType; + +/** + * Callable curtain function generator. * @param curtains The curtains context state. * @param curtainElement The curtain element to open when called. */ -export function callableCurtain(curtains: CurtainsContextState, curtainElement: React.ReactNode): () => CurtainUuidType +export function callableCurtain(curtains: CurtainsContextState, curtainElement: React.ReactNode|F): CallableCurtain { - return () => curtains.open(curtainElement); + if (typeof curtainElement == "function") + // It's a callable curtain element, the callable curtain should be called with the same parameters. + return (...args: Parameters) => curtains.open(curtainElement(...args)); + else + // It's a simple element, just open it. + return () => curtains.open(curtainElement); } /** * Hook to create a simple curtain. * @param curtainElement Content of the curtain to open. */ -export function useCallableCurtain(curtainElement: React.ReactNode): () => CurtainUuidType +export function useCallableCurtain(curtainElement: React.ReactNode|F): CallableCurtain { // Get curtains context state. const curtains = useCurtains();