winbox-ui-next
Version:
We Design Vue 2.0: A Vue.js 3 UI Library
76 lines (75 loc) • 2.34 kB
JavaScript
import { defineComponent, computed, resolveComponent, openBlock, createElementBlock, normalizeClass, renderSlot, createVNode, createCommentVNode } from "vue";
import { getPrefixCls } from "../_utils/global-config.js";
import { STATUSES } from "../_utils/constant.js";
import IconLink from "../icon/icon-link/index.js";
import { hasPropOrSlot } from "../_utils/use-prop-or-slot.js";
import _export_sfc from "../_virtual/plugin-vue_export-helper";
const _sfc_main = defineComponent({
name: "Link",
components: { IconLink },
props: {
href: String,
type: {
type: String,
default: "normal",
validator: (value) => {
return STATUSES.includes(value);
}
},
hoverable: {
type: Boolean,
default: false
},
icon: Boolean,
disabled: Boolean,
onClick: {
type: [Function, Array]
}
},
emits: ["click"],
setup(props, { slots, emit }) {
const prefixCls = getPrefixCls("link");
const showIcon = hasPropOrSlot(props, slots, "icon");
const handleClick = (ev) => {
if (!props.disabled) {
emit("click", ev);
}
};
const cls = computed(() => [
prefixCls,
`${prefixCls}-status-${props.type}`,
{
[`${prefixCls}-disabled`]: props.disabled,
[`${prefixCls}-hoverless`]: !props.hoverable,
[`${prefixCls}-with-icon`]: showIcon.value
}
]);
return {
cls,
prefixCls,
showIcon,
handleClick
};
}
});
const _hoisted_1 = ["href"];
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_icon_link = resolveComponent("icon-link");
return openBlock(), createElementBlock("a", {
href: _ctx.disabled ? void 0 : _ctx.href,
class: normalizeClass(_ctx.cls),
onClick: _cache[0] || (_cache[0] = (...args) => _ctx.handleClick && _ctx.handleClick(...args))
}, [
_ctx.showIcon ? (openBlock(), createElementBlock("span", {
key: 0,
class: normalizeClass(`${_ctx.prefixCls}-icon`)
}, [
renderSlot(_ctx.$slots, "icon", {}, () => [
createVNode(_component_icon_link)
])
], 2)) : createCommentVNode("v-if", true),
renderSlot(_ctx.$slots, "default")
], 10, _hoisted_1);
}
var _Link = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export { _Link as default };