SliderTooltip.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use client";
  2. import * as React from 'react';
  3. import { useRef } from 'react';
  4. import raf from "rc-util/es/raf";
  5. import { composeRef } from "rc-util/es/ref";
  6. import Tooltip from '../tooltip';
  7. const SliderTooltip = /*#__PURE__*/React.forwardRef((props, ref) => {
  8. const {
  9. open,
  10. draggingDelete,
  11. value
  12. } = props;
  13. const innerRef = useRef(null);
  14. const mergedOpen = open && !draggingDelete;
  15. const rafRef = useRef(null);
  16. function cancelKeepAlign() {
  17. raf.cancel(rafRef.current);
  18. rafRef.current = null;
  19. }
  20. function keepAlign() {
  21. rafRef.current = raf(() => {
  22. var _a;
  23. (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.forceAlign();
  24. rafRef.current = null;
  25. });
  26. }
  27. React.useEffect(() => {
  28. if (mergedOpen) {
  29. keepAlign();
  30. } else {
  31. cancelKeepAlign();
  32. }
  33. return cancelKeepAlign;
  34. }, [mergedOpen, props.title, value]);
  35. return /*#__PURE__*/React.createElement(Tooltip, Object.assign({
  36. ref: composeRef(innerRef, ref)
  37. }, props, {
  38. open: mergedOpen
  39. }));
  40. });
  41. if (process.env.NODE_ENV !== 'production') {
  42. SliderTooltip.displayName = 'SliderTooltip';
  43. }
  44. export default SliderTooltip;