Files
video-gen/video-gen-admin/node_modules/@rc-component/table/es/hooks/useSticky.js
T
2026-05-25 17:08:18 +08:00

26 lines
797 B
JavaScript

import * as React from 'react';
import canUseDom from "@rc-component/util/es/Dom/canUseDom";
// fix ssr render
const defaultContainer = canUseDom() ? window : null;
/** Sticky header hooks */
export default function useSticky(sticky, prefixCls) {
const {
offsetHeader = 0,
offsetSummary = 0,
offsetScroll = 0,
getContainer = () => defaultContainer
} = typeof sticky === 'object' ? sticky : {};
const container = getContainer() || defaultContainer;
const isSticky = !!sticky;
return React.useMemo(() => {
return {
isSticky,
stickyClassName: isSticky ? `${prefixCls}-sticky-holder` : '',
offsetHeader,
offsetSummary,
offsetScroll,
container
};
}, [isSticky, offsetScroll, offsetHeader, offsetSummary, prefixCls, container]);
}