zmp-vue
Version:
Build full featured iOS & Android apps using ZMP & Vue
147 lines (128 loc) • 5.08 kB
JavaScript
;
exports.__esModule = true;
exports.default = void 0;
var _vue = require("vue");
var _utils = require("../shared/utils");
var _mixins = require("../shared/mixins");
var _useIcon = require("../shared/use-icon");
var _useRouteProps = require("../shared/use-route-props");
var _useTooltip = require("../shared/use-tooltip");
var _useSmartSelect = require("../shared/use-smart-select");
var _badge = _interopRequireDefault(require("./badge"));
var _useIcon2 = _interopRequireDefault(require("./use-icon"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function render(_ctx, _cache) {
var _component_zmp_use_icon = (0, _vue.resolveComponent)("zmp-use-icon");
var _component_zmp_badge = (0, _vue.resolveComponent)("zmp-badge");
return (0, _vue.openBlock)(), (0, _vue.createBlock)("a", (0, _vue.mergeProps)({
ref: "elRef",
class: _ctx.classes
}, _ctx.attrs), [_ctx.icon ? ((0, _vue.openBlock)(), (0, _vue.createBlock)(_component_zmp_use_icon, {
key: 0,
icon: _ctx.icon
}, null, 8, ["icon"])) : (0, _vue.createCommentVNode)("", true), _ctx.text ? ((0, _vue.openBlock)(), (0, _vue.createBlock)("span", {
key: 1,
class: _ctx.isTabbarLabel ? 'tabbar-label' : ''
}, [(0, _vue.createTextVNode)((0, _vue.toDisplayString)(_ctx.text) + " ", 1), _ctx.badge ? ((0, _vue.openBlock)(), (0, _vue.createBlock)(_component_zmp_badge, {
key: 0,
color: _ctx.badgeColor
}, {
default: (0, _vue.withCtx)(function () {
return [(0, _vue.createTextVNode)((0, _vue.toDisplayString)(_ctx.badge), 1)];
}),
_: 1
}, 8, ["color"])) : (0, _vue.createCommentVNode)("", true)], 2)) : (0, _vue.createCommentVNode)("", true), (0, _vue.renderSlot)(_ctx.$slots, "default")], 16);
}
var _default = {
name: 'zmp-link',
render: render,
components: {
zmpBadge: _badge.default,
zmpUseIcon: _useIcon2.default
},
props: _extends({
noLinkClass: Boolean,
text: String,
tabLink: [Boolean, String],
tabLinkActive: Boolean,
tabbarLabel: Boolean,
iconOnly: Boolean,
badge: [String, Number],
badgeColor: [String],
href: {
type: [String, Boolean],
default: '#'
},
target: String,
tooltip: String,
tooltipTrigger: String,
smartSelect: Boolean,
smartSelectParams: Object
}, _mixins.iconProps, _mixins.colorProps, _mixins.actionsProps, _mixins.routerProps),
setup: function setup(props, _ref) {
var slots = _ref.slots;
var elRef = (0, _vue.ref)(null);
var zmpSmartSelect = null;
(0, _useTooltip.useTooltip)(elRef, props);
(0, _useRouteProps.useRouteProps)(elRef, props);
(0, _useSmartSelect.useSmartSelect)(props, function (instance) {
zmpSmartSelect = instance;
}, function () {
return elRef.value;
});
var TabbarContext = (0, _vue.inject)('TabbarContext', {
value: {}
});
var isTabbarLabel = (0, _vue.computed)(function () {
return props.tabbarLabel || TabbarContext.value.tabbarHasLabels;
});
var attrs = (0, _vue.computed)(function () {
var href = props.href,
tabLink = props.tabLink,
target = props.target;
var hrefComputed = href;
if (href === true) hrefComputed = '#';
if (href === false) hrefComputed = undefined; // no href attribute
return _extends({
href: hrefComputed,
target: target,
'data-tab': (0, _utils.isStringProp)(tabLink) && tabLink || undefined
}, (0, _mixins.routerAttrs)(props), (0, _mixins.actionsAttrs)(props));
});
var classes = (0, _vue.computed)(function () {
var iconOnly = props.iconOnly,
text = props.text,
noLinkClass = props.noLinkClass,
tabLink = props.tabLink,
tabLinkActive = props.tabLinkActive,
smartSelect = props.smartSelect;
var iconOnlyComputed;
var hasChildren = slots && slots.default;
if (iconOnly || !text && !hasChildren) {
iconOnlyComputed = true;
} else {
iconOnlyComputed = false;
}
return (0, _utils.classNames)({
link: !(noLinkClass || isTabbarLabel.value),
'icon-only': iconOnlyComputed,
'tab-link': tabLink || tabLink === '',
'tab-link-active': tabLinkActive,
'smart-select': smartSelect
}, (0, _mixins.colorClasses)(props), (0, _mixins.routerClasses)(props), (0, _mixins.actionsClasses)(props));
});
var icon = (0, _vue.computed)(function () {
return (0, _useIcon.useIcon)(props);
});
return {
elRef: elRef,
icon: icon,
isTabbarLabel: isTabbarLabel,
attrs: attrs,
classes: classes,
zmpSmartSelect: zmpSmartSelect
};
}
};
exports.default = _default;