UNPKG

yuang-framework-ui-pc

Version:

yuang-framework-ui-pc Library

73 lines (72 loc) 2.22 kB
import { defineComponent, inject, watch, createElementBlock, openBlock, createElementVNode, renderSlot } from "vue"; import { useTimer } from "../utils/hook"; import { TOOLBAR_KEY } from "../ele-toolbar/props"; import { toolEmits, toolProps } from "./props"; const _sfc_main = defineComponent({ name: "EleTool", props: toolProps, emits: toolEmits, setup(props, { emit }) { const toolbarProvide = inject(TOOLBAR_KEY, {}); const [startHideTipTimer, stopHideTipTimer] = useTimer(200); const showTooltip = (text, el, options) => { if (toolbarProvide.showTooltip) { toolbarProvide.showTooltip(text, el, options); } }; const hideTooltip = () => { toolbarProvide.hideTooltip && toolbarProvide.hideTooltip(); }; const handleClick = (e) => { if (props.clickHideTooltip) { startHideTipTimer(() => { hideTooltip(); }); } emit("click", e); }; const handleMouseover = (e) => { if (props.title && !props.disabled) { stopHideTipTimer(); showTooltip(props.title, e.currentTarget, { placement: props.placement, offset: 10 }); } }; watch([() => props.disabled, () => props.title], () => { if (!props.title || props.disabled) { hideTooltip(); } }); return { handleClick, handleMouseover, showTooltip, hideTooltip }; } }); const _export_sfc = (sfc, props) => { const target = sfc.__vccOpts || sfc; for (const [key, val] of props) { target[key] = val; } return target; }; const _hoisted_1 = { class: "ele-tool-body" }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return openBlock(), createElementBlock("div", { class: "ele-tool", onClick: _cache[0] || (_cache[0] = (...args) => _ctx.handleClick && _ctx.handleClick(...args)), onMouseover: _cache[1] || (_cache[1] = (...args) => _ctx.handleMouseover && _ctx.handleMouseover(...args)) }, [ createElementVNode("div", _hoisted_1, [ renderSlot(_ctx.$slots, "default") ]) ], 32); } const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); export { index as default };