UNPKG

tdesign-mobile-vue

Version:
148 lines (144 loc) 4.34 kB
/** * tdesign v1.9.3 * (c) 2025 TDesign Group * @license MIT */ import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, ref, createVNode, h, watch } from 'vue'; import { isNumber, isArray, isFunction } from 'lodash-es'; import { useContent } from '../hooks/tnode.js'; import { usePrefixClass } from '../hooks/useClass.js'; import config from '../config.js'; import SkeletonProps from './props.js'; import '../hooks/render-tnode.js'; import '../_common/js/utils/general.js'; import '../config-provider/useConfig.js'; 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-fe4ae270.js'; import '@babel/runtime/helpers/typeof'; import '../_chunks/dep-a8acd638.js'; import 'dayjs'; import '../_chunks/dep-2200259b.js'; import '../config-provider/type.js'; var prefix = config.prefix; var ThemeMap = { avatar: [{ type: "circle", size: "48px" }], image: [{ type: "rect", size: "72px" }], text: [[{ width: "24%", height: "16px", marginRight: "16px" }, { width: "76%", height: "16px" }], 1], paragraph: [1, 1, 1, { width: "55%" }] }; var getColItemStyle = function getColItemStyle(obj) { var styleName = ["width", "height", "marginRight", "marginLeft", "margin", "size", "background", "backgroundColor", "borderRadius"]; var style = {}; styleName.forEach(function (name) { if (name in obj) { var px = isNumber(obj[name]) ? "".concat(obj[name], "px") : obj[name]; if (name === "size") { var _ref = [px, px]; style.width = _ref[0]; style.height = _ref[1]; } else { style[name] = px; } } }); return style; }; var _Skeleton = defineComponent({ name: "".concat(prefix, "-skeleton"), props: SkeletonProps, setup: function setup(props, _ref2) { var slots = _ref2.slots; var isShow = ref(false); var renderContent = useContent(); var skeletonClass = usePrefixClass("skeleton"); var getColItemClass = function getColItemClass(obj) { return ["".concat(skeletonClass.value, "__col"), "".concat(skeletonClass.value, "--type-").concat(obj.type || "text"), _defineProperty({}, "".concat(skeletonClass.value, "--animation-").concat(props.animation), props.animation)]; }; var renderCols = function renderCols(_cols) { var cols = []; if (isArray(_cols)) { cols = _cols; } else if (isNumber(_cols)) { cols = new Array(_cols).fill({ type: "text" }); } else { cols = [_cols]; } return cols.map(function (obj) { return createVNode("div", { "class": getColItemClass(obj), "style": getColItemStyle(obj) }, [isFunction(obj.content) ? obj.content(h) : obj.content]); }); }; var renderRowCol = function renderRowCol(_rowCol) { var rowCol = _rowCol || props.rowCol; return rowCol.map(function (item) { return createVNode("div", { "class": "".concat(skeletonClass.value, "__row") }, [renderCols(item)]); }); }; watch(function () { return props.loading; }, function (val) { if (!val || props.delay === 0) { isShow.value = val; return; } setTimeout(function () { isShow.value = val; }, props.delay); }, { immediate: true }); return function () { var content = renderContent("default", "content"); if (slots.default) { return createVNode("div", null, [content]); } if (!isShow.value) { return; } var children = []; if (props.rowCol) { children.push(renderRowCol(props.rowCol)); } else if (props.theme) { children.push(renderRowCol(ThemeMap[props.theme])); } else if (!props.theme && !props.rowCol) { children.push(renderRowCol([[{ width: "24%", height: "16px", marginRight: "16px" }, { width: "76%", height: "16px" }], 1])); } return createVNode("div", { "class": skeletonClass.value }, [children]); }; } }); export { _Skeleton as default }; //# sourceMappingURL=skeleton.js.map