element-plus
Version:
A Component Library for Vue 3
1 lines • 10.1 kB
Source Map (JSON)
{"version":3,"file":"tooltip.vue2.mjs","sources":["../../../../../../packages/components/tooltip/src/tooltip.vue"],"sourcesContent":["<template>\n <el-popper ref=\"popperRef\" :role=\"role\">\n <el-tooltip-trigger\n :disabled=\"disabled\"\n :trigger=\"trigger\"\n :trigger-keys=\"triggerKeys\"\n :virtual-ref=\"virtualRef\"\n :virtual-triggering=\"virtualTriggering\"\n :focus-on-target=\"focusOnTarget\"\n >\n <slot v-if=\"$slots.default\" />\n </el-tooltip-trigger>\n <el-tooltip-content\n ref=\"contentRef\"\n :aria-label=\"ariaLabel\"\n :boundaries-padding=\"boundariesPadding\"\n :content=\"content\"\n :disabled=\"disabled\"\n :effect=\"effect\"\n :enterable=\"enterable\"\n :fallback-placements=\"fallbackPlacements\"\n :hide-after=\"hideAfter\"\n :gpu-acceleration=\"gpuAcceleration\"\n :offset=\"offset\"\n :persistent=\"persistent\"\n :popper-class=\"kls\"\n :popper-style=\"popperStyle\"\n :placement=\"placement\"\n :popper-options=\"popperOptions\"\n :arrow-offset=\"arrowOffset\"\n :pure=\"pure\"\n :raw-content=\"rawContent\"\n :reference-el=\"referenceEl\"\n :trigger-target-el=\"triggerTargetEl\"\n :show-after=\"showAfter\"\n :strategy=\"strategy\"\n :teleported=\"teleported\"\n :transition=\"transition\"\n :virtual-triggering=\"virtualTriggering\"\n :z-index=\"zIndex\"\n :append-to=\"appendTo\"\n :loop=\"loop\"\n >\n <slot name=\"content\">\n <span v-if=\"rawContent\" v-html=\"content\" />\n <span v-else>{{ content }}</span>\n </slot>\n <el-popper-arrow v-if=\"showArrow\" />\n </el-tooltip-content>\n </el-popper>\n</template>\n\n<script lang=\"ts\" setup>\nimport {\n computed,\n onBeforeUnmount,\n onDeactivated,\n provide,\n readonly,\n ref,\n toRef,\n unref,\n watch,\n} from 'vue'\nimport {\n ElPopper,\n ElPopperArrow,\n popperArrowPropsDefaults,\n} from '@element-plus/components/popper'\nimport { isBoolean } from '@element-plus/utils'\nimport {\n useDelayedToggle,\n useId,\n useNamespace,\n usePopperContainer,\n} from '@element-plus/hooks'\nimport { TOOLTIP_INJECTION_KEY } from './constants'\nimport { tooltipEmits, useTooltipModelToggle } from './tooltip'\nimport ElTooltipTrigger from './trigger.vue'\nimport ElTooltipContent from './content.vue'\nimport { useTooltipContentPropsDefaults } from './content'\nimport { useTooltipTriggerPropsDefaults } from './trigger'\n\nimport type { Mutable } from '@element-plus/utils'\nimport type { TooltipContentInstance } from './content'\nimport type { UseTooltipProps } from './tooltip'\nimport type { PopperInstance } from '@element-plus/components/popper'\n\ndefineOptions({\n name: 'ElTooltip',\n})\n\nconst props = withDefaults(defineProps<UseTooltipProps>(), {\n role: 'tooltip',\n ...useTooltipContentPropsDefaults,\n ...useTooltipTriggerPropsDefaults,\n ...popperArrowPropsDefaults,\n showArrow: true,\n})\nconst emit = defineEmits(tooltipEmits as Mutable<typeof tooltipEmits>)\n\nusePopperContainer()\n\nconst ns = useNamespace('tooltip')\nconst id = useId()\nconst popperRef = ref<PopperInstance>()\nconst contentRef = ref<TooltipContentInstance>()\n\nconst updatePopper = () => {\n const popperComponent = unref(popperRef)\n if (popperComponent) {\n popperComponent.popperInstanceRef?.update()\n }\n}\nconst open = ref(false)\nconst toggleReason = ref<Event>()\n\nconst { show, hide, hasUpdateHandler } = useTooltipModelToggle({\n indicator: open,\n toggleReason,\n})\n\nconst { onOpen, onClose } = useDelayedToggle({\n showAfter: toRef(props, 'showAfter'),\n hideAfter: toRef(props, 'hideAfter'),\n autoClose: toRef(props, 'autoClose'),\n open: show,\n close: hide,\n})\n\nconst controlled = computed(\n () => isBoolean(props.visible) && !hasUpdateHandler.value\n)\n\nconst kls = computed(() => {\n return [ns.b(), props.popperClass!]\n})\n\nprovide(TOOLTIP_INJECTION_KEY, {\n controlled,\n id,\n open: readonly(open),\n trigger: toRef(props, 'trigger'),\n onOpen,\n onClose,\n onToggle: (event?: Event) => {\n if (unref(open)) {\n onClose(event)\n } else {\n onOpen(event)\n }\n },\n onShow: () => {\n emit('show', toggleReason.value)\n },\n onHide: () => {\n emit('hide', toggleReason.value)\n },\n onBeforeShow: () => {\n emit('before-show', toggleReason.value)\n },\n onBeforeHide: () => {\n emit('before-hide', toggleReason.value)\n },\n updatePopper,\n})\n\nwatch(\n () => props.disabled,\n (disabled) => {\n if (disabled && open.value) {\n open.value = false\n }\n }\n)\n\nconst isFocusInsideContent = (event?: FocusEvent) => {\n return contentRef.value?.isFocusInsideContent(event)\n}\n\nonDeactivated(() => open.value && hide())\n\nonBeforeUnmount(() => {\n toggleReason.value = undefined\n})\n\ndefineExpose({\n /**\n * @description el-popper component instance\n */\n popperRef,\n /**\n * @description el-tooltip-content component instance\n */\n contentRef,\n /**\n * @description validate current focus event is trigger inside el-tooltip-content\n */\n isFocusInsideContent,\n /**\n * @description update el-popper component instance\n */\n updatePopper,\n /**\n * @description expose onOpen function to mange el-tooltip open state\n */\n onOpen,\n /**\n * @description expose onClose function to manage el-tooltip close state\n */\n onClose,\n /**\n * @description expose hide function\n */\n hide,\n})\n</script>\n"],"names":["_createBlock","_unref","_createVNode","ElTooltipTrigger","$slots","_renderSlot","ElTooltipContent","_createElementBlock","_openBlock","ElPopperArrow"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA4FA,IAAA,MAAM,KAAA,GAAQ,OAAA;AAOd,IAAA,MAAM,IAAA,GAAO,MAAA;AAEb,IAAA,kBAAA,EAAmB;AAEnB,IAAA,MAAM,EAAA,GAAK,aAAa,SAAS,CAAA;AACjC,IAAA,MAAM,KAAK,KAAA,EAAM;AACjB,IAAA,MAAM,YAAY,GAAA,EAAoB;AACtC,IAAA,MAAM,aAAa,GAAA,EAA4B;AAE/C,IAAA,MAAM,eAAe,MAAM;;AACzB,MAAA,MAAM,eAAA,GAAkB,MAAM,SAAS,CAAA;AACvC,MAAA,IAAI,eAAA,EAAiB;AACnB,QAAA,CAAA,EAAA,GAAA,eAAA,CAAgB,sBAAh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