useSticky.js 758 B

12345678910111213141516171819202122232425
  1. import canUseDom from '../../_util/canUseDom';
  2. import { computed } from 'vue';
  3. // fix ssr render
  4. const defaultContainer = canUseDom() ? window : null;
  5. /** Sticky header hooks */
  6. export default function useSticky(stickyRef, prefixClsRef) {
  7. return computed(() => {
  8. const {
  9. offsetHeader = 0,
  10. offsetSummary = 0,
  11. offsetScroll = 0,
  12. getContainer = () => defaultContainer
  13. } = typeof stickyRef.value === 'object' ? stickyRef.value : {};
  14. const container = getContainer() || defaultContainer;
  15. const isSticky = !!stickyRef.value;
  16. return {
  17. isSticky,
  18. stickyClassName: isSticky ? `${prefixClsRef.value}-sticky-holder` : '',
  19. offsetHeader,
  20. offsetSummary,
  21. offsetScroll,
  22. container
  23. };
  24. });
  25. }