UNPKG

@opensig/opendesign

Version:

90 lines (89 loc) 3.04 kB
"use strict"; const vue = require("vue"); require("../config-provider/index.js"); const global = require("../_utils/global.js"); const icons = require("../_utils/icons.js"); const types = require("./types.js"); const provide = require("../config-provider/provide.js"); const _sfc_main = /* @__PURE__ */ vue.defineComponent({ __name: "OLink", props: types.linkProps, emits: ["click"], setup(__props, { emit: __emit }) { const props = __props; const configProvider = vue.inject(provide.configProviderInjectKey, {}); const $attr = vue.useAttrs(); const emits = __emit; const onClick = (e) => { var _a; if (props.disabled || props.loading) { e.preventDefault(); return; } emits("click", e); if (props.global) { (_a = configProvider.link) == null ? void 0 : _a.click(e, props, $attr); } }; const linkClass = vue.computed(() => [ { "o-link-disabled": props.disabled, "o-link-hover-bg": props.hoverBg, "o-link-hover-underline": props.hoverUnderline }, `o-link-${props.color}`, `o-link-${props.size || global.defaultSize}` ]); const $slots = vue.useSlots(); const RouterLink = vue.resolveComponent("RouterLink"); const prefix = () => { const children = []; if (props.loading) { children.push(vue.h(icons.IconLoading.value, { class: "o-rotating" })); } else if ($slots.icon || props.icon) { children.push(vue.renderSlot($slots, "icon", {}, () => props.icon ? [vue.h(props.icon)] : [])); } if (children.length) { return vue.h("span", { class: "o-link-prefix" }, children); } return null; }; const main = () => { const children = []; const slotVnode = vue.renderSlot($slots, "default"); if (props.hoverUnderline) { children.push(vue.h("span", { class: "o-link-label" }, slotVnode)); } else { children.push(slotVnode); } return vue.h("span", { class: "o-link-main" }, children); }; const suffix = () => { if ($slots.suffix || props.suffix) { return vue.h( "span", { class: "o-link-suffix" }, vue.renderSlot($slots, "suffix", {}, () => props.suffix ? [vue.h(icons.IconLinkArrow.value, { class: "o-link-icon-arrow" })] : []) ); } return null; }; const Link = () => { const _props = { ...$attr, class: ["o-link", linkClass.value], onClick }; if (props.to && RouterLink) { _props.to = props.to; _props.replace = props.replace; return vue.h(RouterLink, _props, { default: () => [prefix(), main(), suffix()] }); } if (props.tag === "a") { _props.href = props.href; _props.target = props.target; } return vue.h(props.tag, _props, { default: () => [prefix(), main(), suffix()] }); }; return (_ctx, _cache) => { return vue.openBlock(), vue.createBlock(Link); }; } }); module.exports = _sfc_main;