content2.mjs 4.5 KB

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