Blame view

天文台pc/tianwentai-ui/node_modules/@mui/material/Tabs/ScrollbarSize.js 2.04 KB
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  "use strict";
  'use client';
  
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = ScrollbarSize;
  var React = _interopRequireWildcard(require("react"));
  var _propTypes = _interopRequireDefault(require("prop-types"));
  var _debounce = _interopRequireDefault(require("../utils/debounce"));
  var _utils = require("../utils");
  var _jsxRuntime = require("react/jsx-runtime");
  const styles = {
    width: 99,
    height: 99,
    position: 'absolute',
    top: -9999,
    overflow: 'scroll'
  };
  
  /**
   * @ignore - internal component.
   * The component originates from https://github.com/STORIS/react-scrollbar-size.
   * It has been moved into the core in order to minimize the bundle size.
   */
  function ScrollbarSize(props) {
    const {
      onChange,
      ...other
    } = props;
    const scrollbarHeight = React.useRef();
    const nodeRef = React.useRef(null);
    const setMeasurements = () => {
      scrollbarHeight.current = nodeRef.current.offsetHeight - nodeRef.current.clientHeight;
    };
    (0, _utils.unstable_useEnhancedEffect)(() => {
      const handleResize = (0, _debounce.default)(() => {
        const prevHeight = scrollbarHeight.current;
        setMeasurements();
        if (prevHeight !== scrollbarHeight.current) {
          onChange(scrollbarHeight.current);
        }
      });
      const containerWindow = (0, _utils.ownerWindow)(nodeRef.current);
      containerWindow.addEventListener('resize', handleResize);
      return () => {
        handleResize.clear();
        containerWindow.removeEventListener('resize', handleResize);
      };
    }, [onChange]);
    React.useEffect(() => {
      setMeasurements();
      onChange(scrollbarHeight.current);
    }, [onChange]);
    return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      style: styles,
      ...other,
      ref: nodeRef
    });
  }
  process.env.NODE_ENV !== "production" ? ScrollbarSize.propTypes = {
    onChange: _propTypes.default.func.isRequired
  } : void 0;