UNPKG

tdesign-mobile-vue

Version:
124 lines (120 loc) 5.58 kB
/** * tdesign v1.15.0 * (c) 2026 TDesign Group * @license MIT */ import _typeof from '@babel/runtime/helpers/typeof'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, computed, ref, createVNode, h } from 'vue'; import { usePrefixClass } from '../hooks/useClass.js'; import { useConfig } from '../config-provider/useConfig.js'; import props from './paragraph-props.js'; import 'lodash-es'; import '../config-provider/context.js'; import '../_common/js/global-config/mobile/default-config.js'; import '../_common/js/global-config/mobile/locale/zh_CN.js'; import '../_chunks/dep-5428cfc4.js'; import '../_chunks/dep-db9f269e.js'; import 'dayjs'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var Ellipsis = defineComponent({ name: "TEllipsis", props: _objectSpread(_objectSpread({}, props), {}, { renderCopy: Function }), setup: function setup(props2, _ref) { var slots = _ref.slots; var COMPONENT_NAME = usePrefixClass("typography"); var _useConfig = useConfig("typography"), globalConfig = _useConfig.globalConfig; var content = computed(function () { return props2.content || (slots === null || slots === void 0 ? void 0 : slots.default()); }); var ellipsisState = computed(function () { var ellipsis = props2.ellipsis; return _objectSpread({ row: 1, expandable: false }, _typeof(ellipsis) === "object" ? ellipsis : null); }); var ellipsisStyles = computed(function () { var ellipsis = ellipsisState.value; var def = { overflow: props2.ellipsis ? "hidden" : "visible", textOverflow: props2.ellipsis ? "ellipsis" : "initial", whiteSpace: props2.ellipsis ? "normal" : "nowrap", display: "-webkit-box", WebkitLineClamp: ellipsis.row, WebkitBoxOrient: "vertical" }; if (isExpand.value) { def.overflow = "visible"; def.whiteSpace = "normal"; def.display = "initial"; } return def; }); var isExpand = ref(false); var onExpand = function onExpand() { var _props2$ellipsis$onEx, _props2$ellipsis; isExpand.value = true; if (_typeof(props2.ellipsis) === "object") (_props2$ellipsis$onEx = (_props2$ellipsis = props2.ellipsis).onExpand) === null || _props2$ellipsis$onEx === void 0 || _props2$ellipsis$onEx.call(_props2$ellipsis, true); }; var onCollapse = function onCollapse() { var _props2$ellipsis$onEx2, _props2$ellipsis2; isExpand.value = false; if (_typeof(props2.ellipsis) === "object") (_props2$ellipsis$onEx2 = (_props2$ellipsis2 = props2.ellipsis).onExpand) === null || _props2$ellipsis$onEx2 === void 0 || _props2$ellipsis$onEx2.call(_props2$ellipsis2, false); }; var renderSuffix = function renderSuffix(expanded) { var suffix = ellipsisState.value.suffix; if (!suffix) return null; if (typeof suffix === "function") return suffix(h, { expanded: expanded }); return suffix; }; var renderEllipsisExpand = function renderEllipsisExpand() { var _globalConfig$value; var suffix = ellipsisState.value.suffix; var symbolStyle = { textDecoration: "none", whiteSpace: "nowrap", flex: 1, marginRight: props2.renderCopy ? "8px" : 0 }; var moreNode = createVNode("span", { "class": "".concat(COMPONENT_NAME.value, "-ellipsis-symbol"), "onClick": onExpand, "style": symbolStyle }, [suffix ? renderSuffix(false) : ((_globalConfig$value = globalConfig.value) === null || _globalConfig$value === void 0 ? void 0 : _globalConfig$value.expandText) || "\u5C55\u5F00"]); var _ellipsisState$value = ellipsisState.value, expandable = _ellipsisState$value.expandable, collapsible = _ellipsisState$value.collapsible; if (!isExpand.value && expandable) { return moreNode; } if (expandable && isExpand.value && collapsible) { var _globalConfig$value2; return createVNode("span", { "class": "".concat(COMPONENT_NAME.value, "-ellipsis-symbol"), "onClick": onCollapse, "style": symbolStyle }, [((_globalConfig$value2 = globalConfig.value) === null || _globalConfig$value2 === void 0 ? void 0 : _globalConfig$value2.collapseText) || "\u6536\u8D77"]); } }; return function () { var _props2$renderCopy; return createVNode("div", { "style": { display: "flex", alignItems: "flex-end" } }, [createVNode("p", { "style": props2.ellipsis ? ellipsisStyles.value : {} }, [content.value]), renderEllipsisExpand(), (_props2$renderCopy = props2.renderCopy) === null || _props2$renderCopy === void 0 ? void 0 : _props2$renderCopy.call(props2)]); }; } }); export { Ellipsis as default }; //# sourceMappingURL=ellipsis.js.map