tdesign-mobile-vue
Version:
tdesign-mobile-vue
155 lines (151 loc) • 4.5 kB
JavaScript
/**
* tdesign v1.7.0
* (c) 2024 TDesign Group
* @license MIT
*/
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, watch, createVNode, h } from 'vue';
import isNumber from 'lodash/isNumber';
import isArray from 'lodash/isArray';
import isFunction from 'lodash/isFunction';
import { useContent } from '../hooks/tnode.js';
import { usePrefixClass } from '../hooks/useClass.js';
import config from '../config.js';
import SkeletonProps from './props.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../hooks/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isString';
import 'lodash/isObject';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
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';
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