tdesign-mobile-vue
Version:
tdesign-mobile-vue
125 lines (121 loc) • 4.88 kB
JavaScript
/**
* tdesign v1.7.0
* (c) 2024 TDesign Group
* @license MIT
*/
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed, createVNode, resolveComponent } from 'vue';
import { ChevronLeftIcon } from 'tdesign-icons-vue-next';
import config from '../config.js';
import props from './props.js';
import { usePrefixClass } from '../hooks/useClass.js';
import { useTNodeJSX } from '../hooks/tnode.js';
import '../config-provider/useConfig.js';
import 'lodash/isFunction';
import 'lodash/cloneDeep';
import 'lodash/isString';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import 'lodash/isArray';
import '../_common/js/global-config/mobile/default-config.js';
import '../_common/js/global-config/mobile/locale/zh_CN.js';
import '../_chunks/dep-d5364bc4.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-eb734424.js';
import 'dayjs';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../hooks/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
var prefix = config.prefix;
var _Navbar = defineComponent({
name: "".concat(prefix, "-navbar"),
components: {
TChevronLeftIcon: ChevronLeftIcon
},
props: props,
emits: ["left-click", "right-click"],
setup: function setup(props2, _ref) {
var slots = _ref.slots;
var navbarClass = usePrefixClass("navbar");
var renderTNodeJSX = useTNodeJSX();
var animationSuffix = computed(function () {
return props2.animation ? "-animation" : "";
});
var navClass = computed(function () {
return [navbarClass.value, _defineProperty({}, "".concat(navbarClass.value, "--fixed"), props2.fixed), props2.visible ? "".concat(navbarClass.value, "--visible").concat(animationSuffix.value) : "".concat(navbarClass.value, "--hide").concat(animationSuffix.value)];
});
var navStyle = computed(function () {
return "position: ".concat(props2.fixed ? "fixed" : "relative", ";");
});
var handleLeftClick = function handleLeftClick() {
var _props2$onLeftClick;
(_props2$onLeftClick = props2.onLeftClick) === null || _props2$onLeftClick === void 0 || _props2$onLeftClick.call(props2);
};
var handleRightClick = function handleRightClick() {
var _props2$onRightClick;
(_props2$onRightClick = props2.onRightClick) === null || _props2$onRightClick === void 0 || _props2$onRightClick.call(props2);
};
return function () {
var fixed = props2.fixed,
titleMaxLength = props2.titleMaxLength,
title = props2.title,
leftArrow = props2.leftArrow;
var renderRightContent = function renderRightContent() {
var rightContent = renderTNodeJSX("right");
if (!rightContent) {
return null;
}
return createVNode("div", {
"class": "".concat(navbarClass.value, "__right"),
"onClick": handleRightClick
}, [rightContent]);
};
var renderCapsuleContent = function renderCapsuleContent() {
var capsuleContent = renderTNodeJSX("capsule");
if (!capsuleContent) {
return null;
}
return createVNode("div", {
"class": "".concat(navbarClass.value, "__capsule")
}, [capsuleContent]);
};
var renderTitleContent = function renderTitleContent() {
var isStringTitle = typeof title === "string" && !slots.title;
var titleContent = renderTNodeJSX("title");
if (!titleContent) {
return null;
}
if (titleMaxLength != null && title) {
if (titleMaxLength <= 0) {
console.warn("titleMaxLength must be greater than 0");
} else {
titleContent = title.length <= titleMaxLength ? title : "".concat(title.slice(0, titleMaxLength), "...");
}
}
return isStringTitle ? createVNode("span", {
"class": "".concat(navbarClass.value, "__center-title")
}, [titleContent]) : titleContent;
};
return createVNode("div", {
"class": navClass.value,
"style": navStyle.value
}, [fixed && createVNode("div", {
"class": "".concat(navbarClass.value, "____placeholder")
}, null), createVNode("div", {
"class": "".concat(navbarClass.value, "__content")
}, [createVNode("div", {
"class": "".concat(navbarClass.value, "__left"),
"onClick": handleLeftClick
}, [leftArrow && createVNode(resolveComponent("t-chevron-left-icon"), {
"class": "".concat(navbarClass.value, "__left-arrow")
}, null), renderTNodeJSX("left"), renderCapsuleContent()]), createVNode("div", {
"class": "".concat(navbarClass.value, "__center")
}, [renderTitleContent()]), renderRightContent()])]);
};
}
});
export { _Navbar as default };
//# sourceMappingURL=navbar.js.map