UNPKG

zmp-vue

Version:

Build full featured iOS & Android apps using ZMP & Vue

82 lines (74 loc) 2.63 kB
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); } import { h, computed, ref } from 'vue'; import { classNames } from '../shared/utils'; import { colorClasses, colorProps } from '../shared/mixins'; import { useTooltip } from '../shared/use-tooltip'; export default { name: 'zmp-fab', props: _extends({ morphTo: String, href: [Boolean, String], target: String, text: String, position: { type: String, default: 'right-bottom' }, tooltip: String, tooltipTrigger: String }, colorProps), emits: ['click'], setup: function setup(props, _ref) { var emit = _ref.emit, slots = _ref.slots; var elRef = ref(null); var onClick = function onClick(e) { emit('click', e); }; useTooltip(elRef, props); var hrefComputed = computed(function () { var href = props.href; if (href === true) href = '#'; if (href === false) href = undefined; // no href attribute return href; }); return function () { var linkChildren = []; var rootChildren = []; var textEl; var linkEl; var linkSlots = slots.link, defaultSlots = slots.default, rootSlots = slots.root, textSlots = slots.text; if (defaultSlots) { defaultSlots().forEach(function (vnode) { if (typeof vnode === 'undefined') return; var tag = vnode.type && vnode.type.name ? vnode.type.name : vnode.type; if (tag === 'FabButtons' || tag === 'zmp-fab-buttons') rootChildren.push(vnode);else linkChildren.push(vnode); }); } if (props.text || textSlots) { textEl = h('div', { class: 'fab-text' }, [props.text, textSlots && textSlots()]); } if (linkChildren.length || linkSlots || textEl) { linkEl = h('a', { target: props.target, href: hrefComputed.value, onClick: onClick }, [linkChildren, textEl, linkSlots && linkSlots()]); } var classes = classNames('fab', "fab-" + props.position, { 'fab-morph': props.morphTo, 'fab-extended': typeof textEl !== 'undefined' }, colorClasses(props)); return h('div', { class: classes, 'data-morph-to': props.morphTo, ref: elRef }, [linkEl, rootChildren, rootSlots && rootSlots()]); }; } };