react-hooks-global-scrollspy
Version:
React Hook for managing navigation by scroll position
26 lines (25 loc) • 1.37 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { jsx as _jsx } from "react/jsx-runtime";
import { GlobalScrollSpyContext } from './GlobalScrollSpyContext';
import { useScrollSpy } from "./useScrollSpy";
/**
* @param ScrollSpyParams Optional params
* @param ScrollSpyParams.offsetPx Distance from Y coordinate of the base (px)
* @param ScrollSpyParams.throttleMs Interval of update processing (ms)
* @returns ScrollSpyProvider - This Provider components provides useScrollSpy return value descendants of this Provider
*/
export var GlobalScrollSpyProvider = function (_a) {
var _b = _a === void 0 ? {} : _a, children = _b.children, _c = _b.offsetPx, offsetPx = _c === void 0 ? 0 : _c, _d = _b.throttleMs, throttleMs = _d === void 0 ? 50 : _d;
var _e = useScrollSpy({ offsetPx: offsetPx, throttleMs: throttleMs }), activeElement = _e[0], actions = _e[1];
return (_jsx(GlobalScrollSpyContext.Provider, __assign({ value: { activeElement: activeElement, actions: actions } }, { children: children }), void 0));
};