@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
27 lines (26 loc) • 880 B
JavaScript
"use client";
import { createContext, use, useCallback, useEffect, useMemo, useState } from "react";
//#region src/base-ui/Drawer/DrawerPushContext.tsx
const DrawerPushContext = createContext(null);
const DrawerPushProvider = DrawerPushContext.Provider;
const useDrawerPush = (open) => {
const parent = use(DrawerPushContext);
const [pushedCount, setPushedCount] = useState(0);
const push = useCallback(() => setPushedCount((count) => count + 1), []);
const pull = useCallback(() => setPushedCount((count) => Math.max(0, count - 1)), []);
useEffect(() => {
if (!open || !parent) return;
parent.push();
return () => parent.pull();
}, [open, parent]);
return {
childValue: useMemo(() => ({
pull,
push
}), [pull, push]),
pushed: pushedCount > 0
};
};
//#endregion
export { DrawerPushProvider, useDrawerPush };
//# sourceMappingURL=DrawerPushContext.mjs.map