UNPKG

hiding-header-react

Version:
38 lines (35 loc) 2.49 kB
"use client"; import { jsx } from 'react/jsx-runtime'; import { hidingHeader } from 'hiding-header'; import { createContext, useContext, useRef, useState, useEffect } from 'react'; var Context = createContext(undefined); var useHidingHeader = function () { return useContext(Context); }; var useRunHidingHeader = function () { var _a; return (_a = useContext(Context)) === null || _a === void 0 ? void 0 : _a.run; }; var usePauseHidingHeader = function () { var _a; return (_a = useContext(Context)) === null || _a === void 0 ? void 0 : _a.pause; }; var useRevealHidingHeader = function () { var _a; return (_a = useContext(Context)) === null || _a === void 0 ? void 0 : _a.reveal; }; var useHideHidingHeader = function () { var _a; return (_a = useContext(Context)) === null || _a === void 0 ? void 0 : _a.hide; }; var HidingHeader = function (_a) { var children = _a.children, _b = _a.className, className = _b === void 0 ? 'hidingHeader' : _b, _c = _a.innerClassName, innerClassName = _c === void 0 ? 'hidingHeader-in' : _c, _d = _a.component, Tag = _d === void 0 ? 'div' : _d, // hiding-header options heightPropertyName = _a.heightPropertyName, boundsHeightPropertyName = _a.boundsHeightPropertyName, animationOffsetPropertyName = _a.animationOffsetPropertyName, snap = _a.snap, onHeightChange = _a.onHeightChange, onVisibleHeightChange = _a.onVisibleHeightChange, onHomeChange = _a.onHomeChange; var container = useRef(null); var _e = useState(), hidingHeaderInstance = _e[0], setHidingHeaderInstance = _e[1]; useEffect(function () { var instance = hidingHeader(container.current, { heightPropertyName: heightPropertyName, boundsHeightPropertyName: boundsHeightPropertyName, animationOffsetPropertyName: animationOffsetPropertyName, snap: snap, onHeightChange: onHeightChange, onVisibleHeightChange: onVisibleHeightChange, onHomeChange: onHomeChange, }); setHidingHeaderInstance(instance); return function () { instance.destroy(); }; }, []); return (jsx(Tag, { className: className, ref: container, children: jsx("div", { className: innerClassName, children: jsx(Context.Provider, { value: hidingHeaderInstance, children: children }) }) })); }; export { HidingHeader, useHideHidingHeader, useHidingHeader, usePauseHidingHeader, useRevealHidingHeader, useRunHidingHeader }; //# sourceMappingURL=HidingHeader.js.map