UNPKG

2.48 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4var _typeof3 = require("@babel/runtime/helpers/typeof");
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.default = useSticky;
9var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
10var React = _interopRequireWildcard(require("react"));
11var _canUseDom = _interopRequireDefault(require("rc-util/lib/Dom/canUseDom"));
12function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
13function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14// fix ssr render
15var defaultContainer = (0, _canUseDom.default)() ? window : null;
16
17/** Sticky header hooks */
18function useSticky(sticky, prefixCls) {
19 var _ref = (0, _typeof2.default)(sticky) === 'object' ? sticky : {},
20 _ref$offsetHeader = _ref.offsetHeader,
21 offsetHeader = _ref$offsetHeader === void 0 ? 0 : _ref$offsetHeader,
22 _ref$offsetSummary = _ref.offsetSummary,
23 offsetSummary = _ref$offsetSummary === void 0 ? 0 : _ref$offsetSummary,
24 _ref$offsetScroll = _ref.offsetScroll,
25 offsetScroll = _ref$offsetScroll === void 0 ? 0 : _ref$offsetScroll,
26 _ref$getContainer = _ref.getContainer,
27 getContainer = _ref$getContainer === void 0 ? function () {
28 return defaultContainer;
29 } : _ref$getContainer;
30 var container = getContainer() || defaultContainer;
31 return React.useMemo(function () {
32 var isSticky = !!sticky;
33 return {
34 isSticky: isSticky,
35 stickyClassName: isSticky ? "".concat(prefixCls, "-sticky-holder") : '',
36 offsetHeader: offsetHeader,
37 offsetSummary: offsetSummary,
38 offsetScroll: offsetScroll,
39 container: container
40 };
41 }, [offsetScroll, offsetHeader, offsetSummary, prefixCls, container]);
42}
\No newline at end of file