content2.mjs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { defineComponent, inject, ref, computed, unref, watch, onMounted, provide, openBlock, createElementBlock, normalizeStyle, normalizeClass, renderSlot, createVNode, withCtx, Fragment, createTextVNode, toDisplayString, createCommentVNode } from 'vue';
  2. import { offset } from '@floating-ui/dom';
  3. import ElVisuallyHidden from '../../visual-hidden/src/visual-hidden2.mjs';
  4. import { tooltipV2RootKey, tooltipV2ContentKey } from './constants.mjs';
  5. import { tooltipV2ContentProps } from './content.mjs';
  6. import { tooltipV2CommonProps } from './common.mjs';
  7. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  8. import { useFloating, arrowMiddleware } from '../../../hooks/use-floating/index.mjs';
  9. import { useZIndex } from '../../../hooks/use-z-index/index.mjs';
  10. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  11. const __default__ = defineComponent({
  12. name: "ElTooltipV2Content"
  13. });
  14. const _sfc_main = /* @__PURE__ */ defineComponent({
  15. ...__default__,
  16. props: { ...tooltipV2ContentProps, ...tooltipV2CommonProps },
  17. setup(__props) {
  18. const props = __props;
  19. const { triggerRef, contentId } = inject(tooltipV2RootKey);
  20. const placement = ref(props.placement);
  21. const strategy = ref(props.strategy);
  22. const arrowRef = ref(null);
  23. const { referenceRef, contentRef, middlewareData, x, y, update } = useFloating({
  24. placement,
  25. strategy,
  26. middleware: computed(() => {
  27. const middleware = [offset(props.offset)];
  28. if (props.showArrow) {
  29. middleware.push(arrowMiddleware({
  30. arrowRef
  31. }));
  32. }
  33. return middleware;
  34. })
  35. });
  36. const zIndex = useZIndex().nextZIndex();
  37. const ns = useNamespace("tooltip-v2");
  38. const side = computed(() => {
  39. return placement.value.split("-")[0];
  40. });
  41. const contentStyle = computed(() => {
  42. return {
  43. position: unref(strategy),
  44. top: `${unref(y) || 0}px`,
  45. left: `${unref(x) || 0}px`,
  46. zIndex
  47. };
  48. });
  49. const arrowStyle = computed(() => {
  50. if (!props.showArrow)
  51. return {};
  52. const { arrow } = unref(middlewareData);
  53. return {
  54. [`--${ns.namespace.value}-tooltip-v2-arrow-x`]: `${arrow == null ? void 0 : arrow.x}px` || "",
  55. [`--${ns.namespace.value}-tooltip-v2-arrow-y`]: `${arrow == null ? void 0 : arrow.y}px` || ""
  56. };
  57. });
  58. const contentClass = computed(() => [
  59. ns.e("content"),
  60. ns.is("dark", props.effect === "dark"),
  61. ns.is(unref(strategy)),
  62. props.contentClass
  63. ]);
  64. watch(arrowRef, () => update());
  65. watch(() => props.placement, (val) => placement.value = val);
  66. onMounted(() => {
  67. watch(() => props.reference || triggerRef.value, (el) => {
  68. referenceRef.value = el || void 0;
  69. }, {
  70. immediate: true
  71. });
  72. });
  73. provide(tooltipV2ContentKey, { arrowRef });
  74. return (_ctx, _cache) => {
  75. return openBlock(), createElementBlock("div", {
  76. ref_key: "contentRef",
  77. ref: contentRef,
  78. style: normalizeStyle(unref(contentStyle)),
  79. "data-tooltip-v2-root": ""
  80. }, [
  81. !_ctx.nowrap ? (openBlock(), createElementBlock("div", {
  82. key: 0,
  83. "data-side": unref(side),
  84. class: normalizeClass(unref(contentClass))
  85. }, [
  86. renderSlot(_ctx.$slots, "default", {
  87. contentStyle: unref(contentStyle),
  88. contentClass: unref(contentClass)
  89. }),
  90. createVNode(unref(ElVisuallyHidden), {
  91. id: unref(contentId),
  92. role: "tooltip"
  93. }, {
  94. default: withCtx(() => [
  95. _ctx.ariaLabel ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
  96. createTextVNode(toDisplayString(_ctx.ariaLabel), 1)
  97. ], 64)) : renderSlot(_ctx.$slots, "default", { key: 1 })
  98. ]),
  99. _: 3
  100. }, 8, ["id"]),
  101. renderSlot(_ctx.$slots, "arrow", {
  102. style: normalizeStyle(unref(arrowStyle)),
  103. side: unref(side)
  104. })
  105. ], 10, ["data-side"])) : createCommentVNode("v-if", true)
  106. ], 4);
  107. };
  108. }
  109. });
  110. var TooltipV2Content = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "content.vue"]]);
  111. export { TooltipV2Content as default };
  112. //# sourceMappingURL=content2.mjs.map