SliderTooltip.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import { createVNode as _createVNode, resolveDirective as _resolveDirective } from "vue";
  3. import { onBeforeUnmount, watch, onActivated, defineComponent, ref } from 'vue';
  4. import Tooltip, { tooltipProps } from '../tooltip';
  5. import raf from '../_util/raf';
  6. export default defineComponent({
  7. compatConfig: {
  8. MODE: 3
  9. },
  10. name: 'SliderTooltip',
  11. inheritAttrs: false,
  12. props: tooltipProps(),
  13. setup(props, _ref) {
  14. let {
  15. attrs,
  16. slots
  17. } = _ref;
  18. const innerRef = ref(null);
  19. const rafRef = ref(null);
  20. function cancelKeepAlign() {
  21. raf.cancel(rafRef.value);
  22. rafRef.value = null;
  23. }
  24. function keepAlign() {
  25. rafRef.value = raf(() => {
  26. var _a;
  27. (_a = innerRef.value) === null || _a === void 0 ? void 0 : _a.forcePopupAlign();
  28. rafRef.value = null;
  29. });
  30. }
  31. const align = () => {
  32. cancelKeepAlign();
  33. if (props.open) {
  34. keepAlign();
  35. }
  36. };
  37. watch([() => props.open, () => props.title], () => {
  38. align();
  39. }, {
  40. flush: 'post',
  41. immediate: true
  42. });
  43. onActivated(() => {
  44. align();
  45. });
  46. onBeforeUnmount(() => {
  47. cancelKeepAlign();
  48. });
  49. return () => {
  50. return _createVNode(Tooltip, _objectSpread(_objectSpread({
  51. "ref": innerRef
  52. }, props), attrs), slots);
  53. };
  54. }
  55. });