zmp-vue
Version:
Build full featured iOS & Android apps using ZMP & Vue
168 lines (148 loc) • 4.76 kB
JavaScript
;
exports.__esModule = true;
exports.default = void 0;
var _vue = require("vue");
var _utils = require("../shared/utils");
var _mixins = require("../shared/mixins");
var _zmp = require("../shared/zmp");
var _useTheme = require("../shared/use-theme");
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); }
var _hoisted_1 = {
key: 0,
className: "toolbar-inner"
};
function render(_ctx, _cache) {
return (0, _vue.openBlock)(), (0, _vue.createBlock)("div", {
ref: "elRef",
class: _ctx.classes
}, [(0, _vue.renderSlot)(_ctx.$slots, "before-inner"), _ctx.inner ? ((0, _vue.openBlock)(), (0, _vue.createBlock)("div", _hoisted_1, [(0, _vue.renderSlot)(_ctx.$slots, "default")])) : (0, _vue.renderSlot)(_ctx.$slots, "default", {
key: 1
}), (0, _vue.renderSlot)(_ctx.$slots, "after-inner")], 2);
}
var _default = {
name: 'zmp-toolbar',
render: render,
props: _extends({
tabbar: Boolean,
labels: Boolean,
scrollable: Boolean,
hidden: Boolean,
noShadow: Boolean,
noHairline: Boolean,
noBorder: Boolean,
position: {
type: String,
default: undefined
},
topMd: {
type: Boolean,
default: undefined
},
topIos: {
type: Boolean,
default: undefined
},
topAurora: {
type: Boolean,
default: undefined
},
top: {
type: Boolean,
default: undefined
},
bottomMd: {
type: Boolean,
default: undefined
},
bottomIos: {
type: Boolean,
default: undefined
},
bottomAurora: {
type: Boolean,
default: undefined
},
bottom: {
type: Boolean,
default: undefined
},
inner: {
type: Boolean,
default: true
}
}, _mixins.colorProps),
emits: ['toolbar:hide', 'toolbar:show'],
setup: function setup(props, _ref) {
var emit = _ref.emit;
var elRef = (0, _vue.ref)(null);
var theme = (0, _useTheme.useTheme)();
var onHide = function onHide(toolbarEl) {
if (elRef.value !== toolbarEl) return;
emit('toolbar:hide');
};
var onShow = function onShow(toolbarEl) {
if (elRef.value !== toolbarEl) return;
emit('toolbar:show');
};
var hide = function hide(animate) {
if (!_zmp.zmp) return;
_zmp.zmp.toolbar.hide(elRef.value, animate);
};
var show = function show(animate) {
if (!_zmp.zmp) return;
_zmp.zmp.toolbar.show(elRef.value, animate);
};
(0, _vue.onMounted)(function () {
if (props.tabbar && _zmp.zmp && elRef.value) {
_zmp.zmp.toolbar.setHighlight(elRef.value);
}
_zmp.zmp.on('toolbarShow', onShow);
_zmp.zmp.on('toolbarHide', onHide);
});
(0, _vue.onBeforeUnmount)(function () {
_zmp.zmp.off('toolbarShow', onShow);
_zmp.zmp.off('toolbarHide', onHide);
});
var TabbarContext = (0, _vue.computed)(function () {
return {
tabbarHasLabels: props.labels
};
});
(0, _vue.provide)('TabbarContext', TabbarContext);
var classes = (0, _vue.computed)(function () {
var tabbar = props.tabbar,
bottomMd = props.bottomMd,
bottomIos = props.bottomIos,
bottomAurora = props.bottomAurora,
bottom = props.bottom,
position = props.position,
topMd = props.topMd,
topIos = props.topIos,
topAurora = props.topAurora,
top = props.top,
labels = props.labels,
scrollable = props.scrollable,
hidden = props.hidden,
noShadow = props.noShadow,
noHairline = props.noHairline,
noBorder = props.noBorder;
return (0, _utils.classNames)('toolbar', {
tabbar: tabbar,
'toolbar-bottom': theme.value && theme.value.md && bottomMd || theme.value && theme.value.ios && bottomIos || theme.value && theme.value.aurora && bottomAurora || bottom || position === 'bottom',
'toolbar-top': theme.value && theme.value.md && topMd || theme.value && theme.value.ios && topIos || theme.value && theme.value.aurora && topAurora || top || position === 'top',
'tabbar-labels': labels,
'tabbar-scrollable': scrollable,
'toolbar-hidden': hidden,
'no-shadow': noShadow,
'no-hairline': noHairline || noBorder
}, (0, _mixins.colorClasses)(props));
});
return {
classes: classes,
elRef: elRef,
hide: hide,
show: show
};
}
};
exports.default = _default;