UNPKG

framework7-vue

Version:

Build full featured iOS & Android apps using Framework7 & Vue

128 lines 4.33 kB
import { resolveComponent as _resolveComponent, openBlock as _openBlock, createBlock as _createBlock, createCommentVNode as _createCommentVNode, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, withCtx as _withCtx, normalizeClass as _normalizeClass, createElementBlock as _createElementBlock, renderSlot as _renderSlot, mergeProps as _mergeProps } from "vue"; function render(_ctx, _cache) { const _component_f7_use_icon = _resolveComponent("f7-use-icon"); const _component_f7_badge = _resolveComponent("f7-badge"); return _openBlock(), _createElementBlock("a", _mergeProps({ ref: "elRef", class: _ctx.classes }, _ctx.attrs), [_ctx.icon ? (_openBlock(), _createBlock(_component_f7_use_icon, { key: 0, icon: _ctx.icon }, null, 8, ["icon"])) : _createCommentVNode("", true), _ctx.text ? (_openBlock(), _createElementBlock("span", { key: 1, class: _normalizeClass(_ctx.isTabbarIcons ? 'tabbar-label' : '') }, [_createTextVNode(_toDisplayString(_ctx.text) + " ", 1), _ctx.badge ? (_openBlock(), _createBlock(_component_f7_badge, { key: 0, color: _ctx.badgeColor }, { default: _withCtx(() => [_createTextVNode(_toDisplayString(_ctx.badge), 1)]), _: 1 }, 8, ["color"])) : _createCommentVNode("", true)], 2)) : _createCommentVNode("", true), _renderSlot(_ctx.$slots, "default")], 16); } import { computed, ref, inject } from 'vue'; import { classNames, isStringProp } from '../shared/utils.js'; import { colorClasses, routerAttrs, routerClasses, actionsAttrs, actionsClasses, colorProps, actionsProps, routerProps, iconProps } from '../shared/mixins.js'; import { useIcon } from '../shared/use-icon.js'; import { useRouteProps } from '../shared/use-route-props.js'; import { useTooltip } from '../shared/use-tooltip.js'; import { useSmartSelect } from '../shared/use-smart-select.js'; import f7Badge from './badge.js'; import f7UseIcon from './use-icon.js'; export default { name: 'f7-link', render, components: { f7Badge, f7UseIcon }, props: { 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, ...iconProps, ...colorProps, ...actionsProps, ...routerProps }, setup(props, { slots }) { const elRef = ref(null); let f7SmartSelect = null; useTooltip(elRef, props); useRouteProps(elRef, props); useSmartSelect(props, instance => { f7SmartSelect = instance; }, () => { return elRef.value; }); const TabbarContext = inject('TabbarContext', { value: {} }); const isTabbarIcons = computed(() => props.tabbarLabel || TabbarContext.value.tabbarHasIcons); const attrs = computed(() => { const { href, tabLink, target } = props; let hrefComputed = href; if (href === true) hrefComputed = '#'; if (href === false) hrefComputed = undefined; // no href attribute return { href: hrefComputed, target, 'data-tab': isStringProp(tabLink) && tabLink || undefined, ...routerAttrs(props), ...actionsAttrs(props) }; }); const classes = computed(() => { const { iconOnly, text, noLinkClass, tabLink, tabLinkActive, smartSelect } = props; let iconOnlyComputed; const hasChildren = slots && slots.default; if (iconOnly || !text && !hasChildren) { iconOnlyComputed = true; } else { iconOnlyComputed = false; } return classNames({ link: !(noLinkClass || isTabbarIcons.value), 'icon-only': iconOnlyComputed, 'tab-link': tabLink || tabLink === '', 'tab-link-active': tabLinkActive, 'smart-select': smartSelect }, colorClasses(props), routerClasses(props), actionsClasses(props)); }); const icon = computed(() => useIcon(props)); return { elRef, icon, isTabbarIcons, attrs, classes, f7SmartSelect }; } };